Skip to content

Commit

Permalink
Merge pull request #249 from xylar/support-omega-time-coord
Browse files Browse the repository at this point in the history
Support the Omega `time` coordinate
  • Loading branch information
xylar authored Dec 23, 2024
2 parents b501e91 + 89a28f8 commit 265bb55
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
2 changes: 1 addition & 1 deletion e3sm_submodules/Omega
Submodule Omega updated 34 files
+26 −3 components/omega/OmegaBuild.cmake
+9 −3 components/omega/configs/Default.yml
+4 −7 components/omega/doc/devGuide/Halo.md
+13 −13 components/omega/doc/devGuide/QuickStart.md
+12 −4 components/omega/doc/devGuide/TimeMgr.md
+5 −1 components/omega/doc/userGuide/Halo.md
+94 −999 components/omega/src/base/Halo.cpp
+525 −106 components/omega/src/base/Halo.h
+12 −11 components/omega/src/infra/Field.cpp
+9 −53 components/omega/src/infra/Field.h
+57 −56 components/omega/src/infra/IOStream.cpp
+7 −0 components/omega/src/infra/IOStream.h
+54 −0 components/omega/src/infra/OmegaKokkos.h
+43 −0 components/omega/src/infra/TimeMgr.cpp
+10 −1 components/omega/src/infra/TimeMgr.h
+228 −0 components/omega/src/ocn/CustomTendencyTerms.cpp
+81 −0 components/omega/src/ocn/CustomTendencyTerms.h
+1 −0 components/omega/src/ocn/HorzMesh.cpp
+13 −12 components/omega/src/ocn/OceanInit.cpp
+2 −6 components/omega/src/ocn/OceanState.cpp
+45 −1 components/omega/src/ocn/Tendencies.cpp
+1 −6 components/omega/src/ocn/Tracers.cpp
+3 −5 components/omega/src/timeStepping/RungeKutta4Stepper.cpp
+338 −202 components/omega/test/base/HaloTest.cpp
+2 −2 components/omega/test/base/ReductionsTest.cpp
+13 −13 components/omega/test/infra/FieldTest.cpp
+3 −2 components/omega/test/infra/IOStreamTest.cpp
+33 −0 components/omega/test/infra/TimeMgrTest.cpp
+2 −5 components/omega/test/ocn/AuxiliaryVarsTest.cpp
+1 −0 components/omega/test/ocn/HorzMeshTest.cpp
+6 −12 components/omega/test/ocn/OceanTestCommon.h
+4 −3 components/omega/test/ocn/StateTest.cpp
+1 −0 components/omega/test/ocn/TracersTest.cpp
+25 −5 components/omega/test/timeStepping/TimeStepperTest.cpp
2 changes: 1 addition & 1 deletion polaris/mpas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from polaris.mpas.area import area_for_field
from polaris.mpas.time import time_index_from_xtime
from polaris.mpas.time import time_index_from_xtime, time_since_start
25 changes: 23 additions & 2 deletions polaris/mpas/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ def time_index_from_xtime(xtime, dt_target, start_xtime=None):
time_index : int
Index in xtime that is closest to dt_target
"""
dt = time_since_start(xtime, start_xtime)
time_index = np.argmin(np.abs(np.subtract(dt, dt_target)))
return time_index


def time_since_start(xtime, start_xtime=None):
"""
Determine the time elapsed since the start of the simulation
Parameters
----------
xtime : numpy.ndarray of numpy.char
Times in the dataset
start_xtime : str, optional
The start time, the first entry in ``xtime`` by default
Returns
-------
dt : numpy.ndarray
The elapsed time in seconds corresponding to each entry in xtime
"""
if start_xtime is None:
start_xtime = xtime[0].decode()

Expand All @@ -32,5 +54,4 @@ def time_index_from_xtime(xtime, dt_target, start_xtime=None):
t = datetime.datetime.strptime(xt.decode(),
'%Y-%m-%d_%H:%M:%S')
dt[idx] = (t - t0).total_seconds()
time_index = np.argmin(np.abs(np.subtract(dt, dt_target)))
return time_index
return dt
17 changes: 13 additions & 4 deletions polaris/ocean/convergence/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import pandas as pd

from polaris.mpas import area_for_field, time_index_from_xtime
from polaris.mpas import area_for_field, time_since_start
from polaris.ocean.convergence import (
get_resolution_for_task,
get_timestep_for_task,
Expand Down Expand Up @@ -395,11 +395,20 @@ def get_output_field(self, refinement_factor, field_name, time, zidx=None):
field_mpas : xarray.DataArray
model output field
"""
ds_out = self.open_model_dataset(f'output_r{refinement_factor:02g}.nc')
config = self.config
ds_out = self.open_model_dataset(f'output_r{refinement_factor:02g}.nc',
decode_times=False)

tidx = time_index_from_xtime(ds_out.xtime.values, time)
ds_out = ds_out.isel(Time=tidx)
model = config.get('ocean', 'model')
if model == 'mpas-o':
dt = time_since_start(ds_out.xtime.values)
else:
# time is seconds since the start of the simulation in Omega
dt = ds_out.Time.values

tidx = np.argmin(np.abs(dt - time))

ds_out = ds_out.isel(Time=tidx)
field_mpas = ds_out[field_name]
if zidx is not None:
field_mpas = field_mpas.isel(nVertLevels=zidx)
Expand Down
28 changes: 20 additions & 8 deletions polaris/ocean/tasks/manufactured_solution/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def run(self):
section = config['manufactured_solution']
eta0 = section.getfloat('ssh_amplitude')

model = config.get('ocean', 'model')

use_mplstyle()
fig, axes = plt.subplots(nrows=nres, ncols=3, figsize=(12, 2 * nres))
rmse = []
Expand All @@ -146,16 +148,26 @@ def run(self):
ds_init = self.open_model_dataset(
f'init_r{refinement_factor:02g}.nc')
ds = self.open_model_dataset(
f'output_r{refinement_factor:02g}.nc')
f'output_r{refinement_factor:02g}.nc', decode_times=False)
exact = ExactSolution(config, ds_init)

t0 = datetime.datetime.strptime(ds.xtime.values[0].decode(),
'%Y-%m-%d_%H:%M:%S')
tf = datetime.datetime.strptime(ds.xtime.values[-1].decode(),
'%Y-%m-%d_%H:%M:%S')
t = (tf - t0).total_seconds()
ssh_model = ds.ssh.values[-1, :]
rmse.append(np.sqrt(np.mean((ssh_model - exact.ssh(t).values)**2)))
if model == 'mpas-o':
t0 = datetime.datetime.strptime(ds.xtime.values[0].decode(),
'%Y-%m-%d_%H:%M:%S')
tf = datetime.datetime.strptime(ds.xtime.values[-1].decode(),
'%Y-%m-%d_%H:%M:%S')
t = (tf - t0).total_seconds()

else:
# time is seconds since the start of the simulation in Omega
t = ds.Time[-1].values

ssh_model = ds.ssh.isel(Time=-1)
if 'nVertLevels' in ssh_model.dims:
# Omega v0 uses stacked shallow water where ssh has nVertLevels
ssh_model = ssh_model.isel(nVertLevels=0)
rmse.append(np.sqrt(np.mean(
(ssh_model.values - exact.ssh(t).values)**2)))

# Comparison plots
ds['ssh_exact'] = exact.ssh(t)
Expand Down

0 comments on commit 265bb55

Please sign in to comment.