Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/structured_1d_dgsem/elixir_advection_basic.jl
2795 views
1
# The same setup as tree_1d_dgsem/elixir_advection_basic.jl
2
# to verify the StructuredMesh implementation against TreeMesh
3
4
using OrdinaryDiffEqLowStorageRK
5
using Trixi
6
7
###############################################################################
8
# semidiscretization of the linear advection equation
9
10
advection_velocity = 1.0
11
equations = LinearScalarAdvectionEquation1D(advection_velocity)
12
13
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
14
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
15
16
coordinates_min = (-1.0,) # minimum coordinate
17
coordinates_max = (1.0,) # maximum coordinate
18
cells_per_dimension = (16,)
19
20
# Create curved mesh with 16 cells
21
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max,
22
periodicity = true)
23
24
# A semidiscretization collects data structures and functions for the spatial discretization
25
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
26
solver;
27
boundary_conditions = boundary_condition_periodic)
28
29
###############################################################################
30
# ODE solvers, callbacks etc.
31
32
# Create ODE problem with time span from 0.0 to 1.0
33
ode = semidiscretize(semi, (0.0, 1.0))
34
35
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
36
# and resets the timers
37
summary_callback = SummaryCallback()
38
39
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
40
analysis_callback = AnalysisCallback(semi, interval = 100)
41
42
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
43
save_solution = SaveSolutionCallback(interval = 100,
44
solution_variables = cons2prim)
45
46
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
47
stepsize_callback = StepsizeCallback(cfl = 1.6)
48
49
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
50
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
51
stepsize_callback)
52
53
###############################################################################
54
# run the simulation
55
56
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
57
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
58
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
59
ode_default_options()..., callback = callbacks);
60
61