Skip to content

Commit 87442c0

Browse files
committed
Remove time integrator as argument
Remove time integrator as argument, add to config options
1 parent e8d5728 commit 87442c0

File tree

6 files changed

+109
-91
lines changed

6 files changed

+109
-91
lines changed

polaris/ocean/tasks/drying_slope/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def add_drying_slope_tasks(component):
110110
baroclinic = Baroclinic(component=component, resolution=resolution,
111111
init=init, subdir=f'{indir}/{method}',
112112
coord_type=coord_type, method=method,
113-
forcing_type=forcing_type,
114-
time_integrator='split_explicit')
113+
forcing_type=forcing_type)
115114
baroclinic.set_shared_config(config, link=config_filename)
116115
component.add_task(baroclinic)

polaris/ocean/tasks/drying_slope/baroclinic/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class Baroclinic(Task):
2121
def __init__(self, component, resolution, init, subdir,
2222
coord_type='sigma',
2323
forcing_type='linear_drying', method='ramp',
24-
drag_type='constant_and_rayleigh',
25-
time_integrator='split_explicit'):
24+
drag_type='constant_and_rayleigh'):
2625
"""
2726
Create the test case
2827
@@ -52,9 +51,6 @@ def __init__(self, component, resolution, init, subdir,
5251
5352
drag_type : str, optional
5453
The bottom drag type to apply as a namelist option
55-
56-
time_integrator : str, optional
57-
The time integration scheme to apply as a namelist option
5854
"""
5955
name = f'baroclinic_{method}'
6056
if drag_type == 'loglaw':
@@ -69,7 +65,7 @@ def __init__(self, component, resolution, init, subdir,
6965
ntasks=None,
7066
min_tasks=None, openmp_threads=1, resolution=resolution,
7167
forcing_type=forcing_type, coord_type=coord_type,
72-
time_integrator=time_integrator, drag_type=drag_type,
68+
drag_type=drag_type,
7369
damping_coeff=1.0e-4, baroclinic=True, method=method))
7470

7571
self.add_step(

polaris/ocean/tasks/drying_slope/barotropic/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Barotropic(Task):
2626
def __init__(self, component, resolution, init, subdir,
2727
coord_type='sigma',
2828
drag_type='constant_and_rayleigh', forcing_type='tidal_cycle',
29-
time_integrator='RK4', method='ramp'):
29+
method='ramp'):
3030
"""
3131
Create the test case
3232
@@ -56,9 +56,6 @@ def __init__(self, component, resolution, init, subdir,
5656
5757
drag_type : str, optional
5858
The bottom drag type to apply as a namelist option
59-
60-
time_integrator : str, optional
61-
The time integration scheme to apply as a namelist option
6259
"""
6360
mesh_name = resolution_to_subdir(resolution)
6461
name = f'barotropic_{method}_{mesh_name}'
@@ -86,9 +83,10 @@ def __init__(self, component, resolution, init, subdir,
8683
name=f'{step_name}_{mesh_name}',
8784
resolution=resolution,
8885
forcing_type=forcing_type, coord_type=coord_type,
89-
time_integrator=time_integrator, drag_type=drag_type,
86+
drag_type=drag_type,
9087
damping_coeff=damping_coeff, baroclinic=False,
91-
method=method)
88+
method=method,
89+
graph_target=f'{init.path}/culled_graph.info')
9290
symlink = None
9391
self.add_step(forward_step, symlink=symlink)
9492
else:
@@ -97,7 +95,7 @@ def __init__(self, component, resolution, init, subdir,
9795
component=component, init=init, indir=subdir, ntasks=None,
9896
min_tasks=None, openmp_threads=1, resolution=resolution,
9997
forcing_type=forcing_type, coord_type=coord_type,
100-
time_integrator=time_integrator, drag_type=drag_type,
98+
drag_type=drag_type,
10199
damping_coeff=1.0e-4, baroclinic=False,
102100
method=method)
103101
self.add_step(forward_step)

