Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/unstructured_2d_fdsbp/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 FDSBP approximation operator
12
13
D_SBP = derivative_operator(SummationByPartsOperators.MattssonAlmquistVanDerWeide2018Accurate(),
14
derivative_order = 1, accuracy_order = 4,
15
xmin = -1.0, xmax = 1.0, N = 15)
16
solver = FDSBP(D_SBP,
17
surface_integral = SurfaceIntegralStrongForm(flux_lax_friedrichs),
18
volume_integral = VolumeIntegralStrongForm())
19
20
###############################################################################
21
# Get the curved quad mesh from a file (downloads the file if not available locally)
22
mesh_file = Trixi.download("https://gist.githubusercontent.com/andrewwinters5000/12ce661d7c354c3d94c74b964b0f1c96/raw/8275b9a60c6e7ebbdea5fc4b4f091c47af3d5273/mesh_periodic_square_with_twist.mesh",
23
joinpath(@__DIR__, "mesh_periodic_square_with_twist.mesh"))
24
25
mesh = UnstructuredMesh2D(mesh_file, periodicity = true)
26
27
###############################################################################
28
# create the semidiscretization object
29
30
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
31
solver)
32
33
###############################################################################
34
# ODE solvers, callbacks etc.
35
36
# Create ODE problem with time span from 0.0 to 1.0
37
ode = semidiscretize(semi, (0.0, 1.0))
38
39
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
40
# and resets the timers
41
summary_callback = SummaryCallback()
42
43
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
44
analysis_callback = AnalysisCallback(semi, interval = 100)
45
46
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
47
save_solution = SaveSolutionCallback(interval = 100,
48
solution_variables = cons2prim)
49
50
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
51
stepsize_callback = StepsizeCallback(cfl = 1.6)
52
53
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
54
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
55
stepsize_callback)
56
57
###############################################################################
58
# run the simulation
59
60
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
61
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
62
ode_default_options()..., callback = callbacks);
63
64