Skip to content

Commit 49b6491

Browse files
committed
format
1 parent 5f07f77 commit 49b6491

File tree

4 files changed

+291
-282
lines changed

4 files changed

+291
-282
lines changed

examples/elixir_euler_density_current.jl

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,51 @@ using Trixi
22
using OrdinaryDiffEq
33

44
function initial_condition_density_current(x, t,
5-
equations::CompressibleEulerEquations2D)
6-
g = 9.81
7-
c_p = 1004.0
8-
c_v = 717.0
9-
# center of perturbation
10-
center_x = -2000.0
11-
center_z = 3000.0
12-
# radius of perturbation
13-
radius = 1.0
14-
x_r = 4000.0
15-
z_r = 2000.0
16-
17-
# distance of current x to center of perturbation
18-
r = sqrt((x[1] - center_x)^2 / x_r^2 + (x[2] - center_z)^2 / z_r^2)
19-
20-
# perturbation in potential temperature
21-
potential_temperature_ref = 300.0
22-
potential_temperature_perturbation = 0.0
23-
if r <= radius
24-
potential_temperature_perturbation = -15 / 2 * (1 + cospi(r))
25-
end
26-
potential_temperature = potential_temperature_ref + potential_temperature_perturbation
27-
28-
# Exner pressure, solves hydrostatic equation for x[2]
29-
exner = 1 - g / (c_p * potential_temperature_ref) * x[2]
30-
31-
# pressure
32-
p_0 = 100_000.0 # reference pressure
33-
R = c_p - c_v # gas constant (dry air)
34-
p = p_0 * exner^(c_p / R)
35-
T = potential_temperature * exner
36-
37-
# density
38-
rho = p / (R * T)
39-
v1 = 20.0
40-
v2 = 0.0
41-
42-
43-
return prim2cons(SVector(rho, v1, v2, p), equations)
5+
equations::CompressibleEulerEquations2D)
6+
g = 9.81
7+
c_p = 1004.0
8+
c_v = 717.0
9+
# center of perturbation
10+
center_x = -2000.0
11+
center_z = 3000.0
12+
# radius of perturbation
13+
radius = 1.0
14+
x_r = 4000.0
15+
z_r = 2000.0
16+
17+
# distance of current x to center of perturbation
18+
r = sqrt((x[1] - center_x)^2 / x_r^2 + (x[2] - center_z)^2 / z_r^2)
19+
20+
# perturbation in potential temperature
21+
potential_temperature_ref = 300.0
22+
potential_temperature_perturbation = 0.0
23+
if r <= radius
24+
potential_temperature_perturbation = -15 / 2 * (1 + cospi(r))
25+
end
26+
potential_temperature = potential_temperature_ref + potential_temperature_perturbation
27+
28+
# Exner pressure, solves hydrostatic equation for x[2]
29+
exner = 1 - g / (c_p * potential_temperature_ref) * x[2]
30+
31+
# pressure
32+
p_0 = 100_000.0 # reference pressure
33+
R = c_p - c_v # gas constant (dry air)
34+
p = p_0 * exner^(c_p / R)
35+
T = potential_temperature * exner
36+
37+
# density
38+
rho = p / (R * T)
39+
v1 = 20.0
40+
v2 = 0.0
41+
42+
return prim2cons(SVector(rho, v1, v2, p), equations)
4443
end
4544

4645
@inline function source_terms_gravity(u, x, t,
47-
equations::CompressibleEulerEquations2D)
48-
rho, _, rho_v2, _ = u
49-
return SVector(zero(eltype(u)), zero(eltype(u)), -9.81 * rho,
50-
-9.81 * rho_v2)
46+
equations::CompressibleEulerEquations2D)
47+
rho, _, rho_v2, _ = u
48+
return SVector(zero(eltype(u)), zero(eltype(u)), -9.81 * rho,
49+
-9.81 * rho_v2)
5150
end
5251

5352
equations = CompressibleEulerEquations2D(1.4)
@@ -59,7 +58,7 @@ surface_flux = FluxLMARS(340.0)
5958
volume_flux = flux_kennedy_gruber
6059

