Skip to content

Commit de7e7e7

Browse files
committed
setMeshData
1 parent 29ba5f8 commit de7e7e7

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/pmpo_c.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -646,21 +646,27 @@ void polympo_getMeshVtxVel_f(MPMesh_ptr p_mpmesh, const int nVertices, double* u
646646
pumipic::RecordTime("PolyMPO_getMeshVtxVel", timer.seconds());
647647
}
648648

649-
void polympo_setMeshVtxMass_f(MPMesh_ptr p_mpmesh, const int nVertices, const double* vtxMass){
649+
template <polyMPO::MeshFieldIndex meshField>
650+
void setMeshData(MPMesh_ptr p_mpmesh, const int nVertices, const double* meshDataIn){
650651
//check mpMesh is valid
651652
checkMPMeshValid(p_mpmesh);
652653
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
653654

654655
//check the size
655-
PMT_ALWAYS_ASSERT(p_mesh->getNumVertices()==nVertices);
656+
// PMT_ALWAYS_ASSERT(p_mesh->getNumVertices()==nVertices);
657+
// PMT_ALWAYS_ASSERT(p_mesh->getNumElements()==nCells);
656658

657659
//copy the host array to the device
658-
auto coordsArray = p_mesh->getMeshField<polyMPO::MeshF_VtxMass>();
659-
auto h_coordsArray = Kokkos::create_mirror_view(coordsArray);
660+
auto meshData = p_mesh->getMeshField<meshField>();
661+
auto meshData_h = Kokkos::create_mirror_view(meshData);
660662
for(int i=0; i<nVertices; i++){
661-
h_coordsArray(i,0) = vtxMass[i];
663+
meshData_h(i,0) = meshDataIn[i];
662664
}
663-
Kokkos::deep_copy(coordsArray, h_coordsArray);
665+
Kokkos::deep_copy(meshData, meshData_h);
666+
}
667+
668+
void polympo_setMeshVtxMass_f(MPMesh_ptr p_mpmesh, const int nVertices, const double* vtxMass){
669+
setMeshData<polyMPO::MeshF_VtxMass>(p_mpmesh, nVertices, vtxMass);
664670
}
665671

666672
void polympo_getMeshVtxMass_f(MPMesh_ptr p_mpmesh, const int nVertices, double* vtxMass){
@@ -682,21 +688,7 @@ void polympo_getMeshVtxMass_f(MPMesh_ptr p_mpmesh, const int nVertices, double*
682688
}
683689

684690
void polympo_setMeshElmMass_f(MPMesh_ptr p_mpmesh, const int nCells, const double* elmMass){
685-
//check mpMesh is valid
686-
checkMPMeshValid(p_mpmesh);
687-
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
688-
689-
//check the size
690-
PMT_ALWAYS_ASSERT(p_mesh->getNumElements()==nCells);
691-
692-
//copy the host array to the device
693-
auto coordsArray = p_mesh->getMeshField<polyMPO::MeshF_ElmMass>();
694-
auto h_coordsArray = Kokkos::create_mirror_view(coordsArray);
695-
kkViewHostU<const double*> arrayHost(elmMass, nCells);
696-
for(int i=0; i<nCells; i++){
697-
h_coordsArray(i,0) = arrayHost[i];
698-
}
699-
Kokkos::deep_copy(coordsArray, h_coordsArray);
691+
setMeshData<polyMPO::MeshF_ElmMass>(p_mpmesh, nCells, elmMass);
700692
}
701693

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

0 commit comments

Comments
 (0)