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

Eg/add mesh vtx strain rate #62

Open
wants to merge 8 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
43 changes: 43 additions & 0 deletions src/pmpo_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,49 @@ void polympo_getMeshOnSurfDispIncr_f(MPMesh_ptr p_mpmesh, const int nComps, cons
Kokkos::deep_copy(arrayHost, array_d);
}

void polympo_setMeshVtxStrainRate_f(MPMesh_ptr p_mpmesh, const int nVertices, const double** forceArray){
//forceArray has 6 entries, each entry must have nVertices values
//check mpMesh is valid
checkMPMeshValid(p_mpmesh);
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;

//check the size
PMT_ALWAYS_ASSERT(p_mesh->getNumVertices()==nVertices);

auto strainRate = p_mesh->getMeshField<polyMPO::MeshF_VtxStrainRate>();
auto h_strainRate = Kokkos::create_mirror_view(strainRate);
for(int i = 0; i < nVertices; i++){
h_strainRate(i,0) = forceArray[0][i];
h_strainRate(i,1) = forceArray[1][i];
h_strainRate(i,2) = forceArray[2][i];
h_strainRate(i,3) = forceArray[3][i];
h_strainRate(i,4) = forceArray[4][i];
h_strainRate(i,5) = forceArray[5][i];
}

Choose a reason for hiding this comment

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

Need to discuss this numbering, i.e., for 6 components of symmetric tensor per vertex (i.e., 0 through 5).

Copy link
Author

Choose a reason for hiding this comment

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

function now uses one 2d array instead of six 1d arrays.

Kokkos::deep_copy(strainRate, h_strainRate);
}

void polympo_getMeshVtxStrainRate_f(MPMesh_ptr p_mpmesh, const int nVertices, double** forceArray){
//check mpMesh is valid
checkMPMeshValid(p_mpmesh);
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;

//check the size
PMT_ALWAYS_ASSERT(p_mesh->getNumVertices()==nVertices);

auto strainRate = p_mesh->getMeshField<polyMPO::MeshF_VtxStrainRate>();
auto h_strainRate = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), strainRate);
for(int i = 0; i < nVertices; i++){
forceArray[0][i] = h_strainRate(i,0);
forceArray[1][i] = h_strainRate(i,1);
forceArray[2][i] = h_strainRate(i,2);
forceArray[3][i] = h_strainRate(i,3);
forceArray[4][i] = h_strainRate(i,4);
forceArray[5][i] = h_strainRate(i,5);
}
}