6160
solver = DGSEM(polydeg = polydeg, surface_flux = surface_flux,
62-
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
61+
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
6362

6463
## Agnesi Profile
6564
L = 25_600 # Length of the box domain
@@ -75,15 +74,15 @@ f4(s) = SVector((s + 1 - 1) * L / 2, H)
7574

7675
trees_per_dimension = (32, 32)
7776
mesh = P4estMesh(trees_per_dimension, polydeg = 3,
78-
faces = (f1, f2, f3, f4),
79-
initial_refinement_level = 1, periodicity = (true, false))
77+
faces = (f1, f2, f3, f4),
78+
initial_refinement_level = 1, periodicity = (true, false))
8079

81-
boundary_conditions = Dict(
82-
:y_neg => boundary_condition_slip_wall,
83-
:y_pos => boundary_condition_slip_wall)
80+
boundary_conditions = Dict(:y_neg => boundary_condition_slip_wall,
81+
:y_pos => boundary_condition_slip_wall)
8482

85-
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_density_current, solver, source_terms = source_terms_gravity,
86-
boundary_conditions = boundary_conditions)
83+
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_density_current,
84+
solver, source_terms = source_terms_gravity,
85+
boundary_conditions = boundary_conditions)
8786

8887
tspan = (0.0, 900.0)
8988
ode = semidiscretize(semi, tspan)
@@ -96,11 +95,11 @@ analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
9695
alive_callback = AliveCallback(analysis_interval = analysis_interval)
9796

9897
callbacks = CallbackSet(summary_callback,
99-
analysis_callback,
100-
alive_callback, visualization_callback)
98+
analysis_callback,
99+
alive_callback, visualization_callback)
101100

102101
sol = solve(ode,
103-
SSPRK43(thread = OrdinaryDiffEq.True()),
104-
maxiters = 1.0e7,
105-
dt = 1e-1,
106-
save_everystep = false, callback = callbacks)
102+
SSPRK43(thread = OrdinaryDiffEq.True()),
103+
maxiters = 1.0e7,
104+
dt = 1e-1,
105+
save_everystep = false, callback = callbacks)

examples/elixir_euler_linear_hydrostatic.jl

Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,97 +2,99 @@ using Trixi
22
using OrdinaryDiffEq
33

44
struct HydrostaticSetup
5-
# Physical constants
6-
g::Float64 # gravity of earth
7-
c_p::Float64 # heat capacity for constant pressure (dry air)
8-
c_v::Float64 # heat capacity for constant volume (dry air)
9-
gamma::Float64 # heat capacity ratio (dry air)
10-
p_0::Float64 # atmospheric pressure
11-
T_0::Float64 #
12-
u0::Float64 #
13-
Nf::Float64 #
14-
z_B::Float64 #
15-
z_T::Float64 #
16-
function HydrostaticSetup(; g = 9.81, c_p = 1004.0, c_v = 717.0, gamma = c_p / c_v, p_0 = 100_000.0, T_0 = 250.0, u0 = 20.0, z_B = 15000.0, z_T = 30000.0)
17-
Nf = g / sqrt(c_p * T_0)
18-
new(g, c_p, c_v, gamma, p_0, T_0, u0, Nf, z_B, z_T)
19-
end
5+
# Physical constants
6+
g::Float64 # gravity of earth
7+
c_p::Float64 # heat capacity for constant pressure (dry air)
8+
c_v::Float64 # heat capacity for constant volume (dry air)
9+
gamma::Float64 # heat capacity ratio (dry air)
10+
p_0::Float64 # atmospheric pressure
11+
T_0::Float64 #
12+
u0::Float64 #
13+
Nf::Float64 #
14+
z_B::Float64 #
15+
z_T::Float64 #
16+
function HydrostaticSetup(; g = 9.81, c_p = 1004.0, c_v = 717.0, gamma = c_p / c_v,
17+
p_0 = 100_000.0, T_0 = 250.0, u0 = 20.0, z_B = 15000.0,
18+
z_T = 30000.0)
19+
Nf = g / sqrt(c_p * T_0)
20+
new(g, c_p, c_v, gamma, p_0, T_0, u0, Nf, z_B, z_T)
21+
end
2022
end
2123

