Skip to content

Commit

Permalink
update dynamic calc
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed Dec 3, 2023
1 parent 691867a commit 4d78342
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,23 @@ public void runTransient(double dt, UUID id) {
if (getCalculateSteadyState()) {
run(id);
increaseTime(dt);
setCalculationIdentifier(id);
return;
} else {
inletStreamMixer.run(id);
thermoSystem.init(3);
thermoSystem.initPhysicalProperties("density");
gasOutStream.getThermoSystem().init(3);
liquidOutStream.getThermoSystem().init(3);
try {
gasOutStream.getThermoSystem().init(3);
liquidOutStream.getThermoSystem().init(3);
} catch (Exception e) {
logger.error(e.getMessage());
}
double deltaEnergy = inletStreamMixer.getOutletStream().getThermoSystem().getEnthalpy()
- gasOutStream.getThermoSystem().getEnthalpy()
- liquidOutStream.getThermoSystem().getEnthalpy();
double newEnergy = thermoSystem.getInternalEnergy() + dt * deltaEnergy;
thermoSystem.init(0);
for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) {
double dncomp = 0.0;
for (int j = 0; j < inletStreamMixer.getOutletStream().getFluid()
Expand All @@ -336,8 +342,19 @@ public void runTransient(double dt, UUID id) {
}
ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem);
thermoOps.VUflash(gasVolume + liquidVolume, newEnergy, "m3", "J");
setTempPres(thermoSystem.getTemperature(), thermoSystem.getPressure());
thermoSystem.initPhysicalProperties("density");

if (thermoSystem.hasPhaseType("gas")) {
gasOutStream.getFluid().setMolarComposition(thermoSystem.getPhase(0).getMolarComposition());
}
if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) {
if (thermoSystem.getNumberOfPhases() > 1) {
liquidOutStream.getFluid()
.setMolarComposition(thermoSystem.getPhase(1).getMolarComposition());
}
}
setTempPres(thermoSystem.getTemperature(), thermoSystem.getPressure());

liquidLevel = 0.0;
if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) {
double volumeLoc = 0.0;
Expand All @@ -353,18 +370,8 @@ public void runTransient(double dt, UUID id) {
* getSeparatorLength();
gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter()
* getInternalDiameter() * getSeparatorLength();
// System.out.println("gas volume " + gasVolume + " liq volime " + liquidVolume);
setCalculationIdentifier(id);

if (thermoSystem.hasPhaseType("gas")) {
gasOutStream.setPressure(thermoSystem.getPressure("bara"), "bara");
gasOutStream.setTemperature(thermoSystem.getTemperature("C"), "C");
}
if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) {
liquidOutStream.setPressure(thermoSystem.getPressure("bara"), "bara");
liquidOutStream.setTemperature(thermoSystem.getTemperature("C"), "C");
}
gasOutStream.run();
liquidOutStream.run();
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package neqsim.processSimulation.processEquipment.valve;

import java.util.UUID;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.processSimulation.mechanicalDesign.valve.ValveMechanicalDesign;
import neqsim.processSimulation.processEquipment.TwoPortEquipment;
import neqsim.processSimulation.processEquipment.stream.StreamInterface;
Expand All @@ -17,7 +19,7 @@
*/
public class ThrottlingValve extends TwoPortEquipment implements ValveInterface {
private static final long serialVersionUID = 1000;

static Logger logger = LogManager.getLogger(ThrottlingValve.class);
SystemInterface thermoSystem;

private boolean valveCvSet = false;
Expand Down Expand Up @@ -274,7 +276,7 @@ public void runTransient(double dt, UUID id) {
double enthalpy = thermoSystem.getEnthalpy();
thermoSystem.setPressure(getOutletStream().getThermoSystem().getPressure());
// System.out.println("enthalpy inn.." + enthalpy);
if (isIsoThermal()) {
if (isIsoThermal() || thermoSystem.getTotalNumberOfMoles() < 0.0001) {
thermoOps.TPflash();
} else {
thermoOps.PHflash(enthalpy, 0);
Expand All @@ -294,14 +296,19 @@ public void runTransient(double dt, UUID id) {
// molarFlow=inletStream.getThermoSystem().getTotalNumberOfMoles();
// }

inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow);
inStream.getThermoSystem().init(1);
inStream.run(id);

outStream.getThermoSystem().setTotalNumberOfMoles(molarFlow);
outStream.getThermoSystem().init(1);
outStream.run(id);

if (molarFlow > 1e-4) {
try {
inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow);
inStream.getThermoSystem().init(1);
inStream.run(id);

outStream.getThermoSystem().setTotalNumberOfMoles(molarFlow);
outStream.getThermoSystem().init(1);
outStream.run(id);
} catch (Exception e) {
logger.error(e.getMessage());
}
}
// System.out.println("delta p valve " +
// (inletStream.getThermoSystem().getPressure() -
// outStream.getThermoSystem().getPressure()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public void testDynamicCalculation() {

Separator separator1 = new Separator("sep 1");
separator1.addStream(valve1.getOutletStream());
separator1.setInternalDiameter(1.0);
separator1.setSeparatorLength(2.5);
separator1.setLiquidLevel(0.5);

ThrottlingValve valve2 = new ThrottlingValve("valve_2", separator1.getLiquidOutStream());
valve2.setOutletPressure(1.0);
Expand All @@ -79,7 +82,7 @@ public void testDynamicCalculation() {
flowController.setTransmitter(flowTransmitter);
flowController.setReverseActing(true);
flowController.setControllerSetPoint(63.5);
flowController.setControllerParameters(1.2, 100.0, 0.0);
flowController.setControllerParameters(0.4, 10.0, 0.0);

p.add(stream1);
p.add(valve1);
Expand Down Expand Up @@ -120,7 +123,7 @@ public void testDynamicCalculation2() {
testSystem3.setMixingRule(2);

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

Expand Down Expand Up @@ -149,7 +152,7 @@ public void testDynamicCalculation2() {

ThrottlingValve valve2 = new ThrottlingValve("valve_2", separator1.getLiquidOutStream());
valve2.setOutletPressure(1.0);
valve2.setPercentValveOpening(50);
valve2.setPercentValveOpening(25);
valve2.setCalculateSteadyState(false);

ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream());
Expand All @@ -166,7 +169,7 @@ public void testDynamicCalculation2() {
separatorLevelController.setReverseActing(false);
separatorLevelController.setTransmitter(separatorLevelTransmitter);
separatorLevelController.setControllerSetPoint(0.45);
separatorLevelController.setControllerParameters(0.0510, 200.0, 0.0);
separatorLevelController.setControllerParameters(1.0, 0.0, 0.0);

PressureTransmitter separatorPressureTransmitter =
new PressureTransmitter(separator1.getGasOutStream());
Expand All @@ -178,7 +181,7 @@ public void testDynamicCalculation2() {
separatorPressureController.setTransmitter(separatorPressureTransmitter);
separatorPressureController.setReverseActing(false);
separatorPressureController.setControllerSetPoint(7.0);
separatorPressureController.setControllerParameters(0.05, 0.0, 0.0);
separatorPressureController.setControllerParameters(0.1, 50.0, 0.0);

p.add(stream1);
p.add(streamPurge);
Expand All @@ -202,7 +205,7 @@ public void testDynamicCalculation2() {

// p.displayResult();
p.setTimeStep(1.0);
for (int i = 0; i < 900; i++) {
for (int i = 0; i < 100; i++) {
System.out.println("pressure " + separator1.getGasOutStream().getPressure() + " flow "
+ separator1.getGasOutStream().getFlowRate("kg/hr") + " sepr height "
+ separatorLevelTransmitter.getMeasuredValue() + "valve2 opening "
Expand Down

0 comments on commit 4d78342

Please sign in to comment.