Path: blob/main/examples/dgmulti_2d/elixir_navierstokes_convergence.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the ideal compressible Navier-Stokes equations56prandtl_number() = 0.727mu() = 0.0189equations = CompressibleEulerEquations2D(1.4)10# Note: If you change the Navier-Stokes parameters here, also change them in the initial condition11# I really do not like this structure but it should work for now12equations_parabolic = CompressibleNavierStokesDiffusion2D(equations, mu = mu(),13Prandtl = prandtl_number(),14gradient_variables = GradientVariablesPrimitive())1516# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux1718# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of19# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.20# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.21# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.22# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.23# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the24# `StepsizeCallback` (CFL-Condition) and less diffusion.25dg = DGMulti(polydeg = 3, element_type = Tri(), approximation_type = Polynomial(),26surface_integral = SurfaceIntegralWeakForm(FluxLaxFriedrichs(max_abs_speed_naive)),27volume_integral = VolumeIntegralWeakForm())2829top_bottom(x, tol = 50 * eps()) = abs(abs(x[2]) - 1) < tol30is_on_boundary = Dict(:top_bottom => top_bottom)3132cells_per_dimension = (16, 16)33mesh = DGMultiMesh(dg, cells_per_dimension; periodicity = (true, false), is_on_boundary)3435# Note: the initial condition cannot be specialized to `CompressibleNavierStokesDiffusion2D`36# since it is called by both the parabolic solver (which passes in `CompressibleNavierStokesDiffusion2D`)37# and by the initial condition (which passes in `CompressibleEulerEquations2D`).38# This convergence test setup was originally derived by Andrew Winters (@andrewwinters5000)39function initial_condition_navier_stokes_convergence_test(x, t, equations)40# Amplitude and shift41A = 0.542c = 2.04344# convenience values for trig. functions45pi_x = pi * x[1]46pi_y = pi * x[2]47pi_t = pi * t4849rho = c + A * sin(pi_x) * cos(pi_y) * cos(pi_t)50v1 = sin(pi_x) * log(x[2] + 2.0) * (1.0 - exp(-A * (x[2] - 1.0))) * cos(pi_t)51v2 = v152p = rho^25354return prim2cons(SVector(rho, v1, v2, p), equations)55end5657@inline function source_terms_navier_stokes_convergence_test(u, x, t, equations)58y = x[2]5960# TODO: parabolic61# we currently need to hardcode these parameters until we fix the "combined equation" issue62# see also https://github.com/trixi-framework/Trixi.jl/pull/116063inv_gamma_minus_one = inv(equations.gamma - 1)64Pr = prandtl_number()65mu_ = mu()6667# Same settings as in `initial_condition`68# Amplitude and shift69A = 0.570c = 2.07172# convenience values for trig. functions73pi_x = pi * x[1]74pi_y = pi * x[2]75pi_t = pi * t7677# compute the manufactured solution and all necessary derivatives78rho = c + A * sin(pi_x) * cos(pi_y) * cos(pi_t)79rho_t = -pi * A * sin(pi_x) * cos(pi_y) * sin(pi_t)80rho_x = pi * A * cos(pi_x) * cos(pi_y) * cos(pi_t)81rho_y = -pi * A * sin(pi_x) * sin(pi_y) * cos(pi_t)82rho_xx = -pi * pi * A * sin(pi_x) * cos(pi_y) * cos(pi_t)83rho_yy = -pi * pi * A * sin(pi_x) * cos(pi_y) * cos(pi_t)8485v1 = sin(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * cos(pi_t)86v1_t = -pi * sin(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * sin(pi_t)87v1_x = pi * cos(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * cos(pi_t)88v1_y = sin(pi_x) *89(A * log(y + 2.0) * exp(-A * (y - 1.0)) +90(1.0 - exp(-A * (y - 1.0))) / (y + 2.0)) * cos(pi_t)91v1_xx = -pi * pi * sin(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * cos(pi_t)92v1_xy = pi * cos(pi_x) *93(A * log(y + 2.0) * exp(-A * (y - 1.0)) +94(1.0 - exp(-A * (y - 1.0))) / (y + 2.0)) * cos(pi_t)95v1_yy = (sin(pi_x) *96(2.0 * A * exp(-A * (y - 1.0)) / (y + 2.0) -97A * A * log(y + 2.0) * exp(-A * (y - 1.0)) -98(1.0 - exp(-A * (y - 1.0))) / ((y + 2.0) * (y + 2.0))) * cos(pi_t))99v2 = v1100v2_t = v1_t101v2_x = v1_x102v2_y = v1_y103v2_xx = v1_xx104v2_xy = v1_xy105v2_yy = v1_yy106107p = rho * rho108p_t = 2.0 * rho * rho_t109p_x = 2.0 * rho * rho_x110p_y = 2.0 * rho * rho_y111p_xx = 2.0 * rho * rho_xx + 2.0 * rho_x * rho_x112p_yy = 2.0 * rho * rho_yy + 2.0 * rho_y * rho_y113114# Note this simplifies slightly because the ansatz assumes that v1 = v2115E = p * inv_gamma_minus_one + 0.5 * rho * (v1^2 + v2^2)116E_t = p_t * inv_gamma_minus_one + rho_t * v1^2 + 2.0 * rho * v1 * v1_t117E_x = p_x * inv_gamma_minus_one + rho_x * v1^2 + 2.0 * rho * v1 * v1_x118E_y = p_y * inv_gamma_minus_one + rho_y * v1^2 + 2.0 * rho * v1 * v1_y119120# Some convenience constants121T_const = equations.gamma * inv_gamma_minus_one / Pr122inv_rho_cubed = 1.0 / (rho^3)123124# compute the source terms125# density equation126du1 = rho_t + rho_x * v1 + rho * v1_x + rho_y * v2 + rho * v2_y127128# x-momentum equation129du2 = (rho_t * v1 + rho * v1_t + p_x + rho_x * v1^2130+ 2.0 * rho * v1 * v1_x131+ rho_y * v1 * v2132+ rho * v1_y * v2133+ rho * v1 * v2_y -134# stress tensor from x-direction1354.0 / 3.0 * v1_xx * mu_ +1362.0 / 3.0 * v2_xy * mu_ -137v1_yy * mu_ -138v2_xy * mu_)139# y-momentum equation140du3 = (rho_t * v2 + rho * v2_t + p_y + rho_x * v1 * v2141+ rho * v1_x * v2142+ rho * v1 * v2_x143+ rho_y * v2^2144+ 2.0 * rho * v2 * v2_y -145# stress tensor from y-direction146v1_xy * mu_ -147v2_xx * mu_ -1484.0 / 3.0 * v2_yy * mu_ +1492.0 / 3.0 * v1_xy * mu_)150# total energy equation151du4 = (E_t + v1_x * (E + p) + v1 * (E_x + p_x)152+ v2_y * (E + p) + v2 * (E_y + p_y) -153# stress tensor and temperature gradient terms from x-direction1544.0 / 3.0 * v1_xx * v1 * mu_ +1552.0 / 3.0 * v2_xy * v1 * mu_ -1564.0 / 3.0 * v1_x * v1_x * mu_ +1572.0 / 3.0 * v2_y * v1_x * mu_ -158v1_xy * v2 * mu_ -159v2_xx * v2 * mu_ -160v1_y * v2_x * mu_ -161v2_x * v2_x * mu_ -162T_const * inv_rho_cubed *163(p_xx * rho * rho -1642.0 * p_x * rho * rho_x +1652.0 * p * rho_x * rho_x -166p * rho * rho_xx) * mu_ -167# stress tensor and temperature gradient terms from y-direction168v1_yy * v1 * mu_ -169v2_xy * v1 * mu_ -170v1_y * v1_y * mu_ -171v2_x * v1_y * mu_ -1724.0 / 3.0 * v2_yy * v2 * mu_ +1732.0 / 3.0 * v1_xy * v2 * mu_ -1744.0 / 3.0 * v2_y * v2_y * mu_ +1752.0 / 3.0 * v1_x * v2_y * mu_ -176T_const * inv_rho_cubed *177(p_yy * rho * rho -1782.0 * p_y * rho * rho_y +1792.0 * p * rho_y * rho_y -180p * rho * rho_yy) * mu_)181182return SVector(du1, du2, du3, du4)183end184185initial_condition = initial_condition_navier_stokes_convergence_test186187# BC types188velocity_bc_top_bottom = NoSlip() do x, t, equations_parabolic189u_cons = initial_condition_navier_stokes_convergence_test(x, t, equations_parabolic)190return SVector(u_cons[2] / u_cons[1], u_cons[3] / u_cons[1])191end192193heat_bc_top_bottom = Adiabatic((x, t, equations_parabolic) -> 0.0)194boundary_condition_top_bottom = BoundaryConditionNavierStokesWall(velocity_bc_top_bottom,195heat_bc_top_bottom)196197# define inviscid boundary conditions198boundary_conditions = (; :top_bottom => boundary_condition_slip_wall)199200# define viscous boundary conditions201boundary_conditions_parabolic = (; :top_bottom => boundary_condition_top_bottom)202203semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),204initial_condition, dg;205boundary_conditions = (boundary_conditions,206boundary_conditions_parabolic),207source_terms = source_terms_navier_stokes_convergence_test)208209###############################################################################210# ODE solvers, callbacks etc.211212# Create ODE problem with time span `tspan`213tspan = (0.0, 0.5)214ode = semidiscretize(semi, tspan)215216summary_callback = SummaryCallback()217alive_callback = AliveCallback(alive_interval = 10)218analysis_interval = 100219analysis_callback = AnalysisCallback(semi, interval = analysis_interval, uEltype = real(dg))220save_solution = SaveSolutionCallback(interval = analysis_interval,221solution_variables = cons2prim)222callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback, save_solution)223224###############################################################################225# run the simulation226227time_int_tol = 1e-8228sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,229ode_default_options()..., callback = callbacks)230231232