Skip to content

Commit 17f3baf

Browse files
authored
update valve calc (#1210)
1 parent d1007e2 commit 17f3baf

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

src/main/java/neqsim/process/equipment/valve/ThrottlingValve.java

+31-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class ThrottlingValve extends TwoPortEquipment implements ValveInterface
4545
boolean isCalcPressure = false;
4646
private boolean gasValve = true;
4747
private double Fp = 1.0;
48+
private double deltaPressure = 0.0;
4849

4950
/**
5051
* * Constructor for ThrottlingValve.
@@ -415,12 +416,20 @@ public double calcPercentValveOpening(double Pus, double Pds, double rhous, doub
415416
public void run(UUID id) {
416417
// System.out.println("valve running..");
417418
// outStream.setSpecification(inletStream.getSpecification());
418-
thermoSystem = getInletStream().getThermoSystem().clone();
419+
if (getInletStream().getThermoSystem() != null) {
420+
thermoSystem = getInletStream().getThermoSystem().clone();
421+
} else {
422+
logger.error("Inlet stream thermo system is null");
423+
return;
424+
}
419425
ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem);
420426
thermoSystem.init(3);
421427
double enthalpy = thermoSystem.getEnthalpy();
422428
inStream.getThermoSystem().initPhysicalProperties(PhysicalPropertyType.MASS_DENSITY);
423429
double outp = 0.0;
430+
if (pressure == 0) {
431+
pressure = inStream.getThermoSystem().getPressure();
432+
}
424433

425434
if (inStream.getThermoSystem().hasPhaseType(PhaseType.GAS)
426435
&& inStream.getThermoSystem().getVolumeFraction(0) > 0.9) {
@@ -441,6 +450,12 @@ public void run(UUID id) {
441450
}
442451
setOutletPressure(outp);
443452
}
453+
if (deltaPressure != 0) {
454+
thermoSystem.setPressure(thermoSystem.getPressure(pressureUnit) - deltaPressure,
455+
pressureUnit);
456+
setOutletPressure(thermoSystem.getPressure());
457+
458+
}
444459

445460
if ((thermoSystem.getPressure(pressureUnit) - pressure) < 0) {
446461
if (isAcceptNegativeDP()) {
@@ -456,14 +471,15 @@ public void run(UUID id) {
456471
// System.out.println("enthalpy inn.." + enthalpy);
457472
// thermoOps.PHflash(enthalpy, 0);
458473
if (isIsoThermal() || Math.abs(pressure - inStream.getThermoSystem().getPressure()) < 1e-6
459-
|| thermoSystem.getNumberOfMoles() < 1e-12) {
474+
|| thermoSystem.getNumberOfMoles() < 1e-12 || pressure == 0) {
460475
thermoOps.TPflash();
461476
} else {
462477
thermoOps.PHflash(enthalpy, 0);
463478
}
464479
outStream.setThermoSystem(thermoSystem);
465480
// System.out.println("Total volume flow " +
466-
// outStream.getThermoSystem().getVolume());
481+
// Uncomment the line below to get the volume of the outlet stream's thermodynamic system
482+
// System.out.println("Total volume flow " + outStream.getThermoSystem().getVolume());
467483
// System.out.println("density valve " +
468484
// inletStream.getThermoSystem().getDensity());
469485

@@ -522,7 +538,9 @@ public void run(UUID id) {
522538
}
523539

524540
/** {@inheritDoc} */
525-
@Override
541+
/**
542+
* This annotation is used to exclude the method from Jacoco code coverage reports.
543+
*/
526544
@ExcludeFromJacocoGeneratedReport
527545
public void displayResult() {
528546
thermoSystem.display(getName());
@@ -813,4 +831,13 @@ public double getFp() {
813831
public void setFp(double fp) {
814832
Fp = fp;
815833
}
834+
835+
public double getDeltaPressure() {
836+
return deltaPressure;
837+
}
838+
839+
public void setDeltaPressure(double deltaPressure, String unit) {
840+
this.deltaPressure = deltaPressure;
841+
this.pressureUnit = unit;
842+
}
816843
}

src/test/java/neqsim/process/equipment/valve/ThrottlingValveTest.java

+53
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,57 @@ void testCalcCvLiquid() {
5252
assertEquals(100, stream1.getFlowRate("kg/hr"), 1e-2);
5353
assertEquals(3.015805897362369E-4, valve1.getCv("US"), 1e-2);
5454
}
55+
56+
@Test
57+
void testSetDeltaPressure() {
58+
neqsim.thermo.system.SystemInterface testSystem2 =
59+
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00);
60+
testSystem2.addComponent("methane", 1.0);
61+
testSystem2.setMixingRule(2);
62+
63+
Stream stream1 = new Stream("Stream1", testSystem2);
64+
stream1.setFlowRate(100.0, "kg/hr");
65+
stream1.setPressure(100.0, "bara");
66+
stream1.setTemperature(55.0, "C");
67+
stream1.run();
68+
69+
double deltaPressure = 10.0;
70+
ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1);
71+
valve1.setDeltaPressure(deltaPressure, "bara");
72+
valve1.run();
73+
74+
Stream stream2 = new Stream("Stream1", valve1.getOutletStream());
75+
stream2.getPressure("bara");
76+
stream2.run();
77+
78+
assertEquals(deltaPressure, valve1.getDeltaPressure(), 1e-2);
79+
assertEquals(deltaPressure, stream1.getPressure("bara") - stream2.getPressure("bara"), 1e-4);
80+
assertEquals(52.269428855, stream2.getTemperature("C"), 1e-2);
81+
}
82+
83+
@Test
84+
void testSetDeltaPressure2() {
85+
neqsim.thermo.system.SystemInterface testSystem2 =
86+
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00);
87+
testSystem2.addComponent("methane", 1.0);
88+
testSystem2.setMixingRule(2);
89+
90+
Stream stream1 = new Stream("Stream1", testSystem2);
91+
stream1.setFlowRate(100.0, "kg/hr");
92+
stream1.setPressure(100.0, "bara");
93+
stream1.setTemperature(55.0, "C");
94+
stream1.run();
95+
96+
double deltaPressure = 0.0;
97+
ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1);
98+
valve1.run();
99+
100+
Stream stream2 = new Stream("Stream1", valve1.getOutletStream());
101+
stream2.getPressure("bara");
102+
stream2.run();
103+
104+
assertEquals(deltaPressure, valve1.getDeltaPressure(), 1e-2);
105+
assertEquals(deltaPressure, stream1.getPressure("bara") - stream2.getPressure("bara"), 1e-4);
106+
assertEquals(55.0, stream2.getTemperature("C"), 1e-2);
107+
}
55108
}

0 commit comments

Comments
 (0)