Skip to content

Commit a36cb73

Browse files
authored
Merge pull request #122 from jiandewang/feature/update-NCAR-GMAO-20231031
update MOM6 to its main repo 20231025 (NCAR candidate) and 20231031(GMAO FMS_cap) updating
2 parents 02d4dc4 + 80a93f6 commit a36cb73

37 files changed

+2087
-733
lines changed

.github/workflows/coupled-api.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,3 @@ jobs:
2828
- name: Compile MOM6 for the NUOPC driver
2929
shell: bash
3030
run: make check_mom6_api_nuopc -j
31-
32-
- name: Compile MOM6 for the MCT driver
33-
shell: bash
34-
run: make check_mom6_api_mct -j

.readthedocs.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
# Read the Docs configuration file for Sphinx projects
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
15
version: 2
26

7+
build:
8+
os: ubuntu-22.04
9+
tools:
10+
python: "3.11"
11+
312
# Extra formats
413
# PDF generation is failing for now; disabled on 2020-12-02
514
#formats:
@@ -10,7 +19,5 @@ sphinx:
1019
configuration: docs/conf.py
1120

1221
python:
13-
# make sure we're using Python 3
14-
version: 3
1522
install:
1623
- requirements: docs/requirements.txt

.testing/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ build/opt/Makefile: MOM_ENV=$(PATH_FMS) $(OPT_FCFLAGS) $(MOM_LDFLAGS)
255255
build/opt_target/Makefile: MOM_ENV=$(PATH_FMS) $(OPT_FCFLAGS) $(MOM_LDFLAGS)
256256
build/coupled/Makefile: MOM_ENV=$(PATH_FMS) $(SYMMETRIC_FCFLAGS) $(MOM_LDFLAGS)
257257
build/nuopc/Makefile: MOM_ENV=$(PATH_FMS) $(SYMMETRIC_FCFLAGS) $(MOM_LDFLAGS)
258-
build/mct/Makefile: MOM_ENV=$(PATH_FMS) $(SYMMETRIC_FCFLAGS) $(MOM_LDFLAGS)
259258
build/cov/Makefile: MOM_ENV=$(PATH_FMS) $(COV_FCFLAGS) $(COV_LDFLAGS)
260259
build/unit/Makefile: MOM_ENV=$(PATH_FMS) $(COV_FCFLAGS) $(COV_LDFLAGS)
261260

@@ -269,7 +268,6 @@ build/opt/Makefile: MOM_ACFLAGS=
269268
build/opt_target/Makefile: MOM_ACFLAGS=
270269
build/coupled/Makefile: MOM_ACFLAGS=--with-driver=FMS_cap
271270
build/nuopc/Makefile: MOM_ACFLAGS=--with-driver=nuopc_cap
272-
build/mct/Makefile: MOM_ACFLAGS=--with-driver=mct_cap
273271
build/cov/Makefile: MOM_ACFLAGS=
274272
build/unit/Makefile: MOM_ACFLAGS=--with-driver=unit_tests
275273

@@ -370,11 +368,6 @@ build/coupled/ocean_model_MOM.o: build/coupled/Makefile
370368
cd $(@D) && make $(@F)
371369
check_mom6_api_coupled: build/coupled/ocean_model_MOM.o
372370

373-
# MCT driver
374-
build/mct/mom_ocean_model_mct.o: build/mct/Makefile
375-
cd $(@D) && make $(@F)
376-
check_mom6_api_mct: build/mct/mom_ocean_model_mct.o
377-
378371

379372
#---
380373
# Testing

