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_extended.jl
5586 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
# you can either use a single function to impose the BCs weakly in all
13
# 1*ndims == 2 directions or you can pass a tuple containing BCs for
14
# each direction
15
boundary_conditions = boundary_condition_periodic
16
17
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
18
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
19
20
# The initial condition is 2-periodic
21
coordinates_min = (-1.5, 1.3) # minimum coordinates (min(x), min(y))
22
coordinates_max = (0.5, 5.3) # maximum coordinates (max(x), max(y))
23
24
cells_per_dimension = (19, 37)
25
26
# Create curved mesh with 19 x 37 elements
27
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max,
28
periodicity = true)
29
30
# A semidiscretization collects data structures and functions for the spatial discretization
31
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
32
boundary_conditions = boundary_conditions)
33
34
###############################################################################
35
# ODE solvers, callbacks etc.
36
37
# Create ODE problem with time span from 0.0 to 1.0
38
tspan = (0.0, 1.0)
39
ode = semidiscretize(semi, tspan)
40
41
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
42
# and resets the timers
43
summary_callback = SummaryCallback()
44
45
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
46
analysis_interval = 100
47
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
48
extra_analysis_integrals = (entropy, energy_total))
49
50
# The AliveCallback prints short status information in regular intervals
51
alive_callback = AliveCallback(analysis_interval = analysis_interval)
52
53
# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted
54
save_restart = SaveRestartCallback(interval = 100,
55
save_final_restart = true)
56
57
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
58
save_solution = SaveSolutionCallback(interval = 100,
59
save_initial_solution = true,
60
save_final_solution = true,
61
solution_variables = cons2prim)
62
63
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
64
stepsize_callback = StepsizeCallback(cfl = 1.6)
65
66
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
67
callbacks = CallbackSet(summary_callback,
68
analysis_callback, alive_callback,
69
save_restart, save_solution,
70
stepsize_callback)
71
72
###############################################################################
73
# run the simulation
74
75
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
76
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
77
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
78
ode_default_options()..., callback = callbacks);
79
80