Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ta/mpas cell centers #35

Open
wants to merge 3 commits into
base: cws/pumipicDps
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove personal attribute files, and put this in .gitignore

Binary file not shown.
61 changes: 48 additions & 13 deletions src/pmpo_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,6 @@ void polympo_setMeshNumVtxs(MPMesh_ptr p_mpmesh, int numVtxs){
p_mesh->setMeshVtxBasedFieldSize();
}

int polympo_getMeshNumVtxs(MPMesh_ptr p_mpmesh) {
checkMPMeshValid(p_mpmesh); //chech vailidity
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
int nVtxs = p_mesh->getNumVertices();
return nVtxs;
}

void polympo_setMeshNumElms(MPMesh_ptr p_mpmesh, int numElms){
checkMPMeshValid(p_mpmesh);
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
Expand All @@ -272,14 +265,10 @@ void polympo_setMeshNumElms(MPMesh_ptr p_mpmesh, int numElms){
p_mesh->setNumElms(numElms);
p_mesh->setElm2VtxConn(elm2Vtx);
p_mesh->setElm2ElmConn(elm2Elm);
p_mesh->setMeshVtxBasedFieldSize();
}

int polympo_getMeshNumElms(MPMesh_ptr p_mpmesh) {
checkMPMeshValid(p_mpmesh); //chech vailidity
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
int nElms = p_mesh->getNumElements();
return nElms;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty lines


void polympo_setMeshTypeGeneralPoly(MPMesh_ptr p_mpmesh){
//chech validity
Expand Down Expand Up @@ -375,6 +364,20 @@ void polympo_setMeshElm2ElmConn(MPMesh_ptr p_mpmesh, int maxEdges, int nCells, i
});
}

int polympo_getMeshNumVtxs(MPMesh_ptr p_mpmesh) {
checkMPMeshValid(p_mpmesh); //chech vailidity
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
int nVtxs = p_mesh->getNumVertices();
return nVtxs;
}

int polympo_getMeshNumElms(MPMesh_ptr p_mpmesh) {
checkMPMeshValid(p_mpmesh); //chech vailidity
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
int nElms = p_mesh->getNumElements();
return nElms;
}

void polympo_setMeshVtxCoords(MPMesh_ptr p_mpmesh, int nVertices, double* xArray, double* yArray, double* zArray){
//chech validity
checkMPMeshValid(p_mpmesh);
Expand Down Expand Up @@ -413,6 +416,38 @@ void polympo_getMeshVtxCoords(MPMesh_ptr p_mpmesh, int nVertices, double* xArray
}
}

/*
void polympo_setMeshCellCenters(MPMesh_ptr p_mpmesh, int nCells, double* xArray, double* yArray, double* zArray){

checkMPMeshValid(p_mpmesh);
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;

auto centersArray = p_mesh->getMeshField<polyMPO::MeshF_CellCenters>();
auto h_centersArray = Kokkos::create_mirror_view(centersArray);
for (int i =0; i<nCenters;i++){
xArray[i] = h_centersArray(i,0);
yArray[i] = h_centersArray(i,1);
zArray[i] = h_centersArray(i,2);
}
Kokkos::deep_copy(centersArray, h_centersArray);
}

void polympo_getMeshCellCenters(MPMesh_ptr p_mpmesh, int nCells, double* xArray, double* yArray, double* zArray){

checkMPMeshValid(p_mpmesh);
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;

auto centersArray = p_mesh->getMeshField<polyMPO::MeshF_CellCenters>();
auto h_centersArray = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(),centersArray);

for (int i=0;i<nCenters;i++){
xArray[i] = h_centersArray(i,0);
yArray[i] = h_centersArray(i,1);
zArray[i] = h_centersArray(i,2);
}
}
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't need the code, please remove it.


void polympo_setMeshOnSurfVeloIncr(MPMesh_ptr p_mpmesh, int nComps, int nVertices, double* array) {
//check mpMesh is valid
checkMPMeshValid(p_mpmesh);
Expand Down
11 changes: 7 additions & 4 deletions src/pmpo_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ void polympo_setMeshGeomTypePlanar(MPMesh_ptr p_mpmesh);
void polympo_setMeshGeomTypeSpherical(MPMesh_ptr p_mpmesh);
void polympo_setMeshSphereRadius(MPMesh_ptr p_mpmesh, double sphereRadius);
void polympo_setMeshNumVtxs(MPMesh_ptr p_mpmesh, int numVtxs);
int polympo_getMeshNumVtxs(MPMesh_ptr p_mpmesh);
void polympo_setMeshNumElms(MPMesh_ptr p_mpmesh, int numElms);
int polympo_getMeshNumElms(MPMesh_ptr p_mpmesh);
void polympo_setMeshNumEdgesPerElm(MPMesh_ptr p_mpmesh, int nCells, int* array);
void polympo_setMeshElm2VtxConn(MPMesh_ptr p_mpmesh, int maxEdges, int nCells, int* array);
void polympo_setMeshElm2ElmConn(MPMesh_ptr p_mpmesh, int maxEdges, int nCells, int* array);
int polympo_getMeshNumVtxs(MPMesh_ptr p_mpmesh);
int polympo_getMeshNumElms(MPMesh_ptr p_mpmesh);

//Mesh fields
void polympo_setMeshVtxCoords(MPMesh_ptr p_mpmesh, int nVertices, double* xArray, double* yArray, double* zArray);
void polympo_getMeshVtxCoords(MPMesh_ptr p_mpmesh, int nVertices, double* xArray, double* yArray, double* zArray);
void polympo_setMeshVtxCoords(MPMesh_ptr p_mpmesh, int nCells, double* xArray, double* yArray, double* zArray);
void polympo_getMeshVtxCoords(MPMesh_ptr p_mpmesh, int nCells, double* xArray, double* yArray, double* zArray);
//void polympo_setMeshCellCenters(MPMesh_ptr p_mpmesh, int nCenters, double* xArray, double* yArray, double* zArray);
//void polympo_getMeshCellCenters(MPMesh_ptr p_mpmesh, int nCenters, double* xArray, double* yArray, double* zArray);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out code.

void polympo_setMeshOnSurfVeloIncr(MPMesh_ptr p_mpmesh, int nComps, int nVertices, double* array);//vec2d
void polympo_getMeshOnSurfVeloIncr(MPMesh_ptr p_mpmesh, int nComps, int nVertices, double* array);//vec2d
void polympo_setMeshOnSurfDispIncr(MPMesh_ptr p_mpmesh, int nComps, int nVertices, double* array);//vec2d
void polympo_getMeshOnSurfDispIncr(MPMesh_ptr p_mpmesh, int nComps, int nVertices, double* array);//vec2d

}
#endif
70 changes: 48 additions & 22 deletions src/pmpo_fortran.f90
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,6 @@ subroutine polympo_setMeshNumVtxs(mpMesh,numVtxs) &
integer(c_int), value :: numVtxs
end subroutine
!---------------------------------------------------------------------------
!> @brief get the number of vertices from the mesh holding by polyMPO
!> @param mpMesh(in) mpMesh object
!> @param numVtxs(return)) the number of vertices
!---------------------------------------------------------------------------
function polympo_getMeshNumVtxs(mpMesh) result(numVtxs) &
bind(C, NAME = 'polympo_getMeshNumVtxs')
use :: iso_c_binding
type(c_ptr), intent(in), value :: mpMesh
integer(c_int) :: numVtxs
end function
!---------------------------------------------------------------------------
!> @brief set the number of elements of the mesh
!> modifies mesh topology polympo_startMeshFill required
!> @param mpMesh(in/out) mpMesh object
Expand All @@ -246,17 +235,6 @@ subroutine polympo_setMeshNumElms(mpMesh,numElms) &
integer(c_int), value :: numElms
end subroutine
!---------------------------------------------------------------------------
!> @brief get the number of elements from the mesh holding by polyMPO
!> @param mpMesh(in) mpMesh object
!> @param numVtxs(return)) the number of elements
!---------------------------------------------------------------------------
function polympo_getMeshNumElms(mpMesh) result(numElms) &
bind(C, NAME = 'polympo_getMeshNumElms')
use :: iso_c_binding
type(c_ptr), intent(in), value :: mpMesh
integer(c_int) :: numElms
end function
!---------------------------------------------------------------------------
!> @brief set the polympo mesh element to vertices connectivity
!> modifies mesh topology polympo_startMeshFill required
!> @param mpmesh(in/out) MPMesh object
Expand Down Expand Up @@ -285,6 +263,28 @@ subroutine polympo_setMeshElm2ElmConn(mpMesh, maxEdges, nCells, cellsOnCell) &
type(c_ptr), intent(in), value :: cellsOnCell
end subroutine
!---------------------------------------------------------------------------
!> @brief get the number of vertices from the mesh holding by polyMPO
!> @param mpMesh(in) mpMesh object
!> @param numVtxs(return)) the number of vertices
!---------------------------------------------------------------------------
function polympo_getMeshNumVtxs(mpMesh) result(numVtxs) &
bind(C, NAME = 'polympo_getMeshNumVtxs')
use :: iso_c_binding
type(c_ptr), intent(in), value :: mpMesh
integer(c_int) :: numVtxs
end function
!---------------------------------------------------------------------------
!> @brief get the number of elements from the mesh holding by polyMPO
!> @param mpMesh(in) mpMesh object
!> @param numVtxs(return)) the number of elements
!---------------------------------------------------------------------------
function polympo_getMeshNumElms(mpMesh) result(numElms) &
bind(C, NAME = 'polympo_getMeshNumElms')
use :: iso_c_binding
type(c_ptr), intent(in), value :: mpMesh
integer(c_int) :: numElms
end function
!---------------------------------------------------------------------------
!> @brief set the polympo mesh number of edges per element
!> modifies mesh topology polympo_startMeshFill required
!> @param mpmesh(in/out) MPMesh object
Expand Down Expand Up @@ -325,6 +325,32 @@ subroutine polympo_getMeshVtxCoords(mpMesh, nVertices, xArray, yArray, zArray) &
type(c_ptr), value :: xArray, yArray, zArray
end subroutine
!---------------------------------------------------------------------------
!> @brief set the polympo mesh cell centers
!> @param mpmesh(in/out) MPMesh object
!> @param nVertices(in) length of array in
!> @param x/y/zArray(in) the 1D arrays of cell coordinates
!---------------------------------------------------------------------------
!subroutine polympo_setMeshCellCenters(mpMesh, nCenters, xArray, yArray, zArray) &
! bind(C, NAME='polympo_setMeshCellCenters')
! use :: iso_c_binding
! type(c_ptr), value :: mpMesh
! integer(c_int), value:: nVertices
! type(c_ptr), value :: xArray, yArray, zArray
!end subroutine
!---------------------------------------------------------------------------
!> @brief get the polympo mesh cell centers
!> @param mpmesh(in/out) MPMesh object
!> @param nVertices(in) length of array in, use for assertion
!> @param x/y/zArray(in/out) the 1D arrays of vertices coordinates
!---------------------------------------------------------------------------
!subroutine polympo_getMeshCellCenters(mpMesh, nCenters, xArray, yArray, zArray) &
! bind(C, NAME='polympo_getMeshCellCenters')
! use :: iso_c_binding
! type(c_ptr), value :: mpMesh
! integer(c_int), value :: nVertices
! type(c_ptr), value :: xArray, yArray, zArray
!end subroutine
!---------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out code.

!> @brief set the spherical velocity increment mesh array
!> from a host array
!> @param mpmesh(in/out) MPMesh object
Expand Down
9 changes: 9 additions & 0 deletions src/pmpo_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ namespace polyMPO{
vtxOnSurfDispIncr_ = DoubleVec2dView(vtxOnSurfDispIncrMapEntry.second,numVtxs_);
}

void Mesh::setMeshElmBasedFieldSize(){
PMT_ALWAYS_ASSERT(meshEdit_);

auto elmCoordsMapEntry = meshFields2TypeAndString.at(MeshF_ElmCenterXYZ);
PMT_ALWAYS_ASSERT(elmCoordsMapEntry.first == MeshFType_ElmBased);
elmCenterXYZ_ = DoubleVec3dView(elmCoordsMapEntry.second, numElms_);

}

} // namespace polyMPO
13 changes: 11 additions & 2 deletions src/pmpo_mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ enum MeshFieldIndex{
MeshF_VtxCoords,
MeshF_Vel,
MeshF_OnSurfVeloIncr,
MeshF_OnSurfDispIncr
MeshF_OnSurfDispIncr,
MeshF_ElmCenterXYZ
};
enum MeshFieldType{
MeshFType_Invalid = -2,
Expand All @@ -37,7 +38,8 @@ const std::map<MeshFieldIndex, std::pair<MeshFieldType,
{MeshF_VtxCoords, {MeshFType_VtxBased,"MeshField_VerticesCoords"}},
{MeshF_Vel, {MeshFType_VtxBased,"MeshField_Velocity"}},
{MeshF_OnSurfVeloIncr, {MeshFType_VtxBased,"MeshField_OnSurfaceVelocityIncrement"}},
{MeshF_OnSurfDispIncr, {MeshFType_VtxBased,"MeshField_OnSurfaceDisplacementIncrement"}}};
{MeshF_OnSurfDispIncr, {MeshFType_VtxBased,"MeshField_OnSurfaceDisplacementIncrement"}},
{MeshF_ElmCenterXYZ, {MeshFType_ElmBased,"MeshField_ElementCenterXYZ"}}};

enum mesh_type {mesh_unrecognized_lower = -1,
mesh_general_polygonal, //other meshes
Expand All @@ -64,6 +66,7 @@ class Mesh {

//start of meshFields
DoubleVec3dView vtxCoords_;
DoubleVec3dView elmCenterXYZ_;
DoubleVec2dView vtxVel_;
DoubleVec2dView vtxOnSurfVeloIncr_;
DoubleVec2dView vtxOnSurfDispIncr_;
Expand All @@ -88,6 +91,7 @@ class Mesh {
elm2ElmConn_(elm2ElmConn){
meshEdit_ = true;
setMeshVtxBasedFieldSize();
setMeshElmBasedFieldSize();
meshEdit_ = false;
vtxCoords_ = vtxCoords;
}
Expand All @@ -105,6 +109,8 @@ class Mesh {
IntElm2ElmView getElm2ElmConn() { return elm2ElmConn_; }
template<MeshFieldIndex index> auto getMeshField();
void setMeshVtxBasedFieldSize();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the empty line.

void setMeshElmBasedFieldSize();

void setMeshEdit(bool meshEdit) { meshEdit_ = meshEdit; }
//onec MeshType/GeomType is set to valid types, we can't change them anymore
Expand Down Expand Up @@ -146,6 +152,9 @@ auto Mesh::getMeshField(){
else if constexpr (index==MeshF_OnSurfDispIncr){
return vtxOnSurfDispIncr_;
}
else if constexpr (index==MeshF_ElmCenterXYZ){
return elmCenterXYZ_;
}
fprintf(stderr,"Mesh Field Index error!\n");
exit(1);
}
Expand Down
Binary file added src/polympo.mod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this .mod file.

Binary file not shown.
15 changes: 12 additions & 3 deletions test/readMPAS.f90
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ subroutine readMPASMesh(filename, maxEdges, vertexDegree, &
nCells, nVertices, nEdgesOnCell, &
onSphere, sphereRadius, &
xVertex, yVertex, zVertex, &
verticesOnCell, cellsOnCell)
verticesOnCell, cellsOnCell)!,&
!cellCenters)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out code.

use :: netcdf
use :: iso_c_binding
implicit none
Expand All @@ -142,7 +143,7 @@ subroutine readMPASMesh(filename, maxEdges, vertexDegree, &

integer :: ncid, status, nCellsID, nVerticesID, maxEdgesID, vertexDegreeID, &
nEdgesOnCellID, xVertexID, yVertexID, zVertexID, &
verticesOnCellID, cellsOnCellID
verticesOnCellID, cellsOnCellID, cellCentersID

status = nf90_open(path=trim(filename), mode=nf90_nowrite, ncid=ncid)
if (status /= nf90_noerr) then
Expand Down Expand Up @@ -211,9 +212,10 @@ subroutine readMPASMesh(filename, maxEdges, vertexDegree, &
allocate(yVertex(nVertices))
allocate(zVertex(nVertices))
allocate(nEdgesOnCell(nCells))
!allocate(cellCenters(nCells))
allocate(verticesOnCell(maxEdges, nCells))
allocate(cellsOnCell(maxEdges, nCells))

status = nf90_get_att(ncid, nf90_global, "on_a_sphere", onSphere)
if (status /= nf90_noerr) then
write(0, *) "readMPASMesh: Error on get attribute 'on_a_sphere'"
Expand Down Expand Up @@ -315,6 +317,13 @@ subroutine readMPASMesh(filename, maxEdges, vertexDegree, &
stop
end if

!status = nf90_get_var(ncid, cellCentersID, cellCenters)
!if (status /= nf90_noerr) then
! write(0, *) "readMPASMesh: Error on get var of 'cellCenters'"
! write(0, *) trim(nf90_strerror(status))
! stop
!end if

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out code.

status = nf90_close(ncid)
end subroutine readMPASMesh
subroutine setWithMPASMeshByFortran(mpMesh, fileName, n) bind(C, name="setWithMPASMeshByFortran")
Expand Down