Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_2d_dgsem/elixir_acoustics_gauss_wall.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the acoustic perturbation equations
6
7
equations = AcousticPerturbationEquations2D(v_mean_global = (0.5, 0.0), c_mean_global = 1.0,
8
rho_mean_global = 1.0)
9
10
# Create DG solver with polynomial degree = 5 and (local) Lax-Friedrichs/Rusanov flux as surface flux
11
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
12
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
13
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
14
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
15
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
16
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
17
# `StepsizeCallback` (CFL-Condition) and less diffusion.
18
solver = DGSEM(polydeg = 5, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive))
19
20
coordinates_min = (-100.0, 0.0) # minimum coordinates (min(x), min(y))
21
coordinates_max = (100.0, 200.0) # maximum coordinates (max(x), max(y))
22
23
# Create a uniformly refined mesh with periodic boundaries
24
mesh = TreeMesh(coordinates_min, coordinates_max,
25
initial_refinement_level = 4,
26
n_cells_max = 100_000,
27
periodicity = false)
28
29
"""
30
initial_condition_gauss_wall(x, t, equations::AcousticPerturbationEquations2D)
31
32
A Gaussian pulse, used in the `gauss_wall` example elixir in combination with
33
[`boundary_condition_wall`](@ref). Uses the global mean values from `equations`.
34
"""
35
function initial_condition_gauss_wall(x, t, equations::AcousticPerturbationEquations2D)
36
RealT = eltype(x)
37
v1_prime = 0
38
v2_prime = 0
39
p_prime = exp(-log(convert(RealT, 2)) * (x[1]^2 + (x[2] - 25)^2) / 25)
40
41
prim = SVector(v1_prime, v2_prime, p_prime, global_mean_vars(equations)...)
42
43
return prim2cons(prim, equations)
44
end
45
initial_condition = initial_condition_gauss_wall
46
47
# A semidiscretization collects data structures and functions for the spatial discretization
48
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
49
boundary_conditions = boundary_condition_wall)
50
51
###############################################################################
52
# ODE solvers, callbacks etc.
53
54
# Create ODE problem with time span from 0.0 to 30.0
55
tspan = (0.0, 30.0)
56
ode = semidiscretize(semi, tspan)
57
58
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
59
# and resets the timers
60
summary_callback = SummaryCallback()
61
62
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
63
analysis_callback = AnalysisCallback(semi, interval = 100)
64
65
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
66
save_solution = SaveSolutionCallback(interval = 100, solution_variables = cons2state)
67
68
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
69
stepsize_callback = StepsizeCallback(cfl = 0.7)
70
71
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
72
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
73
stepsize_callback)
74
75
###############################################################################
76
# run the simulation
77
78
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
79
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
80
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
81
ode_default_options()..., callback = callbacks)
82
83