Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend manufactured solution to del2 and del4 #234

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions docs/users_guide/ocean/tasks/manufactured_solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Currently, the there is only one task, the convergence test from

These tasks support both MPAS-Ocean and Omega.

(ocean-manufactured-solution-convergence)=
(ocean-manufactured-solution-default)=

## convergence
## default

### description

Expand Down Expand Up @@ -121,3 +121,22 @@ conv_thresh = 1.8

The number of cores is determined according to the config options
``max_cells_per_core`` and ``goal_cells_per_core``.

(ocean-manufactured-solution-del2)=

## del2

### description

All settings are the same as the {ref}`ocean-manufactured-solution-default` case
except laplacian viscosity is turned on.

(ocean-manufactured-solution-del4)=

## del4

### description

All settings are the same as the {ref}`ocean-manufactured-solution-default` case
except hyperviscosity is turned on. The expected convergence should not be
significantly different from the {ref}`ocean-manufactured-solution-default` case.
3 changes: 2 additions & 1 deletion polaris/ocean/suites/convergence.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ocean/planar/inertial_gravity_wave
ocean/planar/manufactured_solution
ocean/planar/manufactured_solution/default
ocean/planar/manufactured_solution/del2
ocean/spherical/icos/correlated_tracers_2d
cached: icos_base_mesh_60km icos_base_mesh_120km icos_base_mesh_240km icos_base_mesh_480km
ocean/spherical/qu/correlated_tracers_2d
Expand Down
50 changes: 42 additions & 8 deletions polaris/ocean/tasks/manufactured_solution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def add_manufactured_solution_tasks(component):
the ocean component that the task will be added to
"""
component.add_task(ManufacturedSolution(component=component))
component.add_task(ManufacturedSolution(component=component, del2=True))
component.add_task(ManufacturedSolution(component=component, del4=True))


class ManufacturedSolution(Task):
Expand All @@ -28,32 +30,64 @@ class ManufacturedSolution(Task):
resolutions : list of floats
The resolutions of the test case in km
"""
def __init__(self, component):
def __init__(self, component, del2=False, del4=False):
"""
Create the test case

Parameters
----------
component : polaris.ocean.Ocean
The ocean component that this task belongs to

del2 : bool
Whether to evaluate the momentum del2 operator

del4 : bool
Whether to evaluate the momentum del4 operator
"""
name = 'manufactured_solution'
subdir = f'planar/{name}'
taskdir = f'planar/{name}'
if del2:
name = f'{name}_del2'
subdir = f'{taskdir}/del2'
elif del4:
name = f'{name}_del4'
subdir = f'{taskdir}/del4'
else:
subdir = f'{taskdir}/default'

super().__init__(component=component, name=name, subdir=subdir)

self.resolutions = [200., 100., 50., 25.]
max_resolution = 200.
self.resolutions = [max_resolution,
max_resolution / 2,
max_resolution / 4,
max_resolution / 8]
analysis_dependencies: Dict[str, Dict[float, Step]] = (
dict(mesh=dict(), init=dict(), forward=dict()))
for resolution in self.resolutions:
mesh_name = resolution_to_subdir(resolution)
init_step = Init(component=component, resolution=resolution,
taskdir=self.subdir)
self.add_step(init_step)

init_name = f'init_{mesh_name}'
init_subdir = f'{taskdir}/init/{mesh_name}'
if init_subdir in component.steps:
init_step = component.steps[init_subdir]
else:
init_step = Init(component=component, resolution=resolution,
subdir=init_subdir, name=init_name)
self.add_step(init_step, symlink='init/{mesh_name}')

forward_name = f'forward_{mesh_name}'
if del2:
forward_name = f'{forward_name}_del2'
if del4:
forward_name = f'{forward_name}_del4'
forward_step = Forward(component=component, resolution=resolution,
name=f'forward_{mesh_name}',
name=forward_name,
subdir=f'{self.subdir}/forward/{mesh_name}',
init=init_step)
init=init_step, del2=del2, del4=del4)
self.add_step(forward_step)

analysis_dependencies['mesh'][resolution] = init_step
analysis_dependencies['init'][resolution] = init_step
analysis_dependencies['forward'][resolution] = forward_step
Expand Down
46 changes: 38 additions & 8 deletions polaris/ocean/tasks/manufactured_solution/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ class Forward(ConvergenceForward):
----------
resolution : float
The resolution of the test case in km

del2 : bool
Whether to evaluate the momentum del2 operator

del4 : bool
Whether to evaluate the momentum del4 operator
"""
def __init__(self, component, name, resolution, subdir, init):
def __init__(self, component, name, resolution, subdir, init, del2=False,
del4=False):
"""
Create a new test case

