Skip to content

Commit

Permalink
Merge pull request #717 from xylar/add-step-for-reconstruction-coeffs
Browse files Browse the repository at this point in the history
Add step for reconstruction coeffs
  • Loading branch information
xylar authored Oct 18, 2023
2 parents b372d6f + 2bd9845 commit ab68ad7
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 5 deletions.
7 changes: 7 additions & 0 deletions compass/ocean/tests/global_ocean/files_for_e3sm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
from compass.ocean.tests.global_ocean.files_for_e3sm.seaice_mesh import ( # noqa: E501
SeaiceMesh,
)
from compass.ocean.tests.global_ocean.files_for_e3sm.write_coeffs_reconstruct import ( # noqa: E501
WriteCoeffsReconstruct,
)
from compass.ocean.tests.global_ocean.forward import get_forward_subdir
from compass.testcase import TestCase

Expand Down Expand Up @@ -115,6 +118,10 @@ def __init__(self, test_group, mesh=None, init=None,
self.add_step(RemapIcebergClimatology(
test_case=self))

if mesh is not None and init is not None:
self.add_step(WriteCoeffsReconstruct(
test_case=self, mesh=mesh, init=init))

def configure(self):
"""
Modify the configuration options for this test case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class FilesForE3SMStep(Step):
A list of the variables that belong to the MPAS horizontal mesh
"""

def __init__(self, test_case, name, subdir=None, cpus_per_task=1,
min_cpus_per_task=1, ntasks=1, min_tasks=1,):
def __init__(self, test_case, name='files_for_e3sm_step', subdir=None,
cpus_per_task=1, min_cpus_per_task=1, ntasks=1, min_tasks=1,
**kwargs):
"""
Create a new test case
Expand Down Expand Up @@ -79,7 +80,7 @@ def __init__(self, test_case, name, subdir=None, cpus_per_task=1,
super().__init__(test_case=test_case, name=name, subdir=subdir,
cpus_per_task=cpus_per_task,
min_cpus_per_task=min_cpus_per_task, ntasks=ntasks,
min_tasks=min_tasks)
min_tasks=min_tasks, **kwargs)

self.mesh_short_name = None
self.creation_date = None
Expand Down Expand Up @@ -130,6 +131,7 @@ def setup(self):
if with_ice_shelf_cavities != 'autodetect':
self.with_ice_shelf_cavities = \
(with_ice_shelf_cavities.lower() == 'true')
super().setup()

def run(self): # noqa: C901
"""
Expand Down Expand Up @@ -209,3 +211,5 @@ def run(self): # noqa: C901
os.makedirs(dest_dir)
except FileExistsError:
pass

super().run()
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os

from mpas_tools.logging import check_call

from compass.io import symlink
from compass.ocean.tests.global_ocean.files_for_e3sm.files_for_e3sm_step import ( # noqa: E501
FilesForE3SMStep,
)
from compass.ocean.tests.global_ocean.forward import ForwardStep


class WriteCoeffsReconstruct(ForwardStep, FilesForE3SMStep):
"""
A step for writing out ``coeffs_reconstruct`` for a given MPAS mesh
"""

def __init__(self, test_case, mesh, init):
"""
Create a new step
Parameters
----------
test_case : compass.TestCase
The test case this step belongs to
mesh : compass.ocean.tests.global_ocean.mesh.Mesh
The test case that produces the mesh for this run
init : compass.ocean.tests.global_ocean.init.Init
The test case that produces the initial condition for this run
"""
super().__init__(test_case=test_case, mesh=mesh, init=init,
time_integrator='split_explicit',
name='write_coeffs_reconstruct')

package = 'compass.ocean.tests.global_ocean.files_for_e3sm.' \
'write_coeffs_reconstruct'

self.add_namelist_file(package, 'namelist.reconstruct')
self.add_streams_file(package, 'streams.reconstruct')

def run(self):
"""
Run this step of the testcase
"""
super().run()

# perform a test reconstruction to make sure things are working
args = ['vector_reconstruct',
'-i', 'restart.nc',
'-o', 'velocity_components.nc',
'-w', 'coeffs_reconstruct.nc',
'-v', 'normalVelocity',
'--out_variables', 'velocity']
check_call(args=args, logger=self.logger)

reconstruct_dir = \
'../assembled_files/diagnostics/mpas_analysis/reconstruct'
try:
os.makedirs(reconstruct_dir)
except FileExistsError:
pass

reconstruct_filename = f'{self.mesh_short_name}_coeffs_reconstruct.nc'
# make links in diagnostics directory
symlink(os.path.abspath('coeffs_reconstruct.nc'),
f'{reconstruct_dir}/{reconstruct_filename}')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config_run_duration = '0000_00:00:01'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<streams>

<stream name="coeffs_reconstruct"
type="output"
filename_template="coeffs_reconstruct.nc"
output_interval="0000_00:00:01"
reference_time="0001-01-01_00:00:00"
clobber_mode="truncate">

<var name="coeffs_reconstruct"/>
</stream>

</streams>
7 changes: 5 additions & 2 deletions compass/ocean/tests/global_ocean/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ForwardStep(Step):
def __init__(self, test_case, mesh, time_integrator, init=None,
name='forward', subdir=None, ntasks=None, min_tasks=None,
openmp_threads=None, get_dt_from_min_res=True,
land_ice_flux_mode='pressure_only'):
land_ice_flux_mode='pressure_only', **kwargs):
"""
Create a new step
Expand Down Expand Up @@ -91,7 +91,7 @@ def __init__(self, test_case, mesh, time_integrator, init=None,
min_tasks = ntasks
super().__init__(test_case=test_case, name=name, subdir=subdir,
ntasks=ntasks, min_tasks=min_tasks,
openmp_threads=openmp_threads)
openmp_threads=openmp_threads, **kwargs)

if (ntasks is None) != (openmp_threads is None):
raise ValueError('You must specify both ntasks and openmp_threads '
Expand Down Expand Up @@ -179,6 +179,7 @@ def setup(self):
else:
# RK4, so use the smaller time step
self.add_namelist_options({'config_dt': btr_dt})
super().setup()

def constrain_resources(self, available_resources):
"""
Expand Down Expand Up @@ -206,11 +207,13 @@ def runtime_setup(self):
else:
# RK4, so use the smaller time step
self.update_namelist_at_runtime({'config_dt': btr_dt})
super().runtime_setup()

