MEASUR-Tools-Suite v1.0.11
The MEASUR Tools Suite is a collection of industrial efficiency calculations written in C++ and with bindings for compilation to WebAssembly.
Loading...
Searching...
No Matches
CompressedAirLeakSurvey.h
1#ifndef TOOLS_SUITE_COMPRESSEDAIRLEAKSURVEY_H
2#define TOOLS_SUITE_COMPRESSEDAIRLEAKSURVEY_H
3
4#include <exception>
5#include <stdexcept>
6#include <vector>
7
8#include "treasureHunt/CompressedAirReduction.h"
9
10#ifndef M_PI
11 #define M_PI 3.14159265358979323846
12#endif
13
14// BagMethodData implemented in CompressedAirReduction.h
15// BagMethod is now used for all new logic and data flow
16
18 public:
19 EstimateMethodData(const double leakRateEstimate) : leakRateEstimate(leakRateEstimate) {}
20
21 double getLeakRateEstimate() const { return leakRateEstimate; }
22
23 private:
24 double leakRateEstimate;
25};
26
28 public:
29 DecibelsMethodData(const double linePressure, const double decibels, const double decibelRatingA,
30 const double pressureA, const double firstFlowA, const double secondFlowA,
31 const double decibelRatingB, const double pressureB, const double firstFlowB,
32 const double secondFlowB)
33 : linePressure(linePressure), decibels(decibels), decibelRatingA(decibelRatingA), pressureA(pressureA),
34 firstFlowA(firstFlowA), secondFlowA(secondFlowA), decibelRatingB(decibelRatingB), pressureB(pressureB),
35 firstFlowB(firstFlowB), secondFlowB(secondFlowB) {}
36
37 double calculate() {
38 const double denominator = (pressureB - pressureA) * (decibelRatingB - decibelRatingA);
39 const double leakRateEstimate =
40 ((pressureB - linePressure) * (decibelRatingB - decibels)) / denominator * firstFlowA +
41 ((linePressure - pressureA) * (decibelRatingB - decibels)) / denominator * secondFlowA +
42 ((pressureB - linePressure) * (decibels - decibelRatingA)) / denominator * firstFlowB +
43 ((linePressure - pressureA) * (decibels - decibelRatingA)) / denominator * secondFlowB;
44
45 return leakRateEstimate;
46 }
47
48 private:
49 double linePressure; // X
50 double decibels; // Y
51 double decibelRatingA; // Y1
52 double pressureA; // X1
53 double firstFlowA; // Q11
54 double secondFlowA; // Q21
55 double decibelRatingB; // Y2
56 double pressureB; // X2
57 double firstFlowB; // Q12
58 double secondFlowB; // Q22
59};
60
62 public:
63 OrificeMethodData(const double airTemp, const double atmPressure, const double dischargeCoef, const double diameter,
64 const double supplyPressure, const int numOrifices)
65 : airTemp(airTemp), atmPressure(atmPressure), dischargeCoef(dischargeCoef), diameter(diameter),
66 supplyPressure(supplyPressure), numOrifices(numOrifices) {}
67
68 double calculate() {
69 const double caPressurePSIA = atmPressure + supplyPressure;
70
71 // convert to rankine for density calcs
72 const double airTempRankine = airTemp + 459.67;
73
74 const double caDensity = caPressurePSIA * 144 / (53.34 * airTempRankine);
75 const double standardDensity = atmPressure * 144 / (53.34 * airTempRankine);
76 const double sonicDensity = caDensity * std::pow((2 / 2.4), (1 / .4));
77
78 const double leakVelocity = std::pow(((2 * 1.4) / (1.4 + 1)) * 53.34 * airTempRankine * 32.2, 0.5);
79 const double leakRateLBMmin =
80 sonicDensity * (diameter * diameter) * (M_PI / (4 * 144)) * leakVelocity * 60 * dischargeCoef;
81 const double leakRateScfm = leakRateLBMmin / standardDensity;
82 const double leakRateEstimate = leakRateScfm * numOrifices;
83 return leakRateEstimate;
84 }
85
86 private:
87 double airTemp, atmPressure, dischargeCoef, diameter, supplyPressure;
88 int numOrifices;
89};
90
92 public:
93 CompressedAirLeakSurveyInput(const int hoursPerYear, const int utilityType, const double utilityCost,
94 const int measurementMethod, const EstimateMethodData estimateMethodData,
95 const DecibelsMethodData decibelsMethodData, const BagMethod bagMethod,
96 const OrificeMethodData orificeMethodData,
97 const CompressorElectricityData compressorElectricityData, const int units)
98 : hoursPerYear(hoursPerYear), utilityType(utilityType), utilityCost(utilityCost),
99 measurementMethod(measurementMethod), estimateMethodData(estimateMethodData),
100 decibelsMethodData(decibelsMethodData), bagMethod(bagMethod), orificeMethodData(orificeMethodData),
101 compressorElectricityData(compressorElectricityData), units(units) {}
102
103 int getHoursPerYear() const { return hoursPerYear; } // operating time
104 int getUtilityType() const { return utilityType; }
105 int getMeasurementMethod() const { return measurementMethod; }
106 int getUnits() const { return units; }
107 double getUtilityCost() const { return utilityCost; }
108 EstimateMethodData getEstimateMethodData() const { return estimateMethodData; }
109 DecibelsMethodData getDecibelsMethodData() const { return decibelsMethodData; }
110 BagMethod getBagMethod() const { return bagMethod; }
111 OrificeMethodData getOrificeMethodData() const { return orificeMethodData; }
112 CompressorElectricityData getCompressorElectricityData() const { return compressorElectricityData; }
113
114 private:
115 int hoursPerYear, utilityType;
116 double utilityCost;
117 int measurementMethod;
118 EstimateMethodData estimateMethodData;
119 DecibelsMethodData decibelsMethodData;
120 BagMethod bagMethod;
121 OrificeMethodData orificeMethodData;
122 CompressorElectricityData compressorElectricityData;
123 int units;
124};
125
127 public:
128 struct Output {
129 Output(double annualTotalElectricity, double annualTotalElectricityCost, double totalFlowRate,
130 double annualTotalFlowRate)
131 : annualTotalElectricity(annualTotalElectricity), annualTotalElectricityCost(annualTotalElectricityCost),
132 totalFlowRate(totalFlowRate), annualTotalFlowRate(annualTotalFlowRate) {}
133
134 Output() = default;
135 double annualTotalElectricity = 0, annualTotalElectricityCost = 0, totalFlowRate = 0, annualTotalFlowRate = 0;
136 };
137
138 CompressedAirLeakSurvey(std::vector<CompressedAirLeakSurveyInput> compressedAirLeakSurveyInputVec)
139 : compressedAirLeakSurveyInputVec(compressedAirLeakSurveyInputVec) {}
140
142 double annualTotalElectricity = 0, annualTotalElectricityCost = 0, totalFlowRate = 0, annualTotalFlowRate = 0;
143
144 for (auto& compressedAirLeakSurveyInput : compressedAirLeakSurveyInputVec) {
145 double tmpAnnualTotalElectricity = 0, tmpAnnualTotalElectricityCost = 0, tmpTotalFlowRate = 0,
146 tmpAnnualTotalFlowRate = 0;
147
148 // estimate method
149 if (compressedAirLeakSurveyInput.getMeasurementMethod() == 0) {
150 EstimateMethodData estimateMethodData = compressedAirLeakSurveyInput.getEstimateMethodData();
151 tmpTotalFlowRate = estimateMethodData.getLeakRateEstimate() * compressedAirLeakSurveyInput.getUnits();
152 tmpAnnualTotalFlowRate = (compressedAirLeakSurveyInput.getHoursPerYear() * tmpTotalFlowRate * 60);
153 }
154 // decibels method
155 else if (compressedAirLeakSurveyInput.getMeasurementMethod() == 1) {
156 DecibelsMethodData decibelsMethodData = compressedAirLeakSurveyInput.getDecibelsMethodData();
157 tmpTotalFlowRate = decibelsMethodData.calculate() * compressedAirLeakSurveyInput.getUnits();
158 tmpAnnualTotalFlowRate = (compressedAirLeakSurveyInput.getHoursPerYear() * tmpTotalFlowRate * 60);
159 }
160 // bag method
161 else if (compressedAirLeakSurveyInput.getMeasurementMethod() == 2) {
162 BagMethod bagMethod = compressedAirLeakSurveyInput.getBagMethod();
163 // Use BagMethod::calculate() for new logic
164 auto bagOutput = bagMethod.calculate();
165 tmpTotalFlowRate = bagOutput.flowRate * compressedAirLeakSurveyInput.getUnits();
166 tmpAnnualTotalFlowRate = bagOutput.annualConsumption * compressedAirLeakSurveyInput.getUnits();
167 }
168 // orifice method
169 else if (compressedAirLeakSurveyInput.getMeasurementMethod() == 3) {
170 OrificeMethodData orificeMethodData = compressedAirLeakSurveyInput.getOrificeMethodData();
171 tmpTotalFlowRate = orificeMethodData.calculate() * compressedAirLeakSurveyInput.getUnits();
172 tmpAnnualTotalFlowRate = (compressedAirLeakSurveyInput.getHoursPerYear() * tmpTotalFlowRate * 60);
173 }
174
175 // compressed air
176 if (compressedAirLeakSurveyInput.getUtilityType() == 0) {
177 tmpAnnualTotalElectricityCost = compressedAirLeakSurveyInput.getUtilityCost() * tmpAnnualTotalFlowRate;
178 }
179 // electricity
180 else if (compressedAirLeakSurveyInput.getUtilityType() == 1) {
181 CompressorElectricityData compressorElectricityData =
182 compressedAirLeakSurveyInput.getCompressorElectricityData();
183 double electricityCalculation = compressorElectricityData.calculate();
184 tmpAnnualTotalElectricity = electricityCalculation * tmpAnnualTotalFlowRate;
185 tmpAnnualTotalElectricityCost =
186 tmpAnnualTotalElectricity * compressedAirLeakSurveyInput.getUtilityCost();
187 }
188 annualTotalElectricity += tmpAnnualTotalElectricity;
189 annualTotalElectricityCost += tmpAnnualTotalElectricityCost;
190 totalFlowRate += tmpTotalFlowRate;
191 annualTotalFlowRate += tmpAnnualTotalFlowRate;
192 }
193
194 return CompressedAirLeakSurvey::Output(annualTotalElectricity, annualTotalElectricityCost, totalFlowRate,
195 annualTotalFlowRate);
196 }
197 std::vector<CompressedAirLeakSurveyInput> const& getCompressedAirLeakSurveyInputVec() const {
198 return compressedAirLeakSurveyInputVec;
199 }
200 void setCompressedAirReductionInputVec(std::vector<CompressedAirReductionInput>& compressedAirReductionInputVec);
201
202 private:
203 std::vector<CompressedAirLeakSurveyInput> compressedAirLeakSurveyInputVec;
205};
206
207#endif
Output calculate()
Definition BagMethod.h:44