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_gaussian_source.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
# Oscillating Gaussian-shaped source terms
5
function source_terms_gauss(u, x, t, equations::AcousticPerturbationEquations2D)
6
RealT = eltype(u)
7
r = convert(RealT, 0.1)
8
A = 1
9
f = 2
10
11
# Velocity sources
12
s1 = 0
13
s2 = 0
14
# Pressure source
15
s3 = exp(-(x[1]^2 + x[2]^2) / (2 * r^2)) * A * sinpi(2 * f * t)
16
17
# Mean sources
18
s4 = s5 = s6 = s7 = 0
19
20
return SVector(s1, s2, s3, s4, s5, s6, s7)
21
end
22
23
###############################################################################
24
# semidiscretization of the acoustic perturbation equations
25
26
equations = AcousticPerturbationEquations2D(v_mean_global = (-0.5, 0.25),
27
c_mean_global = 1.0,
28
rho_mean_global = 1.0)
29
30
initial_condition = initial_condition_constant
31
32
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
33
34
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
35
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
36
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
37
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
38
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
39
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
40
# `StepsizeCallback` (CFL-Condition) and less diffusion.
41
solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive))
42
43
coordinates_min = (-3.0, -3.0) # minimum coordinates (min(x), min(y))
44
coordinates_max = (3.0, 3.0) # maximum coordinates (max(x), max(y))
45
46
# Create a uniformly refined mesh with periodic boundaries
47
mesh = TreeMesh(coordinates_min, coordinates_max,
48
initial_refinement_level = 4,
49
n_cells_max = 30_000) # set maximum capacity of tree data structure
50
51
# A semidiscretization collects data structures and functions for the spatial discretization
52
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
53
source_terms = source_terms_gauss)
54
55
###############################################################################
56
# ODE solvers, callbacks etc.
57
58
# Create ODE problem with time span from 0.0 to 2.0
59
tspan = (0.0, 2.0)
60
ode = semidiscretize(semi, tspan)
61
62
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
63
# and resets the timers
64
summary_callback = SummaryCallback()
65
66
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
67
analysis_callback = AnalysisCallback(semi, interval = 100)
68
69
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
70
save_solution = SaveSolutionCallback(interval = 100,
71
solution_variables = cons2prim)
72
73
# The TimeSeriesCallback records the solution at the given points over time
74
time_series = TimeSeriesCallback(semi, [(0.0, 0.0), (-1.0, 0.5)])
75
76
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
77
stepsize_callback = StepsizeCallback(cfl = 0.5)
78
79
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
80
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution, time_series,
81
stepsize_callback)
82
83
###############################################################################
84
# run the simulation
85
86
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
87
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
88
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
89
ode_default_options()..., callback = callbacks);
90
91