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

Cv method valves #1047

Merged
merged 7 commits into from
Jul 18, 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public interface ValveInterface extends ProcessEquipmentInterface, TwoPortInterf
*/
public double getCv();

/**
* <p>
* getCv.
* </p>
*
* @param unit can be SI or US SI is unit litre/minute US is gallons per minute
* @return a double
*/
public double getCv(String unit);

/**
* <p>
* setCv.
Expand All @@ -73,6 +83,16 @@ public interface ValveInterface extends ProcessEquipmentInterface, TwoPortInterf
*/
public void setCv(double Cv);

/**
* <p>
* setCv.
* </p>
*
* @param Cv a double
* @param unit can be SI or US SI is unit litre/minute US is gallons per minute
*/
public void setCv(double Cv, String unit);

/** {@inheritDoc} */
@Override
public SystemInterface getThermoSystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void calculate() {
TVP = this.thermoSystem.getPressure();
double liquidVolume = thermoSystem.getVolume();

this.thermoSystem.setPressure(0.9);
this.thermoSystem.setPressure(TVP * 0.9);
try {
this.thermoOps.TVflash(liquidVolume * 4.0);
} catch (Exception ex) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,9 @@ public double getFlowRate(String flowunit) {
return totalNumberOfMoles * getMolarMass() * 3600.0 / getDensity("kg/m3");
} else if (flowunit.equals("idSm3/hr")) {
return totalNumberOfMoles * getMolarMass() * 3600.0 / getIdealLiquidDensity("kg/m3");
} else if (flowunit.equals("gallons/min")) {
initPhysicalProperties("density");
return totalNumberOfMoles * getMolarMass() * 60.0 / getDensity("kg/m3") * 1000 / 3.78541178;
} else if (flowunit.equals("Sm3/sec")) {
return totalNumberOfMoles * ThermodynamicConstantsInterface.R
* ThermodynamicConstantsInterface.standardStateTemperature
Expand Down Expand Up @@ -4914,7 +4917,8 @@ public void setTotalFlowRate(double flowRate, String flowunit) {
logger.error(e.getMessage());
}
double density = 0.0;
if (flowunit.equals("Am3/hr") || flowunit.equals("Am3/min") || flowunit.equals("Am3/sec")) {
if (flowunit.equals("Am3/hr") || flowunit.equals("Am3/min") || flowunit.equals("gallons/min")
|| flowunit.equals("Am3/sec")) {
initPhysicalProperties("density");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ public double solveQ() {
double oldPres = system.getPressure();
double nyPres = system.getPressure();
double iterations = 1;
double error = 100.0, errorOld = 1000.0;
do {
iterations++;
errorOld = error;
oldPres = nyPres;
system.init(3);
nyPres = oldPres - (iterations) / (iterations + 10.0) * calcdQdV() / calcdQdVV();
Expand All @@ -88,9 +90,11 @@ public double solveQ() {
}
system.setPressure(nyPres);
tpFlash.run();
// System.out.println(" dQdv " + calcdQdV() + " new pressure " + nyPres + " error " +
// Math.abs((nyPres-oldPres)/(nyPres)) + " numberofphases "+system.getNumberOfPhases());
} while (Math.abs((nyPres - oldPres) / (nyPres)) > 1e-9 && iterations < 1000 || iterations < 3);
// System.out.println(" dQdv " + calcdQdV() + " new pressure " + nyPres + " error "
// + Math.abs((nyPres - oldPres) / (nyPres)) + " numberofphases "
// + system.getNumberOfPhases());
error = Math.abs(calcdQdV());
} while (Math.abs(error) > 1e-9 && iterations < 200 && error < errorOld || iterations < 3);
return nyPres;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/neqsim/util/unit/RateUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public double getConversionFactor(String name) {
factor = 1.0 / molarmass / 3600.0 * stddens;
} else if (name.equals("idSm3/day")) {
factor = 1.0 / molarmass / (3600.0 * 24.0) * stddens;
} else if (name.equals("gallons/min")) {
factor = 1.0 / molarmass / 60.0 * stddens / 10.0 * 3.78541178;
} else {
throw new RuntimeException(
new InvalidInputException(this, "getConversionFactor", "unit", "not supported"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package neqsim.processSimulation.processEquipment.valve;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import neqsim.processSimulation.processEquipment.stream.Stream;

public class ThrottlingValveTest {
@Test
void testCalcCvGas() {
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(7000, "Sm3/hr");
stream1.setPressure(10.0, "bara");
stream1.setTemperature(55.0, "C");
stream1.run();

ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1);
valve1.setOutletPressure(5.0);
valve1.setPercentValveOpening(100);
valve1.run();

assertEquals(48.2652, valve1.getCv("US"), 1e-2);
assertEquals(2649.7612, valve1.getCv("SI"), 1e-2);

}

@Test
void testCalcCvLiquid() {
neqsim.thermo.system.SystemInterface testSystem2 =
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00);
testSystem2.addComponent("water", 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();

ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1);
valve1.setOutletPressure(50.0);
valve1.setPercentValveOpening(100);
valve1.run();

assertEquals(0.4515327970, stream1.getFlowRate("gallons/min"), 1e-2);
assertEquals(0.0165567743765, valve1.getCv("SI"), 1e-2);
assertEquals(100.0, valve1.getPercentValveOpening(), 1e-2);
assertEquals(100, stream1.getFlowRate("kg/hr"), 1e-2);
assertEquals(3.015805897362369E-4, valve1.getCv("US"), 1e-2);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,34 @@ void testCalculate() {
SystemInterface testSystem = new SystemSrkEos(273.15 + 2.0, 1.0);
testSystem.addComponent("methane", 0.0006538);
testSystem.addComponent("ethane", 0.006538);
testSystem.addComponent("propane", 0.006538);
testSystem.addComponent("propane", 0.06538);
testSystem.addComponent("n-pentane", 0.1545);
testSystem.addComponent("nC10", 0.545);
testSystem.setMixingRule(2);
testSystem.init(0);
Standard_ASTM_D6377 standard = new Standard_ASTM_D6377(testSystem);
standard.setReferenceTemperature(37.8, "C");
standard.calculate();
Assertions.assertEquals(0.94552559993, standard.getValue("RVP", "bara"), 1e-3);
Assertions.assertEquals(1.666298367, standard.getValue("TVP", "bara"), 1e-3);
}

@Test
void testCalculate2() {
SystemInterface testSystem = new SystemSrkEos(273.15 + 2.0, 1.0);
testSystem.addComponent("methane", 0.026538);
testSystem.addComponent("ethane", 0.16538);
testSystem.addComponent("propane", 0.26538);
testSystem.addComponent("n-pentane", 0.545);
testSystem.addComponent("nC10", 0.545);
testSystem.addTBPfraction("C11", 0.545, 145.0 / 1000.0, 0.82);
testSystem.setMixingRule(2);
testSystem.init(0);
testSystem.setPressure(100.0);
Standard_ASTM_D6377 standard = new Standard_ASTM_D6377(testSystem);
standard.setReferenceTemperature(37.8, "C");
standard.calculate();
//Assertions.assertEquals(0.7298246193, standard.getValue("RVP", "bara"), 1e-3);
Assertions.assertEquals(1.8710732396722, standard.getValue("TVP", "bara"), 1e-3);
Assertions.assertEquals(3.017010, standard.getValue("RVP", "bara"), 1e-3);
Assertions.assertEquals(7.8448385024, standard.getValue("TVP", "bara"), 1e-3);
}
}