Skip to main content

Crate numra_pde

Crate numra_pde 

Source
Expand description

PDE (Partial Differential Equation) solvers for Numra.

This crate provides the Method of Lines (MOL) approach for solving PDEs:

  1. Discretize spatial derivatives using finite differences (FDM)
  2. Convert the PDE to a system of ODEs in time
  3. Solve using ODE solvers from numra-ode

§Supported Equation Types

  • Parabolic PDEs: Heat equation, diffusion equations
  • Moving boundary problems: Stefan problem, phase change
  • Reaction-diffusion: Turing patterns, combustion

§Example: 1D Heat Equation

use numra_pde::{Grid1D, HeatEquation1D, MOLSystem};
use numra_pde::boundary::DirichletBC;
use numra_ode::{DoPri5, Solver, SolverOptions};

// Create spatial grid
let grid = Grid1D::uniform(0.0_f64, 1.0, 51);

// Heat equation with diffusivity α = 0.01
let pde = HeatEquation1D::new(0.01);

// Boundary conditions: T(0) = 1, T(1) = 0
let bc_left = DirichletBC::new(1.0);
let bc_right = DirichletBC::new(0.0);

// Create MOL system
let mol = MOLSystem::new(pde, grid.clone(), bc_left, bc_right);

// Initial condition: T(x,0) = sin(πx)
let u0: Vec<f64> = grid.points()
    .iter()
    .map(|&x| (std::f64::consts::PI * x).sin())
    .collect();

// Solve (interior points only)
let options = SolverOptions::default().rtol(1e-6);
let result = DoPri5::solve(&mol, 0.0, 0.5, &u0[1..u0.len()-1], &options);

§Moving Boundary Problems

For problems like the Stefan problem where the domain boundary moves:

∂T/∂t = α ∂²T/∂x²,  0 < x < s(t)
T(0,t) = T_hot
T(s(t),t) = T_melt
ds/dt = -k ∂T/∂x |_{x=s(t)}  (Stefan condition)

Use the moving module with coordinate transforms.

Author: Moussa Leblouba Date: 9 February 2026 Modified: 2 May 2026

Re-exports§

pub use boundary::BoundaryCondition;
pub use boundary::DirichletBC;
pub use boundary::NeumannBC;
pub use boundary::PeriodicBC;
pub use boundary::RobinBC;
pub use boundary2d::BoundaryConditions2D;
pub use boundary2d::BoundaryConditions3D;
pub use moving::Bound;
pub use moving::CoordinateTransform;
pub use moving::Domain1D;
pub use moving::MovingBound;
pub use moving::StefanCondition;

Modules§

boundary
Boundary conditions for PDE problems.
boundary2d
Boundary conditions for 2D and 3D PDE problems.
moving
Moving boundary infrastructure for problems like the Stefan problem.

Structs§

AdvectionDiffusion2D
2D Advection-Diffusion: u_t = D*(u_xx + u_yy) - vxu_x - vyu_y.
AdvectionDiffusion3D
3D Advection-Diffusion: u_t = D*(u_xx + u_yy + u_zz) - vxu_x - vyu_y - vz*u_z.
DiffusionReaction1D
1D Diffusion-Reaction equation: ∂u/∂t = D ∂²u/∂x² + f(u).
FDM
Finite Difference Method utilities.
Grid1D
1D uniform or non-uniform grid.
Grid2D
2D grid (tensor product of 1D grids).
Grid3D
3D grid (tensor product of 1D grids).
HeatEquation1D
1D Heat (diffusion) equation: ∂u/∂t = α ∂²u/∂x².
HeatEquation2D
2D Heat (diffusion) equation: u_t = alpha * (u_xx + u_yy).
HeatEquation3D
3D Heat (diffusion) equation: u_t = alpha * (u_xx + u_yy + u_zz).
MOLSystem
Method of Lines system that wraps a PDE for use with ODE solvers.
MOLSystem2D
2D Method of Lines system.
MOLSystem3D
3D Method of Lines system.
Operator2DCoefficients
Coefficients for a general 2D operator: au_xx + bu_yy + cu_x + du_y + e*u
Operator3DCoefficients
Coefficients for a general 3D operator: au_xx + bu_yy + cu_zz + du_x + eu_y + fu_z + g*u
ParametricMOLSystem2D
Parametric 2D Method of Lines system.
ParametricMOLSystem3D
Parametric 3D Method of Lines system. See crate::ParametricMOLSystem2D for the parameter layout, linearity argument, and BC handling notes — they apply identically here.
ReactionDiffusion2D
2D Reaction-Diffusion: u_t = D*(u_xx + u_yy) + R(t, x, y, u).
ReactionDiffusion3D
3D Reaction-Diffusion: u_t = D*(u_xx + u_yy + u_zz) + R(t, x, y, z, u).
Stencil
Finite difference stencil coefficients.

Enums§

DifferenceScheme
Difference scheme type.

Traits§

PdeSystem
Trait for 1D PDE systems that can be solved via MOL.
Scalar
A real scalar type suitable for numerical computation.
SparseScalar
Trait alias for the faer bounds needed by SparseMatrix. Both f32 and f64 satisfy these bounds.

Functions§

assemble_laplacian_2d
Assemble 2D Laplacian as a sparse matrix for interior grid points.
assemble_laplacian_3d
Assemble 3D Laplacian as a sparse matrix for interior grid points.
assemble_operator_2d
Assemble a general 2D FDM operator as a sparse matrix.
assemble_operator_3d
Assemble a general 3D FDM operator as a sparse matrix.