Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/equations/maxwell_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
MaxwellEquations1D(c = 299_792_458.0)
10
11
The Maxwell equations of electro dynamics
12
```math
13
\frac{\partial}{\partial t}
14
\begin{pmatrix}
15
E \\ B
16
\end{pmatrix}
17
+
18
\frac{\partial}{\partial x}
19
\begin{pmatrix}
20
c^2 B \\ E
21
\end{pmatrix}
22
=
23
\begin{pmatrix}
24
0 \\ 0
25
\end{pmatrix}
26
```
27
in one dimension with speed of light `c = 299792458 m/s` (in vacuum).
28
In one dimension the Maxwell equations reduce to a wave equation.
29
The orthogonal magnetic (e.g.`B_y`) and electric field (`E_z`) propagate as waves
30
through the domain in `x`-direction.
31
For reference, see
32
- e.g. p.15 of Numerical Methods for Conservation Laws: From Analysis to Algorithms
33
https://doi.org/10.1137/1.9781611975109
34
35
- or equation (1) in https://inria.hal.science/hal-01720293/document
36
"""
37
struct MaxwellEquations1D{RealT <: Real} <: AbstractMaxwellEquations{1, 2}
38
speed_of_light::RealT # c
39
40
function MaxwellEquations1D(c::Real = 299_792_458.0)
41
new{typeof(c)}(c)
42
end
43
end
44
45
function varnames(::typeof(cons2cons), ::MaxwellEquations1D)
46
("E", "B")
47
end
48
function varnames(::typeof(cons2prim), ::MaxwellEquations1D)
49
("E", "B")
50
end
51
52
"""
53
initial_condition_convergence_test(x, t, equations::MaxwellEquations1D)
54
55
A smooth initial condition used for convergence tests.
56
"""
57
function initial_condition_convergence_test(x, t, equations::MaxwellEquations1D)
58
c = equations.speed_of_light
59
char_pos = c * t + x[1]
60
61
sin_char_pos = sinpi(2 * char_pos)
62
63
E = -c * sin_char_pos
64
B = sin_char_pos
65
66
return SVector(E, B)
67
end
68
69
# Calculate 1D flux for a single point
70
@inline function flux(u, orientation::Integer,
71
equations::MaxwellEquations1D)
72
E, B = u
73
return SVector(equations.speed_of_light^2 * B, E)
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::Int,
78
equations::MaxwellEquations1D)
79
return equations.speed_of_light
80
end
81
82
@inline have_constant_speed(::MaxwellEquations1D) = True()
83
84
@inline function max_abs_speeds(equations::MaxwellEquations1D)
85
return equations.speed_of_light
86
end
87
88
@inline function min_max_speed_naive(u_ll, u_rr, orientation::Integer,
89
equations::MaxwellEquations1D)
90
min_max_speed_davis(u_ll, u_rr, orientation, equations)
91
end
92
93
@inline function min_max_speed_davis(u_ll, u_rr, orientation::Integer,
94
equations::MaxwellEquations1D)
95
λ_min = -equations.speed_of_light
96
λ_max = equations.speed_of_light
97
98
return λ_min, λ_max
99
end
100
101
# Convert conservative variables to primitive
102
@inline cons2prim(u, ::MaxwellEquations1D) = u
103
@inline cons2entropy(u, ::MaxwellEquations1D) = u
104
end # @muladd
105
106