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

Check list of state variables for required ones #776

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kdraeder
Copy link
Contributor

@kdraeder kdraeder commented Nov 14, 2024

Description:

Users can specify in model_nml which variables should be in the state vector.
They are currently free to leave out variables that are required for some calculations.
Filter writes no useful message about this problem when it fails, which results in a long debugging process.
This fix adds a function call after model_nml has been read and parsed to check whether required variables are in the state, and exit with a helpful message when one is missing.
The lists of required variables are different for cam-fv and cam-se, and may change in the future.

Fixes issue

fixes #662

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Documentation changes needed?

  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.

Tests

I ran both cam-fv and cam-se using model_nml:state_variables which contained

  1. all required variables
  2. all except for PS
  3. all except for CLDICE (cam-se only; dry mass calculation)

These were not set up using the usual setup_ scripts. They use the "assimilation-only" test set up
which is (partly?) in /glade/derecho/scratch/raeder/Test_cam-se_dry_mass.

Checklist for merging

  • Updated changelog entry
  • Documentation updated
  • Update conf.py

Checklist for release

  • Merge into main
  • Create release from the main branch with appropriate tag
  • Delete feature-branch

Testing Datasets

  • Dataset needed for testing available upon request
  • Dataset download instructions included
  • No dataset needed

models/cam-se/model_mod.f90
  Updated subroutine that checks the state vector variable list
  to stop when one of the required is not found.
  Converted message from "looking for" to "did not find".
  Tested for "all variables", "missing PS", and "missing CLDICE".
models/cam-se/model_mod.nml
  Added state vector variable list.
models/cam-se/work/input.nml
  Added the dry mass namelist variables to model_nml
models/cam-fv/model_mod.f90
  Installed subroutine to check whether PS is in the state vector.
  It's required for assimilation of other state variables.
  Tested for "all variables" and "missing PS".
@kdraeder kdraeder added Bug Something isn't working Minor Minor functionality, non-critical data; easy fix CAM Community Atmosphere Model CAM-SE Community Atmosphere Model Spectral Element Core labels Nov 14, 2024
@kdraeder kdraeder self-assigned this Nov 14, 2024
Copy link
Member

@hkershaw-brown hkershaw-brown left a comment

Choose a reason for hiding this comment

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

Hi Kevin,

Functionally the code looks to be doing the checks for the required state variables. At the moment you code seems a bit over complicated, I've put some comments on simplifying it.

You have some debugging statements, that will only print on task 0. I'd advocated for not putting these debugging statements in (see comment on the ~3 places these debug statements were added)

The change in value for the istatus (16 vs 26) - it would be good to know what this change was for.

Do you have a cam-se case I can grab on Derecho that I can add to our test cases? If not I can spin one up.

Cheers,
Helen

models/cam-se/model_mod.f90 Show resolved Hide resolved
models/cam-se/model_mod.f90 Show resolved Hide resolved
models/cam-se/model_mod.f90 Show resolved Hide resolved
models/cam-se/model_mod.f90 Show resolved Hide resolved
models/cam-se/model_mod.f90 Show resolved Hide resolved
models/cam-se/model_mod.f90 Show resolved Hide resolved
character(len=32), dimension(10) :: var_names
integer:: i, varid

data var_names /'PS', 'Q', 'CLDLIQ', 'CLDICE', 6*''/
Copy link
Member

Choose a reason for hiding this comment

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

functionally this looks to be doing what is should, but it seems a little over complicated.

Why do you have 10 var_names, but only 4 names, and 6 blank strings?

Why is PS in the var_names array?
You could check for PS (always required), then loop though your sometimes required variables.
That way

i = 1
i = i+1
if (dry_mass_vertical_coordinate .and. precise_dry_mass_get_close) then
do while (var_names(i) .ne. '')
  i = i + 1
enddo
endif

becomes

check for PS
if (dry_mass_vertical_coordinate .and. precise_dry_mass_get_close) then
  do i = 1, 3
  enddo
endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intent was to write generic and flexible code; more fields may need to be added to var_names in the future and it would be nice if the only required change is to var_names, and not finding where var_names is dimensioned and then used, and changing the sizes there. Although size(var_names) coud be used for the loop.
A more comprehensive fix in the future might involve var_names being passed in, so the code I wrote would be more easily adapted to that.
But if the priority is short code to solve the immediate problem, then I'll do that.

models/cam-se/model_mod.nml Show resolved Hide resolved
models/cam-se/model_mod.f90 Show resolved Hide resolved
Comment on lines +2394 to +2397
character(len=32), dimension(10) :: var_names
integer:: i, varid

data var_names /'PS', 9*''/
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need a data statement & and i variable here
You only have 'PS' so you could call

varid = get_varid_from_varname(domain_id, 'PS')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was making it consistent with the cam-se version to make comparisons easier, and to keep the flexibility for adding fields to the list in the future.
If that's misguided I'll simplify the cam-fv version.

@hkershaw-brown
Copy link
Member

Hi Kevin, just checking in on this cam-se pull request and the review comments. Is your plan to work on this?

@kdraeder
Copy link
Contributor Author

I do plan to finish this after reviewing 740 for Jeff.
I lost momentum on it during the AGU scramble.
Thanks for all of your comments!

@kdraeder
Copy link
Contributor Author

kdraeder commented Jan 3, 2025

The change of istatus values from {16,17} to {26,27} in get_se_four_nonstate_values was useful to me because {16,17} are already used in get_se_four_state_values, so I couldn't see which subroutine was returning a non-0 value. It doesn't seem to break anything or add code, so I left it in to save time in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working CAM Community Atmosphere Model CAM-SE Community Atmosphere Model Spectral Element Core Minor Minor functionality, non-critical data; easy fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cam-se fails if CLDICE, CLDLIQ, or Q (or PS) is not in the state vector
2 participants