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

Handle dimensions for promoted variables #562

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
27 changes: 27 additions & 0 deletions scripts/ccpp_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from parse_tools import init_log, set_log_to_null
from suite_objects import CallList, Group, Scheme
from metavar import CCPP_LOOP_VAR_STDNAMES
from var_props import is_horizontal_dimension

# pylint: disable=too-many-lines

Expand Down Expand Up @@ -308,6 +309,32 @@ def find_variable(self, standard_name=None, source_var=None,
self.add_variable(var, self.__run_env)
# Remove the variable from the group
group.remove_variable(standard_name)
# Make sure the variable's dimensions are available
# at the init stage (for allocation)
for group in self.groups:
# only add dimension variables to init phase calling list
if group.name == self.__suite_init_group.name:
dims = var.get_dimensions()
# replace horizontal loop dimension if necessary
for idx, dim in enumerate(dims):
if is_horizontal_dimension(dim):
if 'horizontal_loop' in dim:
dims[idx] = 'ccpp_constant_one:horizontal_dimension'
# end if
# end if
# end for
subst_dict = {'dimensions': dims}
prop_dict = var.copy_prop_dict(subst_dict=subst_dict)
temp_var = Var(prop_dict,
ParseSource(var.get_prop_value('scheme'),
var.get_prop_value('local_name'), var.context),
self.__run_env)
# Add dimensions if they're not already there
group.add_variable_dimensions(temp_var, [],
adjust_intent=True,
to_dict=group.call_list)
# end if
# end for
else:
emsg = ("Group, {}, claimed it had created {} "
"but variable was not found")
Expand Down
2 changes: 2 additions & 0 deletions test/capgen_test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ required_vars_temp="${required_vars_temp},horizontal_dimension"
required_vars_temp="${required_vars_temp},horizontal_loop_begin"
required_vars_temp="${required_vars_temp},horizontal_loop_end"
required_vars_temp="${required_vars_temp},index_of_water_vapor_specific_humidity"
required_vars_temp="${required_vars_temp},number_of_tracers"
required_vars_temp="${required_vars_temp},potential_temperature"
required_vars_temp="${required_vars_temp},potential_temperature_at_interface"
required_vars_temp="${required_vars_temp},potential_temperature_increment"
Expand All @@ -164,6 +165,7 @@ input_vars_temp="${input_vars_temp},horizontal_dimension"
input_vars_temp="${input_vars_temp},horizontal_loop_begin"
input_vars_temp="${input_vars_temp},horizontal_loop_end"
input_vars_temp="${input_vars_temp},index_of_water_vapor_specific_humidity"
input_vars_temp="${input_vars_temp},number_of_tracers"
input_vars_temp="${input_vars_temp},potential_temperature"
input_vars_temp="${input_vars_temp},potential_temperature_at_interface"
input_vars_temp="${input_vars_temp},potential_temperature_increment"
Expand Down
4 changes: 3 additions & 1 deletion test/capgen_test/temp_adjust.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ MODULE temp_adjust
!! \htmlinclude arg_table_temp_adjust_run.html
!!
subroutine temp_adjust_run(foo, timestep, temp_prev, temp_layer, qv, ps, &
errmsg, errflg, innie, outie, optsie)
to_promote, promote_pcnst, errmsg, errflg, innie, outie, optsie)

integer, intent(in) :: foo
real(kind_phys), intent(in) :: timestep
real(kind_phys), intent(inout),optional :: qv(:)
real(kind_phys), intent(inout) :: ps(:)
REAL(kind_phys), intent(in) :: temp_prev(:)
REAL(kind_phys), intent(inout) :: temp_layer(foo)
real(kind_phys), intent(in) :: to_promote(:)
real(kind_phys), intent(in) :: promote_pcnst(:)
character(len=512), intent(out) :: errmsg
integer, optional, intent(out) :: errflg
real(kind_phys), optional, intent(in) :: innie
Expand Down
14 changes: 14 additions & 0 deletions test/capgen_test/temp_adjust.meta
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
units = Pa
dimensions = (horizontal_loop_extent)
intent = inout
[ to_promote ]
standard_name = promote_this_variable_to_suite
units = K
dimensions = (horizontal_loop_extent)
type = real
kind = kind_phys
intent = in
[ promote_pcnst ]
standard_name = promote_this_variable_with_no_horizontal_dimension
units = K
dimensions = (number_of_tracers)
type = real
kind = kind_phys
intent = in
[ errmsg ]
standard_name = ccpp_error_message
long_name = Error message for error handling in CCPP
Expand Down
4 changes: 3 additions & 1 deletion test/capgen_test/temp_set.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MODULE temp_set
!! \htmlinclude arg_table_temp_set_run.html
!!
SUBROUTINE temp_set_run(ncol, lev, timestep, temp_level, temp, ps, &
errmsg, errflg)
to_promote, promote_pcnst, errmsg, errflg)
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
Expand All @@ -29,6 +29,8 @@ SUBROUTINE temp_set_run(ncol, lev, timestep, temp_level, temp, ps, &
real(kind_phys), intent(in) :: timestep
real(kind_phys), intent(in) :: ps(:)
REAL(kind_phys), INTENT(inout) :: temp_level(:, :)
real(kind_phys), intent(out) :: to_promote(:, :)
real(kind_phys), intent(out) :: promote_pcnst(:)
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errflg
!----------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions test/capgen_test/temp_set.meta
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@
units = Pa
dimensions = (horizontal_loop_extent)
intent = in
[ to_promote ]
standard_name = promote_this_variable_to_suite
units = K
dimensions = (horizontal_loop_extent, vertical_layer_dimension)
type = real
kind = kind_phys
intent = out
[ promote_pcnst ]
standard_name = promote_this_variable_with_no_horizontal_dimension
units = K
dimensions = (number_of_tracers)
type = real
kind = kind_phys
intent = out
[ errmsg ]
standard_name = ccpp_error_message
long_name = Error message for error handling in CCPP
Expand Down
1 change: 1 addition & 0 deletions test/capgen_test/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def usage(errmsg=None):
_REQUIRED_VARS_DDT = _INPUT_VARS_DDT + _OUTPUT_VARS_DDT
_PROT_VARS_TEMP = ["horizontal_loop_begin", "horizontal_loop_end",
"horizontal_dimension", "vertical_layer_dimension",
"number_of_tracers",
# Added for --debug
"index_of_water_vapor_specific_humidity",
"vertical_interface_dimension"]
Expand Down
Loading