Path: blob/main/examples/dgmulti_3d/elixir_navierstokes_convergence.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the ideal compressible Navier-Stokes equations56prandtl_number() = 0.727mu() = 0.0189equations = CompressibleEulerEquations3D(1.4)10equations_parabolic = CompressibleNavierStokesDiffusion3D(equations, mu = mu(),11Prandtl = prandtl_number(),12gradient_variables = GradientVariablesPrimitive())1314# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux1516# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of17# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.18# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.19# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.20# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.21# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the22# `StepsizeCallback` (CFL-Condition) and less diffusion.23dg = DGMulti(polydeg = 3, element_type = Hex(), approximation_type = Polynomial(),24surface_integral = SurfaceIntegralWeakForm(FluxLaxFriedrichs(max_abs_speed_naive)),25volume_integral = VolumeIntegralWeakForm())2627top_bottom(x, tol = 50 * eps()) = abs(abs(x[2]) - 1) < tol28is_on_boundary = Dict(:top_bottom => top_bottom)2930cells_per_dimension = (8, 8, 8)31mesh = DGMultiMesh(dg, cells_per_dimension; periodicity = (true, false, true),32is_on_boundary)3334# Note: the initial condition cannot be specialized to `CompressibleNavierStokesDiffusion3D`35# since it is called by both the parabolic solver (which passes in `CompressibleNavierStokesDiffusion3D`)36# and by the initial condition (which passes in `CompressibleEulerEquations3D`).37# This convergence test setup was originally derived by Andrew Winters (@andrewwinters5000)38function initial_condition_navier_stokes_convergence_test(x, t, equations)39# Constants. OBS! Must match those in `source_terms_navier_stokes_convergence_test`40c = 2.041A1 = 0.542A2 = 1.043A3 = 0.54445# Convenience values for trig. functions46pi_x = pi * x[1]47pi_y = pi * x[2]48pi_z = pi * x[3]49pi_t = pi * t5051rho = c + A1 * sin(pi_x) * cos(pi_y) * sin(pi_z) * cos(pi_t)52v1 = A2 * sin(pi_x) * log(x[2] + 2.0) * (1.0 - exp(-A3 * (x[2] - 1.0))) * sin(pi_z) *53cos(pi_t)54v2 = v155v3 = v156p = rho^25758return prim2cons(SVector(rho, v1, v2, v3, p), equations)59end6061@inline function source_terms_navier_stokes_convergence_test(u, x, t, equations)62# TODO: parabolic63# we currently need to hardcode these parameters until we fix the "combined equation" issue64# see also https://github.com/trixi-framework/Trixi.jl/pull/116065inv_gamma_minus_one = inv(equations.gamma - 1)66Pr = prandtl_number()67mu_ = mu()6869# Constants. OBS! Must match those in `initial_condition_navier_stokes_convergence_test`70c = 2.071A1 = 0.572A2 = 1.073A3 = 0.57475# Convenience values for trig. functions76pi_x = pi * x[1]77pi_y = pi * x[2]78pi_z = pi * x[3]79pi_t = pi * t8081# Define auxiliary functions for the strange function of the y variable82# to make expressions easier to read83g = log(x[2] + 2.0) * (1.0 - exp(-A3 * (x[2] - 1.0)))84g_y = (A3 * log(x[2] + 2.0) * exp(-A3 * (x[2] - 1.0)) +85(1.0 - exp(-A3 * (x[2] - 1.0))) / (x[2] + 2.0))86g_yy = (2.0 * A3 * exp(-A3 * (x[2] - 1.0)) / (x[2] + 2.0) -87(1.0 - exp(-A3 * (x[2] - 1.0))) / ((x[2] + 2.0)^2) -88A3^2 * log(x[2] + 2.0) * exp(-A3 * (x[2] - 1.0)))8990# Density and its derivatives91rho = c + A1 * sin(pi_x) * cos(pi_y) * sin(pi_z) * cos(pi_t)92rho_t = -pi * A1 * sin(pi_x) * cos(pi_y) * sin(pi_z) * sin(pi_t)93rho_x = pi * A1 * cos(pi_x) * cos(pi_y) * sin(pi_z) * cos(pi_t)94rho_y = -pi * A1 * sin(pi_x) * sin(pi_y) * sin(pi_z) * cos(pi_t)95rho_z = pi * A1 * sin(pi_x) * cos(pi_y) * cos(pi_z) * cos(pi_t)96rho_xx = -pi^2 * (rho - c)97rho_yy = -pi^2 * (rho - c)98rho_zz = -pi^2 * (rho - c)99100# Velocities and their derivatives101# v1 terms102v1 = A2 * sin(pi_x) * g * sin(pi_z) * cos(pi_t)103v1_t = -pi * A2 * sin(pi_x) * g * sin(pi_z) * sin(pi_t)104v1_x = pi * A2 * cos(pi_x) * g * sin(pi_z) * cos(pi_t)105v1_y = A2 * sin(pi_x) * g_y * sin(pi_z) * cos(pi_t)106v1_z = pi * A2 * sin(pi_x) * g * cos(pi_z) * cos(pi_t)107v1_xx = -pi^2 * v1108v1_yy = A2 * sin(pi_x) * g_yy * sin(pi_z) * cos(pi_t)109v1_zz = -pi^2 * v1110v1_xy = pi * A2 * cos(pi_x) * g_y * sin(pi_z) * cos(pi_t)111v1_xz = pi^2 * A2 * cos(pi_x) * g * cos(pi_z) * cos(pi_t)112v1_yz = pi * A2 * sin(pi_x) * g_y * cos(pi_z) * cos(pi_t)113# v2 terms (simplifies from ansatz)114v2 = v1115v2_t = v1_t116v2_x = v1_x117v2_y = v1_y118v2_z = v1_z119v2_xx = v1_xx120v2_yy = v1_yy121v2_zz = v1_zz122v2_xy = v1_xy123v2_yz = v1_yz124# v3 terms (simplifies from ansatz)125v3 = v1126v3_t = v1_t127v3_x = v1_x128v3_y = v1_y129v3_z = v1_z130v3_xx = v1_xx131v3_yy = v1_yy132v3_zz = v1_zz133v3_xz = v1_xz134v3_yz = v1_yz135136# Pressure and its derivatives137p = rho^2138p_t = 2.0 * rho * rho_t139p_x = 2.0 * rho * rho_x140p_y = 2.0 * rho * rho_y141p_z = 2.0 * rho * rho_z142143# Total energy and its derivatives; simiplifies from ansatz that v2 = v1 and v3 = v1144E = p * inv_gamma_minus_one + 1.5 * rho * v1^2145E_t = p_t * inv_gamma_minus_one + 1.5 * rho_t * v1^2 + 3.0 * rho * v1 * v1_t146E_x = p_x * inv_gamma_minus_one + 1.5 * rho_x * v1^2 + 3.0 * rho * v1 * v1_x147E_y = p_y * inv_gamma_minus_one + 1.5 * rho_y * v1^2 + 3.0 * rho * v1 * v1_y148E_z = p_z * inv_gamma_minus_one + 1.5 * rho_z * v1^2 + 3.0 * rho * v1 * v1_z149150# Divergence of Fick's law ∇⋅∇q = kappa ∇⋅∇T; simplifies because p = rho², so T = p/rho = rho151kappa = equations.gamma * inv_gamma_minus_one / Pr152q_xx = kappa * rho_xx # kappa T_xx153q_yy = kappa * rho_yy # kappa T_yy154q_zz = kappa * rho_zz # kappa T_zz155156# Stress tensor and its derivatives (exploit symmetry)157tau11 = 4.0 / 3.0 * v1_x - 2.0 / 3.0 * (v2_y + v3_z)158tau12 = v1_y + v2_x159tau13 = v1_z + v3_x160tau22 = 4.0 / 3.0 * v2_y - 2.0 / 3.0 * (v1_x + v3_z)161tau23 = v2_z + v3_y162tau33 = 4.0 / 3.0 * v3_z - 2.0 / 3.0 * (v1_x + v2_y)163164tau11_x = 4.0 / 3.0 * v1_xx - 2.0 / 3.0 * (v2_xy + v3_xz)165tau12_x = v1_xy + v2_xx166tau13_x = v1_xz + v3_xx167168tau12_y = v1_yy + v2_xy169tau22_y = 4.0 / 3.0 * v2_yy - 2.0 / 3.0 * (v1_xy + v3_yz)170tau23_y = v2_yz + v3_yy171172tau13_z = v1_zz + v3_xz173tau23_z = v2_zz + v3_yz174tau33_z = 4.0 / 3.0 * v3_zz - 2.0 / 3.0 * (v1_xz + v2_yz)175176# Compute the source terms177# Density equation178du1 = (rho_t + rho_x * v1 + rho * v1_x179+ rho_y * v2 + rho * v2_y180+ rho_z * v3 + rho * v3_z)181# x-momentum equation182du2 = (rho_t * v1 + rho * v1_t + p_x + rho_x * v1^2183+ 2.0 * rho * v1 * v1_x184+ rho_y * v1 * v2185+ rho * v1_y * v2186+ rho * v1 * v2_y187+ rho_z * v1 * v3188+ rho * v1_z * v3189+ rho * v1 * v3_z -190mu_ * (tau11_x + tau12_y + tau13_z))191# y-momentum equation192du3 = (rho_t * v2 + rho * v2_t + p_y + rho_x * v1 * v2193+ rho * v1_x * v2194+ rho * v1 * v2_x195+ rho_y * v2^2196+ 2.0 * rho * v2 * v2_y197+ rho_z * v2 * v3198+ rho * v2_z * v3199+ rho * v2 * v3_z -200mu_ * (tau12_x + tau22_y + tau23_z))201# z-momentum equation202du4 = (rho_t * v3 + rho * v3_t + p_z + rho_x * v1 * v3203+ rho * v1_x * v3204+ rho * v1 * v3_x205+ rho_y * v2 * v3206+ rho * v2_y * v3207+ rho * v2 * v3_y208+ rho_z * v3^2209+ 2.0 * rho * v3 * v3_z -210mu_ * (tau13_x + tau23_y + tau33_z))211# Total energy equation212du5 = (E_t + v1_x * (E + p) + v1 * (E_x + p_x)213+ v2_y * (E + p) + v2 * (E_y + p_y)214+ v3_z * (E + p) + v3 * (E_z + p_z) -215# stress tensor and temperature gradient from x-direction216mu_ * (q_xx + v1_x * tau11 + v2_x * tau12 + v3_x * tau13217+ v1 * tau11_x + v2 * tau12_x + v3 * tau13_x) -218# stress tensor and temperature gradient terms from y-direction219mu_ * (q_yy + v1_y * tau12 + v2_y * tau22 + v3_y * tau23220+ v1 * tau12_y + v2 * tau22_y + v3 * tau23_y) -221# stress tensor and temperature gradient terms from z-direction222mu_ * (q_zz + v1_z * tau13 + v2_z * tau23 + v3_z * tau33223+ v1 * tau13_z + v2 * tau23_z + v3 * tau33_z))224225return SVector(du1, du2, du3, du4, du5)226end227228initial_condition = initial_condition_navier_stokes_convergence_test229230# BC types231velocity_bc_top_bottom = NoSlip() do x, t, equations_parabolic232u_cons = initial_condition_navier_stokes_convergence_test(x, t, equations_parabolic)233return SVector(u_cons[2] / u_cons[1], u_cons[3] / u_cons[1], u_cons[4] / u_cons[1])234end235236heat_bc_top_bottom = Adiabatic((x, t, equations_parabolic) -> 0.0)237boundary_condition_top_bottom = BoundaryConditionNavierStokesWall(velocity_bc_top_bottom,238heat_bc_top_bottom)239240# define inviscid boundary conditions241boundary_conditions = (; :top_bottom => boundary_condition_slip_wall)242243# define viscous boundary conditions244boundary_conditions_parabolic = (; :top_bottom => boundary_condition_top_bottom)245246semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),247initial_condition, dg;248boundary_conditions = (boundary_conditions,249boundary_conditions_parabolic),250source_terms = source_terms_navier_stokes_convergence_test)251252###############################################################################253# ODE solvers, callbacks etc.254255# Create ODE problem with time span `tspan`256tspan = (0.0, 1.0)257ode = semidiscretize(semi, tspan)258259summary_callback = SummaryCallback()260alive_callback = AliveCallback(alive_interval = 10)261analysis_interval = 100262analysis_callback = AnalysisCallback(semi, interval = analysis_interval, uEltype = real(dg))263save_solution = SaveSolutionCallback(interval = analysis_interval,264solution_variables = cons2prim)265callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback, save_solution)266267###############################################################################268# run the simulation269270time_int_tol = 1e-8271sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,272ode_default_options()..., callback = callbacks)273274275