<jupyter_start><jupyter_text>OCEA272 Problem Set 6<jupyter_code># imports
import numpy as np
from importlib import reload

from scipy import optimize

import unyt

from oceanpy import constants
from oceanpy.forces import coriolis

from os_classes.ocea257 import chapter1, chapter2
from os_classes import plotting as os_plotting

from bokeh import plotting
from bokeh import models
from bokeh import layouts

from IPython.display import Image
from IPython.core.display import HTML<jupyter_output><empty_output><jupyter_text>PS6-1 (C-R 11-4 and 11-5)  Diamond Head  11-5  Wind blowing at 10 m/s encounters Diamond Head, leading to vertical displacements $\xi$.<jupyter_code># Setup
U = 10 * unyt.m / unyt.s  # Flow speed
hb = 232 * unyt.m  # Height of the volcano
L = 20 * unyt.km   # Width of the volcano
N = 0.02 / unyt.s<jupyter_output><empty_output><jupyter_text>In lecture, we considered a very similar problem, deriving: $\xi = - \frac{F_r^2 h_b}{1-F_r^2}$ with $F_r$ the Froude number $F_r \equiv \frac{U}{NH}$.  Consider first: $\frac{U}{N h_b}$<jupyter_code>U / (N * hb)<jupyter_output><empty_output><jupyter_text>If the characteristic height of the flow $H$ is much larger than the volcano $H \gg h_b$, then we will have $F_r \ll 1$.  This is, of course, a requirement for stratification. And our equation for the vertical displacements reduces to: $\xi \approx -F_r^2 h_b$ i.e. the vertical displacements are much less than the height of the volcano.  Is the Coriolis (i.e. rotation) important? Let us calculate the Rossby number: $R_0 = \frac{U}{\Omega L}$  Hawaii is at $\approx 20^\circ$N<jupyter_code>Omega = coriolis.coriolis_parameter(20*unyt.deg)
Omega.to('1/s')
R_0 = U / Omega / L
R_0<jupyter_output><empty_output><jupyter_text>With $R_0 \gg 1$, rotational effects are minimal.  11-5  Now we increase $h_b$ to 1000m and $L = 500$km.<jupyter_code>hb_2 = 1000 * unyt.m
L_2 = 500*unyt.km<jupyter_output><empty_output><jupyter_text>Let us calculate our dimensionaless quantities:<jupyter_code>R_0_2 = U / Omega / L_2
R_0_2<jupyter_output><empty_output><jupyter_text>We see that rotation is now important.  And for this much larger $h_b$, it is possible that $H \sim h_b$ and we estimate the Froude number:<jupyter_code>F_r_2 = U / N / hb_2
F_r_2<jupyter_output><empty_output><jupyter_text>We may compare $F_r^2$ to $R_0$:<jupyter_code>F_r_2**2 / R_0_2<jupyter_output><empty_output><jupyter_text>We appear to be in the regime where both stratification and rotation are important. ----  PS6-2 (C-R 13-2)  Internal waves  The lunar tide $M2$ with period $P=12.42$hrs drives internal waves along Norway's coast. This occurs in a stratified fluid with frequency $N = 2 \times 10^{-3} \, \rm s^{-1}$<jupyter_code># Setup
P = 12.42 * unyt.hour
N = 2e-3 / unyt.s<jupyter_output><empty_output><jupyter_text>Let's consider the oscillatory period $P_N = \frac{2\pi}{N}$<jupyter_code>P_N = 2 * np.pi / N
P_N.to('hour')<jupyter_output><empty_output><jupyter_text>This is much shorter than the tidal period.  As such, we expect to be in the Radiating Wave regime.  For the tidal oscillation, it is reasonable to take the frequency of our internal waves to be: $\omega = \frac{2 \pi}{P}$<jupyter_code>omega = 2*np.pi/P
omega.to('1/s')<jupyter_output><empty_output><jupyter_text>We have derived for internal waves the following relation: $\omega = N \cos\theta$ giving $\cos\theta = \frac{\omega}{N}$<jupyter_code># Numerically
costheta = omega / N
costheta
theta = np.arccos(costheta)
theta # radians
theta_deg = theta * 180. *unyt.deg / np.pi
theta_deg<jupyter_output><empty_output><jupyter_text>And negative solutions are also acceptible, i.e. the waves can travel up and down.  We have: $k_x = k \cos\theta$, $k_z = k \sin\theta$  Now, the energy follows the group velocity $c_g$  In lecture and the text, we derived for a wind moving over a sinusoidal surface: $c_{gx} = U \cos^2 \theta$ $c_{gz} = U \sin\theta \cos\theta$ Here we take $U$ as a characteristic velocity of the tides (not given)<jupyter_code># Numerically
cgx = np.cos(theta)**2
cgz = np.sin(theta)*np.cos(theta)
cgx, cgz<jupyter_output><empty_output><jupyter_text>And the angle of propogation relative to the horizontal is provided by the tangent: $\beta = \tan^{-1} \frac{c_{gz}}{c_{gx}}$<jupyter_code>beta = np.arctan(cgx/cgz) * unyt.rad
beta.to('deg')<jupyter_output><empty_output><jupyter_text>So the energy travels primarily horizontally, but has a small vertical component ----  PS6-3 (C-R 13-4)  Lee waves  We have a wind blowing over a sinusoidal topography with quantities:<jupyter_code>U = 10 * unyt.m/unyt.s # wind speed
N = 0.03 / unyt.s      # Stratification frequency
wave = 25 * unyt.km    # Topography wavelength
H = 500 * unyt.m / 2   # Topography amplitude<jupyter_output><empty_output><jupyter_text>Define $k_x = 2 \pi / \lambda$<jupyter_code>k_x = 2 * np.pi / wave
k_x
k_x * U, N<jupyter_output><empty_output><jupyter_text>We see that $k_x U < N$ and we are in the long wavelength regime. We have solutions of the form: $k_z = \pm \sqrt{N^2/U^2 - k_x^2}$ and may ignore the downward solution.<jupyter_code>k_z = np.sqrt(N**2/U**2 - k_x**2)
k_z<jupyter_output><empty_output><jupyter_text>And we derive a vertical wavelength, $\lambda_z = 2\pi/k_z$<jupyter_code>wave_z = 2*np.pi/k_z
wave_z.to('km')<jupyter_output><empty_output><jupyter_text>We have $\cos\theta = k_x U / N$ which gives:<jupyter_code>theta = np.arccos(k_x*U/N) * unyt.rad
theta.to('deg')<jupyter_output><empty_output><jupyter_text>Therefore our Lee waves are nearly vertical!  From lecture (and the text), the horizontal velocity for Lee waves is: $u = U + k_x U H \sin(k_x x + k_z z - \omega t)$ or at the bottom ($z=0$): $u = U + k_x U H \sin(k_x x - \omega t)$ This is maximal when $\sin = 1$<jupyter_code>u = U + k_x * U * H
u.to('m/s')<jupyter_output><empty_output><jupyter_text>This occurs when $k_x x - \omega t = \pi/2$  Last, our topology is: $z = H \cos(k_x x - \omega t)$ And we have $z=0$ at this maximal velocity, i.e. neither a peak nor trough but the point of maximal slope. ----  PS6-4 (C-R 15-1)  Thermal wind  Consider a region with a thermal gradient $dT/dy = -1^\circ$C/35km. Assume $\phi = 40^\circ$N and $T=290$K.  Our thermal wind equations (derived in lecture) are: $\frac{\partial v}{\partial z} = \frac{g \alpha}{f} \frac{\partial T}{\partial x}$ $\frac{\partial u}{\partial z} = -\frac{g \alpha}{f} \frac{\partial T}{\partial y}$ with $\alpha = 1/T$<jupyter_code># Setup
T = 290 * unyt.K
g = 9.8 * unyt.m / unyt.s**2
dT_dy = -1 * unyt.K / (35*unyt.km)
# Coriolis
phi = 40*unyt.deg
f = coriolis.coriolis_parameter(phi)
f.to('1/s')<jupyter_output><empty_output><jupyter_text>Derive $\partial u/\partial z$<jupyter_code>du_dz = -g * (1/T) /  f * dT_dy
du_dz<jupyter_output><empty_output><jupyter_text>We now calculate the change in velocity $\Delta u$ at $z = 2$km:<jupyter_code>Delta_u = du_dz * 2*unyt.km
Delta_u.to('m/s')<jupyter_output><empty_output><jupyter_text>If we have $u=0$ at $z=0$, then we finish with a wind speed of $u=20$m/s at $z=2$km. We have a positive sign, so the direction is East. ----  PS6-5 (C-R 15-4)  Straight of Gibraltar ----  PS6-5 (C-R 15-4)  Gibraltar  In the narrowest point of the Strait of Gibraltar (Tarifa Narrows), there is a stratified, two-layer fluid with inflowing Atlantic waters on top and outflowing salty Meditteranean waters below. The density difference is $\Delta\rho/\rho = 0.002$, the straight is 11km wide and 650m deep.  We are told that the two layers form an interface with depth 175m at Spain (North) and 225m in Africa (South). And we are told the volumetric transport $V$ is equal between the 2 layers. This latter condition implies: $V_1 = u_1 \rho_1 H_1 = -V_2 = -u_2 \rho_2 H_2$ With that interface,  $ = 200$m and $ = 450$m. Therefore $u_1/u_2 \approx -9/4$, i.e. we know the relative speed.  We may introduce the thermal wind equations to establish another equation for the relative speeds. $\frac{\partial u}{\partial z} = \frac{g}{\rho_0 f} \frac{\partial \rho}{\partial y}$  We may massage this to read: $u_1 = u_2 + \frac{g}{\rho_0 f} \frac{\Delta z}{\Delta y} \Delta\rho$<jupyter_code># Some numerics
L = 11 * unyt.km
Dz_Dy = - 50*unyt.m / L
Dp_p = -0.002
g = 9.8 * unyt.m/unyt.s**2
f = 8.5e-5 / unyt.s<jupyter_output><empty_output><jupyter_text>Substitute $u_2 = -u_1 (4/9)$ $u_1 (1+4/9) = \frac{g}{f} \frac{\Delta z}{\Delta y} \frac{\Delta\rho}{\rho_0}$<jupyter_code>u_1 = (g/f) * (Dz_Dy) * Dp_p / (1+4/9.)
u_1
u_2 = -4*u_1/9
u_2<jupyter_output><empty_output><jupyter_text>Volumetric transport $V_1 = u_1  L  H_1$<jupyter_code>H_1 = 200 * unyt.m
V_1 = u_1 * L * H_1
V_1.to('km**3/s')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13243274448677983, 'fraction_numerical': 0.031058769195243044, 'mean_word_length': 4.471888818698673, 'pattern_counts': {'":': 0, '<': 106, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '26', 'dir': 'jupyter-structured-clean-dedup', 'id': '397044', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 3524, 'n_tokens_neox': 3312, 'n_words': 1009, 'path': 'OCEA-272/hw/OCEA272_PS6.ipynb', 'repo_name': 'profxj/os_classes', 'size': '8661'}