Skip to content

Commit

Permalink
fix minor bug split stream (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed May 22, 2023
1 parent 9e64444 commit dfacb69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,42 +139,34 @@ public void setFlowRates(double[] flowRates, String flowUnit) {
}
this.flowRates = flowRates;
this.flowUnit = flowUnit;

splitNumber = flowRates.length;
splitFactor = new double[flowRates.length];
splitFactor[0] = 1.0;
setInletStream(inletStream);
}

public void calcSplitFactors() {
double sum = 0.0;
for (int i = 0; i < flowRates.length; i++) {
if (flowRates[i] > -0.1) {
if (flowRates[i] > 0.0) {
sum += flowRates[i];
}
}

double missingFlowRate = 0.0;
for (int i = 0; i < flowRates.length; i++) {
if (flowRates[i] < -0.1) {
flowRates[i] = inletStream.getFlowRate(flowUnit) - sum;
missingFlowRate = inletStream.getFlowRate(flowUnit) - sum;
}
}
splitFactor = new double[flowRates.length];
for (int i = 0; i < flowRates.length; i++) {
splitFactor[i] = flowRates[i] / sum;
}
splitNumber = splitFactor.length;
setInletStream(inletStream);
}

public void calcSplitFactors() {
double sum = 0.0;
for (int i = 0; i < splitNumber; i++) {
if (flowRates[i] > -0.1) {
splitFactor[i] = flowRates[i] / inletStream.getFlowRate(flowUnit);
sum += splitFactor[i];
}
}

for (int i = 0; i < splitNumber; i++) {
splitFactor[i] = flowRates[i] / inletStream.getFlowRate(flowUnit);
if (flowRates[i] < -0.1) {
splitFactor[i] = 1 - sum;
splitFactor[i] = missingFlowRate / inletStream.getFlowRate(flowUnit);
}
}


}

/** {@inheritDoc} */
Expand All @@ -185,7 +177,6 @@ public void setInletStream(StreamInterface inletStream) {
splitStream = new Stream[splitNumber];
try {
for (int i = 0; i < splitNumber; i++) {
// System.out.println("splitting...." + i);
splitStream[i] = new Stream("Split Stream", inletStream.getThermoSystem().clone());
}
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public void testRunSplitter2() {
assertEquals(5.00000000, exportStream.getFlowRate("MSm3/day"), 1e-6);
assertEquals(0.1, resycStream1.getFlowRate("MSm3/day"), 1e-6);
assertEquals(8.4328749964588, valve1.getPercentValveOpening(), 1e-2);

splitter.setFlowRates(new double[] {-1, 0.5}, "MSm3/day");
processOps.run();
assertEquals(5.00000000, exportStream.getFlowRate("MSm3/day"), 1e-6);
assertEquals(0.5, resycStream1.getFlowRate("MSm3/day"), 1e-6);
}

}

0 comments on commit dfacb69

Please sign in to comment.