Skip to content

Commit

Permalink
Fix splitter 2 (#581)
Browse files Browse the repository at this point in the history
* fix minor bug split stream

* fix bug

* bug fix

* fix splitter bugs

* update recycle accuracy
  • Loading branch information
EvenSol authored Nov 18, 2022
1 parent 438e7d7 commit 4bfe3fb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,29 @@ public class Recycle extends ProcessEquipmentBaseClass implements MixerInterface
protected StreamInterface mixedStream;
StreamInterface lastIterationStream = null;
private StreamInterface outletStream = null;
private double tolerance = 1e-6;
private double error = 1e6;
private double tolerance = 1e-4;
private int priority = 100;
private double error = 1e10, errorFlow = 1e10;
boolean firstTime = true;
int iterations = 0;
int maxIterations = 10;

double compositionAccuracy = 1.0;
double temperatureAccuracy = 1.0;
double flowAccuracy = 1.0;

double compositionAccuracy = 5.0;
double temperatureAccuracy = 5.0;
double flowAccuracy = 5.0;

public void setCompositionAccuracy(double compositionAccuracy) {
this.compositionAccuracy = compositionAccuracy;
}

public void setTemperatureAccuracy(double temperatureAccuracy) {
this.temperatureAccuracy = temperatureAccuracy;
}

public void setFlowAccuracy(double flowAccuracy) {
this.flowAccuracy = flowAccuracy;
}

/**
* <p>
Expand All @@ -53,6 +65,7 @@ public Recycle() {
public void resetIterations() {
iterations = 0;
}

/**
* <p>
* Constructor for Recycle.
Expand Down Expand Up @@ -256,12 +269,12 @@ public void run(UUID id) {
* }
*/
double enthalpy = 0.0;
logger.info("flow rate old in recycle " +
outletStream.getFlowRate("kg/hr"));

logger.info("flow rate old in recycle " + outletStream.getFlowRate("kg/hr"));
// ((Stream) streams.get(0)).getThermoSystem().display();
SystemInterface thermoSystem2 = streams.get(0).getThermoSystem().clone();
logger.info("total number of moles " +
thermoSystem2.getTotalNumberOfMoles());
logger.info("total number of moles " + thermoSystem2.getTotalNumberOfMoles());

mixedStream.setThermoSystem(thermoSystem2);
ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem2);
if (streams.size() > 1) {
Expand All @@ -288,7 +301,9 @@ public void run(UUID id) {
}
mixedStream.setCalculationIdentifier(id);
setError(massBalanceCheck());
logger.info(name + " recycle error: " + getError());
setErrorFlow(massBalanceCheck2());
logger.info(name + " comp recycle error: " + getError());
logger.info(name + " flow recycle error: " + getErrorFlow());
lastIterationStream = (Stream) mixedStream.clone();
outletStream.setThermoSystem(mixedStream.getThermoSystem());
outletStream.setCalculationIdentifier(id);
Expand All @@ -306,6 +321,26 @@ public void run(UUID id) {
setCalculationIdentifier(id);
}

/**
* <p>
* massBalanceCheck.
* </p>
*
* @return a double
*/
public double massBalanceCheck2() {
double errorFlow = 0.0;
if (mixedStream.getFlowRate("kg/sec") < 1.0) {
errorFlow +=
Math.abs(mixedStream.getFlowRate("kg/sec") - lastIterationStream.getFlowRate("kg/sec"));
} else {
errorFlow +=
Math.abs(mixedStream.getFlowRate("kg/sec") - lastIterationStream.getFlowRate("kg/sec"))
/ mixedStream.getFlowRate("kg/sec") * 100.0;
}
return Math.abs(errorFlow);
}

/**
* <p>
* massBalanceCheck.
Expand All @@ -330,10 +365,9 @@ public double massBalanceCheck() {
// lastIterationStream.getThermoSystem().getPhase(0).getComponent(i).getx());
// logger.info("x new " +
// mixedStream.getThermoSystem().getPhase(0).getComponent(i).getx());
error += Math
.abs(mixedStream.getThermoSystem().getPhase(0).getComponent(i).getx()
- lastIterationStream.getThermoSystem().getPhase(0).getComponent(i).getx())
+ Math.abs(mixedStream.getFlowRate("kg/sec") - lastIterationStream.getFlowRate("kg/sec"));
error += Math.abs(mixedStream.getThermoSystem().getPhase(0).getComponent(i).getx()
- lastIterationStream.getThermoSystem().getPhase(0).getComponent(i).getx());


}
return Math.abs(error);
Expand Down Expand Up @@ -410,6 +444,21 @@ public void setError(double error) {
this.error = error;
}

/**
* <p>
* Setter for the field <code>errorFlow</code>.
* </p>
*
* @param error the error to set
*/
public void setErrorFlow(double error) {
this.errorFlow = error;
}

public double getErrorFlow() {
return errorFlow;
}

/**
* <p>
* Getter for the field <code>priority</code>.
Expand All @@ -435,7 +484,9 @@ public void setPriority(int priority) {
/** {@inheritDoc} */
@Override
public boolean solved() {
if (error < tolerance && iterations > 1) {

if (error < tolerance && errorFlow < flowAccuracy && iterations > 1) {

return true;
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void testRunSplitter2() {
Recycle recycle1 = new Recycle("recycle 1");
recycle1.addStream(valve1.getOutletStream());
recycle1.setOutletStream(streamresycl);
recycle1.setFlowAccuracy(1e-6);

StreamInterface exportStream = splitter.getSplitStream(0);

Expand All @@ -161,11 +162,9 @@ public void testRunSplitter2() {
assertEquals(0.1, resycStream1.getFlowRate("MSm3/day"), 1e-6);
// assertEquals(8.43553108874272, valve1.getPercentValveOpening(), 1e-2);



splitter.setFlowRates(new double[] {5.0, 0.5}, "MSm3/day");
processOps.run();

assertEquals(5.00000000, exportStream.getFlowRate("MSm3/day"), 1e-4);
assertEquals(0.5, resycStream1.getFlowRate("MSm3/day"), 1e-4);
// assertEquals(41.9139926125338, valve1.getPercentValveOpening(), 1e-2);
Expand Down

0 comments on commit 4bfe3fb

Please sign in to comment.