Skip to content

Commit 52b9328

Browse files
add more comments and docs, fix notation
1 parent 0cd9676 commit 52b9328

File tree

6 files changed

+84
-54
lines changed

6 files changed

+84
-54
lines changed

src/callbacks_step/save_solution_covariant.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ end
4343
u_node = Trixi.get_node_vars(u, equations, dg, i, j, element)
4444
aux_node = get_node_aux_vars(aux_node_vars, equations, dg, i, j, element)
4545
relative_vorticity = calc_vorticity_node(u, equations, dg, cache, i, j, element)
46-
b = bottom_topography(aux_node, equations)
46+
h_s = bottom_topography(aux_node, equations)
4747
primitive_global = contravariant2global(cons2prim(u_node, aux_node, equations),
4848
aux_node, equations)
49-
return SVector(primitive_global..., b, relative_vorticity)
49+
return SVector(primitive_global..., h_s, relative_vorticity)
5050
end
5151

52-
# Calculate relative vorticity ζ = ∂₁v₂ - ∂₂v₁ for equations in covariant form
52+
# Calculate relative vorticity ζ = (∂₁v₂ - ∂₂v₁)/J for equations in covariant form
5353
@inline function calc_vorticity_node(u, equations::AbstractCovariantEquations{2},
5454
dg::DGSEM, cache, i, j, element)
5555
(; derivative_matrix) = dg.basis

src/equations/covariant_advection.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ end
5151
# The conservative variables are the scalar conserved quantity and two contravariant
5252
# velocity components.
5353
function Trixi.varnames(::typeof(cons2cons), ::CovariantLinearAdvectionEquation2D)
54-
return ("scalar", "vcon1", "vcon2")
54+
return ("h", "vcon1", "vcon2")
5555
end
5656

5757
# Convenience function to extract the velocity
@@ -62,9 +62,9 @@ end
6262
# Convert contravariant velocity components to the global coordinate system
6363
@inline function contravariant2global(u, aux_vars,
6464
equations::CovariantLinearAdvectionEquation2D)
65-
vglo1, vglo2, vglo3 = basis_covariant(aux_vars, equations) *
66-
velocity_contravariant(u, equations)
67-
return SVector(u[1], vglo1, vglo2, vglo3)
65+
v1, v2, v3 = basis_covariant(aux_vars, equations) *
66+
velocity_contravariant(u, equations)
67+
return SVector(u[1], v1, v2, v3)
6868
end
6969

7070
# Convert velocity components in the global coordinate system to contravariant components
@@ -77,7 +77,7 @@ end
7777
# Scalar conserved quantity and three global velocity components
7878
function Trixi.varnames(::typeof(contravariant2global),
7979
::CovariantLinearAdvectionEquation2D)
80-
return ("scalar", "vglo1", "vglo2", "vglo3")
80+
return ("h", "v1", "v2", "v3")
8181
end
8282

8383
# We will define the "entropy variables" here to just be the scalar variable in the first

