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:
- Use the system partitioning strategy (SPS)
- 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 fwhere ā (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). f̄ and f̌ are the associated reduced
right-hand side vectors. The K̄ (K-bar) matrix is the reduced discrete Laplacian operator and Ǩ (K-check) is a
correction matrix. The Ḵ (K-underline) and K̰ (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 Fwhere ℓ 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) = 0The 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§
- Equation
Handler - Implements a tool to handle the equation numbering such as unknown and prescribed equations due to the essential boundary conditions.
- Essential
Bcs1d - Manages essential (Dirichlet) boundary conditions for 1D PDE problems
- Essential
Bcs2d - 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
- Natural
Bcs1d - Manages natural (Neumann) boundary conditions for 1D PDE problems
- Natural
Bcs2d - Manages natural (Neumann) boundary conditions for 2D PDE problems
- Problem
Samples - 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
- Transfinite
Samples
Enums§
- Side
- Specifies the (boundary) side of a rectangle
Type Aliases§
- FnVec1
Param1 - Calculates a vector v(r) given one scalar parameter r
- FnVec1
Param2 - Calculates a vector v(r,s) given two scalar parameter r and s
- FnVec2
Param2 - Calculates two vectors u(r,s) and v(r,s) given two scalar parameters r and s
- FnVec3
Param2 - 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