polaris/ocean/tasks/drying_slope/drying_slope.cfg

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ min_layer_thickness = ${drying_slope_barotropic:thin_film_thickness}
2525
# config options for all drying slope test cases
2626
[drying_slope]
2727

28-
# time integration scheme
29-
time_integrator = RK4
30-
3128
# time step per resolution (s/km), since dt is proportional to resolution
3229
rk4_dt_per_km = 30
3330

@@ -46,6 +43,9 @@ background_temperature = 20.0
4643
# config options for barotropic drying slope test cases
4744
[drying_slope_barotropic]
4845

46+
# time integration scheme
47+
time_integrator = RK4
48+
4949
# the width of the domain in km
5050
lx = 6.
5151

@@ -79,6 +79,9 @@ thin_film_thickness = 1.0e-3
7979
# config options for barotropic drying slope test cases
8080
[drying_slope_baroclinic]
8181

82+
# time integration scheme
83+
time_integrator = split_explicit
84+
8285
# the width of the domain in km
8386
lx = 12.
8487

polaris/ocean/tasks/drying_slope/forward.py

Lines changed: 78 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ class Forward(OceanModelStep):
2828
"""
2929
def __init__(self, component, resolution, init, name='forward',
3030
subdir=None, indir=None, ntasks=None, min_tasks=None,
31-
openmp_threads=1, time_integrator='rk4', damping_coeff=None,
31+
openmp_threads=1, damping_coeff=None,
3232
coord_type='sigma', forcing_type='tidal_cycle',
3333
drag_type='constant_and_rayleigh', baroclinic=False,
34-
method='ramp', run_time_steps=None):
34+
method='ramp', run_time_steps=None,
35+
graph_target='graph.info'):
3536
"""
3637
Create a new task
3738
@@ -92,55 +93,33 @@ def __init__(self, component, resolution, init, name='forward',
9293
raise ValueError('Damping coefficient must be specified with '
9394
f'drag type {drag_type}')
9495

96+
self.damping_coeff = damping_coeff
97+
self.drag_type = drag_type
9598
self.baroclinic = baroclinic
99+
self.coord_type = coord_type
100+
self.forcing_type = forcing_type
101+
self.method = method
96102
self.resolution = resolution
97103
self.run_time_steps = run_time_steps
104+
self.yaml_filename = 'forward.yaml'
98105
super().__init__(component=component, name=name, subdir=subdir,
99106
indir=indir, ntasks=ntasks, min_tasks=min_tasks,
100-
openmp_threads=openmp_threads)
101-
102-
self.add_input_file(filename='initial_state.nc',
103-
work_dir_target=f'{init.path}/initial_state.nc')
104-
self.add_input_file(filename='graph.info',
105-
work_dir_target=f'{init.path}/culled_graph.info')
106-
self.add_input_file(filename='forcing.nc',
107-
work_dir_target=f'{init.path}/forcing.nc')
107+
openmp_threads=openmp_threads,
108+
graph_target=graph_target)
108109

109110
self.add_yaml_file('polaris.ocean.config', 'output.yaml')
110-
111-
self.add_yaml_file('polaris.ocean.tasks.drying_slope',
112-
'forward.yaml')
113-
114-
options = dict()
115-
if coord_type == 'single_layer':
111+
if self.coord_type == 'single_layer':
116112
self.add_yaml_file('polaris.ocean.config', 'single_layer.yaml')
117-
options['config_disable_thick_sflux'] = True
118-
options['config_disable_vel_hmix'] = True
119-
120-
if method == 'ramp':
121-
options['config_zero_drying_velocity_ramp'] = True
122-
123-
options['config_implicit_bottom_drag_type'] = drag_type
124-
# for drag types not specified here, defaults are used or given in
125-
# forward.yaml
126-
if drag_type == 'constant':
127-
options['config_implicit_constant_bottom_drag_coeff'] = \
128-
3.0e-3 # type: ignore[assignment]
129-
elif drag_type == 'constant_and_rayleigh':
130-
# update the damping coefficient to the requested value *after*
131-
# loading forward.yaml
132-
options['config_Rayleigh_damping_coeff'] = damping_coeff
133-
134-
if baroclinic:
113+
if self.baroclinic:
135114
self.add_yaml_file('polaris.ocean.tasks.drying_slope',
136115
'baroclinic.yaml')
116+
self.add_yaml_file('polaris.ocean.tasks.drying_slope',
117+
self.yaml_filename)
137118

