Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/special_elixirs/elixir_euler_ad.jl
2055 views
1
# This example is described in more detail in the documentation of Trixi.jl
2
3
using Trixi, LinearAlgebra, ForwardDiff
4
5
equations = CompressibleEulerEquations2D(1.4)
6
7
mesh = TreeMesh((-1.0, -1.0), (1.0, 1.0),
8
initial_refinement_level = 2, n_cells_max = 10^5)
9
10
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
11
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
12
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
13
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
14
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
15
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
16
# `StepsizeCallback` (CFL-Condition) and less diffusion.
17
solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive),
18
volume_integral = VolumeIntegralFluxDifferencing(flux_ranocha))
19
20
"""
21
initial_condition_isentropic_vortex(x, t, equations::CompressibleEulerEquations2D)
22
23
The classical isentropic vortex test case of
24
- Chi-Wang Shu (1997)
25
Essentially Non-Oscillatory and Weighted Essentially Non-Oscillatory
26
Schemes for Hyperbolic Conservation Laws
27
[NASA/CR-97-206253](https://ntrs.nasa.gov/citations/19980007543)
28
"""
29
function initial_condition_isentropic_vortex(x, t, equations::CompressibleEulerEquations2D)
30
# needs appropriate mesh size, e.g. [-10,-10]x[10,10]
31
# for error convergence: make sure that the end time is such that the vortex is back at the initial state!!
32
# for the current velocity and domain size: t_end should be a multiple of 20s
33
# initial center of the vortex
34
inicenter = SVector(0.0, 0.0)
35
# size and strength of the vortex
36
iniamplitude = 5.0
37
# base flow
38
rho = 1.0
39
v1 = 1.0
40
v2 = 1.0
41
vel = SVector(v1, v2)
42
p = 25.0
43
rt = p / rho # ideal gas equation
44
t_loc = 0.0
45
cent = inicenter + vel * t_loc # advection of center
46
# ATTENTION: handle periodic BC, but only for v1 = v2 = 1.0 (!!!!)
47
cent = x - cent # distance to center point
48
# cent = cross(iniaxis, cent) # distance to axis, tangent vector, length r
49
# cross product with iniaxis = [0, 0, 1]
50
cent = SVector(-cent[2], cent[1])
51
r2 = cent[1]^2 + cent[2]^2
52
du = iniamplitude / (2 * π) * exp(0.5 * (1 - r2)) # vel. perturbation
53
dtemp = -(equations.gamma - 1) / (2 * equations.gamma * rt) * du^2 # isentropic
54
rho = rho * (1 + dtemp)^(1 / (equations.gamma - 1))
55
vel = vel + du * cent
56
v1, v2 = vel
57
p = p * (1 + dtemp)^(equations.gamma / (equations.gamma - 1))
58
prim = SVector(rho, v1, v2, p)
59
return prim2cons(prim, equations)
60
end
61
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_isentropic_vortex,
62
solver)
63
64
u0_ode = compute_coefficients(0.0, semi)
65
66
J = ForwardDiff.jacobian((du_ode, γ) -> begin
67
equations_inner = CompressibleEulerEquations2D(first(γ))
68
semi_inner = Trixi.remake(semi, equations = equations_inner,
69
uEltype = eltype(γ))
70
Trixi.rhs!(du_ode, u0_ode, semi_inner, 0.0)
71
end, similar(u0_ode), [1.4]); # γ needs to be an `AbstractArray`
72
73