Overview
The operators module provides differential operators, grid functions, and other operations for building equations. All operators return deferred expression trees that are evaluated lazily during timestepping or problem solving.
Differential Operators
Differentiate
Differentiate with respect to a coordinate.
Parameters
- operand: Field or expression to differentiate
- coord (Coordinate): Coordinate for differentiation
Example
import dedalus.public as d3
coords = d3.CartesianCoordinates('x', 'y', 'z')
u = dist.Field(coords, name='u')
# First derivative
du_dx = d3.d(u, coords['x'])
# Second derivative
d2u_dx2 = d3.d(d3.d(u, coords['x']), coords['x'])
Gradient
Compute gradient of a scalar field.
Returns
Vector field containing the gradient.
Example
import dedalus.public as d3
T = dist.ScalarField(name='T')
∇T = d3.grad(T) # Returns VectorField
Divergence
Compute divergence of a vector field.
Returns
Scalar field containing the divergence.
Example
import dedalus.public as d3
u = dist.VectorField(coords, name='u')
∇_dot_u = d3.div(u) # Returns ScalarField
Laplacian
lap(operand, coords=None)
Compute Laplacian (∇²).
Parameters
- operand: Field to operate on
- coords (CoordinateSystem, optional): Coordinates for Laplacian
Example
import dedalus.public as d3
T = dist.ScalarField(name='T')
∇2T = d3.lap(T)
Curl
Compute curl of a vector field (3D only).
Returns
Vector field containing the curl.
Example
import dedalus.public as d3
B = dist.VectorField(coords, name='B') # Magnetic field
J = d3.curl(B) # Current density
Component Selection
Component
Component(operand, index)
Extract a component from a vector or tensor.
Example
u = dist.VectorField(coords)
ux = u[0] # x-component
uy = u[1] # y-component
uz = u[2] # z-component
RadialComponent
Extract radial component in spherical coordinates.
Example
import dedalus.public as d3
coords = d3.SphericalCoordinates('phi', 'theta', 'r')
u = dist.VectorField(coords)
ur = d3.RadialComponent(u)
AngularComponent
AngularComponent(operand, index)
Extract angular component on a sphere.
Example
import dedalus.public as d3
coords = d3.S2Coordinates('phi', 'theta')
u = dist.VectorField(coords)
uθ = d3.AngularComponent(u, 1) # Colatitude component
Tensor Operations
TransposeComponents
TransposeComponents(operand)
Transpose tensor components.
Example
τ = dist.TensorField(coords)
τT = τ.T # Equivalent to TransposeComponents(τ)
Trace
Compute trace of a tensor.
Example
import dedalus.public as d3
σ = dist.TensorField(coords)
tr_σ = d3.Trace(σ)
Skew
Compute skew-symmetric part of a tensor.
Example
import dedalus.public as d3
A = dist.TensorField(coords)
A_skew = d3.Skew(A) # (A - A^T) / 2
Integration and Averaging
Integrate
Integrate(operand, coords)
Integrate over specified coordinates.
Parameters
- operand: Expression to integrate
- coords: Coordinate(s) to integrate over
Example
import dedalus.public as d3
T = dist.Field(name='T')
# Average over x
T_avg = d3.Integrate(T, coords['x']) / Lx
# Total integral
total = d3.Integrate(T, coords)
Average
Compute average over coordinates.
Example
import dedalus.public as d3
u = dist.Field()
u_mean = d3.Average(u, coords['x'])
Grid Functions
UnaryGridFunction
UnaryGridFunction(func, arg)
Apply a numpy ufunc in grid space.
Example
import dedalus.public as d3
import numpy as np
T = dist.Field()
sin_T = np.sin(T) # Automatically creates UnaryGridFunction
exp_T = np.exp(T)
abs_T = np.abs(T)
GeneralFunction
GeneralFunction(dist, domain, tensorsig, dtype, layout, func, args=[], kw={})
General function wrapper for custom operations.
Example
import dedalus.public as d3
import numpy as np
def custom_func(x, y):
return x**2 + y**2
# Use in equations
result = d3.GeneralFunction(
dist, domain, (), np.float64, 'g',
custom_func, args=[x, y]
)
Time Derivatives
TimeDerivative
Time derivative operator for IVPs.
Example
import dedalus.public as d3
u = dist.Field(name='u')
ν = 0.01
# Heat equation
problem = d3.IVP([u])
problem.add_equation("dt(u) - ν*lap(u) = 0")
Boundary Operations
Lift
Lift a lower-dimensional field using boundary terms.
Parameters
- operand: Expression to lift
- basis (Basis): Basis to lift into
- n (int): Boundary index (-1 for lower, +1 for upper)
Example
import dedalus.public as d3
# Tau method with lifting
τ1 = dist.Field(name='τ1')
τ2 = dist.Field(name='τ2')
problem = d3.LBVP([u, τ1, τ2])
problem.add_equation("lap(u) + lift(τ1,-1) + lift(τ2,+1) = f")
problem.add_equation("u(x='left') = 0")
problem.add_equation("u(x='right') = 0")
Interpolation
Interpolate
Interpolate(operand, coord, position)
Interpolate field to a specific position.
Example
import dedalus.public as d3
u = dist.Field()
u_mid = d3.Interpolate(u, coord, 0.5) # Interpolate to x=0.5
Coordinate Conversions
Convert
Convert field to different bases.
Example
import dedalus.public as d3
u_full = dist.Field(bases=(xbasis, ybasis))
u_x = d3.Convert(u_full, xbasis) # Project onto x-basis only
Grid/Coefficient Access
Grid
Force evaluation in grid space.
Coeff
Force evaluation in coefficient space.
CFL Conditions
AdvectiveCFL
AdvectiveCFL(velocity, timestep)
Compute advective CFL number.
Example
import dedalus.public as d3
u = dist.VectorField(coords)
CFL = d3.AdvectiveCFL(u, 0.01)
max_CFL = np.max(CFL['g'])
Common Operator Aliases
Dedalus provides convenient shorthand aliases for frequently used operators:
| Alias | Full Name | Description |
|---|
dt | TimeDerivative | Time derivative |
grad | Gradient | Gradient operator |
div | Divergence | Divergence operator |
curl | Curl | Curl operator |
lap | Laplacian | Laplacian operator |
integ | Integrate | Integration over coordinates |
ave | Average | Average over coordinates |
trans | TransposeComponents | Transpose tensor components |
transpose | TransposeComponents | Transpose tensor components |
skew | Skew | Skew-symmetric part of tensor |
trace | Trace | Trace of tensor |
comp | Component | Extract tensor component |
radial | RadialComponent | Radial component in spherical coords |
angular | AngularComponent | Angular component on sphere |
azimuthal | AzimuthalComponent | Azimuthal component |
lift | Lift | Boundary lifting operator |
These aliases are available directly in the namespace after import dedalus.public as d3. For example, d3.grad(u) is equivalent to d3.Gradient(u).
See Also