Expand All @@ -34,6 +41,12 @@ def __init__(self, component, name, resolution, subdir, init):

init : polaris.Step
The step which generates the mesh and initial condition

del2 : bool
Whether to evaluate the momentum del2 operator

del4 : bool
Whether to evaluate the momentum del4 operator
"""
super().__init__(component=component,
name=name, subdir=subdir,
Expand All @@ -43,6 +56,8 @@ def __init__(self, component, name, resolution, subdir, init):
graph_target=f'{init.path}/culled_graph.info',
output_filename='output.nc',
validate_vars=['layerThickness', 'normalVelocity'])
self.del2 = del2
self.del4 = del4

def setup(self):
"""
Expand Down Expand Up @@ -86,10 +101,25 @@ def dynamic_model_config(self, at_setup):
super().dynamic_model_config(at_setup=at_setup)

exact_solution = ExactSolution(self.config)
options = {'config_manufactured_solution_amplitude':
float(exact_solution.eta0),
'config_manufactured_solution_wavelength_x':
float(exact_solution.lambda_x),
'config_manufactured_solution_wavelength_y':
float(exact_solution.lambda_y)}
self.add_model_config_options(options, config_model='mpas-ocean')
mpas_options = {'config_manufactured_solution_amplitude':
float(exact_solution.eta0),
'config_manufactured_solution_wavelength_x':
float(exact_solution.lambda_x),
'config_manufactured_solution_wavelength_y':
float(exact_solution.lambda_y)}
shared_options = {}
if self.del2:
mpas_options['config_disable_vel_hmix'] = False
shared_options['config_use_mom_del2'] = True
shared_options['config_use_mom_del4'] = False
elif self.del4:
mpas_options['config_disable_vel_hmix'] = False
shared_options['config_use_mom_del2'] = False
shared_options['config_use_mom_del4'] = True
else:
mpas_options['config_disable_vel_hmix'] = True
shared_options['config_use_mom_del2'] = False
shared_options['config_use_mom_del4'] = False

self.add_model_config_options(mpas_options, config_model='mpas-ocean')
self.add_model_config_options(shared_options, config_model='ocean')
9 changes: 4 additions & 5 deletions polaris/ocean/tasks/manufactured_solution/forward.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ mpas-ocean:
config_implicit_constant_bottom_drag_coeff: 0.0
manufactured_solution:
config_use_manufactured_solution: true
debug:
config_disable_vel_hmix: true
hmix_del2:
config_mom_del2: 1000.
hmix_del4:
config_mom_del4: 1.e10

Omega:
Tendencies:
VelDiffTendencyEnable: false
VelHyperDiffTendencyEnable: false
Dimension:
NVertLevels: 1
8 changes: 3 additions & 5 deletions polaris/ocean/tasks/manufactured_solution/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from polaris import Step
from polaris.mesh.planar import compute_planar_hex_nx_ny
from polaris.ocean.resolution import resolution_to_subdir
from polaris.ocean.tasks.manufactured_solution.exact_solution import (
ExactSolution,
)
Expand All @@ -23,7 +22,7 @@ class Init(Step):
resolution : float
The resolution of the test case in km
"""
def __init__(self, component, resolution, taskdir):
def __init__(self, component, resolution, subdir, name):
"""
Create the step

Expand All @@ -38,10 +37,9 @@ def __init__(self, component, resolution, taskdir):
taskdir : str
The subdirectory that the task belongs to
"""
mesh_name = resolution_to_subdir(resolution)
super().__init__(component=component,
name=f'init_{mesh_name}',
subdir=f'{taskdir}/init/{mesh_name}')
name=name,
subdir=subdir)
self.resolution = resolution

def setup(self):
Expand Down
6 changes: 3 additions & 3 deletions polaris/ocean/tasks/manufactured_solution/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def __init__(self, component, resolutions, taskdir):
"""
super().__init__(component=component, name='viz', indir=taskdir)
self.resolutions = resolutions

for resolution in resolutions:
mesh_name = resolution_to_subdir(resolution)
init_path = f'../../init/{mesh_name}'
self.add_input_file(
filename=f'mesh_{mesh_name}.nc',
target=f'../init/{mesh_name}/culled_mesh.nc')
target=f'{init_path}/culled_mesh.nc')
self.add_input_file(
filename=f'init_{mesh_name}.nc',
target=f'../init/{mesh_name}/initial_state.nc')
target=f'{init_path}/initial_state.nc')
self.add_input_file(
filename=f'output_{mesh_name}.nc',
target=f'../forward/{mesh_name}/output.nc')
Expand Down
Loading