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
2055 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
# Create a uniformly refined mesh with periodic boundaries
19
mesh = TreeMesh(coordinates_min, coordinates_max,
20
initial_refinement_level = 4,
21
periodicity = false,
22
n_cells_max = 30_000) # set maximum capacity of tree data structure
23
24
# Example setup taken from
25
# - Truman Ellis, Jesse Chan, and Leszek Demkowicz (2016).
26
# Robust DPG methods for transient convection-diffusion.
27
# In: Building bridges: connections and challenges in modern approaches
28
# to numerical partial differential equations.
29
# [DOI](https://doi.org/10.1007/978-3-319-41640-3_6).
30
function initial_condition_eriksson_johnson(x, t, equations)
31
RealT = eltype(x)
32
l = 4
33
epsilon = diffusivity() # TODO: this requires epsilon < .6 due to sqrt
34
lambda_1 = (-1 + sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
35
lambda_2 = (-1 - sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
36
r1 = (1 + sqrt(1 + 4 * convert(RealT, pi)^2 * epsilon^2)) / (2 * epsilon)
37
s1 = (1 - sqrt(1 + 4 * convert(RealT, pi)^2 * epsilon^2)) / (2 * epsilon)
38
u = exp(-l * t) * (exp(lambda_1 * x[1]) - exp(lambda_2 * x[1])) +
39
cospi(x[2]) * (exp(s1 * x[1]) - exp(r1 * x[1])) / (exp(-s1) - exp(-r1))
40
return SVector{1}(u)
41
end
42
initial_condition = initial_condition_eriksson_johnson
43
44
boundary_conditions = (; x_neg = BoundaryConditionDirichlet(initial_condition),
45
y_neg = BoundaryConditionDirichlet(initial_condition),
46
y_pos = BoundaryConditionDirichlet(initial_condition),
47
x_pos = boundary_condition_do_nothing)
48
49
boundary_conditions_parabolic = BoundaryConditionDirichlet(initial_condition)
50
51
# A semidiscretization collects data structures and functions for the spatial discretization
52
semi = SemidiscretizationHyperbolicParabolic(mesh,
53
(equations, equations_parabolic),
54
initial_condition, solver;
55
solver_parabolic = ViscousFormulationBassiRebay1(),
56
boundary_conditions = (boundary_conditions,
57
boundary_conditions_parabolic))
58
59
###############################################################################
60
# ODE solvers, callbacks etc.
61
62
# Create ODE problem with time span `tspan`
63
tspan = (0.0, 1.5)
64
ode = semidiscretize(semi, tspan)
65
66
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
67
# and resets the timers
68
summary_callback = SummaryCallback()
69
70
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
71
analysis_interval = 100
72
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
73
74
# The AliveCallback prints short status information in regular intervals
75
alive_callback = AliveCallback(analysis_interval = analysis_interval)
76
77
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
78
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback)
79
80
###############################################################################
81
# run the simulation
82
83
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
84
time_int_tol = 1.0e-11
85
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
86
ode_default_options()..., callback = callbacks)
87
88