Skip to content

Commit

Permalink
Merge pull request #390 from sbrus89/hurricane
Browse files Browse the repository at this point in the history
Add hurricane cases from legacy compass
  • Loading branch information
xylar authored Jul 5, 2022
2 parents a718af3 + 76a7457 commit 569e336
Show file tree
Hide file tree
Showing 26 changed files with 1,862 additions and 2 deletions.
2 changes: 2 additions & 0 deletions compass/ocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from compass.ocean.tests.global_convergence import GlobalConvergence
from compass.ocean.tests.global_ocean import GlobalOcean
from compass.ocean.tests.gotm import Gotm
from compass.ocean.tests.hurricane import Hurricane
from compass.ocean.tests.internal_wave import InternalWave
from compass.ocean.tests.ice_shelf_2d import IceShelf2d
from compass.ocean.tests.isomip_plus import IsomipPlus
Expand Down Expand Up @@ -31,6 +32,7 @@ def __init__(self):
self.add_test_group(GlobalConvergence(mpas_core=self))
self.add_test_group(GlobalOcean(mpas_core=self))
self.add_test_group(Gotm(mpas_core=self))
self.add_test_group(Hurricane(mpas_core=self))
self.add_test_group(InternalWave(mpas_core=self))
self.add_test_group(IceShelf2d(mpas_core=self))
self.add_test_group(IsomipPlus(mpas_core=self))
Expand Down
3 changes: 3 additions & 0 deletions compass/ocean/tests/global_ocean/global_ocean.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ email = autodetect
# The URL of the pull request documenting the creation of the mesh
pull_request = <<<Missing>>>

# Elevation threshold for including land cells
floodplain_elevation = 10.0


# config options related to dynamic adjustment
[dynamic_adjustment]
Expand Down
29 changes: 27 additions & 2 deletions compass/ocean/tests/global_ocean/mesh/mesh.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from mpas_tools.ocean import build_spherical_mesh
from mpas_tools.ocean import inject_bathymetry
from abc import ABC, abstractmethod

from compass.ocean.tests.global_ocean.mesh.cull import cull_mesh
Expand All @@ -24,7 +25,8 @@ class MeshStep(Step):
The name of the mesh config file
"""
def __init__(self, test_case, mesh_name, with_ice_shelf_cavities,
package, mesh_config_filename, name='mesh', subdir=None):
package, mesh_config_filename, name='mesh', subdir=None,
do_inject_bathymetry=False, preserve_floodplain=False):
"""
Create a new step
Expand All @@ -50,6 +52,14 @@ def __init__(self, test_case, mesh_name, with_ice_shelf_cavities,
subdir : str, optional
the subdirectory for the step. The default is ``name``
do_inject_bathymetry : bool, optional
Whether to interpolate bathymetry from a data file so it
can be used as a culling criteria
preserve_floodplain : bool, optional
Whether to leave land cells in the mesh based on bathymetry
specified by do_inject_bathymetry
"""
super().__init__(test_case, name=name, subdir=subdir, cores=None,
min_cores=None, threads=None)
Expand All @@ -61,6 +71,8 @@ def __init__(self, test_case, mesh_name, with_ice_shelf_cavities,
self.with_ice_shelf_cavities = with_ice_shelf_cavities
self.package = package
self.mesh_config_filename = mesh_config_filename
self.do_inject_bathymetry = do_inject_bathymetry
self.preserve_floodplain = preserve_floodplain

def setup(self):
"""
Expand All @@ -71,26 +83,39 @@ def setup(self):
config = self.config
self.cores = config.getint('global_ocean', 'mesh_cores')
self.min_cores = config.getint('global_ocean', 'mesh_min_cores')
self.floodplain_elevation = config.getfloat(
'global_ocean',
'floodplain_elevation')

def run(self):
"""
Run this step of the test case
"""
with_ice_shelf_cavities = self.with_ice_shelf_cavities
logger = self.logger
do_inject_bathymetry = self.do_inject_bathymetry
preserve_floodplain = self.preserve_floodplain
floodplain_elevation = self.floodplain_elevation

# only use progress bars if we're not writing to a log file
use_progress_bar = self.log_filename is None

# create the base mesh
cellWidth, lon, lat = self.build_cell_width_lat_lon()
build_spherical_mesh(cellWidth, lon, lat, out_filename='base_mesh.nc',
logger=logger, use_progress_bar=use_progress_bar)
logger=logger, use_progress_bar=use_progress_bar,
do_inject_bathymetry=do_inject_bathymetry,
preserve_floodplain=preserve_floodplain,
floodplain_elevation=floodplain_elevation)

cull_mesh(with_critical_passages=True, logger=logger,
use_progress_bar=use_progress_bar,
preserve_floodplain=preserve_floodplain,
with_cavities=with_ice_shelf_cavities)

if do_inject_bathymetry:
inject_bathymetry(mesh_file='culled_mesh.nc')

@abstractmethod
def build_cell_width_lat_lon(self):
"""
Expand Down
31 changes: 31 additions & 0 deletions compass/ocean/tests/hurricane/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from compass.testgroup import TestGroup

from compass.ocean.tests.hurricane.mesh import Mesh
from compass.ocean.tests.hurricane.init import Init
from compass.ocean.tests.hurricane.forward import Forward


class Hurricane(TestGroup):
"""
A test group for hurricane simulations with MPAS-Ocean
"""
def __init__(self, mpas_core):
"""
mpas_core : compass.ocean.Ocean
the MPAS core that this test group belongs to
"""
super().__init__(mpas_core=mpas_core,
name='hurricane')

storm = 'sandy'
mesh_name = 'DEQU120at30cr10rr2'
mesh = Mesh(test_group=self, mesh_name=mesh_name)
self.add_test_case(mesh)

init = Init(test_group=self, mesh=mesh, storm=storm)
self.add_test_case(init)

self.add_test_case(Forward(test_group=self,
mesh=mesh,
storm=storm,
init=init))
Loading

0 comments on commit 569e336

Please sign in to comment.