Skip to content

Commit

Permalink
Merge pull request #501 from billsacks/fix_xgrid_f_compset
Browse files Browse the repository at this point in the history
Fix for exchange grid with add_gusts false: Only add gust fields if add_gusts is true

### Description of changes

Runs with `aoflux_grid = "xgrid"` and `add_gusts = .false.` have been failing with:

```
20240903 141813.539 ERROR            PET003 ESMCI_Container.h:178 ESMCI::Container::get() Invalid argument  - key does not exist: So_ugustOut
```

This PR fixes this issue by avoiding adding the two new gust fields to the list of mediator fields if add_gusts is false.

The explanation for why this caused an issue with the exchange grid is:
- In `mediator/esmFldsExchange_cesm_mod.F90`: `esmFldsExchange_cesm`, `So_ugustOut` and `So_u10withGust` are added as atmosphere-ocean fluxes regardless of the value of `add_gusts`. 
- But in `mediator/med_phases_aofluxes_mod.F90`: `set_aoflux_out_pointers`, the `fldbun_getfldptr` call is only made if `add_gusts` is true.
- There is a difference in behavior with xgrid than with ogrid here: with xgrid, the call to `fldbun_getfldptr` is responsible for adding the field to `FBaof_x`. (I think with ogrid or agrid, the fields have been added to the relevant field bundle already.)
- So we end up with these gust fields not in `FBaof_x`, but still in `fldnames_aof_out`, and this leads to an inconsistency.

**@megandevlan and @jedwards4b: I'm not positive that this is the right fix: It does solve the issue, but I'd like one or both of your input on whether this is the right way to solve the issue. In particular, can we rely on CAM working correctly when add_gusts is false if these fields are absent? It looks to me like CAM will set the relevant fields to 0 if they are absent; will that lead to correct behavior when add_gusts = .false.?**

### Specific notes

Contributors other than yourself, if any:

CMEPS Issues Fixed (include github issue #):

Are changes expected to change answers? No, but there are FIELDLIST diffs for cases with add_gusts false: the following fields will no longer be present on the cpl hi files when add_gusts is false:
- Med_aoflux_ocn_So_u10withGust
- Med_aoflux_ocn_So_ugustOut
- Med_aoflux_atm_So_u10withGust
- Med_aoflux_atm_So_ugustOut
- atmExp_So_u10withGust
- atmExp_So_ugustOut

Any User Interface Changes (namelist or namelist defaults changes)? No

### Testing performed
Please describe the tests along with the target model and machine(s) 
If possible, please also added hashes that were used in the testing

Ran three versions of `SMS_D_Ln9.ne30pg3_ne30pg3_mg17.FLTHIST.derecho_intel.cam-outfrq9s` from cesm3_0_alpha03c:
1. `add_gusts = .false.`, `aoflux_grid = "ogrid"`
2. `add_gusts = .false.`, `aoflux_grid = "xgrid"` (**This is the case that was failing previously.**
3. `add_gusts = .true.`, `aoflux_grid = "xgrid"`

All three pass now.

Also ran `SMS_Ld40.TL319_t232.C_JRA.derecho_intel` (which has add_gusts = .false.) with `aoflux_grid = "xgrid"`; this also passes now but failed before the changes in this PR.

I have also run the following tests with comparisons against baselines: all pass and are bit-for-bit, though with FIELDLIST diffs as expected:
- SMS.TL319_t232.G_JRA.derecho_intel.mom-no_stoch_physics
-  ERP_Ln9.f09_f09_mg17.F1850.derecho_intel.cam-outfrq9s
- SMS_Ld2.ne30pg3_t232.BLT1850.derecho_intel.allactive-defaultio with change to user_nl_cpl to set add_gusts false
  • Loading branch information
billsacks committed Sep 28, 2024
2 parents 5b7d769 + 771c4d4 commit b1e2325
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions mediator/esmFldsExchange_cesm_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ module esmFldsExchange_cesm_mod
logical :: flds_co2c ! Pass CO2 from ATM to surface (OCN/LND) and back from them to ATM
logical :: flds_wiso ! Pass water isotop fields
logical :: flds_r2l_stream_channel_depths ! Pass channel depths from ROF to LND
logical :: add_gusts ! Whether to include fields related to the gustiness parameterization

character(*), parameter :: u_FILE_u = &
__FILE__
Expand Down Expand Up @@ -232,6 +233,11 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) flds_r2l_stream_channel_depths

! are fields related to the gustiness parameterization enabled?
call NUOPC_CompAttributeGet(gcomp, name='add_gusts', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) add_gusts

! write diagnostic output
if (maintask) then
write(logunit,'(a)' ) ' flds_co2a: prognostic and diagnostic CO2 at lowest atm level is sent to lnd and ocn'
Expand All @@ -246,6 +252,7 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
write(logunit,'(a,l7)') trim(subname)//' flds_wiso = ',flds_wiso
write(logunit,'(a,l7)') trim(subname)//' flds_i2o_per_cat = ',flds_i2o_per_cat
write(logunit,'(a,l7)') trim(subname)//' flds_r2l_stream_channel_depths = ',flds_r2l_stream_channel_depths
write(logunit,'(a,l7)') trim(subname)//' add_gusts = ', add_gusts
write(logunit,'(a,l7)') trim(subname)//' mapuv_with_cart3d = ',mapuv_with_cart3d
end if

Expand Down Expand Up @@ -1414,35 +1421,39 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
! ---------------------------------------------------------------------
! to atm: unmerged ugust_out from ocn
! ---------------------------------------------------------------------
if (phase == 'advertise') then
call addfld_aoflux('So_ugustOut')
call addfld_to(compatm, 'So_ugustOut')
else
if ( fldchk(is_local%wrap%FBexp(compatm), 'So_ugustOut', rc=rc)) then
if (fldchk(is_local%wrap%FBMed_aoflux_o, 'So_ugustOut', rc=rc)) then
if (trim(is_local%wrap%aoflux_grid) == 'ogrid') then
call addmap_aoflux('So_ugustOut', compatm, mapconsf, 'ofrac', ocn2atm_map)
if (add_gusts) then
if (phase == 'advertise') then
call addfld_aoflux('So_ugustOut')
call addfld_to(compatm, 'So_ugustOut')
else
if ( fldchk(is_local%wrap%FBexp(compatm), 'So_ugustOut', rc=rc)) then
if (fldchk(is_local%wrap%FBMed_aoflux_o, 'So_ugustOut', rc=rc)) then
if (trim(is_local%wrap%aoflux_grid) == 'ogrid') then
call addmap_aoflux('So_ugustOut', compatm, mapconsf, 'ofrac', ocn2atm_map)
end if
call addmrg_to(compatm , 'So_ugustOut', &
mrg_from=compmed, mrg_fld='So_ugustOut', mrg_type='merge', mrg_fracname='ofrac')
end if
call addmrg_to(compatm , 'So_ugustOut', &
mrg_from=compmed, mrg_fld='So_ugustOut', mrg_type='merge', mrg_fracname='ofrac')
end if
end if
end if

! ---------------------------------------------------------------------
! to atm: 10 m winds including/excluding gust component
! ---------------------------------------------------------------------
if (phase == 'advertise') then
call addfld_aoflux('So_u10withGust')
call addfld_to(compatm, 'So_u10withGust')
else
if ( fldchk(is_local%wrap%FBexp(compatm), 'So_u10withGust', rc=rc)) then
if (fldchk(is_local%wrap%FBMed_aoflux_o, 'So_u10withGust', rc=rc)) then
if (trim(is_local%wrap%aoflux_grid) == 'ogrid') then
call addmap_aoflux('So_u10withGust', compatm, mapconsf, 'ofrac', ocn2atm_map)
if (add_gusts) then
if (phase == 'advertise') then
call addfld_aoflux('So_u10withGust')
call addfld_to(compatm, 'So_u10withGust')
else
if ( fldchk(is_local%wrap%FBexp(compatm), 'So_u10withGust', rc=rc)) then
if (fldchk(is_local%wrap%FBMed_aoflux_o, 'So_u10withGust', rc=rc)) then
if (trim(is_local%wrap%aoflux_grid) == 'ogrid') then
call addmap_aoflux('So_u10withGust', compatm, mapconsf, 'ofrac', ocn2atm_map)
end if
call addmrg_to(compatm , 'So_u10withGust', &
mrg_from=compmed, mrg_fld='So_u10withGust', mrg_type='merge', mrg_fracname='ofrac')
end if
call addmrg_to(compatm , 'So_u10withGust', &
mrg_from=compmed, mrg_fld='So_u10withGust', mrg_type='merge', mrg_fracname='ofrac')
end if
end if
end if
Expand Down

0 comments on commit b1e2325

Please sign in to comment.