138-
forcing_dict = {'tidal_cycle': 'monochromatic',
139-
'linear_drying': 'linear'}
140-
141-
options['config_tidal_forcing_model'] = \
142-
forcing_dict[forcing_type] # type: ignore[assignment]
143-
self.add_model_config_options(options=options)
119+
self.add_input_file(filename='initial_state.nc',
120+
work_dir_target=f'{init.path}/initial_state.nc')
121+
self.add_input_file(filename='forcing.nc',
122+
work_dir_target=f'{init.path}/forcing.nc')
144123

145124
self.add_output_file(
146125
filename='output.nc',
@@ -184,48 +163,78 @@ def dynamic_model_config(self, at_setup):
184163
"""
185164
super().dynamic_model_config(at_setup)
186165

187-
config = self.config
188-
189-
options = dict()
166+
if self.baroclinic:
167+
section = self.config['vertical_grid']
168+
vert_levels = section.getint('vert_levels')
169+
section = self.config['drying_slope_baroclinic']
170+
time_integrator = section.get('time_integrator')
171+
thin_film_thickness = section.getfloat('min_column_thickness') / \
172+
vert_levels
173+
else:
174+
section = self.config['drying_slope_barotropic']
175+
time_integrator = section.get('time_integrator')
176+
thin_film_thickness = section.getfloat('thin_film_thickness')
190177

191178
# dt is proportional to resolution: default 30 seconds per km
192-
section = config['drying_slope']
193-
time_integrator = section.get('time_integrator')
194-
options['config_time_integrator'] = time_integrator
195-
179+
section = self.config['drying_slope']
196180
if time_integrator == 'RK4':
197181
dt_per_km = section.getfloat('rk4_dt_per_km')
198-
if time_integrator == 'split_explicit':
182+
elif time_integrator == 'split_explicit':
199183
dt_per_km = section.getfloat('split_dt_per_km')
200184
# btr_dt is also proportional to resolution
201-
btr_dt_per_km = config.getfloat('drying_slope', 'btr_dt_per_km')
185+
btr_dt_per_km = section.getfloat('btr_dt_per_km')
202186
btr_dt = btr_dt_per_km * self.resolution
203-
options['config_btr_dt'] = \
204-
time.strftime('%H:%M:%S', time.gmtime(btr_dt))
205187
self.btr_dt = btr_dt
188+
else:
189+
print(f'Time integrator {time_integrator} not supported')
190+
btr_dt_str = time.strftime('%H:%M:%S', time.gmtime(self.btr_dt))
191+
206192
dt = dt_per_km * self.resolution
207193
# https://stackoverflow.com/a/1384565/7728169
208-
options['config_dt'] = \
209-
time.strftime('%H:%M:%S', time.gmtime(dt))
194+
dt_str = time.strftime('%H:%M:%S', time.gmtime(dt))
210195
self.dt = dt
211196

212197
if self.run_time_steps is not None:
213-
options['run_duration'] = time.strftime(
198+
run_duration_str = time.strftime(
214199
'%H:%M:%S', time.gmtime(dt * self.run_time_steps))
215-
216-
if self.baroclinic:
217-
section = self.config['vertical_grid']
218-
vert_levels = section.getint('vert_levels')
219-
section = self.config['drying_slope_baroclinic']
220-
thin_film_thickness = section.getfloat('min_column_thickness') / \
221-
vert_levels
222200
else:
223-
section = self.config['drying_slope_barotropic']
224-
thin_film_thickness = section.getfloat('thin_film_thickness')
225-
options['config_drying_min_cell_height'] = thin_film_thickness
226-
options['config_zero_drying_velocity_ramp_hmin'] = \
227-
thin_film_thickness
228-
options['config_zero_drying_velocity_ramp_hmax'] = \
229-
thin_film_thickness * 10.
201+
run_duration_str = '0000_12:00:01'
202+
203+
replacements = dict(
204+
time_integrator=time_integrator,
205+
dt=dt_str,
206+
btr_dt=btr_dt_str,
207+
run_duration=run_duration_str,
208+
hmin=f'{thin_film_thickness}',
209+
ramp_hmin=f'{thin_film_thickness}',
210+
ramp_hmax=f'{1.}',
211+
)
212+
213+
mpas_options = dict()
214+
if self.method == 'ramp':
215+
mpas_options['config_zero_drying_velocity_ramp'] = True
216+
217+
mpas_options['config_implicit_bottom_drag_type'] = self.drag_type
218+
# for drag types not specified here, defaults are used or given in
219+
# forward.yaml
220+
if self.drag_type == 'constant':
221+
mpas_options['config_implicit_constant_bottom_drag_coeff'] = \
222+
3.0e-3 # type: ignore[assignment]
223+
elif self.drag_type == 'constant_and_rayleigh':
224+
# update the damping coefficient to the requested value *after*
225+
# loading forward.yaml
226+
mpas_options['config_Rayleigh_damping_coeff'] = self.damping_coeff
230227

231-
self.add_model_config_options(options=options)
228+
forcing_dict = {'tidal_cycle': 'monochromatic',
229+
'linear_drying': 'linear'}
230+
231+
mpas_options['config_tidal_forcing_model'] = \
232+
forcing_dict[self.forcing_type] # type: ignore[assignment]
233+
234+
print(mpas_options)
235+
self.add_model_config_options(options=mpas_options,
236+
config_model='mpas-ocean')
237+
print(replacements)
238+
self.add_yaml_file('polaris.ocean.tasks.drying_slope',
239+
self.yaml_filename,
240+
template_replacements=replacements)

polaris/ocean/tasks/drying_slope/forward.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
omega:
1+
ocean:
2+
time_management:
3+
config_run_duration: {{ run_duration }}
4+
time_integration:
5+
config_dt: {{ dt }}
6+
config_time_integrator: {{ time_integrator }}
7+
8+
mpas-ocean:
29
io:
310
config_write_output_on_startup: false
11+
split_explicit_ts:
12+
config_btr_dt: {{ btr_dt }}
413
cvmix:
514
config_use_cvmix: false
6-
time_management:
7-
config_run_duration: 0000_12:00:01
815
tidal_forcing:
916
config_use_tidal_forcing: true
1017
config_use_tidal_forcing_tau: 60.0
@@ -16,15 +23,20 @@ omega:
1623
config_Rayleigh_damping_depth_variable: true
1724
wetting_drying:
1825
config_use_wetting_drying: true
26+
config_drying_min_cell_height: {{ hmin }}
1927
config_prevent_drying: true
2028
config_zero_drying_velocity: true
21-
config_zero_drying_velocity_ramp: true
29+
config_zero_drying_velocity_ramp_hmin: {{ ramp_hmin }}
30+
config_zero_drying_velocity_ramp_hmax: {{ ramp_hmax }}
2231
config_verify_not_dry: true
2332
ALE_vertical_grid:
2433
config_vert_coord_movement: impermeable_interfaces
2534
config_ALE_thickness_proportionality: weights_only
2635
advection:
2736
config_thickness_flux_type: upwind
37+
debug:
38+
config_disable_thick_sflux: true
39+
config_disable_vel_hmix: true
2840
streams:
2941
mesh:
3042
filename_template: initial_state.nc
@@ -47,6 +59,7 @@ omega:
4759
- tracers
4860
- xtime
4961
- daysSinceStartOfSim
62+
- upwindFactor
5063
- normalVelocity
5164
- velocityX
5265
- velocityY

0 commit comments

Comments
 (0)