Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/dgmulti_2d/elixir_navierstokes_lid_driven_cavity.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the ideal compressible Navier-Stokes equations
6
7
prandtl_number() = 0.72
8
mu = 0.001
9
10
equations = CompressibleEulerEquations2D(1.4)
11
equations_parabolic = CompressibleNavierStokesDiffusion2D(equations, mu = mu,
12
Prandtl = prandtl_number())
13
14
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
15
16
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
17
# `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 the
22
# `StepsizeCallback` (CFL-Condition) and less diffusion.
23
dg = DGMulti(polydeg = 3, element_type = Quad(), approximation_type = GaussSBP(),
24
surface_integral = SurfaceIntegralWeakForm(FluxLaxFriedrichs(max_abs_speed_naive)),
25
volume_integral = VolumeIntegralFluxDifferencing(flux_ranocha))
26
27
top(x, tol = 50 * eps()) = abs(x[2] - 1) < tol
28
rest_of_boundary(x, tol = 50 * eps()) = !top(x, tol)
29
is_on_boundary = Dict(:top => top, :rest_of_boundary => rest_of_boundary)
30
31
cells_per_dimension = (16, 16)
32
mesh = DGMultiMesh(dg, cells_per_dimension; is_on_boundary)
33
34
function initial_condition_cavity(x, t, equations::CompressibleEulerEquations2D)
35
Ma = 0.1
36
rho = 1.0
37
u, v = 0.0, 0.0
38
p = 1.0 / (Ma^2 * equations.gamma)
39
return prim2cons(SVector(rho, u, v, p), equations)
40
end
41
initial_condition = initial_condition_cavity
42
43
# BC types
44
velocity_bc_lid = NoSlip((x, t, equations_parabolic) -> SVector(1.0, 0.0))
45
velocity_bc_cavity = NoSlip((x, t, equations_parabolic) -> SVector(0.0, 0.0))
46
heat_bc = Adiabatic((x, t, equations_parabolic) -> 0.0)
47
boundary_condition_lid = BoundaryConditionNavierStokesWall(velocity_bc_lid, heat_bc)
48
boundary_condition_cavity = BoundaryConditionNavierStokesWall(velocity_bc_cavity, heat_bc)
49
50
# define inviscid boundary conditions
51
boundary_conditions = (; :top => boundary_condition_slip_wall,
52
:rest_of_boundary => boundary_condition_slip_wall)
53
54
# define viscous boundary conditions
55
boundary_conditions_parabolic = (; :top => boundary_condition_lid,
56
:rest_of_boundary => boundary_condition_cavity)
57
58
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
59
initial_condition, dg;
60
boundary_conditions = (boundary_conditions,
61
boundary_conditions_parabolic))
62
63
###############################################################################
64
# ODE solvers, callbacks etc.
65
66
# Create ODE problem with time span `tspan`
67
tspan = (0.0, 10.0)
68
ode = semidiscretize(semi, tspan)
69
70
summary_callback = SummaryCallback()
71
alive_callback = AliveCallback(alive_interval = 10)
72
analysis_interval = 100
73
analysis_callback = AnalysisCallback(semi, interval = analysis_interval, uEltype = real(dg))
74
save_solution = SaveSolutionCallback(interval = analysis_interval,
75
solution_variables = cons2prim)
76
callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback, save_solution)
77
78
###############################################################################
79
# run the simulation
80
81
time_int_tol = 1e-8
82
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
83
ode_default_options()..., callback = callbacks)
84
85