Skip to main content

Crate russell_pde

Crate russell_pde 

Source
Expand description

Russell - Rust Scientific Library

russell_pde: Solvers for ordinary differential equations and differential algebraic equations

Important: This crate depends on external libraries (non-Rust). Thus, please check the Installation Instructions on the GitHub Repository.

To account for the EBCs, two approaches are possible:

  1. Use the system partitioning strategy (SPS)
  2. Use the Lagrange multipliers method (LMM)

§Approach 1: System partitioning strategy (SPS)

Consider the following partitioning of the vectors a and f and the matrix K:

┌       ┐ ┌   ┐   ┌   ┐
│ K̄   Ǩ │ │ ̄a │   │ f̄ │
│       │ │   │ = │   │
│ Ḵ   ̰K │ │ ǎ │   │ f̌ │
└       ┘ └   ┘   └   ┘
    K       a       f

where (a-bar) is a reduced vector containing only the unknown values (i.e., non-EBC nodes), and (a-check) is a reduced vector containing only the prescribed values (i.e., EBC nodes). and are the associated reduced right-hand side vectors. The (K-bar) matrix is the reduced discrete Laplacian operator and (K-check) is a correction matrix. The (K-underline) and (K-under-tilde) matrices are often not needed.

Thus, the linear system to be solved is:

K̄ ā = f̄ - Ǩ ǎ

§Approach 2: Lagrange multipliers method (LMM)

The LMM consists of augmenting the original linear system with additional equations:

┌       ┐ ┌   ┐   ┌   ┐
│ K  Cᵀ │ │ a │   │ f │
│       │ │   │ = │   │
│ C  0  │ │ ℓ │   │ ǎ │
└       ┘ └   ┘   └   ┘
    M       A       F

where is the vector of Lagrange multipliers, C is the constraints matrix, and is the vector of prescribed values at EBC nodes. The constraints matrix C has a row for each EBC (prescribed) node and a column for every node. Each row in C has a single 1 at the column corresponding to the EBC node, and 0s elsewhere.

§Examples

Solve the Poisson equation in 1D with homogeneous Dirichlet boundary conditions:

-d²ϕ/dx² = 1   on  x ∈ [0, 1]

ϕ(0) = 0
ϕ(1) = 0

The analytical solution is ϕ(x) = (x - x²) / 2.

use russell_lab::approx_eq;
use russell_pde::{EssentialBcs1d, Fdm1d, Grid1d, NaturalBcs1d, Side, StrError};

fn main() -> Result<(), StrError> {
    // grid
    let xmin = 0.0;
    let xmax = 1.0;
    let nx = 4;
    let mut grid = Grid1d::new_uniform(xmin, xmax, nx)?;

    // Essential BCs
    let mut ebcs = EssentialBcs1d::new();
    ebcs.set(Side::Xmin, |_| 0.0);
    ebcs.set(Side::Xmax, |_| 0.0);

    // Natural BCs (none)
    let nbcs = NaturalBcs1d::new();

    // FDM solver
    let kx = 1.0;
    let fdm = Fdm1d::new(grid, ebcs, nbcs, kx)?;

    // Solve system
    let alpha = 0.0; // Poisson
    let source = |_| 1.0;
    let phi = fdm.solve_sps(alpha, source)?;

    // Check
    fdm.for_each_coord(|m, x| {
        let analytical = x * (1.0 - x) / 2.0;
        approx_eq(phi[m], analytical, 1e-14);
    });
    Ok(())
}

Structs§

EquationHandler
Implements a tool to handle the equation numbering such as unknown and prescribed equations due to the essential boundary conditions.
EssentialBcs1d
Manages essential (Dirichlet) boundary conditions for 1D PDE problems
EssentialBcs2d
Manages essential (Dirichlet) boundary conditions for 2D PDE problems
Fdm1d
Implements the Finite Difference Method (FDM) for 1D problems
Fdm2d
Implements the Finite Difference Method (FDM) for 2D problems
Grid1d
Defines a one-dimensional grid with node coordinates
Grid2d
Defines a 2D Cartesian grid
Metrics
Calculates and stores the metrics coefficients for a given mapping between reference and physical coordinates
NaturalBcs1d
Manages natural (Neumann) boundary conditions for 1D PDE problems
NaturalBcs2d
Manages natural (Neumann) boundary conditions for 2D PDE problems
ProblemSamples
Spc1d
Implements the Spectral Collocation Method (SPC) for 1D problems
Spc2d
Implements the Spectral Collocation Method (SPC) for 2D problems
SpcMap2d
Implements the Spectral Collocation Method (SPC) for 2D problems with curvilinear coordinates
Transfinite2d
Implements the transfinite mapping
Transfinite3d
Implements the transfinite mapping
TransfiniteSamples

Enums§

Side
Specifies the (boundary) side of a rectangle

Type Aliases§

FnVec1Param1
Calculates a vector v(r) given one scalar parameter r
FnVec1Param2
Calculates a vector v(r,s) given two scalar parameter r and s
FnVec2Param2
Calculates two vectors u(r,s) and v(r,s) given two scalar parameters r and s
FnVec3Param2
Calculates three vectors u(r,s), v(r,s) and w(r,s) given two scalar parameters r and s
StrError
Defines the error output as a static string