Skip to content

Commit 201bcd7

Browse files
committed
Replace resolution str with float
1 parent ceb2c4d commit 201bcd7

File tree

4 files changed

+59
-44
lines changed

4 files changed

+59
-44
lines changed

compass/ocean/tests/turbulence_closure/__init__.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ def __init__(self, mpas_core):
1515
"""
1616
super().__init__(mpas_core=mpas_core, name='turbulence_closure')
1717

18-
for resolution in ['10km']:
18+
for resolution in [1e4]:
1919
self.add_test_case(
2020
DecompTest(test_group=self, resolution=resolution))
2121
self.add_test_case(
2222
RestartTest(test_group=self, resolution=resolution))
23-
for resolution in ['1m', '2m', '10km']:
23+
for resolution in [1, 2, 1e4]:
2424
for forcing in ['cooling', 'evaporation']:
2525
self.add_test_case(
2626
Default(test_group=self, resolution=resolution, forcing=forcing))
@@ -32,38 +32,41 @@ def configure(resolution, forcing, config):
3232
3333
Parameters
3434
----------
35-
resolution : str
36-
The resolution of the test case
35+
resolution : float
36+
The resolution of the test case in meters
3737
3838
config : configparser.ConfigParser
3939
Configuration options for this test case
4040
"""
41-
res_params = {'10km': {'nx': 16,
42-
'ny': 50,
43-
'dc': 10e3},
44-
'2m': {'nx': 150,
45-
'ny': 150,
46-
'dc': 2},
47-
'1m': {'nx': 128,
48-
'ny': 128,
49-
'dc': 1}}
50-
vert_params = {'10km': {'vert_levels': 20,
51-
'bottom_depth': 1e3},
52-
'2m': {'vert_levels': 50,
53-
'bottom_depth': 100.0},
54-
'1m': {'vert_levels': 128,
55-
'bottom_depth': 128.0}}
41+
# The resolution parameters are different for different resolutions
42+
# to match existing simulations
43+
if resolution > 1e3:
44+
nx = 16
45+
ny = 50
46+
vert_levels = 20
47+
bottom_depth = 1e3
48+
elif resolution <= 1e3 and resolution > 5:
49+
nx = 50
50+
ny = 50
51+
vert_levels = 50
52+
bottom_depth = 100.0
53+
elif resolution <= 5 and resolution > 1:
54+
nx = 150
55+
ny = 150
56+
vert_levels = 50
57+
bottom_depth = 100.0
58+
elif resolution <= 1:
59+
nx = 128
60+
ny = 128
61+
vert_levels = 128
62+
bottom_depth = 128.0
5663

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

61-
res_params = res_params[resolution]
62-
for param in res_params:
63-
config.set('turbulence_closure', param, f'{res_params[param]}')
64-
vert_params = vert_params[resolution]
65-
for param in vert_params:
66-
config.set('vertical_grid', param, f'{vert_params[param]}')
65+
config.set('turbulence_closure', 'nx', f'{nx}')
66+
config.set('turbulence_closure', 'ny', f'{ny}')
67+
config.set('turbulence_closure', 'dc', f'{resolution}')
68+
config.set('vertical_grid', 'vert_levels', f'{vert_levels}')
69+
config.set('vertical_grid', 'bottom_depth', f'{bottom_depth}')
6770

6871
if forcing == 'cooling':
6972
config.set('turbulence_closure', 'surface_heat_flux', '-100')

compass/ocean/tests/turbulence_closure/decomp_test/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class DecompTest(TestCase):
1212
1313
Attributes
1414
----------
15-
resolution : str
16-
The resolution of the test case
15+
resolution : float
16+
The resolution of the test case in meters
1717
"""
1818

1919
def __init__(self, test_group, resolution, forcing='cooling'):
@@ -25,12 +25,16 @@ def __init__(self, test_group, resolution, forcing='cooling'):
2525
test_group : compass.ocean.tests.turbulence_closure.TurbulenceClosure
2626
The test group that this test case belongs to
2727
28-
resolution : str
29-
The resolution of the test case
28+
resolution : float
29+
The resolution of the test case in meters
3030
"""
3131
name = 'decomp_test'
3232
self.resolution = resolution
33-
subdir = f'{resolution}/{forcing}/{name}'
33+
if resolution >= 1e3:
34+
res_name = f'{int(resolution/1e3)}km'
35+
else:
36+
res_name = f'{int(resolution)}m'
37+
subdir = f'{res_name}/{forcing}/{name}'
3438
super().__init__(test_group=test_group, name=name,
3539
subdir=subdir)
3640

compass/ocean/tests/turbulence_closure/default/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class Default(TestCase):
1313
1414
Attributes
1515
----------
16-
resolution : str
17-
The resolution of the test case
16+
resolution : float
17+
The resolution of the test case in meters
1818
"""
1919

2020
def __init__(self, test_group, resolution, forcing='cooling'):
@@ -26,20 +26,24 @@ def __init__(self, test_group, resolution, forcing='cooling'):
2626
test_group : compass.ocean.tests.turbulence_closure.TurbulenceClosure
2727
The test group that this test case belongs to
2828
29-
resolution : str
30-
The resolution of the test case
29+
resolution : float
30+
The resolution of the test case in meters
3131
3232
forcing: str
3333
The forcing applied to the test case
3434
"""
3535
name = 'default'
3636
self.resolution = resolution
3737
self.forcing = forcing
38-
subdir = f'{resolution}/{forcing}/{name}'
38+
if resolution >= 1e3:
39+
res_name = f'{int(resolution/1e3)}km'
40+
else:
41+
res_name = f'{int(resolution)}m'
42+
subdir = f'{res_name}/{forcing}/{name}'
3943
super().__init__(test_group=test_group, name=name,
4044
subdir=subdir)
4145

42-
if resolution == '1m' or resolution == '2m':
46+
if resolution <= 5:
4347
ntasks = 128
4448
plot_comparison=True
4549
else:

compass/ocean/tests/turbulence_closure/restart_test/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class RestartTest(TestCase):
1313
1414
Attributes
1515
----------
16-
resolution : str
17-
The resolution of the test case
16+
resolution : float
17+
The resolution of the test case in meters
1818
"""
1919

2020
def __init__(self, test_group, resolution, forcing='cooling'):
@@ -26,12 +26,16 @@ def __init__(self, test_group, resolution, forcing='cooling'):
2626
test_group : compass.ocean.tests.baroclinic_channel.BaroclinicChannel
2727
The test group that this test case belongs to
2828
29-
resolution : str
30-
The resolution of the test case
29+
resolution : float
30+
The resolution of the test case in meters
3131
"""
3232
name = 'restart_test'
3333
self.resolution = resolution
34-
subdir = f'{resolution}/{forcing}/{name}'
34+
if resolution >= 1e3:
35+
res_name = f'{int(resolution/1e3)}km'
36+
else:
37+
res_name = f'{int(resolution)}m'
38+
subdir = f'{res_name}/{forcing}/{name}'
3539
super().__init__(test_group=test_group, name=name,
3640
subdir=subdir)
3741

0 commit comments

Comments
 (0)