Skip to content

Commit

Permalink
added test and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed Dec 3, 2023
1 parent 62ca186 commit a81212f
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ public void run(UUID id) {
if (thermoSystem2.hasPhaseType("aqueous") || thermoSystem2.hasPhaseType("oil")) {
liquidOutStream.run(id);
} else {
liquidOutStream.getFluid().init(3);
try {
liquidOutStream.getFluid().init(3);
} catch (Exception e) {
logger.error(e.getMessage());
}
}
if (getCalculateSteadyState()) {
thermoSystem = thermoSystem2;
Expand Down Expand Up @@ -274,7 +278,6 @@ public void run(UUID id) {
ops.TPflash();
thermoSystem.init(3);
thermoSystem.initPhysicalProperties("density");
// thermoSystem.prettyPrint();
if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) {
liquidLevel = thermoSystem.getPhase(1).getVolume("m3") / (liquidVolume + gasVolume);
liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter()
Expand Down Expand Up @@ -324,17 +327,24 @@ public void runTransient(double dt, UUID id) {
} catch (Exception e) {
logger.error(e.getMessage());
}
double deliq = 0.0;
if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) {
deliq = -liquidOutStream.getThermoSystem().getEnthalpy();
}
double deltaEnergy = inletStreamMixer.getOutletStream().getThermoSystem().getEnthalpy()
- gasOutStream.getThermoSystem().getEnthalpy()
- liquidOutStream.getThermoSystem().getEnthalpy();
- gasOutStream.getThermoSystem().getEnthalpy() + deliq;
double newEnergy = thermoSystem.getInternalEnergy() + dt * deltaEnergy;
thermoSystem.init(0);
for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) {
double dncomp = 0.0;
dncomp +=
inletStreamMixer.getOutletStream().getThermoSystem().getComponent(i).getNumberOfmoles();
dncomp += -gasOutStream.getThermoSystem().getComponent(i).getNumberOfmoles()
- liquidOutStream.getThermoSystem().getComponent(i).getNumberOfmoles();
double dniliq = 0.0;
if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) {
dniliq = -liquidOutStream.getThermoSystem().getComponent(i).getNumberOfmoles();
}
dncomp += -gasOutStream.getThermoSystem().getComponent(i).getNumberOfmoles() + dniliq;

thermoSystem.addComponent(i, dncomp * dt);
}
ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ public void run(UUID id) {
molarFlow = inStream.getThermoSystem().getTotalNumberOfMoles();
}

inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow);
inStream.getThermoSystem().init(3);
try {
inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow);
inStream.getThermoSystem().init(3);
} catch (Exception e) {
logger.error(e.getMessage());
}
// inletStream.run(id);

