forked from trixi-framework/Trixi.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelixir_hypdiff_lax_friedrichs.jl
91 lines (71 loc) · 3.31 KB
/
elixir_hypdiff_lax_friedrichs.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# We use time integration methods implemented in Trixi.jl, but we need the `CallbackSet`
using OrdinaryDiffEq: CallbackSet
using Trixi
###############################################################################
# semidiscretization of the hyperbolic diffusion equations
equations = HyperbolicDiffusionEquations2D()
function initial_condition_poisson_periodic(x, t, equations::HyperbolicDiffusionEquations2D)
# elliptic equation: -νΔϕ = f
# depending on initial constant state, c, for phi this converges to the solution ϕ + c
RealT = eltype(x)
if iszero(t)
phi = zero(RealT)
q1 = zero(RealT)
q2 = zero(RealT)
else
phi = sinpi(2 * x[1]) * sinpi(2 * x[2])
q1 = 2 * convert(RealT, pi) * cospi(2 * x[1]) * sinpi(2 * x[2])
q2 = 2 * convert(RealT, pi) * sinpi(2 * x[1]) * cospi(2 * x[2])
end
return SVector(phi, q1, q2)
end
initial_condition = initial_condition_poisson_periodic
@inline function source_terms_poisson_periodic(u, x, t,
equations::HyperbolicDiffusionEquations2D)
# elliptic equation: -νΔϕ = f
# analytical solution: phi = sin(2πx)*sin(2πy) and f = -8νπ^2 sin(2πx)*sin(2πy)
RealT = eltype(u)
@unpack inv_Tr = equations
C = -8 * equations.nu * convert(RealT, pi)^2
x1, x2 = x
tmp1 = sinpi(2 * x1)
tmp2 = sinpi(2 * x2)
du1 = -C * tmp1 * tmp2
du2 = -inv_Tr * u[2]
du3 = -inv_Tr * u[3]
return SVector(du1, du2, du3)
end
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
coordinates_min = (0.0, 0.0)
coordinates_max = (1.0, 1.0)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 3,
n_cells_max = 30_000)
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
source_terms = source_terms_poisson_periodic)
###############################################################################
# ODE solvers, callbacks etc.
tspan = (0.0, 2.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
resid_tol = 5.0e-12
steady_state_callback = SteadyStateCallback(abstol = resid_tol, reltol = 0.0)
analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
extra_analysis_integrals = (entropy, energy_total))
alive_callback = AliveCallback(analysis_interval = analysis_interval)
save_solution = SaveSolutionCallback(interval = 100,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)
stepsize_callback = StepsizeCallback(cfl = 1.2)
callbacks = CallbackSet(summary_callback, steady_state_callback,
analysis_callback, alive_callback,
save_solution,
stepsize_callback)
###############################################################################
# run the simulation
sol = Trixi.solve(ode, Trixi.HypDiffN3Erk3Sstar52(),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary