Skip to content

Commit 1edca5b

Browse files
committed
add script for notebook
1 parent 13816af commit 1edca5b

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

docs/assets/swm_equations.jl

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# # ShallowWaters.jl - The equations
2+
#
3+
# The shallow water equations for the prognostic variables velocity $\mathbf{u} = (u,v)$ and sea surface elevation $\eta$ over the 2-dimensional domain $\Omega$ in $x,y$ are
4+
#
5+
# ```math
6+
# \begin{align}
7+
# \partial_t u &+ u\partial_xu + v\partial_yu - fv = -g\partial_x\eta + D_x(u,v,\eta) + F_x, \\
8+
# \partial_t v &+ u\partial_xv + v\partial_yv + fu = -g\partial_y\eta + D_y(u,v,\eta) + F_y, \\
9+
# \partial_t \eta &+ \partial_x(uh) + \partial_y(vh) = 0.
10+
# \end{align}
11+
# ```
12+
# where the first two are the momentum equations for $u,v$ and the latter is the continuity equation. The layer thickness is $h = \eta + H$ with $H=H(x,y)$ being the bottom topography. The gravitational acceleration is $g$, the coriolis parameter $f = f(y)$ depends only (i.e. latitude) only and the beta-plane approximation is used. $(D_x,D_y) = \mathbf{D}$ are the dissipative terms
13+
#
14+
# ```math
15+
# \mathbf{D} = -\frac{c_D}{h}\vert \mathbf{u} \vert \mathbf{u} - u \nabla^4\mathbf{u}
16+
# ```
17+
18+
# which are a sum of a quadratic bottom drag with dimensionless coefficient $c_D$ and a biharmonic diffusion with viscosity coefficient $u$. $\mathbf{F} = (F_x,F_y)$ is the wind forcing which can depend on time and space, i.e. $F_x = F_x(x,y,t)$ and $F_y = F_y(x,y,t)$.
19+
20+
# ## The vector invariant formulation
21+
22+
# The Bernoulli potential $p$ is introduced as
23+
24+
# ```math
25+
# p = \frac{1}{2}(u^2 + v^2) + gh
26+
# ```
27+
28+
# The relative vorticity $\zeta = \partial_xv + \partial_yu$ lets us define the potential vorticity $q$ as
29+
30+
# ```math
31+
# q = \frac{f + \zeta}{h}
32+
# ```
33+
34+
# such that we can rewrite the shallow water equations as
35+
36+
# ```math
37+
# \begin{align}
38+
# \partial_t u &= qhv -g\partial_xp + D_x(u,v,\eta) + F_x, \\
39+
# \partial_t v &= -qhu -g\partial_yp + D_y(u,v,\eta) + F_y, \\
40+
# \partial_t \eta &= -\partial_x(uh) -\partial_y(vh).
41+
# \end{align}
42+
# ```
43+
44+
# ## Runge-Kutta time discretisation
45+
46+
# Let
47+
# ```math
48+
# R(u,v,\eta) = \begin{pmatrix}
49+
# qhv-g\partial_xp+F_x
50+
# -qhu-g\partial_yp+F_y
51+
# -\partial_x(uh) -\partial_y(vh)
52+
# \end{pmatrix}
53+
# ```
54+
#
55+
# be the non-dissipative right-hand side, i.e. excluding the dissipative terms $\mathbf{D}$. Then we dicretise the time derivative with 4th order Runge-Kutta with $\mathbf{k}_n = (u_n,v_n,\eta_n)$ by
56+
#
57+
# ```math
58+
# \begin{align}
59+
# \mathbf{d}_1 &= R(\mathbf{k}_n) , \\
60+
# \mathbf{d}_2 &= R(\mathbf{k}_n + \frac{1}{2}\Delta t \mathbf{d}_1), \\
61+
# \mathbf{d}_3 &= R(\mathbf{k}_n + \frac{1}{2}\Delta t \mathbf{d}_2), \\
62+
# \mathbf{d}_4 &= R(\mathbf{k}_n + \Delta t \mathbf{d}_3), \\
63+
# u_{n+1}^*,v_{n+1}^*,\eta_{n+1} = \mathbf{k}_{n+1} &= \mathbf{k}_n + \frac{1}{6}\Delta t(\mathbf{d}_1 + 2\mathbf{d}_2 + 2\mathbf{d}_3 + \mathbf{d}_1),
64+
# \end{align}
65+
# ```
66+
67+
# and the dissipative terms are then added semi-implictly.
68+
69+
# ```math
70+
# \begin{align}
71+
# u_{n+1} = u_{n+1}^* + \Delta t D_x(u_{n+1}^*,v_{n+1}^*,\eta_{n+1}) , \\
72+
# v_{n+1} = v_{n+1}^* + \Delta t D_y(u_{n+1}^*,v_{n+1}^*,\eta_{n+1}).
73+
# \end{align}
74+
# ```
75+
76+
77+
# Consequently, the dissipative terms only have to be evaluated once per time step, which reduces the computational cost of the right=hand side drastically. This is motivated as the Courant number $C = \sqrt{gH_0}$ is restricted by gravity waves, which are caused by $\partial_t\mathbf{u} = -g\nabla\eta$ and $\partial_t\eta = -H_0\nabla \cdot \mathbf{u}$. The other terms have longer time scales, and it is therefore sufficient to solve those with larger time steps. With this scheme, the shallow water model runs stable at $C=1$."
78+
79+
# ## Strong stability preserving Runge-Kutta with semi-implicit continuity equation
80+
81+
# We split the right-hand side into the momentum equations and the continuity equation
82+
83+
# ```math
84+
# R_m(u,v,\eta) = \begin{pmatrix}
85+
# qhv-g\partial_xp+F_x
86+
# -qhu-g\partial_yp+F_y
87+
# \end{pmatrix}, \quad R_\eta(u,v,\eta) = -\partial_x(uh) -\partial_y(vh)
88+
# ```
89+
90+
# The 4-stage strong stability preserving Runge-Kutta scheme, with a semi-implicit treatment of the continuity equation then reads as
91+
92+
# ```math
93+
# \begin{align}
94+
# \mathbf{u}_1 &= \mathbf{u}_n + \frac{1}{2} \Delta t R_m(u_n,v_n,\eta_n), \quad \text{then}
95+
# \quad \eta_1 = \eta_n + \frac{1}{2} \Delta t R_\eta(u_1,v_1,\eta_n), \\
96+
# \mathbf{u}_2 &= \mathbf{u}_1 + \frac{1}{2} \Delta t R_m(u_1,v_1,\eta_1), \quad \text{then}
97+
# \quad \eta_2 = \eta_1 + \frac{1}{2} \Delta t R_\eta(u_2,v_2,\eta_1) , \\
98+
# \mathbf{u}_3 &= \frac{2}{3}\mathbf{u}_n + \frac{1}{3}\mathbf{u}_2 + \frac{1}{6} \Delta t R_m(u_2,v_2,\eta_2), \quad \text{then}
99+
# \quad \eta_3 = \frac{2}{3}\eta_n + \frac{1}{3}\eta_2 + \frac{1}{6} \Delta t R_\eta(u_3,v_3,\eta_2), \\
100+
# \mathbf{u}_{n+1} &= \mathbf{u}_3 + \frac{1}{2} \Delta t R_m(u_3,v_3,\eta_3), \quad \text{then}
101+
# \quad \eta_{n+1} = \eta_3 + \frac{1}{2} \Delta t R_\eta(u_{n+1},v_{n+1},\eta_3).
102+
# \end{align}
103+
# ```
104+
105+
# ## Splitting the continuity equation
106+
107+
# From
108+
# ```math
109+
# \partial_t = -\partial_x(uh) - \partial_y(vh)
110+
# ```

0 commit comments

Comments
 (0)