|
| 1 | + |
| 2 | +using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK |
| 3 | +using Trixi |
| 4 | + |
| 5 | +# Warm bubble test case from |
| 6 | +# - Wicker, L. J., and Skamarock, W. C. (1998) |
| 7 | +# A time-splitting scheme for the elastic equations incorporating |
| 8 | +# second-order Runge–Kutta time differencing |
| 9 | +# [DOI: 10.1175/1520-0493(1998)126%3C1992:ATSSFT%3E2.0.CO;2](https://doi.org/10.1175/1520-0493(1998)126%3C1992:ATSSFT%3E2.0.CO;2) |
| 10 | +# See also |
| 11 | +# - Bryan and Fritsch (2002) |
| 12 | +# A Benchmark Simulation for Moist Nonhydrostatic Numerical Models |
| 13 | +# [DOI: 10.1175/1520-0493(2002)130<2917:ABSFMN>2.0.CO;2](https://doi.org/10.1175/1520-0493(2002)130<2917:ABSFMN>2.0.CO;2) |
| 14 | +# - Carpenter, Droegemeier, Woodward, Hane (1990) |
| 15 | +# Application of the Piecewise Parabolic Method (PPM) to |
| 16 | +# Meteorological Modeling |
| 17 | +# [DOI: 10.1175/1520-0493(1990)118<0586:AOTPPM>2.0.CO;2](https://doi.org/10.1175/1520-0493(1990)118<0586:AOTPPM>2.0.CO;2) |
| 18 | +struct WarmBubbleSetup |
| 19 | + # Physical constants |
| 20 | + g::Float64 # gravity of earth |
| 21 | + c_p::Float64 # heat capacity for constant pressure (dry air) |
| 22 | + c_v::Float64 # heat capacity for constant volume (dry air) |
| 23 | + gamma::Float64 # heat capacity ratio (dry air) |
| 24 | + |
| 25 | + function WarmBubbleSetup(; g = 9.81, c_p = 1004.0, c_v = 717.0, gamma = c_p / c_v) |
| 26 | + new(g, c_p, c_v, gamma) |
| 27 | + end |
| 28 | +end |
| 29 | + |
| 30 | +# Initial condition |
| 31 | +function (setup::WarmBubbleSetup)(x, t, equations::CompressibleEulerEquationsWithGravity2D) |
| 32 | + RealT = eltype(x) |
| 33 | + @unpack g, c_p, c_v = setup |
| 34 | + |
| 35 | + # center of perturbation |
| 36 | + center_x = 10000 |
| 37 | + center_z = 2000 |
| 38 | + # radius of perturbation |
| 39 | + radius = 2000 |
| 40 | + # distance of current x to center of perturbation |
| 41 | + r = sqrt((x[1] - center_x)^2 + (x[2] - center_z)^2) |
| 42 | + |
| 43 | + # perturbation in potential temperature |
| 44 | + potential_temperature_ref = 300 |
| 45 | + potential_temperature_perturbation = zero(RealT) |
| 46 | + if r <= radius |
| 47 | + potential_temperature_perturbation = 2 * cospi(0.5f0 * r / radius)^2 |
| 48 | + end |
| 49 | + potential_temperature = potential_temperature_ref + potential_temperature_perturbation |
| 50 | + |
| 51 | + # Exner pressure, solves hydrostatic equation for x[2] |
| 52 | + exner = 1 - g / (c_p * potential_temperature) * x[2] |
| 53 | + |
| 54 | + # pressure |
| 55 | + p_0 = 100_000 # reference pressure |
| 56 | + R = c_p - c_v # gas constant (dry air) |
| 57 | + p = p_0 * exner^(c_p / R) |
| 58 | + |
| 59 | + # temperature |
| 60 | + T = potential_temperature * exner |
| 61 | + # T = potential_temperature - g / (c_p) * x[2] |
| 62 | + |
| 63 | + # density |
| 64 | + rho = p / (R * T) |
| 65 | + |
| 66 | + # Geopotential |
| 67 | + phi = g * x[2] |
| 68 | + |
| 69 | + v1 = 20 |
| 70 | + v2 = 0 |
| 71 | + E = c_v * T + 0.5f0 * (v1^2 + v2^2) + phi |
| 72 | + return SVector(rho, rho * v1, rho * v2, rho * E, phi) |
| 73 | +end |
| 74 | + |
| 75 | +############################################################################### |
| 76 | +# semidiscretization of the compressible Euler equations |
| 77 | +warm_bubble_setup = WarmBubbleSetup() |
| 78 | + |
| 79 | +equations = CompressibleEulerEquationsWithGravity2D(warm_bubble_setup.gamma) |
| 80 | + |
| 81 | +initial_condition = warm_bubble_setup |
| 82 | + |
| 83 | +volume_flux = (flux_kennedy_gruber, flux_nonconservative_waruszewski) |
| 84 | +surface_flux = (FluxLMARS(340.0), flux_nonconservative_waruszewski) |
| 85 | + |
| 86 | +polydeg = 3 |
| 87 | +solver = DGSEM(polydeg = polydeg, surface_flux = surface_flux, |
| 88 | + volume_integral = VolumeIntegralFluxDifferencing(volume_flux)) |
| 89 | + |
| 90 | +coordinates_min = (0.0, -5000.0) |
| 91 | +coordinates_max = (20_000.0, 15_000.0) |
| 92 | +mesh = TreeMesh(coordinates_min, coordinates_max, |
| 93 | + initial_refinement_level = 6, |
| 94 | + n_cells_max = 10_000, |
| 95 | + periodicity = (true, false)) |
| 96 | + |
| 97 | +boundary_conditions = (; x_neg = boundary_condition_periodic, |
| 98 | + x_pos = boundary_condition_periodic, |
| 99 | + y_neg = boundary_condition_slip_wall, |
| 100 | + y_pos = boundary_condition_slip_wall) |
| 101 | + |
| 102 | +semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, |
| 103 | + boundary_conditions = boundary_conditions) |
| 104 | + |
| 105 | +############################################################################### |
| 106 | +# ODE solvers, callbacks etc. |
| 107 | + |
| 108 | +tspan = (0.0, 1000.0) # 1000 seconds final time |
| 109 | +ode = semidiscretize(semi, tspan) |
| 110 | + |
| 111 | +summary_callback = SummaryCallback() |
| 112 | + |
| 113 | +analysis_interval = 100 |
| 114 | +analysis_callback = AnalysisCallback(semi, interval = analysis_interval, |
| 115 | + analysis_polydeg = polydeg) |
| 116 | + |
| 117 | +alive_callback = AliveCallback(analysis_interval = analysis_interval) |
| 118 | + |
| 119 | +save_solution = SaveSolutionCallback(dt = 10.0, #interval = 1, #dt = 10.0, |
| 120 | + save_initial_solution = true, |
| 121 | + save_final_solution = true, |
| 122 | + solution_variables = cons2prim) |
| 123 | + |
| 124 | +stepsize_callback = StepsizeCallback(cfl = 1.0) |
| 125 | + |
| 126 | +callbacks = CallbackSet(summary_callback, |
| 127 | + analysis_callback, alive_callback, |
| 128 | + save_solution, |
| 129 | + stepsize_callback) |
| 130 | + |
| 131 | +############################################################################### |
| 132 | +# run the simulation |
| 133 | + |
| 134 | +sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false), |
| 135 | + dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback |
| 136 | + save_everystep = false, callback = callbacks); |
0 commit comments