2224
function (setup::HydrostaticSetup)(u, x, t, equations::CompressibleEulerEquations2D)
23-
@unpack g, c_p, c_v, gamma, p_0, T_0, z_B, z_T, Nf, u0 = setup
25+
@unpack g, c_p, c_v, gamma, p_0, T_0, z_B, z_T, Nf, u0 = setup
2426

25-
rho, rho_v1, rho_v2, rho_e = u
27+
rho, rho_v1, rho_v2, rho_e = u
2628

27-
R = c_p - c_v
29+
R = c_p - c_v
2830

29-
v1 = rho_v1 / rho
30-
v2 = rho_v2 / rho
31-
p = (equations.gamma - 1) * (rho_e - 0.5 * (rho_v1 * v1 + rho_v2 * v2))
32-
rho_theta = (p / p_0)^(c_v / c_p) * p_0 / R
33-
theta = rho_theta / rho
31+
v1 = rho_v1 / rho
32+
v2 = rho_v2 / rho
33+
p = (equations.gamma - 1) * (rho_e - 0.5 * (rho_v1 * v1 + rho_v2 * v2))
34+
rho_theta = (p / p_0)^(c_v / c_p) * p_0 / R
35+
theta = rho_theta / rho
3436

35-
alfa = 0.1
37+
alfa = 0.1
3638

37-
xr_B = 80000.0
38-
xr_T = 120000.0
39+
xr_B = 80000.0
40+
xr_T = 120000.0
3941

40-
if x[2] <= z_B
41-
S_v = 0.0
42-
else
43-
S_v = -alfa * sinpi(0.5 * (x[2] - z_B) / (z_T - z_B))^2
44-
end
45-
if x[1] < xr_B
46-
S_h1 = 0.0
47-
else
48-
S_h1 = -alfa * sinpi(0.5 * (x[1] - xr_B) / (xr_T - xr_B))^2
49-
end
42+
if x[2] <= z_B
43+
S_v = 0.0
44+
else
45+
S_v = -alfa * sinpi(0.5 * (x[2] - z_B) / (z_T - z_B))^2
46+
end
47+
if x[1] < xr_B
48+
S_h1 = 0.0
49+
else
50+
S_h1 = -alfa * sinpi(0.5 * (x[1] - xr_B) / (xr_T - xr_B))^2
51+
end
5052

51-
if x[1] > -xr_B
52-
S_h2 = 0.0
53-
else
54-
S_h2 = -alfa * sinpi(0.5 * (x[1] + xr_B) / (-xr_T + xr_B))^2
55-
end
53+
if x[1] > -xr_B
54+
S_h2 = 0.0
55+
else
56+
S_h2 = -alfa * sinpi(0.5 * (x[1] + xr_B) / (-xr_T + xr_B))^2
57+
end
5658

57-
exner = exp(-Nf^2 / g * x[2])
59+
exner = exp(-Nf^2 / g * x[2])
5860

59-
theta_0 = T_0 / exner
61+
theta_0 = T_0 / exner
6062

61-
K = p_0 * (R / p_0)^gamma
62-
du2 = rho * (v1 - u0) * (S_v + S_h1 + S_h2)
63-
du3 = rho_v2 * (S_v + S_h1 + S_h2)
64-
du4 = rho * (theta - theta_0) * (S_v + S_h1 + S_h2) * K * gamma / (gamma - 1.0) * (rho_theta)^(gamma - 1.0) + du2 * v1 + du3 * v2
65-
66-
return SVector(zero(eltype(u)), du2, du3 - g * rho, du4 - g * rho_v2)
63+
K = p_0 * (R / p_0)^gamma
64+
du2 = rho * (v1 - u0) * (S_v + S_h1 + S_h2)
65+
du3 = rho_v2 * (S_v + S_h1 + S_h2)
66+
du4 = rho * (theta - theta_0) * (S_v + S_h1 + S_h2) * K * gamma / (gamma - 1.0) *
67+
(rho_theta)^(gamma - 1.0) + du2 * v1 + du3 * v2
6768

