@@ -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 )
0 commit comments