Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/p4est_2d_dgsem/elixir_advection_diffusion_rotated.jl
5586 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear advection-diffusion equation
6
7
diffusivity() = 1.0e-2
8
advection_velocity = (-1.0, 1.0)
9
equations = LinearScalarAdvectionEquation2D(advection_velocity)
10
equations_parabolic = LaplaceDiffusion2D(diffusivity(), equations)
11
12
function initial_condition_gauss_damped(x, t, equations)
13
damping_factor = 1 + 4 * diffusivity() * t
14
return SVector(exp(-(x[1]^2 + x[2]^2) / damping_factor) / damping_factor)
15
end
16
initial_condition = initial_condition_gauss_damped
17
18
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
19
20
# This maps the domain [-1, 1]^2 to a 45-degree rotated increased square
21
square_size() = 5.0
22
function mapping(xi, eta)
23
x = square_size() * xi
24
y = square_size() * eta
25
return SVector((x - y) / sqrt(2), (x + y) / sqrt(2))
26
end
27
28
trees_per_dimension = (23, 23)
29
mesh = P4estMesh(trees_per_dimension,
30
polydeg = 3, initial_refinement_level = 0,
31
mapping = mapping, periodicity = true)
32
33
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
34
initial_condition, solver;
35
solver_parabolic = ParabolicFormulationLocalDG(),
36
boundary_conditions = (boundary_condition_periodic,
37
boundary_condition_periodic))
38
39
###############################################################################
40
# ODE solvers, callbacks etc.
41
42
n_passes = 2
43
tspan = (0.0, n_passes * square_size() * sqrt(2))
44
ode = semidiscretize(semi, tspan)
45
46
summary_callback = SummaryCallback()
47
48
analysis_interval = 100
49
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
50
51
alive_callback = AliveCallback(analysis_interval = analysis_interval)
52
53
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback)
54
55
###############################################################################
56
# run the simulation
57
58
time_int_tol = 1.0e-6
59
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
60
ode_default_options()..., callback = callbacks)
61
62