Skip to content

HMath.PDE

Module index · Numerical conventions

Description

Structured-grid reference PDEs in one, two or three spatial dimensions. Coordinates use consistent caller-selected length units; diffusivity is L²/T, velocity LT and reaction 1T. Nodes are row-major, last axis fastest. Nonperiodic axes include both endpoints; periodic axes exclude the upper endpoint. Boundary derivatives are outward normal derivatives, not fluxes.

FD uses nodal kappa*(-Laplacian); FV uses conservative arithmetic face kappa and half control volumes at physical faces. Q1 FEM uses two-point tensor Gauss quadrature, a consistent mass matrix, and natural boundary integrals (cf. https://mfem.org/tutorial/fem/). FEM supports nonperiodic grids. Spectral paths require periodic axes. Sparse assembly is bounded to 32768 nodes (FEM 2048); dense reference solves/time evolution to 1024 nodes.

On this page

API Purpose
Grid Opaque Cartesian grid with positive representable spacings and 1..3 axes.
grid Construct a grid with >=3 nodes per axis; reject overflowing counts and rounded-away duplicate coordinates.
gridShape Number of nodes along each axis, preserving last-axis-fastest storage order.
gridCoordinates Physical coordinates in flat storage order; periodic upper endpoints are omitted.
gridSpacing Positive uniform distance between adjacent nodes on each axis.
flattenIndex Checked conversion of zero-based multidimensional node coordinates to a row-major flat index.
unflattenIndex Inverse checked row-major index conversion.
Boundary Constant essential value, outward derivative, au+bdu/dn=c, or paired periodic faces.
Dirichlet Declaration and type contract below.
Neumann Declaration and type contract below.
Robin Declaration and type contract below.
Periodic Declaration and type contract below.
Discretization Nodal nondivergence FD, conservative face-flux FV, or tensor-product Q1 Galerkin FEM.
FiniteDifference Declaration and type contract below.
FiniteVolume Declaration and type contract below.
FiniteElement Declaration and type contract below.
PDEOperator Opaque assembled stiffness, source mass matrix, boundary load and essential constraints.
assemblePDE Assemble -kappa*Laplacian (FD) or -div(kappa grad) (FV/FEM) plus constant reaction; coefficient field is positive at every node.
pdeStiffness Read the canonical sparse stiffness and source mass operators; essential rows are identity/zero respectively.
pdeMass Read the canonical sparse stiffness and source mass operators; essential rows are identity/zero respectively.
pdeBoundaryLoad Read boundary contributions, including prescribed values at essential rows.
PDEResult Nodal solution with independently recomputed infinity residual; errorEstimate reports backward residual only.
PDEResult Declaration and type contract below.
pdeValues Computed grid solution values in the solver's documented spatial order.
pdeResidual Residual measure at the returned grid solution.
pdeErrorEstimate Solver-specific discretization/error estimate; not a universal certified bound.
solveElliptic Dense pivoted reference solve and independently recomputed infinity residual.
poisson Solve a unit-diffusivity zero-reaction Poisson problem with the selected spatial discretization.
laplace Solve the corresponding homogeneous-source boundary-value problem.
helmholtz Solve -Laplacian(u)-k²u=f; resonances/singular systems fail.
spatialGradient Second-order central spatial gradients; physical endpoints use second-order one-sided stencils.
laplacianStencil Apply the FD Laplacian with ghost normal/Robin boundary data.
spectralDerivative Periodic Fourier collocation derivative of order 0..8 along one axis; odd real Nyquist derivatives are zero.
spectralLaplacian Sum periodic second Fourier derivatives over all spatial axes.
spectralPoisson Solve (-Laplacian+reaction)u=f spectrally; reaction>=0, and zero reaction requires a mean-free source with zero-mean solution gauge.
pseudoSpectralDiffusion Pseudospectral divergence(kappa*gradient u).
methodOfLines Method of lines with a constant assembled operator and checked time-source callback.
heat Explicit heat/diffusion uses RK4, with a conservative forward-Euler CFL check (therefore valid for RK4 too).
diffusion Variable positive nodal diffusivity, chosen spatial method and increasing output times; FEM uses a stricter consistent-mass CFL bound.
wave Periodic velocity-Verlet wave equation u_tt=c² Laplacian(u); returns u at requested equally or unequally spaced increasing times.
advection Conservative first-order upwind periodic advection, central conservative variable-coefficient diffusion.
advectionDiffusion Periodic upwind advection plus central diffusion using explicit Euler and the combined positivity CFL bound.
stabilityLimit Conservative explicit positivity bound 1sum(|v|h+2*kappa/h^2); infinity denotes a zero spatial operator.
cflNumber Requested nonnegative timestep divided by the conservative combined stability limit.
manufacturedError Maximum absolute nodal difference from a finite exact-solution callback; this measures continuum error when an exact solution is known.

Documentation

Grid

data Grid Source #

Opaque Cartesian grid with positive representable spacings and 1..3 axes.

Instances

Instances details
Show Grid Source # 
Instance details

Defined in HMath.PDE

Methods

showsPrec :: Int -> Grid -> ShowS #

show :: Grid -> String #

showList :: [Grid] -> ShowS #

Eq Grid Source # 
Instance details

Defined in HMath.PDE

Methods

(==) :: Grid -> Grid -> Bool #

(/=) :: Grid -> Grid -> Bool #

grid

grid :: [Int] -> [(Double, Double)] -> [Bool] -> Either MathError Grid Source #

Construct a grid with >=3 nodes per axis; reject overflowing counts and rounded-away duplicate coordinates.

gridShape

gridShape :: Grid -> [Int] Source #

Number of nodes along each axis, preserving last-axis-fastest storage order.

gridCoordinates

gridCoordinates :: Grid -> [[Double]] Source #

Physical coordinates in flat storage order; periodic upper endpoints are omitted.

gridSpacing

gridSpacing :: Grid -> [Double] Source #

Positive uniform distance between adjacent nodes on each axis.

flattenIndex

flattenIndex :: Grid -> [Int] -> Either MathError Int Source #

Checked conversion of zero-based multidimensional node coordinates to a row-major flat index.

unflattenIndex

unflattenIndex :: Grid -> Int -> Either MathError [Int] Source #

Inverse checked row-major index conversion.

Boundary

data Boundary Source #

Constant essential value, outward derivative, a*u+b*du/dn=c, or paired periodic faces.

Instances

Instances details
Show Boundary Source # 
Instance details

Defined in HMath.PDE

Eq Boundary Source # 
Instance details

Defined in HMath.PDE

Discretization

data Discretization Source #

Nodal nondivergence FD, conservative face-flux FV, or tensor-product Q1 Galerkin FEM.

Instances

Instances details
Show Discretization Source # 
Instance details

Defined in HMath.PDE

Eq Discretization Source # 
Instance details

Defined in HMath.PDE

PDEOperator

data PDEOperator Source #

Opaque assembled stiffness, source mass matrix, boundary load and essential constraints.

Instances

Instances details
Show PDEOperator Source # 
Instance details

Defined in HMath.PDE

Eq PDEOperator Source # 
Instance details

Defined in HMath.PDE

assemblePDE

assemblePDE :: Discretization -> Grid -> [(Boundary, Boundary)] -> [Double] -> Double -> Either MathError PDEOperator Source #

Assemble -kappa*Laplacian (FD) or -div(kappa grad) (FV/FEM) plus constant reaction; coefficient field is positive at every node.

pdeStiffness

pdeStiffness :: PDEOperator -> Sparse Double Source #

Read the canonical sparse stiffness and source mass operators; essential rows are identity/zero respectively.

pdeMass

pdeMass :: PDEOperator -> Sparse Double Source #

Read the canonical sparse stiffness and source mass operators; essential rows are identity/zero respectively.

pdeBoundaryLoad

pdeBoundaryLoad :: PDEOperator -> [Double] Source #

Read boundary contributions, including prescribed values at essential rows.

PDEResult

data PDEResult Source #

Nodal solution with independently recomputed infinity residual; errorEstimate reports backward residual only.

Constructors

PDEResult 

Fields

Instances

Instances details
Show PDEResult Source # 
Instance details

Defined in HMath.PDE

Eq PDEResult Source # 
Instance details

Defined in HMath.PDE

solveElliptic

solveElliptic :: PDEOperator -> [Double] -> Either MathError PDEResult Source #

Dense pivoted reference solve and independently recomputed infinity residual. The error estimate is backward residual, not continuum error.

poisson

poisson :: Discretization -> Grid -> [(Boundary, Boundary)] -> [Double] -> Either MathError PDEResult Source #

Solve a unit-diffusivity zero-reaction Poisson problem with the selected spatial discretization.

laplace

laplace :: Discretization -> Grid -> [(Boundary, Boundary)] -> Either MathError PDEResult Source #

Solve the corresponding homogeneous-source boundary-value problem.

helmholtz

helmholtz :: Discretization -> Grid -> [(Boundary, Boundary)] -> Double -> [Double] -> Either MathError PDEResult Source #

Solve -Laplacian(u)-k²u=f; resonances/singular systems fail.

spatialGradient

spatialGradient :: Grid -> [Double] -> Either MathError [[Double]] Source #

Second-order central spatial gradients; physical endpoints use second-order one-sided stencils.

laplacianStencil

laplacianStencil :: Grid -> [(Boundary, Boundary)] -> [Double] -> Either MathError [Double] Source #

Apply the FD Laplacian with ghost normal/Robin boundary data. Essential rows return prescribed-value minus current-value residuals.

spectralDerivative

spectralDerivative :: Grid -> Int -> Int -> [Double] -> Either MathError [Double] Source #

Periodic Fourier collocation derivative of order 0..8 along one axis; odd real Nyquist derivatives are zero.

spectralLaplacian

spectralLaplacian :: Grid -> [Double] -> Either MathError [Double] Source #

Sum periodic second Fourier derivatives over all spatial axes.

spectralPoisson

spectralPoisson :: Grid -> Double -> [Double] -> Either MathError PDEResult Source #

Solve (-Laplacian+reaction)u=f spectrally; reaction>=0, and zero reaction requires a mean-free source with zero-mean solution gauge.

pseudoSpectralDiffusion

pseudoSpectralDiffusion :: Grid -> [Double] -> [Double] -> Either MathError [Double] Source #

Pseudospectral divergence(kappa*gradient u). Products are evaluated at collocation nodes; no implicit de-aliasing, so caller must resolve coefficients.

methodOfLines

methodOfLines :: Method -> PDEOperator -> (Double -> [Double]) -> [Double] -> [Double] -> Either MathError Trajectory Source #

Method of lines with a constant assembled operator and checked time-source callback. Essential Dirichlet values remain constant in time; initial state must satisfy them. Consistent FEM mass is inverted on unconstrained rows.

heat

heat :: Grid -> [(Boundary, Boundary)] -> Double -> [Double] -> [Double] -> Either MathError Trajectory Source #

Explicit heat/diffusion uses RK4, with a conservative forward-Euler CFL check (therefore valid for RK4 too). Positive diffusivity and ordered times.

diffusion

diffusion :: Discretization -> Grid -> [(Boundary, Boundary)] -> [Double] -> [Double] -> [Double] -> Either MathError Trajectory Source #

Variable positive nodal diffusivity, chosen spatial method and increasing output times; FEM uses a stricter consistent-mass CFL bound.

wave

wave :: Grid -> Double -> [Double] -> [Double] -> [Double] -> Either MathError [[Double]] Source #

Periodic velocity-Verlet wave equation u_tt=c² Laplacian(u); returns u at requested equally or unequally spaced increasing times. Spectral Laplacian.

advection

advection :: Grid -> [Double] -> [Double] -> [Double] -> Either MathError [[Double]] Source #

Conservative first-order upwind periodic advection, central conservative variable-coefficient diffusion. Explicit Euler preserves constants and total mass for periodic data when the combined positivity CFL is satisfied.

advectionDiffusion

advectionDiffusion :: Grid -> [Double] -> Double -> [Double] -> [Double] -> Either MathError [[Double]] Source #

Periodic upwind advection plus central diffusion using explicit Euler and the combined positivity CFL bound.

stabilityLimit

stabilityLimit :: Grid -> Double -> [Double] -> Either MathError Double Source #

Conservative explicit positivity bound 1sum(|v|h+2*kappa/h^2); infinity denotes a zero spatial operator.

cflNumber

cflNumber :: Grid -> Double -> [Double] -> Double -> Either MathError Double Source #

Requested nonnegative timestep divided by the conservative combined stability limit.

manufacturedError

manufacturedError :: Grid -> ([Double] -> Double) -> [Double] -> Either MathError Double Source #

Maximum absolute nodal difference from a finite exact-solution callback; this measures continuum error when an exact solution is known.