Skip to main content

tpt_sci_grid/
lib.rs

1//! # tpt-sci-grid
2//!
3//! Structured finite-difference grids and stencils for the `tpt-science`
4//! pillar: uniform 1-D, 2-D and 3-D tensor-product grids, finite-difference
5//! stencil coefficients, and assembly of discrete PDE operators (Laplacians)
6//! on those grids.
7//!
8//!
9//! This crate is built from scratch (no wrap target — see `spec.txt`). It is
10//! motivated by the compartmental-ODE / structured-grid spatial-model needs of
11//! `tpt-soma` and `tpt-cerebrum` (reaction–diffusion, cable-equation /
12//! cortical-sheet style models).
13//!
14//! The assembled operators are returned as [`DMatrix`] / [`DVector`] from the
15//! `tpt-math` dense linear-algebra substrate ([`linalg`]), which is an in-house,
16//! dual-licensed (MIT OR Apache-2.0) backend with no `nalgebra`/`faer` license
17//! exposure, per the workspace policy in ADR 0007.
18//!
19//! ## Example
20//!
21//! ```rust
22//! use tpt_sci_grid::{laplacian_1d, UniformGrid1D, Boundary};
23//!
24//! let g = UniformGrid1D::new(11, 0.0, 1.0).unwrap();
25//! let l = laplacian_1d(&g, Boundary::Dirichlet);
26//! assert_eq!(l.nrows(), 11);
27//! assert_eq!(l.ncols(), 11);
28//! ```
29
30pub mod error;
31pub mod grid;
32pub mod operator;
33#[cfg(feature = "sparse")]
34pub mod sparse;
35pub mod stencil;
36
37pub use error::GridError;
38pub use grid::{Boundary, UniformGrid1D, UniformGrid2D, UniformGrid3D, linspace};
39pub use operator::{derivative_1d, kron, laplacian_1d, laplacian_2d, laplacian_3d};
40pub use stencil::Stencil;
41
42#[cfg(feature = "sparse")]
43pub use sparse::{
44    CsrMatrix, diffuse_step, laplacian_1d_sparse, laplacian_2d_sparse, laplacian_3d_sparse,
45};
46
47/// The `tpt-math` linear-algebra substrate this crate builds on.
48pub use tpt_math_linalg as linalg;
49
50/// Dense matrix / vector types re-exported from the `tpt-math` substrate so
51/// callers can consume assembled operators without a separate dependency.
52pub use tpt_math_linalg::tpt_math_linalg_dense::{DMatrix, DVector};