Skip to main content

outram_foam_basic_lib/fv_options/
semi_implicit.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. See `src/lib.rs` for the full licence
8// notice.
9
10// Upstream source: src/fvModels/general/semiImplicitSource/.
11
12//! A general explicit/implicit source on one field.
13
14use super::{CellSelection, SourceContribution};
15
16/// A constant source term with an explicit and an implicit part.
17///
18/// Upstream's `semiImplicitSource`, the simplest `fvModel` there is, and the
19/// one that exercises the mechanism end to end without any physics of its own.
20///
21/// # Units
22///
23/// Both parts are **per unit volume**, in the units of the equation's residual;
24/// see [`SourceContribution`]. The cell volume is applied when the contribution
25/// is placed into the matrix.
26#[derive(Debug, Clone, PartialEq)]
27pub struct SemiImplicitSource {
28    name: String,
29    field: String,
30    selection: CellSelection,
31    contribution: SourceContribution,
32}
33
34impl SemiImplicitSource {
35    /// A source named `name` on the equation for `field`, over `selection`.
36    ///
37    /// `explicit` is added to the right-hand side; `implicit` is the
38    /// coefficient of the solved variable, where a **negative** value is a sink
39    /// and stabilises the matrix.
40    #[must_use]
41    pub fn new(
42        name: impl Into<String>,
43        field: impl Into<String>,
44        selection: CellSelection,
45        explicit: f64,
46        implicit: f64,
47    ) -> Self {
48        Self {
49            name: name.into(),
50            field: field.into(),
51            selection,
52            contribution: SourceContribution { explicit, implicit },
53        }
54    }
55
56    /// The model's name.
57    #[must_use]
58    pub fn name(&self) -> &str {
59        &self.name
60    }
61
62    /// The field whose equation this contributes to.
63    #[must_use]
64    pub fn field_name(&self) -> &str {
65        &self.field
66    }
67
68    /// The cells acted on.
69    #[must_use]
70    pub fn selection(&self) -> &CellSelection {
71        &self.selection
72    }
73
74    /// The per-unit-volume contribution.
75    #[must_use]
76    pub fn contribution(&self) -> SourceContribution {
77        self.contribution
78    }
79}