Skip to main content

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

d(operand, coord)
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

grad(operand)
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

div(operand)
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

curl(operand)
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

RadialComponent(operand)
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)
= d3.AngularComponent(u, 1)  # Colatitude component

Tensor Operations

TransposeComponents

TransposeComponents(operand)
Transpose tensor components.

Example

τ = dist.TensorField(coords)
τT = τ.T  # Equivalent to TransposeComponents(τ)  

Trace

Trace(operand)
Compute trace of a tensor.

Example

import dedalus.public as d3  

σ = dist.TensorField(coords)
tr_σ = d3.Trace(σ)

Skew

Skew(operand)
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

Average(operand, coords)
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

dt(operand)  
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(operand, basis, n)
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(operand, bases)
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

Grid(operand)
Force evaluation in grid space.

Coeff

Coeff(operand)
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:
AliasFull NameDescription
dtTimeDerivativeTime derivative
gradGradientGradient operator
divDivergenceDivergence operator
curlCurlCurl operator
lapLaplacianLaplacian operator
integIntegrateIntegration over coordinates
aveAverageAverage over coordinates
transTransposeComponentsTranspose tensor components
transposeTransposeComponentsTranspose tensor components
skewSkewSkew-symmetric part of tensor
traceTraceTrace of tensor
compComponentExtract tensor component
radialRadialComponentRadial component in spherical coords
angularAngularComponentAngular component on sphere
azimuthalAzimuthalComponentAzimuthal component
liftLiftBoundary 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

Build docs developers (and LLMs) love