Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_1d_dgsem/elixir_maxwell_E_excitation.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear advection equation
6
7
equations = MaxwellEquations1D()
8
9
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
10
11
coordinates_min = 0.0
12
coordinates_max = 1.0
13
14
# Create a uniformly refined mesh with periodic boundaries
15
mesh = TreeMesh(coordinates_min, coordinates_max,
16
initial_refinement_level = 4,
17
n_cells_max = 30_000) # set maximum capacity of tree data structure
18
19
# Excite the electric field which causes a standing wave.
20
# The solution is an undamped exchange between electric and magnetic energy.
21
function initial_condition_E_excitation(x, t, equations::MaxwellEquations1D)
22
RealT = eltype(x)
23
c = equations.speed_of_light
24
E = -c * sinpi(2 * x[1])
25
B = 0
26
27
return SVector(E, B)
28
end
29
30
initial_condition = initial_condition_E_excitation
31
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
32
33
###############################################################################
34
# ODE solvers, callbacks etc.
35
36
# As the wave speed is equal to the speed of light which is on the order of 3 * 10^8
37
# we consider only a small time horizon.
38
ode = semidiscretize(semi, (0.0, 1e-7))
39
40
summary_callback = SummaryCallback()
41
42
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
43
analysis_callback = AnalysisCallback(semi, interval = 100)
44
45
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
46
stepsize_callback = StepsizeCallback(cfl = 1.6)
47
48
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
49
callbacks = CallbackSet(summary_callback, analysis_callback, stepsize_callback)
50
51
###############################################################################
52
# run the simulation
53
54
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
55
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
56
ode_default_options()..., callback = callbacks);
57
58