Guide
Documentation may not be accurate as this is a beta stage package undergoing changes. Get started with tutorials which are more up to date.
Scalar & vector fields
Scalar & vector fields are represented as 2d/3d arrays of canonically scalars or vectors. Array values can alternatively be any type that Supports addition & multiplication.
Customizable grid
Grid — TypeGrid(resolutions, [origin], [sz])
Grid(resolutions, rmax)
Grid(cell, [origin], [sz])Constructs Grid struct Used downstream for interpolation (both read/write). Grids can be in any dimension and be Boundless or bounded. At minimum, a grid stores its discretization cell and origin in pixels. For an orthogonal grid, supply a list of resolutions in each dimension. For non-orthogonal grid, supply the cell vectors as a column-wise matrix. Origin by default is at index (1, ...).
Bounded grids compute and store additional info eg position vectors and their norms of all grid points. To construct bounded grid, supply the overall integer pixel size sz. For bounded cubic grid, use convenience constructor with rmax
Params
resolutions: list of resolutions in each dimension for orthogonal gridsorigin: indices of the origin, may be decimal valuedsz: integer size (pixel dimensions) of bounded gridrmax: halflength (in length units, not pixels) of bounded cubic gridcell: column-wise matrix of discretization cell vectors
fields
Examples
Grid((0.1,)) # 1d grid spaced 0.1 apart with origin at (1,) Grid((0.1, 0.2), (2, 5)) # 2d grid spaced 0.1 along x and 0.2 along y, with origin at (2 ,5) Grid((0.1, 0.1), 20.0) # bounded 2d grid spaced 0.1 apart, halflength 20.0, with origin at (201, 201), pixel size (401, 401) Grid(0.1 * [1 1 0; 1 0 1; 1 1 1]', ones(3), (10, 12, 15)) # bounded 3d grid with cell vectors [.1, .1, 0], [.1, 0, .1], .1, .1, .1. origin (1, 1, 1), pixel size (10, 12, 15). can construct lattice this way
Particle mesh placement and interpolation
Base.get — Methodget(collection, key, default)Return the value stored for the given key, or the given default value if no mapping for the key is present.
For tuples and numbers, this function requires at least Julia 1.7.
Examples
julia> d = Dict("a"=>1, "b"=>2);
julia> get(d, "a", 3)
1
julia> get(d, "c", 3)
3Base.get(field::AbstractArray, grid::Grid, rvec::AbstractVector)
Base.put!(
field::AbstractArray,
grid::Grid,
rvec::AbstractVector,
val::AbstractVector,
)With grid info we can interpolate a scalar or vector field at any location. We can also place a scalar or vector point source anywhere with automatic normalization wrt discretization. Both work via a proximity weighted average of the closest grid points (in general up to 4 in 2d and 8 in 3d).
Finite difference equivariant operators
Op — TypeOp(radfunc, rmax, cell::AbstractMatrix; kw...)constructs equivariant operator
function (m::Op)(x::AbstractArray, )Del — Function" Del(cell; pad = :same, border = :smooth)
constructs gradient operator
Laplacian — FunctionLaplacian(cell; pad = :same, border = :smooth)constructs Laplacian operator
Examples
Gaussian — FunctionGaussian(cell, σ, rmax; kw...)constructs Normalized Gaussian diffusion operator
Lower level utilities
Convolutions
Feature rich convolution and cross correlation functions with options for padding, stride, boundary conditions, and custom products (tensor field convolutions).
cvconv — Functioncvconv(x, f; product = *, stride = 1, pad = 0, alg = nothing)"convolution" in computer vision for any dimension, same as Cross correlation. Automatically uses FFT for big kernels. For convolution in signal processing , use dspconv instead.
x input array f filter array product product in convolution, eg *, dot pad amount of padding or padding option
- any integer number of pixels on each boundary
:same: adds enough padding so ouoverlapdotut is same size as input:outer: ouoverlapdotut size issize(x) .+ size(f) .- 1
border type of padding
0value pixels:replicaterepeats edge valuesperiodicor:circular: periodic BC:smoothcontinuous derivatives at boundaries useful for differential operators:reflectreflects interior across boundaries which are not repeated:symmetricsame as:reflectbut with boundaries repeated
alg specifies convolution algorithm
nothingAutomatically chooses fastest algorithm:directconvolution, scales as O(n^2):fftFourier convolution, scales as O(n log(n))
Convolutions in other Julia packages, fewer features but perhaps more optimized for speed in their specific use cases
- ImageFiltering.imfilter. Its docs has excellent mathematical explaination of convolutions and correlation as well as padding/border options
DSP.convDSP.xcorFlux.conv
dspconv — Functiondspconv(x, f; product = *,pad = :outer,border=0)
Convolution in signal processing. For "convolution" in computer vision, use cvconv instead. Automatically uses FFT for big kernels. By default output size is size(x) .+ size(f) .- 1. See cvconv for its keyword options which also apply here