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