@@ -36,7 +36,7 @@ module MOM
3636use MOM_diag_mediator, only : diag_set_state_ptrs, diag_update_remap_grids
3737use MOM_diag_mediator, only : disable_averaging, post_data, safe_alloc_ptr
3838use MOM_diag_mediator, only : register_diag_field, register_static_field
39- use MOM_diag_mediator, only : register_scalar_field
39+ use MOM_diag_mediator, only : register_scalar_field, get_diag_time_end
4040use MOM_diag_mediator, only : set_axes_info, diag_ctrl, diag_masks_set
4141use MOM_domains, only : MOM_domains_init, clone_MOM_domain
4242use MOM_domains, only : sum_across_PEs, pass_var, pass_vector
@@ -62,6 +62,7 @@ module MOM
6262use MOM_time_manager, only : operator (- ), operator (>), operator (* ), operator (/ )
6363use MOM_time_manager, only : increment_date
6464use MOM_unit_tests, only : unit_tests
65+ use coupler_types_mod, only : coupler_type_send_data, coupler_1d_bc_type, coupler_type_spawn
6566
6667! MOM core modules
6768use MOM_ALE, only : ALE_init, ALE_end, ALE_main, ALE_CS, adjustGridForIntegrity
@@ -430,6 +431,7 @@ module MOM
430431public step_MOM
431432public step_offline
432433public MOM_end
434+ public allocate_surface_state
433435public calculate_surface_state
434436
435437integer :: id_clock_ocean
@@ -1926,7 +1928,7 @@ subroutine initialize_MOM(Time, param_file, dirs, CS, Time_in, offline_tracer_mo
19261928 endif
19271929
19281930 if (CS% bulkmixedlayer .or. CS% use_temperature) then
1929- allocate (CS% Hml(isd:ied,jsd:jed)) ; CS% Hml(:,:) = 0.0
1931+ allocate (CS% Hml(isd:ied,jsd:jed)) ; CS% Hml(:,:) = 0.0
19301932 endif
19311933
19321934 if (CS% bulkmixedlayer) then
@@ -3222,6 +3224,8 @@ subroutine post_surface_diagnostics(CS, G, diag, state)
32223224 call post_data(CS% id_speed, sfc_speed, diag, mask= G% mask2dT)
32233225 endif
32243226
3227+ call coupler_type_send_data(state% tr_fields, get_diag_time_end(diag))
3228+
32253229end subroutine post_surface_diagnostics
32263230
32273231! > Offers the static fields in the ocean grid type
@@ -3428,6 +3432,64 @@ subroutine adjust_ssh_for_p_atm(CS, G, GV, ssh, p_atm)
34283432
34293433end subroutine adjust_ssh_for_p_atm
34303434
3435+ ! > This subroutine allocates the fields for the surface (return) properties of
3436+ ! ! the ocean model. Unused fields are unallocated.
3437+ subroutine allocate_surface_state (state , G , use_temperature , do_integrals , &
3438+ gas_fields_ocn )
3439+ type (ocean_grid_type), intent (in ) :: G ! < ocean grid structure
3440+ type (surface), intent (inout ) :: state ! < ocean surface state type to be allocated.
3441+ logical , optional , intent (in ) :: use_temperature ! < If true, allocate the space for thermodynamic variables.
3442+ logical , optional , intent (in ) :: do_integrals ! < If true, allocate the space for vertically integrated fields.
3443+ type (coupler_1d_bc_type), &
3444+ optional , intent (in ) :: gas_fields_ocn ! < If present, this type describes the ocean
3445+ ! ! ocean and surface-ice fields that will participate
3446+ ! ! in the calculation of additional gas or other
3447+ ! ! tracer fluxes, and can be used to spawn related
3448+ ! ! internal variables in the ice model.
3449+
3450+ logical :: use_temp, alloc_integ
3451+ integer :: is, ie, js, je, isd, ied, jsd, jed
3452+ integer :: isdB, iedB, jsdB, jedB
3453+
3454+ is = G% isc ; ie = G% iec ; js = G% jsc ; je = G% jec
3455+ isd = G% isd ; ied = G% ied ; jsd = G% jsd ; jed = G% jed
3456+ isdB = G% isdB ; iedB = G% iedB; jsdB = G% jsdB ; jedB = G% jedB
3457+
3458+ use_temp = .true. ; if (present (use_temperature)) use_temp = use_temperature
3459+ alloc_integ = .true. ; if (present (do_integrals)) alloc_integ = do_integrals
3460+
3461+ if (state% arrays_allocated) return
3462+
3463+ if (use_temp) then
3464+ allocate (state% SST(isd:ied,jsd:jed)) ; state% SST(:,:) = 0.0
3465+ allocate (state% SSS(isd:ied,jsd:jed)) ; state% SSS(:,:) = 0.0
3466+ else
3467+ allocate (state% sfc_density(isd:ied,jsd:jed)) ; state% sfc_density(:,:) = 0.0
3468+ endif
3469+ allocate (state% sea_lev(isd:ied,jsd:jed)) ; state% sea_lev(:,:) = 0.0
3470+ allocate (state% Hml(isd:ied,jsd:jed)) ; state% Hml(:,:) = 0.0
3471+ allocate (state% u(IsdB:IedB,jsd:jed)) ; state% u(:,:) = 0.0
3472+ allocate (state% v(isd:ied,JsdB:JedB)) ; state% v(:,:) = 0.0
3473+
3474+ if (alloc_integ) then
3475+ ! Allocate structures for the vertically integrated ocean_mass, ocean_heat,
3476+ ! and ocean_salt.
3477+ allocate (state% ocean_mass(isd:ied,jsd:jed)) ; state% ocean_mass(:,:) = 0.0
3478+ if (use_temp) then
3479+ allocate (state% ocean_heat(isd:ied,jsd:jed)) ; state% ocean_heat(:,:) = 0.0
3480+ allocate (state% ocean_salt(isd:ied,jsd:jed)) ; state% ocean_salt(:,:) = 0.0
3481+ endif
3482+ allocate (state% salt_deficit(isd:ied,jsd:jed)) ; state% salt_deficit(:,:) = 0.0
3483+ endif
3484+
3485+ if (present (gas_fields_ocn)) &
3486+ call coupler_type_spawn(gas_fields_ocn, state% tr_fields, &
3487+ (/ isd,is,ie,ied/ ), (/ jsd,js,je,jed/ ), as_needed= .true. )
3488+
3489+ state% arrays_allocated = .true.
3490+
3491+ end subroutine allocate_surface_state
3492+
34313493! > This subroutine sets the surface (return) properties of the ocean
34323494! ! model by setting the appropriate fields in state. Unused fields
34333495! ! are set to NULL or are unallocated.
@@ -3462,28 +3524,9 @@ subroutine calculate_surface_state(state, u, v, h, ssh, G, GV, CS)
34623524 isdB = G% isdB ; iedB = G% iedB; jsdB = G% jsdB ; jedB = G% jedB
34633525
34643526 if (.not. state% arrays_allocated) then
3465- if (CS% use_temperature) then
3466- allocate (state% SST(isd:ied,jsd:jed)) ; state% SST(:,:) = 0.0
3467- allocate (state% SSS(isd:ied,jsd:jed)) ; state% SSS(:,:) = 0.0
3468- else
3469- allocate (state% sfc_density(isd:ied,jsd:jed)) ; state% sfc_density(:,:) = 0.0
3470- endif
3471- allocate (state% sea_lev(isd:ied,jsd:jed)) ; state% sea_lev(:,:) = 0.0
3472- allocate (state% Hml(isd:ied,jsd:jed)) ; state% Hml(:,:) = 0.0
3473- allocate (state% u(IsdB:IedB,jsd:jed)) ; state% u(:,:) = 0.0
3474- allocate (state% v(isd:ied,JsdB:JedB)) ; state% v(:,:) = 0.0
3475-
3476- ! Allocate structures for ocean_mass, ocean_heat, and ocean_salt. This could
3477- ! be wrapped in a run-time flag to disable it for economy, since the 3-d
3478- ! sums are not negligible.
3479- allocate (state% ocean_mass(isd:ied,jsd:jed)) ; state% ocean_mass(:,:) = 0.0
3480- if (CS% use_temperature) then
3481- allocate (state% ocean_heat(isd:ied,jsd:jed)) ; state% ocean_heat(:,:) = 0.0
3482- allocate (state% ocean_salt(isd:ied,jsd:jed)) ; state% ocean_salt(:,:) = 0.0
3483- endif
3484- allocate (state% salt_deficit(isd:ied,jsd:jed)) ; state% salt_deficit(:,:) = 0.0
3485-
3486- state% arrays_allocated = .true.
3527+ ! Consider using a run-time flag to determine whether to do the vertical
3528+ ! integrals, since the 3-d sums are not negligible in cost.
3529+ call allocate_surface_state(state, G, CS% use_temperature, do_integrals= .true. )
34873530 endif
34883531 state% frazil = > CS% tv% frazil
34893532 state% TempxPmE = > CS% tv% TempxPmE
0 commit comments