diff --git a/MOM6/CMakeLists.txt b/MOM6/CMakeLists.txt index fe55acd..db05e92 100644 --- a/MOM6/CMakeLists.txt +++ b/MOM6/CMakeLists.txt @@ -367,6 +367,7 @@ target_sources(OM3_mom6 PRIVATE MOM6/config_src/drivers/nuopc_cap/mom_cap.F90 MOM6/config_src/drivers/nuopc_cap/mom_cap_methods.F90 MOM6/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90 + MOM6/config_src/drivers/nuopc_cap/mom_cap_gtracer_flux.F90 MOM6/config_src/infra/FMS2/MOM_couplertype_infra.F90 MOM6/src/framework/MOM_coupler_types.F90 MOM6/src/tracer/MOM_generic_tracer.F90 @@ -378,20 +379,8 @@ target_sources(OM3_mom6 PRIVATE MOM6/src/equation_of_state/MOM_EOS_base_type.F90 MOM6/src/parameterizations/lateral/MOM_self_attr_load.F90 - MOM6/config_src/drivers/nuopc_cap/mom_cap_gtracer_flux.F90 ) -#turning off patches - cb 17/12/24 -#add_patched_source(OM3_mom6 MOM6/config_src/drivers/nuopc_cap/mom_cap.F90) -#add_patched_source(OM3_mom6 MOM6/config_src/drivers/nuopc_cap/mom_cap_methods.F90) -#add_patched_source(OM3_mom6 MOM6/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90) -#add_patched_source(OM3_mom6 MOM6/config_src/infra/FMS2/MOM_couplertype_infra.F90) -#add_patched_source(OM3_mom6 MOM6/src/framework/MOM_coupler_types.F90) -#add_patched_source(OM3_mom6 MOM6/src/tracer/MOM_generic_tracer.F90) -#add_patched_source(OM3_mom6 MOM6/src/core/MOM_forcing_type.F90) -#add_patched_source(OM3_mom6 MOM6/config_src/infra/FMS2/MOM_io_infra.F90) -#add_patched_source(OM3_mom6 MOM6/src/diagnostics/MOM_PointAccel.F90) - ### Install and Export ## Library diff --git a/MOM6/patches/MOM_PointAccel.F90.patch b/MOM6/patches/MOM_PointAccel.F90.patch deleted file mode 100644 index a19ffd6..0000000 --- a/MOM6/patches/MOM_PointAccel.F90.patch +++ /dev/null @@ -1,24 +0,0 @@ ---- ../MOM6/src/diagnostics/MOM_PointAccel.F90 2024-10-23 10:07:22.000000000 +1100 -+++ ../MOM6/src/diagnostics/MOM_PointAccel.F90.new 2024-10-23 10:15:54.000000000 +1100 -@@ -122,8 +122,8 @@ - if (CS%u_file < 0) then - if (len_trim(CS%u_trunc_file) < 1) return - call open_ASCII_file(CS%u_file, trim(CS%u_trunc_file), action=APPEND_FILE, & -- threading=MULTIPLE, fileset=SINGLE_FILE) -- if (CS%u_file < 0) then -+ threading=MULTIPLE, fileset=MULTIPLE) -+ if (CS%u_file == -1) then - call MOM_error(NOTE, 'Unable to open file '//trim(CS%u_trunc_file)//'.') - return - endif -@@ -461,8 +461,8 @@ - if (CS%v_file < 0) then - if (len_trim(CS%v_trunc_file) < 1) return - call open_ASCII_file(CS%v_file, trim(CS%v_trunc_file), action=APPEND_FILE, & -- threading=MULTIPLE, fileset=SINGLE_FILE) -- if (CS%v_file < 0) then -+ threading=MULTIPLE, fileset=MULTIPLE) -+ if (CS%v_file == -1) then - call MOM_error(NOTE, 'Unable to open file '//trim(CS%v_trunc_file)//'.') - return - endif diff --git a/MOM6/patches/MOM_coupler_types.F90.patch b/MOM6/patches/MOM_coupler_types.F90.patch deleted file mode 100644 index 25a2759..0000000 --- a/MOM6/patches/MOM_coupler_types.F90.patch +++ /dev/null @@ -1,28 +0,0 @@ -diff --git a/MOM6/src/framework/MOM_coupler_types.F90 b/MOM6/src/framework/MOM_coupler_types.F90.new -index f87b409..124d786 100644 ---- a/MOM6/src/framework/MOM_coupler_types.F90 -+++ b/MOM6/src/framework/MOM_coupler_types.F90.new -@@ -8,7 +8,10 @@ use MOM_couplertype_infra, only : CT_set_diags, CT_send_data, CT_write_chksums, - use MOM_couplertype_infra, only : CT_copy_data, CT_increment_data, CT_rescale_data - use MOM_couplertype_infra, only : CT_set_data, CT_extract_data, CT_redistribute_data - use MOM_couplertype_infra, only : coupler_1d_bc_type, coupler_2d_bc_type, coupler_3d_bc_type --use MOM_couplertype_infra, only : ind_flux, ind_alpha, ind_csurf -+use MOM_couplertype_infra, only : ind_flux, ind_deltap, ind_kw, ind_flux0 -+use MOM_couplertype_infra, only : ind_pcair, ind_u10, ind_psurf -+use MOM_couplertype_infra, only : ind_alpha, ind_csurf, ind_sc_no -+use MOM_couplertype_infra, only : ind_runoff, ind_deposition - use MOM_domain_infra, only : domain2D - use MOM_time_manager, only : time_type - -@@ -22,7 +25,10 @@ public :: atmos_ocn_coupler_flux, coupler_type_data_override - public :: coupler_1d_bc_type, coupler_2d_bc_type, coupler_3d_bc_type - ! These are encoding constant parameters that indicate whether a flux, solubility or - ! surface ocean concentration are being set or accessed with an inquiry. --public :: ind_flux, ind_alpha, ind_csurf -+public :: ind_flux, ind_deltap, ind_kw, ind_flux0 -+public :: ind_pcair, ind_u10, ind_psurf -+public :: ind_alpha, ind_csurf, ind_sc_no -+public :: ind_runoff, ind_deposition - - !> This is the interface to spawn one coupler_bc_type into another. - interface coupler_type_spawn diff --git a/MOM6/patches/MOM_couplertype_infra.F90.patch b/MOM6/patches/MOM_couplertype_infra.F90.patch deleted file mode 100644 index 2b7cf4f..0000000 --- a/MOM6/patches/MOM_couplertype_infra.F90.patch +++ /dev/null @@ -1,28 +0,0 @@ -diff --git a/MOM6/config_src/infra/FMS2/MOM_couplertype_infra.F90 b/MOM6/config_src/infra/FMS2/MOM_couplertype_infra.F90.new -index 3bcccc1..50fd5b0 100644 ---- a/MOM6/config_src/infra/FMS2/MOM_couplertype_infra.F90 -+++ b/MOM6/config_src/infra/FMS2/MOM_couplertype_infra.F90.new -@@ -9,7 +9,10 @@ use coupler_types_mod, only : coupler_type_write_chksums, coupler_type_redistrib - use coupler_types_mod, only : coupler_type_increment_data, coupler_type_rescale_data - use coupler_types_mod, only : coupler_type_extract_data, coupler_type_set_data - use coupler_types_mod, only : coupler_type_data_override --use coupler_types_mod, only : ind_flux, ind_alpha, ind_csurf -+use coupler_types_mod, only : ind_flux, ind_deltap, ind_kw, ind_flux0 -+use coupler_types_mod, only : ind_pcair, ind_u10, ind_psurf -+use coupler_types_mod, only : ind_alpha, ind_csurf, ind_sc_no -+use coupler_types_mod, only : ind_runoff, ind_deposition - use coupler_types_mod, only : coupler_1d_bc_type, coupler_2d_bc_type, coupler_3d_bc_type - use atmos_ocean_fluxes_mod, only : aof_set_coupler_flux - use MOM_domain_infra, only : domain2D -@@ -22,7 +25,10 @@ public :: CT_set_diags, CT_send_data, CT_data_override, CT_write_chksums - public :: CT_set_data, CT_increment_data, CT_rescale_data - public :: CT_copy_data, CT_extract_data, CT_redistribute_data - public :: atmos_ocn_coupler_flux --public :: ind_flux, ind_alpha, ind_csurf -+public :: ind_flux, ind_deltap, ind_kw, ind_flux0 -+public :: ind_pcair, ind_u10, ind_psurf -+public :: ind_alpha, ind_csurf, ind_sc_no -+public :: ind_runoff, ind_deposition - public :: coupler_1d_bc_type, coupler_2d_bc_type, coupler_3d_bc_type - - !> This is the interface to spawn one coupler_bc_type into another. diff --git a/MOM6/patches/MOM_forcing_type.F90.patch b/MOM6/patches/MOM_forcing_type.F90.patch deleted file mode 100644 index 76bccef..0000000 --- a/MOM6/patches/MOM_forcing_type.F90.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff --git a/MOM6/src/core/MOM_forcing_type.F90 b/MOM6/src/core/MOM_forcing_type.F90.new -index 200bbd7..fca9187 100644 ---- a/MOM6/src/core/MOM_forcing_type.F90 -+++ b/MOM6/src/core/MOM_forcing_type.F90.new -@@ -2080,6 +2080,11 @@ subroutine fluxes_accumulate(flux_tmp, fluxes, G, wt2, forces) - - fluxes%salt_flux(i,j) = wt1*fluxes%salt_flux(i,j) + wt2*flux_tmp%salt_flux(i,j) - enddo ; enddo -+ if (associated(fluxes%salt_flux_added) .and. associated(flux_tmp%salt_flux_added)) then -+ do j=js,je ; do i=is,ie -+ fluxes%salt_flux_added(i,j) = wt1*fluxes%salt_flux_added(i,j) + wt2*flux_tmp%salt_flux_added(i,j) -+ enddo ; enddo -+ endif - if (associated(fluxes%heat_added) .and. associated(flux_tmp%heat_added)) then - do j=js,je ; do i=is,ie - fluxes%heat_added(i,j) = wt1*fluxes%heat_added(i,j) + wt2*flux_tmp%heat_added(i,j) diff --git a/MOM6/patches/MOM_generic_tracer.F90.patch b/MOM6/patches/MOM_generic_tracer.F90.patch deleted file mode 100644 index 92ffb2d..0000000 --- a/MOM6/patches/MOM_generic_tracer.F90.patch +++ /dev/null @@ -1,36 +0,0 @@ -diff --git a/MOM6/src/tracer/MOM_generic_tracer.F90 b/MOM6/src/tracer/MOM_generic_tracer.F90.new -index 131110e..ae75b2e 100644 ---- a/MOM6/src/tracer/MOM_generic_tracer.F90 -+++ b/MOM6/src/tracer/MOM_generic_tracer.F90.new -@@ -21,7 +21,7 @@ module MOM_generic_tracer - use generic_tracer, only: generic_tracer_coupler_get, generic_tracer_coupler_set - use generic_tracer, only: generic_tracer_end, generic_tracer_get_list, do_generic_tracer - use generic_tracer, only: generic_tracer_update_from_bottom,generic_tracer_vertdiff_G -- use generic_tracer, only: generic_tracer_coupler_accumulate -+ use generic_tracer, only: generic_tracer_coupler_accumulate, generic_tracer_update_from_coupler - - use g_tracer_utils, only: g_tracer_get_name,g_tracer_set_values,g_tracer_set_common,g_tracer_get_common - use g_tracer_utils, only: g_tracer_get_next,g_tracer_type,g_tracer_is_prog,g_tracer_flux_init -@@ -352,7 +352,9 @@ contains - enddo ; enddo ; enddo - - !jgj: Reset CASED to 0 below K=1 -- if ( (trim(g_tracer_name) == 'cased') .or. (trim(g_tracer_name) == 'ca13csed') ) then -+ ! dts: also WOMBAT sediment tracers -+ if ( (trim(g_tracer_name) == 'cased') .or. (trim(g_tracer_name) == 'ca13csed') .or. & -+ (trim(g_tracer_name) == 'det_sediment') .or. (trim(g_tracer_name) == 'caco3_sediment')) then - do k=2,nk ; do j=jsc,jec ; do i=isc,iec - if (tr_ptr(i,j,k) /= CS%tracer_land_val) then - tr_ptr(i,j,k) = 0.0 -@@ -507,6 +509,11 @@ contains - ! the fluxes without coming into this subroutine. - ! MOM5 has to modified to conform. - -+ ! -+ !Call the generic_tracer's update_from_coupler routine (convert salt_flux_added to g/m^2/sec) -+ ! -+ call generic_tracer_update_from_coupler(G%isd, G%jsd, 1000*(US%RZ_T_to_kg_m2s*fluxes%salt_flux_added)) -+ - ! - !Add contribution of river to surface flux - ! diff --git a/MOM6/patches/MOM_io_infra.F90.patch b/MOM6/patches/MOM_io_infra.F90.patch deleted file mode 100644 index d631f31..0000000 --- a/MOM6/patches/MOM_io_infra.F90.patch +++ /dev/null @@ -1,27 +0,0 @@ ---- ../MOM6/config_src/infra/FMS2/MOM_io_infra.F90 2024-10-23 10:07:33.000000000 +1100 -+++ ../MOM6/config_src/infra/FMS2/MOM_io_infra.F90.new 2024-10-23 10:16:45.000000000 +1100 -@@ -376,8 +376,7 @@ - logical :: exists - logical :: is_open - character(len=6) :: action_arg, position_arg -- character(len=:), allocatable :: filename -- -+ character(len=500) :: filename - ! NOTE: This function is written to emulate the original behavior of mpp_open - ! from the FMS1 library, on which the MOM API is still based. Much of this - ! can be removed if we choose to drop this compatibility, but for now we -@@ -433,12 +432,12 @@ - endif - endif - -- inquire(file=filename, exist=exists) -+ inquire(file=trim(filename), exist=exists) - if (exists .and. action_flag == WRITEONLY_FILE) & - call MOM_error(WARNING, 'open_ASCII_file: File ' // trim(filename) // & - ' opened WRITEONLY already exists!') - -- open(newunit=unit, file=filename, action=trim(action_arg), & -+ open(newunit=unit, file=trim(filename), action=trim(action_arg), & - position=trim(position_arg)) - - ! This checks if open() failed but did not raise a runtime error. diff --git a/MOM6/patches/mom_cap.F90.patch b/MOM6/patches/mom_cap.F90.patch deleted file mode 100644 index dee5a39..0000000 --- a/MOM6/patches/mom_cap.F90.patch +++ /dev/null @@ -1,314 +0,0 @@ -diff --git a/MOM6/config_src/drivers/nuopc_cap/mom_cap.F90 b/MOM6/config_src/drivers/nuopc_cap/mom_cap.F90.new -index 3574943..f948684 100644 ---- a/MOM6/config_src/drivers/nuopc_cap/mom_cap.F90 -+++ b/MOM6/config_src/drivers/nuopc_cap/mom_cap.F90.new -@@ -2,8 +2,9 @@ - - module MOM_cap_mod - -+use field_manager_mod, only: field_manager_init, field_manager_end - use MOM_domains, only: get_domain_extent --use MOM_io, only: stdout, io_infra_end -+use MOM_io, only: stdout, io_infra_end, slasher - use mpp_domains_mod, only: mpp_get_compute_domains - use mpp_domains_mod, only: mpp_get_ntile_count, mpp_get_pelist, mpp_get_global_domain - use mpp_domains_mod, only: mpp_get_domain_npes -@@ -30,6 +31,7 @@ use MOM_cap_methods, only: med2mod_areacor, state_diagnose - use MOM_cap_methods, only: ChkErr - use MOM_ensemble_manager, only: ensemble_manager_init - use MOM_coms, only: sum_across_PEs -+use MOM_coupler_types, only: coupler_1d_bc_type, coupler_2d_bc_type - - #ifdef CESMCOUPLED - use shr_log_mod, only: shr_log_setLogUnit -@@ -37,6 +39,15 @@ use nuopc_shr_methods, only: get_component_instance - #endif - use time_utils_mod, only: esmf2fms_time - -+#ifdef _USE_GENERIC_TRACER -+use MOM_coupler_types, only: coupler_type_spawn, coupler_type_destructor -+use MOM_coupler_types, only: coupler_type_set_diags, coupler_type_send_data, coupler_type_data_override -+use MOM_data_override, only: data_override_init, data_override -+use MOM_cap_gtracer_flux, only: gas_exchange_init, gas_fields_restore, gas_fields_restart -+use MOM_cap_gtracer_flux, only: get_coupled_field_name, add_gas_fluxes_param, UNKNOWN_CMEPS_FIELD -+use MOM_cap_gtracer_flux, only: atmos_ocean_fluxes_calc -+#endif -+ - use, intrinsic :: iso_fortran_env, only: output_unit - - use ESMF, only: ESMF_ClockAdvance, ESMF_ClockGet, ESMF_ClockPrint, ESMF_VMget -@@ -96,11 +107,14 @@ implicit none; private - public SetServices - public SetVM - --!> Internal state type with pointers to three types defined by MOM. -+!> Internal state type with pointers to types defined by MOM. - type ocean_internalstate_type - type(ocean_public_type), pointer :: ocean_public_type_ptr - type(ocean_state_type), pointer :: ocean_state_type_ptr - type(ice_ocean_boundary_type), pointer :: ice_ocean_boundary_type_ptr -+#ifdef _USE_GENERIC_TRACER -+ type(coupler_2d_bc_type), pointer :: coupler_2d_bc_type_ptr -+#endif - end type - - !> Wrapper-derived type required to associate an internal state instance -@@ -408,6 +422,10 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) - type (ocean_public_type), pointer :: ocean_public => NULL() - type (ocean_state_type), pointer :: ocean_state => NULL() - type(ice_ocean_boundary_type), pointer :: Ice_ocean_boundary => NULL() -+ type(coupler_1d_bc_type), pointer :: gas_fields_atm => NULL() -+ type(coupler_1d_bc_type), pointer :: gas_fields_ocn => NULL() -+ type(coupler_1d_bc_type), pointer :: gas_fluxes => NULL() -+ type(coupler_2d_bc_type), pointer :: atm_fields => NULL() - type(ocean_internalstate_wrapper) :: ocean_internalstate - type(ocean_grid_type), pointer :: ocean_grid => NULL() - type(directories) :: dirs -@@ -439,6 +457,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) - character(len=512) :: restartfile ! Path/Name of restart file - character(len=2048) :: restartfiles ! Path/Name of restart files - ! (same as restartfile if single restart file) -+ character(240) :: additional_restart_dir - character(len=*), parameter :: subname='(MOM_cap:InitializeAdvertise)' - character(len=32) :: calendar - character(len=:), allocatable :: rpointer_filename -@@ -517,6 +536,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) - if (chkerr(rc,__LINE__,u_FILE_u)) return - call MOM_infra_init(mpi_comm_mom) - -+ call field_manager_init -+ - ! determine the calendar - if (cesm_coupled) then - call NUOPC_CompAttributeGet(gcomp, name="calendar", value=cvalue, & -@@ -648,13 +669,44 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) - - endif - -+ ! Set NUOPC attribute additional_restart_dir to RESTART/ if not defined -+ additional_restart_dir = "RESTART/" -+ call NUOPC_CompAttributeGet(gcomp, name="additional_restart_dir", value=cvalue, & -+ isPresent=isPresent, isSet=isSet, rc=rc) -+ if (ChkErr(rc,__LINE__,u_FILE_u)) return -+ if (isPresent .and. isSet) then -+ additional_restart_dir = slasher(cvalue) -+ else -+ call ESMF_LogWrite('MOM_cap:additional_restart_dir unset. Defaulting to '//trim(additional_restart_dir), & -+ ESMF_LOGMSG_INFO) -+ endif -+ call NUOPC_CompAttributeSet(gcomp, name="additional_restart_dir", value=additional_restart_dir, rc=rc) -+ if (chkerr(rc,__LINE__,u_FILE_u)) return -+ - ocean_public%is_ocean_pe = .true. -+#ifdef _USE_GENERIC_TRACER -+ ! Initialise structures for extra tracer fluxes -+ call gas_exchange_init(gas_fields_atm=gas_fields_atm, gas_fields_ocn=gas_fields_ocn, gas_fluxes=gas_fluxes) -+ -+ if (cesm_coupled .and. len_trim(inst_suffix)>0) then -+ call ocean_model_init(ocean_public, ocean_state, time0, time_start, gas_fields_ocn=gas_fields_ocn, & -+ input_restart_file=trim(adjustl(restartfiles)), inst_index=inst_index) -+ else -+ call ocean_model_init(ocean_public, ocean_state, time0, time_start, gas_fields_ocn=gas_fields_ocn, & -+ input_restart_file=trim(adjustl(restartfiles))) -+ endif -+ -+ ! Enable data override via the data_table using the component name 'OCN' -+ call get_ocean_grid(ocean_state, ocean_grid) -+ call data_override_init(ocean_grid%Domain) -+#else - if (cesm_coupled .and. len_trim(inst_suffix)>0) then - call ocean_model_init(ocean_public, ocean_state, time0, time_start, & - input_restart_file=trim(adjustl(restartfiles)), inst_index=inst_index) - else - call ocean_model_init(ocean_public, ocean_state, time0, time_start, input_restart_file=trim(adjustl(restartfiles))) - endif -+#endif - - ! GMM, this call is not needed in CESM. Check with EMC if it can be deleted. - call ocean_model_flux_init(ocean_state) -@@ -721,6 +773,31 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) - Ice_ocean_boundary%hcond = 0.0 - endif - -+#ifdef _USE_GENERIC_TRACER -+ ! Allocate fields for extra tracer fluxes in Ice_ocean_boundary -+ ! Annoyingly, spawning doesn't copy param array, so add manually -+ call coupler_type_spawn(gas_fluxes, Ice_ocean_boundary%fluxes, (/isc,isc,iec,iec/), & -+ (/jsc,jsc,jec,jec/), suffix='_ice_ocn') -+ call add_gas_fluxes_param(Ice_ocean_boundary%fluxes) -+ -+ ! Initialise structure for atmos fields related to extra tracer fluxes -+ ! This is set in the ESMF Internal State to be accessed elsewhere -+ ! TODO: should we deallocate atm_fields in a finalise step? Ice_ocean_boundary is handled -+ ! in a similar way and does not appear to be deallocated. -+ allocate(atm_fields) -+ ocean_internalstate%ptr%coupler_2d_bc_type_ptr => atm_fields -+ call coupler_type_spawn(gas_fields_atm, atm_fields, (/isc,isc,iec,iec/), & -+ (/jsc,jsc,jec,jec/), suffix='_atm') -+ -+ ! Register diagnosics for extra tracer flux structures -+ call coupler_type_set_diags(Ice_ocean_boundary%fluxes, "ocean_flux", ocean_public%axes(1:2), time_start) -+ call coupler_type_set_diags(atm_fields, "atmos_sfc", ocean_public%axes(1:2), time_start) -+ -+ ! Restore ocean fields related to extra tracer fluxes from restart files -+ call get_MOM_input(dirs=dirs) -+ call gas_fields_restore(ocean_public%fields, ocean_public%domain, dirs%restart_input_dir) -+#endif -+ - call query_ocean_state(ocean_state, use_waves=use_waves, wave_method=wave_method) - if (use_waves) then - if (wave_method == "EFACTOR") then -@@ -789,6 +866,15 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) - endif - endif - -+#ifdef _USE_GENERIC_TRACER -+ ! Add import fields required for extra tracer fluxes -+ do n = 1, gas_fluxes%num_bcs -+ stdname = get_coupled_field_name(gas_fluxes%bc(n)%name) -+ if (stdname /= UNKNOWN_CMEPS_FIELD) & -+ call fld_list_add(fldsToOcn_num, fldsToOcn, stdname, "will provide") -+ enddo -+#endif -+ - !--------- export fields ------------- - call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_omask" , "will provide") - call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_t" , "will provide") -@@ -800,6 +886,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) - call fld_list_add(fldsFrOcn_num, fldsFrOcn, "Fioo_q" , "will provide") - call fld_list_add(fldsFrOcn_num, fldsFrOcn, "So_bldepth" , "will provide") - -+ ! TODO: dts: How to handle export fields from generic tracers? -+ - do n = 1,fldsToOcn_num - call NUOPC_Advertise(importState, standardName=fldsToOcn(n)%stdname, name=fldsToOcn(n)%shortname, rc=rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return -@@ -1611,11 +1699,14 @@ subroutine ModelAdvance(gcomp, rc) - type (ocean_public_type), pointer :: ocean_public => NULL() - type (ocean_state_type), pointer :: ocean_state => NULL() - type(ice_ocean_boundary_type), pointer :: Ice_ocean_boundary => NULL() -+ type(coupler_2d_bc_type), pointer :: atm_fields => NULL() - type(ocean_internalstate_wrapper) :: ocean_internalstate - type(ocean_grid_type) , pointer :: ocean_grid - type(time_type) :: Time -+ type(time_type) :: Time_import - type(time_type) :: Time_step_coupled - type(time_type) :: Time_restart_current -+ integer :: isc,iec,jsc,jec - integer :: dth, dtm, dts - integer :: nc - type(ESMF_Time) :: MyTime -@@ -1627,12 +1718,13 @@ subroutine ModelAdvance(gcomp, rc) - integer :: writeunit - integer :: localPet - type(ESMF_VM) :: vm -- integer :: n, i -+ integer :: m, n, i - character(240) :: import_timestr, export_timestr - character(len=128) :: fldname - character(len=*),parameter :: subname='(MOM_cap:ModelAdvance)' - character(len=8) :: suffix - character(len=:), allocatable :: rpointer_filename -+ character(240) :: additional_restart_dir - integer :: num_rest_files - real(8) :: MPI_Wtime, timers - logical :: write_restart -@@ -1673,6 +1765,7 @@ subroutine ModelAdvance(gcomp, rc) - - Time_step_coupled = esmf2fms_time(timeStep) - Time = esmf2fms_time(currTime) -+ Time_import = Time - - !--------------- - ! Apply ocean lag for startup runs: -@@ -1748,8 +1841,39 @@ subroutine ModelAdvance(gcomp, rc) - ! Import data - !--------------- - -+#ifdef _USE_GENERIC_TRACER -+ atm_fields => ocean_internalstate%ptr%coupler_2d_bc_type_ptr -+ -+ call mom_import(ocean_public, ocean_grid, importState, ice_ocean_boundary, atm_fields=atm_fields, rc=rc) -+ if (ChkErr(rc,__LINE__,u_FILE_u)) return -+ -+ ! Potentially override atm_fields from data_table. -+ call coupler_type_data_override('OCN', atm_fields, Time_import) -+ -+ ! Potentially override ice_ocean_boundary%fluxes from data_table. -+ ! Doing this before atmos_ocean_fluxes_calc call avoids unnecessary calculation of overridden fluxes. -+ ! However, we cannot use coupler_type_data_override here since it does not set the override flag on -+ ! overridden fields -+ do n = 1, ice_ocean_boundary%fluxes%num_bcs -+ do m = 1, ice_ocean_boundary%fluxes%bc(n)%num_fields -+ call data_override('OCN', ice_ocean_boundary%fluxes%bc(n)%field(m)%name, & -+ ice_ocean_boundary%fluxes%bc(n)%field(m)%values, Time_import, & -+ override=ice_ocean_boundary%fluxes%bc(n)%field(m)%override) -+ enddo -+ enddo -+ -+ ! Calculate the extra tracer fluxes -+ call get_domain_extent(ocean_public%domain, isc, iec, jsc, jec) -+ call atmos_ocean_fluxes_calc(atm_fields, ocean_public%fields, ice_ocean_boundary%fluxes, & -+ ice_ocean_boundary%ice_fraction, isc, iec, jsc, jec) -+ -+ ! Send diagnostics -+ call coupler_type_send_data(atm_fields, Time_import) -+ call coupler_type_send_data(ice_ocean_boundary%fluxes, Time_import) -+#else - call mom_import(ocean_public, ocean_grid, importState, ice_ocean_boundary, rc=rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return -+#endif - - !--------------- - ! Update MOM6 -@@ -1811,7 +1935,7 @@ subroutine ModelAdvance(gcomp, rc) - ! determine restart filename - call ESMF_ClockGetNextTime(clock, MyTime, rc=rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return -- call ESMF_TimeGet (MyTime, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc ) -+ call ESMF_TimeGet (MyTime, yy=year, mm=month, dd=day, s=seconds, rc=rc ) - if (ChkErr(rc,__LINE__,u_FILE_u)) return - - if (cesm_coupled) then -@@ -1869,6 +1993,14 @@ subroutine ModelAdvance(gcomp, rc) - - endif - -+#ifdef _USE_GENERIC_TRACER -+ ! Write fields for extra tracer fluxes to their internally defined ocean restart file -+ call NUOPC_CompAttributeGet(gcomp, name="additional_restart_dir", value=additional_restart_dir, rc=rc) -+ if (ChkErr(rc,__LINE__,u_FILE_u)) return -+ -+ call gas_fields_restart(ocean_public%fields, ocean_public%domain, additional_restart_dir) -+#endif -+ - if (is_root_pe()) then - write(stdout,*) subname//' writing restart file ',trim(restartname) - endif -@@ -2149,6 +2281,7 @@ subroutine ocean_model_finalize(gcomp, rc) - integer :: alarmCount - character(len=64) :: timestamp - logical :: write_restart -+ character(240) :: additional_restart_dir - character(len=*),parameter :: subname='(MOM_cap:ocean_model_finalize)' - real(8) :: MPI_Wtime, timefs - -@@ -2182,6 +2315,18 @@ subroutine ocean_model_finalize(gcomp, rc) - - call ocean_model_end(ocean_public, ocean_State, Time, write_restart=write_restart) - -+#ifdef _USE_GENERIC_TRACER -+ if (write_restart) then -+ ! Write fields for extra tracer fluxes to their internally defined ocean restart file -+ call NUOPC_CompAttributeGet(gcomp, name="additional_restart_dir", value=additional_restart_dir, rc=rc) -+ if (ChkErr(rc,__LINE__,u_FILE_u)) return -+ -+ call gas_fields_restart(ocean_public%fields, ocean_public%domain, additional_restart_dir) -+ endif -+#endif -+ -+ call field_manager_end() -+ - call io_infra_end() - call MOM_infra_end() - diff --git a/MOM6/patches/mom_cap_methods.F90.patch b/MOM6/patches/mom_cap_methods.F90.patch deleted file mode 100644 index b87c0b2..0000000 --- a/MOM6/patches/mom_cap_methods.F90.patch +++ /dev/null @@ -1,98 +0,0 @@ -diff --git a/MOM6/config_src/drivers/nuopc_cap/mom_cap_methods.F90 b/MOM6/config_src/drivers/nuopc_cap/mom_cap_methods.F90.new -index 125bae5..67f3314 100644 ---- a/MOM6/config_src/drivers/nuopc_cap/mom_cap_methods.F90 -+++ b/MOM6/config_src/drivers/nuopc_cap/mom_cap_methods.F90.new -@@ -20,8 +20,15 @@ use MOM_ocean_model_nuopc, only: ocean_public_type, ocean_state_type - use MOM_surface_forcing_nuopc, only: ice_ocean_boundary_type - use MOM_grid, only: ocean_grid_type - use MOM_domains, only: pass_var -+use MOM_coupler_types, only: coupler_2d_bc_type - use mpp_domains_mod, only: mpp_get_compute_domain - -+#ifdef _USE_GENERIC_TRACER -+use MOM_coupler_types, only: set_coupler_type_data -+use MOM_coupler_types, only: ind_pcair, ind_u10, ind_psurf, ind_runoff, ind_deposition -+use MOM_cap_gtracer_flux, only: get_coupled_field_name, UNKNOWN_CMEPS_FIELD -+#endif -+ - ! By default make data private - implicit none; private - -@@ -72,11 +79,16 @@ end subroutine mom_set_geomtype - !> This function has a few purposes: - !! (1) it imports surface fluxes using data from the mediator; and - !! (2) it can apply restoring in SST and SSS. --subroutine mom_import(ocean_public, ocean_grid, importState, ice_ocean_boundary, rc) -+!! (3) optional: if atm_fields is provided, it imports and sets the fields in atm_fields required for the -+!! calculation of coupled generic tracer fluxes -+subroutine mom_import(ocean_public, ocean_grid, importState, ice_ocean_boundary, atm_fields, rc) - type(ocean_public_type) , intent(in) :: ocean_public !< Ocean surface state - type(ocean_grid_type) , intent(in) :: ocean_grid !< Ocean model grid - type(ESMF_State) , intent(inout) :: importState !< incoming data from mediator - type(ice_ocean_boundary_type) , intent(inout) :: ice_ocean_boundary !< Ocean boundary forcing -+ type(coupler_2d_bc_type), optional, intent(inout) :: atm_fields !< If present, this type describes the atmospheric -+ !! tracer fields to be imported for the calculation -+ !! of generic tracer fluxes. - integer , intent(inout) :: rc !< Return code - - ! Local Variables -@@ -88,7 +100,10 @@ subroutine mom_import(ocean_public, ocean_grid, importState, ice_ocean_boundary, - real(ESMF_KIND_R8), allocatable :: tauy(:,:) - real(ESMF_KIND_R8), allocatable :: stkx(:,:,:) - real(ESMF_KIND_R8), allocatable :: stky(:,:,:) -+ real(ESMF_KIND_R8), allocatable :: work(:,:) - character(len=*) , parameter :: subname = '(mom_import)' -+ character(len=256) :: stdname -+ integer :: field_index - - rc = ESMF_SUCCESS - -@@ -364,6 +379,48 @@ subroutine mom_import(ocean_public, ocean_grid, importState, ice_ocean_boundary, - deallocate(stkx,stky) - endif - -+ !--- -+ ! Tracer flux fields for generic tracers -+ !--- -+#ifdef _USE_GENERIC_TRACER -+ if (present(atm_fields)) then -+ ! Set fields in atm_fields from coupler -+ allocate (work(isc:iec,jsc:jec)) -+ do n = 1, atm_fields%num_bcs -+ if (atm_fields%bc(n)%flux_type .eq. 'air_sea_deposition') then -+ field_index = ind_deposition -+ elseif (atm_fields%bc(n)%flux_type .eq. 'land_sea_runoff') then -+ field_index = ind_runoff -+ else -+ ! This is a gas flux - set ind_u10 and ind_psurf -+ ! Note, we set these fields even though the pcair field may not be set below. This -+ ! is to allow flux calculation with overridden pcair fields -+ field_index = ind_pcair -+ call set_coupler_type_data(sqrt(ice_ocean_boundary%u10_sqr), n, atm_fields, & -+ idim=(/isc,isc,iec,iec/), jdim=(/jsc,jsc,jec,jec/), field_index=ind_u10) -+ call set_coupler_type_data(ice_ocean_boundary%p, n, atm_fields, & -+ idim=(/isc,isc,iec,iec/), jdim=(/jsc,jsc,jec,jec/), field_index=ind_psurf) -+ endif -+ -+ stdname = get_coupled_field_name(atm_fields%bc(n)%name) -+ if (stdname /= UNKNOWN_CMEPS_FIELD) then -+ call ESMF_LogWrite(trim(subname)//': generic_tracer flux, '//trim(atm_fields%bc(n)%name)//& -+ ': setting field index '//CHAR(48+field_index)//' to '//trim(stdname)//' if provided '//& -+ 'by coupler, otherwise defaulting to zero', ESMF_LOGMSG_INFO) -+ work(:,:) = 0._ESMF_KIND_R8 -+ call state_getimport(importState, trim(stdname), isc, iec, jsc, jec, work, rc=rc) -+ if (ChkErr(rc,__LINE__,u_FILE_u)) return -+ call set_coupler_type_data(work, n, atm_fields, & -+ idim=(/isc,isc,iec,iec/), jdim=(/jsc,jsc,jec,jec/), field_index=field_index) -+ else -+ call ESMF_LogWrite(trim(subname)//': generic_tracer flux, '//trim(atm_fields%bc(n)%name)//& -+ ': no fields set from coupler', ESMF_LOGMSG_INFO) -+ endif -+ enddo -+ deallocate(work) -+ endif -+#endif -+ - end subroutine mom_import - - !> Maps outgoing ocean data to ESMF State diff --git a/MOM6/patches/mom_ocean_model_nuopc.F90.patch b/MOM6/patches/mom_ocean_model_nuopc.F90.patch deleted file mode 100644 index 273a96a..0000000 --- a/MOM6/patches/mom_ocean_model_nuopc.F90.patch +++ /dev/null @@ -1,115 +0,0 @@ -diff --git a/MOM6/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90 b/MOM6/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90.new -index 04b60b0..9855c24 100644 ---- a/MOM6/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90 -+++ b/MOM6/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90.new -@@ -19,6 +19,7 @@ use MOM_coms, only : field_chksum - use MOM_constants, only : CELSIUS_KELVIN_OFFSET, hlf - use MOM_diag_mediator, only : diag_ctrl, enable_averages, disable_averaging - use MOM_diag_mediator, only : diag_mediator_close_registration, diag_mediator_end -+use MOM_domains, only : MOM_domain_type, domain2d, clone_MOM_domain, get_domain_extent - use MOM_domains, only : pass_var, pass_vector, AGRID, BGRID_NE, CGRID_NE - use MOM_domains, only : TO_ALL, Omit_Corners - use MOM_error_handler, only : MOM_error, FATAL, WARNING, is_root_pe -@@ -51,8 +52,6 @@ use MOM_coupler_types, only : coupler_1d_bc_type, coupler_2d_bc_type - use MOM_coupler_types, only : coupler_type_spawn, coupler_type_write_chksums - use MOM_coupler_types, only : coupler_type_initialized, coupler_type_copy_data - use MOM_coupler_types, only : coupler_type_set_diags, coupler_type_send_data --use mpp_domains_mod, only : domain2d, mpp_get_layout, mpp_get_global_domain --use mpp_domains_mod, only : mpp_define_domains, mpp_get_compute_domain, mpp_get_data_domain - use MOM_io, only : stdout - use MOM_EOS, only : gsw_sp_from_sr, gsw_pt_from_ct - use MOM_wave_interface, only : wave_parameters_CS, MOM_wave_interface_init -@@ -102,7 +101,7 @@ type, public :: ocean_public_type - !! points of the two velocity components. Valid entries - !! include AGRID, BGRID_NE, CGRID_NE, BGRID_SW, and CGRID_SW, - !! corresponding to the community-standard Arakawa notation. -- !! (These are named integers taken from mpp_parameter_mod.) -+ !! (These are named integers taken from the MOM_domains module.) - !! Following MOM5, stagger is BGRID_NE by default when the - !! ocean is initialized, but here it is set to -999 so that - !! a global max across ocean and non-ocean processors can be -@@ -410,14 +409,7 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i - ! it also initializes statistical waves. - call MOM_wave_interface_init(OS%Time, OS%grid, OS%GV, OS%US, param_file, OS%Waves, OS%diag, OS%restart_CSp) - -- if (associated(OS%grid%Domain%maskmap)) then -- call initialize_ocean_public_type(OS%grid%Domain%mpp_domain, Ocean_sfc, & -- OS%diag, maskmap=OS%grid%Domain%maskmap, & -- gas_fields_ocn=gas_fields_ocn) -- else -- call initialize_ocean_public_type(OS%grid%Domain%mpp_domain, Ocean_sfc, & -- OS%diag, gas_fields_ocn=gas_fields_ocn) -- endif -+ call initialize_ocean_public_type(OS%grid%Domain, Ocean_sfc, OS%diag, gas_fields_ocn=gas_fields_ocn) - - ! This call can only occur here if the coupler_bc_type variables have been - ! initialized already using the information from gas_fields_ocn. -@@ -532,8 +524,7 @@ subroutine update_ocean_model(Ice_ocean_boundary, OS, Ocean_sfc, & - (/is,is,ie,ie/), (/js,js,je,je/), as_needed=.true.) - - ! Translate Ice_ocean_boundary into fluxes. -- call mpp_get_compute_domain(Ocean_sfc%Domain, index_bnds(1), index_bnds(2), & -- index_bnds(3), index_bnds(4)) -+ call get_domain_extent(Ocean_sfc%Domain, index_bnds(1), index_bnds(2), index_bnds(3), index_bnds(4)) - - weight = 1.0 - -@@ -795,7 +786,7 @@ end subroutine ocean_model_end - subroutine ocean_model_save_restart(OS, Time, directory, filename_suffix) - type(ocean_state_type), pointer :: OS !< A pointer to the structure containing the - !! internal ocean state (in). -- type(time_type), intent(in) :: Time !< The model time at this call, needed for mpp_write calls. -+ type(time_type), intent(in) :: Time !< The model time at this call, needed for writing files. - character(len=*), optional, intent(in) :: directory !< An optional directory into which to - !! write these restart files. - character(len=*), optional, intent(in) :: filename_suffix !< An optional suffix (e.g., a time-stamp) -@@ -827,16 +818,12 @@ subroutine ocean_model_save_restart(OS, Time, directory, filename_suffix) - end subroutine ocean_model_save_restart - - !> Initialize the public ocean type --subroutine initialize_ocean_public_type(input_domain, Ocean_sfc, diag, maskmap, & -- gas_fields_ocn) -- type(domain2D), intent(in) :: input_domain !< The ocean model domain description -+subroutine initialize_ocean_public_type(input_domain, Ocean_sfc, diag, gas_fields_ocn) -+ type(MOM_domain_type), intent(in) :: input_domain !< The ocean model domain description - type(ocean_public_type), intent(inout) :: Ocean_sfc !< A structure containing various publicly -- !! visible ocean surface properties after initialization, whose -- !! elements are allocated here. -- type(diag_ctrl), intent(in) :: diag !< A structure that regulates diagnsotic output -- logical, dimension(:,:), & -- optional, intent(in) :: maskmap !< A mask indicating which virtual processors -- !! are actually in use. If missing, all are used. -+ !! visible ocean surface properties after -+ !! initialization, whose elements are allocated here. -+ type(diag_ctrl), intent(in) :: diag !< A structure that regulates diagnostic output - type(coupler_1d_bc_type), & - optional, intent(in) :: gas_fields_ocn !< If present, this type describes the - !! ocean and surface-ice fields that will participate -@@ -848,14 +835,9 @@ subroutine initialize_ocean_public_type(input_domain, Ocean_sfc, diag, maskmap, - ! and have no halos. - integer :: isc, iec, jsc, jec - -- call mpp_get_layout(input_domain,layout) -- call mpp_get_global_domain(input_domain, xsize=xsz, ysize=ysz) -- if (PRESENT(maskmap)) then -- call mpp_define_domains((/1,xsz,1,ysz/),layout,Ocean_sfc%Domain, maskmap=maskmap) -- else -- call mpp_define_domains((/1,xsz,1,ysz/),layout,Ocean_sfc%Domain) -- endif -- call mpp_get_compute_domain(Ocean_sfc%Domain, isc, iec, jsc, jec) -+ call clone_MOM_domain(input_domain, Ocean_sfc%Domain, halo_size=0, symmetric=.false.) -+ -+ call get_domain_extent(Ocean_sfc%Domain, isc, iec, jsc, jec) - - allocate ( Ocean_sfc%t_surf (isc:iec,jsc:jec), & - Ocean_sfc%s_surf (isc:iec,jsc:jec), & -@@ -911,8 +893,7 @@ subroutine convert_state_to_ocean_type(sfc_state, Ocean_sfc, G, US, patm, press_ - is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec - call pass_vector(sfc_state%u, sfc_state%v, G%Domain) - -- call mpp_get_compute_domain(Ocean_sfc%Domain, isc_bnd, iec_bnd, & -- jsc_bnd, jec_bnd) -+ call get_domain_extent(Ocean_sfc%Domain, isc_bnd, iec_bnd, jsc_bnd, jec_bnd) - if (present(patm)) then - ! Check that the inidicies in patm are (isc_bnd:iec_bnd,jsc_bnd:jec_bnd). - if (.not.present(press_to_z)) call MOM_error(FATAL, &