Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_2d_dgsem/elixir_advection_diffusion_nonperiodic.jl
5586 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear advection-diffusion equation
6
7
diffusivity() = 5.0e-2
8
advection_velocity = (1.0, 0.0)
9
equations = LinearScalarAdvectionEquation2D(advection_velocity)
10
equations_parabolic = LaplaceDiffusion2D(diffusivity(), equations)
11
12
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
13
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
14
15
coordinates_min = (-1.0, -0.5) # minimum coordinates (min(x), min(y))
16
coordinates_max = (0.0, 0.5) # maximum coordinates (max(x), max(y))
17
18
mesh = TreeMesh(coordinates_min, coordinates_max,
19
initial_refinement_level = 4,
20
periodicity = false,
21
n_cells_max = 30_000) # set maximum capacity of tree data structure
22
23
# Example setup taken from
24
# - Truman Ellis, Jesse Chan, and Leszek Demkowicz (2016).
25
# Robust DPG methods for transient convection-diffusion.
26
# In: Building bridges: connections and challenges in modern approaches
27
# to numerical partial differential equations.
28
# [DOI](https://doi.org/10.1007/978-3-319-41640-3_6).
29
function initial_condition_eriksson_johnson(x, t, equations)
30
RealT = eltype(x)
31
l = 4
32
epsilon = diffusivity() # NOTE: this requires epsilon <= 1/16 due to sqrt
33
lambda_1 = (-1 + sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
34
lambda_2 = (-1 - sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
35
r1 = (1 + sqrt(1 + 4 * convert(RealT, pi)^2 * epsilon^2)) / (2 * epsilon)
36
s1 = (1 - sqrt(1 + 4 * convert(RealT, pi)^2 * epsilon^2)) / (2 * epsilon)
37
u = exp(-l * t) * (exp(lambda_1 * x[1]) - exp(lambda_2 * x[1])) +
38
cospi(x[2]) * (exp(s1 * x[1]) - exp(r1 * x[1])) / (exp(-s1) - exp(-r1))
39
return SVector{1}(u)
40
end
41
initial_condition = initial_condition_eriksson_johnson
42
43
boundary_conditions = (; x_neg = BoundaryConditionDirichlet(initial_condition),
44
y_neg = BoundaryConditionDirichlet(initial_condition),
45
y_pos = BoundaryConditionDirichlet(initial_condition),
46
x_pos = boundary_condition_do_nothing)
47
48
boundary_conditions_parabolic = BoundaryConditionDirichlet(initial_condition)
49
50
# A semidiscretization collects data structures and functions for the spatial discretization
51
semi = SemidiscretizationHyperbolicParabolic(mesh,
52
(equations, equations_parabolic),
53
initial_condition, solver;
54
solver_parabolic = ParabolicFormulationBassiRebay1(),
55
boundary_conditions = (boundary_conditions,
56
boundary_conditions_parabolic))
57
58
###############################################################################
59
# ODE solvers, callbacks etc.
60
61
# Create ODE problem with time span `tspan`
62
tspan = (0.0, 1.5)
63
ode = semidiscretize(semi, tspan)
64
65
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
66
# and resets the timers
67
summary_callback = SummaryCallback()
68
69
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
70
analysis_interval = 100
71
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
72
73
# The AliveCallback prints short status information in regular intervals
74
alive_callback = AliveCallback(analysis_interval = analysis_interval)
75
76
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
77
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback)
78
79
###############################################################################
80
# run the simulation
81
82
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
83
time_int_tol = 1.0e-11
84
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
85
ode_default_options()..., callback = callbacks)
86
87