Skip to content
Merged
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
18 changes: 10 additions & 8 deletions scripts/suite_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
'suites':''})

###############################################################################
def new_suite_object(item, context, parent, run_env):
def new_suite_object(item, context, parent, run_env, loop_count=0):
###############################################################################
"'Factory' method to create the appropriate suite object from XML"
new_item = None
if item.tag == 'subcycle':
new_item = Subcycle(item, context, parent, run_env)
new_item = Subcycle(item, context, parent, run_env, loop_count=loop_count)
elif item.tag == 'scheme':
new_item = Scheme(item, context, parent, run_env)
elif item.tag == _API_TIMESPLIT_TAG:
Expand Down Expand Up @@ -2039,16 +2039,17 @@ def dimension_name(self):
class Subcycle(SuiteObject):
"""Class to represent a subcycled group of schemes or scheme collections"""

def __init__(self, sub_xml, context, parent, run_env):
def __init__(self, sub_xml, context, parent, run_env, loop_count=0):
self._loop_extent = sub_xml.get('loop', "1") # Number of iterations
self._loop = None
# See if our loop variable is an interger or a variable
# See if our loop variable is an integer or a variable
try:
_ = int(self._loop_extent)
self._loop = self._loop_extent
self._loop_var_int = True
name = f"loop{self._loop}"
name = f"loop{loop_count}"
super().__init__(name, context, parent, run_env, active_call_list=False)
loop_count = loop_count + 1
except ValueError:
self._loop_var_int = False
lvar = parent.find_variable(standard_name=self._loop_extent, any_scope=True)
Expand All @@ -2059,12 +2060,13 @@ def __init__(self, sub_xml, context, parent, run_env):
self._loop_var_int = False
self._loop = lvar.get_prop_value('local_name')
# end if
name = f"loop_{self._loop_extent}"[0:63]
name = f"loop{loop_count}_{self._loop_extent}"[0:63]
super().__init__(name, context, parent, run_env, active_call_list=True)
parent.add_call_list_variable(lvar)
parent.add_call_list_variable(lvar, exists_ok=True)
loop_count = loop_count + 1
# end try
for item in sub_xml:
new_item = new_suite_object(item, context, self, run_env)
new_item = new_suite_object(item, context, self, run_env, loop_count=loop_count)
self.add_part(new_item)
# end for

Expand Down
5 changes: 5 additions & 0 deletions test/var_compatibility_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Tests the variable compatibility object (`VarCompatObj`):
- Vertical array flipping (`top_at_one=true`)
- Kind conversions (`kind_phys <-> 8`)
- And various combinations thereof of the above cases
- Also tests subcycles:
- Nested subcycles
- A subcycle with dynamic iteration length (defined by a standard name) and a subcycle with fixed/integer iteration length
- Multiple ubcycles with same standard name defining the iteration length
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- Multiple ubcycles with same standard name defining the iteration length
- Multiple subcycles with same standard name defining the iteration length

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed!

- Nested subcycles with the same iteration length

## Building/Running

Expand Down
2 changes: 1 addition & 1 deletion test/var_compatibility_test/test_host_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ logical function compare_data()
real(kind_phys), parameter :: effrr_expected = 1.0E-3 ! 1000 microns, in meter
real(kind_phys), parameter :: effrl_expected = 5.0E-5 ! 50 microns, in meter
real(kind_phys), parameter :: effri_expected = 7.5E-5 ! 75 microns, in meter
real(kind_phys), parameter :: effrs_expected = 5.1E-4 ! 510 microns, in meter
real(kind_phys), parameter :: effrs_expected = 5.2E-4 ! 520 microns, in meter
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, why this change? Is every subcycle adding 10 microns?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

correct, I modified the SDF to do a total of 4 subcycles (2 nested within 2) rather than 2.

Actually, now that I look at it, I don't understand it! The effr_calc_run subroutine that is run 4 times instead of 2 adds 10.0 / 6.0 microns each iteration, which doesn't add up either with my mods or the existing expectation... I shall look into this!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nevermind, it used to be doing 3*2 = 6 subcycles, so adding 10/6 6 times for a total of 10 microns.

With my updates, it's now doing 322 = 12 subcycles, so adding 20 microns.

So all is OK

real(kind_phys), parameter :: scalar_expected = 2.0E3 ! 2 km, in meter
real(kind_phys), parameter :: tke_expected = 10.0 ! 10 J kg-1
real(kind_phys), parameter :: tolerance = 1.0E-6 ! used as scaling factor for expected value
Expand Down
6 changes: 5 additions & 1 deletion test/var_compatibility_test/var_compatibility_suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
<subcycle loop="num_subcycles_for_effr">
<scheme>effr_pre</scheme>
<subcycle loop="2">
<scheme>effr_calc</scheme>
<subcycle loop="2">
<scheme>effr_calc</scheme>
</subcycle>
</subcycle>
<scheme>effr_post</scheme>
</subcycle>
<subcycle loop="num_subcycles_for_effr">
</subcycle>
<scheme>effr_diag</scheme>
<scheme>rad_lw</scheme>
<scheme>rad_sw</scheme>
Expand Down