Path: blob/main/examples/p4est_2d_dgsem/elixir_euler_NACA0012airfoil_mach085.jl
2055 views
using OrdinaryDiffEqSSPRK1using Trixi23###############################################################################4# semidiscretization of the compressible Euler equations56equations = CompressibleEulerEquations2D(1.4)78p_inf() = 1.09rho_inf() = p_inf() / (1.0 * 287.87) # p_inf = 1.0, T = 1, R = 287.8710mach_inf() = 0.8511aoa() = pi / 180.0 # 1 Degree angle of attack12c_inf(equations) = sqrt(equations.gamma * p_inf() / rho_inf())13u_inf(equations) = mach_inf() * c_inf(equations)1415# Leave `equations` unspecified here to enable usage of `BoundaryConditionDirichlet(initial_condition)`16# in the "elixir_navierstokes_NACA0012airfoil_mach085_restart.jl" which includes this elixir to17# demonstrate restarting/initializing a hyperbolic-parabolic simulation from a purely hyperbolic simulation.18@inline function initial_condition_mach085_flow(x, t, equations)19v1 = u_inf(equations) * cos(aoa())20v2 = u_inf(equations) * sin(aoa())2122prim = SVector(rho_inf(), v1, v2, p_inf())23return prim2cons(prim, equations)24end2526initial_condition = initial_condition_mach085_flow2728volume_flux = flux_ranocha_turbo29# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of30# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.31# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.32# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.33# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.34# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the35# `StepsizeCallback` (CFL-Condition) and less diffusion.36surface_flux = FluxLaxFriedrichs(max_abs_speed_naive)3738polydeg = 339basis = LobattoLegendreBasis(polydeg)40shock_indicator = IndicatorHennemannGassner(equations, basis,41alpha_max = 0.5,42alpha_min = 0.001,43alpha_smooth = true,44variable = density_pressure)45volume_integral = VolumeIntegralShockCapturingHG(shock_indicator;46volume_flux_dg = volume_flux,47volume_flux_fv = surface_flux)48solver = DGSEM(polydeg = polydeg, surface_flux = surface_flux,49volume_integral = volume_integral)5051mesh_file = Trixi.download("https://gist.githubusercontent.com/Arpit-Babbar/339662b4b46164a016e35c81c66383bb/raw/8bf94f5b426ba907ace87405cfcc1dcc2ef7cbda/NACA0012.inp",52joinpath(@__DIR__, "NACA0012.inp"))5354mesh = P4estMesh{2}(mesh_file)5556# The outer boundary is constant but subsonic, so we cannot compute the57# boundary flux for the external information alone. Thus, we use the numerical flux to distinguish58# between inflow and outflow characteristics59@inline function boundary_condition_subsonic_constant(u_inner,60normal_direction::AbstractVector, x,61t,62surface_flux_function,63equations::CompressibleEulerEquations2D)64u_boundary = initial_condition_mach085_flow(x, t, equations)6566return flux_hll(u_inner, u_boundary, normal_direction, equations)67end6869boundary_conditions = Dict(:Left => boundary_condition_subsonic_constant,70:Right => boundary_condition_subsonic_constant,71:Top => boundary_condition_subsonic_constant,72:Bottom => boundary_condition_subsonic_constant,73:AirfoilBottom => boundary_condition_slip_wall,74:AirfoilTop => boundary_condition_slip_wall)7576semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,77boundary_conditions = boundary_conditions)7879###############################################################################80# ODE solvers8182# Run for a long time to reach a steady state83tspan = (0.0, 20.0)84ode = semidiscretize(semi, tspan)8586# Callbacks8788summary_callback = SummaryCallback()8990analysis_interval = 20009192l_inf = 1.0 # Length of airfoil9394force_boundary_names = (:AirfoilBottom, :AirfoilTop)95drag_coefficient = AnalysisSurfaceIntegral(force_boundary_names,96DragCoefficientPressure2D(aoa(), rho_inf(),97u_inf(equations),98l_inf))99100lift_coefficient = AnalysisSurfaceIntegral(force_boundary_names,101LiftCoefficientPressure2D(aoa(), rho_inf(),102u_inf(equations),103l_inf))104105analysis_callback = AnalysisCallback(semi, interval = analysis_interval,106output_directory = "out",107save_analysis = true,108analysis_integrals = (drag_coefficient,109lift_coefficient))110111alive_callback = AliveCallback(analysis_interval = analysis_interval)112113save_solution = SaveSolutionCallback(interval = 500,114save_initial_solution = true,115save_final_solution = true,116solution_variables = cons2prim)117118stepsize_callback = StepsizeCallback(cfl = 1.0)119120amr_indicator = IndicatorLöhner(semi, variable = Trixi.density)121122amr_controller = ControllerThreeLevel(semi, amr_indicator,123base_level = 1,124med_level = 3, med_threshold = 0.05,125max_level = 4, max_threshold = 0.1)126127amr_interval = 100128amr_callback = AMRCallback(semi, amr_controller,129interval = amr_interval,130adapt_initial_condition = true,131adapt_initial_condition_only_refine = true)132133save_restart = SaveRestartCallback(interval = 10_000,134save_final_restart = true)135136callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback,137save_solution, save_restart,138stepsize_callback, amr_callback)139140###############################################################################141# run the simulation142sol = solve(ode, SSPRK54(thread = Trixi.True());143dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback144ode_default_options()..., callback = callbacks);145146147