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

Select short name of variable defining ModelVerticalGrid #3182

Open
wants to merge 12 commits into
base: release/MAPL-v3
Choose a base branch
from

Conversation

pchakraborty
Copy link
Collaborator

@pchakraborty pchakraborty commented Nov 15, 2024

Types of change(s)

  • 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 change)
  • Trivial change (affects only documentation or cleanup)
  • Refactor (no functional changes, no api changes)

Checklist

  • Tested this change with a run of GEOSgcm
  • Ran the Unit Tests (make tests)

Description

  • A Model VerticalGrid is now instantiated with standard_name, units and num_levels. The method add_short_names is used to specify variable short names corresponding to edge and center vertical staggerings, which is selected at runtime using the method get_short_name.
  • Updated ComponentSpecParse::parse_geometry_spec to use the new interface.
  • Updated Test_ModelVerticalGrid.pf to use the new interface.
  • Updated vertical regridding tests to specify standard_name instead of short_name for Model VerticalGrids.
  • Cleanup of FixedLevels VerticalGrid - we didn't need MAPL_BaseMod::MAPL_GridGet after all.

Related Issue

@pchakraborty pchakraborty self-assigned this Nov 15, 2024
@pchakraborty pchakraborty added 🎁 New Feature This is a new feature 0 Diff The changes in this pull request have verified to be zero-diff with the target branch. 📈 MAPL3 MAPL 3 Related Changelog Skip Skips the Changelog Enforcer labels Nov 15, 2024
@pchakraborty pchakraborty marked this pull request as ready for review November 15, 2024 12:55
@pchakraborty pchakraborty requested a review from a team as a code owner November 15, 2024 12:55
Comment on lines +117 to +123
if (standard_name == "air_pressure") then
call vertical_grid%add_short_names(edge="PLE", center="PL")
else if (standard_name == "height") then
call vertical_grid%add_short_names(edge="ZLE", center="ZL")
else
_FAIL("unsupported standard name ["//standard_name//"]")
end if
Copy link
Collaborator

Choose a reason for hiding this comment

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

These cannot be hardwired here. At least not in the long term. How about requiring them in the yaml file when you try to specify the vertical grid that way:

vertical_grid:
    coordinate:
        dimension: pressure
        stagger: edge
        field: PLE
    coordinate:
        dimension: height
        stagger: center
        field: ZL
...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created #3184. I'll do it in a separate PR

end function new_ModelVerticalGrid_basic

integer function get_num_levels(this) result(num_levels)
class(ModelVerticalGrid), intent(in) :: this
num_levels = this%num_levels
end function get_num_levels

subroutine add_variant(this, short_name)
subroutine add_short_names(this, edge, center)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure that this is what we want here. It is conceivable that someone could provide just the edge and not the center. or vice versa. The center can in theory be derived from the edge (with some assumptions that appear to be nigh universal.)

It can stay for now, but be prepared for something where instead you specify name and staggerloc.

class(ModelVerticalGrid), intent(inout) :: this
character(*), intent(in) :: short_name
character(*), optional, intent(in) :: edge
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need an "unusable" argument here to separate out the options. Both arguments are the same type (character), so it is dangerously ambiguous which one is intended.

Copy link
Collaborator Author

@pchakraborty pchakraborty Nov 15, 2024

Choose a reason for hiding this comment

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

Not sure I understand. Both edge and center are optional arguments. Did you mean something like

   subroutine add_short_names(this, edge, unusable, center)
      class(ModelVerticalGrid), intent(inout) :: this
      character(*), optional, intent(in) :: edge
      class(KeywordEnforder), optional, intent(in) :: unusable
      character(*), optional, intent(in) :: center

      if (present(edge)) this%short_name_edge = edge
      if (present(center)) this%short_name_center = center
      _UNUSED_DUMMY(unusable)
   end subroutine add_short_names

Comment on lines 98 to 106
if (vertical_dim_spec == VERTICAL_DIM_EDGE) then
short_name = this%short_name_edge
_RETURN(_SUCCESS)
else if (vertical_dim_spec == VERTICAL_DIM_CENTER) then
short_name = this%short_name_center
_RETURN(_SUCCESS)
else
_FAIL("unsupported vertical_dim_spec")
end if
Copy link
Collaborator

Choose a reason for hiding this comment

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

War on nesting ... (Makes it more obvious that a final _RETURN(_SUCCESS) is not needed also)

Suggested change
if (vertical_dim_spec == VERTICAL_DIM_EDGE) then
short_name = this%short_name_edge
_RETURN(_SUCCESS)
else if (vertical_dim_spec == VERTICAL_DIM_CENTER) then
short_name = this%short_name_center
_RETURN(_SUCCESS)
else
_FAIL("unsupported vertical_dim_spec")
end if
if (vertical_dim_spec == VERTICAL_DIM_EDGE) then
short_name = this%short_name_edge
_RETURN(_SUCCESS)
end if
if (vertical_dim_spec == VERTICAL_DIM_CENTER) then
short_name = this%short_name_center
_RETURN(_SUCCESS)
end if
_FAIL("unsupported vertical_dim_spec")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no nesting here. Also I don't see how separate if blocks is any more readable than the if/else if/else block.

Copy link
Collaborator

@tclune tclune left a comment

Choose a reason for hiding this comment

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

A couple of minor changes requested. See inline comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 Diff The changes in this pull request have verified to be zero-diff with the target branch. Changelog Skip Skips the Changelog Enforcer 📈 MAPL3 MAPL 3 Related 🎁 New Feature This is a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants