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

update valve calc #1210

Merged
merged 1 commit into from
Dec 11, 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 @@ -45,6 +45,7 @@ public class ThrottlingValve extends TwoPortEquipment implements ValveInterface
boolean isCalcPressure = false;
private boolean gasValve = true;
private double Fp = 1.0;
private double deltaPressure = 0.0;

/**
* * Constructor for ThrottlingValve.
Expand Down Expand Up @@ -415,12 +416,20 @@ public double calcPercentValveOpening(double Pus, double Pds, double rhous, doub
public void run(UUID id) {
// System.out.println("valve running..");
// outStream.setSpecification(inletStream.getSpecification());
thermoSystem = getInletStream().getThermoSystem().clone();
if (getInletStream().getThermoSystem() != null) {
thermoSystem = getInletStream().getThermoSystem().clone();
} else {
logger.error("Inlet stream thermo system is null");
return;
}
ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem);
thermoSystem.init(3);
double enthalpy = thermoSystem.getEnthalpy();
inStream.getThermoSystem().initPhysicalProperties(PhysicalPropertyType.MASS_DENSITY);
double outp = 0.0;
if (pressure == 0) {
pressure = inStream.getThermoSystem().getPressure();
}

if (inStream.getThermoSystem().hasPhaseType(PhaseType.GAS)
&& inStream.getThermoSystem().getVolumeFraction(0) > 0.9) {
Expand All @@ -441,6 +450,12 @@ public void run(UUID id) {
}
setOutletPressure(outp);
}
if (deltaPressure != 0) {
thermoSystem.setPressure(thermoSystem.getPressure(pressureUnit) - deltaPressure,
pressureUnit);
setOutletPressure(thermoSystem.getPressure());

}

if ((thermoSystem.getPressure(pressureUnit) - pressure) < 0) {
if (isAcceptNegativeDP()) {
Expand All @@ -456,14 +471,15 @@ public void run(UUID id) {
// System.out.println("enthalpy inn.." + enthalpy);
// thermoOps.PHflash(enthalpy, 0);
if (isIsoThermal() || Math.abs(pressure - inStream.getThermoSystem().getPressure()) < 1e-6
|| thermoSystem.getNumberOfMoles() < 1e-12) {
|| thermoSystem.getNumberOfMoles() < 1e-12 || pressure == 0) {
thermoOps.TPflash();
} else {
thermoOps.PHflash(enthalpy, 0);
}
outStream.setThermoSystem(thermoSystem);
// System.out.println("Total volume flow " +
// outStream.getThermoSystem().getVolume());
// Uncomment the line below to get the volume of the outlet stream's thermodynamic system
// System.out.println("Total volume flow " + outStream.getThermoSystem().getVolume());
// System.out.println("density valve " +
// inletStream.getThermoSystem().getDensity());

Expand Down Expand Up @@ -522,7 +538,9 @@ public void run(UUID id) {
}

/** {@inheritDoc} */
@Override
/**
* This annotation is used to exclude the method from Jacoco code coverage reports.
*/
@ExcludeFromJacocoGeneratedReport
public void displayResult() {
thermoSystem.display(getName());
Expand Down Expand Up @@ -813,4 +831,13 @@ public double getFp() {
public void setFp(double fp) {
Fp = fp;
}

public double getDeltaPressure() {
return deltaPressure;
}

public void setDeltaPressure(double deltaPressure, String unit) {
this.deltaPressure = deltaPressure;
this.pressureUnit = unit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,57 @@ void testCalcCvLiquid() {
assertEquals(100, stream1.getFlowRate("kg/hr"), 1e-2);
assertEquals(3.015805897362369E-4, valve1.getCv("US"), 1e-2);
}

@Test
void testSetDeltaPressure() {
neqsim.thermo.system.SystemInterface testSystem2 =
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00);
testSystem2.addComponent("methane", 1.0);
testSystem2.setMixingRule(2);

Stream stream1 = new Stream("Stream1", testSystem2);
stream1.setFlowRate(100.0, "kg/hr");
stream1.setPressure(100.0, "bara");
stream1.setTemperature(55.0, "C");
stream1.run();

double deltaPressure = 10.0;
ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1);
valve1.setDeltaPressure(deltaPressure, "bara");
valve1.run();

Stream stream2 = new Stream("Stream1", valve1.getOutletStream());
stream2.getPressure("bara");
stream2.run();

assertEquals(deltaPressure, valve1.getDeltaPressure(), 1e-2);
assertEquals(deltaPressure, stream1.getPressure("bara") - stream2.getPressure("bara"), 1e-4);
assertEquals(52.269428855, stream2.getTemperature("C"), 1e-2);
}

@Test
void testSetDeltaPressure2() {
neqsim.thermo.system.SystemInterface testSystem2 =
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00);
testSystem2.addComponent("methane", 1.0);
testSystem2.setMixingRule(2);

Stream stream1 = new Stream("Stream1", testSystem2);
stream1.setFlowRate(100.0, "kg/hr");
stream1.setPressure(100.0, "bara");
stream1.setTemperature(55.0, "C");
stream1.run();

double deltaPressure = 0.0;
ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1);
valve1.run();

Stream stream2 = new Stream("Stream1", valve1.getOutletStream());
stream2.getPressure("bara");
stream2.run();

assertEquals(deltaPressure, valve1.getDeltaPressure(), 1e-2);
assertEquals(deltaPressure, stream1.getPressure("bara") - stream2.getPressure("bara"), 1e-4);
assertEquals(55.0, stream2.getTemperature("C"), 1e-2);
}
}
Loading