Skip to main content

outram_foam_basic_lib/math/
mod.rs

1// SPDX-License-Identifier: GPL-3.0-only
2// Copyright (C) 2026 OUTRAM PARK contributors
3// Derived from OpenFOAM (www.openfoam.com)
4// Copyright (C) 2004-2023 OpenFOAM Foundation
5// Copyright (C) 2016-2023 OpenCFD Ltd.
6//
7// This file is part of OUTRAM PARK.
8//
9// OUTRAM PARK is free software: you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by the
11// Free Software Foundation, either version 3 of the License, or (at your
12// option) any later version.
13//
14// OUTRAM PARK is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17// General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License along
20// with OUTRAM PARK.  If not, see <https://www.gnu.org/licenses/>.
21
22//! Special mathematical functions used by the thermophysics and statistics
23//! kernels.
24//!
25//! Ports the OpenFOAM `primitives/functions/Math` helpers: the inverse error
26//! function ([`erf_inv`](crate::math::erf_inv::erf_inv)), the regularised lower/upper incomplete gamma
27//! functions and their unnormalised forms
28//! ([`inc_gamma_ratio_p`](crate::math::inc_gamma::inc_gamma_ratio_p),
29//! [`inc_gamma_ratio_q`](crate::math::inc_gamma::inc_gamma_ratio_q),
30//! [`inc_gamma_p`](crate::math::inc_gamma::inc_gamma_p),
31//! [`inc_gamma_q`](crate::math::inc_gamma::inc_gamma_q)), and the inverse of
32//! the regularised lower incomplete gamma
33//! ([`inv_inc_gamma`](crate::math::inv_inc_gamma::inv_inc_gamma)). All arguments and
34//! results are dimensionless `f64`.
35
36//! It also hosts [`parallel`](crate::math::parallel), the **batched** root finders — bisection, Brent,
37//! bracket-safeguarded Newton, and batched closed-form polynomial roots — each
38//! dispatched across [`crate::compute::ComputeBackend`]. They live here rather
39//! than under `polynomial/` because the general case solves a caller-supplied
40//! residual such as `h(T) - h_target`, which is not a polynomial at all, and
41//! because this module is already where the crate's iterative inversions live.
42
43pub mod differentiate;
44pub mod erf_inv;
45pub mod inc_gamma;
46pub mod inv_inc_gamma;
47pub mod minimise;
48pub mod parallel;
49
50pub use differentiate::{
51    derivative, derivative_backend_for, derivative_batch, jacobian, jacobian_batch,
52    jacobian_batch_backend_for, jacobian_column_backend_for, ode_system_jacobian, DerivativeBatch,
53    DerivativeSolution, DiffBatchFailure, DiffScheme, DiffSettings, DiffStatus, JacobianBatch,
54    JacobianSolution, NumericalJacobian, CBRT_EPSILON, DERIVATIVE_BATCH_MIN_POINTS,
55    FIFTH_ROOT_EPSILON, JACOBIAN_BATCH_MIN_PROBLEMS, JACOBIAN_COLUMN_MIN_DIMENSION,
56};
57pub use erf_inv::erf_inv;
58pub use inc_gamma::{inc_gamma_p, inc_gamma_q, inc_gamma_ratio_p, inc_gamma_ratio_q};
59pub use inv_inc_gamma::inv_inc_gamma;
60pub use minimise::{
61    golden_section_batch, minimise_backend_for, MinBatch, MinBatchFailure, MinProblem, MinSettings,
62    MinSolution, MinStatus, Sense, GOLDEN_RATIO, MINIMISE_BATCH_MIN_PROBLEMS, SQRT_EPSILON,
63};
64pub use parallel::{
65    cubic_roots_batch, linear_roots_batch, poly_roots_backend_for, quadratic_roots_batch,
66    root_batch_backend_for, solve_bracketed_batch, solve_newton_batch, RootBatch, RootBatchFailure,
67    RootMethod, RootProblem, RootSettings, RootSolution, RootStatus,
68};