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

Capgen in SCM: Fix to allow for scheme subcycling. #633

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/ccpp_datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ def _add_suite_object(parent, suite_object):
obj_elem.set("dimension_name", suite_object.dimension_name)
# end if
if isinstance(suite_object, Subcycle):
obj_elem.set("loop", suite_object.loop)
obj_elem.set("loop", suite_object._loop)
# end if
for obj_part in suite_object.parts:
_add_suite_object(obj_elem, obj_part)
Expand Down
25 changes: 25 additions & 0 deletions scripts/metavar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1677,12 +1677,37 @@ def add_variable(self, newvar, run_env, exists_ok=False, gen_unique=False,
context=newvar.context)
# end if
# end if
# Check if local_name exists in Group. If applicable, Create new
dustinswales marked this conversation as resolved.
Show resolved Hide resolved
# variable with uniquie name. There are two instances when new names are
dustinswales marked this conversation as resolved.
Show resolved Hide resolved
# created:
# - Same <local_name> used in different DDTs.
# - Different <standard_name> using the same <local_name> in a Group.
# During the Group analyze phase, <gen_unique> is True.
lname = newvar.get_prop_value('local_name')
lvar = self.find_local_name(lname)
if lvar is not None:
# Check if <lvar> is part of a different DDT than <newvar>.
# The API uses the full variable references when calling the Group Caps,
# <lvar.call_string(self))> and <newvar.call_string(self)>.
# Within the context of a full reference, it is allowable for local_names
# to be the same in different data containers.
newvar_callstr = newvar.call_string(self)
lvar_callstr = lvar.call_string(self)
if newvar_callstr and lvar_callstr:
if newvar_callstr != lvar_callstr:
if not gen_unique:
exists_ok = True
# end if
# end if
# end if
if gen_unique:
new_lname = self.new_internal_variable_name(prefix=lname)
newvar = newvar.clone(new_lname)
# Local_name needs to be the local_name for the new
dustinswales marked this conversation as resolved.
Show resolved Hide resolved
# internal variable, otherwise multiple instances of the same
# local_name in the Group cap will all be overwritten with the
# same local_name
lname = new_lname
elif not exists_ok:
errstr = 'Invalid local_name: {} already registered{}'
cstr = context_string(lvar.source.context, with_comma=True)
Expand Down
13 changes: 6 additions & 7 deletions scripts/suite_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2006,12 +2006,11 @@ def analyze(self, phase, group, scheme_library, suite_vars, level):
if self.name is None:
self.name = "subcycle_index{}".format(level)
# end if
# Create a variable for the loop index
self.add_variable(Var({'local_name':self.name,
'standard_name':'loop_variable',
'type':'integer', 'units':'count',
'dimensions':'()'}, _API_SOURCE, self.run_env),
self.run_env)
# Create a Group variable for the subcycle index.
newvar = Var({'local_name':self.name, 'standard_name':self.name,
'type':'integer', 'units':'count', 'dimensions':'()'},
_API_LOCAL, self.run_env)
group.manage_variable(newvar)
# Handle all the suite objects inside of this subcycle
scheme_mods = set()
for item in self.parts:
Expand All @@ -2025,7 +2024,7 @@ def analyze(self, phase, group, scheme_library, suite_vars, level):

def write(self, outfile, errcode, errmsg, indent):
"""Write code for the subcycle loop, including contents, to <outfile>"""
outfile.write('do {} = 1, {}'.format(self.name, self.loop), indent)
outfile.write('do {} = 1, {}'.format(self.name, self._loop), indent)
# Note that 'scheme' may be a sybcycle or other construct
for item in self.parts:
item.write(outfile, errcode, errmsg, indent+1)
Expand Down
3 changes: 2 additions & 1 deletion test/var_compatibility_test/effr_diag.F90
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ end subroutine effr_diag_init
!> \section arg_table_effr_diag_run Argument Table
!! \htmlinclude arg_table_effr_diag_run.html
!!
subroutine effr_diag_run( effrr_in, errmsg, errflg)
subroutine effr_diag_run( effrr_in, scalar_var, errmsg, errflg)

