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