Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_3d_dgsem/elixir_advection_diffusion_amr.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, 0.5)
8
equations = LinearScalarAdvectionEquation3D(advection_velocity)
9
10
diffusivity() = 5.0e-4
11
equations_parabolic = LaplaceDiffusion3D(diffusivity(), equations)
12
13
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
14
15
coordinates_min = (-1.0, -1.0, -1.0)
16
coordinates_max = (1.0, 1.0, 1.0)
17
mesh = TreeMesh(coordinates_min, coordinates_max,
18
initial_refinement_level = 4,
19
n_cells_max = 80_000)
20
21
# Define initial condition
22
function initial_condition_diffusive_convergence_test(x, t,
23
equation::LinearScalarAdvectionEquation3D)
24
# Store translated coordinate for easy use of exact solution
25
x_trans = x - equation.advection_velocity * t
26
27
nu = diffusivity()
28
c = 1.0
29
A = 0.5
30
L = 2
31
f = 1 / L
32
omega = 2 * pi * f
33
scalar = c + A * sin(omega * sum(x_trans)) * exp(-2 * nu * omega^2 * t)
34
return SVector(scalar)
35
end
36
initial_condition = initial_condition_diffusive_convergence_test
37
38
# define periodic boundary conditions everywhere
39
boundary_conditions = boundary_condition_periodic
40
boundary_conditions_parabolic = boundary_condition_periodic
41
42
# A semidiscretization collects data structures and functions for the spatial discretization
43
semi = SemidiscretizationHyperbolicParabolic(mesh,
44
(equations, equations_parabolic),
45
initial_condition, solver;
46
solver_parabolic = ViscousFormulationBassiRebay1(),
47
boundary_conditions = (boundary_conditions,
48
boundary_conditions_parabolic))
49
50
###############################################################################
51
# ODE solvers, callbacks etc.
52
53
tspan = (0.0, 0.2)
54
ode = semidiscretize(semi, tspan)
55
56
summary_callback = SummaryCallback()
57
58
analysis_interval = 100
59
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
60
extra_analysis_integrals = (entropy,))
61
62
alive_callback = AliveCallback(analysis_interval = analysis_interval)
63
64
save_solution = SaveSolutionCallback(interval = 100,
65
save_initial_solution = true,
66
save_final_solution = true,
67
solution_variables = cons2prim)
68
69
amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first),
70
base_level = 3,
71
med_level = 4, med_threshold = 1.2,
72
max_level = 5, max_threshold = 1.45)
73
amr_callback = AMRCallback(semi, amr_controller,
74
interval = 5,
75
adapt_initial_condition = true,
76
adapt_initial_condition_only_refine = true)
77
78
stepsize_callback = StepsizeCallback(cfl = 1.0)
79
80
callbacks = CallbackSet(summary_callback,
81
analysis_callback,
82
alive_callback,
83
save_solution,
84
amr_callback,
85
stepsize_callback)
86
87
###############################################################################
88
# run the simulation
89
90
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
91
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
92
ode_default_options()..., callback = callbacks);
93
94