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
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)
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)
34
35
# A semidiscretization collects data structures and functions for the spatial discretization
36
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
37
38
###############################################################################
39
# ODE solvers, callbacks etc.
40
41
# Create ODE problem with time span from 0.0 to 1.0
42
ode = semidiscretize(semi, (0.0, 1.0))
43
44
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
45
# and resets the timers
46
summary_callback = SummaryCallback()
47
48
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
49
analysis_callback = AnalysisCallback(semi, interval = 100)
50
51
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
52
save_solution = SaveSolutionCallback(interval = 100,
53
solution_variables = cons2prim)
54
55
# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted
56
save_restart = SaveRestartCallback(interval = 100,
57
save_final_restart = true)
58
59
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
60
stepsize_callback = StepsizeCallback(cfl = 2.0)
61
62
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
63
callbacks = CallbackSet(summary_callback, analysis_callback, save_restart, save_solution,
64
stepsize_callback)
65
66
###############################################################################
67
# run the simulation
68
69
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
70
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
71
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
72
ode_default_options()..., callback = callbacks);
73
74