Skip to content

mpas_atm refactor to use state structure module #780

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

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

Conversation

hkershaw-brown
Copy link
Member

@hkershaw-brown hkershaw-brown commented Dec 9, 2024

Description:

Refactor mpas_atm model_mod to use state_structure, remove progvar to vector.

Fixes issue

Various mpas_atm issues, notes in #753
fixes #523,
fixes mpas part of #389
fixes #781
#624, #768

note on subroutines, functions in mpas_atm model_mod refactor vs removed vs unchanged

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

MPAS model_mod_check and filter

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

Note still have clamp or fail being read but not used #624
Removed state_vector_to_boundary_file  and update_wind_components so I can compile with debugging flags
see comment #753 (comment)

Remove not used variables:
add_static_data_to_diags  - not used
ew_boundary_type, ns_boundary_type  -not used

 Shortened some very verbose comments.
statevector_to_boundary_file and statevector_to_analysis file need to be done.
set ids array to length nc rather than 3
Q. Are there any surface obs that are not required for RTTOV?
QTY_CLOUD_FRACTION is also limited to 1
@hkershaw-brown
Copy link
Member Author

mpas code from MPAS-Model in DART repo is missing the MPAS-Model is missing the LICENCE.

moved MPAS-model code to a directory with the LICENCE for the code
from https://github.com/MPAS-Dev/MPAS-Model/blob/master/LICENSE

fixes #781
todo: wind, domain_id
see #753 (comment)
for various notes on update_mpas_states
have netcdf utitilies module for this
@hkershaw-brown
Copy link
Member Author

@mjs2369 Jeff's not looking at mpas dart code (my bad I though he was working on this), so I'm adding you as a reviewer.
It is a decent sized pull request, so take a look. Let me know if you want to go over the code and changes, and the original code.

@hkershaw-brown hkershaw-brown requested a review from mjs2369 March 19, 2025 14:09
@jlaucar
Copy link
Contributor

jlaucar commented Mar 21, 2025 via email

hkershaw-brown and others added 2 commits March 31, 2025 09:17
find_vert_level:
- use var_id for vertisheight, maybe on nVertLevelsP1,  nVertLevels
- Use var_id for vertislevel, maybe on nVertLevelsP1,  nVertLevels
- use nVertLevels for vertispressure
- use nVertlevels if obs_qty is not in state

on_edge:
- If qty is not in state on_edge = .false.

Also too_high magic number 81 replaced with too high parameter
Removed save hanging out, module variables are saved.
@jlaucar
Copy link
Contributor

jlaucar commented Apr 7, 2025

Line 899 in model_mod.f90/qty_ok_to_interpolate
Would it be clearer to roll all the cases that have identical actions into a single case?

Line 167: Why a separate public statement for these three things?

HK fixed.

@mjs2369
Copy link
Contributor

mjs2369 commented Apr 22, 2025

Few more comment fixes:

! FIXME:
! we can hard-code R3 here since it comes from the (3d) x/y/z cartesian coordinate.

R3 is already hardcoded here, think we can remove these lines - maybe just keep the part "comes from the (3d) x/y/z cartesian coordinate" and move it next to where R3 is defined (line 4341 and 4310)

string1 = 'WARNING: There is a possibility you need to increase ''MAX_STATE_VARIABLES'''
write(string2,'(''WARNING: you have specified at least '',i4,'' perhaps more.'')')ngood

A bit confusing in the wording, is like maybe you should increase MAX_STATE_VARIABLES, but it's not really clear that's what the comment is suggesting. Also, do we want to recommend people change MAX_STATE_VARIABLES? Maybe we just make this a bit bigger now

@mjs2369
Copy link
Contributor

mjs2369 commented Apr 22, 2025

Just to clarify:

