Skip to content

Commit f525ddb

Browse files
committed
StressDivergence within Elastic Time Loop compared
1 parent cf5afec commit f525ddb

7 files changed

Lines changed: 53 additions & 27 deletions

File tree

src/pmpo_MPMesh.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ void MPMesh::calculateStrain(){
5252
v22 = v22 + MPsBasisGrads(mp, i*2 + 1) * velField(iVertex, 1);
5353
uTanOverR = uTanOverR + MPsBasis(mp, i) * tanLatVertexRotatedOverRadius(iVertex, 0) * velField(iVertex, 0);
5454
vTanOverR = vTanOverR + MPsBasis(mp, i) * tanLatVertexRotatedOverRadius(iVertex, 0) * velField(iVertex, 1);
55-
MPsStrainRate(mp, 0) = v11 - vTanOverR;
56-
MPsStrainRate(mp, 1) = v22;
57-
MPsStrainRate(mp, 2) = 0.5*(v12 + v21 + uTanOverR);
5855
//Debugging
5956
if(MPsAppID(mp)==0){
6057
printf("Strain Calc: iVertex %d vel field %.15e %.15e \n", iVertex, velField(iVertex, 0), velField(iVertex, 1));
@@ -86,7 +83,7 @@ void MPMesh::calculateStress(){
8683
if(mask){
8784

8885
Vec3d strain_rate (MPsStrainRate(mp, 0), MPsStrainRate(mp, 1), MPsStrainRate(mp, 2));
89-
Vec3d stress(MPsStress(mp, 0), MPsStress(mp, 1), MPsStress(mp, 1));
86+
Vec3d stress(MPsStress(mp, 0), MPsStress(mp, 1), MPsStress(mp, 2));
9087
constitutive_evp(strain_rate, stress, MPsIcePressure(mp, 0), MPsRepPressure(mp, 0), MPsArea(mp, 0), elasticTimeStep, dampingTimescale);
9188
for (int m=0 ; m<3; m++)
9289
MPsStress(mp, m) = stress[m];
@@ -172,26 +169,24 @@ void MPMesh::calculateStressDivergence(){
172169
};
173170
p_MPs->parallel_for(stress_div, "assembly");
174171

175-
//TODO
176-
//COMMUNICATE THE VERTEX FIELDS
172+
//TODO COMMUNICATE THE VERTEX FIELDS
177173

178-
//TODO put as mesh field
179-
Kokkos::View<vec2d_t*> stressDivergence("stressDivergence", p_mesh->getNumVertices());
174+
175+
auto stressDivergence = p_mesh->getMeshField<MeshF_StressDivergence>();
180176

181-
Kokkos::parallel_for("calculate_divergence", numVtx, KOKKOS_LAMBDA(const int vtx){
182-
177+
Kokkos::parallel_for("calculate_divergence", numVtx, KOKKOS_LAMBDA(const int vtx){
183178
stressDivergence(vtx, 0) = stress_divU(vtx);
184179
stressDivergence(vtx, 1) = stress_divV(vtx);
185180
//Debugging
186181
if (vtx >= 10 && vtx <= 11) {
187-
printf("Vtx %d Divergence %.15e %.15e %.15e %.15e %.15e %.15e \n", vtx, nearAnEdge_l(vtx), vtxMatrixMass_l(vtx),
188-
stress_divU(vtx), stress_divV(vtx),
189-
divU_edge(vtx), divV_edge(vtx));
182+
//printf("Vtx %d Divergence %.15e %.15e %.15e %.15e %.15e %.15e \n", vtx, nearAnEdge_l(vtx), vtxMatrixMass_l(vtx),
183+
// stress_divU(vtx), stress_divV(vtx),
184+
// divU_edge(vtx), divV_edge(vtx));
185+
printf("Vtx %d Divergence %.15e %.15e \n", vtx, stressDivergence(vtx, 0), stressDivergence(vtx, 1));
190186
}
191187
});
192-
193-
//TODO
194-
//COMMUNICATE THE VERTEX FIELDS
188+
189+
//TODO COMMUNICATE THE VERTEX FIELDS
195190

196191
}
197192

src/pmpo_MPMesh_assembly.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,6 @@ void MPMesh::assemblyVtx1(){
382382
if(numProcsTot>1)
383383
communicate_and_take_halo_contributions(meshField, numVertices, numEntries, 0, 0);
384384
pumipic::RecordTime("Communicate Field Values" + std::to_string(self), timer.seconds());
385-
386-
Kokkos::parallel_for("printSymmetricBlock", numVertices, KOKKOS_LAMBDA(const int vtx){
387-
if (vtx >= 10 && vtx <= 10) {
388-
printf("Field in %d: ", vtx);
389-
for (int k=0; k<numEntries; k++)
390-
printf(" %.15e ", meshField(vtx, k));
391-
printf("\n");
392-
}
393-
});
394385
}
395386

396387
//Start Communication routine

src/pmpo_c.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,24 @@ void polympo_calculateStressDivergence_f(MPMesh_ptr p_mpmesh){
13491349
((polyMPO::MPMesh*)p_mpmesh) -> calculateStressDivergence();
13501350
}
13511351

1352+
void polympo_getStressDivergence_f(MPMesh_ptr p_mpmesh, const int nVertices, double* uArray, double* vArray){
1353+
//chech validity
1354+
checkMPMeshValid(p_mpmesh);
1355+
auto p_mesh = ((polyMPO::MPMesh*)p_mpmesh)->p_mesh;
1356+
1357+
//check the size
1358+
PMT_ALWAYS_ASSERT(p_mesh->getNumVertices()==nVertices);
1359+
1360+
//copy the device to host
1361+
auto stressDivergence = p_mesh->getMeshField<polyMPO::MeshF_StressDivergence>();
1362+
auto h_stressDivergence = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), stressDivergence);
1363+
for(int i=0; i<nVertices; i++){
1364+
uArray[i] = h_stressDivergence(i,0);
1365+
vArray[i] = h_stressDivergence(i,1);
1366+
}
1367+
}
1368+
1369+
13521370
//Advection Calcualtions
13531371
void polympo_push_f(MPMesh_ptr p_mpmesh){
13541372
checkMPMeshValid(p_mpmesh);

src/pmpo_c.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ void polympo_setElasticTimeStep_f(MPMesh_ptr p_mpmesh, const double elasticTimeS
103103
void polympo_setDynamicTimeStep_f(MPMesh_ptr p_mpmesh, const double dynamicTimeStep);
104104
void polympo_setSolveStressMesh_f(MPMesh_ptr p_mpmesh, const int nCells, int* array);
105105
void polympo_calculateStressDivergence_f(MPMesh_ptr p_mpmesh);
106+
void polympo_getStressDivergence_f(MPMesh_ptr p_mpmesh, const int nVertices, double* uArray, double* vArray);
107+
106108

107109
// Advection calculations
108110
void polympo_push_f(MPMesh_ptr p_mpmesh);

src/pmpo_fortran.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,15 @@ subroutine polympo_calculateStressDivergence(mpMesh) &
966966
type(c_ptr), value :: mpMesh
967967
end subroutine
968968

969+
subroutine polympo_getStressDivergence(mpMesh, nVertices, uArray, vArray) &
970+
bind(C, NAME='polympo_getStressDivergence_f')
971+
use :: iso_c_binding
972+
type(c_ptr), value :: mpMesh
973+
integer(c_int), value :: nVertices
974+
type(c_ptr), value :: uArray, vArray
975+
end subroutine
976+
977+
969978
!---------------------------------------------------------------------------
970979
!> @brief calculate the MPs from given mesh vertices rotational latitude
971980
!> longitude, update the MP slices

src/pmpo_mesh.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ namespace polyMPO{
5151
auto interiorVertexEntry = meshFields2TypeAndString.at(MeshF_InteriorVertex);
5252
PMT_ALWAYS_ASSERT(interiorVertexEntry.first == MeshFType_VtxBased);
5353
interiorVertex_ = MeshFView<MeshF_InteriorVertex>(interiorVertexEntry.second, numVtxs_);
54+
55+
auto stressDivergenceEntry = meshFields2TypeAndString.at(MeshF_StressDivergence);
56+
PMT_ALWAYS_ASSERT(stressDivergenceEntry.first == MeshFType_VtxBased);
57+
stressDivergence_ = MeshFView<MeshF_StressDivergence>(stressDivergenceEntry.second, numVtxs_);
5458
}
5559

5660
void Mesh::setMeshElmBasedFieldSize(){

src/pmpo_mesh.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ enum MeshFieldIndex{
3131
MeshF_ElmCenterGnomProj,
3232
MeshF_TanLatVertexRotatedOverRadius,
3333
MeshF_SolveStress,
34-
MeshF_InteriorVertex
34+
MeshF_InteriorVertex,
35+
MeshF_StressDivergence
3536
};
3637
enum MeshFieldType{
3738
MeshFType_Invalid = -2,
@@ -56,6 +57,7 @@ template <> struct meshFieldToType < MeshF_ElmCenterGnomProj > { using type = Ko
5657
template <> struct meshFieldToType < MeshF_TanLatVertexRotatedOverRadius > { using type = Kokkos::View<doubleSclr_t*>; };
5758
template <> struct meshFieldToType < MeshF_SolveStress > { using type = IntView; };
5859
template <> struct meshFieldToType < MeshF_InteriorVertex > { using type = IntView; };
60+
template <> struct meshFieldToType < MeshF_StressDivergence > { using type = Kokkos::View<vec2d_t*>; };
5961

6062
template <MeshFieldIndex index>
6163
using MeshFView = typename meshFieldToType<index>::type;
@@ -77,7 +79,8 @@ const std::map<MeshFieldIndex, std::pair<MeshFieldType, std::string>> meshFields
7779
{MeshF_ElmCenterGnomProj,{MeshFType_ElmBased,"MeshField_ElementCenterGnomonicprojection"}},
7880
{MeshF_TanLatVertexRotatedOverRadius, {MeshFType_VtxBased,"MeshField_TanLatVertexRotatedOverRadius"}},
7981
{MeshF_SolveStress, {MeshFType_ElmBased,"MeshField_SolveStress"}},
80-
{MeshF_InteriorVertex, {MeshFType_VtxBased,"MeshField_InteriorVertex"}}
82+
{MeshF_InteriorVertex, {MeshFType_VtxBased,"MeshField_InteriorVertex"}},
83+
{MeshF_StressDivergence, {MeshFType_VtxBased,"MeshField_StressDivergence"}},
8184
};
8285

8386
enum mesh_type {mesh_unrecognized_lower = -1,
@@ -111,6 +114,7 @@ class Mesh {
111114
MeshFView<MeshF_VtxRotLat> vtxRotLat_;
112115
MeshFView<MeshF_ElmCenterXYZ> elmCenterXYZ_;
113116
MeshFView<MeshF_DualTriangleArea> dualTriangleArea_;
117+
MeshFView<MeshF_StressDivergence> stressDivergence_;
114118
MeshFView<MeshF_Vel> vtxVel_;
115119
MeshFView<MeshF_VtxMass> vtxMass_;
116120
MeshFView<MeshF_ElmMass> elmMass_;
@@ -281,6 +285,9 @@ auto Mesh::getMeshField(){
281285
else if constexpr (index==MeshF_InteriorVertex){
282286
return interiorVertex_;
283287
}
288+
else if constexpr (index==MeshF_StressDivergence){
289+
return stressDivergence_;
290+
}
284291
fprintf(stderr,"Mesh Field Index error!\n");
285292
exit(1);
286293
}

0 commit comments

Comments
 (0)