Skip to content

Commit 0b4cd86

Browse files
committed
most mesh data working
1 parent de7e7e7 commit 0b4cd86

File tree

1 file changed

+24
-64
lines changed

1 file changed

+24
-64
lines changed

src/pmpo_c.cpp

Lines changed: 24 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -496,25 +496,29 @@ int polympo_getMeshFElmType_f() {
496496
return polyMPO::MeshFType_ElmBased;
497497
}
498498

499-
void polympo_setMeshVtxCoords_f(MPMesh_ptr p_mpmesh, const int nVertices, const double* xArray, const double* yArray, const double* zArray){
499+
template<polyMPO::MeshFieldIndex fieldType>
500+
void setMeshData(MPMesh_ptr p_mpmesh, const int nComps, const int nVertices, const double** meshDataIn){
500501
Kokkos::Timer timer;
501-
//chech validity
502502
checkMPMeshValid(p_mpmesh);
503503
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
504504

505505
//check the size
506-
PMT_ALWAYS_ASSERT(p_mesh->getNumVertices()==nVertices);
506+
// PMT_ALWAYS_ASSERT(p_mesh->getNumVertices()==nVertices);
507+
// PMT_ALWAYS_ASSERT(p_mesh->getNumElements()==nCells);
507508

508509
//copy the host array to the device
509-
auto coordsArray = p_mesh->getMeshField<polyMPO::MeshF_VtxCoords>();
510-
auto h_coordsArray = Kokkos::create_mirror_view(coordsArray);
511-
for(int i=0; i<nVertices; i++){
512-
h_coordsArray(i,0) = xArray[i];
513-
h_coordsArray(i,1) = yArray[i];
514-
h_coordsArray(i,2) = zArray[i];
515-
}
516-
Kokkos::deep_copy(coordsArray, h_coordsArray);
517-
pumipic::RecordTime("PolyMPO_setMeshVtxCoords", timer.seconds());
510+
auto meshData = p_mesh->getMeshField<fieldType>();
511+
auto meshData_h = Kokkos::create_mirror_view(meshData);
512+
for(int i=0; i<nVertices; i++)
513+
for(int j=0; j<nComps; j++)
514+
meshData_h(i, j) = meshDataIn[j][i];
515+
Kokkos::deep_copy(meshData, meshData_h);
516+
pumipic::RecordTime("PolyMPO_setMeshData", timer.seconds());
517+
}
518+
519+
void polympo_setMeshVtxCoords_f(MPMesh_ptr p_mpmesh, const int nVertices, const double* xArray, const double* yArray, const double* zArray){
520+
const double* dataIn[] = {xArray, yArray, zArray};
521+
setMeshData<polyMPO::MeshF_VtxCoords>(p_mpmesh, 3, nVertices, dataIn);
518522
}
519523

520524
void polympo_getMeshVtxCoords_f(MPMesh_ptr p_mpmesh, const int nVertices, double* xArray, double* yArray, double* zArray){
@@ -573,22 +577,8 @@ void polympo_getMeshVtxRotLat_f(MPMesh_ptr p_mpmesh, const int nVertices, double
573577
}
574578

575579
void polympo_setMeshElmCenter_f(MPMesh_ptr p_mpmesh, const int nCells, const double* xArray, const double* yArray, const double* zArray){
576-
//chech validity
577-
checkMPMeshValid(p_mpmesh);
578-
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
579-
580-
//check the size
581-
PMT_ALWAYS_ASSERT(p_mesh->getNumElements()==nCells);
582-
583-
//copy the host array to the device
584-
auto elmCenter = p_mesh->getMeshField<polyMPO::MeshF_ElmCenterXYZ>();
585-
auto h_elmCenter = Kokkos::create_mirror_view(elmCenter);
586-
for(int i=0; i<nCells; i++){
587-
h_elmCenter(i,0) = xArray[i];
588-
h_elmCenter(i,1) = yArray[i];
589-
h_elmCenter(i,2) = zArray[i];
590-
}
591-
Kokkos::deep_copy(elmCenter, h_elmCenter);
580+
const double* dataIn[] = {xArray, yArray, zArray};
581+
setMeshData<polyMPO::MeshF_ElmCenterXYZ>(p_mpmesh, 3, nCells, dataIn);
592582
}
593583

594584
void polympo_getMeshElmCenter_f(MPMesh_ptr p_mpmesh, const int nCells, double* xArray, double* yArray, double* zArray){
@@ -610,21 +600,8 @@ void polympo_getMeshElmCenter_f(MPMesh_ptr p_mpmesh, const int nCells, double* x
610600
}
611601

612602
void polympo_setMeshVtxVel_f(MPMesh_ptr p_mpmesh, const int nVertices, const double* uVelIn, const double* vVelIn){
613-
//check mpMesh is valid
614-
checkMPMeshValid(p_mpmesh);
615-
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
616-
617-
//check the size
618-
PMT_ALWAYS_ASSERT(p_mesh->getNumVertices()==nVertices);
619-
620-
//copy the host array to the device
621-
auto coordsArray = p_mesh->getMeshField<polyMPO::MeshF_Vel>();
622-
auto h_coordsArray = Kokkos::create_mirror_view(coordsArray);
623-
for(int i=0; i<nVertices; i++){
624-
h_coordsArray(i,0) = uVelIn[i];
625-
h_coordsArray(i,1) = vVelIn[i];
626-
}
627-
Kokkos::deep_copy(coordsArray, h_coordsArray);
603+
const double* dataIn[] = {uVelIn, vVelIn};
604+
setMeshData<polyMPO::MeshF_Vel>(p_mpmesh, 2, nVertices, dataIn);
628605
}
629606

630607
void polympo_getMeshVtxVel_f(MPMesh_ptr p_mpmesh, const int nVertices, double* uVelOut, double* vVelOut){
@@ -646,27 +623,9 @@ void polympo_getMeshVtxVel_f(MPMesh_ptr p_mpmesh, const int nVertices, double* u
646623
pumipic::RecordTime("PolyMPO_getMeshVtxVel", timer.seconds());
647624
}
648625

649-
template <polyMPO::MeshFieldIndex meshField>
650-
void setMeshData(MPMesh_ptr p_mpmesh, const int nVertices, const double* meshDataIn){
651-
//check mpMesh is valid
652-
checkMPMeshValid(p_mpmesh);
653-
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
654-
655-
//check the size
656-
// PMT_ALWAYS_ASSERT(p_mesh->getNumVertices()==nVertices);
657-
// PMT_ALWAYS_ASSERT(p_mesh->getNumElements()==nCells);
658-
659-
//copy the host array to the device
660-
auto meshData = p_mesh->getMeshField<meshField>();
661-
auto meshData_h = Kokkos::create_mirror_view(meshData);
662-
for(int i=0; i<nVertices; i++){
663-
meshData_h(i,0) = meshDataIn[i];
664-
}
665-
Kokkos::deep_copy(meshData, meshData_h);
666-
}
667-
668626
void polympo_setMeshVtxMass_f(MPMesh_ptr p_mpmesh, const int nVertices, const double* vtxMass){
669-
setMeshData<polyMPO::MeshF_VtxMass>(p_mpmesh, nVertices, vtxMass);
627+
const double* dataIn[] = {vtxMass};
628+
setMeshData<polyMPO::MeshF_VtxMass>(p_mpmesh, 1, nVertices, dataIn);
670629
}
671630

672631
void polympo_getMeshVtxMass_f(MPMesh_ptr p_mpmesh, const int nVertices, double* vtxMass){
@@ -688,7 +647,8 @@ void polympo_getMeshVtxMass_f(MPMesh_ptr p_mpmesh, const int nVertices, double*
688647
}
689648

690649
void polympo_setMeshElmMass_f(MPMesh_ptr p_mpmesh, const int nCells, const double* elmMass){
691-
setMeshData<polyMPO::MeshF_ElmMass>(p_mpmesh, nCells, elmMass);
650+
const double* dataIn[] = {elmMass};
651+
setMeshData<polyMPO::MeshF_ElmMass>(p_mpmesh, 1, nCells, dataIn);
692652
}
693653

694654
void polympo_getMeshElmMass_f(MPMesh_ptr p_mpmesh, const int nCells, double* elmMass){

0 commit comments

Comments
 (0)