select case (qty)
case (QTY_TEMPERATURE, QTY_2M_TEMPERATURE)
qty_ok = .true.
case (QTY_SURFACE_ELEVATION, QTY_GEOPOTENTIAL_HEIGHT)
qty_ok = .true.
case (QTY_PRESSURE) ! surface pressure should be in the state !HK @todo check "should"
qty_ok = .true.
case (QTY_SKIN_TEMPERATURE, QTY_SURFACE_TYPE, QTY_CLOUD_FRACTION)
qty_ok = .true.
case (QTY_SPECIFIC_HUMIDITY, QTY_2M_SPECIFIC_HUMIDITY)
qty_ok = .true.
case (QTY_U_WIND_COMPONENT, QTY_V_WIND_COMPONENT)
if (get_varid_from_kind(anl_domid, QTY_EDGE_NORMAL_SPEED) > 0 .and. use_u_for_wind) qty_ok = .true.
case default
qty_ok = .false.
end select

Is this function (qty_ok_to_interpolate) specifying the QTYs that we can interpolate even if they are not in the state vector?

@hkershaw-brown
Copy link
Member Author

hkershaw-brown commented Apr 23, 2025

Notes meeting April 23rd 2025:

documentation for wind options is needed, what you can select and what happens.

  • question: has_edge_u .and. use_u_for_wind for the condition to call compute_u_with_rbf vs. call compute_scalar_with_barycentric if one or both is .false.

Jla: error on "deprecated" option RBF since there is a bug in the main version: #861

edit: HK depricated use_u_for_wind in aa5435e

@hkershaw-brown
Copy link
Member Author

Line 899 in model_mod.f90/qty_ok_to_interpolate Would it be clearer to roll all the cases that have identical actions into a single case?

Line 167: Why a separate public statement for these three things?

rolled case together & joined public statements in 52b87fc

@hkershaw-brown
Copy link
Member Author

Just to clarify:

select case (qty)
case (QTY_TEMPERATURE, QTY_2M_TEMPERATURE)
qty_ok = .true.
case (QTY_SURFACE_ELEVATION, QTY_GEOPOTENTIAL_HEIGHT)
qty_ok = .true.
case (QTY_PRESSURE) ! surface pressure should be in the state !HK @todo check "should"
qty_ok = .true.
case (QTY_SKIN_TEMPERATURE, QTY_SURFACE_TYPE, QTY_CLOUD_FRACTION)
qty_ok = .true.
case (QTY_SPECIFIC_HUMIDITY, QTY_2M_SPECIFIC_HUMIDITY)
qty_ok = .true.
case (QTY_U_WIND_COMPONENT, QTY_V_WIND_COMPONENT)
if (get_varid_from_kind(anl_domid, QTY_EDGE_NORMAL_SPEED) > 0 .and. use_u_for_wind) qty_ok = .true.
case default
qty_ok = .false.
end select

Is this function (qty_ok_to_interpolate) specifying the QTYs that we can interpolate even if they are not in the state vector?

Yup you got it. Some are static, some you need to have other variables.

match namelist with options in code
removed strange space characters
On advice from jla: error if a user has selected use_u_for_wind
as there is a bug in Manhattan, where all ensemble members are set to
the last ensemble member value in the rbf calculation
#861
see #780 (comment)

Documentation for mpas regristry changes needed for DART

Regional wind updates namelist options in update_bc - not sure whey
they do not use the same model_nml options, so not added to docs in
this commit.
@hkershaw-brown hkershaw-brown requested a review from Copilot June 9, 2025 16:48
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the MPAS ATM model_mod utilities to use the state_structure module for variable access, replaces the old progvar-to-vector approach, and cleans up netCDF handling across initialization, state updating, and boundary condition routines.

  • Swap out read_variables/statevector logic for state_structure_mod APIs and nc_get_variable/nc_put_variable.
  • Introduce branching logic to handle reconstructed vs. direct wind updates in both update_mpas_states.f90 and update_bc.f90.
  • Remove legacy namelist flags and model utilities, update input defaults in input.nml.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
