Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_1d_dgsem/elixir_hypdiff_nonperiodic_perk4.jl
2055 views
1
using Trixi
2
3
# Convex and ECOS are imported because they are used for finding the optimal time step and optimal
4
# monomial coefficients in the stability polynomial of P-ERK time integrators.
5
using Convex, ECOS
6
7
###############################################################################
8
# semidiscretization of the hyperbolic diffusion equations
9
10
equations = HyperbolicDiffusionEquations1D()
11
12
initial_condition = initial_condition_poisson_nonperiodic
13
14
boundary_conditions = boundary_condition_poisson_nonperiodic
15
16
solver = DGSEM(polydeg = 4, surface_flux = flux_lax_friedrichs)
17
18
coordinates_min = 0.0
19
coordinates_max = 1.0
20
mesh = TreeMesh(coordinates_min, coordinates_max,
21
initial_refinement_level = 3,
22
n_cells_max = 30_000,
23
periodicity = false)
24
25
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
26
boundary_conditions = boundary_conditions,
27
source_terms = source_terms_poisson_nonperiodic)
28
29
###############################################################################
30
# ODE solvers, callbacks etc.
31
32
tspan = (0.0, 5.0)
33
ode = semidiscretize(semi, tspan);
34
35
summary_callback = SummaryCallback()
36
37
resid_tol = 5.0e-12
38
steady_state_callback = SteadyStateCallback(abstol = resid_tol, reltol = 0.0)
39
40
analysis_interval = 100
41
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
42
43
alive_callback = AliveCallback(analysis_interval = analysis_interval)
44
45
# Construct fourth order paired explicit Runge-Kutta method with 11 stages for given simulation setup.
46
# Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used
47
# in calculating the polynomial coefficients in the ODE algorithm.
48
ode_algorithm = Trixi.PairedExplicitRK4(11, tspan, semi)
49
50
cfl_number = Trixi.calculate_cfl(ode_algorithm, ode)
51
stepsize_callback = StepsizeCallback(cfl = 0.9 * cfl_number)
52
53
callbacks = CallbackSet(summary_callback,
54
analysis_callback, alive_callback,
55
stepsize_callback)
56
57
###############################################################################
58
# run the simulation
59
60
sol = Trixi.solve(ode, ode_algorithm;
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