Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce tolerance for recycle #1123

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Recycle extends ProcessEquipmentBaseClass implements MixerInterface
protected StreamInterface mixedStream;
StreamInterface lastIterationStream = null;
private StreamInterface outletStream = null;
private double tolerance = 1e-4;
private double tolerance = 1e-2;
private int priority = 100;
private double error = 1e10;
private double errorFlow = 1e10;
Expand All @@ -38,7 +38,7 @@ public class Recycle extends ProcessEquipmentBaseClass implements MixerInterface

double compositionAccuracy = 1.0;
double temperatureAccuracy = 1.0;
double flowAccuracy = 1.0;
double flowAccuracy = 1.0e-2;

/**
* <p>
Expand Down Expand Up @@ -354,7 +354,6 @@ public double massBalanceCheck2() {
Math.abs(mixedStream.getFlowRate("kg/sec") - lastIterationStream.getFlowRate("kg/sec"))
/ mixedStream.getFlowRate("kg/sec") * 100.0;
}

return abs_sum_errorFlow;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,44 +47,40 @@ public void runProcess() throws InterruptedException {
thermoSystem.addPlusFraction("C38_C80", 1.0, 662.0 / 1000.0, 0.92);
thermoSystem.setMixingRule("classic");
thermoSystem.setMultiPhaseCheck(true);
thermoSystem.setMolarComposition(new double[] {0.034266, 0.005269, 0.039189, 0.700553, 0.091154,
thermoSystem.setMolarComposition(new double[] { 0.034266, 0.005269, 0.039189, 0.700553, 0.091154,
0.050908, 0.007751, 0.014665, 0.004249, 0.004878, 0.004541, 0.007189, 0.006904, 0.004355,
0.007658, 0.003861, 0.003301, 0.002624, 0.001857, 0.001320, 0.001426, 0.001164, 0.000916});
0.007658, 0.003861, 0.003301, 0.002624, 0.001857, 0.001320, 0.001426, 0.001164, 0.000916 });
// thermoSystem.prettyPrint();

Stream feedStream = new Stream("feed stream", thermoSystem);
feedStream.setFlowRate(604094, "kg/hr");
feedStream.setTemperature(25.5, "C");
feedStream.setPressure(26.0, "bara");

neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator seprator1stStage =
new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator(
"1st stage separator", feedStream);
neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator seprator1stStage = new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator(
"1st stage separator", feedStream);

ThrottlingValve valve1 = new ThrottlingValve("valve1", seprator1stStage.getLiquidOutStream());
valve1.setOutletPressure(19.0);

Heater oilHeater = new Heater("oil heater", valve1.getOutletStream());
oilHeater.setOutTemperature(359.0);

neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator seprator2ndStage =
new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator(
"2nd stage separator", oilHeater.getOutletStream());
neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator seprator2ndStage = new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator(
"2nd stage separator", oilHeater.getOutletStream());

ThrottlingValve valve2 = new ThrottlingValve("valve2", seprator2ndStage.getLiquidOutStream());
valve2.setOutletPressure(2.7);

StreamInterface recircstream1 = valve2.getOutletStream().clone("oilRecirc1");
recircstream1.setFlowRate(1e-6, "kg/hr");

neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator seprator3rdStage =
new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator(
"3rd stage separator");
neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator seprator3rdStage = new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator(
"3rd stage separator");
seprator3rdStage.addStream(valve2.getOutletStream());
seprator3rdStage.addStream(recircstream1);

ThrottlingValve pipeloss1st =
new ThrottlingValve("pipeloss1st", seprator3rdStage.getGasOutStream());
ThrottlingValve pipeloss1st = new ThrottlingValve("pipeloss1st", seprator3rdStage.getGasOutStream());
pipeloss1st.setOutletPressure(2.7 - 0.03);

Heater coolerLP = new Heater("cooler LP", pipeloss1st.getOutletStream());
Expand All @@ -102,8 +98,7 @@ public void runProcess() throws InterruptedException {
recycle1.addStream(valveLP1.getOutletStream());
recycle1.setOutletStream(recircstream1);

neqsim.processSimulation.processSystem.ProcessSystem operations =
new neqsim.processSimulation.processSystem.ProcessSystem();
neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem();
operations.add(feedStream);
operations.add(seprator1stStage);
operations.add(valve1);
Expand All @@ -121,7 +116,7 @@ public void runProcess() throws InterruptedException {

operations.run();

assertEquals(17105.52983567356, seprator3rdStage.getGasOutStream().getFlowRate("kg/hr"), 1.1);
assertEquals(17105.52983567356, seprator3rdStage.getGasOutStream().getFlowRate("kg/hr"), 10.1);

assertEquals(seprator3rdStage.getGasOutStream().getFlowRate("kg/hr"),
coolerLP.getOutletStream().getFlowRate("kg/hr"), 1e-4);
Expand Down Expand Up @@ -161,9 +156,8 @@ public void runAntiSurgeProcess() throws InterruptedException {
gascompressor.run();

double fluidh = gascompressor.getPolytropicFluidHead();
neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator compchartgenerator =
new neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator(
gascompressor);
neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator compchartgenerator = new neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator(
gascompressor);
gascompressor.setCompressorChart(compchartgenerator.generateCompressorChart("mid range"));

Cooler gascooler = new Cooler("gas cooler");
Expand All @@ -177,7 +171,7 @@ public void runAntiSurgeProcess() throws InterruptedException {

Splitter gassplitter = new Splitter("gas splitter");
gassplitter.setInletStream(gassep.getGasOutStream());
gassplitter.setFlowRates(new double[] {7.0, 1.2}, "MSm3/day");
gassplitter.setFlowRates(new double[] { 7.0, 1.2 }, "MSm3/day");
gassplitter.run();

ThrottlingValve antisurgevalve = new ThrottlingValve("gas valve");
Expand All @@ -188,15 +182,13 @@ public void runAntiSurgeProcess() throws InterruptedException {
Recycle recycl = new Recycle("rec");
recycl.addStream(antisurgevalve.getOutletStream());
recycl.setOutletStream(recyclegasstream);
recycl.setFlowAccuracy(1e-20);
recycl.run();

Calculator antisurgeCalculator = new Calculator("anti surge calculator");
antisurgeCalculator.addInputVariable(gascompressor);
antisurgeCalculator.setOutputVariable(gassplitter);

neqsim.processSimulation.processSystem.ProcessSystem operations =
new neqsim.processSimulation.processSystem.ProcessSystem();
neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem();
operations.add(gas_from_separator);
operations.add(recyclegasstream);
operations.add(gasmixer);
Expand All @@ -213,38 +205,39 @@ public void runAntiSurgeProcess() throws InterruptedException {
// gascompressor.getCompressorChart().setUseCompressorChart(false);

operations.run();
assertEquals(6.9999999, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
assertEquals(1e-6, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-4);
assertEquals(6.9999999, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-2);
assertEquals(0.0, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-2);
assertEquals(4009.59769517, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(90.91657683, gascompressor.getOutletPressure(), 1e-4);
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1);
assertEquals(90.91657683, gascompressor.getOutletPressure(), 1e-1);

gas_from_separator.setFlowRate(2.0, "MSm3/day");
operations.run();
// assertEquals(4.00961638, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-4);
// assertEquals(4.00961638,
// gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-4);
assertEquals(2.005737385700, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-2);
assertEquals(4157.46978573787, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-1);
assertEquals(4157.470818, gascompressor.getInletStream().getFlowRate("m3/hr"), 1e-2);
assertEquals(109.8098956, gascompressor.getOutletPressure(), 1e-2);
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1);
assertEquals(4157.470818, gascompressor.getInletStream().getFlowRate("m3/hr"), 10);
assertEquals(109.8098956, gascompressor.getOutletPressure(), 1e-1);

gas_from_separator.setFlowRate(8.0, "MSm3/day");
operations.run();
assertEquals(1.0000000000014376E-6, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"),
1e-4);
assertEquals(8.000000000000004, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
1e-1);
assertEquals(8.000000000000004, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-2);
assertEquals(3914.332053456, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(82.7494476493, gascompressor.getOutletPressure(), 1e-4);
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 10);
assertEquals(82.7494476493, gascompressor.getOutletPressure(), 1e-1);

gas_from_separator.setFlowRate(0.5, "MSm3/day");

operations.run();
assertEquals(5.70145187, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-4);
assertEquals(0.50010559709, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
assertEquals(5.70145187, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-2);
assertEquals(0.50010559709, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 5e-2);
assertEquals(4159.042541, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(112.0488937, gascompressor.getOutletPressure(), 1e-4);
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 10);
assertEquals(112.0488937, gascompressor.getOutletPressure(), 1);
}

@Test
Expand Down Expand Up @@ -286,7 +279,7 @@ public void runAntiSurgeProcess2() throws InterruptedException {

Splitter gassplitter = new Splitter("gas splitter");
gassplitter.setInletStream(gassep.getGasOutStream());
gassplitter.setFlowRates(new double[] {7.0, 1.2}, "MSm3/day");
gassplitter.setFlowRates(new double[] { 7.0, 1.2 }, "MSm3/day");

ThrottlingValve antisurgevalve = new ThrottlingValve("gas valve");
antisurgevalve.setInletStream(gassplitter.getSplitStream(1));
Expand All @@ -295,10 +288,9 @@ public void runAntiSurgeProcess2() throws InterruptedException {
Recycle recycl = new Recycle("rec");
recycl.addStream(antisurgevalve.getOutletStream());
recycl.setOutletStream(recyclegasstream);
recycl.setFlowAccuracy(1e-15);
recycl.setFlowAccuracy(1e-3);

neqsim.processSimulation.processSystem.ProcessSystem operations =
new neqsim.processSimulation.processSystem.ProcessSystem();
neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem();
operations.add(gas_from_separator);
operations.add(recyclegasstream);
operations.add(gasmixer);
Expand All @@ -314,9 +306,8 @@ public void runAntiSurgeProcess2() throws InterruptedException {
double fluidh = gascompressor.getPolytropicFluidHead();
double flowratetocompressor = gascompressor.getInletStream().getFlowRate("MSm3/day");

neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator compchartgenerator =
new neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator(
gascompressor);
neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator compchartgenerator = new neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator(
gascompressor);
gascompressor.setCompressorChart(compchartgenerator.generateCompressorChart("mid range"));
gascompressor.setOutletPressure(90.0);
gascompressor.getCompressorChart().setUseCompressorChart(false);
Expand All @@ -329,40 +320,39 @@ public void runAntiSurgeProcess2() throws InterruptedException {

operations.run();
assertEquals(7.00019789, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-2);
assertEquals(0.001732061306, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-4);
assertEquals(0.0, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-1);
assertEquals(4685.038961, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-2);
assertEquals(5176.97051519596, gascompressor.getInletStream().getFlowRate("m3/hr"), 10);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-4);
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 10);
assertEquals(5176.97051519596, gascompressor.getInletStream().getFlowRate("m3/hr"), 50);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-1);

gas_from_separator.setFlowRate(1.0, "MSm3/day");
operations.run();
double flow = gasmixer.getOutletStream().getFlowRate("MSm3/day");
assertEquals(5.33483946, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-2);
assertEquals(1.0, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
assertEquals(1.0, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-2);
assertEquals(4685.0389615, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-2);
assertEquals(4684.996901, gascompressor.getInletStream().getFlowRate("m3/hr"), 1e-1);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-4);

.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 10);
assertEquals(4684.996901, gascompressor.getInletStream().getFlowRate("m3/hr"), 10);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-1);

gas_from_separator.setFlowRate(9.0, "MSm3/day");
operations.run();
assertEquals(1.0224661428980936E-8, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"),
1e-2);
assertEquals(9.0, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
assertEquals(9.0, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-2);
assertEquals(4685.0389615, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-2);
assertEquals(6656.10407208, gascompressor.getInletStream().getFlowRate("m3/hr"), 1e-2);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-4);
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 10);
assertEquals(6656.10407208, gascompressor.getInletStream().getFlowRate("m3/hr"), 10);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-2);

gas_from_separator.setFlowRate(5.5, "MSm3/day");
operations.run();
assertEquals(0.834839487572494, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-2);
assertEquals(5.5, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
assertEquals(5.5, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-2);
assertEquals(4685.0389615, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-2);
assertEquals(4685.038986, gascompressor.getInletStream().getFlowRate("m3/hr"), 1);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-4);
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 10);
assertEquals(4685.038986, gascompressor.getInletStream().getFlowRate("m3/hr"), 10);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-2);
}
}