Path: blob/main/examples/structured_1d_dgsem/elixir_advection_shockcapturing.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56advection_velocity = 1.078"""9initial_condition_composite(x, t, equations::LinearScalarAdvectionEquation1D)1011Wave form that is a combination of a Gaussian pulse, a square wave, a triangle wave,12and half an ellipse with periodic boundary conditions.13Slight simplification from14- Jiang, Shu (1996)15Efficient Implementation of Weighted ENO Schemes16[DOI: 10.1006/jcph.1996.0130](https://doi.org/10.1006/jcph.1996.0130)17"""18function initial_condition_composite(x, t, equations::LinearScalarAdvectionEquation1D)19xmin, xmax = -1.0, 1.0 # Only works if the domain is [-1.0,1.0]20x_trans = x[1] - t21L = xmax - xmin22if x_trans > xmax23x_ = x_trans - L * floor((x_trans + xmin) / L)24elseif x_trans < xmin25x_ = x_trans + L * floor((xmax - x_trans) / L)26else27x_ = x_trans28end2930if x_ > -0.8 && x_ < -0.631value = exp(-log(2.0) * (x_ + 0.7)^2 / 0.0009)32elseif x_ > -0.4 && x_ < -0.233value = 1.034elseif x_ > 0.0 && x_ < 0.235value = 1.0 - abs(10.0 * (x_ - 0.1))36elseif x_ > 0.4 && x_ < 0.637value = sqrt(1.0 - 100.0 * (x_ - 0.5)^2)38else39value = 0.040end4142return SVector(value)43end4445initial_condition = initial_condition_composite4647equations = LinearScalarAdvectionEquation1D(advection_velocity)4849surface_flux = flux_lax_friedrichs50volume_flux = flux_central51polydeg = 352basis = LobattoLegendreBasis(polydeg)53indicator_sc = IndicatorHennemannGassner(equations, basis,54alpha_max = 0.5,55alpha_min = 0.001,56alpha_smooth = true,57variable = Trixi.first)58volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;59volume_flux_dg = volume_flux,60volume_flux_fv = surface_flux)61solver = DGSEM(basis, surface_flux, volume_integral)6263# Create curved mesh64cells_per_dimension = (120,)65coordinates_min = (-1.0,) # minimum coordinate66coordinates_max = (1.0,) # maximum coordinate67mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max,68periodicity = true)6970# A semidiscretization collects data structures and functions for the spatial discretization71semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)7273###############################################################################74# ODE solvers, callbacks etc.7576# Create ODE problem with a given time span77tspan = (0.0, 4.0)78ode = semidiscretize(semi, tspan)7980# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup81# and resets the timers82summary_callback = SummaryCallback()8384# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results85analysis_callback = AnalysisCallback(semi, interval = 100)8687# The SaveSolutionCallback allows to save the solution to a file in regular intervals88save_solution = SaveSolutionCallback(interval = 100, solution_variables = cons2prim)8990# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step91stepsize_callback = StepsizeCallback(cfl = 0.5)9293# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver94callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,95stepsize_callback)9697###############################################################################98# run the simulation99100# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks101sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);102dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback103ode_default_options()..., callback = callbacks);104105106