Skip to content

Commit 7e41847

Browse files
committed
Merge in new flag to select method for calculating cubed sphere coords.
Merge branch 'add_cs_coord_option_flag' into develop
2 parents 8af94f2 + d5b2497 commit 7e41847

File tree

4 files changed

+172
-22
lines changed

4 files changed

+172
-22
lines changed

src/Infrastructure/Grid/interface/ESMF_Grid.F90

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14615,10 +14615,11 @@ end function ESMF_GridCreateShapeTileArb
1461514615
! !INTERFACE:
1461614616
! Private name; call using ESMF_GridCreateCubedSphere()
1461714617
function ESMF_GridCreateCubedSphereReg(tileSize,keywordEnforcer, &
14618-
regDecompPTile, decompflagPTile, &
14619-
coordSys, coordTypeKind, &
14620-
deLabelList, staggerLocList, &
14621-
delayout, indexflag, name, transformArgs, rc)
14618+
regDecompPTile, decompflagPTile, &
14619+
coordSys, coordTypeKind, &
14620+
deLabelList, staggerLocList, &
14621+
delayout, indexflag, name, transformArgs, coordCalcFlag, &
14622+
rc)
1462214623
!
1462314624
! !RETURN VALUE:
1462414625
type(ESMF_Grid) :: ESMF_GridCreateCubedSphereReg
@@ -14636,6 +14637,7 @@ function ESMF_GridCreateCubedSphereReg(tileSize,keywordEnforcer, &
1463614637
type(ESMF_Index_Flag), intent(in), optional :: indexflag
1463714638
character(len=*), intent(in), optional :: name
1463814639
type(ESMF_CubedSphereTransform_Args), intent(in), optional :: transformArgs
14640+
type(ESMF_CubedSphereCalc_Flag),intent(in), optional :: coordCalcFlag
1463914641
integer, intent(out), optional :: rc
1464014642

1464114643
!
@@ -14693,14 +14695,19 @@ function ESMF_GridCreateCubedSphereReg(tileSize,keywordEnforcer, &
1469314695
! {\tt regDecompPTile} will be constructed accordingly.
1469414696
! \item[{[indexflag]}]
1469514697
! Indicates the indexing scheme to be used in the new Grid. Please see
14696-
! Section~\ref{const:indexflag} for the list of options. If not present,
14698+
! section~\ref{const:indexflag} for the list of options. If not present,
1469714699
! defaults to ESMF\_INDEX\_DELOCAL.
1469814700
! \item[{[name]}]
1469914701
! {\tt ESMF\_Grid} name.
1470014702
! \item[{[transformArgs]}]
1470114703
! A data type containing the stretch factor, target longitude, and target latitude
14702-
! to perform a Schmidt transformation on the Cubed-Sphere grid. See section
14704+
! to perform a Schmidt transformation on the Cubed-Sphere grid.
1470314705
! \ref{sec:usage:cubedspherewttransform} for details.
14706+
! \item[{[coordCalcFlag]}]
14707+
! A flag which controls the method used to calculate the cubed sphere coordinates.
14708+
! Please see section~\ref{const:cubedspherecalcflag} for a list of options. If not set,
14709+
! defaults to {\tt ESMF\_CUBEDSPHERECALC\_1TILE} which was the original method used
14710+
! to calculate coordinates.
1470414711
! \item[{[rc]}]
1470514712
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
1470614713
! \end{description}
@@ -14734,10 +14741,13 @@ function ESMF_GridCreateCubedSphereReg(tileSize,keywordEnforcer, &
1473414741
type(ESMF_Index_Flag) :: localIndexFlag
1473514742
type(ESMF_CoordSys_Flag) :: coordSysLocal
1473614743
type(ESMF_TypeKind_Flag) :: coordTypeKindLocal
14744+
type(ESMF_CubedSphereCalc_Flag) :: coordCalcFlagLocal
1473714745
integer :: s
1473814746
logical :: docenter, docorner
14747+
logical :: local_algorithm
1473914748
!real(ESMF_KIND_R8) :: starttime, endtime
1474014749

14750+
1474114751
if (present(rc)) rc=ESMF_SUCCESS
1474214752
!------------------------------------------------------------------------
1474314753
! get global vm information
@@ -14819,7 +14829,11 @@ function ESMF_GridCreateCubedSphereReg(tileSize,keywordEnforcer, &
1481914829
else
1482014830
coordTypeKindLocal=ESMF_TYPEKIND_R8
1482114831
endif
14822-
14832+
14833+
! Set default coord. calc. flag
14834+
coordCalcFlagLocal=ESMF_CUBEDSPHERECALC_1TILE
14835+
if (present(coordCalcFlag)) coordCalcFlagLocal= coordCalcFlag
14836+
1482314837
! set defaults
1482414838
docenter = .false.
1482514839
docorner = .false.
@@ -14977,22 +14991,26 @@ function ESMF_GridCreateCubedSphereReg(tileSize,keywordEnforcer, &
1497714991
endif
1497814992
endif
1497914993
!call ESMF_VMWtime(starttime, rc=localrc)
14980-
! Generate glocal edge coordinates and local center coordinates
1498114994

14995+
! Set coordinate calc method balop's[ed on flag (by setting local_algorithm switch)
14996+
local_algorithm=.false.
14997+
if (coordCalcFlagLocal == ESMF_CUBEDSPHERECALC_LOCAL) local_algorithm=.true.
14998+
14999+
! Generate glocal edge coordinates and local center coordinates
1498215000
if (docenter .and. docorner) then
1498315001
call ESMF_UtilCreateCSCoordsPar(tileSize, lonEdge=lonCornerPtrR8, &
1498415002
latEdge=latCornerPtrR8, start=start, count=count, &
1498515003
tile=tile, lonCenter=lonPtrR8, latCenter=latPtrR8, &
14986-
schmidtTransform=transformArgs)
15004+
schmidtTransform=transformArgs, local_algorithm=local_algorithm)
1498715005
elseif (docorner) then
1498815006
call ESMF_UtilCreateCSCoordsPar(tileSize, lonEdge=lonCornerPtrR8, &
1498915007
latEdge=latCornerPtrR8, start=start, count=count, tile=tile, &
14990-
schmidtTransform=transformArgs)
15008+
schmidtTransform=transformArgs, local_algorithm=local_algorithm)
1499115009
else
1499215010
call ESMF_UtilCreateCSCoordsPar(tileSize, &
1499315011
start=start, count=count, &
1499415012
tile=tile, lonCenter=lonPtrR8, latCenter=latPtrR8, &
14995-
schmidtTransform=transformArgs)
15013+
schmidtTransform=transformArgs, local_algorithm=local_algorithm)
1499615014
endif
1499715015

1499815016
!call ESMF_VMWtime(endtime, rc=localrc)
@@ -15084,12 +15102,13 @@ end function ESMF_GridCreateCubedSphereReg
1508415102

1508515103
! !INTERFACE:
1508615104
! Private name; call using ESMF_GridCreateCubedSphere()
15087-
function ESMF_GridCreateCubedSphereIReg(tileSize, &
15088-
countsPerDEDim1PTile, countsPerDEDim2PTile, &
15089-
keywordEnforcer, &
15090-
coordSys, coordTypeKind, &
15091-
deLabelList, staggerLocList, &
15092-
delayout, indexflag, name, transformArgs, rc)
15105+
function ESMF_GridCreateCubedSphereIReg(tileSize, &
15106+
countsPerDEDim1PTile, countsPerDEDim2PTile, &
15107+
keywordEnforcer, &
15108+
coordSys, coordTypeKind, &
15109+
deLabelList, staggerLocList, &
15110+
delayout, indexflag, name, transformArgs, coordCalcFlag, &
15111+
rc)
1509315112
!
1509415113
! !RETURN VALUE:
1509515114
type(ESMF_Grid) :: ESMF_GridCreateCubedSphereIReg
@@ -15107,6 +15126,7 @@ function ESMF_GridCreateCubedSphereIReg(tileSize, &
1510715126
type(ESMF_Index_Flag), intent(in), optional :: indexflag
1510815127
character(len=*), intent(in), optional :: name
1510915128
type(ESMF_CubedSphereTransform_Args), intent(in), optional :: transformArgs
15129+
type(ESMF_CubedSphereCalc_Flag),intent(in), optional :: coordCalcFlag
1511015130
integer, intent(out), optional :: rc
1511115131

1511215132
!
@@ -15160,6 +15180,11 @@ function ESMF_GridCreateCubedSphereIReg(tileSize, &
1516015180
! A data type containing the stretch factor, target longitude, and target latitude
1516115181
! to perform a Schmidt transformation on the Cubed-Sphere grid. See section
1516215182
! \ref{sec:usage:cubedspherewttransform} for details.
15183+
! \item[{[coordCalcFlag]}]
15184+
! A flag which controls the method used to calculate the cubed sphere coordinates.
15185+
! Please see section~\ref{const:cubedspherecalcflag} for a list of options. If not set,
15186+
! defaults to {\tt ESMF\_CUBEDSPHERECALC\_1TILE} which was the original method used
15187+
! to calculate coordinates.
1516315188
! \item[{[rc]}]
1516415189
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
1516515190
! \end{description}
@@ -15189,13 +15214,15 @@ function ESMF_GridCreateCubedSphereIReg(tileSize, &
1518915214
type(ESMF_Index_Flag) :: localIndexFlag
1519015215
type(ESMF_CoordSys_Flag) :: coordSysLocal
1519115216
type(ESMF_TypeKind_Flag) :: coordTypeKindLocal
15217+
type(ESMF_CubedSphereCalc_Flag) :: coordCalcFlagLocal
1519215218
integer :: s
1519315219
logical :: docenter, docorner
1519415220
integer, pointer :: deBlockList(:,:,:), deToTileMap(:)
1519515221
integer, pointer :: DeDim1(:), DeDim2(:), demap(:)
1519615222
integer :: k,t, minIndx, minIndy
1519715223
integer :: myde, startde, endde
1519815224
integer :: tiles, totalelmt
15225+
logical :: local_algorithm
1519915226
!real(ESMF_KIND_R8) :: starttime, endtime
1520015227

1520115228
if (present(rc)) rc=ESMF_SUCCESS
@@ -15320,6 +15347,11 @@ function ESMF_GridCreateCubedSphereIReg(tileSize, &
1532015347
coordTypeKindLocal=ESMF_TYPEKIND_R8
1532115348
endif
1532215349

15350+
! Set default coord. calc. flag
15351+
coordCalcFlagLocal=ESMF_CUBEDSPHERECALC_1TILE
15352+
if (present(coordCalcFlag)) coordCalcFlagLocal= coordCalcFlag
15353+
15354+
1532315355
! set defaults
1532415356
docenter = .false.
1532515357
docorner = .false.
@@ -15458,22 +15490,26 @@ function ESMF_GridCreateCubedSphereIReg(tileSize, &
1545815490
endif
1545915491
endif
1546015492
!call ESMF_VMWtime(starttime, rc=localrc)
15461-
! Generate glocal edge coordinates and local center coordinates
1546215493

15494+
! Set coordinate calc method balop's[ed on flag (by setting local_algorithm switch)
15495+
local_algorithm=.false.
15496+
if (coordCalcFlagLocal == ESMF_CUBEDSPHERECALC_LOCAL) local_algorithm=.true.
15497+
15498+
! Generate glocal edge coordinates and local center coordinates
1546315499
if (docenter .and. docorner) then
1546415500
call ESMF_UtilCreateCSCoordsPar(tileSize, lonEdge=lonCornerPtrR8, &
1546515501
latEdge=latCornerPtrR8, start=start, count=count, &
1546615502
tile=tile, lonCenter=lonPtrR8, latCenter=latPtrR8, &
15467-
schmidtTransform=transformArgs)
15503+
schmidtTransform=transformArgs, local_algorithm=local_algorithm)
1546815504
elseif (docorner) then
1546915505
call ESMF_UtilCreateCSCoordsPar(tileSize, lonEdge=lonCornerPtrR8, &
1547015506
latEdge=latCornerPtrR8, start=start, count=count, tile=tile, &
15471-
schmidtTransform=transformArgs)
15507+
schmidtTransform=transformArgs, local_algorithm=local_algorithm)
1547215508
else
1547315509
call ESMF_UtilCreateCSCoordsPar(tileSize, &
1547415510
start=start, count=count, &
1547515511
tile=tile, lonCenter=lonPtrR8, latCenter=latPtrR8, &
15476-
schmidtTransform=transformArgs)
15512+
schmidtTransform=transformArgs, local_algorithm=local_algorithm)
1547715513
endif
1547815514

1547915515
!call ESMF_VMWtime(endtime, rc=localrc)

src/Infrastructure/Grid/tests/ESMF_GridCreateUTest.F90

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2871,7 +2871,7 @@ program ESMF_GridCreateUTest
28712871

28722872
call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
28732873
!-----------------------------------------------------------------------------
2874-
2874+
28752875
!-----------------------------------------------------------------------------
28762876
!NEX_UTest
28772877
write(name, *) "Testing GridCreateCubedSphere with SchmidtTransform"
@@ -3313,6 +3313,59 @@ program ESMF_GridCreateUTest
33133313
call ESMF_Test(((rc.eq.ESMF_SUCCESS) .and. correct), name, failMsg, result, ESMF_SRCLINE)
33143314

33153315

3316+
!-----------------------------------------------------------------------------
3317+
!NEX_UTest
3318+
write(name, *) "Testing GridCreateCubedSphere with calcCoordType=ESMF_CUBEDSPHERECALC_LOCAL"
3319+
write(failMsg, *) "Incorrect result"
3320+
3321+
! create grid
3322+
rc=ESMF_SUCCESS
3323+
grid=ESMF_GridCreateCubedSphere(15, &
3324+
staggerLocList = (/ESMF_STAGGERLOC_CENTER, ESMF_STAGGERLOC_CORNER/), &
3325+
coordCalcFlag=ESMF_CUBEDSPHERECALC_LOCAL, rc=localrc)
3326+
if (localrc .ne. ESMF_SUCCESS) rc=ESMF_FAILURE
3327+
3328+
3329+
! Write to make sure it looks ok
3330+
call ESMF_GridCellWriteVTK(grid, "csGrid", rc=localrc)
3331+
if (localrc .ne. ESMF_SUCCESS) rc=ESMF_FAILURE
3332+
3333+
! Loop through just making sure coordinates are there
3334+
call ESMF_GridGet(grid, localDECount=localDECount, rc=localrc)
3335+
if (localrc .ne. ESMF_SUCCESS) rc=ESMF_FAILURE
3336+
3337+
do lde = 0, localDECount-1
3338+
3339+
call ESMF_GridGetCoord(grid, coordDim=1, localDE=lde, farrayPtr=fptr1, &
3340+
exclusiveLBound=exlbnd, exclusiveUBound=exubnd, rc=localrc)
3341+
if (localrc .ne. ESMF_SUCCESS) rc=ESMF_FAILURE
3342+
call ESMF_GridGetCoord(grid, coordDim=2, localDE=lde, farrayPtr=fptr2, &
3343+
exclusiveLBound=exlbnd, exclusiveUBound=exubnd, rc=localrc)
3344+
if (localrc .ne. ESMF_SUCCESS) rc=ESMF_FAILURE
3345+
3346+
#if 0
3347+
print *, "coords from de", lde
3348+
3349+
print *, "lower bounds = [", exlbnd(1), ", ", exlbnd(2), "]"
3350+
print *, "upper bounds = [", exubnd(1), ", ", exubnd(2), "]"
3351+
3352+
print *, "["
3353+
do j = 1, exubnd(1)
3354+
do i = 1, exubnd(2)
3355+
print *, "[", fptr1(i,j), ", ", fptr2(i,j), "]"
3356+
enddo
3357+
enddo
3358+
print *, "]"
3359+
#endif
3360+
enddo
3361+
3362+
! destroy grid
3363+
call ESMF_GridDestroy(grid, rc=localrc)
3364+
if (localrc .ne. ESMF_SUCCESS) rc=ESMF_FAILURE
3365+
3366+
call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
3367+
!-----------------------------------------------------------------------------
3368+
33163369
!-----------------------------------------------------------------------------
33173370
! Stop testing
33183371
call ESMF_TestEnd(ESMF_SRCLINE)

src/Infrastructure/Util/src/ESMF_UtilTypes.F90

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,20 @@ module ESMF_UtilTypesMod
781781
ESMF_EXTRAPMETHOD_CREEP_NRST_D = ESMF_ExtrapMethod_Flag(5)
782782

783783

784+
!------------------------------------------------------------------------------
785+
type ESMF_CubedSphereCalc_Flag
786+
#ifndef ESMF_NO_SEQUENCE
787+
sequence
788+
#endif
789+
! private
790+
integer :: cubedspherecalc
791+
end type
792+
793+
794+
type(ESMF_CubedSphereCalc_Flag), parameter :: &
795+
ESMF_CUBEDSPHERECALC_1TILE = ESMF_CubedSphereCalc_Flag(1), &
796+
ESMF_CUBEDSPHERECALC_LOCAL = ESMF_CubedSphereCalc_Flag(2)
797+
784798
!------------------------------------------------------------------------------
785799
type ESMF_LineType_Flag
786800
#ifndef ESMF_NO_SEQUENCE
@@ -1155,6 +1169,11 @@ module ESMF_UtilTypesMod
11551169
ESMF_EXTRAPMETHOD_CREEP, &
11561170
ESMF_EXTRAPMETHOD_CREEP_NRST_D
11571171

1172+
public ESMF_CubedSphereCalc_Flag, &
1173+
ESMF_CUBEDSPHERECALC_1TILE, &
1174+
ESMF_CUBEDSPHERECALC_LOCAL
1175+
1176+
11581177
public ESMF_LineType_Flag, &
11591178
ESMF_LINETYPE_CART, &
11601179
ESMF_LINETYPE_GREAT_CIRCLE
@@ -1295,6 +1314,7 @@ module ESMF_UtilTypesMod
12951314
module procedure ESMF_FileStatusEq
12961315
module procedure ESMF_RegridMethodEq
12971316
module procedure ESMF_ExtrapMethodEq
1317+
module procedure ESMF_CubedSphereCalcEq
12981318
module procedure ESMF_CoordSysEqual
12991319
module procedure ESMF_LineTypeEqual
13001320
module procedure ESMF_NormTypeEqual
@@ -1320,6 +1340,7 @@ module ESMF_UtilTypesMod
13201340
module procedure ESMF_FileStatusNe
13211341
module procedure ESMF_RegridMethodNe
13221342
module procedure ESMF_ExtrapMethodNe
1343+
module procedure ESMF_CubedSphereCalcNe
13231344
module procedure ESMF_CoordSysNotEqual
13241345
module procedure ESMF_LineTypeNotEqual
13251346
module procedure ESMF_NormTypeNotEqual
@@ -2029,6 +2050,23 @@ impure elemental function ESMF_RegridMethodNe(rp1, rp2)
20292050
ESMF_RegridMethodNe = (rp1%regridmethod /= rp2%regridmethod)
20302051
end function
20312052

2053+
!------------------------------------------------------------------------------
2054+
! function to compare two ESMF_CubedSphereCalc types
2055+
2056+
impure elemental function ESMF_CubedSphereCalcEq(csc1, csc2)
2057+
logical ESMF_CubedSphereCalcEq
2058+
type(ESMF_CubedSphereCalc_Flag), intent(in) :: csc1, csc2
2059+
2060+
ESMF_CubedSphereCalcEq = (csc1%cubedspherecalc == csc2%cubedspherecalc)
2061+
end function
2062+
2063+
impure elemental function ESMF_CubedSphereCalcNe(csc1, csc2)
2064+
logical ESMF_CubedSphereCalcNe
2065+
type(ESMF_CubedSphereCalc_Flag), intent(in) :: csc1, csc2
2066+
2067+
ESMF_CubedSphereCalcNe = (csc1%cubedspherecalc /= csc2%cubedspherecalc)
2068+
end function
2069+
20322070
!------------------------------------------------------------------------------
20332071
! function to compare two ESMF_ExtrapMethod types
20342072

src/doc/ESMF_options.tex

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,29 @@ \subsection{ESMF\_COORDSYS}
133133

134134
\end{description}
135135

136+
\subsection{ESMF\_CUBEDSPHERECALC}
137+
\label{const:cubedspherecalcflag}
138+
{\sf DESCRIPTION:\\}
139+
Indicates the method used to calculate coordinates during cubed sphere creation.
140+
141+
The type of this flag is:
142+
143+
{\tt type(ESMF\_CubedSphereCalc\_Flag)}
144+
145+
The valid values are:
146+
\begin{description}
147+
148+
\item [ESMF\_CUBEDSPHERECALC\_1TILE:]
149+
This is the original method used to calculate coordinates for the ESMF cubed sphere. It uses
150+
an array the size of one tile of the cubed sphere on each PET to calculate coordinates
151+
and ensure their symmetry.
152+
\item [ESMF\_CUBEDSPHERECALC\_LOCAL:]
153+
This method just uses an array large enough to hold the local cubed sphere coordinates on each PET.
154+
It relies on careful design of loops and calculation to ensure symmetry of the coordinates. This
155+
method will in general use less memory than ESMF\_CUBEDSPHERECALC\_1TILE.
156+
\end{description}
157+
158+
136159
\subsection{ESMF\_DATACOPY}
137160
\label{const:datacopyflag}
138161
{\sf DESCRIPTION:\\}

0 commit comments

Comments
 (0)