Path: blob/main/examples/tree_1d_dgsem/elixir_maxwell_E_excitation.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56equations = MaxwellEquations1D()78solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)910coordinates_min = 0.011coordinates_max = 1.01213# Create a uniformly refined mesh with periodic boundaries14mesh = TreeMesh(coordinates_min, coordinates_max,15initial_refinement_level = 4,16n_cells_max = 30_000) # set maximum capacity of tree data structure1718# Excite the electric field which causes a standing wave.19# The solution is an undamped exchange between electric and magnetic energy.20function initial_condition_E_excitation(x, t, equations::MaxwellEquations1D)21RealT = eltype(x)22c = equations.speed_of_light23E = -c * sinpi(2 * x[1])24B = 02526return SVector(E, B)27end2829initial_condition = initial_condition_E_excitation30semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)3132###############################################################################33# ODE solvers, callbacks etc.3435# As the wave speed is equal to the speed of light which is on the order of 3 * 10^836# we consider only a small time horizon.37ode = semidiscretize(semi, (0.0, 1e-7))3839summary_callback = SummaryCallback()4041# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results42analysis_callback = AnalysisCallback(semi, interval = 100)4344# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step45stepsize_callback = StepsizeCallback(cfl = 1.6)4647# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver48callbacks = CallbackSet(summary_callback, analysis_callback, stepsize_callback)4950###############################################################################51# run the simulation5253sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);54dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback55ode_default_options()..., callback = callbacks);565758