Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/unstructured_2d_dgsem/elixir_advection_basic.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
###############################################################################
11
# Get the DG approximation space
12
13
solver = DGSEM(polydeg = 6, surface_flux = flux_lax_friedrichs)
14
15
###############################################################################
16
# Get the curved quad mesh from a file (downloads the file if not available locally)
17
mesh_file = Trixi.download("https://gist.githubusercontent.com/andrewwinters5000/12ce661d7c354c3d94c74b964b0f1c96/raw/8275b9a60c6e7ebbdea5fc4b4f091c47af3d5273/mesh_periodic_square_with_twist.mesh",
18
joinpath(@__DIR__, "mesh_periodic_square_with_twist.mesh"))
19
20
mesh = UnstructuredMesh2D(mesh_file, periodicity = true)
21
22
###############################################################################
23
# create the semi discretization object
24
25
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
26
solver)
27
28
###############################################################################
29
# ODE solvers, callbacks etc.
30
31
# Create ODE problem with time span from 0.0 to 1.0
32
tspan = (0.0, 1.0)
33
ode = semidiscretize(semi, tspan)
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
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
57
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
58
ode_default_options()..., callback = callbacks);
59
60