From 26688d6dc7e3ae411d6097ab07322322fa40085c Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Thu, 7 Nov 2024 20:22:02 -0600 Subject: [PATCH] Add Omega support to Cosine Bell tests --- polaris/ocean/tasks/cosine_bell/analysis.py | 2 +- .../ocean/tasks/cosine_bell/cosine_bell.cfg | 5 ++- polaris/ocean/tasks/cosine_bell/forward.py | 10 +++++ polaris/ocean/tasks/cosine_bell/forward.yaml | 41 ++++++++++++++++--- polaris/ocean/tasks/cosine_bell/init.py | 11 ++--- polaris/ocean/tasks/cosine_bell/viz.py | 11 +++-- 6 files changed, 59 insertions(+), 21 deletions(-) diff --git a/polaris/ocean/tasks/cosine_bell/analysis.py b/polaris/ocean/tasks/cosine_bell/analysis.py index 28fd7576e..a5ba6e94c 100644 --- a/polaris/ocean/tasks/cosine_bell/analysis.py +++ b/polaris/ocean/tasks/cosine_bell/analysis.py @@ -79,7 +79,7 @@ def exact_solution(self, refinement_factor, field_name, time, zidx=None): ds_mesh = xr.open_dataset(f'mesh_r{refinement_factor:02g}.nc') sphere_radius = ds_mesh.sphere_radius - ds_init = xr.open_dataset(f'init_r{refinement_factor:02g}.nc') + ds_init = self.open_model_dataset(f'init_r{refinement_factor:02g}.nc') latCell = ds_init.latCell.values lonCell = ds_init.lonCell.values diff --git a/polaris/ocean/tasks/cosine_bell/cosine_bell.cfg b/polaris/ocean/tasks/cosine_bell/cosine_bell.cfg index 045389e71..06884ce13 100644 --- a/polaris/ocean/tasks/cosine_bell/cosine_bell.cfg +++ b/polaris/ocean/tasks/cosine_bell/cosine_bell.cfg @@ -36,7 +36,10 @@ error_type = l2 # config options for convergence forward steps [convergence_forward] -# time integrator: {'split_explicit', 'RK4'} +# time integrator +# either: {'RK4'} +# mpas-ocean: {'split_explicit'} +# omega: {'Forward-Backward', 'RungeKutta2'} time_integrator = RK4 # RK4 time step per resolution (s/km), since dt is proportional to resolution diff --git a/polaris/ocean/tasks/cosine_bell/forward.py b/polaris/ocean/tasks/cosine_bell/forward.py index 8c477d9e7..270f4048f 100644 --- a/polaris/ocean/tasks/cosine_bell/forward.py +++ b/polaris/ocean/tasks/cosine_bell/forward.py @@ -46,3 +46,13 @@ def __init__(self, component, name, subdir, mesh, init, graph_target=f'{mesh.path}/graph.info', refinement_factor=refinement_factor, refinement=refinement) + + def setup(self): + """ + TEMP: symlink initial condition to name hard-coded in Omega + """ + super().setup() + model = self.config.get('ocean', 'model') + # TODO: remove as soon as Omega no longer hard-codes this file + if model == 'omega': + self.add_input_file(filename='OmegaMesh.nc', target='init.nc') diff --git a/polaris/ocean/tasks/cosine_bell/forward.yaml b/polaris/ocean/tasks/cosine_bell/forward.yaml index 0496cfe82..41bd59b6a 100644 --- a/polaris/ocean/tasks/cosine_bell/forward.yaml +++ b/polaris/ocean/tasks/cosine_bell/forward.yaml @@ -1,14 +1,16 @@ -mpas-ocean: - run_modes: - config_ocean_run_mode: forward +ocean: time_management: config_stop_time: none config_run_duration: {{ run_duration }} - decomposition: - config_block_decomp_file_prefix: graph.info.part. time_integration: config_dt: {{ dt }} config_time_integrator: {{ time_integrator }} + +mpas-ocean: + run_modes: + config_ocean_run_mode: forward + decomposition: + config_block_decomp_file_prefix: graph.info.part. debug: config_disable_thick_all_tend: true config_disable_thick_hadv: true @@ -65,3 +67,32 @@ mpas-ocean: - refLayerThickness - kineticEnergyCell - relativeVorticityCell + +Omega: + Tendencies: + ThicknessFluxTendencyEnable : false + PVTendencyEnable : false + KETendencyEnable : false + SSHTendencyEnable : false + VelDiffTendencyEnable: false + VelHyperDiffTendencyEnable: false + TracerHorzAdvTendencyEnable : true + TracerDiffTendencyEnable : false + TracerHyperDiffTendencyEnable : false + Dimension: + NVertLevels: 1 + IOStreams: + InitialState: + Filename: init.nc + Contents: + - State + - Tracers + History: + Filename: output.nc + Freq: {{ output_freq }} + FreqUnits: Seconds + Contents: + - Tracers + - LayerThickness + - NormalVelocity + RestartRead: {} diff --git a/polaris/ocean/tasks/cosine_bell/init.py b/polaris/ocean/tasks/cosine_bell/init.py index 788f0b6cf..f74165b07 100644 --- a/polaris/ocean/tasks/cosine_bell/init.py +++ b/polaris/ocean/tasks/cosine_bell/init.py @@ -1,14 +1,13 @@ import numpy as np import xarray as xr -from mpas_tools.io import write_netcdf from mpas_tools.transects import lon_lat_to_cartesian from mpas_tools.vector import Vector -from polaris import Step +from polaris.ocean.model import OceanIOStep from polaris.ocean.vertical import init_vertical_coord -class Init(Step): +class Init(OceanIOStep): """ A step for an initial condition for for the cosine bell test case """ @@ -36,10 +35,6 @@ def __init__(self, component, name, subdir, base_mesh): filename='mesh.nc', work_dir_target=f'{base_mesh.path}/base_mesh.nc') - self.add_input_file( - filename='graph.info', - work_dir_target=f'{base_mesh.path}/graph.info') - self.add_output_file(filename='initial_state.nc') def run(self): @@ -107,7 +102,7 @@ def run(self): ds['fEdge'] = xr.zeros_like(ds_mesh.xEdge) ds['fVertex'] = xr.zeros_like(ds_mesh.xVertex) - write_netcdf(ds, 'initial_state.nc') + self.write_model_dataset(ds, 'initial_state.nc') def cosine_bell(max_value, ri, r): diff --git a/polaris/ocean/tasks/cosine_bell/viz.py b/polaris/ocean/tasks/cosine_bell/viz.py index ebc32110c..2990f8d55 100644 --- a/polaris/ocean/tasks/cosine_bell/viz.py +++ b/polaris/ocean/tasks/cosine_bell/viz.py @@ -1,11 +1,10 @@ import cmocean # noqa: F401 -import xarray as xr -from polaris import Step +from polaris.ocean.model import OceanIOStep from polaris.viz import plot_global_mpas_field -class Viz(Step): +class Viz(OceanIOStep): """ A step for plotting fields from the cosine bell output @@ -64,7 +63,7 @@ def run(self): mesh_name = self.mesh_name run_duration = config.getfloat('convergence_forward', 'run_duration') - ds_init = xr.open_dataset('initial_state.nc') + ds_init = self.open_model_dataset('initial_state.nc') da = ds_init['tracer1'].isel(Time=0, nVertLevels=0) plot_global_mpas_field( @@ -73,11 +72,11 @@ def run(self): title=f'{mesh_name} tracer at init', plot_land=False, central_longitude=180.) - ds_out = xr.open_dataset('output.nc') + ds_out = self.open_model_dataset('output.nc') da = ds_out['tracer1'].isel(Time=-1, nVertLevels=0) plot_global_mpas_field( mesh_filename='mesh.nc', da=da, out_filename='final.png', config=config, colormap_section='cosine_bell_viz', - title=f'{mesh_name} tracer after {run_duration/24.:g} days', + title=f'{mesh_name} tracer after {run_duration / 24.:g} days', plot_land=False, central_longitude=180.)