Skip to main content

outram_foam_basic_lib/
prelude.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/// Convenience re-export of the most commonly used types and functions.
23///
24/// ```rust
25/// use outram_foam_basic_lib::prelude::*;
26/// ```
27///
28/// # What's included
29///
30/// **Primitives** (Layer 1a)
31/// - Scalar constants: `SMALL`, `VSMALL`, `GREAT`, `VGREAT`, `ROOT_SMALL`, `ROOT_VSMALL`
32/// - Types: `Vector3`, `Tensor`, `SymmTensor`, `SphericalTensor`
33///
34/// **Polynomial algebra** (Layers 1c + 1d)
35/// - Root types: `RootType`, `Roots`
36/// - Equation solvers: `LinearEqn`, `QuadraticEqn`, `CubicEqn`
37/// - Function evaluation: `Polynomial`
38///
39/// **Math special functions** (Layer 1g)
40/// - `erf_inv`, `inc_gamma_ratio_p`, `inc_gamma_ratio_q`, `inc_gamma_p`, `inc_gamma_q`, `inv_inc_gamma`
41///
42/// **Specie-level thermophysics** (Layer 1h)
43/// - Custom quantity: `Compressibility` (ψ = ∂ρ/∂p|T, s²/m²)
44/// - EOS traits/types: `EquationOfState`, `PerfectGas`, `RhoConst`
45/// - Thermo traits/types: `ThermoModel`, `HConstThermo`, `JanafThermo`
46/// - Transport traits/types: `TransportModel`, `ConstTransport`, `SutherlandTransport`
47// --- Primitive scalars ---
48pub use crate::primitives::{GREAT, ROOT_GREAT, ROOT_SMALL, ROOT_VSMALL, SMALL, VGREAT, VSMALL};
49
50// --- Primitive tensor types ---
51pub use crate::primitives::{SphericalTensor, SymmTensor, Tensor, Vector3};
52
53// --- Spectral decomposition (Layer 1a) ---
54pub use crate::primitives::{
55    eigen_values, eigen_values_checked, eigen_values_symm, eigen_vectors, eigen_vectors_symm,
56    eigen_vectors_symm_with, eigen_vectors_with,
57};
58
59// --- Polynomial algebra ---
60pub use crate::polynomial::{CubicEqn, LinearEqn, Polynomial, QuadraticEqn, RootType, Roots};
61
62// --- Math special functions ---
63pub use crate::math::{
64    erf_inv, inc_gamma_p, inc_gamma_q, inc_gamma_ratio_p, inc_gamma_ratio_q, inv_inc_gamma,
65};
66
67// --- Dense matrices (Layer 1b) ---
68pub use crate::matrix::{MatrixError, SquareMatrix};
69
70// --- ODE solvers (Layer 1e) ---
71pub use crate::ode::{
72    DynSystemIntegrator, Euler, NoTypedSystem, OdeError, OdeIntegrator, OdeSolver, OdeSolverConfig,
73    OdeSystem, Rkf45, Rosenbrock23, SharedOdeSystem, TypedStateIntegrator,
74};
75
76// --- Interpolation (Layer 1f) ---
77pub use crate::interpolation::{interpolate_spline_xy, interpolate_xy};
78
79// --- Specie-level thermophysics (Layer 1h) ---
80pub use crate::thermophysics::eos::*;
81pub use crate::thermophysics::error::ThermoError;
82pub use crate::thermophysics::quantities::Compressibility;
83pub use crate::thermophysics::thermo::*;
84pub use crate::thermophysics::transport::*;
85
86// --- Fields (Layer 2) ---
87pub use crate::fields::{
88    BoundaryCondition, Field, PatchField, SurfaceField, SurfaceScalarField, SurfaceVectorField,
89    VolField, VolScalarField, VolSymmTensorField, VolTensorField, VolVectorField,
90};
91
92// --- Mesh (Layer 2) ---
93pub use crate::mesh::{
94    AmiCoupling, AmiOverlap, AmiWeight, BoundaryPatch, CyclicCoupling, FvMesh, FvMeshBuilder,
95    MeshError, PatchKind, RegionInterface,
96};
97
98// --- AMI (arbitrary mesh interface) overlap weighting ---
99pub use crate::mesh::ami::overlap_weights_1d;
100
101// --- Sparse linear system (Layer 2) ---
102pub use crate::ldu_matrix::{FvMatrix, FvVectorMatrix, LduMatrix, SolverPerformance, SolverSettings};
103
104// --- FV operators (Layer 3) ---
105pub use crate::fv_operators::{adjust_phi, fvc, fvm};
106
107// --- KNP central-upwind face flux (rhoCentralFoam kernel, Layer 3) ---
108pub use crate::fv_operators::fvc::central_upwind::{KnpFaceFlux, KnpFaceState, KnpWaveSpeeds};
109
110// --- Non-orthogonal (mesh-quality) correction for the Laplacian ---
111pub use crate::fv_operators::fvc::grad_least_squares;
112pub use crate::fv_operators::fvm::{
113    laplacian_corrected, max_non_orthogonality_deg, non_ortho_geometry,
114    solve_laplacian_non_orthogonal, NonOrthoGeometry, NonOrthoScheme,
115};
116
117// --- Optional equation sources, OpenFOAM `fvOptions` / `fvModels` (Layer 3) ---
118pub use crate::fv_options::{
119    CellSelection, EquationField, FvModel, FvModels, MomentumEquationForm, SemiImplicitSource,
120    SolidificationMelting, SolidificationMeltingCoefficients, SolidificationPorosity,
121    SourceContribution, TemperatureTable, VofSolidificationMelting,
122};
123
124// --- Field-level tensor algebra (tr/symm/two_symm/dev/dev2 on vol fields) ---
125pub use crate::fields::vol_field_algebra;
126
127// --- Field-level fluid thermodynamics (Layer 4) ---
128pub use crate::fluid_thermo::{ConstSolidThermo, FluidThermo, PsiThermo, RhoThermo, SolidThermo};
129
130// --- LDU solvers ---
131pub use crate::ldu_matrix::{conjugate_gradient, gamg, gauss_seidel};
132
133// --- FvMatrix/FvVectorMatrix bridge onto the asymmetric Krylov solvers ---
134pub use crate::ldu_matrix::{
135    krylov_solve, krylov_solve_prepared, KrylovMethod, KrylovOptions, PreconditionerKind,
136};
137
138// --- Asymmetric Krylov solvers + preconditioners ---
139pub use crate::krylov::{
140    bicgstab, bicgstab_prepared, gmres, gmres_prepared, Ilu0Preconditioner, JacobiPreconditioner,
141    KrylovResult, KrylovSettings, Preconditioner,
142};
143
144// -- Interface ---
145//
146// Basically, OpenFOAM primitives aren't easy to use.
147// But I want some functions that can help construct and use them
148pub use crate::interface;
149
150// Steady heat conduction with an energy balance (gh:#949)
151pub use crate::steady_conduction::{
152    radial_mesh, voxel_mesh, ConductionMesh, EnergyBalance, PatchCondition, RadialClosedForm,
153    RadialGeometry, RadialLayer, RadialShell, SteadyConductionError, SteadyConductionProblem,
154    SteadyConductionSettings, SteadyConductionSolution, ThermalBoundary, VoxelGrid, VoxelMesh,
155};
156
157// TVD flux limiters (translated from OpenFOAM limitedSchemes)
158pub use crate::limiters::FluxLimiter;
159
160// --- Hybrid execution backend (dispatch only, no kernels) ---
161//
162// `ComputeBackend::Serial` is always available and is the oracle every other
163// backend is verified against; `CpuMulti` needs the `parallel` feature and
164// `Gpu` the `gpu` feature plus an actual adapter. `select_backend` is the one
165// named policy function that decides between them.
166pub use crate::compute::{
167    gpu_adapter_present, select_backend, ComputeBackend, ThreadCount, CPU_MULTI_MIN_WORK_ITEMS,
168    GPU_MIN_WORK_ITEMS,
169};
170
171// --- Parallel field algebra: policy items ONLY ---
172//
173// The kernels themselves (`add`, `sub`, `sum`, `min`, `max`, `scale`, `dot`,
174// ...) are deliberately NOT re-exported here: those names would collide on
175// sight with `std` and with `ldu_matrix::parallel`. Call them path-qualified,
176// e.g. `fields::parallel::add(backend, &a, &b)`.
177pub use crate::fields::parallel::{
178    field_parallel_crossover, should_parallelise, FIELD_PARALLEL_CROSSOVER, REDUCTION_CHUNK,
179};
180
181// --- Hybrid LDU sparse matrix-vector product + Krylov vector operations ---
182//
183// `HybridLdu` carries the cell-gather topology that makes the parallel SpMV
184// bit-for-bit identical to the serial oracle. The free vecops are exported
185// under `ldu_` prefixes here because bare `dot`/`axpy` would read ambiguously
186// beside `fields::parallel`'s reductions; call them path-qualified if the
187// prefix is unwanted.
188pub use crate::ldu_matrix::parallel::{
189    axpy as ldu_axpy, dot as ldu_dot, norm_l1 as ldu_norm_l1, norm_l2 as ldu_norm_l2,
190    scale as ldu_scale, spmv_backend_for, vecop_backend_for, HybridLdu, LduTopology, CELL_BLOCK,
191    REDUCTION_BLOCK, SPMV_MIN_CELLS, VECOP_MIN_ELEMENTS,
192};
193
194// --- Batched root finding on the hybrid backend (Layer 1) ---
195pub use crate::math::parallel::{
196    cubic_roots_batch, linear_roots_batch, poly_roots_backend_for, quadratic_roots_batch,
197    root_batch_backend_for, solve_bracketed_batch, solve_newton_batch, RootBatch, RootBatchFailure,
198    RootMethod, RootProblem, RootSettings, RootSolution, RootStatus,
199};
200
201// --- Batched 1-D golden-section extremum search (Layer 1) ---
202//
203// Generalised from `tampines-steam-tables`' choked-flow `golden_section_max_g`
204// rather than written afresh. `Sense` exists because the production caller
205// MAXIMISES, and negating internally would flip the sign of returned values
206// under the caller's feet.
207pub use crate::math::minimise::{
208    golden_section_batch, minimise_backend_for, MinBatch, MinBatchFailure, MinProblem, MinSettings,
209    MinSolution, MinStatus, Sense, GOLDEN_RATIO, MINIMISE_BATCH_MIN_PROBLEMS, SQRT_EPSILON,
210};
211
212// --- Batched numerical integration on the hybrid backend (Layer 1) ---
213//
214// ODE ensembles (N independent IVPs) and batched quadrature (N independent
215// definite integrals). `MAX_ADAPTIVE_DEPTH` is deliberately not re-exported —
216// it is an internal safety ceiling, not a tuning knob.
217pub use crate::ode::parallel::{
218    adaptive_quadrature_batch, ensemble_backend_for, integrate_ensemble, integrate_ensemble_mixed,
219    quadrature_backend_for, quadrature_batch, AdaptiveSettings, GaussOrder, OdeEnsemble,
220    OdeEnsembleFailure, OdeLane, OdeLaneSolution, OdeLaneStatus, QuadratureBatch,
221    QuadratureBatchFailure, QuadratureInterval, QuadratureRule, QuadratureSolution,
222    QuadratureStatus, ODE_ENSEMBLE_MIN_LANES, QUADRATURE_MIN_INTERVALS,
223};
224
225// --- Finite differences and batched Jacobians on the hybrid backend (Layer 1) ---
226//
227// `NumericalJacobian` supplies `OdeSystem::jacobian` numerically, so
228// `Rosenbrock23` runs on a system that has not hand-coded one — the default
229// impl of that method panics.
230pub use crate::math::differentiate::{
231    derivative, derivative_backend_for, derivative_batch, jacobian, jacobian_batch,
232    jacobian_batch_backend_for, jacobian_column_backend_for, ode_system_jacobian, DerivativeBatch,
233    DerivativeSolution, DiffBatchFailure, DiffScheme, DiffSettings, DiffStatus, JacobianBatch,
234    JacobianSolution, NumericalJacobian, CBRT_EPSILON, DERIVATIVE_BATCH_MIN_POINTS,
235    FIFTH_ROOT_EPSILON, JACOBIAN_BATCH_MIN_PROBLEMS, JACOBIAN_COLUMN_MIN_DIMENSION,
236};