From bf1abf87434df2ad733066835a069256d4e3b78c Mon Sep 17 00:00:00 2001 From: Carolyn Begeman Date: Thu, 19 Sep 2024 10:28:51 -0500 Subject: [PATCH 1/5] Add del2 and del4 tasks --- .../tasks/manufactured_solution/__init__.py | 17 +++++++++-- .../tasks/manufactured_solution/forward.py | 29 +++++++++++++++++-- .../tasks/manufactured_solution/forward.yaml | 9 +++--- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/polaris/ocean/tasks/manufactured_solution/__init__.py b/polaris/ocean/tasks/manufactured_solution/__init__.py index 2c95b634e..51e1bd75a 100644 --- a/polaris/ocean/tasks/manufactured_solution/__init__.py +++ b/polaris/ocean/tasks/manufactured_solution/__init__.py @@ -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): @@ -28,7 +30,7 @@ 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 @@ -36,9 +38,20 @@ def __init__(self, component): ---------- 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' + if del2: + name = f'{name}_del2' + if del4: + name = f'{name}_del4' subdir = f'planar/{name}' + super().__init__(component=component, name=name, subdir=subdir) self.resolutions = [200., 100., 50., 25.] @@ -52,7 +65,7 @@ def __init__(self, component): forward_step = Forward(component=component, resolution=resolution, name=f'forward_{mesh_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 diff --git a/polaris/ocean/tasks/manufactured_solution/forward.py b/polaris/ocean/tasks/manufactured_solution/forward.py index 62bd76a4d..176db619f 100644 --- a/polaris/ocean/tasks/manufactured_solution/forward.py +++ b/polaris/ocean/tasks/manufactured_solution/forward.py @@ -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 @@ -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, @@ -54,6 +67,8 @@ def setup(self): # TODO: remove as soon as Omega supports I/O streams if model == 'omega': self.add_input_file(filename='OmegaMesh.nc', target='init.nc') + self.del2 = del2 + self.del4 = del4 def compute_cell_count(self): """ @@ -91,5 +106,15 @@ def dynamic_model_config(self, at_setup): 'config_manufactured_solution_wavelength_x': float(exact_solution.lambda_x), 'config_manufactured_solution_wavelength_y': - float(exact_solution.lambda_y)} + float(exact_solution.lambda_y), + 'config_disable_vel_hmix': + True} + + if self.del2: + options['config_disable_vel_hmix'] = False + options['config_use_mom_del2'] = True + if self.del4: + options['config_disable_vel_hmix'] = False + options['config_use_mom_del4'] = True + self.add_model_config_options(options, config_model='mpas-ocean') diff --git a/polaris/ocean/tasks/manufactured_solution/forward.yaml b/polaris/ocean/tasks/manufactured_solution/forward.yaml index f7aefa138..b60885105 100644 --- a/polaris/ocean/tasks/manufactured_solution/forward.yaml +++ b/polaris/ocean/tasks/manufactured_solution/forward.yaml @@ -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 From b1530860d52a63bf8128198401b985fd6c57d892 Mon Sep 17 00:00:00 2001 From: Carolyn Begeman Date: Fri, 20 Sep 2024 13:47:26 -0500 Subject: [PATCH 2/5] Share init steps --- .../tasks/manufactured_solution/__init__.py | 35 +++++++++++++++---- .../ocean/tasks/manufactured_solution/init.py | 8 ++--- .../ocean/tasks/manufactured_solution/viz.py | 6 ++-- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/polaris/ocean/tasks/manufactured_solution/__init__.py b/polaris/ocean/tasks/manufactured_solution/__init__.py index 51e1bd75a..f59df0b23 100644 --- a/polaris/ocean/tasks/manufactured_solution/__init__.py +++ b/polaris/ocean/tasks/manufactured_solution/__init__.py @@ -46,27 +46,48 @@ def __init__(self, component, del2=False, del4=False): Whether to evaluate the momentum del4 operator """ name = 'manufactured_solution' + taskdir = f'planar/{name}' if del2: name = f'{name}_del2' - if del4: + subdir = f'{taskdir}/del2' + elif del4: name = f'{name}_del4' - subdir = f'planar/{name}' + 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, 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 diff --git a/polaris/ocean/tasks/manufactured_solution/init.py b/polaris/ocean/tasks/manufactured_solution/init.py index 788cae069..065c57982 100644 --- a/polaris/ocean/tasks/manufactured_solution/init.py +++ b/polaris/ocean/tasks/manufactured_solution/init.py @@ -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, ) @@ -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 @@ -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): diff --git a/polaris/ocean/tasks/manufactured_solution/viz.py b/polaris/ocean/tasks/manufactured_solution/viz.py index 65a232f7b..efc867ac6 100644 --- a/polaris/ocean/tasks/manufactured_solution/viz.py +++ b/polaris/ocean/tasks/manufactured_solution/viz.py @@ -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') From 85e5a4d620da28c446e00dcbf1aceba32b1c5d1b Mon Sep 17 00:00:00 2001 From: Carolyn Begeman Date: Tue, 1 Oct 2024 09:37:49 -0500 Subject: [PATCH 3/5] fixup omega cfg options --- .../tasks/manufactured_solution/forward.py | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/polaris/ocean/tasks/manufactured_solution/forward.py b/polaris/ocean/tasks/manufactured_solution/forward.py index 176db619f..27e2b9a92 100644 --- a/polaris/ocean/tasks/manufactured_solution/forward.py +++ b/polaris/ocean/tasks/manufactured_solution/forward.py @@ -56,6 +56,8 @@ def __init__(self, component, name, resolution, subdir, init, del2=False, 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): """ @@ -67,8 +69,6 @@ def setup(self): # TODO: remove as soon as Omega supports I/O streams if model == 'omega': self.add_input_file(filename='OmegaMesh.nc', target='init.nc') - self.del2 = del2 - self.del4 = del4 def compute_cell_count(self): """ @@ -101,20 +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), - 'config_disable_vel_hmix': - True} - + 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: - options['config_disable_vel_hmix'] = False - options['config_use_mom_del2'] = True - if self.del4: - options['config_disable_vel_hmix'] = False - options['config_use_mom_del4'] = True - - self.add_model_config_options(options, config_model='mpas-ocean') + 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') From 30ff99f29de85b409d81d3225da5507332bcc590 Mon Sep 17 00:00:00 2001 From: Carolyn Begeman Date: Tue, 1 Oct 2024 14:10:21 -0500 Subject: [PATCH 4/5] Add manufactured tests to convergence suite --- polaris/ocean/suites/convergence.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polaris/ocean/suites/convergence.txt b/polaris/ocean/suites/convergence.txt index 56a8e63c7..3c2ff3b7f 100644 --- a/polaris/ocean/suites/convergence.txt +++ b/polaris/ocean/suites/convergence.txt @@ -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 From 4d915a5e33cff6649e351fd49daad35997988b77 Mon Sep 17 00:00:00 2001 From: Carolyn Begeman Date: Tue, 1 Oct 2024 14:17:00 -0500 Subject: [PATCH 5/5] Update docs --- .../ocean/tasks/manufactured_solution.md | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/users_guide/ocean/tasks/manufactured_solution.md b/docs/users_guide/ocean/tasks/manufactured_solution.md index f9e840e0f..80b65b509 100644 --- a/docs/users_guide/ocean/tasks/manufactured_solution.md +++ b/docs/users_guide/ocean/tasks/manufactured_solution.md @@ -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 @@ -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.