Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getters and setters for variables used to override surface radiative fluxes #244

Merged
merged 36 commits into from
Mar 22, 2021

Conversation

spencerkclark
Copy link
Member

@spencerkclark spencerkclark commented Feb 23, 2021

This PR is tied to ai2cm/fv3gfs-fortran#158. It adds getters and setters for four fields in the fortran model:

  • Statein%adjsfcdlw_override (the downward longwave radiative flux at the surface seen by the land surface model)
  • Statein%adjsfcdsw_override (the downward shortwave radiative flux at the surface seen by the land surface model)
  • Statein%adjsfcnsw_override (the net shortwave radiative flux at the surface seen by the land surface model).
  • Radtend%sfalb (the average surface albedo)

The first three are only valid if gfs_physics_nml.override_surface_radiative_fluxes is set to .true. in the fortran namelist (if it is not set to .true., memory will not be allocated for them). We add a flag to the wrapper to be able to dynamically check this; if it is not set and a user asks to get or set one of these variables, then an informative error will be raised (rather than a model segmentation fault). The test infrastructure for the setters is modified to check this.

In adding the new boolean flag, it was discovered that there was a bug in the implementation of earlier boolean flags (#244 (comment)). We fixed this, and added more comprehensive tests of the flags, which did not exist previously. In addition we added a flag for the physics timestep, dt_atmos, using the preexisting get_physics_timestep_subroutine subroutine.

Finally, to check that the fortran diagnostics for the radiative fluxes were updated as expected, we added an additional set of tests (which basically are an automated way of doing what we did in this notebook). We also add a test that ensures that modifying the surface radiative fluxes modifies the temperature after a timestep (indicating that the modifications are being felt by the land surface model).

spencerkclark added a commit to ai2cm/fv3gfs-fortran that referenced this pull request Mar 12, 2021
#158)

This PR adds three variables to the `Statein` derived type that we can use to override the downward longwave, downward shortwave, and net shortwave radiative fluxes at the surface.  By default these variables are not allocated or used.  To use them one must set the `gfs_physics_nml.override_surface_radiative_fluxes` namelist parameter to `.true.`.   Setters for these variables in the Python wrapper can be found in a [complementary PR](ai2cm/fv3gfs-wrapper#244).

A significant amount of work in this PR also goes into refactoring the diagnostics related to these variables.  When running in a mode where we override these fluxes, we want the usual fortran diagnostics  -- namely `DLWRF`, `DSWRF`, `USWRF`, `DLWRFI`, `DSWRFI`, and `USWRFI` -- to correspond to the overriding fluxes.  We modify things such that this is the case.  In addition, to enable diagnosis of what the traditional radiation code would predict for these fluxes, we add diagnostics with the suffix `_from_rrtmg`.  [This notebook](https://github.com/VulcanClimateModeling/explore/blob/master/spencerc/2021-03-04-predicting-radiative-fluxes-online/2021-03-11-verify-diagnostics.ipynb) checks to make sure all of these diagnostics work as expected in a case where we override the fluxes with ML (the regression tests ensure that things continue to work when we are not overriding the fluxes).

Care has been made to ensure that if `gfs_physics_nml.override_surface_radiative_fluxes` is set to `.false.`, the model will run identically to before, both in producing bit-for-bit identical results and in terms of memory allocated during runtime.  When it is set to `.true.` the model will use more memory to accommodate the arrays used for storing the RRTMG diagnostics as well as the overriding fluxes in the `Statein`.
@brianhenn brianhenn marked this pull request as ready for review March 16, 2021 00:16
@spencerkclark spencerkclark changed the title Add getters and setters for radiative flux correction variables Add getters and setters for variables used to override surface radiative fluxes Mar 16, 2021
Copy link
Collaborator

@mcgibbon mcgibbon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names for these new getters should be adjusted to be more in line with standard_name conventions. Are we sure the adjustments work? It would be worth adding a test for the behavior, since the feature is fairly complicated and there is an obvious way to test it (apply the override, confirm that it gets used, and also when you tell it not to override, confirm the override does not get used).

fv3gfs/wrapper/physics_properties.json Outdated Show resolved Hide resolved
fv3gfs/wrapper/physics_properties.json Outdated Show resolved Hide resolved
fv3gfs/wrapper/physics_properties.json Show resolved Hide resolved
tests/default_config.yml Outdated Show resolved Hide resolved
Copy link
Collaborator

@mcgibbon mcgibbon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! A couple small updates if you have the time.

templates/_wrapper.pyx Show resolved Hide resolved
tests/test_all.py Outdated Show resolved Hide resolved
tests/test_flags.py Show resolved Hide resolved
tests/test_getters.py Show resolved Hide resolved
tests/test_setters.py Outdated Show resolved Hide resolved
tests/test_setters.py Outdated Show resolved Hide resolved
tests/util.py Outdated Show resolved Hide resolved
@spencerkclark spencerkclark merged commit 1d04999 into master Mar 22, 2021
@spencerkclark spencerkclark deleted the new-getters-and-setters branch March 22, 2021 13:39
spencerkclark added a commit to ai2cm/SHiELD-wrapper that referenced this pull request Nov 2, 2023
This PR ports the ability to override the surface radiative fluxes seen by the land surface model from the wrapper.  This was split across two PRs originally in the case of FV3GFS:

- ai2cm/fv3gfs-fortran#158
- ai2cm/fv3gfs-wrapper#244

This depends on the fortran changes made in:

- NOAA-GFDL/SHiELD_physics#31
- NOAA-GFDL/atmos_drivers#31

which have now been merged, and incorporated into this repo via #11.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants