Skip to content

Rayleigh-Taylor instability in 2D

Two fluids with different temperatures start mixing.

julia
using CairoMakie
using IncompressibleNavierStokes

Output directory for saving results

julia
outdir = joinpath(@__DIR__, "output", "RayleighTaylor2D")
"/home/runner/work/IncompressibleNavierStokes.jl/IncompressibleNavierStokes.jl/docs/build/examples/generated/output/RayleighTaylor2D"

Hardware

julia
backend = CPU()

# using CUDA, CUDSS
# backend = CUDABackend()
CPU(false)

Precision

julia
T = Float64
Float64

Grid

julia
n = 50
x = tanh_grid(T(0), T(1), n, T(1.5)), tanh_grid(T(0), T(2), 2n, T(1.5))
plotgrid(x...; figure = (; size = (300, 600)))

Setup

julia
temperature = temperature_equation(;
    Pr = T(0.71),
    Ra = T(1e6),
    Ge = T(1.0),
    dodissipation = true,
    boundary_conditions = ((SymmetricBC(), SymmetricBC()), (SymmetricBC(), SymmetricBC())),
    gdir = 2,
    nondim_type = 1,
)
setup = Setup(;
    x,
    boundary_conditions = ((DirichletBC(), DirichletBC()), (DirichletBC(), DirichletBC())),
    Re = 1 / temperature.α1,
    temperature,
);

Initial conditions

julia
ustart = velocityfield(setup, (dim, x, y) -> zero(x));
tempstart = temperaturefield(setup, (x, y) -> one(x) * (1 + sinpi(x) / 50 > y));

Solve equation

julia
state, outputs = solve_unsteady(;
    setup,
    ustart,
    tempstart,
    tlims = (T(0), T(10)),
    Δt = T(5e-3),
    processors = (;
        rtp = realtimeplotter(;
            setup,
            nupdate = 20,
            fieldname = :temperature,
            size = (400, 600),
        ),
        log = timelogger(; nupdate = 200),
    ),
);
[ Info: t = 1	Δt = 0.005	umax = 0.1	itertime = 0.011
[ Info: t = 2	Δt = 0.005	umax = 0.32	itertime = 0.0032
[ Info: t = 3	Δt = 0.005	umax = 0.78	itertime = 0.0032
[ Info: t = 4	Δt = 0.005	umax = 0.75	itertime = 0.0032
[ Info: t = 5	Δt = 0.005	umax = 0.78	itertime = 0.0032
[ Info: t = 6	Δt = 0.005	umax = 0.84	itertime = 0.0034
[ Info: t = 7	Δt = 0.005	umax = 0.84	itertime = 0.0032
[ Info: t = 8	Δt = 0.005	umax = 0.89	itertime = 0.0032
[ Info: t = 9	Δt = 0.005	umax = 1.2	itertime = 0.0032
[ Info: t = 10	Δt = 0.005	umax = 0.88	itertime = 0.0032

Copy-pasteable code

Below is the full code for this example stripped of comments and output.

julia
using GLMakie
using IncompressibleNavierStokes

outdir = joinpath(@__DIR__, "output", "RayleighTaylor2D")

backend = CPU()

# using CUDA, CUDSS
# backend = CUDABackend()

T = Float64

n = 50
x = tanh_grid(T(0), T(1), n, T(1.5)), tanh_grid(T(0), T(2), 2n, T(1.5))
plotgrid(x...; figure = (; size = (300, 600)))

temperature = temperature_equation(;
    Pr = T(0.71),
    Ra = T(1e6),
    Ge = T(1.0),
    dodissipation = true,
    boundary_conditions = ((SymmetricBC(), SymmetricBC()), (SymmetricBC(), SymmetricBC())),
    gdir = 2,
    nondim_type = 1,
)
setup = Setup(;
    x,
    boundary_conditions = ((DirichletBC(), DirichletBC()), (DirichletBC(), DirichletBC())),
    Re = 1 / temperature.α1,
    temperature,
);

ustart = velocityfield(setup, (dim, x, y) -> zero(x));
tempstart = temperaturefield(setup, (x, y) -> one(x) * (1 + sinpi(x) / 50 > y));

state, outputs = solve_unsteady(;
    setup,
    ustart,
    tempstart,
    tlims = (T(0), T(10)),
    Δt = T(5e-3),
    processors = (;
        rtp = realtimeplotter(;
            setup,
            nupdate = 20,
            fieldname = :temperature,
            size = (400, 600),
        ),
        log = timelogger(; nupdate = 200),
    ),
);

This page was generated using Literate.jl.