models/mpas_atm/work/input.nml Updated default restart filename and cleaned up obsolete flags
models/mpas_atm/update_mpas_states.f90 Refactored state updates to use state_structure_mod; wind logic
models/mpas_atm/update_bc.f90 Refactored boundary updates to use state_structure_mod APIs
models/mpas_atm/mpas_dart_obs_preprocess.f90 Removed unused grid check; cleaned up metadata parameters
models/mpas_atm/MPAS_model_modules/get_reconstruct_mod.f90 Added module privacy controls
models/mpas_atm/MPAS_model_modules/get_geometry_mod.f90 Added private but omitted necessary public exports
models/mpas_atm/MPAS_model_modules/get_coeff_mod.f90 Streamlined version metadata and error handler calls
models/mpas_atm/MPAS_model_modules/LICENSE Added license file for MPAS module code
assimilation_code/modules/observations/obs_kind_mod.rst Minor RST formatting
Comments suppressed due to low confidence (3)

models/mpas_atm/MPAS_model_modules/get_geometry_mod.f90:6

  • Declaring the module as private without any public declarations means none of the routines are exported. You need to explicitly mark the intended subroutines (mpas_*, etc.) as public.
     private

models/mpas_atm/update_mpas_states.f90:116

  • The logical OR operator is malformed here ('.or.' appears attached to the string literal). It should read .or. between each equality check, for example:
if (name == 'uReconstructZonal' .or. &
    name == 'uReconstructMeridional' .or. &
    name == 'u') cycle varloop
          get_variable_name(dom_id,i) == 'uReconstructMeridional'.or. &

models/mpas_atm/work/input.nml:213

  • Missing comma between the state variable name and its quantity code. It should be 't2m', 'QTY_2M_TEMPERATURE',.
                          't2m'                    'QTY_2M_TEMPERATURE',

Comment on lines +180 to +182
call nc_put_variable(ncBckID, 'u', variable)
call nc_put_variable(ncBckID, 'uReconstructZonal', variable)
call nc_put_variable(ncBckID, 'uReconstructMeridional', variable)
Copy link
Preview

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

In this branch you intended to write the reconstructed wind array u, but you are passing variable (from the non-wind loop). Replace variable with u (and similarly for the subsequent calls writing zonal/meridional arrays).

Suggested change
call nc_put_variable(ncBckID, 'u', variable)
call nc_put_variable(ncBckID, 'uReconstructZonal', variable)
call nc_put_variable(ncBckID, 'uReconstructMeridional', variable)
call nc_put_variable(ncBckID, 'u', u)
call nc_put_variable(ncBckID, 'uReconstructZonal', ucell_dart)
call nc_put_variable(ncBckID, 'uReconstructMeridional', vcell_dart)

Copilot uses AI. Check for mistakes.

Comment on lines +256 to +257
call nc_get_variable(ncBdyID, 'lbc_ur', lbc_vcell) ! already blended in VARLOOP
call nc_get_variable(ncBdyID, 'lbc_vr', lbc_ucell) ! already blended in VALOOP
Copy link
Preview

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

The data from 'lbc_ur' (zonal reconstruct) is being read into lbc_vcell (meridional array) by mistake. These two should be swapped (lbc_urlbc_ucell, lbc_vrlbc_vcell).

Suggested change
call nc_get_variable(ncBdyID, 'lbc_ur', lbc_vcell) ! already blended in VARLOOP
call nc_get_variable(ncBdyID, 'lbc_vr', lbc_ucell) ! already blended in VALOOP
call nc_get_variable(ncBdyID, 'lbc_ur', lbc_ucell) ! already blended in VARLOOP
call nc_get_variable(ncBdyID, 'lbc_vr', lbc_vcell) ! already blended in VALOOP

Copilot uses AI. Check for mistakes.

@@ -14,83 +14,77 @@ program update_mpas_states
! The update_mpas_states_nml namelist defines the input and output file
! name lists for all ensemble members.
! The input list should be matched with output_state_file_list in &filter_nml.
!
!
! variables that are not wind are copied from one file to the another
Copy link
Preview

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

[nitpick] Minor grammar: remove "the" before "another". For example: "variables that are not wind are copied from one file to another."

Suggested change
! variables that are not wind are copied from one file to the another
! variables that are not wind are copied from one file to another

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mpas Model for Prediction Across Scales (MPAS)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mpas code from MPAS-Model in DART repo is missing the MPAS-Model is missing the LICENCE mpas model_mod needs to support interpolating values for w
3 participants