1 #ifndef AMO_TOOLS_SUITE_STANDALONE_H 2 #define AMO_TOOLS_SUITE_STANDALONE_H 6 #include "calculator/util/CHP.h" 7 #include "calculator/util/CompressedAir.h" 21 double Get(std::string
const & nm) {
22 Local<String> getName = Nan::New<String>(nm).ToLocalChecked();
23 v8::Isolate *isolate = v8::Isolate::GetCurrent();
24 v8::Local<v8::Context> context = isolate->GetCurrentContext();
25 Local<Value> rObj = Nan::To<Object>(inp).ToLocalChecked()->Get(context, getName).ToLocalChecked();
26 if (rObj->IsUndefined()) {
27 ThrowTypeError(std::string(
"Get method in standalone.h: " + nm +
" not present in object").c_str());
29 return Nan::To<double>(rObj).FromJust();
32 std::vector<double> GetVector(
const std::string &key, Local<Object> obj)
34 v8::Isolate *isolate = v8::Isolate::GetCurrent();
35 v8::Local<v8::Context> context = isolate->GetCurrentContext();
37 Local<Value> arrayTmp = Nan::Get(Nan::To<v8::Object>(obj).ToLocalChecked(), Nan::New<String>(key).ToLocalChecked()).ToLocalChecked();
38 Local<Array> jsArray = v8::Local<v8::Array>::Cast(arrayTmp);
39 std::vector<double> array;
41 for (
unsigned int i = 0; i < jsArray->Length(); i++)
43 v8::Local<v8::Value> jsElement = jsArray->Get(context, i).ToLocalChecked();
44 double val = Nan::To<double>(jsElement).FromJust();
50 void SetR(std::string
const & nm,
double n) {
51 Local<String> getName = Nan::New<String>(nm).ToLocalChecked();
52 Local<Number> getNum = Nan::New<Number>(n);
53 Nan::Set(r, getName, getNum);
56 NAN_METHOD(CHPcalculator) {
57 inp = Nan::To<Object>(info[0]).ToLocalChecked();
58 r = Nan::New<Object>();
60 const double annualOperatingHours = Get(
"annualOperatingHours");
61 const double annualElectricityConsumption = Get(
"annualElectricityConsumption");
62 const double annualThermalDemand = Get(
"annualThermalDemand");
63 const double boilerThermalFuelCosts = Get(
"boilerThermalFuelCosts");
64 const double avgElectricityCosts = Get(
"avgElectricityCosts");
65 const double boilerThermalFuelCostsCHPcase = Get(
"boilerThermalFuelCostsCHPcase");
66 const double CHPfuelCosts = Get(
"CHPfuelCosts");
67 const double percentAvgkWhElectricCostAvoidedOrStandbyRate = Get(
"percentAvgkWhElectricCostAvoidedOrStandbyRate");
68 const double displacedThermalEfficiency = Get(
"displacedThermalEfficiency");
69 const double chpAvailability = Get(
"chpAvailability");
70 const double thermalUtilization = Get(
"thermalUtilization");
72 unsigned val =
static_cast<unsigned>(Get(
"option"));
75 auto const chp =
CHP(annualOperatingHours, annualElectricityConsumption, annualThermalDemand,
76 boilerThermalFuelCosts, avgElectricityCosts, option, boilerThermalFuelCostsCHPcase,
77 CHPfuelCosts, percentAvgkWhElectricCostAvoidedOrStandbyRate, displacedThermalEfficiency,
78 chpAvailability, thermalUtilization);
80 auto const & costInfo = chp.getCostInfo();
82 SetR(
"annualOperationSavings", costInfo.at(
"annualOperationSavings"));
83 SetR(
"totalInstalledCostsPayback", costInfo.at(
"totalInstalledCostsPayback"));
84 SetR(
"simplePayback", costInfo.at(
"simplePayback"));
85 SetR(
"fuelCosts", costInfo.at(
"fuelCosts"));
86 SetR(
"thermalCredit", costInfo.at(
"thermalCredit"));
87 SetR(
"incrementalOandM", costInfo.at(
"incrementalOandM"));
88 SetR(
"totalOperatingCosts", costInfo.at(
"totalOperatingCosts"));
89 info.GetReturnValue().Set(r);
92 NAN_METHOD(usableAirCapacity) {
93 inp = Nan::To<Object>(info[0]).ToLocalChecked();
94 const double tankSize = Get(
"tankSize");
95 const double airPressureIn = Get(
"airPressureIn");
96 const double airPressureOut = Get(
"airPressureOut");
100 NAN_METHOD(pneumaticAirRequirement) {
101 inp = Nan::To<Object>(info[0]).ToLocalChecked();
102 r = Nan::New<Object>();
104 int val = Get(
"pistonType");
105 auto const pistonType = (!val) ? PneumaticAirRequirement::PistonType::SingleActing : PneumaticAirRequirement::PistonType::DoubleActing;
106 const double cylinderDiameter = Get(
"cylinderDiameter");
107 const double cylinderStroke = Get(
"cylinderStroke");
108 const double airPressure = Get(
"airPressure");
109 const double cyclesPerMinute = Get(
"cyclesPerMinute");
113 if (pistonType == PneumaticAirRequirement::PistonType::SingleActing) {
114 airRequirement =
PneumaticAirRequirement(pistonType, cylinderDiameter, cylinderStroke, airPressure, cyclesPerMinute);
116 const double pistonRodDiameter = Get(
"pistonRodDiameter");
117 airRequirement =
PneumaticAirRequirement(pistonType, cylinderDiameter, cylinderStroke, pistonRodDiameter, airPressure, cyclesPerMinute);
120 auto const output = airRequirement.
calculate();
121 SetR(
"airRequirementPneumaticCylinder", output.airRequirementPneumaticCylinder);
122 SetR(
"volumeAirIntakePiston", output.volumeAirIntakePiston);
123 SetR(
"compressionRatio", output.compressionRatio);
124 info.GetReturnValue().Set(r);
127 NAN_METHOD(receiverTank) {
128 inp = Nan::To<Object>(info[0]).ToLocalChecked();
131 ReceiverTank::Method method =
static_cast<ReceiverTank::Method
>(
static_cast<unsigned>(Get(
"method")));
134 if (method == ReceiverTank::Method::General) {
136 const double airDemand = Get(
"airDemand");
137 const double allowablePressureDrop = Get(
"allowablePressureDrop");
138 const double atmosphericPressure = Get(
"atmosphericPressure");
140 tank = {ReceiverTank::Method::General, airDemand, allowablePressureDrop, atmosphericPressure};
142 }
else if (method == ReceiverTank::Method::DedicatedStorage) {
144 const double finalTankPressure = Get(
"finalTankPressure");
145 const double initialTankPressure = Get(
"initialTankPressure");
146 const double lengthOfDemand = Get(
"lengthOfDemand");
147 const double airFlowRequirement = Get(
"airFlowRequirement");
148 const double atmosphericPressure = Get(
"atmosphericPressure");
150 tank = {ReceiverTank::Method::DedicatedStorage, lengthOfDemand, airFlowRequirement, atmosphericPressure, initialTankPressure, finalTankPressure};
152 }
else if (method == ReceiverTank::Method::BridgingCompressorReactionDelay) {
154 const double speedOfAir = Get(
"speedOfAir");
155 const double distanceToCompressorRoom = Get(
"distanceToCompressorRoom");
156 const double atmosphericPressure = Get(
"atmosphericPressure");
157 const double airDemand = Get(
"airDemand");
158 const double allowablePressureDrop = Get(
"allowablePressureDrop");
160 tank = {ReceiverTank::Method::BridgingCompressorReactionDelay, distanceToCompressorRoom, speedOfAir, atmosphericPressure, airDemand, allowablePressureDrop};
163 const double lengthOfDemand = Get(
"lengthOfDemand");
164 const double airFlowRequirement = Get(
"airFlowRequirement");
165 const double atmosphericPressure = Get(
"atmosphericPressure");
166 const double initialTankPressure = Get(
"initialTankPressure");
167 const double finalTankPressure = Get(
"finalTankPressure");
168 const double meteredControl = Get(
"meteredControl");
170 tank = {ReceiverTank::Method::MeteredStorage, lengthOfDemand, airFlowRequirement, atmosphericPressure, initialTankPressure, finalTankPressure, meteredControl};
173 info.GetReturnValue().Set(size);
176 NAN_METHOD(operatingCost) {
177 inp = Nan::To<Object>(info[0]).ToLocalChecked();
178 r = Nan::New<Object>();
180 const double motorBhp = Get(
"motorBhp");
181 const double bhpUnloaded = Get(
"bhpUnloaded");
182 const double annualOperatingHours = Get(
"annualOperatingHours");
183 const double runTimeLoaded = Get(
"runTimeLoaded");
184 const double efficiencyLoaded = Get(
"efficiencyLoaded");
185 const double efficiencyUnloaded = Get(
"efficiencyUnloaded");
186 const double costOfElectricity = Get(
"costOfElectricity");
189 runTimeLoaded, efficiencyLoaded, efficiencyUnloaded,
190 costOfElectricity).calculate();
192 SetR(
"runTimeUnloaded", output.runTimeUnloaded);
193 SetR(
"costForLoaded", output.costForLoaded);
194 SetR(
"costForUnloaded", output.costForUnloaded);
195 SetR(
"totalAnnualCost", output.totalAnnualCost);
196 info.GetReturnValue().Set(r);
199 NAN_METHOD(airSystemCapacity) {
200 inp = Nan::To<Object>(info[0]).ToLocalChecked();
201 r = Nan::New<Object>();
203 std::vector<double> receiverCapacitiesGallons = GetVector(
"receiverCapacities", inp);
204 const double oneHalf = Get(
"oneHalf");
205 const double threeFourths = Get(
"threeFourths");
206 const double one = Get(
"one");
207 const double oneAndOneFourth = Get(
"oneAndOneFourth");
208 const double oneAndOneHalf = Get(
"oneAndOneHalf");
209 const double two = Get(
"two");
210 const double twoAndOneHalf = Get(
"twoAndOneHalf");
211 const double three = Get(
"three");
212 const double threeAndOneHalf = Get(
"threeAndOneHalf");
213 const double four = Get(
"four");
214 const double five = Get(
"five");
215 const double six = Get(
"six");
216 const double eight = Get(
"eight");
217 const double ten = Get(
"ten");
218 const double twelve = Get(
"twelve");
219 const double fourteen = Get(
"fourteen");
220 const double sixteen = Get(
"sixteen");
221 const double eighteen = Get(
"eighteen");
222 const double twenty = Get(
"twenty");
223 const double twentyFour = Get(
"twentyFour");
228 oneHalf, threeFourths, one, oneAndOneFourth,
229 oneAndOneHalf, two, twoAndOneHalf, three,
230 threeAndOneHalf, four, five, six, eight, ten, twelve, fourteen,
231 sixteen, eighteen, twenty, twentyFour
233 std::move(receiverCapacitiesGallons)
236 SetR(
"totalPipeVolume", output.totalPipeVolume);
237 SetR(
"totalReceiverVolume", output.totalReceiverVol);
238 SetR(
"totalCapacityOfCompressedAirSystem", output.totalCapacityOfCompressedAirSystem);
240 v8::Local<v8::Array> receiverCapacities = Nan::New<v8::Array>(output.receiverCapacities.size());
241 for (std::size_t i = 0; i < output.receiverCapacities.size(); i++) {
242 Nan::Set(receiverCapacities, i, Nan::New<Number>(output.receiverCapacities[i]));
244 Nan::Set(r, Nan::New<String>(
"receiverCapacities").ToLocalChecked(), receiverCapacities);
246 SetR(
"oneHalf", output.pipeLengths.oneHalf);
247 SetR(
"threeFourths", output.pipeLengths.threeFourths);
248 SetR(
"one", output.pipeLengths.one);
249 SetR(
"oneAndOneFourth", output.pipeLengths.oneAndOneFourth);
250 SetR(
"oneAndOneHalf", output.pipeLengths.oneAndOneHalf);
251 SetR(
"two", output.pipeLengths.two);
252 SetR(
"twoAndOneHalf", output.pipeLengths.twoAndOneHalf);
253 SetR(
"three", output.pipeLengths.three);
254 SetR(
"threeAndOneHalf", output.pipeLengths.threeAndOneHalf);
255 SetR(
"four", output.pipeLengths.four);
256 SetR(
"five", output.pipeLengths.five);
257 SetR(
"six", output.pipeLengths.six);
258 SetR(
"eight", output.pipeLengths.eight);
259 SetR(
"ten", output.pipeLengths.ten);
260 SetR(
"twelve", output.pipeLengths.twelve);
261 SetR(
"fourteen", output.pipeLengths.fourteen);
262 SetR(
"sixteen", output.pipeLengths.sixteen);
263 SetR(
"eighteen", output.pipeLengths.eighteen);
264 SetR(
"twenty", output.pipeLengths.twenty);
265 SetR(
"twentyFour", output.pipeLengths.twentyFour);
266 info.GetReturnValue().Set(r);
269 NAN_METHOD(airVelocity) {
270 inp = Nan::To<Object>(info[0]).ToLocalChecked();
271 r = Nan::New<Object>();
273 const double airFlow = Get(
"airFlow");
274 const double pipePressure = Get(
"pipePressure");
275 const double atmosphericPressure = Get(
"atmosphericPressure");
279 SetR(
"oneHalf", output.oneHalf);
280 SetR(
"threeFourths", output.threeFourths);
281 SetR(
"one", output.one);
282 SetR(
"oneAndOneFourth", output.oneAndOneFourth);
283 SetR(
"oneAndOneHalf", output.oneAndOneHalf);
284 SetR(
"two", output.two);
285 SetR(
"twoAndOneHalf", output.twoAndOneHalf);
286 SetR(
"three", output.three);
287 SetR(
"threeAndOneHalf", output.threeAndOneHalf);
288 SetR(
"four", output.four);
289 SetR(
"five", output.five);
290 SetR(
"six", output.six);
291 SetR(
"eight", output.eight);
292 SetR(
"ten", output.ten);
293 SetR(
"twelve", output.twelve);
294 SetR(
"fourteen", output.fourteen);
295 SetR(
"sixteen", output.sixteen);
296 SetR(
"eighteen", output.eighteen);
297 SetR(
"twenty", output.twenty);
298 SetR(
"twentyFour", output.twentyFour);
300 info.GetReturnValue().Set(r);
303 NAN_METHOD(pipeSizing) {
304 inp = Nan::To<Object>(info[0]).ToLocalChecked();
305 r = Nan::New<Object>();
307 const double airFlow = Get(
"airFlow");
308 const double airlinePressure = Get(
"airlinePressure");
309 const double designVelocity = Get(
"designVelocity");
310 const double atmosphericPressure = Get(
"atmosphericPressure");
314 SetR(
"crossSectionalArea", output.crossSectionalArea);
315 SetR(
"pipeDiameter", output.pipeDiameter);
317 info.GetReturnValue().Set(r);
320 NAN_METHOD(pneumaticValve) {
321 inp = Nan::To<Object>(info[0]).ToLocalChecked();
322 r = Nan::New<Object>();
323 v8::Isolate *isolate = v8::Isolate::GetCurrent();
324 v8::Local<v8::Context> context = isolate->GetCurrentContext();
326 Local<Value> flowRate = inp->Get(context, Nan::New<String>(
"flowRate").ToLocalChecked()).ToLocalChecked();
327 const double inletPressure = Get(
"inletPressure");
328 const double outletPressure = Get(
"outletPressure");
329 if (flowRate->IsUndefined()) {
331 SetR(
"flowRate", output);
333 const double flowRateInput = Get(
"flowRate");
335 SetR(
"flowCoefficient", output);
338 info.GetReturnValue().Set(r);
341 NAN_METHOD(bagMethod) {
342 inp = Nan::To<Object>(info[0]).ToLocalChecked();
343 r = Nan::New<Object>();
345 const double operatingTime = Get(
"operatingTime");
346 const double bagFillTime = Get(
"bagFillTime");
347 const double heightOfBag = Get(
"heightOfBag");
348 const double diameterOfBag = Get(
"diameterOfBag");
349 const double numberOfUnits = Get(
"numberOfUnits");
351 auto output =
BagMethod(operatingTime, bagFillTime, heightOfBag, diameterOfBag, numberOfUnits).
calculate();
352 SetR(
"flowRate", output.flowRate);
353 SetR(
"annualConsumption", output.annualConsumption);
355 info.GetReturnValue().Set(r);
359 #endif //AMO_TOOLS_SUITE_STANDALONE_H
static double calculateUsableCapacity(const double tankSize, const double airPressureIn, const double airPressureOut)