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_waving_flag.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_convergence_test
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
# Deformed rectangle that looks like a waving flag,
16
# lower and upper faces are sinus curves, left and right are vertical lines.
17
f1(s) = SVector(-1.0, s - 1.0)
18
f2(s) = SVector(1.0, s + 1.0)
19
f3(s) = SVector(s, -1.0 + sin(0.5 * pi * s))
20
f4(s) = SVector(s, 1.0 + sin(0.5 * pi * s))
21
22
cells_per_dimension = (16, 16)
23
24
# Create curved mesh with 16 x 16 elements
25
mesh = StructuredMesh(cells_per_dimension, (f1, f2, f3, f4))
26
27
# A semidiscretization collects data structures and functions for the spatial discretization
28
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
29
30
###############################################################################
31
# ODE solvers, callbacks etc.
32
33
# Create ODE problem with time span from 0.0 to 1.0
34
ode = semidiscretize(semi, (0.0, 1.0))
35
36
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
37
# and resets the timers
38
summary_callback = SummaryCallback()
39
40
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
41
analysis_callback = AnalysisCallback(semi, interval = 100)
42
43
# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted
44
save_restart = SaveRestartCallback(interval = 100,
45
save_final_restart = true)
46
47
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
48
save_solution = SaveSolutionCallback(interval = 100,
49
solution_variables = cons2prim)
50
51
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
52
stepsize_callback = StepsizeCallback(cfl = 1.4)
53
54
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
55
callbacks = CallbackSet(summary_callback, analysis_callback, save_restart, save_solution,
56
stepsize_callback)
57
58
###############################################################################
59
# run the simulation
60
61
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
62
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
63
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
64
ode_default_options()..., callback = callbacks);
65
66