hydr_structures/structures/gate/
parameters.rs1use super::GateApplicability;
4use crate::structures::{StructureError, StructureInputErrorKind};
5
6#[derive(Clone, Debug, PartialEq)]
8pub struct GateParameters {
9 width_m: f64,
10 sill_m: f64,
11 maximum_opening_m: f64,
12 discharge_coefficient: f64,
13 gravity_m_per_s2: f64,
14 applicability: GateApplicability,
15}
16impl GateParameters {
17 pub fn new(
19 width_m: f64,
20 sill_m: f64,
21 maximum_opening_m: f64,
22 discharge_coefficient: f64,
23 gravity_m_per_s2: f64,
24 applicability: GateApplicability,
25 ) -> Result<Self, StructureError> {
26 applicability.check()?;
27 if !sill_m.is_finite()
28 || [
29 width_m,
30 maximum_opening_m,
31 discharge_coefficient,
32 gravity_m_per_s2,
33 ]
34 .iter()
35 .any(|value| !value.is_finite() || *value <= 0.0)
36 {
37 return Err(StructureError::input(
38 StructureInputErrorKind::Definition,
39 format!(
40 "width_m={width_m},sill_m={sill_m},maximum_opening_m={maximum_opening_m},discharge_coefficient={discharge_coefficient},gravity_m_per_s2={gravity_m_per_s2}: supply finite sill and positive finite width, maximum opening, coefficient, and gravity"
41 ),
42 ));
43 }
44 Ok(Self {
45 width_m,
46 sill_m,
47 maximum_opening_m,
48 discharge_coefficient,
49 gravity_m_per_s2,
50 applicability,
51 })
52 }
53 pub fn width_m(&self) -> f64 {
55 self.width_m
56 }
57 pub fn sill_m(&self) -> f64 {
59 self.sill_m
60 }
61 pub fn maximum_opening_m(&self) -> f64 {
63 self.maximum_opening_m
64 }
65 pub fn discharge_coefficient(&self) -> f64 {
67 self.discharge_coefficient
68 }
69 pub fn gravity_m_per_s2(&self) -> f64 {
71 self.gravity_m_per_s2
72 }
73 pub fn applicability(&self) -> &GateApplicability {
75 &self.applicability
76 }
77}