Skip to content

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

Decaying Homogeneous Isotropic Turbulence - 3D

In this example we consider decaying homogeneous isotropic turbulence, similar to the cases considered in [1] and [2]. The initial velocity field is created randomly, but with a specific energy spectrum. Due to viscous dissipation, the turbulent features eventually group to form larger visible eddies.

julia
using CairoMakie
using IncompressibleNavierStokes
# using CUDA;

Problem setup

julia
T = Float32
n = 128
ax = range(T(0), T(1), n + 1)
setup = Setup(;
    x = (ax, ax, ax),
    boundary_conditions = (;
        u = (
            (PeriodicBC(), PeriodicBC()),
            (PeriodicBC(), PeriodicBC()),
            (PeriodicBC(), PeriodicBC()),
        ),
    ),
    # backend = CUDABackend(),
);
psolver = default_psolver(setup);
u = random_field(setup; psolver);
nothing #hide

Solve problem

julia
state, outputs = solve_unsteady(;
    setup,
    start = (; u),
    tlims = (T(0), T(1)),
    psolver,
    params = (; viscosity = T(2e-4)),
    processors = (
        # rtp = realtimeplotter(; setup, plot = fieldplot, nupdate = 10),
        # ehist = realtimeplotter(; setup, plot = energy_history_plot, nupdate = 10),
        espec = realtimeplotter(; setup, plot = energy_spectrum_plot, nupdate = 10),
        # anim = animator(; setup, path = "$outdir/solution.mkv", nupdate = 20),
        # vtk = vtk_writer(; setup, nupdate = 10, dir = outdir, filename = "solution"),
        log = timelogger(; nupdate = 10),
    ),
);
nothing #hide

Post-process

Field plot

julia
# outputs.rtp
# fieldplot(state; setup, levels = 0:5)

Energy history

julia
# outputs.ehist

Energy spectrum

julia
outputs.espec

Copy-pasteable code

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

julia
using WGLMakie
using IncompressibleNavierStokes
# using CUDA;

T = Float32
n = 128
ax = range(T(0), T(1), n + 1)
setup = Setup(;
    x = (ax, ax, ax),
    boundary_conditions = (;
        u = (
            (PeriodicBC(), PeriodicBC()),
            (PeriodicBC(), PeriodicBC()),
            (PeriodicBC(), PeriodicBC()),
        ),
    ),
    # backend = CUDABackend(),
);
psolver = default_psolver(setup);
u = random_field(setup; psolver);

state, outputs = solve_unsteady(;
    setup,
    start = (; u),
    tlims = (T(0), T(1)),
    psolver,
    params = (; viscosity = T(2e-4)),
    processors = (
        # rtp = realtimeplotter(; setup, plot = fieldplot, nupdate = 10),
        # ehist = realtimeplotter(; setup, plot = energy_history_plot, nupdate = 10),
        espec = realtimeplotter(; setup, plot = energy_spectrum_plot, nupdate = 10),
        # anim = animator(; setup, path = "$outdir/solution.mkv", nupdate = 20),
        # vtk = vtk_writer(; setup, nupdate = 10, dir = outdir, filename = "solution"),
        log = timelogger(; nupdate = 10),
    ),
);

# outputs.rtp
# fieldplot(state; setup, levels = 0:5)

# outputs.ehist

outputs.espec

This page was generated using Literate.jl.