AMO-Tools-Suite  v.0.9.0
Set of tools for calculating energy efficiency in industrial equipment
All Classes Namespaces Files Functions Variables Enumerations Friends Macros Pages
svi.h
1 #include <nan.h>
2 #include <node.h>
3 #include <string>
4 #include <array>
5 #include <vector>
6 #include <exception>
7 #include <iostream>
8 #include "./NanDataConverters.h"
9 #include "calculator/util/SludgeVolumeIndex.h"
10 
11 using namespace Nan;
12 using namespace v8;
13 
14 NAN_METHOD(svi)
15 {
16  inp = Nan::To<Object>(info[0]).ToLocalChecked();
17  r = Nan::New<Object>();
18 
19  try
20  {
21  const int sviParameter = getDouble("sviParameter", inp);
22  const double sviValue = getDouble("sviValue", inp);
23  const int numberOfClarifiers = getDouble("numberOfClarifiers", inp);
24  const double areaOfClarifier = getDouble("areaOfClarifier", inp);
25  const double MLSS = getDouble("MLSS", inp);
26  const double influentFlow = getDouble("influentFlow", inp);
27  const double rasFlow = getDouble("rasFlow", inp);
28  const double sludgeSettlingVelocity = getDouble("sludgeSettlingVelocity", inp);
29 
30  SludgeVolumeIndex::SVIParameter parm;
31  switch (sviParameter) {
32  case 0: parm = SludgeVolumeIndex::SVIParameter::SVISN; break;
33  case 1: parm = SludgeVolumeIndex::SVIParameter::SVIGN; break;
34  case 2: parm = SludgeVolumeIndex::SVIParameter::SVIGS; break;
35  case 3: parm = SludgeVolumeIndex::SVIParameter::SVISS; break;
36  case 4: parm = SludgeVolumeIndex::SVIParameter::VoK; break;
37  }
38 
39  auto output = SludgeVolumeIndex(parm, sviValue, numberOfClarifiers, areaOfClarifier, MLSS, influentFlow, rasFlow, sludgeSettlingVelocity).calculate();
40  setR("TotalAreaClarifier", output.TotalAreaClarifier);
41  setR("SurfaceOverflow", output.SurfaceOverflow);
42  setR("AppliedSolidsLoading", output.AppliedSolidsLoading);
43  setR("RasConcentration", output.RasConcentration);
44  setR("UnderFlowRateX2", output.UnderFlowRateX2);
45  setR("UnderFlowRateY1", output.UnderFlowRateY1);
46  setR("OverFlowRateX2", output.OverFlowRateX2);
47  setR("OverFlowRateY2", output.OverFlowRateY2);
48  setR("StatePointX", output.StatePointX);
49  setR("StatePointY", output.StatePointY);
50 
51  auto graphData = output.GraphData;
52  auto graphDataPoints = New<Array>(graphData.size());
53  for (unsigned i = 0; i < graphDataPoints->Length(); i++)
54  {
55  auto ctArray = New<Array>(2);
56  ctArray->Set(Nan::GetCurrentContext(), 0, New(graphData[i].SolidsConcentration));
57  ctArray->Set(Nan::GetCurrentContext(), 1, New(graphData[i].SolidsFlux));
58 
59  graphDataPoints->Set(Nan::GetCurrentContext(), i, ctArray);
60  }
61  Nan::Set(r, New("graphData").ToLocalChecked(), graphDataPoints);
62 
63  info.GetReturnValue().Set(r);
64  }
65  catch (std::runtime_error const &e)
66  {
67  std::string const what = e.what();
68  ThrowError(std::string("std::runtime_error thrown in SludgeVolumeIndex - calculator: " + what).c_str());
69  }
70 }