real(kind_phys), intent(in) :: effrr_in(:,:)
real(kind_phys), intent(in) :: scalar_var
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errflg
!----------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions test/var_compatibility_test/effr_diag.meta
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
kind = kind_phys
intent = in
top_at_one = True
[ scalar_var ]
standard_name = scalar_variable_for_testing_c
long_name = unused scalar variable C
units = m
dimensions = ()
type = real
kind = kind_phys
intent = in
[ errmsg ]
standard_name = ccpp_error_message
long_name = Error message for error handling in CCPP
Expand Down
3 changes: 2 additions & 1 deletion test/var_compatibility_test/effr_post.F90
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ end subroutine effr_post_init
!> \section arg_table_effr_post_run Argument Table
!! \htmlinclude arg_table_effr_post_run.html
!!
subroutine effr_post_run( effrr_inout, errmsg, errflg)
subroutine effr_post_run( effrr_inout, scalar_var, errmsg, errflg)

real(kind_phys), intent(inout) :: effrr_inout(:,:)
real(kind_phys), intent(in) :: scalar_var
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errflg
!----------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions test/var_compatibility_test/effr_post.meta
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
type = real
kind = kind_phys
intent = inout
[ scalar_var ]
standard_name = scalar_variable_for_testing_b
long_name = unused scalar variable B
units = m
dimensions = ()
type = real
kind = kind_phys
intent = in
[ errmsg ]
standard_name = ccpp_error_message
long_name = Error message for error handling in CCPP
Expand Down
3 changes: 2 additions & 1 deletion test/var_compatibility_test/effr_pre.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ end subroutine effr_pre_init
!> \section arg_table_effr_pre_run Argument Table
!! \htmlinclude arg_table_effr_pre_run.html
!!
subroutine effr_pre_run( effrr_inout, errmsg, errflg)
subroutine effr_pre_run( effrr_inout, scalar_var, errmsg, errflg)

real(kind_phys), intent(inout) :: effrr_inout(:,:)
real(kind_phys), intent(in) :: scalar_var
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errflg
!----------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions test/var_compatibility_test/effr_pre.meta
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
type = real
kind = kind_phys
intent = inout
[ scalar_var ]
standard_name = scalar_variable_for_testing_a
long_name = unused scalar variable A
units = m
dimensions = ()
type = real
kind = kind_phys
intent = in
[ errmsg ]
standard_name = ccpp_error_message
long_name = Error message for error handling in CCPP
Expand Down
6 changes: 6 additions & 0 deletions test/var_compatibility_test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ required_vars_var_compatibility="${required_vars_var_compatibility},horizontal_d
required_vars_var_compatibility="${required_vars_var_compatibility},horizontal_loop_begin"
required_vars_var_compatibility="${required_vars_var_compatibility},horizontal_loop_end"
required_vars_var_compatibility="${required_vars_var_compatibility},scalar_variable_for_testing"
required_vars_var_compatibility="${required_vars_var_compatibility},scalar_variable_for_testing_a"
required_vars_var_compatibility="${required_vars_var_compatibility},scalar_variable_for_testing_b"
required_vars_var_compatibility="${required_vars_var_compatibility},scalar_variable_for_testing_c"
required_vars_var_compatibility="${required_vars_var_compatibility},scheme_order_in_suite"
required_vars_var_compatibility="${required_vars_var_compatibility},vertical_layer_dimension"
input_vars_var_compatibility="cloud_graupel_number_concentration"
Expand All @@ -158,6 +161,9 @@ input_vars_var_compatibility="${input_vars_var_compatibility},horizontal_dimensi
input_vars_var_compatibility="${input_vars_var_compatibility},horizontal_loop_begin"
input_vars_var_compatibility="${input_vars_var_compatibility},horizontal_loop_end"
input_vars_var_compatibility="${input_vars_var_compatibility},scalar_variable_for_testing"
input_vars_var_compatibility="${input_vars_var_compatibility},scalar_variable_for_testing_a"
input_vars_var_compatibility="${input_vars_var_compatibility},scalar_variable_for_testing_b"
input_vars_var_compatibility="${input_vars_var_compatibility},scalar_variable_for_testing_c"
input_vars_var_compatibility="${input_vars_var_compatibility},scheme_order_in_suite"
input_vars_var_compatibility="${input_vars_var_compatibility},vertical_layer_dimension"
output_vars_var_compatibility="ccpp_error_code,ccpp_error_message"
Expand Down
10 changes: 8 additions & 2 deletions test/var_compatibility_test/test_host.F90
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,16 @@ program test