void polympo_push_f(MPMesh_ptr p_mpmesh){
checkMPMeshValid(p_mpmesh);
((polyMPO::MPMesh*)p_mpmesh) ->push();
Expand Down
2 changes: 2 additions & 0 deletions src/pmpo_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void polympo_setMeshOnSurfVeloIncr_f(MPMesh_ptr p_mpmesh, const int nComps, cons
void polympo_getMeshOnSurfVeloIncr_f(MPMesh_ptr p_mpmesh, const int nComps, const int nVertices, double* array);//vec2d
void polympo_setMeshOnSurfDispIncr_f(MPMesh_ptr p_mpmesh, const int nComps, const int nVertices, const double* array);//vec2d
void polympo_getMeshOnSurfDispIncr_f(MPMesh_ptr p_mpmesh, const int nComps, const int nVertices, double* array);//vec2d
void polympo_setMeshVtxStrainRate_f(MPMesh_ptr p_mpmesh, const int nVertices, const double** forceArray);
void polympo_getMeshVtxStrainRate_f(MPMesh_ptr p_mpmesh, const int nVertices, double** forceArray);

// calculations
void polympo_push_f(MPMesh_ptr p_mpmesh);
Expand Down
24 changes: 24 additions & 0 deletions src/pmpo_fortran.f90
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,30 @@ subroutine polympo_getMeshOnSurfDispIncr(mpMesh, nComps, nVertices, array) &
type(c_ptr), value :: array
end subroutine
!---------------------------------------------------------------------------
!> @brief set the verte strain rate from a host array
!> @param mpmesh(in/out) MPMesh object
!> @param nVertices(in) numVertices
!> @param forceArray(in) input mesh strain rate 2D array (6,numVtx)
subroutine polympo_setMeshVtxStrainRate(mpMesh, nVertices, forceArray) &
bind(C, NAME='polympo_setMeshVtxStrainRate_f')
use :: iso_c_binding
type(c_ptr), value :: mpMesh
integer(c_int), value :: nVertices
type(c_ptr), intent(in), value :: forceArray
end subroutine
!---------------------------------------------------------------------------
!> @brief get the verte strain rate from polyMPO
!> @param mpmesh(in/out) MPMesh object
!> @param nVertices(in) numVertices
!> @param forceArray(in/out) output mesh strain rate 2D array (6,numVtx)
subroutine polympo_getMeshVtxStrainRate(mpMesh, nVertices, forceArray) &
bind(C, NAME='polympo_getMeshVtxStrainRate_f')
use :: iso_c_binding
type(c_ptr), value :: mpMesh
integer(c_int), value :: nVertices
type(c_ptr), value :: forceArray
end subroutine
!---------------------------------------------------------------------------
!> @brief calculate the MPs from given mesh vertices rotational latitude
!> longitude, update the MP slices
!> MPs MUST have rotated flag set to True(>0)
Expand Down
4 changes: 4 additions & 0 deletions src/pmpo_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ namespace polyMPO{
auto vtxRotLatLonIncrMapEntry = meshFields2TypeAndString.at(MeshF_RotLatLonIncr);
PMT_ALWAYS_ASSERT(vtxRotLatLonIncrMapEntry.first == MeshFType_VtxBased);
vtxRotLatLonIncr_ = DoubleVec2dView(vtxRotLatLonIncrMapEntry.second,numVtxs_);

auto vtxStrainRateMapEntry = meshFields2TypeAndString.at(MeshF_VtxStrainRate);
PMT_ALWAYS_ASSERT(vtxStrainRateMapEntry.first == MeshFType_VtxBased);
vtxStrainRate_ = DoubleSymMat3dView(vtxStrainRateMapEntry.second,numVtxs_);
}

void Mesh::computeRotLatLonIncr(){
Expand Down
10 changes: 8 additions & 2 deletions src/pmpo_mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ enum MeshFieldIndex{
MeshF_Vel,
MeshF_OnSurfVeloIncr,
MeshF_OnSurfDispIncr,
MeshF_RotLatLonIncr
MeshF_RotLatLonIncr,
MeshF_VtxStrainRate
};
enum MeshFieldType{
MeshFType_Invalid = -2,
Expand All @@ -42,7 +43,8 @@ const std::map<MeshFieldIndex, std::pair<MeshFieldType,
{MeshF_Vel, {MeshFType_VtxBased,"MeshField_Velocity"}},
{MeshF_OnSurfVeloIncr, {MeshFType_VtxBased,"MeshField_OnSurfaceVelocityIncrement"}},
{MeshF_OnSurfDispIncr, {MeshFType_VtxBased,"MeshField_OnSurfaceDisplacementIncrement"}},
{MeshF_RotLatLonIncr, {MeshFType_VtxBased,"MeshField_RotationalLatitudeLongitudeIncreasement"}}};
{MeshF_RotLatLonIncr, {MeshFType_VtxBased,"MeshField_RotationalLatitudeLongitudeIncreasement"}},
{MeshF_VtxStrainRate, {MeshFType_VtxBased,"MeshField_StrainRate"}}};

enum mesh_type {mesh_unrecognized_lower = -1,
mesh_general_polygonal, //other meshes
Expand Down Expand Up @@ -74,6 +76,7 @@ class Mesh {
DoubleVec2dView vtxOnSurfVeloIncr_;
DoubleVec2dView vtxOnSurfDispIncr_;
DoubleVec2dView vtxRotLatLonIncr_;
DoubleSymMat3dView vtxStrainRate_;
//DoubleMat2DView vtxStress_;

public:
Expand Down Expand Up @@ -161,6 +164,9 @@ auto Mesh::getMeshField(){
else if constexpr (index==MeshF_RotLatLonIncr){
return vtxRotLatLonIncr_;
}
else if constexpr (index==MeshF_VtxStrainRate){
return vtxStrainRate_;
}
fprintf(stderr,"Mesh Field Index error!\n");
exit(1);
}
Expand Down
42 changes: 30 additions & 12 deletions test/testFortran.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ program main
integer, dimension(:), pointer :: MPElmID
real(kind=APP_RKIND), dimension(:,:), pointer :: MParray
real(kind=APP_RKIND), dimension(:,:), pointer :: MPPositions
real(kind=APP_RKIND), dimension(:,:), pointer :: Mesharray
real(kind=APP_RKIND), dimension(:,:), pointer :: mesharray_vel
real(kind=APP_RKIND), dimension(:,:), pointer :: mesharray_strainrate
real(kind=APP_RKIND), dimension(:), pointer :: xArray, yArray, zArray
integer :: ierr, self
type(c_ptr) :: mpMesh
Expand All @@ -52,10 +53,11 @@ program main
numMPs = 49 !todo use getNumMPs from the MaterialPoints object
numElms = 10

allocate(Mesharray(numCompsVel,nverts))
allocate(mesharray_vel(numCompsVel,nverts))
allocate(MParray(numCompsVel,numMPs))
allocate(MPElmID(numMPs))
allocate(MPPositions(numCompsCoords,numMPs))
allocate(mesharray_strainrate(6,nverts))
allocate(xArray(nverts))
allocate(yArray(nverts))
allocate(zArray(nverts))
Expand Down Expand Up @@ -90,25 +92,25 @@ program main
! set mesh Fields
do i = 1,numCompsVel
do j = 1,nverts
Mesharray(i,j) = (i-1)*nverts + j
mesharray_vel(i,j) = (i-1)*nverts + j
end do
end do
call polympo_setMeshOnSurfVeloIncr(mpMesh, numCompsVel, nverts, c_loc(Mesharray))
call polympo_setMeshOnSurfDispIncr(mpMesh, numCompsVel, nverts, c_loc(Mesharray))
call polympo_setMeshOnSurfVeloIncr(mpMesh, numCompsVel, nverts, c_loc(mesharray_vel))
call polympo_setMeshOnSurfDispIncr(mpMesh, numCompsVel, nverts, c_loc(mesharray_vel))

! check mesh Fields
Mesharray = -1
call polympo_getMeshOnSurfVeloIncr(mpMesh, numCompsVel, nverts, c_loc(Mesharray))
mesharray_vel = -1
call polympo_getMeshOnSurfVeloIncr(mpMesh, numCompsVel, nverts, c_loc(mesharray_vel))
do i = 1,numCompsVel
do j = 1,nverts
call assert((Mesharray(i,j) .eq. (i-1)*nverts+j), "Assert MeshOnSurfVeloIncr Fail")
call assert((mesharray_vel(i,j) .eq. (i-1)*nverts+j), "Assert MeshOnSurfVeloIncr Fail")
end do
end do
Mesharray = -1
call polympo_getMeshOnSurfDispIncr(mpMesh, numCompsVel, nverts, c_loc(Mesharray))
mesharray_vel = -1
call polympo_getMeshOnSurfDispIncr(mpMesh, numCompsVel, nverts, c_loc(mesharray_vel))
do i = 1,numCompsVel
do j = 1,nverts
call assert((Mesharray(i,j) .eq. (i-1)*nverts+j), "Assert MeshOnSurfDispIncr Fail")
call assert((mesharray_vel(i,j) .eq. (i-1)*nverts+j), "Assert MeshOnSurfDispIncr Fail")
end do
end do

Expand Down Expand Up @@ -139,12 +141,28 @@ program main
call assert((xArray(i) .eq. i+value1), "Assert MeshVel u-component Velocity Fail")
call assert((yArray(i) .eq. value2-i), "Assert MeshVel v-component Velocity Fail")
end do

!VtxStrainRate needs 6 arrays, using mesharray_strainrate to hold them
do i = 1, 6
do j = 1, nverts
mesharray_strainrate(i,j) = (i + j) * ((2 * i) + (3 * j))
end do
end do
call polympo_setMeshVtxStrainRate(mpMesh, nverts, c_loc(mesharray_strainrate))
mesharray_strainrate = -1
call polympo_getMeshVtxStrainRate(mpMesh, nverts, c_loc(mesharray_strainrate))
do i = 1, 6
do j = 1, nverts
call assert((mesharray_strainrate(i,j) .eq. (i + j) * ((2 * i) + (3 * j))), "Assert MeshVtxStrainRate Fail")
end do
end do

deallocate(MParray)
deallocate(Mesharray)
deallocate(mesharray_vel)
deallocate(xArray)
deallocate(yArray)
deallocate(zArray)
deallocate(mesharray_strainrate)

call polympo_deleteMPMesh(mpMesh)
call polympo_finalize()
Expand Down
Loading