Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/p4est_2d_dgsem/elixir_linearizedeuler_gaussian_source.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
# Based on the TreeMesh example `elixir_acoustics_gaussian_source.jl`.
5
# The acoustic perturbation equations have been replaced with the linearized Euler
6
# equations and instead of the Cartesian `TreeMesh` a rotated `P4estMesh` is used
7
8
# Oscillating Gaussian-shaped source terms
9
function source_terms_gauss(u, x, t, equations::LinearizedEulerEquations2D)
10
r = 0.1
11
A = 1.0
12
f = 2.0
13
14
# Velocity sources
15
s2 = 0.0
16
s3 = 0.0
17
# Density and pressure source
18
s1 = s4 = exp(-(x[1]^2 + x[2]^2) / (2 * r^2)) * A * sin(2 * pi * f * t)
19
20
return SVector(s1, s2, s3, s4)
21
end
22
23
function initial_condition_zero(x, t, equations::LinearizedEulerEquations2D)
24
SVector(0.0, 0.0, 0.0, 0.0)
25
end
26
27
###############################################################################
28
# semidiscretization of the linearized Euler equations
29
30
# Create a domain that is a 30° rotated version of [-3, 3]^2
31
c = cospi(2 * 30.0 / 360.0)
32
s = sinpi(2 * 30.0 / 360.0)
33
rot_mat = Trixi.SMatrix{2, 2}([c -s; s c])
34
mapping(xi, eta) = rot_mat * SVector(3.0 * xi, 3.0 * eta)
35
36
# Mean density and speed of sound are slightly off from 1.0 to allow proper verification of
37
# curved LEE implementation using this elixir (some things in the LEE cancel if both are 1.0)
38
equations = LinearizedEulerEquations2D(v_mean_global = Tuple(rot_mat * SVector(-0.5, 0.25)),
39
c_mean_global = 1.02, rho_mean_global = 1.01)
40
41
initial_condition = initial_condition_zero
42
43
# Create DG solver with polynomial degree = 3 and upwind flux as surface flux
44
solver = DGSEM(polydeg = 3, surface_flux = flux_godunov)
45
46
# Create a uniformly refined mesh with periodic boundaries
47
trees_per_dimension = (4, 4)
48
mesh = P4estMesh(trees_per_dimension, polydeg = 1,
49
mapping = mapping,
50
periodicity = true, initial_refinement_level = 2)
51
52
# A semidiscretization collects data structures and functions for the spatial discretization
53
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
54
source_terms = source_terms_gauss)
55
56
###############################################################################
57
# ODE solvers, callbacks etc.
58
59
# Create ODE problem with time span from 0.0 to 2.0
60
tspan = (0.0, 2.0)
61
ode = semidiscretize(semi, tspan)
62
63
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
64
# and resets the timers
65
summary_callback = SummaryCallback()
66
67
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
68
analysis_callback = AnalysisCallback(semi, interval = 100)
69
70
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
71
save_solution = SaveSolutionCallback(interval = 100)
72
73
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
74
stepsize_callback = StepsizeCallback(cfl = 0.5)
75
76
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
77
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
78
stepsize_callback)
79
80
###############################################################################
81
# run the simulation
82
83
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
84
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
85
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
86
ode_default_options()..., callback = callbacks);
87
88