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

Add Kuroshio8to60E2r4 and Kuroshio12to60E2r4 meshes #525

Merged
merged 19 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions compass/ocean/suites/kuroshio12to60.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ocean/global_ocean/Kuroshio12to60/mesh
ocean/global_ocean/Kuroshio12to60/PHC/init
ocean/global_ocean/Kuroshio12to60/PHC/performance_test
ocean/global_ocean/Kuroshio12to60/PHC/dynamic_adjustment
ocean/global_ocean/Kuroshio12to60/PHC/files_for_e3sm
5 changes: 5 additions & 0 deletions compass/ocean/suites/kuroshio8to60.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ocean/global_ocean/Kuroshio8to60/mesh
ocean/global_ocean/Kuroshio8to60/PHC/init
ocean/global_ocean/Kuroshio8to60/PHC/performance_test
ocean/global_ocean/Kuroshio8to60/PHC/dynamic_adjustment
ocean/global_ocean/Kuroshio8to60/PHC/files_for_e3sm
26 changes: 26 additions & 0 deletions compass/ocean/tests/global_ocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from compass.ocean.tests.global_ocean.mesh.ec30to60.dynamic_adjustment import (
EC30to60DynamicAdjustment,
)
from compass.ocean.tests.global_ocean.mesh.kuroshio.dynamic_adjustment import (
KuroshioDynamicAdjustment,
)
from compass.ocean.tests.global_ocean.mesh.qu240.dynamic_adjustment import (
QU240DynamicAdjustment,
)
Expand Down Expand Up @@ -229,5 +232,28 @@ def __init__(self, mpas_core):
test_group=self, mesh=mesh, init=init,
dynamic_adjustment=dynamic_adjustment))

# Kuroshio meshes without ice-shelf cavities
for mesh_name in ['Kuroshio12to60', 'Kuroshio8to60']:
mesh = Mesh(test_group=self, mesh_name=mesh_name)
self.add_test_case(mesh)

init = Init(test_group=self, mesh=mesh,
initial_condition='PHC',
with_bgc=False)
self.add_test_case(init)
time_integrator = 'split_explicit'
self.add_test_case(
PerformanceTest(
test_group=self, mesh=mesh, init=init,
time_integrator=time_integrator))
dynamic_adjustment = KuroshioDynamicAdjustment(
test_group=self, mesh=mesh, init=init,
time_integrator=time_integrator)
self.add_test_case(dynamic_adjustment)
self.add_test_case(
FilesForE3SM(
test_group=self, mesh=mesh, init=init,
dynamic_adjustment=dynamic_adjustment))

# A test case for making E3SM support files from an existing mesh
self.add_test_case(FilesForE3SM(test_group=self))
53 changes: 0 additions & 53 deletions compass/ocean/tests/global_ocean/configure.py

This file was deleted.

8 changes: 3 additions & 5 deletions compass/ocean/tests/global_ocean/files_for_e3sm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

from compass.io import package_path, symlink
from compass.ocean.tests.global_ocean.configure import configure_global_ocean
from compass.ocean.tests.global_ocean.files_for_e3sm.diagnostic_maps import (
DiagnosticMaps,
)
Expand Down Expand Up @@ -92,15 +91,14 @@ def configure(self):
"""
Modify the configuration options for this test case
"""
if self.init is not None:
self.init.configure(config=self.config)

mesh = self.mesh
init = self.init
dynamic_adjustment = self.dynamic_adjustment
config = self.config
work_dir = self.work_dir

if mesh is not None:
configure_global_ocean(test_case=self, mesh=mesh,
init=init)
package = 'compass.ocean.tests.global_ocean.files_for_e3sm'
with package_path(package, 'README') as target:
symlink(str(target), f'{work_dir}/README')
Expand Down
11 changes: 6 additions & 5 deletions compass/ocean/tests/global_ocean/forward.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
from importlib.resources import contents

from compass.ocean.tests.global_ocean.configure import configure_global_ocean
from compass.ocean.tests.global_ocean.metadata import \
add_mesh_and_init_metadata
from compass.model import run_model
from compass.testcase import TestCase
from compass.ocean.tests.global_ocean.metadata import (
add_mesh_and_init_metadata,
)
from compass.step import Step
from compass.testcase import TestCase


