pub struct TemperatureTable { /* private fields */ }Expand description
A monotone-in-temperature lookup table with linear interpolation and end-clamping.
Upstream’s Function1<scalar> table entry. Two knots are the usual case
for a phase-change coefficient — one value below the freezing point, another
above it — which makes the function ramp linearly across the interval
between them instead of stepping discontinuously.
§Units
temperatures are kelvin [K]. values have whatever unit the owning
model gives them — a rate [1/s] for
SolidificationPorosity’s drag D(T), a
dimensionless fraction [-] for
VofSolidificationMelting’s
alphaSolid(T). The table itself does not know and does not check.
§Valid ranges
temperatures must be strictly ascending; values need not be monotone
in either direction (the drag table descends, and a fraction table may do
either). A query outside the tabulated range returns the nearest end value
rather than extrapolating, which is Function1’s table behaviour and is
what lets a two-knot table act as a smoothed step.
Implementations§
Source§impl TemperatureTable
impl TemperatureTable
Sourcepub fn new(temperatures: Vec<f64>, values: Vec<f64>) -> Self
pub fn new(temperatures: Vec<f64>, values: Vec<f64>) -> Self
Build a table from ascending temperatures [K] and their values.
§Panics
Panics if the two vectors differ in length, if either is empty, or if the temperatures are not strictly ascending. All three are case-setup errors that would otherwise yield a silently wrong coefficient, so they fail loudly at construction rather than at the first lookup.
Sourcepub fn two_knot(
t_cold: f64,
t_hot: f64,
cold_value: f64,
hot_value: f64,
) -> Self
pub fn two_knot( t_cold: f64, t_hot: f64, cold_value: f64, hot_value: f64, ) -> Self
A two-knot table: cold_value at and below t_cold, hot_value at and
above t_hot, linear in between.
This is the shape both upstream examples use — (330 10000) (330.5 0)
for the drag table, (330 1) (335 0) for the solid-fraction table.
§Panics
Panics if t_hot <= t_cold.
Sourcepub fn value(&self, t: f64) -> f64
pub fn value(&self, t: f64) -> f64
The tabulated value at temperature t [K], clamped at both ends.
Sourcepub fn temperatures(&self) -> &[f64]
pub fn temperatures(&self) -> &[f64]
The tabulated temperatures [K], ascending.