outStream.setThermoSystem(thermoSystem.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public void run() {
try {
bubOps.TPflash();
if (system.getPhase(0).getType() == PhaseType.GAS) {
bubOps.dewPointTemperatureFlash();
try {
bubOps.dewPointTemperatureFlash();
} catch (Exception e) {
system.setTemperature(298.0);
}
} else {
bubOps.bubblePointTemperatureFlash();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public void testDynamicCalculation() {
// transient behaviour
p.setTimeStep(1.0);
for (int i = 0; i < 50; i++) {
// System.out.println("volume flow " + flowTransmitter.getMeasuredValue() + " valve opening "
// + valve1.getPercentValveOpening() + " pressure "
// + separator1.getGasOutStream().getPressure());
// System.out.println("volume flow " + flowTransmitter.getMeasuredValue() + " valve opening "
// + valve1.getPercentValveOpening() + " pressure "
// + separator1.getGasOutStream().getPressure());
p.runTransient();
for (SimulationInterface sim : p.getUnitOperations()) {
assertEquals(sim.getCalculationIdentifier(), p.getCalculationIdentifier());
Expand All @@ -113,13 +113,13 @@ public void testDynamicCalculation2() {
neqsim.thermo.system.SystemInterface testSystem2 =
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00);
testSystem2.addComponent("methane", 1.1);
testSystem2.addComponent("n-heptane", 1.001);
testSystem2.addComponent("water", 1.001);
testSystem2.setMixingRule(2);

neqsim.thermo.system.SystemInterface testSystem3 =
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00);
testSystem3.addComponent("methane", 1.1);
testSystem3.addComponent("n-heptane", 0.001);
testSystem3.addComponent("water", 0.001);
testSystem3.setMixingRule(2);

Stream stream1 = new Stream("Stream1", testSystem2);
Expand Down Expand Up @@ -206,10 +206,97 @@ public void testDynamicCalculation2() {
// p.displayResult();
p.setTimeStep(2.0);
for (int i = 0; i < 500; i++) {
// System.out.println("pressure " + separator1.getGasOutStream().getPressure() + " flow "
// + separator1.getGasOutStream().getFlowRate("kg/hr") + " sepr height "
// + separatorLevelTransmitter.getMeasuredValue() + "valve2 opening "
// + valve2.getPercentValveOpening() + "valve3 opening " + valve3.getPercentValveOpening());
System.out.println("pressure " + separator1.getGasOutStream().getPressure() + " flow "
+ separator1.getGasOutStream().getFlowRate("kg/hr") + " sepr height "
+ separatorLevelTransmitter.getMeasuredValue() + "valve2 opening "
+ valve2.getPercentValveOpening() + "valve3 opening " + valve3.getPercentValveOpening());
p.runTransient();
for (SimulationInterface sim : p.getUnitOperations()) {
assertEquals(p.getCalculationIdentifier(), sim.getCalculationIdentifier());
}
}
}

@Test
public void testDynamicCalculation3() {
neqsim.thermo.system.SystemInterface testSystem2 =
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00);
testSystem2.addComponent("methane", 1.1);
testSystem2.addComponent("ethane", 0.1);
testSystem2.setMixingRule(2);

neqsim.thermo.system.SystemInterface testSystem3 =
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00);
testSystem3.addComponent("methane", 1.1);
testSystem2.addComponent("ethane", 0.1);
testSystem3.setMixingRule(2);

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

Stream streamPurge = new Stream("StreamPurge", testSystem3);
streamPurge.setFlowRate(5.0, "kg/hr");
streamPurge.setPressure(10.0, "bara");
streamPurge.setTemperature(25.0, "C");

ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1);
valve1.setOutletPressure(7.0);
valve1.setPercentValveOpening(50);
valve1.setCalculateSteadyState(false);

ThrottlingValve valvePurge = new ThrottlingValve("valve_purge", streamPurge);
valvePurge.setOutletPressure(7.0);
valvePurge.setPercentValveOpening(50);
valvePurge.setCalculateSteadyState(false);

Separator separator1 = new Separator("separator_1");
separator1.addStream(valve1.getOutletStream());
separator1.addStream(valvePurge.getOutletStream());
separator1.setCalculateSteadyState(false);
separator1.setSeparatorLength(3.0);
separator1.setInternalDiameter(0.8);
separator1.setLiquidLevel(0.0);

ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream());
valve3.setOutletPressure(1.0);
valve3.setPercentValveOpening(50);
valve3.setCalculateSteadyState(false);

PressureTransmitter separatorPressureTransmitter =
new PressureTransmitter(separator1.getGasOutStream());
separatorPressureTransmitter.setUnit("bar");
separatorPressureTransmitter.setMaximumValue(10.0);
separatorPressureTransmitter.setMinimumValue(1.0);

ControllerDeviceInterface separatorPressureController = new ControllerDeviceBaseClass();
separatorPressureController.setTransmitter(separatorPressureTransmitter);
separatorPressureController.setReverseActing(false);
separatorPressureController.setControllerSetPoint(5.0);
separatorPressureController.setControllerParameters(0.5, 100.0, 0.0);

p.add(stream1);
p.add(streamPurge);
p.add(valve1);
p.add(valvePurge);
p.add(separator1);
p.add(valve3);

p.add(separatorPressureTransmitter);
valve3.setController(separatorPressureController);

p.run();
for (SimulationInterface sim : p.getUnitOperations()) {
assertEquals(sim.getCalculationIdentifier(), p.getCalculationIdentifier());
}

// p.displayResult();
p.setTimeStep(0.01);
for (int i = 0; i < 50; i++) {
System.out.println("pressure " + separator1.getGasOutStream().getPressure() + " flow "
+ separator1.getGasOutStream().getFlowRate("kg/hr") + "valve3 opening "
+ valve3.getPercentValveOpening());
p.runTransient();
for (SimulationInterface sim : p.getUnitOperations()) {
assertEquals(p.getCalculationIdentifier(), sim.getCalculationIdentifier());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package neqsim.thermodynamicOperations.flashOps;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import neqsim.thermodynamicOperations.ThermodynamicOperations;

/**
* Test VUFlash.
*/
class VUFlashTest {
static Logger logger = LogManager.getLogger(VUFlashTest.class);

static neqsim.thermo.system.SystemInterface testSystem = null;
static neqsim.thermo.system.SystemInterface testSystem2 = null;
static ThermodynamicOperations testOps = null;

/**
* Sets up test system.
*
* @throws java.lang.Exception
*/
@BeforeEach
void setUp() throws Exception {

}

@Test
void testVUflash() {
testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(293.15, 23.5);
testSystem.addComponent("methane", 1.0);
testSystem.addComponent("ethane", 0.01);
testSystem.addComponent("n-pentane", 0.01);
testSystem.setMixingRule("classic");
testOps = new ThermodynamicOperations(testSystem);
testOps.TPflash();
testSystem.initProperties();

double volume = testSystem.getVolume("m3");
double internalenergy = testSystem.getInternalEnergy("J");

testOps.VUflash(volume * 1.1, internalenergy, "m3", "J");

assertEquals(21.387, testSystem.getPressure(), 0.01);
}

}

0 comments on commit a81212f

Please sign in to comment.