-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from cbegeman/enhance-convergence-tasks
Add convergence tasks for space and time only This PR extends the convergence test framework to accommodate convergence in space, time or both. This PR also adds additional tests for space-only and time-only convergence for the cosine_bell, geostrophic, manufactured_solution, and inertial_gravity_wave groups. The convergence_time cases have not been optimized (in terms of resolution and time steps) nor have separate convergence thresholds been specified.
- Loading branch information
Showing
39 changed files
with
1,068 additions
and
492 deletions.
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
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.