Operators
All discrete operators are implemented as matrix-free kernels using KernelAbstractions.jl and Cartesian indices, similar to WaterLily.jl. This allows for dimension- and backend-agnostic code; the same kernels run on CPU and GPU. See this blog post for how such kernels are written.
Each operator comes in two variants:
A fast mutating variant with an exclamation mark (e.g.
divergence!), which writes its result into a preallocated output array.A non-mutating variant (e.g.
divergence), which allocates its output and is differentiable with reverse-mode automatic differentiation (see Differentiating code).
The operators act on fields that include ghost volumes, so boundary conditions must be applied first with apply_bc_u and friends (see Problem setup). Sparse matrix versions of the linear operators are also available, see Sparse matrices.
API
IncompressibleNavierStokes.Offset Type
struct Offset{D}Cartesian index unit vector in D = 2 or D = 3 dimensions. Calling Offset(D)(i) returns a Cartesian index with 1 in the dimension i and zeros elsewhere.
See https://b-fg.github.io/research/2023-07-05-waterlily-on-gpu.html for writing kernel loops using Cartesian indices.
Fields
sourceIncompressibleNavierStokes.apply! Method
apply!(kernel, setup, args...; ndrange, offset)Apply kernel to args with offset offset. By default, it is applied everywhere except for at the outermost boundary.
IncompressibleNavierStokes.applygravity! Method
applygravity!(f, temp, setup, gdir, gravity) -> AnyCompute gravity term (in-place version). add the result to F.
IncompressibleNavierStokes.applygravity Method
applygravity(temp, setup, gdir, gravity) -> AnyCompute gravity term (differentiable version).
sourceIncompressibleNavierStokes.applypressure! Method
applypressure!(u, p, setup) -> AnySubtract pressure gradient (in-place version).
sourceIncompressibleNavierStokes.avg Method
avg(ϕ, Δ, I, i) -> AnyAverage scalar field ϕ in the i-direction.
IncompressibleNavierStokes.convection! Method
convection!(f, u, setup) -> AnyCompute convective term (in-place version). Add the result to F.
IncompressibleNavierStokes.convection Method
convection(u, setup) -> AnyCompute convective term (differentiable version).
sourceIncompressibleNavierStokes.convection_diffusion_temp! Method
convection_diffusion_temp!(
c,
u,
temp,
setup,
conductivity
) -> AnyCompute convection-diffusion term for the temperature equation. (in-place version). Add result to c.
IncompressibleNavierStokes.convection_diffusion_temp Method
convection_diffusion_temp(
u,
temp,
setup,
conductivity
) -> AnyCompute convection-diffusion term for the temperature equation. (differentiable version).
sourceIncompressibleNavierStokes.convection_diffusion_temp_adjoint_temp! Method
convection_diffusion_temp_adjoint_temp!(
tempbar,
φ,
u,
setup,
conductivity
) -> AnyAdjoint of convection_diffusion_temp! with respect to temp (add result to tempbar).
IncompressibleNavierStokes.convection_diffusion_temp_adjoint_u! Method
convection_diffusion_temp_adjoint_u!(
ubar,
φ,
temp,
setup
) -> AnyAdjoint of convection_diffusion_temp! with respect to u (add result to ubar).
IncompressibleNavierStokes.convectiondiffusion! Method
convectiondiffusion!(f, u, setup, viscosity) -> AnyCompute convective and diffusive terms (in-place version). Add the result to f.
IncompressibleNavierStokes.diffusion! Method
diffusion!(f, u, setup, viscosity) -> AnyCompute diffusive term (in-place version). Add the result to F.
IncompressibleNavierStokes.diffusion Method
diffusion(u, setup, viscosity) -> AnyCompute diffusive term (differentiable version).
sourceIncompressibleNavierStokes.dissipation! Method
dissipation!(diss, u, setup, coeff) -> AnyCompute dissipation term for the temperature equation (in-place version). Add result to diss.
IncompressibleNavierStokes.dissipation Method
dissipation(u, setup, coeff) -> AnyCompute dissipation term for the temperature equation (differentiable version).
sourceIncompressibleNavierStokes.divergence! Method
divergence!(div, u, setup) -> AnyCompute divergence of velocity field (in-place version).
sourceIncompressibleNavierStokes.divergence Method
divergence(u, setup) -> AnyCompute divergence of velocity field (differentiable version).
sourceIncompressibleNavierStokes.gridsize_vol Method
gridsize_vol(setup, I::CartesianIndex{2}) -> AnyGrid size based on the volume of the cell.
sourceIncompressibleNavierStokes.interpolate_u_p! Method
interpolate_u_p!(up, u, setup) -> AnyInterpolate velocity to pressure points (in-place version).
sourceIncompressibleNavierStokes.interpolate_u_p Method
interpolate_u_p(u, setup) -> AnyInterpolate velocity to pressure points (differentiable version).
sourceIncompressibleNavierStokes.interpolate_ω_p! Method
interpolate_ω_p!(ωp, ω, setup) -> AnyInterpolate vorticity to pressure points (in-place version).
sourceIncompressibleNavierStokes.interpolate_ω_p Method
interpolate_ω_p(ω, setup) -> AnyInterpolate vorticity to pressure points (differentiable version).
sourceIncompressibleNavierStokes.kinetic_energy! Method
kinetic_energy!(ke, u, setup; interpolate_first) -> AnyCompute kinetic energy field (in-place version).
sourceIncompressibleNavierStokes.kinetic_energy Method
kinetic_energy(u, setup; kwargs...) -> AnyCompute kinetic energy field interpolate_first is true, it is given by
Otherwise, it is given by
as in [14].
Differentiable version.
sourceIncompressibleNavierStokes.laplacian! Method
laplacian!(L, p, setup) -> AnyCompute Laplacian of pressure field (in-place version).
sourceIncompressibleNavierStokes.laplacian Method
laplacian(p, setup) -> AnyCompute Laplacian of pressure field (differentiable version).
sourceIncompressibleNavierStokes.left Method
left(I::CartesianIndex{D}, i) -> Any
left(I::CartesianIndex{D}, i, n) -> AnyLeft index n times away in direction i.
IncompressibleNavierStokes.pressuregradient! Method
pressuregradient!(G, p, setup) -> AnyCompute pressure gradient (in-place version).
sourceIncompressibleNavierStokes.pressuregradient Method
pressuregradient(p, setup) -> AnyCompute pressure gradient (differentiable version).
sourceIncompressibleNavierStokes.qcrit Method
qcrit(u, setup) -> AnyCompute
IncompressibleNavierStokes.right Method
right(I::CartesianIndex{D}, i) -> Any
right(I::CartesianIndex{D}, i, n) -> AnyRight index n times away in direction i.
IncompressibleNavierStokes.scalewithvolume! Method
scalewithvolume!(p, setup) -> AnyScale scalar field with volume sizes (in-place version).
sourceIncompressibleNavierStokes.scalewithvolume Method
scalewithvolume(p, setup) -> AnyScale scalar field p with volume sizes (differentiable version).
IncompressibleNavierStokes.total_kinetic_energy Method
total_kinetic_energy(u, setup; kwargs...) -> AnyCompute total kinetic energy. The velocity components are interpolated to the volume centers and squared.
sourceIncompressibleNavierStokes.unit_cartesian_indices Method
unit_cartesian_indices(D) -> AnyGet tuple of all unit vectors as Cartesian indices.
sourceIncompressibleNavierStokes.vorticity! Method
vorticity!(ω, u, setup) -> AnyCompute vorticity field (in-place version).
sourceIncompressibleNavierStokes.vorticity Method
vorticity(u, setup) -> AnyCompute vorticity field (differentiable version).
sourceIncompressibleNavierStokes.δ Method
δ(setup, p, i, I) -> AnyDifferentiate scalar
IncompressibleNavierStokes.δ Method
δ(setup, u, i, j, I) -> AnyDifferentiate vector i and j are known at compile-time to remove the if-statement.