Skip to content

Commit b1a4b0c

Browse files
authored
Merge pull request #1640 from knutfrode/dev
[run-ex] New config setting 'drift:water_column_stretching' for Ocean…
2 parents 03d8032 + 10b6d57 commit b1a4b0c

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python
2+
"""
3+
Water column stretching
4+
========================
5+
"""
6+
7+
from datetime import datetime, timedelta
8+
import numpy as np
9+
import matplotlib.pyplot as plt
10+
from opendrift.readers import reader_oscillating
11+
from opendrift.models.oceandrift import OceanDrift
12+
13+
14+
#%%
15+
# In OpenDrift, the vertical position of elements ("z") is defined as relative to actual surface,
16+
# and not an absolute reference level (e.g. mean sea surface height).
17+
# Thus if sea surface elevation changes with time (e.g. tides),
18+
# we need to add a "correction / perturbation" to z, otherwise elements at/near seafloor
19+
# will be lifted if surface elevation increases and z (relative to surface) remains unchanged.
20+
# This correction is presently only implemented for OceanDrift, and must be switched on
21+
# with config setting "drift:water:column_stretching"
22+
23+
# To illustrate, we add a reader with oscillating sea surface elevation (tidal)
24+
# with amplitude of 1m and peroid of 6 hours
25+
time = datetime.now()
26+
reader_tidal = reader_oscillating.Reader('sea_surface_height', amplitude=-1,
27+
period=timedelta(hours=6), zero_time=time)
28+
29+
#%%
30+
# First an illustration withouth this correction.
31+
o = OceanDrift(loglevel=20)
32+
o.add_reader(reader_tidal)
33+
o.set_config('drift:water_column_stretching', False)
34+
o.set_config('environment:constant:sea_floor_depth_below_sea_level', 10)
35+
z = np.arange(0, -11, -1) # Seeding one particle every meter from surface to 10m depth
36+
o.seed_elements(lon=0, lat=0, time=time, z=z, number=11)
37+
o.run(duration=timedelta(hours=24), time_step=1800)
38+
o.result.z.plot.line(x='time', add_legend=False)
39+
plt.show()
40+
41+
#%%
42+
# We see that the particles remain at their initial depths (since we have no vertical advection or mixing),
43+
# except for the element starting at seafloor, which is lifted up when sea level rises,
44+
# since the config setting `drift:seafloor_action` is `lift_to_seafloor` by default.
45+
# This lifting is in this case unphysical.
46+
47+
#%%
48+
o = OceanDrift(loglevel=20)
49+
o.add_reader(reader_tidal)
50+
o.set_config('drift:water_column_stretching', True)
51+
o.set_config('environment:constant:sea_floor_depth_below_sea_level', 10)
52+
o.seed_elements(lon=0, lat=0, time=time, z=z, number=11)
53+
o.run(duration=timedelta(hours=24), time_step=1800)
54+
o.result.z.plot.line(x='time', add_legend=False)
55+
plt.show()
56+
57+
# Here we see that element depth (z, relative to surface) is changed so that
58+
# elements at surface and seafloor remain at resp surface (z=0) and
59+
# seafloor (z = sea_floor_depth + sea_surface_elevation)

opendrift/models/oceandrift.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def __init__(self, *args, **kwargs):
121121
'drift:vertical_advection_at_surface': {'type': 'bool', 'default': False, 'description':
122122
'If vertical advection is activated, surface elements (z=0) can only be advected (downwards) if this setting it True.',
123123
'level': CONFIG_LEVEL_ADVANCED},
124+
'drift:water_column_stretching': {'type': 'bool', 'default': False, 'description':
125+
'If sea surface elevation changes, vertical particle position (element property "z" is relative to surface, and not absolute zero-level) is adjusted so that elements at surface and seafloor remains at resp surface and seafloor.',
126+
'level': CONFIG_LEVEL_ADVANCED},
124127
'drift:vertical_mixing': {'type': 'bool', 'default': False, 'level': CONFIG_LEVEL_BASIC,
125128
'description': 'Activate vertical mixing scheme with inner loop'},
126129
'drift:vertical_mixing_at_surface': {'type': 'bool', 'default': False, 'description':
@@ -292,8 +295,12 @@ def prepare_run(self):
292295
def water_column_stretching(self):
293296
"""If sea_water_level changes, adjust z for continuity"""
294297

295-
return # To be implemented
298+
if self.get_config('drift:water_column_stretching') is False:
299+
return
300+
296301
delta_zeta = self.environment.sea_surface_height - self.environment_previous.sea_surface_height
302+
logger.info('Compensating for change in surface elevation')
303+
self.elements.z = self.elements.z + delta_zeta*(self.elements.z/self.environment.sea_floor_depth_below_sea_level)
297304

298305
def vertical_advection(self):
299306
"""Move particles vertically according to vertical ocean current

0 commit comments

Comments
 (0)