character(len=cs), target :: test_parts1(1) = (/ 'radiation ' /)

character(len=cm), target :: test_invars1(9) = (/ &
character(len=cm), target :: test_invars1(12) = (/ &
'effective_radius_of_stratiform_cloud_rain_particle ', &
'effective_radius_of_stratiform_cloud_liquid_water_particle', &
'effective_radius_of_stratiform_cloud_snow_particle ', &
'effective_radius_of_stratiform_cloud_graupel ', &
'cloud_graupel_number_concentration ', &
'scalar_variable_for_testing ', &
'scalar_variable_for_testing_a ', &
'scalar_variable_for_testing_b ', &
'scalar_variable_for_testing_c ', &
'scheme_order_in_suite ', &
'flag_indicating_cloud_microphysics_has_graupel ', &
'flag_indicating_cloud_microphysics_has_ice '/)
Expand All @@ -374,7 +377,7 @@ program test
'scheme_order_in_suite '/)


character(len=cm), target :: test_reqvars1(13) = (/ &
character(len=cm), target :: test_reqvars1(16) = (/ &
'ccpp_error_code ', &
'ccpp_error_message ', &
'effective_radius_of_stratiform_cloud_rain_particle ', &
Expand All @@ -385,6 +388,9 @@ program test
'cloud_graupel_number_concentration ', &
'cloud_ice_number_concentration ', &
'scalar_variable_for_testing ', &
'scalar_variable_for_testing_a ', &
'scalar_variable_for_testing_b ', &
'scalar_variable_for_testing_c ', &
'scheme_order_in_suite ', &
'flag_indicating_cloud_microphysics_has_graupel ', &
'flag_indicating_cloud_microphysics_has_ice '/)
Expand Down
4 changes: 4 additions & 0 deletions test/var_compatibility_test/test_host_data.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ module test_host_data
ncg, & ! number concentration of cloud graupel
nci ! number concentration of cloud ice
real(kind_phys) :: scalar_var
real(kind_phys) :: scalar_varA
real(kind_phys) :: scalar_varB
real(kind_phys) :: scalar_varC
integer :: scheme_order

end type physics_state

public allocate_physics_state
Expand Down
21 changes: 21 additions & 0 deletions test/var_compatibility_test/test_host_data.meta
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@
dimensions = ()
type = real
kind = kind_phys
[scalar_varA]
standard_name = scalar_variable_for_testing_a
long_name = unused scalar variable A
units = m
dimensions = ()
type = real
kind = kind_phys
[scalar_varB]
standard_name = scalar_variable_for_testing_b
long_name = unused scalar variable B
units = m
dimensions = ()
type = real
kind = kind_phys
[scalar_varC]
standard_name = scalar_variable_for_testing_c
long_name = unused scalar variable C
units = m
dimensions = ()
type = real
kind = kind_phys
[scheme_order]
standard_name = scheme_order_in_suite
long_name = scheme order in suite definition file
Expand Down
3 changes: 3 additions & 0 deletions test/var_compatibility_test/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def usage(errmsg=None):
"effective_radius_of_stratiform_cloud_graupel",
"cloud_graupel_number_concentration",
"scalar_variable_for_testing",
"scalar_variable_for_testing_a",
"scalar_variable_for_testing_b",
"scalar_variable_for_testing_c",
"scheme_order_in_suite",
"flag_indicating_cloud_microphysics_has_graupel",
"flag_indicating_cloud_microphysics_has_ice"]
Expand Down
4 changes: 3 additions & 1 deletion test/var_compatibility_test/var_compatibility_suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<scheme>effr_pre</scheme>
<scheme>effr_calc</scheme>
<scheme>effr_post</scheme>
<scheme>effr_diag</scheme>
<subcycle loop="1">
dustinswales marked this conversation as resolved.
Show resolved Hide resolved
<scheme>effr_diag</scheme>
</subcycle>
</group>
</suite>