class ForwardStep(Step):
Expand Down Expand Up @@ -164,6 +164,7 @@ def _get_resources(self):
self.openmp_threads = config.getint(
'global_ocean', 'forward_threads')


class ForwardTestCase(TestCase):
"""
A parent class for test cases for forward runs with global MPAS-Ocean mesh
Expand Down Expand Up @@ -211,7 +212,7 @@ def configure(self):
"""
Modify the configuration options for this test case
"""
configure_global_ocean(test_case=self, mesh=self.mesh, init=self.init)
self.init.configure(config=self.config)


def get_forward_subdir(init_subdir, time_integrator, name):
Expand Down
27 changes: 23 additions & 4 deletions compass/ocean/tests/global_ocean/init/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os

from compass.testcase import TestCase
from compass.ocean.tests.global_ocean.init.initial_state import InitialState
from compass.ocean.tests.global_ocean.init.ssh_adjustment import SshAdjustment
from compass.ocean.tests.global_ocean.configure import configure_global_ocean
from compass.testcase import TestCase
from compass.validate import compare_variables


Expand Down Expand Up @@ -67,11 +66,31 @@ def __init__(self, test_group, mesh, initial_condition, with_bgc):
self.add_step(
SshAdjustment(test_case=self))

def configure(self):
def configure(self, config=None):
"""
Modify the configuration options for this test case

config : compass.config.CompassConfigParser, optional
Configuration options to update if not those for this test case
"""
configure_global_ocean(test_case=self, mesh=self.mesh, init=self)
if config is None:
config = self.config

# set mesh-relate config options
self.mesh.configure(config=config)

initial_condition = self.initial_condition
descriptions = {'PHC': 'Polar science center Hydrographic '
'Climatology (PHC)',
'EN4_1900':
"Met Office Hadley Centre's EN4 dataset from 1900"}
config.set('global_ocean', 'init_description',
descriptions[initial_condition])

if self.with_bgc:
# todo: this needs to be filled in!
config.set('global_ocean', 'bgc_description',
'<<<Missing>>>')

def validate(self):
"""
Expand Down
46 changes: 39 additions & 7 deletions compass/ocean/tests/global_ocean/mesh/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from compass.testcase import TestCase
from compass.mesh.spherical import IcosahedralMeshStep, \
QuasiUniformSphericalMeshStep
from compass.mesh.spherical import (
IcosahedralMeshStep,
QuasiUniformSphericalMeshStep,
)
from compass.ocean.mesh.cull import CullMeshStep
from compass.ocean.tests.global_ocean.mesh.arrm10to60 import ARRM10to60BaseMesh
from compass.ocean.tests.global_ocean.mesh.ec30to60 import EC30to60BaseMesh
from compass.ocean.tests.global_ocean.mesh.kuroshio import KuroshioBaseMesh
from compass.ocean.tests.global_ocean.mesh.so12to60 import SO12to60BaseMesh
from compass.ocean.tests.global_ocean.mesh.wc14 import WC14BaseMesh
from compass.ocean.tests.global_ocean.configure import configure_global_ocean
from compass.ocean.tests.global_ocean.metadata import (
get_author_and_email_from_git,
)
from compass.testcase import TestCase
from compass.validate import compare_variables


Expand Down Expand Up @@ -68,6 +73,8 @@ def __init__(self, test_group, mesh_name):
base_mesh_step = ARRM10to60BaseMesh(self, name=name, subdir=subdir)
elif mesh_name in ['SO12to60', 'SOwISC12to60']:
base_mesh_step = SO12to60BaseMesh(self, name=name, subdir=subdir)
elif mesh_name.startswith('Kuroshio'):
base_mesh_step = KuroshioBaseMesh(self, name=name, subdir=subdir)
elif mesh_name in ['WC14']:
base_mesh_step = WC14BaseMesh(self, name=name, subdir=subdir)
else:
Expand All @@ -79,14 +86,39 @@ def __init__(self, test_group, mesh_name):
test_case=self, base_mesh_step=base_mesh_step,
with_ice_shelf_cavities=self.with_ice_shelf_cavities))

