Path: blob/main/examples/tree_3d_dgsem/elixir_navierstokes_viscous_shock.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23# This is the classic 1D viscous shock wave problem with analytical solution4# for a special value of the Prandtl number.5# The original references are:6#7# - R. Becker (1922)8# Stoßwelle und Detonation.9# [DOI: 10.1007/BF01329605](https://doi.org/10.1007/BF01329605)10#11# English translations:12# Impact waves and detonation. Part I.13# https://ntrs.nasa.gov/api/citations/19930090862/downloads/19930090862.pdf14# Impact waves and detonation. Part II.15# https://ntrs.nasa.gov/api/citations/19930090863/downloads/19930090863.pdf16#17# - M. Morduchow, P. A. Libby (1949)18# On a Complete Solution of the One-Dimensional Flow Equations19# of a Viscous, Head-Conducting, Compressible Gas20# [DOI: 10.2514/8.11882](https://doi.org/10.2514/8.11882)21#22#23# The particular problem considered here is described in24# - L. G. Margolin, J. M. Reisner, P. M. Jordan (2017)25# Entropy in self-similar shock profiles26# [DOI: 10.1016/j.ijnonlinmec.2017.07.003](https://doi.org/10.1016/j.ijnonlinmec.2017.07.003)2728### Fixed parameters ###2930# Special value for which nonlinear solver can be omitted31# Corresponds essentially to fixing the Mach number32alpha = 0.533# We want kappa = cp * mu = mu_bar to ensure constant enthalpy34prandtl_number() = 3 / 43536### Free choices: ###37gamma() = 5 / 33839# In Margolin et al., the Navier-Stokes equations are given for an40# isotropic stress tensor τ, i.e., ∇ ⋅ τ = μ Δu41mu_isotropic() = 0.1542mu_bar() = mu_isotropic() / (gamma() - 1) # Re-scaled viscosity4344rho_0() = 145v() = 1 # Shock speed4647domain_length = 4.04849### Derived quantities ###5051Ma() = 2 / sqrt(3 - gamma()) # Mach number for alpha = 0.552c_0() = v() / Ma() # Speed of sound ahead of the shock5354# From constant enthalpy condition55p_0() = c_0()^2 * rho_0() / gamma()5657l() = mu_bar() / (rho_0() * v()) * 2 * gamma() / (gamma() + 1) # Appropriate length scale5859"""60initial_condition_viscous_shock(x, t, equations)6162Classic 1D viscous shock wave problem with analytical solution63for a special value of the Prandtl number.64The version implemented here is described in65- L. G. Margolin, J. M. Reisner, P. M. Jordan (2017)66Entropy in self-similar shock profiles67[DOI: 10.1016/j.ijnonlinmec.2017.07.003](https://doi.org/10.1016/j.ijnonlinmec.2017.07.003)68"""69function initial_condition_viscous_shock(x, t, equations)70y = x[1] - v() * t # Translated coordinate7172# Coordinate transformation. See eq. (33) in Margolin et al. (2017)73chi = 2 * exp(y / (2 * l()))7475w = 1 + 1 / (2 * chi^2) * (1 - sqrt(1 + 2 * chi^2))7677rho = rho_0() / w78u = v() * (1 - w)79p = p_0() * 1 / w * (1 + (gamma() - 1) / 2 * Ma()^2 * (1 - w^2))8081return prim2cons(SVector(rho, u, 0, 0, p), equations)82end83initial_condition = initial_condition_viscous_shock8485###############################################################################86# semidiscretization of the ideal compressible Navier-Stokes equations8788equations = CompressibleEulerEquations3D(gamma())8990# Trixi implements the stress tensor in deviatoric form, thus we need to91# convert the "isotropic viscosity" to the "deviatoric viscosity"92mu_deviatoric() = mu_bar() * 3 / 493equations_parabolic = CompressibleNavierStokesDiffusion3D(equations, mu = mu_deviatoric(),94Prandtl = prandtl_number(),95gradient_variables = GradientVariablesPrimitive())9697solver = DGSEM(polydeg = 3, surface_flux = flux_hlle)9899coordinates_min = (-domain_length / 2, -domain_length / 2, -domain_length / 2)100coordinates_max = (domain_length / 2, domain_length / 2, domain_length / 2)101102mesh = TreeMesh(coordinates_min, coordinates_max,103initial_refinement_level = 3,104periodicity = (false, true, true),105n_cells_max = 100_000)106107### Inviscid boundary conditions ###108109# Prescribe pure influx based on initial conditions110function boundary_condition_inflow(u_inner, orientation, direction, x, t,111surface_flux_function,112equations::CompressibleEulerEquations3D)113u_cons = initial_condition_viscous_shock(x, t, equations)114return flux(u_cons, orientation, equations)115end116117# Completely free outflow118function boundary_condition_outflow(u_inner, orientation, direction, x, t,119surface_flux_function,120equations::CompressibleEulerEquations3D)121# Calculate the boundary flux entirely from the internal solution state122return flux(u_inner, orientation, equations)123end124125boundary_conditions = (; x_neg = boundary_condition_inflow,126x_pos = boundary_condition_outflow,127y_neg = boundary_condition_periodic,128y_pos = boundary_condition_periodic,129z_neg = boundary_condition_periodic,130z_pos = boundary_condition_periodic)131132### Viscous boundary conditions ###133# For the viscous BCs, we use the known analytical solution134velocity_bc = NoSlip() do x, t, equations_parabolic135return Trixi.velocity(initial_condition_viscous_shock(x,136t,137equations_parabolic),138equations_parabolic)139end140141heat_bc = Isothermal() do x, t, equations_parabolic142return Trixi.temperature(initial_condition_viscous_shock(x,143t,144equations_parabolic),145equations_parabolic)146end147148boundary_condition_parabolic = BoundaryConditionNavierStokesWall(velocity_bc, heat_bc)149150boundary_conditions_parabolic = (x_neg = boundary_condition_parabolic,151x_pos = boundary_condition_parabolic,152y_neg = boundary_condition_periodic,153y_pos = boundary_condition_periodic,154z_neg = boundary_condition_periodic,155z_pos = boundary_condition_periodic)156157semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),158initial_condition, solver;159boundary_conditions = (boundary_conditions,160boundary_conditions_parabolic))161162###############################################################################163# ODE solvers, callbacks etc.164165# Create ODE problem with time span `tspan`166tspan = (0.0, 0.5)167ode = semidiscretize(semi, tspan)168169summary_callback = SummaryCallback()170171alive_callback = AliveCallback(alive_interval = 10)172173analysis_interval = 100174analysis_callback = AnalysisCallback(semi, interval = analysis_interval)175176# For this setup, both hyperbolic and parabolic timestep restrictions are relevant, i.e.,177# may not be increased beyond the given values.178stepsize_callback = StepsizeCallback(cfl = 0.4,179cfl_parabolic = 0.2)180181callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback,182stepsize_callback)183184###############################################################################185# run the simulation186187# Use time integrator tailored to compressible Navier-Stokes188sol = solve(ode, CKLLSRK95_4S(), adaptive = false, dt = 1.0,189save_everystep = false, callback = callbacks);190191192