Path: blob/main/examples/tree_2d_dgsem/elixir_acoustics_monopole.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the acoustic perturbation equations56equations = AcousticPerturbationEquations2D(v_mean_global = (0.0, 0.0), c_mean_global = 0.0,7rho_mean_global = 0.0)89# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux1011# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of12# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.13# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.14# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.15# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.16# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the17# `StepsizeCallback` (CFL-Condition) and less diffusion.18solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive))1920coordinates_min = (-20.6, 0.0) # minimum coordinates (min(x), min(y))21coordinates_max = (30.6, 51.2) # maximum coordinates (max(x), max(y))2223"""24initial_condition_monopole(x, t, equations::AcousticPerturbationEquations2D)2526Initial condition for the monopole in a boundary layer setup, used in combination with27[`boundary_condition_monopole`](@ref).28"""29function initial_condition_monopole(x, t, equations::AcousticPerturbationEquations2D)30RealT = eltype(x)31m = convert(RealT, 0.3) # Mach number3233v1_prime = 034v2_prime = 035p_prime = 03637v1_mean = x[2] > 1 ? m : m * (2 * x[2] - 2 * x[2]^2 + x[2]^4)38v2_mean = 039c_mean = 140rho_mean = 14142prim = SVector(v1_prime, v2_prime, p_prime, v1_mean, v2_mean, c_mean, rho_mean)4344return prim2cons(prim, equations)45end46initial_condition = initial_condition_monopole # does not use the global mean values given above4748"""49boundary_condition_monopole(u_inner, orientation, direction, x, t, surface_flux_function,50equations::AcousticPerturbationEquations2D)5152Boundary condition for a monopole in a boundary layer at the -y boundary, i.e. `direction = 3`.53This will return an error for any other direction. This boundary condition is used in combination54with [`initial_condition_monopole`](@ref).55"""56function boundary_condition_monopole(u_inner, orientation, direction, x, t,57surface_flux_function,58equations::AcousticPerturbationEquations2D)59RealT = eltype(u_inner)60if direction != 361error("expected direction = 3, got $direction instead")62end6364# Wall at the boundary in -y direction with a monopole at -0.05 <= x <= 0.05. In the monopole area65# we use a sinusoidal boundary state for the perturbed variables. For the rest of the -y boundary66# we set the boundary state to the inner state and multiply the perturbed velocity in the67# y-direction by -1.68if RealT(-0.05) <= x[1] <= RealT(0.05) # Monopole69v1_prime = 070v2_prime = p_prime = sinpi(2 * t)7172prim_boundary = SVector(v1_prime, v2_prime, p_prime, u_inner[4], u_inner[5],73u_inner[6], u_inner[7])7475u_boundary = prim2cons(prim_boundary, equations)76else # Wall77u_boundary = SVector(u_inner[1], -u_inner[2], u_inner[3], u_inner[4], u_inner[5],78u_inner[6],79u_inner[7])80end8182# Calculate boundary flux83flux = surface_flux_function(u_boundary, u_inner, orientation, equations)8485return flux86end8788"""89boundary_condition_zero(u_inner, orientation, direction, x, t, surface_flux_function,90equations::AcousticPerturbationEquations2D)9192Boundary condition that uses a boundary state where the state variables are zero and the mean93variables are the same as in `u_inner`.94"""95function boundary_condition_zero(u_inner, orientation, direction, x, t,96surface_flux_function,97equations::AcousticPerturbationEquations2D)98value = zero(eltype(u_inner))99u_boundary = SVector(value, value, value, cons2mean(u_inner, equations)...)100101# Calculate boundary flux102if iseven(direction) # u_inner is "left" of boundary, u_boundary is "right" of boundary103flux = surface_flux_function(u_inner, u_boundary, orientation, equations)104else # u_boundary is "left" of boundary, u_inner is "right" of boundary105flux = surface_flux_function(u_boundary, u_inner, orientation, equations)106end107108return flux109end110111boundary_conditions = (x_neg = boundary_condition_zero,112x_pos = boundary_condition_zero,113y_neg = boundary_condition_monopole,114y_pos = boundary_condition_zero)115116# Create a uniformly refined mesh with periodic boundaries117mesh = TreeMesh(coordinates_min, coordinates_max,118initial_refinement_level = 6,119n_cells_max = 100_000,120periodicity = false)121122# A semidiscretization collects data structures and functions for the spatial discretization123semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,124boundary_conditions = boundary_conditions)125126###############################################################################127# ODE solvers, callbacks etc.128129# Create ODE problem with time span from 0.0 to 24.0130tspan = (0.0, 24.0)131ode = semidiscretize(semi, tspan)132133# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup134# and resets the timers135summary_callback = SummaryCallback()136137# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results138analysis_callback = AnalysisCallback(semi, interval = 100)139140# The SaveSolutionCallback allows to save the solution to a file in regular intervals141save_solution = SaveSolutionCallback(interval = 100, solution_variables = cons2prim)142143# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step144stepsize_callback = StepsizeCallback(cfl = 0.8)145146# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver147callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,148stepsize_callback)149150###############################################################################151# run the simulation152153# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks154sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);155dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback156ode_default_options()..., callback = callbacks)157158159