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 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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 @@ -127,3 +127,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.
4 changes: 3 additions & 1 deletion polaris/ocean/suites/convergence.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ocean/planar/inertial_gravity_wave/convergence_both
ocean/planar/manufactured_solution/convergence_both
ocean/planar/manufactured_solution/convergence_both/default
ocean/planar/manufactured_solution/convergence_both/del2
ocean/planar/manufactured_solution/convergence_both/del4
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
5 changes: 5 additions & 0 deletions polaris/ocean/suites/manufactured_solution.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ocean/planar/manufactured_solution/convergence_space/default
# ocean/planar/manufactured_solution/convergence_time/default
ocean/planar/manufactured_solution/convergence_both/default
ocean/planar/manufactured_solution/convergence_both/del2
ocean/planar/manufactured_solution/convergence_both/del4
42 changes: 37 additions & 5 deletions polaris/ocean/tasks/manufactured_solution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@ def add_manufactured_solution_tasks(component):
component.add_task(ManufacturedSolution(component=component,
config=config,
refinement=refinement))
component.add_task(ManufacturedSolution(component=component,
config=config,
refinement='both',
del2=True))
component.add_task(ManufacturedSolution(component=component,
config=config,
refinement='both',
del4=True))


class ManufacturedSolution(Task):
"""
The convergence test case using the method of manufactured solutions
"""

def __init__(self, component, config, refinement='both'):
def __init__(self, component, config, refinement='both', del2=False,
del4=False):
"""
Create the test case

Expand All @@ -56,11 +65,33 @@ def __init__(self, component, config, refinement='both'):

refinement : str, optional
Whether to refine in space, time or both space and time

del2 : bool
Whether to evaluate the momentum del2 operator

del4 : bool
Whether to evaluate the momentum del4 operator
"""
name = f'manufactured_solution_convergence_{refinement}'
basedir = 'planar/manufactured_solution'
subdir = f'{basedir}/convergence_{refinement}'
name = f'manufactured_solution_convergence_{refinement}'

if del2:
test_name = 'del2'
if del4:
del4 = False
print('Manufactured solution test does not currently support'
'both del2 and del4 convergence; testing del2 alone.')
elif del4:
test_name = 'del4'
else:
test_name = 'default'

name = f'{name}_{test_name}'
subdir = f'{subdir}/{test_name}'

config_filename = 'manufactured_solution.cfg'

super().__init__(component=component, name=name, subdir=subdir)
self.set_shared_config(config, link=config_filename)

Expand All @@ -86,7 +117,7 @@ def __init__(self, component, config, refinement='both'):
init_step = component.steps[subdir]
else:
init_step = Init(component=component, resolution=resolution,
subdir=subdir)
name=f'init_{mesh_name}', subdir=subdir)
init_step.set_shared_config(self.config, link=config_filename)
if resolution not in resolutions:
self.add_step(init_step, symlink=symlink)
Expand All @@ -97,7 +128,7 @@ def __init__(self, component, config, refinement='both'):
timestep = ceil(timestep)
timesteps.append(timestep)

subdir = f'{basedir}/forward/{mesh_name}_{timestep}s'
subdir = f'{basedir}/{test_name}/forward/{mesh_name}_{timestep}s'
symlink = f'forward/{mesh_name}_{timestep}s'
if subdir in component.steps:
forward_step = component.steps[subdir]
Expand All @@ -108,7 +139,8 @@ def __init__(self, component, config, refinement='both'):
refinement_factor=refinement_factor,
name=f'forward_{mesh_name}_{timestep}s',
subdir=subdir,
init=init_step)
init=init_step,
del2=del2, del4=del4)
forward_step.set_shared_config(
config, link=config_filename)
self.add_step(forward_step, symlink=symlink)
Expand Down
48 changes: 40 additions & 8 deletions polaris/ocean/tasks/manufactured_solution/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ class Forward(ConvergenceForward):
refinement : str
Refinement type. One of 'space', 'time' or 'both' indicating both
space and time

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, refinement_factor, subdir,
init, refinement='both'):
init, refinement='both', del2=False, del4=False):
"""
Create a new test case

Expand All @@ -47,6 +56,12 @@ def __init__(self, component, name, refinement_factor, subdir,
refinement : str, optional
Refinement type. One of 'space', 'time' or 'both' indicating both
space and time

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 @@ -57,6 +72,8 @@ def __init__(self, component, name, refinement_factor, subdir,
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 @@ -102,10 +119,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
Comment on lines -36 to -38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbegeman, this change will break manufactured solution in Omega because the associated changes in forward.py don't yet include anything related to Omega. I know you don't want to address Omega here yet but maybe the solution is: 1) to leave these changes out for Omega and 2) to have setup fail for Omega for the del2 and del4 tasks for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xylar I removed the whole Omega section from this file. Is that in line with what you were thinking?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbegeman, hmm, I'm hesitant to drop Omega support for manufactured_solution entirely. It's one of only 2 working tests we have.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xylar Should I just go ahead and make the io streams changes then to support all 3?

Dimension:
NVertLevels: 1
6 changes: 2 additions & 4 deletions polaris/ocean/tasks/manufactured_solution/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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

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

Expand Down
2 changes: 1 addition & 1 deletion polaris/ocean/tasks/manufactured_solution/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def setup(self):
forward = dependencies['forward'][refinement_factor]
self.add_input_file(
filename=f'mesh_r{refinement_factor:02g}.nc',
work_dir_target=f'{base_mesh.path}/base_mesh.nc')
work_dir_target=f'{base_mesh.path}/culled_mesh.nc')
self.add_input_file(
filename=f'init_r{refinement_factor:02g}.nc',
work_dir_target=f'{init.path}/initial_state.nc')
Expand Down
Loading