1 /**
2     libs.weirs.weir module
3 */
4 module libs.weirs.weir;
5 
6 import std.math : pow;
7 
8 /**
9     Base class for weirs
10 */
11 class Weir 
12 {
13     enum Units
14     {
15         METRIC,
16         ENGLISH
17     }
18 
19     ///////////////////////////////////////
20     //  Constants                        //
21     ///////////////////////////////////////
22     protected const double ERROR = 0.0001;             // Allowed accuracy in iteration
23     
24     ///////////////////////////////////////
25     //  Properties                       //
26     ///////////////////////////////////////
27     protected double TRIAL_INCREMENT = 0.0001;
28     /// Total discharge that will flow over a weir.
29     protected double discharge;
30     
31     /// Length of the topmost of the crest
32     protected double crestLength;
33 
34     /// Elevation of crest.
35     protected double crestElev;
36 
37     /// Elevation of upstream apron.
38     protected double usApronElev;
39     
40     /// Elevation of downstream apron.
41     protected double dsApronElev;
42 
43     /// Water elevation if there will be no weir.
44     protected double tailwaterElev;
45 
46     /// Discharge intensity. Discharge per unit width.
47     protected double dischargeIntensity;
48 
49     /// Discharge intensity used for trial and error.
50     protected double calculatedDischargeIntensity;
51 
52     /// Elevation of the highest water elevation after weir construction.
53     protected double affluxElevation;
54 
55     /// Length of hydraulic jump. Downstream apron length can be designed
56     /// based on this.
57     protected double lengthOfHydraulicJump;
58 
59     /// Elevation of pre-jump
60     protected double preJumpElev;
61 
62     /// Elevation of hydraulic jump.
63     protected double jumpElev;
64 
65     /// Info about calculation error.
66     string errorMessage;
67 
68     protected Units unit = Units.METRIC;
69 
70     ///////////////////////////////////////
71     //  Setters                          //
72     ///////////////////////////////////////
73     /**
74      Sets the discharge.
75      Params:
76         pDeischarge = discharge in either cubic meter per second or
77      cubic foot per second.
78     */
79     public void setDischarge(double pDischarge)
80     {
81         if (unit == Units.ENGLISH)
82         {
83             discharge = pDischarge * pow(1 / 3.28, 3);
84         } 
85         else 
86         {
87             discharge = pDischarge;
88         }
89     }
90 
91     public void setUSApronElev(double elev)
92     {
93         if (unit == Units.ENGLISH)
94         {
95             usApronElev = elev / 3.28;
96         } 
97         else 
98         {
99             usApronElev = elev;
100         }
101     }
102 
103     public void setDSApronElev(double elev)
104     {
105         if (unit == Units.ENGLISH)
106         {
107             dsApronElev = elev / 3.28;
108         } 
109         else 
110         {
111             dsApronElev = elev;
112         }
113     }
114 
115     public void setCrestLength(double l)
116     {
117         if (unit == Units.ENGLISH)
118         {
119             crestLength = l / 3.28;
120         } 
121         else 
122         {
123             crestLength = l;
124         }
125     }
126 
127     public void setCrestElev(double elev)
128     {
129         if (unit == Units.ENGLISH)
130         {
131             crestElev = elev / 3.28;
132         } 
133         else 
134         {
135             crestElev = elev;
136         }
137     }
138 
139     public void setTailwaterElev(double elev)
140     {
141         if (unit == Units.ENGLISH)
142         {
143             tailwaterElev = elev / 3.28;
144         } 
145         else 
146         {
147             tailwaterElev = elev;
148         }
149     }
150 
151     ///////////////////////////////////////
152     //  Getters                          //
153     ///////////////////////////////////////
154     /** 
155     Returns the rate of flow in either cubic meter per second (metric)
156     or cubic feet per second (english). 
157     */
158     public double getDischarge()
159     {
160         if (unit == Units.ENGLISH)
161         {
162             return discharge * pow(3.28, 3);
163         } else {
164             return discharge;        }
165     }
166 
167     public double getAffluxElevation()
168     {
169         if (unit == Units.ENGLISH)
170         {
171             return affluxElevation * 3.25;
172         }
173         else
174         {
175             return affluxElevation;
176         }
177     }
178 
179     public double getLengthOfHydraulicJump()
180     {
181         if (unit == Units.ENGLISH)
182         {
183             return lengthOfHydraulicJump * 3.28;
184         }
185         else
186         {
187             return lengthOfHydraulicJump;
188         }
189     }
190 }