69+
return SVector(zero(eltype(u)), du2, du3 - g * rho, du4 - g * rho_v2)
6870
end
6971

7072
function (setup::HydrostaticSetup)(x, t, equations::CompressibleEulerEquations2D)
71-
@unpack g, c_p, c_v, p_0, T_0, u0, Nf = setup
73+
@unpack g, c_p, c_v, p_0, T_0, u0, Nf = setup
7274

73-
# Exner pressure, solves hydrostatic equation for x[2]
74-
exner = exp(-Nf^2 / g * x[2])
75-
# pressure
76-
p_0 = 100_000.0 # reference pressure
77-
R = c_p - c_v # gas constant (dry air)
78-
p = p_0 * exner^(c_p / R)
75+
# Exner pressure, solves hydrostatic equation for x[2]
76+
exner = exp(-Nf^2 / g * x[2])
77+
# pressure
78+
p_0 = 100_000.0 # reference pressure
79+
R = c_p - c_v # gas constant (dry air)
80+
p = p_0 * exner^(c_p / R)
7981

80-
# density
81-
rho = p / (R * T_0)
82-
v1 = u0
83-
v2 = 0.0
82+
# density
83+
rho = p / (R * T_0)
84+
v1 = u0
85+
v2 = 0.0
8486

85-
return prim2cons(SVector(rho, v1, v2, p), equations)
87+
return prim2cons(SVector(rho, v1, v2, p), equations)
8688
end
8789

8890
linear_hydrostatic_setup = HydrostaticSetup()
8991

9092
equations = CompressibleEulerEquations2D(linear_hydrostatic_setup.gamma)
9193

9294
boundary_conditions = (x_neg = boundary_condition_periodic,
93-
x_pos = boundary_condition_periodic,
94-
y_neg = boundary_condition_slip_wall,
95-
y_pos = boundary_condition_slip_wall)
95+
x_pos = boundary_condition_periodic,
96+
y_neg = boundary_condition_slip_wall,
97+
y_pos = boundary_condition_slip_wall)
9698

9799
polydeg = 3
98100
basis = LobattoLegendreBasis(polydeg)
@@ -118,8 +120,9 @@ f4(s) = SVector((s + 1 - 1) * L / 2, H)
118120
cells_per_dimension = (100, 50)
119121
mesh = StructuredMesh(cells_per_dimension, (f1, f2, f3, f4), periodicity = (true, false))
120122

121-
semi = SemidiscretizationHyperbolic(mesh, equations, linear_hydrostatic_setup, solver, source_terms = linear_hydrostatic_setup,
122-
boundary_conditions = boundary_conditions)
123+
semi = SemidiscretizationHyperbolic(mesh, equations, linear_hydrostatic_setup, solver,
124+
source_terms = linear_hydrostatic_setup,
125+
boundary_conditions = boundary_conditions)
123126

124127
###############################################################################
125128
# ODE solvers, callbacks etc.
@@ -136,15 +139,15 @@ analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
136139
alive_callback = AliveCallback(analysis_interval = analysis_interval)
137140

138141
callbacks = CallbackSet(summary_callback,
139-
analysis_callback,
140-
alive_callback)
142+
analysis_callback,
143+
alive_callback)
141144

142145
###############################################################################
143146
# run the simulation
144147
sol = solve(ode,
145-
SSPRK43(thread = OrdinaryDiffEq.True()),
146-
maxiters = 1.0e7,
147-
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
148-
save_everystep = false, callback = callbacks)
148+
SSPRK43(thread = OrdinaryDiffEq.True()),
149+
maxiters = 1.0e7,
150+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
151+
save_everystep = false, callback = callbacks)
149152

150153
summary_callback()

0 commit comments

Comments
 (0)