Skip to content

Commit c09f001

Browse files
authored
added compressor test and initial code (#877)
* added compressor test and initial code * some more work * some further work to get dynamic compressor to work * strugling to find error * improve compressor calcs * added compressor mointor * further work in dynamic compressors * update * updates * updated * further work * update dynamic * update * update * update * update * update * update * update * update * update power * add maxminspeed setters * check if controller is active * removed try catch block and added check for actualFlowRateNew * removed print to screen in test
1 parent 85c580e commit c09f001

File tree

15 files changed

+869
-117
lines changed

15 files changed

+869
-117
lines changed

src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceBaseClass.java

+19
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class ControllerDeviceBaseClass extends NamedBaseClass implements Control
4444

4545
// Internal state of integration contribution
4646
private double TintValue = 0.0;
47+
boolean isActive = true;
4748

4849
/**
4950
* <p>
@@ -54,6 +55,19 @@ public ControllerDeviceBaseClass() {
5455
this("controller");
5556
}
5657

58+
59+
/** {@inheritDoc} */
60+
@Override
61+
public void setActive(boolean isActive) {
62+
this.isActive = isActive;
63+
}
64+
65+
/** {@inheritDoc} */
66+
@Override
67+
public boolean isActive() {
68+
return isActive;
69+
}
70+
5771
/**
5872
* <p>
5973
* Constructor for ControllerDeviceBaseClass.
@@ -80,6 +94,11 @@ public double getMeasuredValue() {
8094
/** {@inheritDoc} */
8195
@Override
8296
public void runTransient(double initResponse, double dt, UUID id) {
97+
if (!isActive) {
98+
response = initResponse;
99+
calcIdentifier = id;
100+
return;
101+
}
83102
if (isReverseActing()) {
84103
propConstant = -1;
85104
}

src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceInterface.java

+16
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,20 @@ public default void runTransient(double initResponse, double dt) {
128128
/** {@inheritDoc} */
129129
@Override
130130
public int hashCode();
131+
132+
/**
133+
* <p>
134+
* setActive
135+
* </p>
136+
* Set if controller is active
137+
*/
138+
public void setActive(boolean isActive);
139+
140+
/**
141+
* <p>
142+
* isActive
143+
* </p>
144+
* Specifies if controller is active
145+
*/
146+
public boolean isActive();
131147
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package neqsim.processSimulation.measurementDevice;
2+
3+
import neqsim.processSimulation.processEquipment.compressor.Compressor;
4+
5+
/**
6+
* <p>
7+
* CompressorMonitor class.
8+
* </p>
9+
*
10+
* @author ESOL
11+
* @version $Id: $Id
12+
*/
13+
public class CompressorMonitor extends MeasurementDeviceBaseClass {
14+
private static final long serialVersionUID = 1000;
15+
protected Compressor compressor = null;
16+
17+
/**
18+
* <p>
19+
* Constructor for CompressorMonitor.
20+
* </p>
21+
*
22+
* @param compressor a {@link neqsim.processSimulation.processEquipment.compressor.Compressor}
23+
* object
24+
*/
25+
public CompressorMonitor(Compressor compressor) {
26+
this("Compressor Monitor", compressor);
27+
}
28+
29+
/**
30+
* <p>
31+
* Constructor for CompressorMonitor.
32+
* </p>
33+
*
34+
* @param name Name of Compressor
35+
* @param compressor a {@link neqsim.processSimulation.processEquipment.compressor.Compressor}
36+
*/
37+
public CompressorMonitor(String name, Compressor compressor) {
38+
super(name, "rpm");
39+
this.compressor = compressor;
40+
}
41+
42+
/** {@inheritDoc} */
43+
@Override
44+
public void displayResult() {
45+
System.out.println("measured speed " + compressor.getSpeed());
46+
}
47+
48+
/** {@inheritDoc} */
49+
@Override
50+
public double getMeasuredValue(String unit) {
51+
if (unit.equals("distance to surge")) {
52+
return compressor.getDistanceToSurge();
53+
} else {
54+
return compressor.getDistanceToSurge();
55+
// return compressor.getSpeed();
56+
}
57+
}
58+
}

src/main/java/neqsim/processSimulation/processEquipment/compressor/Compressor.java

+95-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public class Compressor extends TwoPortEquipment implements CompressorInterface
3838
public double dH = 0.0;
3939
public double inletEnthalpy = 0;
4040
public double pressure = 0.0;
41-
private int speed = 3000;
41+
private double speed = 3000;
42+
private double maxspeed = 30000;
43+
private double minspeed = 0;
4244
public double isentropicEfficiency = 1.0;
4345
public double polytropicEfficiency = 1.0;
4446
public boolean usePolytropicCalc = false;
@@ -670,6 +672,50 @@ public void run(UUID id) {
670672
setCalculationIdentifier(id);
671673
}
672674

675+
/** {@inheritDoc} */
676+
@Override
677+
public void runTransient(double dt, UUID id) {
678+
if (getCalculateSteadyState()) {
679+
run(id);
680+
increaseTime(dt);
681+
return;
682+
}
683+
runController(dt, id);
684+
685+
inStream.getThermoSystem().init(3);
686+
outStream.getThermoSystem().init(3);
687+
double head = (outStream.getThermoSystem().getEnthalpy("kJ/kg")
688+
- inStream.getThermoSystem().getEnthalpy("kJ/kg"));
689+
double guessFlow = inStream.getFluid().getFlowRate("m3/hr");
690+
double actualFlowRateNew = getCompressorChart().getFlow(head, getSpeed(), guessFlow);
691+
if (actualFlowRateNew < 0.0 || Double.isNaN(actualFlowRateNew)) {
692+
logger.error(
693+
"actual flow rate is negative or NaN and would lead to failure of calculation: actual flow rate "
694+
+ actualFlowRateNew);
695+
}
696+
inStream.setFlowRate(actualFlowRateNew, "Am3/hr");
697+
698+
inStream.getThermoSystem().init(3);
699+
inStream.getThermoSystem().initPhysicalProperties("density");
700+
inStream.run(id);
701+
inStream.getThermoSystem().init(3);
702+
703+
outStream.setFlowRate(inStream.getFlowRate("kg/hr"), "kg/hr");
704+
outStream.run();
705+
outStream.getThermoSystem().init(3);
706+
707+
inletEnthalpy = inStream.getFluid().getEnthalpy();
708+
thermoSystem = outStream.getThermoSystem().clone();
709+
thermoSystem.initPhysicalProperties("density");
710+
711+
polytropicEfficiency =
712+
compressorChart.getPolytropicEfficiency(inStream.getFlowRate("m3/hr"), speed) / 100.0;
713+
polytropicFluidHead = head * polytropicEfficiency;
714+
dH = polytropicFluidHead * 1000.0 * thermoSystem.getMolarMass() / getPolytropicEfficiency()
715+
* inStream.getThermoSystem().getTotalNumberOfMoles();
716+
setCalculationIdentifier(id);
717+
}
718+
673719
/**
674720
* <p>
675721
* generateCompressorCurves.
@@ -955,6 +1001,12 @@ public boolean isSurge(double flow, double head) {
9551001
return getAntiSurge().isSurge();
9561002
}
9571003

1004+
public double getDistanceToSurge() {
1005+
return (getInletStream().getFlowRate("m3/hr")
1006+
- getCompressorChart().getSurgeCurve().getSurgeFlow(getPolytropicFluidHead()))
1007+
/ getCompressorChart().getSurgeCurve().getSurgeFlow(getPolytropicFluidHead());
1008+
}
1009+
9581010
/**
9591011
* <p>
9601012
* isStoneWall.
@@ -985,9 +1037,9 @@ public void setAntiSurge(AntiSurge antiSurge) {
9851037
* Getter for the field <code>speed</code>.
9861038
* </p>
9871039
*
988-
* @return a int
1040+
* @return a double
9891041
*/
990-
public int getSpeed() {
1042+
public double getSpeed() {
9911043
return speed;
9921044
}
9931045

@@ -998,7 +1050,7 @@ public int getSpeed() {
9981050
*
9991051
* @param speed a int
10001052
*/
1001-
public void setSpeed(int speed) {
1053+
public void setSpeed(double speed) {
10021054
this.speed = speed;
10031055
}
10041056

@@ -1256,6 +1308,29 @@ public void setPropertyProfile(CompressorPropertyProfile propertyProfile) {
12561308
this.propertyProfile = propertyProfile;
12571309
}
12581310

1311+
/**
1312+
* <p>
1313+
* runController.
1314+
* </p>
1315+
*
1316+
* @param dt a double
1317+
* @param id Calculation identifier
1318+
*/
1319+
public void runController(double dt, UUID id) {
1320+
if (hasController && getController().isActive()) {
1321+
getController().runTransient(this.speed, dt, id);
1322+
this.speed = getController().getResponse();
1323+
if (this.speed > maxspeed) {
1324+
this.speed = maxspeed;
1325+
}
1326+
if (this.speed < minspeed) {
1327+
this.speed = minspeed;
1328+
}
1329+
// System.out.println("valve opening " + this.percentValveOpening + " %");
1330+
}
1331+
setCalculationIdentifier(id);
1332+
}
1333+
12591334
/** {@inheritDoc} */
12601335
@Override
12611336
public int hashCode() {
@@ -1310,4 +1385,20 @@ public boolean equals(Object obj) {
13101385
&& usePolytropicCalc == other.usePolytropicCalc
13111386
&& useRigorousPolytropicMethod == other.useRigorousPolytropicMethod;
13121387
}
1388+
1389+
public void setMaximumSpeed(double maxSpeed) {
1390+
this.maxspeed = maxSpeed;
1391+
}
1392+
1393+
public void setMinimumSpeed(double minspeed) {
1394+
this.minspeed = minspeed;
1395+
}
1396+
1397+
public double getMaximumSpeed() {
1398+
return maxspeed;
1399+
}
1400+
1401+
public double getMinimumSpeed() {
1402+
return minspeed;
1403+
}
13131404
}

src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorChart.java

+26
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,32 @@ public int getSpeed(double flow, double head) {
162162
return (int) Math.round(newspeed);
163163
}
164164

165+
/** {@inheritDoc} */
166+
@Override
167+
public double getFlow(double head, double speed, double guessFlow) {
168+
int iter = 1;
169+
double error = 1.0;
170+
double derrordspeed = 1.0;
171+
double newflow = guessFlow;
172+
double newhead = 0.0;
173+
double oldflow = newflow * 1.1;
174+
double oldhead = getPolytropicHead(oldflow, speed);
175+
double olderror = oldhead - head;
176+
do {
177+
iter++;
178+
newhead =
179+
getPolytropicHead(newflow, speed) / (getPolytropicEfficiency(newflow, speed) / 100.0);
180+
error = newhead - head;
181+
derrordspeed = (error - olderror) / (newflow - oldflow);
182+
newflow -= error / derrordspeed;
183+
// System.out.println("newflow " + newflow);
184+
} while (Math.abs(error) > 1e-6 && iter < 100);
185+
186+
// change speed to minimize
187+
// Math.abs(head - reducedHeadFitterFunc.value(flow / speed) * speed * speed);
188+
return newflow;
189+
}
190+
165191
/**
166192
* <p>
167193
* addSurgeCurve.

src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartAlternativeMapLookup.java

+6
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,10 @@ public static int bisect_left(Double[] A, double x, int lo, int hi) {
541541
/** {@inheritDoc} */
542542
@Override
543543
public void plot() {}
544+
545+
/** {@inheritDoc} */
546+
@Override
547+
public double getFlow(double head, double speed, double guessFlow) {
548+
return 0.0;
549+
}
544550
}

src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartGenerator.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,41 @@ public CompressorChart generateCompressorChart(String generationOption) {
2121
double[] chartConditions = new double[3];
2222
chartConditions[0] = compressor.getOutletStream().getFluid().getMolarMass("kg/mol");
2323

24-
int refspeed = compressor.getSpeed();
24+
double refspeed = compressor.getSpeed();
2525
double[] speed = new double[1];
2626
speed[0] = refspeed;
2727
double minSpeed = refspeed / 2.0;
2828
double maxSpeed = refspeed * 2.0;
2929

30+
compressor.getInletStream().getFluid().initPhysicalProperties("density");
3031
double refflow = compressor.getInletStream().getFlowRate("m3/hr");
31-
double[][] flow = new double[1][1];
32-
flow[0][0] = refflow;
32+
double[][] flow = new double[1][3];
33+
flow[0][0] = refflow * 0.7;
34+
flow[0][1] = refflow * 1.0;
35+
flow[0][2] = refflow * 1.43;
3336
double minFlow = refflow / 2.0;
3437
double maxFlow = refflow * 2.0;
3538

36-
double refhead = compressor.getPolytropicHead("kJ/kg");
37-
double[][] head = new double[1][1];
38-
head[0][0] = refhead;
39-
40-
double[][] polyEff = new double[1][1];
41-
polyEff[0][0] = compressor.getPolytropicEfficiency() * 100.0;
39+
double refhead = compressor.getPolytropicFluidHead();
40+
double[][] head = new double[1][3];
41+
head[0][0] = refhead * 1.5;
42+
head[0][1] = refhead;
43+
head[0][2] = refhead * 0.5;
4244

45+
double[][] polyEff = new double[1][3];
46+
polyEff[0][0] = compressor.getPolytropicEfficiency() * 100.0 * 0.9;
47+
polyEff[0][1] = compressor.getPolytropicEfficiency() * 100.0;
48+
polyEff[0][2] = compressor.getPolytropicEfficiency() * 100.0 * 0.85;
4349
CompressorChart compChart = new CompressorChart();
4450
compChart.setUseCompressorChart(true);
4551
compChart.setHeadUnit("kJ/kg");
4652
compChart.setCurves(chartConditions, speed, flow, head, polyEff);
4753

4854

4955
// Generating surge curve
50-
double minFlowSurgeFlow = 0.3 * refflow;
51-
double refSurgeFlow = 0.5 * refflow;
52-
double maxSurgeFlow = 0.8 * refflow;
56+
double minFlowSurgeFlow = 0.7 * refflow;
57+
double refSurgeFlow = 0.8 * refflow;
58+
double maxSurgeFlow = 0.9 * refflow;
5359
double headSurgeRef = compChart.getPolytropicHead(refSurgeFlow, refspeed);
5460
double headSurgeMin = compChart.getPolytropicHead(minFlow, minSpeed);
5561
double headSurgeMax = compChart.getPolytropicHead(maxSurgeFlow, maxSpeed);

src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartInterface.java

+3
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,7 @@ public void setReferenceConditions(double refMW, double refTemperature, double r
166166
/** {@inheritDoc} */
167167
@Override
168168
public int hashCode();
169+
170+
/** {@inheritDoc} */
171+
public double getFlow(double head, double speed, double guessFlow);
169172
}

src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorInterface.java

+10
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,14 @@ public interface CompressorInterface extends ProcessEquipmentInterface, TwoPortI
7171
* @return a {@link neqsim.processSimulation.processEquipment.compressor.AntiSurge} object
7272
*/
7373
public AntiSurge getAntiSurge();
74+
75+
public double getDistanceToSurge();
76+
77+
public void setMaximumSpeed(double maxSpeed);
78+
79+
public void setMinimumSpeed(double minspeed);
80+
81+
public double getMaximumSpeed();
82+
83+
public double getMinimumSpeed();
7484
}

0 commit comments

Comments
 (0)