-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add convergence tasks for space and time only #236
Merged
cbegeman
merged 9 commits into
E3SM-Project:main
from
cbegeman:enhance-convergence-tasks
Nov 25, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
457c77c
Extend convergence framework to space and time
cbegeman ad8e4d6
Update docs for new convergence tests
cbegeman c661b93
Update doc strings
cbegeman d29a199
Update suites
cbegeman e46197a
Update docs for new convergence tests
cbegeman f39c33d
Update sphere_transport for convergence
cbegeman fa5d6c1
fixup imports
cbegeman 97ff0dd
Separate refinement factors config options by refinement type
cbegeman 9fe597a
Change task list order
cbegeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,16 +219,35 @@ tests on {ref}`dev-ocean-spherical-meshes` and planar meshes. | |
The ocean framework includes shared config options and base classes for | ||
forward and analysis steps that are expected to be useful across these tests. | ||
|
||
The key config options that control the convergence test are `base_resolution` | ||
and `refinement_factors`. The `base_resolution` is multipled by the | ||
`refinement_factors` to determine which resolutions to test when the | ||
convergence is being tested in space (or space and time together). The | ||
`base_resolution` is applied to all steps when convergence in time is tested. | ||
`base_resolution` times `dt_per_km` determines the base timestep in that case | ||
and is then multiplied by the `refinement_factors` to determine which time steps | ||
to test. When spherical meshes are being tested, the values in the | ||
`convergence` section are overridden by their values in the | ||
`spherical_convergence` section with a prefix indicating the mesh type. | ||
|
||
The shared config options are: | ||
```cfg | ||
# config options for spherical convergence tests | ||
[spherical_convergence] | ||
|
||
# The base resolution for the icosahedral mesh to which the refinement | ||
# factors are applied | ||
icos_base_resolution = 60. | ||
|
||
# a list of icosahedral mesh resolutions (km) to test | ||
icos_resolutions = 60, 120, 240, 480 | ||
icos_refinement_factors = 8., 4., 2., 1. | ||
|
||
# The base resolution for the quasi-uniform mesh to which the refinement | ||
# factors are applied | ||
qu_base_resolution = 120. | ||
|
||
# a list of quasi-uniform mesh resolutions (km) to test | ||
qu_resolutions = 60, 90, 120, 150, 180, 210, 240 | ||
qu_refinement_factors = 0.5, 0.75, 1., 1.25, 1.5, 1.75, 2. | ||
|
||
[convergence] | ||
|
||
|
@@ -241,6 +260,15 @@ convergence_thresh = 1.0 | |
# Type of error to compute | ||
error_type = l2 | ||
|
||
# the base mesh resolution (km) to which refinement_factors | ||
# are applied if refinement is 'space' or 'both' on a planar mesh | ||
# base resolutions for spherical meshes are given in section spherical_convergence | ||
base_resolution = 120 | ||
|
||
# refinement factors for a planar mesh applied to either space or time | ||
# refinement factors for a spherical mesh given in section spherical_convergence | ||
refinement_factors = 4., 2., 1., 0.5 | ||
Comment on lines
+268
to
+270
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this has now been updated to separate lists for time and space in the code. |
||
|
||
# config options for convergence forward steps | ||
[convergence_forward] | ||
|
||
|
@@ -325,7 +353,8 @@ class Forward(SphericalConvergenceForward): | |
bell test case | ||
""" | ||
|
||
def __init__(self, component, name, subdir, resolution, mesh, init): | ||
def __init__(self, component, name, subdir, mesh, init, | ||
refinement_factor, refinement='both'): | ||
""" | ||
Create a new step | ||
|
||
|
@@ -348,6 +377,9 @@ class Forward(SphericalConvergenceForward): | |
|
||
init : polaris.Step | ||
The init step | ||
|
||
refinement_factor : float | ||
The factor by which to scale space, time or both | ||
""" | ||
package = 'polaris.ocean.tasks.cosine_bell' | ||
validate_vars = ['normalVelocity', 'tracer1'] | ||
|
@@ -356,7 +388,10 @@ class Forward(SphericalConvergenceForward): | |
init=init, package=package, | ||
yaml_filename='forward.yaml', | ||
output_filename='output.nc', | ||
validate_vars=validate_vars) | ||
validate_vars=validate_vars, | ||
graph_target=f'{init.path}/graph.info', | ||
refinement_factor=refinement_factor, | ||
refinement=refinement) | ||
``` | ||
Each convergence test must define a YAML file with model config options, called | ||
`forward.yaml` by default. The `package` parameter is the location of this | ||
|
@@ -419,7 +454,7 @@ class Analysis(ConvergenceAnalysis): | |
""" | ||
A step for analyzing the output from the cosine bell test case | ||
""" | ||
def __init__(self, component, resolutions, subdir, dependencies): | ||
def __init__(self, component, subdir, dependencies, refinement='both'): | ||
""" | ||
Create the step | ||
|
||
|
@@ -436,14 +471,18 @@ class Analysis(ConvergenceAnalysis): | |
|
||
dependencies : dict of dict of polaris.Steps | ||
The dependencies of this step | ||
|
||
refinement : str, optional | ||
Whether to refine in space, time or both space and time | ||
""" | ||
convergence_vars = [{'name': 'tracer1', | ||
'title': 'tracer1', | ||
'zidx': 0}] | ||
super().__init__(component=component, subdir=subdir, | ||
resolutions=resolutions, | ||
dependencies=dependencies, | ||
convergence_vars=convergence_vars) | ||
convergence_vars=convergence_vars, | ||
refinement=refinement) | ||
``` | ||
|
||
Many tasks will also need to override the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,106 @@ | ||
from polaris.ocean.convergence.analysis import ConvergenceAnalysis | ||
from polaris.ocean.convergence.forward import ConvergenceForward | ||
import numpy as np | ||
|
||
|
||
def get_resolution_for_task(config, refinement_factor, | ||
refinement='both'): | ||
""" | ||
Get the resolution for a step in a convergence task | ||
|
||
Parameters | ||
---------- | ||
config : polaris.Config | ||
The config options for this task | ||
|
||
refinement_factor : float | ||
The factor by which either resolution or time is refined for this step | ||
|
||
refinement : str, optional | ||
Whether to refine in space, time or both | ||
|
||
Returns | ||
------- | ||
resolution : float | ||
The resolution corresponding to the refinement_factor and convergence | ||
test type | ||
""" | ||
if refinement == 'both': | ||
option = 'refinement_factors_space' | ||
else: | ||
option = f'refinement_factors_{refinement}' | ||
base_resolution = config.getfloat('convergence', 'base_resolution') | ||
refinement_factors = config.getlist('convergence', option, dtype=float) | ||
|
||
if refinement_factor not in refinement_factors: | ||
raise ValueError( | ||
'refinement_factor not found in config option refinement_factors') | ||
|
||
if refinement == 'time': | ||
resolution = base_resolution | ||
else: | ||
resolution = refinement_factor * base_resolution | ||
|
||
return resolution | ||
|
||
|
||
def get_timestep_for_task(config, refinement_factor, | ||
refinement='both'): | ||
""" | ||
Get the time step for a forward step in a convergence task | ||
|
||
Parameters | ||
---------- | ||
config : polaris.Config | ||
The config options for this task | ||
|
||
refinement_factor : float | ||
The factor by which either resolution or time is refined for this step | ||
|
||
refinement : str, optional | ||
Whether to refine in space, time or both | ||
|
||
Returns | ||
------- | ||
resolution : float | ||
The resolution corresponding to the refinement_factor and convergence | ||
test type | ||
""" | ||
|
||
if refinement == 'both': | ||
option = 'refinement_factors_space' | ||
else: | ||
option = f'refinement_factors_{refinement}' | ||
base_resolution = config.getfloat('convergence', 'base_resolution') | ||
refinement_factors = config.getlist('convergence', option, dtype=float) | ||
|
||
if refinement_factor not in refinement_factors: | ||
raise ValueError( | ||
'refinement_factor not found in config option refinement_factors') | ||
|
||
resolution = get_resolution_for_task( | ||
config, refinement_factor, refinement=refinement) | ||
|
||
section = config['convergence_forward'] | ||
time_integrator = section.get('time_integrator') | ||
# dt is proportional to resolution: default 30 seconds per km | ||
if time_integrator == 'RK4': | ||
dt_per_km = section.getfloat('rk4_dt_per_km') | ||
btr_timestep = 0. | ||
else: | ||
dt_per_km = section.getfloat('split_dt_per_km') | ||
btr_dt_per_km = section.getfloat('btr_dt_per_km') | ||
for idx, refinement_factor in enumerate(refinement_factors): | ||
if refinement == 'time': | ||
btr_timestep = btr_dt_per_km * base_resolution * \ | ||
refinement_factor | ||
elif refinement == 'space': | ||
btr_timestep = btr_dt_per_km * base_resolution | ||
else: | ||
btr_timestep = btr_dt_per_km * resolution | ||
if refinement == 'time': | ||
timestep = dt_per_km * refinement_factor * resolution | ||
elif refinement == 'space': | ||
timestep = dt_per_km * base_resolution | ||
else: | ||
timestep = dt_per_km * resolution | ||
|
||
return timestep, btr_timestep |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe these config options need to be updated to match recent code changes.