Skip to content

Commit

Permalink
updated dynamics calc
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed Dec 3, 2023
1 parent d39c594 commit e48c982
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public class ControllerDeviceBaseClass extends NamedBaseClass implements Control
private double TintValue = 0.0;

/**
* <p>Constructor for ControllerDeviceBaseClass.</p>
* <p>
* Constructor for ControllerDeviceBaseClass.
* </p>
*/
public ControllerDeviceBaseClass() {
super("controller");
Expand Down Expand Up @@ -75,7 +77,8 @@ public void runTransient(double initResponse, double dt, UUID id) {
transmitter.getMeasuredPercentValue() - (controllerSetPoint - transmitter.getMinimumValue())
/ (transmitter.getMaximumValue() - transmitter.getMinimumValue()) * 100;

TintValue += Kp / Ti * error * dt;
if (Ti > 0)
TintValue += Kp / Ti * error * dt;
double TderivValue = Kp * Td * (error - oldError) / dt;
response = initResponse + propConstant * (Kp * error + TintValue + TderivValue);
// System.out.println("error " + error + " %");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,47 +244,52 @@ public void run(UUID id) {
liquidOutStream.getFluid().init(3);
}
// liquidOutStream.setThermoSystemFromPhase(thermoSystem2, "aqueous");
try {
thermoSystem = thermoSystem2.clone();
thermoSystem.setTotalNumberOfMoles(1.0e-10);
thermoSystem.init(1);
// System.out.println("number of phases " + thermoSystem.getNumberOfPhases());
double totalliquidVolume = 0.0;
for (int j = 0; j < thermoSystem.getNumberOfPhases(); j++) {
double relFact = gasVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5);
if (j >= 1) {
relFact = liquidVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5);

totalliquidVolume += liquidVolume / thermoSystem2.getPhase(j).getMolarVolume();
}
for (int i = 0; i < thermoSystem.getPhase(j).getNumberOfComponents(); i++) {
thermoSystem.addComponent(thermoSystem.getPhase(j).getComponent(i).getComponentNumber(),
relFact * thermoSystem2.getPhase(j).getComponent(i).getNumberOfMolesInPhase(), j);
if (getCalculateSteadyState()) {
thermoSystem = thermoSystem2;
} else {
try {
thermoSystem = thermoSystem2.clone();
// thermoSystem.setTotalNumberOfMoles(1.0);
thermoSystem.init(1);
// System.out.println("number of phases " + thermoSystem.getNumberOfPhases());
double totalliquidVolume = 0.0;
for (int j = 0; j < thermoSystem.getNumberOfPhases(); j++) {
double relFact = gasVolume / (thermoSystem2.getPhase(j).getVolume("m3"));
if (j >= 1) {
relFact = liquidVolume / (thermoSystem2.getPhase(j).getVolume("m3"));

totalliquidVolume += liquidVolume / thermoSystem2.getPhase(j).getMolarVolume();
}

for (int i = 0; i < thermoSystem.getPhase(j).getNumberOfComponents(); i++) {
thermoSystem.addComponent(i, Math.signum(relFact - 1.0) * relFact
* thermoSystem2.getPhase(j).getComponent(i).getNumberOfMolesInPhase(), j);
}
}
}

if (thermoSystem.hasPhaseType("gas")) {
thermoSystem.setBeta(gasVolume / thermoSystem2.getPhase(0).getMolarVolume()
/ (gasVolume / thermoSystem2.getPhase(0).getMolarVolume() + totalliquidVolume));
if (thermoSystem.hasPhaseType("gas")) {
thermoSystem.setBeta(gasVolume / thermoSystem2.getPhase(0).getMolarVolume()
/ (gasVolume / thermoSystem2.getPhase(0).getMolarVolume() + totalliquidVolume));
}
thermoSystem.initBeta();
thermoSystem.init(3);
// System.out.println("moles in separator " + thermoSystem.getNumberOfMoles());
// double volume1 = thermoSystem.getVolume();
// System.out.println("volume1 bef " + volume1);
// System.out.println("beta " + thermoSystem.getBeta());

liquidLevel = thermoSystem.getPhase(1).getVolume("m3") / (liquidVolume + gasVolume);
liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter()
* getSeparatorLength();
gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter()
* getInternalDiameter() * getSeparatorLength();
// System.out.println("moles out" +
// liquidOutStream.getThermoSystem().getTotalNumberOfMoles());
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
thermoSystem.initBeta();
thermoSystem.init(3);
// System.out.println("moles in separator " + thermoSystem.getNumberOfMoles());
// double volume1 = thermoSystem.getVolume();
// System.out.println("volume1 bef " + volume1);
// System.out.println("beta " + thermoSystem.getBeta());

liquidLevel = thermoSystem.getPhase(1).getVolume() * 1e-5 / (liquidVolume + gasVolume);
liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter()
* getSeparatorLength();
gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter()
* getInternalDiameter() * getSeparatorLength();
// System.out.println("moles out" +
// liquidOutStream.getThermoSystem().getTotalNumberOfMoles());
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
thermoSystem = thermoSystem2;
// thermoSystem = thermoSystem2;
setCalculationIdentifier(id);
}

Expand All @@ -307,49 +312,44 @@ public void runTransient(double dt, UUID id) {
run(id);
increaseTime(dt);
return;
}
} else {
inletStreamMixer.run(id);
thermoSystem.init(3);
gasOutStream.getThermoSystem().init(3);
liquidOutStream.getThermoSystem().init(3);
double volume1 = thermoSystem.getVolume("m3");
// System.out.println("volume " + volume1);
double deltaEnergy = inletStreamMixer.getOutletStream().getThermoSystem().getEnthalpy()
- gasOutStream.getThermoSystem().getEnthalpy()
- liquidOutStream.getThermoSystem().getEnthalpy();
// System.out.println("enthalph delta " + deltaEnergy);
double newEnergy = thermoSystem.getInternalEnergy() + dt * deltaEnergy;
for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) {
double dn = inletStreamMixer.getOutletStream().getThermoSystem().getPhase(0).getComponent(i)
.getNumberOfMolesInPhase()
+ inletStreamMixer.getOutletStream().getThermoSystem().getPhase(1).getComponent(i)
.getNumberOfMolesInPhase()
- gasOutStream.getThermoSystem().getPhase(0).getComponent(i).getNumberOfMolesInPhase()
- liquidOutStream.getThermoSystem().getPhase(0).getComponent(i)
.getNumberOfMolesInPhase();
// System.out.println("dn " + dn);
thermoSystem.addComponent(inletStreamMixer.getOutletStream().getThermoSystem().getPhase(0)
.getComponent(i).getComponentNumber(), dn * dt);
}
ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem);
thermoOps.VUflash(volume1, newEnergy, "m3", "J");

inletStreamMixer.run(id);
setTempPres(thermoSystem.getTemperature(), thermoSystem.getPressure());

// System.out.println("moles out" +
// liquidOutStream.getThermoSystem().getTotalNumberOfMoles());
// double inMoles =
// inletStreamMixer.getOutStream().getThermoSystem().getTotalNumberOfMoles();
// double gasoutMoles = gasOutStream.getThermoSystem().getNumberOfMoles();
// double liqoutMoles = liquidOutStream.getThermoSystem().getNumberOfMoles();
thermoSystem.init(3);
gasOutStream.getThermoSystem().init(3);
liquidOutStream.getThermoSystem().init(3);
double volume1 = thermoSystem.getVolume();
// System.out.println("volume1 " + volume1);
double deltaEnergy = inletStreamMixer.getOutletStream().getThermoSystem().getEnthalpy()
- gasOutStream.getThermoSystem().getEnthalpy()
- liquidOutStream.getThermoSystem().getEnthalpy();
// System.out.println("enthalph delta " + deltaEnergy);
double newEnergy = thermoSystem.getInternalEnergy() + dt * deltaEnergy;
for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) {
double dn = inletStreamMixer.getOutletStream().getThermoSystem().getPhase(0).getComponent(i)
.getNumberOfMolesInPhase()
+ inletStreamMixer.getOutletStream().getThermoSystem().getPhase(1).getComponent(i)
.getNumberOfMolesInPhase()
- gasOutStream.getThermoSystem().getPhase(0).getComponent(i).getNumberOfMolesInPhase()
- liquidOutStream.getThermoSystem().getPhase(0).getComponent(i).getNumberOfMolesInPhase();
// System.out.println("dn " + dn);
thermoSystem.addComponent(inletStreamMixer.getOutletStream().getThermoSystem().getPhase(0)
.getComponent(i).getComponentNumber(), dn * dt);
liquidLevel = thermoSystem.getPhase(1).getVolume("m3") / (liquidVolume + gasVolume);
// System.out.println("liquid level " + liquidLevel);
liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter()
* getSeparatorLength();
// System.out.println("gasvol " + gasVolume + " liqvol " + liquidVolume);
gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter()
* getInternalDiameter() * getSeparatorLength();
setCalculationIdentifier(id);
}
ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem);
thermoOps.VUflash(volume1, newEnergy);

