Skip to main content

outram_foam_basic_lib/thermophysics/
error.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/// Errors produced by the specie-level thermophysics layer.
23#[derive(Debug, Clone, PartialEq)]
24pub enum ThermoError {
25    /// Newton T-inversion exhausted all iterations without meeting the
26    /// convergence tolerance (|ΔT/T| < 1e-6). Carries the last iterate.
27    NonConvergent { max_iter: usize, last_t: f64 },
28}
29
30impl std::fmt::Display for ThermoError {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            ThermoError::NonConvergent { max_iter, last_t } => write!(
34                f,
35                "Newton T-inversion did not converge after {max_iter} iterations \
36                 (last T = {last_t:.2} K)"
37            ),
38        }
39    }
40}
41
42impl std::error::Error for ThermoError {}