Skip to content

Commit

Permalink
Replace resolution str with float
Browse files Browse the repository at this point in the history
  • Loading branch information
cbegeman committed Mar 3, 2023
1 parent 4319588 commit 511ff3a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 44 deletions.
59 changes: 31 additions & 28 deletions compass/ocean/tests/turbulence_closure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def __init__(self, mpas_core):
"""
super().__init__(mpas_core=mpas_core, name='turbulence_closure')

for resolution in ['10km']:
for resolution in [1e4]:
self.add_test_case(
DecompTest(test_group=self, resolution=resolution))
self.add_test_case(
RestartTest(test_group=self, resolution=resolution))
for resolution in ['1m', '2m', '10km']:
for resolution in [1, 2, 1e4]:
for forcing in ['cooling', 'evaporation']:
self.add_test_case(
Default(test_group=self, resolution=resolution, forcing=forcing))
Expand All @@ -32,38 +32,41 @@ def configure(resolution, forcing, config):
Parameters
----------
resolution : str
The resolution of the test case
resolution : float
The resolution of the test case in meters
config : configparser.ConfigParser
Configuration options for this test case
"""
res_params = {'10km': {'nx': 16,
'ny': 50,
'dc': 10e3},
'2m': {'nx': 150,
'ny': 150,
'dc': 2},
'1m': {'nx': 128,
'ny': 128,
'dc': 1}}
vert_params = {'10km': {'vert_levels': 20,
'bottom_depth': 1e3},
'2m': {'vert_levels': 50,
'bottom_depth': 100.0},
'1m': {'vert_levels': 128,
'bottom_depth': 128.0}}
# The resolution parameters are different for different resolutions
# to match existing simulations
if resolution > 1e3:
nx = 16
ny = 50
vert_levels = 20
bottom_depth = 1e3
elif resolution <= 1e3 and resolution > 5:
nx = 50
ny = 50
vert_levels = 50
bottom_depth = 100.0
elif resolution <= 5 and resolution > 1:
nx = 150
ny = 150
vert_levels = 50
bottom_depth = 100.0
elif resolution <= 1:
nx = 128
ny = 128
vert_levels = 128
bottom_depth = 128.0

if resolution not in res_params:
raise ValueError(f'Unsupported resolution {resolution}. '
f'Supported values are: {list(res_params)}')

res_params = res_params[resolution]
for param in res_params:
config.set('turbulence_closure', param, f'{res_params[param]}')
vert_params = vert_params[resolution]
for param in vert_params:
config.set('vertical_grid', param, f'{vert_params[param]}')
config.set('turbulence_closure', 'nx', f'{nx}')
config.set('turbulence_closure', 'ny', f'{ny}')
config.set('turbulence_closure', 'dc', f'{resolution}')
config.set('vertical_grid', 'vert_levels', f'{vert_levels}')
config.set('vertical_grid', 'bottom_depth', f'{bottom_depth}')

if forcing == 'cooling':
config.set('turbulence_closure', 'surface_heat_flux', '-100')
Expand Down
14 changes: 9 additions & 5 deletions compass/ocean/tests/turbulence_closure/decomp_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class DecompTest(TestCase):
Attributes
----------
resolution : str
The resolution of the test case
resolution : float
The resolution of the test case in meters
"""

def __init__(self, test_group, resolution, forcing='cooling'):
Expand All @@ -25,12 +25,16 @@ def __init__(self, test_group, resolution, forcing='cooling'):
test_group : compass.ocean.tests.turbulence_closure.TurbulenceClosure
The test group that this test case belongs to
resolution : str
The resolution of the test case
resolution : float
The resolution of the test case in meters
"""
name = 'decomp_test'
self.resolution = resolution
subdir = f'{resolution}/{forcing}/{name}'
if resolution >= 1e3:
res_name = f'{int(resolution/1e3)}km'
else:
res_name = f'{int(resolution)}m'
subdir = f'{res_name}/{forcing}/{name}'
super().__init__(test_group=test_group, name=name,
subdir=subdir)

Expand Down
16 changes: 10 additions & 6 deletions compass/ocean/tests/turbulence_closure/default/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Default(TestCase):
Attributes
----------
resolution : str
The resolution of the test case
resolution : float
The resolution of the test case in meters
"""

def __init__(self, test_group, resolution, forcing='cooling'):
Expand All @@ -26,20 +26,24 @@ def __init__(self, test_group, resolution, forcing='cooling'):
test_group : compass.ocean.tests.turbulence_closure.TurbulenceClosure
The test group that this test case belongs to
resolution : str
The resolution of the test case
resolution : float
The resolution of the test case in meters
forcing: str
The forcing applied to the test case
"""
name = 'default'
self.resolution = resolution
self.forcing = forcing
subdir = f'{resolution}/{forcing}/{name}'
if resolution >= 1e3:
res_name = f'{int(resolution/1e3)}km'
else:
res_name = f'{int(resolution)}m'
subdir = f'{res_name}/{forcing}/{name}'
super().__init__(test_group=test_group, name=name,
subdir=subdir)

if resolution == '1m' or resolution == '2m':
if resolution <= 5:
ntasks = 128
plot_comparison=True
else:
Expand Down
14 changes: 9 additions & 5 deletions compass/ocean/tests/turbulence_closure/restart_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class RestartTest(TestCase):
Attributes
----------
resolution : str
The resolution of the test case
resolution : float
The resolution of the test case in meters
"""

def __init__(self, test_group, resolution, forcing='cooling'):
Expand All @@ -26,12 +26,16 @@ def __init__(self, test_group, resolution, forcing='cooling'):
test_group : compass.ocean.tests.baroclinic_channel.BaroclinicChannel
The test group that this test case belongs to
resolution : str
The resolution of the test case
resolution : float
The resolution of the test case in meters
"""
name = 'restart_test'
self.resolution = resolution
subdir = f'{resolution}/{forcing}/{name}'
if resolution >= 1e3:
res_name = f'{int(resolution/1e3)}km'
else:
res_name = f'{int(resolution)}m'
subdir = f'{res_name}/{forcing}/{name}'
super().__init__(test_group=test_group, name=name,
subdir=subdir)

Expand Down

0 comments on commit 511ff3a

Please sign in to comment.