Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/structured_1d_dgsem/elixir_linearizedeuler_characteristic_system.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using LinearAlgebra: dot
3
using Trixi
4
5
###############################################################################
6
# semidiscretization of the linearized Euler equations
7
8
rho_0 = 1.0
9
v_0 = 1.0
10
c_0 = 1.0
11
equations = LinearizedEulerEquations1D(rho_0, v_0, c_0)
12
13
solver = DGSEM(polydeg = 3, surface_flux = flux_hll)
14
15
coordinates_min = (0.0,) # minimum coordinate
16
coordinates_max = (1.0,) # maximum coordinate
17
cells_per_dimension = (64,)
18
19
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)
20
21
# For eigensystem of the linearized Euler equations see e.g.
22
# https://www.nas.nasa.gov/assets/nas/pdf/ams/2018/introtocfd/Intro2CFD_Lecture1_Pulliam_Euler_WaveEQ.pdf
23
# Linearized Euler: Eigensystem
24
lin_euler_eigvals = [v_0 - c_0; v_0; v_0 + c_0]
25
lin_euler_eigvecs = [-rho_0/c_0 1 rho_0/c_0;
26
1 0 1;
27
-rho_0*c_0 0 rho_0*c_0]
28
lin_euler_eigvecs_inv = inv(lin_euler_eigvecs)
29
30
# Trace back characteristics.
31
# See https://metaphor.ethz.ch/x/2019/hs/401-4671-00L/literature/mishra_hyperbolic_pdes.pdf, p.95
32
function compute_char_initial_pos(x, t)
33
return SVector(x[1], x[1], x[1]) .- t * lin_euler_eigvals
34
end
35
36
function compute_primal_sol(char_vars)
37
return lin_euler_eigvecs * char_vars
38
end
39
40
# Initial condition is in principle arbitrary, only periodicity is required
41
function initial_condition_entropy_wave(x, t, equations::LinearizedEulerEquations1D)
42
# Parameters
43
alpha = 1.0
44
beta = 150.0
45
center = 0.5
46
47
rho_prime = alpha * exp(-beta * (x[1] - center)^2)
48
v_prime = 0.0
49
p_prime = 0.0
50
51
return SVector(rho_prime, v_prime, p_prime)
52
end
53
54
function initial_condition_char_vars(x, t, equations::LinearizedEulerEquations1D)
55
# Trace back characteristics
56
x_char = compute_char_initial_pos(x, t)
57
58
# Employ periodicity
59
for p in 1:3
60
while x_char[p] < coordinates_min[1]
61
x_char[p] += coordinates_max[1] - coordinates_min[1]
62
end
63
while x_char[p] > coordinates_max[1]
64
x_char[p] -= coordinates_max[1] - coordinates_min[1]
65
end
66
end
67
68
# Set up characteristic variables
69
w = zeros(3)
70
t_0 = 0 # Assumes t_0 = 0
71
for p in 1:3
72
u_char = initial_condition_entropy_wave(x_char[p], t_0, equations)
73
w[p] = dot(lin_euler_eigvecs_inv[p, :], u_char)
74
end
75
76
return compute_primal_sol(w)
77
end
78
79
initial_condition = initial_condition_char_vars
80
81
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
82
83
###############################################################################
84
# ODE solvers, callbacks etc.
85
86
tspan = (0.0, 0.3)
87
ode = semidiscretize(semi, tspan)
88
89
summary_callback = SummaryCallback()
90
91
analysis_interval = 100
92
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
93
94
alive_callback = AliveCallback(analysis_interval = analysis_interval)
95
96
stepsize_callback = StepsizeCallback(cfl = 1.0)
97
98
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
99
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback,
100
stepsize_callback)
101
102
###############################################################################
103
# run the simulation
104
105
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
106
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
107
ode_default_options()..., callback = callbacks);
108
109