Skip to content

Commit

Permalink
Update CMEPS to its ESCOMP/master branch 20220607 commit (#67)
Browse files Browse the repository at this point in the history
* add new flux computation for UFS model and add new coupling mode for exchange grid implementation
* fix area field for new flux algorithm
* send fluxes to atmospheric model
* initial implementation for sending fluxes to UFS ATM
* update CCPP host model
* fix latent and sensible heat fluxes and clean code
* add new coupling mode for side by side flux comparison
* fix CCPP host model for latent and sensible heat fluxes
* fix aoflux calculation on agrid and add missing error checks
* add option to write meshes and update code that retrieve area information from xgrid
* update ccpp host based on recent changes in ccpp framework
* fix for providing cell area to CCPP host model
* make ccpp physics options configurable
* Refactor nems field exchange; set default masks for mapping in med_internalstate (ESCOMP#279)
Refactors esmFldsExchange_nems.F90 to use separate advertise and initialize phases and to check that a component is present before advertising a field to or from that component. Implements default src and dst mask values in place of the code currently in med_map_mod.F90. Fixes #63 and #64.
* use mesh file instead of grid name (ESCOMP#285)
This was done so that vertical component used in grid name does not affect tests.

Co-authored-by: Dom Heinzeller <[email protected]>
Co-authored-by: Francis Vitt <[email protected]>
Co-authored-by: Courtney Peverley <[email protected]>
Co-authored-by: Jim Edwards <[email protected]>
Co-authored-by: mvertens <[email protected]>
Co-authored-by: Denise Worthen <[email protected]>
Co-authored-by: Mariana Vertenstein <[email protected]>
Co-authored-by: Ufuk Turuncoglu <[email protected]>
  • Loading branch information
9 people authored Jun 9, 2022
1 parent 763405c commit 424a086
Show file tree
Hide file tree
Showing 23 changed files with 4,419 additions and 119 deletions.
31 changes: 20 additions & 11 deletions .github/workflows/extbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ jobs:
CXX: mpicxx
CPPFLAGS: "-I/usr/include -I/usr/local/include"
# Versions of all dependencies can be updated here
ESMF_VERSION: ESMF_8_2_0_beta_snapshot_14
PNETCDF_VERSION: pnetcdf-1.12.2
ESMF_VERSION: v8.3.0b13
PNETCDF_VERSION: pnetcdf-1.12.3
NETCDF_FORTRAN_VERSION: v4.5.2
# PIO version is awkward
PIO_VERSION_DIR: pio2_5_3
PIO_VERSION: pio-2.5.3
PIO_VERSION: pio2_5_7
steps:
- uses: actions/checkout@v2
# Build the ESMF library, if the cache contains a previous build
Expand All @@ -38,12 +36,19 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install gfortran wget openmpi-bin netcdf-bin libopenmpi-dev libnetcdf-dev
- id: checkout-ESMF
uses: actions/checkout@v3
with:
repository: esmf-org/esmf
path: esmf-src
ref: ${{ env.ESMF_VERSION }}
- id: build-ESMF
if: steps.cache-esmf.outputs.cache-hit != 'true'
run: |
wget https://github.com/esmf-org/esmf/archive/${{ env.ESMF_VERSION }}.tar.gz
tar -xzvf ${{ env.ESMF_VERSION }}.tar.gz
pushd esmf-${{ env.ESMF_VERSION }}
#wget https://github.com/esmf-org/esmf/archive/${{ env.ESMF_VERSION }}.tar.gz
#tar -xzvf ${{ env.ESMF_VERSION }}.tar.gz
#pushd esmf-${{ env.ESMF_VERSION }}
pushd esmf-src
export ESMF_DIR=`pwd`
export ESMF_COMM=openmpi
export ESMF_YAMLCPP="internal"
Expand Down Expand Up @@ -95,14 +100,18 @@ jobs:
${{ runner.os }}-${{ env.NETCDF_FORTRAN_VERSION }}-netcdf-fortran
${{ runner.os }}-${{ env.PNETCDF_VERSION }}-pnetcdf
- id: checkout-PIO
uses: actions/checkout@v3
with:
repository: NCAR/ParallelIO
path: parallelio-src
ref: ${{ env.PIO_VERSION }}
- name: Build PIO
if: steps.cache-PIO.outputs.cache-hit != 'true'
run: |
wget https://github.com/NCAR/ParallelIO/releases/download/${{ env.PIO_VERSION_DIR }}/${{ env.PIO_VERSION }}.tar.gz
tar -xzvf ${{ env.PIO_VERSION }}.tar.gz
mkdir build-pio
pushd build-pio
cmake -Wno-dev -DNetCDF_C_LIBRARY=/usr/lib/x86_64-linux-gnu/libnetcdf.so -DNetCDF_C_INCLUDE_DIR=/usr/include -DCMAKE_PREFIX_PATH=/usr -DCMAKE_INSTALL_PREFIX=$HOME/pio -DPIO_HDF5_LOGGING=On -DPIO_USE_MALLOC=On -DPIO_ENABLE_TESTS=Off -DPIO_ENABLE_LOGGING=On -DPIO_ENABLE_EXAMPLES=Off -DPIO_ENABLE_TIMING=Off -DNetCDF_Fortran_PATH=$HOME/netcdf-fortran -DPnetCDF_PATH=$HOME/pnetcdf ../${{ env.PIO_VERSION }}
cmake -Wno-dev -DNetCDF_C_LIBRARY=/usr/lib/x86_64-linux-gnu/libnetcdf.so -DNetCDF_C_INCLUDE_DIR=/usr/include -DCMAKE_PREFIX_PATH=/usr -DCMAKE_INSTALL_PREFIX=$HOME/pio -DPIO_HDF5_LOGGING=On -DPIO_USE_MALLOC=On -DPIO_ENABLE_TESTS=Off -DPIO_ENABLE_LOGGING=On -DPIO_ENABLE_EXAMPLES=Off -DPIO_ENABLE_TIMING=Off -DNetCDF_Fortran_PATH=$HOME/netcdf-fortran -DPnetCDF_PATH=$HOME/pnetcdf ../parallelio-src
make VERBOSE=1
make install
popd
Expand Down
78 changes: 62 additions & 16 deletions cesm/driver/esm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,8 @@ subroutine esm_set_single_column_attributes(compname, gcomp, rc)
use netcdf, only : nf90_inq_dimid, nf90_inquire_dimension, nf90_inq_varid, nf90_get_var
use NUOPC , only : NUOPC_CompAttributeGet, NUOPC_CompAttributeSet, NUOPC_CompAttributeAdd
use ESMF , only : ESMF_GridComp, ESMF_GridCompGet, ESMF_VM, ESMF_VMGet, ESMF_SUCCESS
use ESMF , only : ESMF_Mesh, ESMF_MeshCreate, ESMF_FILEFORMAT_ESMFMESH, ESMF_MeshGet, ESMF_MESHLOC_ELEMENT
use ESMF , only : ESMF_Field, ESMF_FieldCreate, ESMF_FieldGet, ESMF_FieldRegridGetArea, ESMF_TYPEKIND_r8

! input/output variables
character(len=*) , intent(in) :: compname
Expand All @@ -1212,14 +1214,24 @@ subroutine esm_set_single_column_attributes(compname, gcomp, rc)
! local variables
type(ESMF_VM) :: vm
character(len=CL) :: single_column_lnd_domainfile
character(len=CL) :: single_column_global_meshfile
real(r8) :: scol_lon
real(r8) :: scol_lat
real(r8) :: scol_area
integer :: scol_lndmask
real(r8) :: scol_lndfrac
integer :: scol_ocnmask
real(r8) :: scol_ocnfrac
integer :: i,j,ni,nj
integer :: scol_mesh_n
type(ESMF_Mesh) :: mesh
type(ESMF_Field) :: lfield
integer :: lsize
integer :: spatialdim
real(r8), pointer :: ownedElemCoords(:)
real(r8), pointer :: latMesh(:)
real(r8), pointer :: lonMesh(:)
real(r8), pointer :: dataptr(:)
integer :: i,j,ni,nj,n
integer :: ncid
integer :: dimid
integer :: varid_xc
Expand All @@ -1243,7 +1255,6 @@ subroutine esm_set_single_column_attributes(compname, gcomp, rc)
character(len=*), parameter :: subname= ' (esm_get_single_column_attributes) '
!-------------------------------------------------------------------------------


rc = ESMF_SUCCESS

! obtain the single column lon and lat
Expand All @@ -1255,6 +1266,8 @@ subroutine esm_set_single_column_attributes(compname, gcomp, rc)
read(cvalue,*) scol_lat
call NUOPC_CompAttributeGet(gcomp, name='single_column_lnd_domainfile', value=single_column_lnd_domainfile, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeGet(gcomp, name='mesh_atm', value=single_column_global_meshfile, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeAdd(gcomp, attrList=(/'scol_spval'/), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

Expand Down Expand Up @@ -1349,6 +1362,7 @@ subroutine esm_set_single_column_attributes(compname, gcomp, rc)
do j = 1,nj
lats(j) = glob_grid(1,j)
end do

! find nearest neighbor indices of scol_lon and scol_lat in single_column_lnd_domain file
! convert lons array and scol_lon to 0,360 and find index of value closest to 0
! and obtain single-column longitude/latitude indices to retrieve
Expand Down Expand Up @@ -1388,26 +1402,53 @@ subroutine esm_set_single_column_attributes(compname, gcomp, rc)
//' ocean and land mask cannot both be zero')
end if

status = nf90_close(ncid)
if (status /= nf90_noerr) call shr_sys_abort (trim(subname) //': closing '//&
trim(single_column_lnd_domainfile))

! Now read in mesh file to get exact values of scol_lon and scol_lat that will be used
! by the models - assume that this occurs only on 1 processor
mesh = ESMF_MeshCreate(filename=trim(single_column_global_meshfile), fileformat=ESMF_FILEFORMAT_ESMFMESH, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_MeshGet(mesh, spatialDim=spatialDim, numOwnedElements=lsize, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
allocate(ownedElemCoords(spatialDim*lsize))
allocate(lonMesh(lsize), latMesh(lsize))
call ESMF_MeshGet(mesh, ownedElemCoords=ownedElemCoords)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
do n = 1,lsize
lonMesh(n) = ownedElemCoords(2*n-1)
latMesh(n) = ownedElemCoords(2*n)
if (abs(lonMesh(n) - scol_lon) < 1.e-4 .and. abs(latMesh(n) - scol_lat) < 1.e-4) then
scol_mesh_n = n
scol_mesh_n = n
exit
end if
end do
scol_lon = lonMesh(scol_mesh_n)
scol_lat = latMesh(scol_mesh_n)

! Obtain mesh info areas
lfield = ESMF_FieldCreate(mesh, ESMF_TYPEKIND_r8, name='area', meshloc=ESMF_MESHLOC_ELEMENT, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_FieldRegridGetArea(lfield, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_FieldGet(lfield, farrayPtr=dataptr, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
scol_area = dataptr(scol_mesh_n)

! Set single column attribute values for all components
write(cvalue,*) scol_lon
call NUOPC_CompAttributeSet(gcomp, name='scol_lon', value=trim(cvalue), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

write(cvalue,*) scol_lat
call NUOPC_CompAttributeSet(gcomp, name='scol_lat', value=trim(cvalue), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

write(cvalue,*) ni
call NUOPC_CompAttributeSet(gcomp, name='scol_ni', value=trim(cvalue), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

write(cvalue,*) nj
call NUOPC_CompAttributeSet(gcomp, name='scol_nj', value=trim(cvalue), rc=rc)
write(cvalue,*) scol_area
call NUOPC_CompAttributeSet(gcomp, name='scol_area', value=trim(cvalue), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

status = nf90_close(ncid)
if (status /= nf90_noerr) call shr_sys_abort (trim(subname) //': closing '//&
trim(single_column_lnd_domainfile))

! Write out diagnostic info
write(logunit,'(a,2(f13.5,2x))')trim(subname)//' nearest neighbor scol_lon and scol_lat in '&
//trim(single_column_lnd_domainfile)//' are ',scol_lon,scol_lat
if (trim(compname) == 'LND') then
Expand All @@ -1419,6 +1460,12 @@ subroutine esm_set_single_column_attributes(compname, gcomp, rc)
else
write(logunit,'(a)')trim(subname)//' atm point has unit mask and unit fraction '
end if
write(cvalue,*) ni
call NUOPC_CompAttributeSet(gcomp, name='scol_ni', value=trim(cvalue), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
write(cvalue,*) nj
call NUOPC_CompAttributeSet(gcomp, name='scol_nj', value=trim(cvalue), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

else

Expand All @@ -1431,12 +1478,11 @@ subroutine esm_set_single_column_attributes(compname, gcomp, rc)
scol_ocnfrac = 1._r8
scol_area = 1.e30

write(cvalue,*) 1
call NUOPC_CompAttributeSet(gcomp, name='scol_ni', value=trim(cvalue), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
write(cvalue,*) 1
call NUOPC_CompAttributeSet(gcomp, name='scol_nj', value=trim(cvalue), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
write(cvalue,*) 1

write(logunit,'(a)')' single point mode is active'
write(logunit,'(a,f13.5,a,f13.5,a)')' scol_lon is ',scol_lon,' and scol_lat is '
Expand Down
28 changes: 18 additions & 10 deletions cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ def _create_drv_namelists(case, infile, confdir, nmlgen, files):
config['lnd_grid'] = lnd_grid
config['ice_grid'] = ice_grid
config['ocn_grid'] = ocn_grid
config['samegrid_atm_lnd'] = 'true' if atm_grid == lnd_grid else 'false'
config['samegrid_atm_ice'] = 'true' if atm_grid == ice_grid else 'false'
config['samegrid_atm_ocn'] = 'true' if atm_grid == ocn_grid else 'false'
config['samegrid_atm_wav'] = 'true' if atm_grid == wav_grid else 'false'
config['samegrid_lnd_rof'] = 'true' if lnd_grid == rof_grid else 'false'

atm_mesh = case.get_value("ATM_DOMAIN_MESH")
lnd_mesh = case.get_value("LND_DOMAIN_MESH")
rof_mesh = case.get_value("ROF_DOMAIN_MESH")
config['samegrid_atm_lnd'] = 'true' if atm_mesh == case.get_value("LND_DOMAIN_MESH") else 'false'
config['samegrid_atm_ocn'] = 'true' if atm_mesh == case.get_value("OCN_DOMAIN_MESH") else 'false'
config['samegrid_atm_ice'] = 'true' if atm_mesh == case.get_value("ICE_DOMAIN_MESH") else 'false'
config['samegrid_atm_wav'] = 'true' if atm_mesh == case.get_value("WAV_DOMAIN_MESH") else 'false'
config['samegrid_lnd_rof'] = 'true' if lnd_mesh == rof_mesh else 'false'

# determine if need to set atm_domainfile
scol_lon = float(case.get_value('PTS_LON'))
Expand Down Expand Up @@ -102,6 +106,12 @@ def _create_drv_namelists(case, infile, confdir, nmlgen, files):
#----------------------------------------------------
nmlgen.init_defaults(infile, config, skip_default_for_groups=["modelio"])

#--------------------------------
# Overwrite: wav-ice coupling (assumes cice6 as the ice component
#--------------------------------
if (case.get_value("COMP_WAV") == 'ww3dev' and case.get_value("COMP_ICE") == 'cice'):
nmlgen.set_value('wavice_coupling', value='.true.')

#--------------------------------
# Overwrite: set brnch_retain_casename
#--------------------------------
Expand Down Expand Up @@ -307,7 +317,7 @@ def _create_drv_namelists(case, infile, confdir, nmlgen, files):
model = model.lower()
config = {}
config['component'] = model
nmlgen.init_defaults(infile, config, skip_entry_loop=True)
nmlgen.init_defaults([], config, skip_entry_loop=True)
if model == 'cpl':
newgroup = "MED_modelio"
else:
Expand Down Expand Up @@ -340,16 +350,14 @@ def _create_drv_namelists(case, infile, confdir, nmlgen, files):
nmlgen.set_value("diro", case.get_value('RUNDIR'))
if model == 'cpl':
logfile = 'med' + inst_string + ".log." + str(lid)
elif model == 'drv':
logfile = model + ".log." + str(lid)
else:
logfile = model + inst_string + ".log." + str(lid)
nmlgen.set_value("logfile", logfile)
inst_index = inst_index + 1
nmlgen.write_nuopc_config_file(conffile)





#--------------------------------
# Update nuopc.runconfig file if component needs it
#--------------------------------
Expand Down
Loading

0 comments on commit 424a086

Please sign in to comment.