src/equations/covariant_shallow_water.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ components $G_{ab}$ as
5757
Journal of Computational Physics 271:224-243.
5858
[DOI: 10.1016/j.jcp.2013.11.033](https://doi.org/10.1016/j.jcp.2013.11.033)
5959
60-
``` note
61-
For problems with variable bottom topography and entropy-stable schemes,
62-
[SplitCovariantShallowWaterEquations2D](@ref) should be used.
63-
```
60+
!!! note
61+
When solving problems with variable bottom topography as well as when using
62+
entropy-stable schemes, [SplitCovariantShallowWaterEquations2D](@ref) should be used
63+
instead.
6464
"""
6565
struct CovariantShallowWaterEquations2D{GlobalCoordinateSystem, RealT <: Real} <:
6666
AbstractCovariantShallowWaterEquations2D{GlobalCoordinateSystem}
@@ -95,7 +95,7 @@ end
9595
# specifically to transformations from conservative variables.
9696
function Trixi.varnames(::typeof(contravariant2global),
9797
::AbstractCovariantShallowWaterEquations2D)
98-
return ("h", "h_vglo1", "h_vglo2", "h_vglo3")
98+
return ("h", "h_v1", "h_v2", "h_v3")
9999
end
100100

101101
# Convenience functions to extract physical variables from state vector
@@ -112,35 +112,34 @@ end
112112
@inline function Trixi.cons2prim(u, aux_vars,
113113
equations::AbstractCovariantShallowWaterEquations2D)
114114
h, h_vcon1, h_vcon2 = u
115-
b = bottom_topography(aux_vars, equations)
116-
H = h + b
117-
return SVector(H, h_vcon1 / h, h_vcon2 / h)
115+
h_s = bottom_topography(aux_vars, equations)
116+
return SVector(h + h_s, h_vcon1 / h, h_vcon2 / h)
118117
end
119118

120119
@inline function Trixi.prim2cons(u, aux_vars,
121120
equations::AbstractCovariantShallowWaterEquations2D)
122121
H, vcon1, vcon2 = u
123-
b = bottom_topography(aux_vars, equations)
124-
h = H - b
125-
return SVector(h, h * vcon1, h * vcon2)
122+
h_s = bottom_topography(aux_vars, equations)
123+
return SVector(H - h_s, h * vcon1, h * vcon2)
126124
end
127125

126+
# Entropy variables are w = (g(h+hₛ) - (v₁v¹ + v₂v²)/2, v₁, v₂)ᵀ
128127
@inline function Trixi.cons2entropy(u, aux_vars,
129128
equations::AbstractCovariantShallowWaterEquations2D)
130129
h = waterheight(u, equations)
131-
b = bottom_topography(aux_vars, equations)
130+
h_s = bottom_topography(aux_vars, equations)
132131
vcon = velocity_contravariant(u, equations)
133132
vcov = metric_covariant(aux_vars, equations) * vcon
134-
return SVector{3}(equations.gravity * (h + b) - 0.5f0 * dot(vcov, vcon), vcov[1],
135-
vcov[2])
133+
return SVector{3}(equations.gravity * (h + h_s) - 0.5f0 * dot(vcov, vcon),
134+
vcov[1], vcov[2])
136135
end
137136

138137
# Convert contravariant momentum components to the global coordinate system
139138
@inline function contravariant2global(u, aux_vars,
140139
equations::AbstractCovariantShallowWaterEquations2D)
141-
h_vglo1, h_vglo2, h_vglo3 = basis_covariant(aux_vars, equations) *
142-
momentum_contravariant(u, equations)
143-
return SVector(waterheight(u, equations), h_vglo1, h_vglo2, h_vglo3)
140+
h_v1, h_v2, h_v3 = basis_covariant(aux_vars, equations) *
141+
momentum_contravariant(u, equations)
142+
return SVector(waterheight(u, equations), h_v1, h_v2, h_v3)
144143
end
145144

146145
# Convert momentum components in the global coordinate system to contravariant components
@@ -151,15 +150,15 @@ end
151150
return SVector(u[1], h_vcon1, h_vcon2)
152151
end
153152

154-
# Entropy function (total energy per unit volume)
153+
# Entropy function (total energy) given by S = (h(v₁v¹ + v₂v²) + gh² + ghhₛ)/2
155154
@inline function Trixi.entropy(u, aux_vars,
156155
equations::AbstractCovariantShallowWaterEquations2D)
157156
h = waterheight(u, equations)
158-
b = bottom_topography(aux_vars, equations)
157+
h_s = bottom_topography(aux_vars, equations)
159158
vcon = velocity_contravariant(u, equations)
160159
vcov = metric_covariant(aux_vars, equations) * vcon
161160
return 0.5f0 * (h * dot(vcov, vcon) + equations.gravity * h^2) +
162-
equations.gravity * h * b
161+
equations.gravity * h * h_s
163162
end
164163

165164
# Flux as a function of the state vector u, as well as the auxiliary variables aux_vars,

src/equations/covariant_shallow_water_split.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ end
111111
Gcon_ll = metric_contravariant(aux_vars_ll, equations)
112112
Gcov_rr = metric_covariant(aux_vars_rr, equations)
113113
J_ll = area_element(aux_vars_ll, equations)
114-
b_jump = bottom_topography(aux_vars_rr, equations) -
115-
bottom_topography(aux_vars_ll, equations)
114+
h_s_jump = bottom_topography(aux_vars_rr, equations) -
115+
bottom_topography(aux_vars_ll, equations)
116116

117117
# Physical variables
118118
h_ll = waterheight(u_ll, equations)
@@ -122,7 +122,8 @@ end
122122
vcov_rr = Gcov_rr * vcon_rr
123123

124124
geometric_term = 0.5f0 * h_vcon_ll[orientation] * (Gcon_ll * vcov_rr - vcon_rr)
125-
pressure_term = equations.gravity * Gcon_ll[:, orientation] * h_ll * (h_rr + b_jump)
125+
pressure_term = equations.gravity * Gcon_ll[:, orientation] * h_ll *
126+
(h_rr + h_s_jump)
126127

127128
return SVector(zero(eltype(u_ll)), J_ll * (geometric_term[1] + pressure_term[1]),
128129
J_ll * (geometric_term[2] + pressure_term[2]))

src/equations/equations.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ end
172172
nvars_christoffel
173173
end
174174

175-
# Return auxiliary variable names for 2D covariant form
175+
# Return auxiliary variable names for 2D covariant form. Note that e₁, e₂, e₃ are the
176+
# global basis vectors, which may be Cartesian or spherical
176177
@inline function auxvarnames(::AbstractCovariantEquations{2})
177178
return ("basis_covariant[1,1]", # e₁ ⋅ a₁
178179
"basis_covariant[2,1]", # e₂ ⋅ a₁
@@ -193,7 +194,7 @@ end
193194
"metric_contravariant[1,1]", # G¹¹
194195
"metric_contravariant[1,2]", # G¹² = G²¹
195196
"metric_contravariant[2,2]", # G²²
196-
"bottom_topography", # b
197+
"bottom_topography", # hₛ
197198
"christoffel_symbols[1][1,1]", # Γ¹₁₁
198199
"christoffel_symbols[1][1,2]", # Γ¹₁₂ = Γ¹₂₁
199200
"christoffel_symbols[1][2,2]", # Γ¹₂₂
@@ -236,7 +237,7 @@ end
236237
aux_vars[18], aux_vars[19])
237238
end
238239

239-
# Extract the bottom topography b from the auxiliary variables
240+
# Extract the bottom topography hₛ from the auxiliary variables
240241
@inline function bottom_topography(aux_vars, ::AbstractCovariantEquations{2})
241242
return aux_vars[20]
242243
end

src/equations/reference_data.jl

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ This problem is adapted from Case 1 of the test suite described in the following
6565

6666
# Convert primitive variables from Cartesian coordinates to the chosen global
6767
# coordinate system, which depends on the equation type
68-
return cartesian2global(SVector(h, vx, vy, vz, 0.0f0), x, equations)
68+
return cartesian2global(SVector(h, vx, vy, vz, zero(RealT)), x, equations)
6969
end
7070

7171
@doc raw"""
@@ -104,7 +104,8 @@ test suite described in the following paper:
104104

105105
# Convert primitive variables from spherical coordinates to the chosen global
106106
# coordinate system, which depends on the equation type
107-
return spherical2global(SVector(h, vlon, vlat, zero(RealT)), x, equations)
107+
return spherical2global(SVector(h, vlon, vlat, zero(RealT), zero(RealT)), x,
108+
equations)
108109
end
109110

110111
@doc raw"""
@@ -126,12 +127,12 @@ $g = 9.80616 \ \mathrm{m}/\mathrm{s}^2$, $\Omega = 7.292 \times 10^{-5} \ \mathr
126127
and $h_0 = 8000 \ \mathrm{m}$ and defining the functions
127128
```math
128129
\begin{aligned}
129-
A(\theta) &:= \frac{\omega}{2}(2 \Omega+\omega) \cos^2 \theta +
130+
A(\theta) &= \frac{\omega}{2}(2 \Omega+\omega) \cos^2 \theta +
130131
\frac{1}{4} K^2 \cos^{2 R} \theta\Big((R+1) \cos^2\theta +\left(2 R^2-R-2\right) -
131132
\big(2 R^2 / \cos^2 \theta\big) \Big), \\
132-
B(\theta) &:= \frac{2(\Omega+\omega) K}{(R+1)(R+2)} \cos ^R \theta\big((R^2+2 R+2) -
133+
B(\theta) &= \frac{2(\Omega+\omega) K}{(R+1)(R+2)} \cos ^R \theta\big((R^2+2 R+2) -
133134
(R+1)^2 \cos^2 \theta\big), \\
134-
C(\theta) &:= \frac{1}{4} K^2 \cos^{2 R} \theta\big((R+1) \cos^2 \theta-(R+2)\big),
135+
C(\theta) &= \frac{1}{4} K^2 \cos^{2 R} \theta\big((R+1) \cos^2 \theta-(R+2)\big),
135136
\end{aligned}
136137
```
137138
the initial height field is given by
@@ -147,9 +148,8 @@ This problem corresponds to Case 6 of the test suite described in the following
147148
"""
148149
@inline function initial_condition_rossby_haurwitz(x, t, equations)
149150
RealT = eltype(x)
150-
a = sqrt(x[1]^2 + x[2]^2 + x[3]^2)
151-
lon = atan(x[2], x[1])
152-
lat = asin(x[3] / a)
151+
a = sqrt(x[1]^2 + x[2]^2 + x[3]^2) # radius of the sphere
152+
lon, lat = atan(x[2], x[1]), asin(x[3] / a)
153153

154154
h_0 = 8.0f3
155155
omega = 7.848f-6
@@ -176,7 +176,8 @@ This problem corresponds to Case 6 of the test suite described in the following
176176

177177
# Convert primitive variables from spherical coordinates to the chosen global
178178
# coordinate system, which depends on the equation type
179-
return spherical2global(SVector(h, vlon, vlat, zero(RealT)), x, equations)
179+
return spherical2global(SVector(h, vlon, vlat, zero(RealT), zero(RealT)), x,
180+
equations)
180181
end
181182

182183
@doc raw"""
@@ -222,7 +223,8 @@ test suite described in the following paper:
222223

223224
# Convert primitive variables from spherical coordinates to the chosen global
224225
# coordinate system, which depends on the equation type
225-
return spherical2global(SVector(h, vlon, vlat, zero(RealT)), x, equations)
226+
return spherical2global(SVector(h, vlon, vlat, zero(RealT), zero(RealT)), x,
227+
equations)
226228
end
227229

228230
# Bottom topography function to pass as auxiliary_field keyword argument in constructor for
@@ -279,12 +281,12 @@ H(\vec{x},t) =
279281
\vec{\varphi}(\vec{c},t) \cdot \vec{x}/\lVert \vec{x} \rVert \big)^2 +
280282
(\vec{\Omega} \cdot \vec{x})^2 + 2k_1\right),
281283
```
282-
where we take $v_0 = 2\pi a / (12 \ \mathrm{days})$ and
283-
$k_1 = 133681 \ \mathrm{m}^2/\mathrm{s}^2$, and we use $\lVert \cdot \rVert$ to denote the
284-
Euclidean norm. To use this test case with [`SplitCovariantShallowWaterEquations2D`](@ref),
285-
the keyword argument `auxiliary_field = bottom_topography_unsteady_solid_body_rotation`
286-
should be passed into the `SemidiscretizationHyperbolic` constructor. This analytical
287-
solution was derived in the following paper:
284+
where $v_0 = 2\pi a / (12 \ \mathrm{days})$, $k_1 = 133681 \ \mathrm{m}^2/\mathrm{s}^2$,
285+
and $\lVert \cdot \rVert$ denotes the Euclidean norm. To use this test case with
286+
[`SplitCovariantShallowWaterEquations2D`](@ref), the keyword argument
287+
`auxiliary_field = bottom_topography_unsteady_solid_body_rotation` should be passed into
288+
the `SemidiscretizationHyperbolic` constructor. This analytical solution was derived in the
289+
following paper:
288290
- M. Läuter, D. Handorf, and K. Dethloff (2005). Unsteady analytical solutions of the
289291
spherical shallow water equations. Journal of Computational Physics 210:535–553.
290292
[DOI: 10.1016/j.jcp.2005.04.022](https://doi.org/10.1016/j.jcp.2005.04.022)
@@ -320,7 +322,7 @@ solution was derived in the following paper:
320322

321323
# Convert primitive variables from Cartesian coordinates to the chosen global
322324
# coordinate system, which depends on the equation type
323-
return cartesian2global(SVector(H, v[1], v[2], v[3]), x, equations)
325+
return cartesian2global(SVector(H, v[1], v[2], v[3], zero(RealT)), x, equations)
324326
end
325327

326328
# Bottom topography function to pass as auxiliary_field keyword argument in constructor for
@@ -332,8 +334,34 @@ end
332334
@doc raw"""
333335
initial_condition_barotropic_instability(x, t, equations)
334336
335-
Barotrotropic instability initiated by a perturbation applied to a mid-latitude jet. A full
336-
description of this case is provided in the following paper:
337+
Barotrotropic instability initiated by a perturbation applied to a mid-latitude jet. The velocity field is a purely zonal flow, given as a function of the latitude $\theta$ as
338+
```math
339+
v_\lambda(\theta) = \begin{cases}
340+
u_0 \exp(-4 / (\theta_1 - \theta_0)^{-2})\exp((\theta - \theta_0)^{-1}
341+
(\theta - \theta_1)^{-1}), & \quad \theta_0 < \theta < \theta_1, \\
342+
0 & \quad \text{otherwise},
343+
\end{cases}
344+
```
345+
where $u_0 = 80 \ \mathrm{m}/\mathrm{s}$, $\theta_0 = \pi/7$, and
346+
$\theta_1 = \pi/2 - \theta_0$. The background geopotential height field is given by
347+
```math
348+
h_0(\theta) = 10158 \ \mathrm{m} -
349+
\frac{a}{g} \int_{-\pi/2}^\theta v_\lambda(\theta')\big(2\Omega\sin\theta' +
350+
v_\lambda(\theta')\tan\theta' / a \big)\, \mathrm{d}\theta',
351+
```
352+
where $a = 6.37122 \times 10^3\ \mathrm{m}$ is the Earth's radius,
353+
$g = 9.80616 \ \mathrm{m}/\mathrm{s}^2$ is the Earth's gravitational acceleration, and
354+
$\Omega = 7.292 \times 10^{-5}\ \mathrm{s}^{-1}$ is the Earth's rotation rate. The
355+
perturbation is then added to obtain the following geopotential height field:
356+
```math
357+
h(\lambda, \theta) = \begin{cases}
358+
h_0(\theta) + \delta h \cos\theta \exp(-(\lambda/\alpha)^2)
359+
\exp(-((\theta_2 -\theta)/\beta)^2), & \quad -\pi < \lambda < \pi,\\
360+
h_0(\theta), & \quad \text{otherwise},
361+
\end{cases}
362+
```
363+
where $\lambda$ is the longitude coordinate, and we take $\alpha = 1/3$, $\beta = 1/15$,
364+
and $\delta h = 120 \ \mathrm{m}$. This problem was proposed in the following paper:
337365
- J. Galewsky, R. K. Scott, and L. M. Polvani (2004). An initial-value problem for
338366
testing numerical models of the global shallow-water equations. Tellus A 56.5:429–440.
339367
[DOI: 10.3402/tellusa.v56i5.14436](https://doi.org/10.3402/tellusa.v56i5.14436)
@@ -366,7 +394,8 @@ description of this case is provided in the following paper:
366394

367395
# Convert primitive variables from spherical coordinates to the chosen global
368396
# coordinate system, which depends on the equation type
369-
return spherical2global(SVector(h, vlon, vlat, zero(RealT)), x, equations)
397+
return spherical2global(SVector(h, vlon, vlat, zero(RealT), zero(RealT)), x,
398+
equations)
370399
end
371400

372401
@inline function galewsky_velocity(lat, u_0, lat_0, lat_1)

0 commit comments

Comments
 (0)