Skip to content

Commit

Permalink
Fix-antisurge-calc (#1101)
Browse files Browse the repository at this point in the history
* fix anti surge calc

* update antisurge

* update test

* update
  • Loading branch information
EvenSol authored Sep 23, 2024
1 parent 13b3125 commit 66f9f2b
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public SurgeCurve() {}
public SurgeCurve(double[] flow, double[] head) {
this.flow = flow;
this.head = head;
this.setCurve(null, flow, head);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ public boolean needRecalculation() {

public void runAntiSurgeCalc(UUID id) {
Compressor compressor = (Compressor) inputVariable.get(0);
double distToSurge = compressor.getDistanceToSurge();
double distToSurge = compressor.getDistanceToSurge();
double flowInAntiSurge = 1e-6;
if (distToSurge < 0) {
flowInAntiSurge = -distToSurge * compressor.getInletStream().getFlowRate("MSm3/day");
}

Splitter anitSurgeSplitter = (Splitter) outputVariable;

anitSurgeSplitter.setFlowRates(new double[] {-1, flowInAntiSurge}, "MSm3/day");

anitSurgeSplitter.run();
anitSurgeSplitter.setCalculationIdentifier(id);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import neqsim.processSimulation.processEquipment.compressor.Compressor;
import neqsim.processSimulation.processEquipment.compressor.SurgeCurve;
import neqsim.processSimulation.processEquipment.heatExchanger.Cooler;
import neqsim.processSimulation.processEquipment.heatExchanger.Heater;
import neqsim.processSimulation.processEquipment.mixer.Mixer;
Expand Down Expand Up @@ -148,7 +149,7 @@ public void runAntiSurgeProcess() throws InterruptedException {
gas_from_separator.run();

Stream recyclegasstream = gas_from_separator.clone();
recyclegasstream.setFlowRate(1.2, "MSm3/day");
recyclegasstream.setFlowRate(1e-10, "MSm3/day");
recyclegasstream.run();

Mixer gasmixer = new Mixer("gas mixer");
Expand All @@ -162,9 +163,6 @@ public void runAntiSurgeProcess() throws InterruptedException {
gascompressor.run();

double fluidh = gascompressor.getPolytropicFluidHead();

// gascompressor.generateCompressorCurves();

neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator compchartgenerator =
new neqsim.processSimulation.processEquipment.compressor.CompressorChartGenerator(
gascompressor);
Expand Down Expand Up @@ -193,6 +191,7 @@ public void runAntiSurgeProcess() throws InterruptedException {
Recycle recycl = new Recycle("rec");
recycl.addStream(antisurgevalve.getOutletStream());
recycl.setOutletStream(recyclegasstream);
recycl.setFlowAccuracy(1e-12);
recycl.run();

Calculator antisurgeCalculator = new Calculator("anti surge calculator");
Expand All @@ -212,24 +211,150 @@ public void runAntiSurgeProcess() throws InterruptedException {
operations.add(recycl);
operations.add(antisurgeCalculator);
operations.run();
gascompressor.setOutletPressure(90.0);

gascompressor.getCompressorChart().setUseCompressorChart(false);
// gascompressor.setOutletPressure(90.0);
// 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(4685.039100, gascompressor.getCompressorChart().getSurgeCurve()
assertEquals(4009.59769517, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-4);
assertEquals(90.91657683, gascompressor.getOutletPressure(), 1e-4);

gas_from_separator.setFlowRate(2.0, "MSm3/day");
operations.run();
assertEquals(1.5704782278734, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-4);
assertEquals(1.99999997741, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
assertEquals(4402.40767965, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(144.6783957, gascompressor.getOutletPressure(), 1e-4);

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);
assertEquals(3914.332053456, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(82.7494476493, gascompressor.getOutletPressure(), 1e-4);

gas_from_separator.setFlowRate(0.1, "MSm3/day");
gascompressor.setSpeed(2000);
operations.run();
assertEquals(0.66417291176, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-4);
assertEquals(0.09999851484397385, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
assertEquals(4037.5356388, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(96.609347, gascompressor.getOutletPressure(), 1e-4);


}

@Test
public void runAntiSurgeProcess2() throws InterruptedException {
SystemInterface thermoSystem = new SystemSrkEos(298.0, 10.0);
thermoSystem.addComponent("nitrogen", 1.0);
thermoSystem.addComponent("CO2", 1.0);
thermoSystem.addComponent("methane", 51.0);
thermoSystem.addComponent("ethane", 1.0);
thermoSystem.setMixingRule("classic");

Stream gas_from_separator = new Stream("feed stream", thermoSystem);
gas_from_separator.setPressure(55.0, "bara");
gas_from_separator.setTemperature(30.0, "C");
gas_from_separator.setFlowRate(7.0, "MSm3/day");

Stream recyclegasstream = gas_from_separator.clone();
recyclegasstream.setFlowRate(1e-10, "MSm3/day");

Mixer gasmixer = new Mixer("gas mixer");
gasmixer.addStream(gas_from_separator);
gasmixer.addStream(recyclegasstream);

Compressor gascompressor = new Compressor("gas compressor");
gascompressor.setInletStream(gasmixer.getOutletStream());
gascompressor.setOutletPressure(90.0, "bara");

Cooler gascooler = new Cooler("gas cooler");
gascooler.setInletStream(gascompressor.getOutletStream());
gascooler.setOutTemperature(30.0, "C");

Separator gassep = new Separator("gas separator");
gassep.setInletStream(gascooler.getOutletStream());

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

ThrottlingValve antisurgevalve = new ThrottlingValve("gas valve");
antisurgevalve.setInletStream(gassplitter.getSplitStream(1));
antisurgevalve.setOutletPressure(55.0, "bara");

Recycle recycl = new Recycle("rec");
recycl.addStream(antisurgevalve.getOutletStream());
recycl.setOutletStream(recyclegasstream);
recycl.setFlowAccuracy(1e-15);

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

neqsim.processSimulation.processSystem.ProcessSystem operations =
new neqsim.processSimulation.processSystem.ProcessSystem();
operations.add(gas_from_separator);
operations.add(recyclegasstream);
operations.add(gasmixer);
operations.add(gascompressor);
operations.add(gascooler);
operations.add(gassep);
operations.add(gassplitter);
operations.add(antisurgevalve);
operations.add(recycl);
operations.add(antisurgeCalculator);
operations.run();

double fluidh = gascompressor.getPolytropicFluidHead();
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);

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(4646.77601821, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-4);

gas_from_separator.setFlowRate(2.0, "MSm3/day");
operations.run();
assertEquals(1.36857161, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-4);
assertEquals(1.99999997741, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
assertEquals(4671.5920797, gascompressor.getCompressorChart().getSurgeCurve()
assertEquals(1.58988554, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-2);
assertEquals(1.99847869184, gassplitter.getSplitStream(0).getFlowRate("MSm3/day"), 1e-4);
assertEquals(4632.1489149, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-4);

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);
assertEquals(4646.77601880, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-4);
assertEquals(90.0, gascompressor.getOutletPressure(), 1e-4);

double[] flows = new double[] {7044, 7560, 7760};
double[] head = new double[] {74, 80, 90};
SurgeCurve surg = new SurgeCurve(flows, head);
gascompressor.getCompressorChart().setSurgeCurve(surg);
operations.run();
assertEquals(6753.1900, gascompressor.getCompressorChart().getSurgeCurve()
.getSurgeFlow(gascompressor.getPolytropicFluidHead()), 1e-2);
assertEquals(5998.55269, gascompressor.getInletStream().getFlowRate("m3/hr"), 1e-4);
assertEquals(0.9071841061, gassplitter.getSplitStream(1).getFlowRate("MSm3/day"), 1e-4);
}
}

0 comments on commit 66f9f2b

Please sign in to comment.