setTempPres(thermoSystem.getTemperature(), thermoSystem.getPressure());

liquidLevel = thermoSystem.getPhase(1).getVolume() * 1e-5 / (liquidVolume + gasVolume);
// System.out.println("liquid level " + liquidLevel);
liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter()
* getSeparatorLength();
gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter()
* getInternalDiameter() * getSeparatorLength();
setCalculationIdentifier(id);
}

/**
Expand Down Expand Up @@ -499,7 +499,7 @@ public void setInternalDiameter(double diameter) {
* @return a double
*/
public double getGasSuperficialVelocity() {
return thermoSystem.getPhase(0).getTotalVolume() / 1e5
return thermoSystem.getPhase(0).getVolume("m3")
/ (neqsim.thermo.ThermodynamicConstantsInterface.pi * getInternalDiameter()
* getInternalDiameter() / 4.0);
}
Expand Down Expand Up @@ -554,7 +554,7 @@ public double getDeRatedGasLoadFactor() {
if (surfaceTension < 10.0e-3) {
derating = 1.0 - 0.5 * (10.0e-3 - surfaceTension) / 10.0e-3;
}
System.out.println("derating " + derating);
// System.out.println("derating " + derating);
double term1 = (thermoSystem.getPhase(1).getPhysicalProperties().getDensity()
- thermoSystem.getPhase(0).getPhysicalProperties().getDensity())
/ thermoSystem.getPhase(0).getPhysicalProperties().getDensity();
Expand All @@ -577,7 +577,7 @@ public double getDeRatedGasLoadFactor(int phase) {
if (surfaceTension < 10.0e-3) {
derating = 1.0 - 0.5 * (10.0e-3 - surfaceTension) / 10.0e-3;
}
System.out.println("derating " + derating);
// System.out.println("derating " + derating);
double term1 = (thermoSystem.getPhase(phase).getPhysicalProperties().getDensity()
- thermoSystem.getPhase(0).getPhysicalProperties().getDensity())
/ thermoSystem.getPhase(0).getPhysicalProperties().getDensity();
Expand Down Expand Up @@ -658,7 +658,7 @@ public SeparatorSection getSeparatorSection(String name) {
return sec;
}
}
System.out.println("no section with name: " + name + " found.....");
// System.out.println("no section with name: " + name + " found.....");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ProcessSystem extends SimulationBaseClass {
static Logger logger = LogManager.getLogger(ProcessSystem.class);

transient Thread thisThread;
String[][] signalDB = new String[1000][100];
String[][] signalDB = new String[10000][100];
private double surroundingTemperature = 288.15;
private int timeStepNumber = 0;
private ArrayList<ProcessEquipmentInterface> unitOperations =
Expand Down
Loading

0 comments on commit e48c982

Please sign in to comment.