Skip to content

Note: Output is not generated for this example (to save resources on GitHub).

Shear layer - 2D

Shear layer example.

We start by loading packages. A Makie 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.

julia
using CairoMakie
using IncompressibleNavierStokes

Output directory

julia
outdir = joinpath(@__DIR__, "output", "ShearLayer2D")

Floating point type

julia
T = Float64

Array type

julia
ArrayType = Array
# using CUDA; ArrayType = CuArray
# using AMDGPU; ArrayType = ROCArray
# using oneAPI; ArrayType = oneArray
# using Metal; ArrayType = MtlArray

Reynolds number

julia
Re = T(2000)

A 2D grid is a Cartesian product of two vectors

julia
n = 128
lims = T(0), T()
x = LinRange(lims..., n + 1), LinRange(lims..., n + 1)
plotgrid(x...)

Build setup and assemble operators

julia
setup = Setup(; x, Re, ArrayType);
nothing #hide

Initial conditions: We add 1 to u in order to make global momentum conservation less trivial

julia
d = T(π / 15)
e = T(0.05)
U1(y) = y  π ? tanh((y - T(π / 2)) / d) : tanh((T( / 2) - y) / d)
# U1(y) = T(1) + (y ≤ π ? tanh((y - T(π / 2)) / d) : tanh((T(3π / 2) - y) / d))
ustart = velocityfield(setup, (dim, x, y) -> dim == 1 ? U1(y) : e * sin(x));
nothing #hide

Solve unsteady problem

julia
state, outputs = solve_unsteady(;
    setup,
    ustart,
    tlims = (T(0), T(8)),
    Δ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),
    ),
);
nothing #hide

Post-process

We may visualize or export the computed fields

julia
outputs.rtp

Export to VTK

julia
save_vtk(state; setup, filename = joinpath(outdir, "solution"))

Plot pressure

julia
fieldplot(state; setup, fieldname = :pressure)

Plot velocity

julia
fieldplot(state; setup, fieldname = :velocitynorm)

Plot vorticity

julia
fieldplot(state; setup, fieldname = :vorticity)

This page was generated using Literate.jl.