config_src/drivers/FMS_cap/ocean_model_MOM.F90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,14 @@ subroutine ocean_model_get_UV_surf(OS, Ocean, name, array2D, isc, jsc)
12011201
array2D(i,j) = G%mask2dBu(I+i0,J+j0) * &
12021202
0.5*(sfc_state%v(i+i0,J+j0)+sfc_state%v(i+i0+1,J+j0))
12031203
enddo ; enddo
1204+
case('uc')
1205+
do j=jsc_bnd,jec_bnd ; do i=isc_bnd,iec_bnd
1206+
array2D(i,j) = G%mask2dCu(I+i0,J+j0) * sfc_state%u(I+i0,j+j0)
1207+
enddo ; enddo
1208+
case('vc')
1209+
do j=jsc_bnd,jec_bnd ; do i=isc_bnd,iec_bnd
1210+
array2D(i,j) = G%mask2dCv(I+i0,J+j0) * sfc_state%v(i+i0,J+j0)
1211+
enddo ; enddo
12041212
case default
12051213
call MOM_error(FATAL,'ocean_model_get_UV_surf: unknown argument name='//name)
12061214
end select

config_src/drivers/nuopc_cap/mom_cap.F90

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ module MOM_cap_mod
2828
use MOM_cap_methods, only: mom_import, mom_export, mom_set_geomtype, mod2med_areacor
2929
use MOM_cap_methods, only: med2mod_areacor, state_diagnose
3030
use MOM_cap_methods, only: ChkErr
31+
use MOM_ensemble_manager, only: ensemble_manager_init
3132

3233
#ifdef CESMCOUPLED
3334
use shr_log_mod, only: shr_log_setLogUnit
35+
use nuopc_shr_methods, only: get_component_instance
3436
#endif
3537
use time_utils_mod, only: esmf2fms_time
3638

@@ -147,7 +149,8 @@ module MOM_cap_mod
147149
logical :: cesm_coupled = .false.
148150
type(ESMF_GeomType_Flag) :: geomtype
149151
#endif
150-
character(len=8) :: restart_mode = 'alarms'
152+
character(len=8) :: restart_mode = 'alarms'
153+
character(len=16) :: inst_suffix = ''
151154
real(8) :: timere
152155

153156
contains
@@ -434,6 +437,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
434437
! (same as restartfile if single restart file)
435438
character(len=*), parameter :: subname='(MOM_cap:InitializeAdvertise)'
436439
character(len=32) :: calendar
440+
character(len=:), allocatable :: rpointer_filename
441+
integer :: inst_index
437442
real(8) :: MPI_Wtime, timeiads
438443
!--------------------------------
439444

@@ -465,6 +470,13 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
465470
CALL ESMF_TimeIntervalGet(TINT, S=DT_OCEAN, RC=rc)
466471
if (ChkErr(rc,__LINE__,u_FILE_u)) return
467472

473+
#ifdef CESMCOUPLED
474+
call get_component_instance(gcomp, inst_suffix, inst_index, rc)
475+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
476+
call ensemble_manager_init(inst_suffix)
477+
rpointer_filename = 'rpointer.ocn'//trim(inst_suffix)
478+
#endif
479+
468480
! reset shr logging to my log file
469481
if (localPet==0) then
470482
call NUOPC_CompAttributeGet(gcomp, name="diro", &
@@ -474,11 +486,20 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
474486
isPresent=isPresentLogfile, rc=rc)
475487
if (ChkErr(rc,__LINE__,u_FILE_u)) return
476488
if (isPresentDiro .and. isPresentLogfile) then
477-
call NUOPC_CompAttributeGet(gcomp, name="diro", value=diro, rc=rc)
478-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
479-
call NUOPC_CompAttributeGet(gcomp, name="logfile", value=logfile, rc=rc)
480-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
481-
open(newunit=stdout,file=trim(diro)//"/"//trim(logfile))
489+
call NUOPC_CompAttributeGet(gcomp, name="diro", value=diro, rc=rc)
490+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
491+
call NUOPC_CompAttributeGet(gcomp, name="logfile", value=logfile, rc=rc)
492+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
493+
494+
if (cesm_coupled) then
495+
! Multiinstance logfile name needs a correction
496+
if(len_trim(inst_suffix) > 0) then
497+
n = index(logfile, '.')
498+
logfile = logfile(1:n-1)//trim(inst_suffix)//logfile(n:)
499+
endif
500+
endif
501+
502+
open(newunit=stdout,file=trim(diro)//"/"//trim(logfile))
482503
else
483504
stdout = output_unit
484505
endif
@@ -535,12 +556,6 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
535556

536557
time0 = set_date (YEAR,MONTH,DAY,HOUR,MINUTE,SECOND)
537558

538-
539-
! rsd need to figure out how to get this without share code
540-
!call shr_nuopc_get_component_instance(gcomp, inst_suffix, inst_index)
541-
!inst_name = "OCN"//trim(inst_suffix)
542-
543-
544559
if (is_root_pe()) then
545560
write(stdout,*) subname//'start time: y,m,d-',year,month,day,'h,m,s=',hour,minute,second
546561
endif
@@ -595,9 +610,9 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
595610

596611
if (localPet == 0) then
597612
! this hard coded for rpointer.ocn right now
598-
open(newunit=readunit, file='rpointer.ocn', form='formatted', status='old', iostat=iostat)
613+
open(newunit=readunit, file=rpointer_filename, form='formatted', status='old', iostat=iostat)
599614
if (iostat /= 0) then
600-
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, msg=subname//' ERROR opening rpointer.ocn', &
615+
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, msg=subname//' ERROR opening '//rpointer_filename, &
601616
line=__LINE__, file=u_FILE_u, rcToReturn=rc)
602617
return
603618
endif
@@ -607,7 +622,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
607622
if (len(trim(restartfiles))>1 .and. iostat<0) then
608623
exit ! done reading restart files list.
609624
else
610-
call ESMF_LogSetError(ESMF_RC_FILE_READ, msg=subname//' ERROR reading rpointer.ocn', &
625+
call ESMF_LogSetError(ESMF_RC_FILE_READ, msg=subname//' ERROR reading '//rpointer_filename, &
611626
line=__LINE__, file=u_FILE_u, rcToReturn=rc)
612627
return
613628
endif
@@ -630,7 +645,12 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
630645
endif
631646

632647
ocean_public%is_ocean_pe = .true.
633-
call ocean_model_init(ocean_public, ocean_state, time0, time_start, input_restart_file=trim(adjustl(restartfiles)))
648+
if (cesm_coupled .and. len_trim(inst_suffix)>0) then
649+
call ocean_model_init(ocean_public, ocean_state, time0, time_start, &
650+
input_restart_file=trim(adjustl(restartfiles)), inst_index=inst_index)
651+
else
652+
call ocean_model_init(ocean_public, ocean_state, time0, time_start, input_restart_file=trim(adjustl(restartfiles)))
653+
endif
634654

635655
! GMM, this call is not needed in CESM. Check with EMC if it can be deleted.
636656
call ocean_model_flux_init(ocean_state)
@@ -1511,6 +1531,7 @@ subroutine ModelAdvance(gcomp, rc)
15111531
character(len=128) :: fldname
15121532
character(len=*),parameter :: subname='(MOM_cap:ModelAdvance)'
15131533
character(len=8) :: suffix
1534+
character(len=:), allocatable :: rpointer_filename
15141535
integer :: num_rest_files
15151536
real(8) :: MPI_Wtime, timers
15161537

@@ -1685,20 +1706,26 @@ subroutine ModelAdvance(gcomp, rc)
16851706
call ESMF_VMGet(vm, localPet=localPet, rc=rc)
16861707
if (ChkErr(rc,__LINE__,u_FILE_u)) return
16871708

1709+
rpointer_filename = 'rpointer.ocn'//trim(inst_suffix)
1710+
16881711
write(restartname,'(A,".mom6.r.",I4.4,"-",I2.2,"-",I2.2,"-",I5.5)') &
16891712
trim(casename), year, month, day, seconds
16901713
call ESMF_LogWrite("MOM_cap: Writing restart : "//trim(restartname), ESMF_LOGMSG_INFO)
16911714
! write restart file(s)
16921715
call ocean_model_restart(ocean_state, restartname=restartname, num_rest_files=num_rest_files)
16931716
if (localPet == 0) then
16941717
! Write name of restart file in the rpointer file - this is currently hard-coded for the ocean
1695-
open(newunit=writeunit, file='rpointer.ocn', form='formatted', status='unknown', iostat=iostat)
1718+
open(newunit=writeunit, file=rpointer_filename, form='formatted', status='unknown', iostat=iostat)
16961719
if (iostat /= 0) then
16971720
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, &
1698-
msg=subname//' ERROR opening rpointer.ocn', line=__LINE__, file=u_FILE_u, rcToReturn=rc)
1721+
msg=subname//' ERROR opening '//rpointer_filename, line=__LINE__, file=u_FILE_u, rcToReturn=rc)
16991722
return
17001723
endif
1701-
write(writeunit,'(a)') trim(restartname)//'.nc'
1724+
if (len_trim(inst_suffix) == 0) then
1725+
write(writeunit,'(a)') trim(restartname)//'.nc'
1726+
else
1727+
write(writeunit,'(a)') trim(restartname)//'.'//trim(inst_suffix)//'.nc'
1728+
endif
17021729

17031730
if (num_rest_files > 1) then
17041731
! append i.th restart file name to rpointer

config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module MOM_ocean_model_nuopc
4141
use MOM_time_manager, only : operator(/=), operator(<=), operator(>=)
4242
use MOM_time_manager, only : operator(<), real_to_time_type, time_type_to_real
4343
use MOM_interpolate, only : time_interp_external_init
44-
use MOM_tracer_flow_control, only : call_tracer_flux_init
44+
use MOM_tracer_flow_control, only : tracer_flow_control_CS, call_tracer_flux_init, call_tracer_set_forcing
4545
use MOM_unit_scaling, only : unit_scale_type
4646
use MOM_variables, only : surface
4747
use MOM_verticalGrid, only : verticalGrid_type
@@ -210,6 +210,8 @@ module MOM_ocean_model_nuopc
210210
type(marine_ice_CS), pointer :: &
211211
marine_ice_CSp => NULL() !< A pointer to the control structure for the
212212
!! marine ice effects module.
213+
type(tracer_flow_control_CS), pointer :: &
214+
tracer_flow_CSp => NULL() !< A pointer to the tracer flow control structure
213215
type(wave_parameters_CS), pointer, public :: &
214216
Waves => NULL() !< A pointer to the surface wave control structure
215217
type(surface_forcing_CS), pointer :: &
@@ -229,7 +231,7 @@ module MOM_ocean_model_nuopc
229231
!! This subroutine initializes both the ocean state and the ocean surface type.
230232
!! Because of the way that indicies and domains are handled, Ocean_sfc must have
231233
!! been used in a previous call to initialize_ocean_type.
232-
subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, input_restart_file)
234+
subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, input_restart_file, inst_index)
233235
type(ocean_public_type), target, &
234236
intent(inout) :: Ocean_sfc !< A structure containing various publicly
235237
!! visible ocean surface properties after initialization,
@@ -246,6 +248,7 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
246248
!! tracer fluxes, and can be used to spawn related
247249
!! internal variables in the ice model.
248250
character(len=*), optional, intent(in) :: input_restart_file !< If present, name of restart file to read
251+
integer, optional :: inst_index !< Ensemble index provided by the cap (instead of FMS ensemble manager)
249252

250253
! Local variables
251254
real :: Rho0 ! The Boussinesq ocean density, in kg m-3.
@@ -255,7 +258,6 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
255258
!! min(HFrz, OBLD), where OBLD is the boundary layer depth.
256259
!! If HFrz <= 0 (default), melt potential will not be computed.
257260
logical :: use_melt_pot !< If true, allocate melt_potential array
258-
logical :: use_CFC !< If true, allocated arrays for surface CFCs.
259261

260262

261263
! This include declares and sets the variable "version".
@@ -283,7 +285,8 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
283285
call initialize_MOM(OS%Time, Time_init, param_file, OS%dirs, OS%MOM_CSp, &
284286
OS%restart_CSp, Time_in, offline_tracer_mode=OS%offline_tracer_mode, &
285287
input_restart_file=input_restart_file, &
286-
diag_ptr=OS%diag, count_calls=.true., waves_CSp=OS%Waves)
288+
diag_ptr=OS%diag, count_calls=.true., tracer_flow_CSp=OS%tracer_flow_CSp, &
289+
waves_CSp=OS%Waves, ensemble_num=inst_index)
287290
call get_MOM_state_elements(OS%MOM_CSp, G=OS%grid, GV=OS%GV, US=OS%US, C_p=OS%C_p, &
288291
C_p_scaled=OS%fluxes%C_p, use_temp=use_temperature)
289292

@@ -376,16 +379,14 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
376379
use_melt_pot=.false.
377380
endif
378381

379-
call get_param(param_file, mdl, "USE_CFC_CAP", use_CFC, &
380-
default=.false., do_not_log=.true.)
381382
call get_param(param_file, mdl, "USE_WAVES", OS%Use_Waves, &
382383
"If true, enables surface wave modules.", default=.false.)
383384

384385
! Consider using a run-time flag to determine whether to do the diagnostic
385386
! vertical integrals, since the related 3-d sums are not negligible in cost.
386387
call allocate_surface_state(OS%sfc_state, OS%grid, use_temperature, &
387388
do_integrals=.true., gas_fields_ocn=gas_fields_ocn, &
388-
use_meltpot=use_melt_pot, use_cfcs=use_CFC)
389+
use_meltpot=use_melt_pot)
389390

390391
call surface_forcing_init(Time_in, OS%grid, OS%US, param_file, OS%diag, &
391392
OS%forcing_CSp, OS%restore_salinity, OS%restore_temp, OS%use_waves)
@@ -611,6 +612,11 @@ subroutine update_ocean_model(Ice_ocean_boundary, OS, Ocean_sfc, &
611612
call finish_MOM_initialization(OS%Time, OS%dirs, OS%MOM_CSp, OS%restart_CSp)
612613
endif
613614

615+
if (do_thermo) &
616+
call call_tracer_set_forcing(OS%sfc_state, OS%fluxes, OS%Time, &
617+
real_to_time_type(dt_coupling), OS%grid, OS%US, OS%GV%Rho0, &
618+
OS%tracer_flow_CSp)
619+
614620
call disable_averaging(OS%diag)
615621
Master_time = OS%Time ; Time1 = OS%Time
616622

0 commit comments

Comments
 (0)