Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/equations/traffic_flow_lwr_1d.jl
2055 views
1
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
2
# Since these FMAs can increase the performance of many numerical algorithms,
3
# we need to opt-in explicitly.
4
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
5
@muladd begin
6
#! format: noindent
7
8
@doc raw"""
9
TrafficFlowLWREquations1D
10
11
The classic Lighthill-Witham Richards (LWR) model for 1D traffic flow.
12
The car density is denoted by $u \in [0, 1]$ and
13
the maximum possible speed (e.g. due to speed limits) is $v_{\text{max}}$.
14
```math
15
\partial_t u + v_{\text{max}} \partial_1 [u (1 - u)] = 0
16
```
17
For more details see e.g. Section 11.1 of
18
- Randall LeVeque (2002)
19
Finite Volume Methods for Hyperbolic Problems
20
[DOI: 10.1017/CBO9780511791253](https://doi.org/10.1017/CBO9780511791253)
21
"""
22
struct TrafficFlowLWREquations1D{RealT <: Real} <: AbstractTrafficFlowLWREquations{1, 1}
23
v_max::RealT
24
25
function TrafficFlowLWREquations1D(v_max = 1.0)
26
new{typeof(v_max)}(v_max)
27
end
28
end
29
30
varnames(::typeof(cons2cons), ::TrafficFlowLWREquations1D) = ("car-density",)
31
varnames(::typeof(cons2prim), ::TrafficFlowLWREquations1D) = ("car-density",)
32
33
"""
34
initial_condition_convergence_test(x, t, equations::TrafficFlowLWREquations1D)
35
36
A smooth initial condition used for convergence tests.
37
"""
38
function initial_condition_convergence_test(x, t, equations::TrafficFlowLWREquations1D)
39
RealT = eltype(x)
40
c = 2
41
A = 1
42
L = 1
43
f = 1.0f0 / L
44
omega = 2 * convert(RealT, pi) * f
45
scalar = c + A * sin(omega * (x[1] - t))
46
47
return SVector(scalar)
48
end
49
50
"""
51
source_terms_convergence_test(u, x, t, equations::TrafficFlowLWREquations1D)
52
53
Source terms used for convergence tests in combination with
54
[`initial_condition_convergence_test`](@ref).
55
"""
56
@inline function source_terms_convergence_test(u, x, t,
57
equations::TrafficFlowLWREquations1D)
58
# Same settings as in `initial_condition`
59
RealT = eltype(x)
60
c = 2
61
A = 1
62
L = 1
63
f = 1.0f0 / L
64
omega = 2 * convert(RealT, pi) * f
65
du = omega * cos(omega * (x[1] - t)) *
66
(-1 - equations.v_max * (2 * sin(omega * (x[1] - t)) + 3))
67
68
return SVector(du)
69
end
70
71
# Calculate 1D flux for a single point
72
@inline function flux(u, orientation::Integer, equations::TrafficFlowLWREquations1D)
73
return SVector(equations.v_max * u[1] * (1 - u[1]))
74
end
75
76
# Calculate maximum wave speed for local Lax-Friedrichs-type dissipation
77
@inline function max_abs_speed_naive(u_ll, u_rr, orientation::Integer,
78
equations::TrafficFlowLWREquations1D)
79
return max(abs(equations.v_max * (1 - 2 * u_ll[1])),
80
abs(equations.v_max * (1 - 2 * u_rr[1])))
81
end
82
83
# Calculate minimum and maximum wave speeds for HLL-type fluxes
84
@inline function min_max_speed_naive(u_ll, u_rr, orientation::Integer,
85
equations::TrafficFlowLWREquations1D)
86
jac_L = equations.v_max * (1 - 2 * u_ll[1])
87
jac_R = equations.v_max * (1 - 2 * u_rr[1])
88
89
λ_min = min(jac_L, jac_R)
90
λ_max = max(jac_L, jac_R)
91
92
return λ_min, λ_max
93
end
94
95
@inline function min_max_speed_davis(u_ll, u_rr, orientation::Integer,
96
equations::TrafficFlowLWREquations1D)
97
min_max_speed_naive(u_ll, u_rr, orientation, equations)
98
end
99
100
@inline function max_abs_speeds(u, equations::TrafficFlowLWREquations1D)
101
return (abs(equations.v_max * (1 - 2 * u[1])),)
102
end
103
104
# Convert conservative variables to primitive
105
@inline cons2prim(u, equations::TrafficFlowLWREquations1D) = u
106
107
# Convert conservative variables to entropy variables
108
@inline cons2entropy(u, equations::TrafficFlowLWREquations1D) = u
109
110
# Calculate entropy for a conservative state `cons`
111
@inline entropy(u::Real, ::TrafficFlowLWREquations1D) = 0.5f0 * u^2
112
@inline entropy(u, equations::TrafficFlowLWREquations1D) = entropy(u[1], equations)
113
114
# Calculate total energy for a conservative state `cons`
115
@inline energy_total(u::Real, ::TrafficFlowLWREquations1D) = 0.5f0 * u^2
116
@inline energy_total(u, equations::TrafficFlowLWREquations1D) = energy_total(u[1],
117
equations)
118
end # @muladd
119
120