Skip to content
Closed
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
6 changes: 6 additions & 0 deletions compass/ocean/tests/global_ocean/global_ocean.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ btr_dt_per_km = 1.5

# Maximum allowed Haney number for configurations with ice-shelf cavities
rx1_max = 20
# the number of iterations of topography smoothing (0 means no smoothing)
topo_smooth_num_passes = 0
# The distance in km over which the Gaussian filter is applied
topo_smooth_distance_limit = 200.0
# The standard deviation in km of the Gaussian filter
topo_smooth_std_deviation = 100.0

# number of cores to use
init_ntasks = 36
Expand Down
52 changes: 50 additions & 2 deletions compass/ocean/tests/global_ocean/init/initial_state.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
from importlib.resources import contents
from importlib.resources import contents, read_text

import xarray as xr
from jinja2 import Template
from mpas_tools.io import write_netcdf
from mpas_tools.logging import check_call

from compass.io import symlink
from compass.model import run_model
from compass.ocean.plot import plot_initial_state, plot_vertical_grid
from compass.ocean.tests.global_ocean.metadata import (
Expand Down Expand Up @@ -79,7 +85,7 @@ def __init__(self, test_case, mesh, initial_condition):

cull_step = self.mesh.steps['cull_mesh']
target = os.path.join(cull_step.path, 'topography_culled.nc')
self.add_input_file(filename='topography.nc',
self.add_input_file(filename='topography_culled.nc',
work_dir_target=target)

self.add_input_file(
Expand Down Expand Up @@ -162,6 +168,8 @@ def run(self):
Run this step of the testcase
"""
config = self.config
self._smooth_topography()

interfaces = generate_1d_grid(config=config)

write_1d_grid(interfaces=interfaces, out_filename='vertical_grid.nc')
Expand All @@ -186,3 +194,43 @@ def _get_resources(self):
self.cpus_per_task = config.getint('global_ocean',
'init_cpus_per_task')
self.min_cpus_per_task = self.cpus_per_task

def _smooth_topography(self):
""" Smooth the topography using a Gaussian filter """
config = self.config
section = config['global_ocean']
num_passes = section.getint('topo_smooth_num_passes')
if num_passes == 0:
# just symlink the culled topography to be the topography used for
# the initial condition
symlink(target='topography_culled.nc', link_name='topography.nc')
return

distance_limit = section.getfloat('topo_smooth_distance_limit')
std_deviation = section.getfloat('topo_smooth_std_deviation')

template = Template(read_text(
'compass.ocean.tests.global_ocean.init', 'smooth_topo.template'))

text = template.render(num_passes=f'{num_passes}',
distance_limit=f'{distance_limit}',
std_deviation=f'{std_deviation}')

# add trailing end line
text = f'{text}\n'

with open('smooth_depth_in', 'w') as file:
file.write(text)

check_call(args=['ocean_smooth_topo_before_init'],
logger=self.logger)

with (xr.open_dataset('topography_culled.nc') as ds_topo):
with xr.open_dataset('topography_orig_and_smooth.nc') as ds_smooth:
for field in ['bed_elevation', 'landIceDraftObserved',
'landIceThkObserved']:
attrs = ds_topo[field].attrs
ds_topo[field] = ds_smooth[f'{field}New']
ds_topo[field].attrs = attrs

write_netcdf(ds_topo, 'topography.nc')
8 changes: 8 additions & 0 deletions compass/ocean/tests/global_ocean/init/smooth_topo.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
&smooth
filename_depth_in = "topography_culled.nc"
filename_depth_out = "topography_orig_and_smooth.nc"
filename_mpas_mesh = "mesh.nc"
distanceLimit = {{ distance_limit }}
stdDeviation = {{ std_deviation }}
numSmoothingPasses = {{ num_passes }}
/
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dynamic_adjustment:
land_ice_flux_mode: data
land_ice_flux_mode: pressure_only
get_dt_from_min_res: False

steps:
Expand Down Expand Up @@ -28,9 +28,9 @@ dynamic_adjustment:
Rayleigh_damping_coeff: 1.0e-6

simulation:
run_duration: 10_00:00:00
run_duration: 20_00:00:00
output_interval: 10_00:00:00
restart_interval: 10_00:00:00
dt: 00:30:00
btr_dt: 00:01:00
dt: 00:20:00
btr_dt: 00:00:40
Rayleigh_damping_coeff: None
13 changes: 10 additions & 3 deletions compass/ocean/tests/global_ocean/mesh/ec30to60/ec30to60.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ transition_levels = 28
# Maximum allowed Haney number for configurations with ice-shelf cavities
rx1_max = 10

# the number of iterations of topography smoothing
topo_smooth_num_passes = 0
# The distance in km over which the Gaussian filter is applied
topo_smooth_distance_limit = 200.0
# The standard deviation in km of the Gaussian filter
topo_smooth_std_deviation = 100.0

# the approximate number of cells in the mesh
approx_cell_count = 240000

Expand All @@ -37,15 +44,15 @@ prefix = EC
mesh_description = MPAS Eddy Closure mesh for E3SM version ${e3sm_version} with
enhanced resolution around the equator (30 km), South pole
(35 km), Greenland (${min_res} km), ${max_res}-km resolution
at mid latitudes, and <<<levels>>> vertical levels
at mid latitudes, and <<<levels>>> vertical levels.
# E3SM version that the mesh is intended for
e3sm_version = 3
# The revision number of the mesh, which should be incremented each time the
# mesh is revised
mesh_revision = 2
mesh_revision = 5
# the minimum (finest) resolution in the mesh
min_res = 30
# the maximum (coarsest) resolution in the mesh, can be the same as min_res
max_res = 60
# The URL of the pull request documenting the creation of the mesh
pull_request = https://github.com/MPAS-Dev/compass/pull/689
pull_request = https://github.com/MPAS-Dev/compass/pull/736
1 change: 1 addition & 0 deletions compass/ocean/tests/global_ocean/streams.forward
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<var name="xtime"/>
<var name="normalVelocity"/>
<var name="layerThickness"/>
<var name="kineticEnergyCell"/>
</stream>

<stream name="forcing_data"
Expand Down
2 changes: 1 addition & 1 deletion conda/compass_env/spec-file.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mache=1.16.0
{% endif %}
matplotlib-base
metis
mpas_tools=0.26.0
mpas_tools=0.28.0
nco
netcdf4=*=nompi_*
numpy
Expand Down