def configure(self):
def configure(self, config=None):
"""
Modify the configuration options for this test case

config : compass.config.CompassConfigParser, optional
Configuration options to update if not those for this test case
"""
configure_global_ocean(test_case=self, mesh=self)
config = self.config
if config is None:
config = self.config
config.set('spherical_mesh', 'add_mesh_density', 'True')
config.set('spherical_mesh', 'plot_cell_width', 'True')
config.add_from_package('compass.mesh', 'mesh.cfg')
if self.mesh_name.startswith('Kuroshio'):
# add the config options for all kuroshio meshes
config.add_from_package(
'compass.ocean.tests.global_ocean.mesh.kuroshio',
'kuroshio.cfg', exception=True)
config.add_from_package(self.package, self.mesh_config_filename,
exception=True)

if self.with_ice_shelf_cavities:
prefix = config.get('global_ocean', 'prefix')
config.set('global_ocean', 'prefix', f'{prefix}wISC')
config.set('global_ocean', 'wisc_description',
'Includes cavities under the ice shelves around '
'Antarctica')

# a description of the bathymetry
config.set('global_ocean', 'bathy_description',
'Bathymetry is from GEBCO 2022, combined with BedMachine '
'Antarctica v2 around Antarctica.')

get_author_and_email_from_git(config)

def validate(self):
"""
Expand Down
106 changes: 106 additions & 0 deletions compass/ocean/tests/global_ocean/mesh/kuroshio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import mpas_tools.mesh.creation.mesh_definition_tools as mdt
import numpy as np
from geometric_features import read_feature_collection
from mpas_tools.cime.constants import constants
from mpas_tools.mesh.creation.signed_distance import (
signed_distance_from_geojson,
)

from compass.mesh import QuasiUniformSphericalMeshStep


class KuroshioBaseMesh(QuasiUniformSphericalMeshStep):
"""
A step for creating Kuroshio meshes
"""
def setup(self):
"""
Add some input files
"""
self.add_input_file(filename='wbc_rectangle3-1.geojson',
package=self.__module__)
self.add_input_file(filename='wbc_rectangle3-2.geojson',
package=self.__module__)
self.add_input_file(filename='wbc_rectangle3-3.geojson',
package=self.__module__)

super().setup()

def build_cell_width_lat_lon(self):
"""
Create cell width array for this mesh on a regular latitude-longitude
grid

Returns
-------
cellWidth : numpy.array
m x n array of cell width in km

lon : numpy.array
longitude in degrees (length n and between -180 and 180)

lat : numpy.array
longitude in degrees (length m and between -90 and 90)
"""
config = self.config
dlon = 0.1
dlat = dlon
earth_radius = constants['SHR_CONST_REARTH']
nlon = int(360. / dlon) + 1
nlat = int(180. / dlat) + 1
lon = np.linspace(-180., 180., nlon)
lat = np.linspace(-90., 90., nlat)

cellWidth = mdt.EC_CellWidthVsLat(lat, cellWidthEq=30.,
cellWidthMidLat=60.,
cellWidthPole=35.,
latPosEq=7.5, latWidthEq=3.0)

_, cellWidth = np.meshgrid(lon, cellWidth)

fc1 = read_feature_collection('wbc_rectangle3-1.geojson')

ks_signed_distance1 = signed_distance_from_geojson(fc1, lon, lat,
earth_radius,
max_length=0.25)

trans_width = 400e3
trans_start = 0
dx_min = config.getfloat('global_ocean', 'min_res')

weights = 0.5 * (1 + np.tanh((ks_signed_distance1 - trans_start) /
trans_width))

cellWidth = dx_min * (1 - weights) + cellWidth * weights

fc2 = read_feature_collection('wbc_rectangle3-2.geojson')

ks_signed_distance2 = signed_distance_from_geojson(fc2, lon, lat,
earth_radius,
max_length=0.25)

trans_width = 400e3
trans_start = 0
dx_min = 40.

weights = 0.5 * (1 + np.tanh((ks_signed_distance2 - trans_start) /
trans_width))

cellWidth = dx_min * (1 - weights) + cellWidth * weights

fc3 = read_feature_collection('wbc_rectangle3-3.geojson')

ks_signed_distance3 = signed_distance_from_geojson(fc3, lon, lat,
earth_radius,
max_length=0.25)

trans_width = 400e3
trans_start = 0
dx_min = 30.

weights = 0.5 * (1 + np.tanh((ks_signed_distance3 - trans_start) /
trans_width))

cellWidth = dx_min * (1 - weights) + cellWidth * weights

return cellWidth, lon, lat
Loading