Path: blob/main/examples/tree_3d_dgsem/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.23solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive),24volume_integral = VolumeIntegralWeakForm())2526coordinates_min = (-1.0, -1.0, -1.0) # minimum coordinates (min(x), min(y), min(z))27coordinates_max = (1.0, 1.0, 1.0) # maximum coordinates (max(x), max(y), max(z))2829# Create a uniformly refined mesh with periodic boundaries30mesh = TreeMesh(coordinates_min, coordinates_max,31initial_refinement_level = 3,32periodicity = (true, false, true),33n_cells_max = 50_000) # set maximum capacity of tree data structure3435# Note: the initial condition cannot be specialized to `CompressibleNavierStokesDiffusion3D`36# since it is called by both the parabolic solver (which passes in `CompressibleNavierStokesDiffusion3D`)37# and by the initial condition (which passes in `CompressibleEulerEquations3D`).38# This convergence test setup was originally derived by Andrew Winters (@andrewwinters5000)39function initial_condition_navier_stokes_convergence_test(x, t, equations)40# Constants. OBS! Must match those in `source_terms_navier_stokes_convergence_test`41c = 2.042A1 = 0.543A2 = 1.044A3 = 0.54546# Convenience values for trig. functions47pi_x = pi * x[1]48pi_y = pi * x[2]49pi_z = pi * x[3]50pi_t = pi * t5152rho = c + A1 * sin(pi_x) * cos(pi_y) * sin(pi_z) * cos(pi_t)53v1 = A2 * sin(pi_x) * log(x[2] + 2.0) * (1.0 - exp(-A3 * (x[2] - 1.0))) * sin(pi_z) *54cos(pi_t)55v2 = v156v3 = v157p = rho^25859return prim2cons(SVector(rho, v1, v2, v3, p), equations)60end6162@inline function source_terms_navier_stokes_convergence_test(u, x, t, equations)63# TODO: parabolic64# we currently need to hardcode these parameters until we fix the "combined equation" issue65# see also https://github.com/trixi-framework/Trixi.jl/pull/116066inv_gamma_minus_one = inv(equations.gamma - 1)67Pr = prandtl_number()68mu_ = mu()6970# Constants. OBS! Must match those in `initial_condition_navier_stokes_convergence_test`71c = 2.072A1 = 0.573A2 = 1.074A3 = 0.57576# Convenience values for trig. functions77pi_x = pi * x[1]78pi_y = pi * x[2]79pi_z = pi * x[3]80pi_t = pi * t8182# Define auxiliary functions for the strange function of the y variable83# to make expressions easier to read84g = log(x[2] + 2.0) * (1.0 - exp(-A3 * (x[2] - 1.0)))85g_y = (A3 * log(x[2] + 2.0) * exp(-A3 * (x[2] - 1.0)) +86(1.0 - exp(-A3 * (x[2] - 1.0))) / (x[2] + 2.0))87g_yy = (2.0 * A3 * exp(-A3 * (x[2] - 1.0)) / (x[2] + 2.0) -88(1.0 - exp(-A3 * (x[2] - 1.0))) / ((x[2] + 2.0)^2) -89A3^2 * log(x[2] + 2.0) * exp(-A3 * (x[2] - 1.0)))9091# Density and its derivatives92rho = c + A1 * sin(pi_x) * cos(pi_y) * sin(pi_z) * cos(pi_t)93rho_t = -pi * A1 * sin(pi_x) * cos(pi_y) * sin(pi_z) * sin(pi_t)94rho_x = pi * A1 * cos(pi_x) * cos(pi_y) * sin(pi_z) * cos(pi_t)95rho_y = -pi * A1 * sin(pi_x) * sin(pi_y) * sin(pi_z) * cos(pi_t)96rho_z = pi * A1 * sin(pi_x) * cos(pi_y) * cos(pi_z) * cos(pi_t)97rho_xx = -pi^2 * (rho - c)98rho_yy = -pi^2 * (rho - c)99rho_zz = -pi^2 * (rho - c)100101# Velocities and their derivatives102# v1 terms103v1 = A2 * sin(pi_x) * g * sin(pi_z) * cos(pi_t)104v1_t = -pi * A2 * sin(pi_x) * g * sin(pi_z) * sin(pi_t)105v1_x = pi * A2 * cos(pi_x) * g * sin(pi_z) * cos(pi_t)106v1_y = A2 * sin(pi_x) * g_y * sin(pi_z) * cos(pi_t)107v1_z = pi * A2 * sin(pi_x) * g * cos(pi_z) * cos(pi_t)108v1_xx = -pi^2 * v1109v1_yy = A2 * sin(pi_x) * g_yy * sin(pi_z) * cos(pi_t)110v1_zz = -pi^2 * v1111v1_xy = pi * A2 * cos(pi_x) * g_y * sin(pi_z) * cos(pi_t)112v1_xz = pi^2 * A2 * cos(pi_x) * g * cos(pi_z) * cos(pi_t)113v1_yz = pi * A2 * sin(pi_x) * g_y * cos(pi_z) * cos(pi_t)114# v2 terms (simplifies from ansatz)115v2 = v1116v2_t = v1_t117v2_x = v1_x118v2_y = v1_y119v2_z = v1_z120v2_xx = v1_xx121v2_yy = v1_yy122v2_zz = v1_zz123v2_xy = v1_xy124v2_yz = v1_yz125# v3 terms (simplifies from ansatz)126v3 = v1127v3_t = v1_t128v3_x = v1_x129v3_y = v1_y130v3_z = v1_z131v3_xx = v1_xx132v3_yy = v1_yy133v3_zz = v1_zz134v3_xz = v1_xz135v3_yz = v1_yz136137# Pressure and its derivatives138p = rho^2139p_t = 2.0 * rho * rho_t140p_x = 2.0 * rho * rho_x141p_y = 2.0 * rho * rho_y142p_z = 2.0 * rho * rho_z143144# Total energy and its derivatives; simiplifies from ansatz that v2 = v1 and v3 = v1145E = p * inv_gamma_minus_one + 1.5 * rho * v1^2146E_t = p_t * inv_gamma_minus_one + 1.5 * rho_t * v1^2 + 3.0 * rho * v1 * v1_t147E_x = p_x * inv_gamma_minus_one + 1.5 * rho_x * v1^2 + 3.0 * rho * v1 * v1_x148E_y = p_y * inv_gamma_minus_one + 1.5 * rho_y * v1^2 + 3.0 * rho * v1 * v1_y149E_z = p_z * inv_gamma_minus_one + 1.5 * rho_z * v1^2 + 3.0 * rho * v1 * v1_z150151# Divergence of Fick's law ∇⋅∇q = kappa ∇⋅∇T; simplifies because p = rho², so T = p/rho = rho152kappa = equations.gamma * inv_gamma_minus_one / Pr153q_xx = kappa * rho_xx # kappa T_xx154q_yy = kappa * rho_yy # kappa T_yy155q_zz = kappa * rho_zz # kappa T_zz156157# Stress tensor and its derivatives (exploit symmetry)158tau11 = 4.0 / 3.0 * v1_x - 2.0 / 3.0 * (v2_y + v3_z)159tau12 = v1_y + v2_x160tau13 = v1_z + v3_x161tau22 = 4.0 / 3.0 * v2_y - 2.0 / 3.0 * (v1_x + v3_z)162tau23 = v2_z + v3_y163tau33 = 4.0 / 3.0 * v3_z - 2.0 / 3.0 * (v1_x + v2_y)164165tau11_x = 4.0 / 3.0 * v1_xx - 2.0 / 3.0 * (v2_xy + v3_xz)166tau12_x = v1_xy + v2_xx167tau13_x = v1_xz + v3_xx168169tau12_y = v1_yy + v2_xy170tau22_y = 4.0 / 3.0 * v2_yy - 2.0 / 3.0 * (v1_xy + v3_yz)171tau23_y = v2_yz + v3_yy172173tau13_z = v1_zz + v3_xz174tau23_z = v2_zz + v3_yz175tau33_z = 4.0 / 3.0 * v3_zz - 2.0 / 3.0 * (v1_xz + v2_yz)176177# Compute the source terms178# Density equation179du1 = (rho_t + rho_x * v1 + rho * v1_x180+ rho_y * v2 + rho * v2_y181+ rho_z * v3 + rho * v3_z)182# x-momentum equation183du2 = (rho_t * v1 + rho * v1_t + p_x + rho_x * v1^2184+ 2.0 * rho * v1 * v1_x185+ rho_y * v1 * v2186+ rho * v1_y * v2187+ rho * v1 * v2_y188+ rho_z * v1 * v3189+ rho * v1_z * v3190+ rho * v1 * v3_z -191mu_ * (tau11_x + tau12_y + tau13_z))192# y-momentum equation193du3 = (rho_t * v2 + rho * v2_t + p_y + rho_x * v1 * v2194+ rho * v1_x * v2195+ rho * v1 * v2_x196+ rho_y * v2^2197+ 2.0 * rho * v2 * v2_y198+ rho_z * v2 * v3199+ rho * v2_z * v3200+ rho * v2 * v3_z -201mu_ * (tau12_x + tau22_y + tau23_z))202# z-momentum equation203du4 = (rho_t * v3 + rho * v3_t + p_z + rho_x * v1 * v3204+ rho * v1_x * v3205+ rho * v1 * v3_x206+ rho_y * v2 * v3207+ rho * v2_y * v3208+ rho * v2 * v3_y209+ rho_z * v3^2210+ 2.0 * rho * v3 * v3_z -211mu_ * (tau13_x + tau23_y + tau33_z))212# Total energy equation213du5 = (E_t + v1_x * (E + p) + v1 * (E_x + p_x)214+ v2_y * (E + p) + v2 * (E_y + p_y)215+ v3_z * (E + p) + v3 * (E_z + p_z) -216# stress tensor and temperature gradient from x-direction217mu_ * (q_xx + v1_x * tau11 + v2_x * tau12 + v3_x * tau13218+ v1 * tau11_x + v2 * tau12_x + v3 * tau13_x) -219# stress tensor and temperature gradient terms from y-direction220mu_ * (q_yy + v1_y * tau12 + v2_y * tau22 + v3_y * tau23221+ v1 * tau12_y + v2 * tau22_y + v3 * tau23_y) -222# stress tensor and temperature gradient terms from z-direction223mu_ * (q_zz + v1_z * tau13 + v2_z * tau23 + v3_z * tau33224+ v1 * tau13_z + v2 * tau23_z + v3 * tau33_z))225226return SVector(du1, du2, du3, du4, du5)227end228229initial_condition = initial_condition_navier_stokes_convergence_test230231# BC types232velocity_bc_top_bottom = NoSlip() do x, t, equations_parabolic233u_cons = initial_condition_navier_stokes_convergence_test(x, t, equations_parabolic)234return SVector(u_cons[2] / u_cons[1], u_cons[3] / u_cons[1], u_cons[4] / u_cons[1])235end236heat_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 = (; x_neg = boundary_condition_periodic,242x_pos = boundary_condition_periodic,243y_neg = boundary_condition_slip_wall,244y_pos = boundary_condition_slip_wall,245z_neg = boundary_condition_periodic,246z_pos = boundary_condition_periodic)247248# define viscous boundary conditions249boundary_conditions_parabolic = (; x_neg = boundary_condition_periodic,250x_pos = boundary_condition_periodic,251y_neg = boundary_condition_top_bottom,252y_pos = boundary_condition_top_bottom,253z_neg = boundary_condition_periodic,254z_pos = boundary_condition_periodic)255256semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),257initial_condition, solver;258boundary_conditions = (boundary_conditions,259boundary_conditions_parabolic),260source_terms = source_terms_navier_stokes_convergence_test)261262###############################################################################263# ODE solvers, callbacks etc.264265# Create ODE problem with time span `tspan`266tspan = (0.0, 1.0)267ode = semidiscretize(semi, tspan)268269summary_callback = SummaryCallback()270alive_callback = AliveCallback(alive_interval = 10)271analysis_interval = 100272analysis_callback = AnalysisCallback(semi, interval = analysis_interval)273callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback)274275###############################################################################276# run the simulation277278time_int_tol = 1e-8279sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol, dt = 1e-5,280ode_default_options()..., callback = callbacks)281282283