def run(self):
"""
Run this step of the testcase
"""
super().run()
update_pio = self.config.getboolean('global_ocean',
'forward_update_pio')
run_model(self, update_pio=update_pio)
Expand Down
2 changes: 2 additions & 0 deletions docs/developers_guide/ocean/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ test cases and steps
files_for_e3sm.remap_sea_surface_salinity_restoring.RemapSeaSurfaceSalinityRestoring.run
files_for_e3sm.remap_iceberg_climatology.RemapIcebergClimatology
files_for_e3sm.remap_iceberg_climatology.RemapIcebergClimatology.run
files_for_e3sm.write_coeffs_reconstruct.WriteCoeffsReconstruct
files_for_e3sm.write_coeffs_reconstruct.WriteCoeffsReconstruct.run

init.Init
init.Init.configure
Expand Down
6 changes: 6 additions & 0 deletions docs/developers_guide/ocean/test_groups/global_ocean.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,12 @@ The test case is made up of 10 steps:
the MPAS mesh. This dataset is used in E3SM for compsets with data iceberg
freshwater fluxes (``DIB``).

:py:class:`compass.ocean.tests.global_ocean.files_for_e3sm.write_coeffs_reconstruct.WriteCoeffsReconstruct`
is used to do a one-time-step forward run to write out coefficients
``coeff_reconstruct`` for reconstructing vector fields at cell centers from
normal values at edges. These can be used in combination with the


files_for_e3sm for an existing mesh
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit ab68ad7

Please sign in to comment.