use crate::structures::{BlockageFraction, CulvertBarrel, StructureError};
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CulvertOutletRow {
pub barrel: CulvertBarrel,
pub length_m: f64,
pub manning_n: f64,
pub entrance_loss: f64,
pub slope: f64,
pub gravity_m_per_s2: f64,
pub face_blockage: BlockageFraction,
}
impl CulvertOutletRow {
pub(crate) fn check(&self) -> Result<(), StructureError> {
let fields = format!(
"length_m={:?},manning_n={:?},entrance_loss={:?},slope={:?},gravity_m_per_s2={:?}",
self.length_m, self.manning_n, self.entrance_loss, self.slope, self.gravity_m_per_s2
);
let positive = [
(self.length_m, "barrel length in metres"),
(self.manning_n, "Manning n in s/m^(1/3)"),
(
self.gravity_m_per_s2,
"gravity in metres per second squared",
),
];
for (value, what) in positive {
if !(value.is_finite() && value > 0.0) {
return Err(StructureError::definition(format!(
"{fields}: supply a finite positive {what}"
)));
}
}
if !(self.entrance_loss.is_finite() && self.entrance_loss >= 0.0) {
return Err(StructureError::definition(format!(
"{fields}: supply a finite nonnegative entrance loss coefficient"
)));
}
if !self.slope.is_finite() {
return Err(StructureError::definition(format!(
"{fields}: supply a finite barrel slope in metres per metre"
)));
}
let rise = self.barrel.open_rise_m();
if self.slope * self.length_m < -0.5 * rise {
let bed = match self.barrel.floor() {
Some(floor) => format!(",sediment_depth_m={:?}", floor.sediment_depth_m),
None => String::new(),
};
return Err(StructureError::definition(format!(
"{fields},rise_m={rise:?}{bed}: the outlet invert sits more than half the rise above the inlet invert. Supply an adverse fall of at most rise/2"
)));
}
Ok(())
}
}