|
| 1 | +using OrdinaryDiffEqSSPRK |
| 2 | +using OrdinaryDiffEqCore: PIDController |
| 3 | +using Trixi |
| 4 | + |
| 5 | +############################################################################### |
| 6 | +# semidiscretization of the compressible Euler equations |
| 7 | + |
| 8 | +equations = CompressibleEulerEquations1D(1.4) |
| 9 | + |
| 10 | +# Shu-Osher initial condition for 1D compressible Euler equations |
| 11 | +# Example 8 from Shu, Osher (1989). |
| 12 | +# https://doi.org/10.1016/0021-9991(89)90222-2 |
| 13 | +function initial_condition_shu_osher(x, t, equations::CompressibleEulerEquations1D) |
| 14 | + x0 = -4 |
| 15 | + |
| 16 | + rho_left = 27 / 7 |
| 17 | + v_left = 4 * sqrt(35) / 9 |
| 18 | + p_left = 31 / 3 |
| 19 | + |
| 20 | + v_right = 0.0 |
| 21 | + p_right = 1.0 |
| 22 | + |
| 23 | + rho = ifelse(x[1] > x0, 1 + 1 / 5 * sin(5 * x[1]), rho_left) |
| 24 | + v = ifelse(x[1] > x0, v_right, v_left) |
| 25 | + p = ifelse(x[1] > x0, p_right, p_left) |
| 26 | + |
| 27 | + return prim2cons(SVector(rho, v, p), equations) |
| 28 | +end |
| 29 | + |
| 30 | +initial_condition = initial_condition_shu_osher |
| 31 | + |
| 32 | +surface_flux = flux_hllc |
| 33 | +polydeg = 3 # governs in this case only the number of FV subcells per DG cell |
| 34 | +basis = LobattoLegendreBasis(polydeg) |
| 35 | +volume_integral = VolumeIntegralPureLGLFiniteVolumeO2(basis, |
| 36 | + volume_flux_fv = surface_flux, |
| 37 | + reconstruction_mode = reconstruction_O2_inner, |
| 38 | + slope_limiter = monotonized_central) |
| 39 | +solver = DGSEM(polydeg = polydeg, surface_flux = surface_flux, |
| 40 | + volume_integral = volume_integral) |
| 41 | + |
| 42 | +function refined_mapping(xi) |
| 43 | + fine_fraction = 0.8 |
| 44 | + a_fine = 4.0 |
| 45 | + x_max = 5.0 |
| 46 | + |
| 47 | + # Compute the value at the boundary for continuity |
| 48 | + x_boundary = a_fine * fine_fraction |
| 49 | + # Slope for the outer region |
| 50 | + a_outer = (x_max - x_boundary) / (1 - fine_fraction) |
| 51 | + if abs(xi) <= fine_fraction |
| 52 | + x = a_fine * xi |
| 53 | + else |
| 54 | + x = x_boundary + a_outer * (abs(xi) - fine_fraction) |
| 55 | + x *= sign(xi) |
| 56 | + end |
| 57 | + return x |
| 58 | +end |
| 59 | + |
| 60 | +cells_per_dimension = (128,) |
| 61 | +mesh = StructuredMesh(cells_per_dimension, refined_mapping, periodicity = false) |
| 62 | + |
| 63 | +boundary_condition = BoundaryConditionDirichlet(initial_condition) |
| 64 | +boundary_conditions = boundary_condition_default(mesh, boundary_condition) |
| 65 | + |
| 66 | +semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, |
| 67 | + boundary_conditions = boundary_conditions) |
| 68 | + |
| 69 | +############################################################################### |
| 70 | +# ODE solvers, callbacks etc. |
| 71 | + |
| 72 | +tspan = (0.0, 2.0) |
| 73 | +ode = semidiscretize(semi, tspan) |
| 74 | + |
| 75 | +summary_callback = SummaryCallback() |
| 76 | + |
| 77 | +analysis_interval = 1000 |
| 78 | +analysis_callback = AnalysisCallback(semi, interval = analysis_interval) |
| 79 | + |
| 80 | +alive_callback = AliveCallback(analysis_interval = analysis_interval) |
| 81 | + |
| 82 | +callbacks = CallbackSet(summary_callback, |
| 83 | + analysis_callback, |
| 84 | + alive_callback) |
| 85 | + |
| 86 | +############################################################################### |
| 87 | +# run the simulation |
| 88 | + |
| 89 | +# Solve ODE with optimized timestep controller from https://doi.org/10.1007/s42967-021-00159-w |
| 90 | +sol = solve(ode, SSPRK43(); |
| 91 | + controller = PIDController(0.55, -0.27, 0.05), |
| 92 | + abstol = 1e-4, reltol = 1e-4, |
| 93 | + callback = callbacks, ode_default_options()...) |
0 commit comments