Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/structured_3d_dgsem/elixir_advection_free_stream.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear advection equation
6
7
advection_velocity = (0.2, -0.7, 0.5)
8
equations = LinearScalarAdvectionEquation3D(advection_velocity)
9
10
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
11
solver = DGSEM(3, flux_lax_friedrichs)
12
13
# Mapping as described in https://arxiv.org/abs/2012.12040
14
function mapping(xi_, eta_, zeta_)
15
# Transform input variables between -1 and 1 onto [0,3]
16
xi = 1.5 * xi_ + 1.5
17
eta = 1.5 * eta_ + 1.5
18
zeta = 1.5 * zeta_ + 1.5
19
20
y = eta +
21
3 / 8 * (cos(1.5 * pi * (2 * xi - 3) / 3) *
22
cos(0.5 * pi * (2 * eta - 3) / 3) *
23
cos(0.5 * pi * (2 * zeta - 3) / 3))
24
25
x = xi +
26
3 / 8 * (cos(0.5 * pi * (2 * xi - 3) / 3) *
27
cos(2 * pi * (2 * y - 3) / 3) *
28
cos(0.5 * pi * (2 * zeta - 3) / 3))
29
30
z = zeta +
31
3 / 8 * (cos(0.5 * pi * (2 * x - 3) / 3) *
32
cos(pi * (2 * y - 3) / 3) *
33
cos(0.5 * pi * (2 * zeta - 3) / 3))
34
35
return SVector(x, y, z)
36
end
37
38
cells_per_dimension = (8, 8, 8)
39
40
# Create curved mesh with 8 x 8 x 8 elements
41
mesh = StructuredMesh(cells_per_dimension, mapping)
42
43
# A semidiscretization collects data structures and functions for the spatial discretization
44
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_constant, solver)
45
46
###############################################################################
47
# ODE solvers, callbacks etc.
48
49
# Create ODE problem with time span from 0.0 to 1.0
50
ode = semidiscretize(semi, (0.0, 1.0))
51
52
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
53
# and resets the timers
54
summary_callback = SummaryCallback()
55
56
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
57
analysis_callback = AnalysisCallback(semi, interval = 100)
58
59
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
60
save_solution = SaveSolutionCallback(interval = 100,
61
solution_variables = cons2prim)
62
63
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
64
stepsize_callback = StepsizeCallback(cfl = 2.0)
65
66
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
67
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
68
stepsize_callback)
69
70
###############################################################################
71
# run the simulation
72
73
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
74
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
75
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
76
ode_default_options()..., callback = callbacks);
77
78