forked from agdestein/IncompressibleNavierStokes.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackwardFacingStep3D.jl
99 lines (80 loc) · 2.79 KB
/
BackwardFacingStep3D.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# # Backward Facing Step - 3D
#
# In this example we consider a channel with periodic side boundaries, walls at
# the top and bottom, and a step at the left with a parabolic inflow. Initially
# the velocity is an extension of the inflow, but as time passes the velocity
# finds a new steady state.
# We start by loading packages.
# A [Makie](https://github.com/JuliaPlots/Makie.jl) plotting backend is needed
# for plotting. `GLMakie` creates an interactive window (useful for real-time
# plotting), but does not work when building this example on GitHub.
# `CairoMakie` makes high-quality static vector-graphics plots.
#md using CairoMakie
using GLMakie #!md
using IncompressibleNavierStokes
# Output directory
outdir = joinpath(@__DIR__, "output", "BackwardFacingStep3D")
# Floating point type
T = Float32
# Array type
ArrayType = Array
## using CUDA; ArrayType = CuArray
## using AMDGPU; ArrayType = ROCArray
## using oneAPI; ArrayType = oneArray
## using Metal; ArrayType = MtlArray
# Reynolds number
Re = T(1000)
# A 3D grid is a Cartesian product of three vectors
x = LinRange(T(0), T(10), 129)
y = LinRange(-T(0.5), T(0.5), 17)
z = LinRange(-T(0.25), T(0.25), 9)
plotgrid(x, y, z)
# Boundary conditions: steady inflow on the top half
U(dim, x, y, z, t) = dim() == 1 && y ≥ 0 ? 24y * (one(x) / 2 - y) : zero(x)
dUdt(dim, x, y, z, t) = zero(x)
boundary_conditions = (
## x left, x right
(DirichletBC(U, dUdt), PressureBC()),
## y rear, y front
(DirichletBC(), DirichletBC()),
## z bottom, z top
(PeriodicBC(), PeriodicBC()),
)
# Build setup and assemble operators
setup = Setup(x, y, z; Re, boundary_conditions, ArrayType);
# Initial conditions (extend inflow)
ustart = create_initial_conditions(setup, (dim, x, y, z) -> U(dim, x, y, z, zero(x)));
# Solve steady state problem
## u, p = solve_steady_state(setup, u₀, p₀);
nothing
# Solve unsteady problem
state, outputs = solve_unsteady(;
setup,
ustart,
tlims = (T(0), T(7)),
Δt = T(0.01),
processors = (
rtp = realtimeplotter(;
setup,
plot = fieldplot,
## plot = energy_history_plot,
## plot = energy_spectrum_plot,
nupdate = 1,
),
## anim = animator(; setup, path = "$outdir/vorticity.mkv", nupdate = 20),
## vtk = vtk_writer(; setup, nupdate = 10, dir = outdir, filename = "solution"),
## field = fieldsaver(; setup, nupdate = 10),
log = timelogger(; nupdate = 100),
),
)
# ## Post-process
#
# We may visualize or export the computed fields
# Export to VTK
save_vtk(state; setup, filename = joinpath(outdir, "solution"))
# Plot pressure
fieldplot(state; setup, fieldname = :pressure)
# Plot velocity
fieldplot(state; setup, fieldname = :velocitynorm)
# Plot vorticity
fieldplot(state; setup, fieldname = :vorticity)