Skip to content

Commit

Permalink
During Grid to Mesh, when an Array looks like a vector field, then lo…
Browse files Browse the repository at this point in the history
…ad it into the Mesh as a field with an extra dim. (The new Mesh field create and data copy code should work no matter where the undistributed dim is in the Array.)"
  • Loading branch information
oehmke committed Jul 27, 2023
1 parent eaa4889 commit a3e5be6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 25 deletions.
17 changes: 16 additions & 1 deletion src/Infrastructure/Field/tests/ESMF_FieldRegridUTest.F90
Original file line number Diff line number Diff line change
Expand Up @@ -45028,6 +45028,7 @@ subroutine test_sph_vec_blnr_csG_to_llG(rc)
real(ESMF_KIND_R8), pointer :: tmp1farrayPtr(:,:)
real(ESMF_KIND_R8), pointer :: tmp2farrayPtr(:,:)
real(ESMF_KIND_R8), pointer :: tmp3farrayPtr(:,:)
real(ESMF_KIND_R8), pointer :: dstVecfarrayPtr(:,:,:)
integer :: clbnd(2),cubnd(2)
integer :: fclbnd(3),fcubnd(3)
integer :: i1,i2,i3, index(2)
Expand Down Expand Up @@ -45411,6 +45412,13 @@ subroutine test_sph_vec_blnr_csG_to_llG(rc)
return
endif

call ESMF_FieldGet(dstVecField, lDE, dstVecfarrayPtr, rc=localrc)
if (localrc /=ESMF_SUCCESS) then
rc=ESMF_FAILURE
return
endif



!! Set Field value
do i1=fclbnd(1),fcubnd(1)
Expand Down Expand Up @@ -45441,7 +45449,14 @@ subroutine test_sph_vec_blnr_csG_to_llG(rc)
xfarrayPtr(i1,i2,2) = x*n_vec(1)+y*n_vec(2)+z*n_vec(3)

! initialize destination field
farrayPtr(i1,i2,i3)=0.0
farrayPtr(i1,i2,1)=0.0
farrayPtr(i1,i2,2)=0.0

! initialize dest vec field
dstVecfarrayPtr(i1,i2,1)=1.0
dstVecfarrayPtr(i1,i2,2)=2.0
dstVecfarrayPtr(i1,i2,3)=3.0

enddo
enddo

Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Grid/src/ESMCI_Grid.C
Original file line number Diff line number Diff line change
Expand Up @@ -8630,7 +8630,7 @@ void GridIter::getArrayVecData(
arrayInd[undistDim]=d;

// Get data
localArray->getDataInternal(curInd, data+pos);
localArray->getDataInternal(arrayInd, data+pos);

// Advance to next entry in data
pos++;
Expand Down
51 changes: 28 additions & 23 deletions src/Infrastructure/Mesh/src/ESMCI_Mesh_GToM_Glue.C
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,6 @@ void ESMCI_GridToMesh(const Grid &grid_, int staggerLoc,
"- Grid being used in Regrid call does not contain coordinates at appropriate staggerloc ", ESMC_CONTEXT, &localrc);
throw localrc;
}


for (UInt i = 0; i < arrays.size(); ++i) {

int rank=arrays[i]->getRank();


// Get array undist. dim
int undistDimCount=arrays[i]->getTensorCount();

const int *arrayToDistGridMap=arrays[i]->getArrayToDistGridMap();

printf("%d rank=%d tensorCount=%d arrayToDistGridMap=",i,rank,undistDimCount);
for (int r=0; r<rank; r++) {
printf("%d ",arrayToDistGridMap[r]);

}
printf("\n");
}



// Create Mesh
Expand Down Expand Up @@ -471,7 +451,8 @@ Par::Out() << "GID=" << gid << ", LID=" << lid << std::endl;
if ((tmp_meshFieldDim == 2) || (tmp_meshFieldDim == 3)) {
meshFieldDim=tmp_meshFieldDim;
}
printf("%d Array undist dim size=%d\n",i,meshFieldDim);
// DEBUG OUTPUT
// printf("%d Array undist dim size=%d\n",i,meshFieldDim);
}

// Register Field
Expand Down Expand Up @@ -515,10 +496,34 @@ Par::Out() << "GID=" << gid << ", LID=" << lid << std::endl;

// Other arrays
for (UInt i = 0; i < arrays.size(); ++i) {
gni->getArrayData(arrays[i], &fdata);

// Get array undist. dim
int undistDimCount=arrays[i]->getTensorCount();

// Get array info based on if looks like a vector Array
// For now a Vector Array is a field with 1 undist dim of size 2 or 3
int meshFieldDim=1; // Not a vector by default
if (undistDimCount == 1) {
const int *undistLBound=arrays[i]->getUndistLBound();
const int *undistUBound=arrays[i]->getUndistUBound();
int tmp_meshFieldDim=undistUBound[0]-undistLBound[0]+1;
if ((tmp_meshFieldDim == 2) || (tmp_meshFieldDim == 3)) {
meshFieldDim=tmp_meshFieldDim;
}
}

// Get data pointer from mesh
double *data = nfields[i]->data(*ni);
ThrowRequire(data);
data[0] = fdata;

// Get data based on the mesh field dim
if (meshFieldDim == 1) {
gni->getArrayData(arrays[i], &fdata);
data[0] = fdata;
} else {
gni->getArrayVecData(arrays[i], data);
// DEBUG OUTPUT printf("%s data=%f %f %f\n", arrays[i]->getName(),data[0],data[1],data[2]);
}
}

#ifdef G2M_DBG
Expand Down

0 comments on commit a3e5be6

Please sign in to comment.