|
| 1 | +using LibTrixi |
| 2 | +using OrdinaryDiffEq |
| 3 | +using Trixi |
| 4 | + |
| 5 | +# The function to create the simulation state needs to be named `init_simstate` |
| 6 | +function init_simstate() |
| 7 | + |
| 8 | + ############################################################################### |
| 9 | + # semidiscretization of the linear advection equation |
| 10 | + |
| 11 | + advection_velocity = (0.2, -0.7) |
| 12 | + equations = LinearScalarAdvectionEquation2D(advection_velocity) |
| 13 | + |
| 14 | + # Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux |
| 15 | + solver = DGSEM(polydeg=3, surface_flux=flux_lax_friedrichs) |
| 16 | + |
| 17 | + coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y)) |
| 18 | + coordinates_max = ( 1.0, 1.0) # maximum coordinates (max(x), max(y)) |
| 19 | + |
| 20 | + mapping = Trixi.coordinates2mapping(coordinates_min, coordinates_max) |
| 21 | + |
| 22 | + trees_per_dimension = (4, 4) |
| 23 | + |
| 24 | + mesh = T8codeMesh(trees_per_dimension, polydeg=3, |
| 25 | + mapping=mapping, |
| 26 | + initial_refinement_level=1) |
| 27 | + |
| 28 | + # A semidiscretization collects data structures and functions for the spatial discretization |
| 29 | + semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test, solver) |
| 30 | + |
| 31 | + |
| 32 | + ############################################################################### |
| 33 | + # ODE solvers, callbacks etc. |
| 34 | + |
| 35 | + # Create ODE problem with time span from 0.0 to 1.0 |
| 36 | + ode = semidiscretize(semi, (0.0, 1.0)); |
| 37 | + |
| 38 | + # At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup |
| 39 | + # and resets the timers |
| 40 | + summary_callback = SummaryCallback() |
| 41 | + |
| 42 | + # The AnalysisCallback allows to analyse the solution in regular intervals and prints the results |
| 43 | + analysis_interval = 100 |
| 44 | + analysis_callback = AnalysisCallback(semi, interval=analysis_interval) |
| 45 | + |
| 46 | + alive_callback = AliveCallback(analysis_interval=analysis_interval) |
| 47 | + |
| 48 | + # The StepsizeCallback handles the re-calculation of the maximum Δt after each time step |
| 49 | + stepsize_callback = StepsizeCallback(cfl=0.5) |
| 50 | + |
| 51 | + # Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver |
| 52 | + callbacks = CallbackSet(summary_callback, |
| 53 | + analysis_callback, |
| 54 | + alive_callback, |
| 55 | + stepsize_callback) |
| 56 | + |
| 57 | + |
| 58 | + ############################################################################### |
| 59 | + # create the time integrator |
| 60 | + |
| 61 | + # OrdinaryDiffEq's `integrator` |
| 62 | + integrator = init(ode, CarpenterKennedy2N54(williamson_condition=false), |
| 63 | + dt=1.0, # solve needs some value here but it will be overwritten by the stepsize_callback |
| 64 | + save_everystep=false, callback=callbacks); |
| 65 | + |
| 66 | + ############################################################################### |
| 67 | + # Create simulation state |
| 68 | + |
| 69 | + simstate = SimulationState(semi, integrator) |
| 70 | + |
| 71 | + return simstate |
| 72 | +end |
0 commit comments