Skip to content

Commit

Permalink
Transient test error fix (#327)
Browse files Browse the repository at this point in the history
* fix ertor in test

* Update ProcessSystemRunTransientTest.java
  • Loading branch information
EvenSol authored Feb 21, 2022
1 parent b8f1072 commit 26922fe
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void runTransient(double percentSignal, double dt) {
TintValue += Ksp / Tint * error * dt;
double TderivValue = Ksp * Tderiv * (error - oldError) / dt;
response = percentSignal + propConstant * (Ksp * error + TintValue + TderivValue);
System.out.println("error " + error + " %");
//System.out.println("error " + error + " %");
// error = device.getMeasuredPercentValue()-controlValue;
// double regulatorSignal = error*1.0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public void displayResult() {
@Override
public double getMeasuredValue() {
stream.getThermoSystem().initPhysicalProperties();
if (unit.equals("m^3/hr")) {
if (unit.equals("kg/hr")) {
return stream.getFlowRate(unit);
}
else if (unit.equals("m^3/hr")) {
return stream.getThermoSystem().getPhase(measuredPhaseNumber).getNumberOfMolesInPhase()
* stream.getThermoSystem().getPhase(measuredPhaseNumber).getMolarMass()
/ stream.getThermoSystem().getPhase(measuredPhaseNumber).getPhysicalProperties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public String[][] getResultTable() {
public void runTransient(double dt) {
inletStreamMixer.run();

System.out.println("moles out" + liquidOutStream.getThermoSystem().getTotalNumberOfMoles());
//System.out.println("moles out" + liquidOutStream.getThermoSystem().getTotalNumberOfMoles());
// double inMoles =
// inletStreamMixer.getOutStream().getThermoSystem().getTotalNumberOfMoles();
// double gasoutMoles = gasOutStream.getThermoSystem().getNumberOfMoles();
Expand All @@ -275,11 +275,11 @@ public void runTransient(double dt) {
gasOutStream.getThermoSystem().init(3);
liquidOutStream.getThermoSystem().init(3);
double volume1 = thermoSystem.getVolume();
System.out.println("volume1 " + volume1);
//System.out.println("volume1 " + volume1);
double deltaEnergy = inletStreamMixer.getOutStream().getThermoSystem().getEnthalpy()
- gasOutStream.getThermoSystem().getEnthalpy()
- liquidOutStream.getThermoSystem().getEnthalpy();
System.out.println("enthalph delta " + deltaEnergy);
//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.getOutStream().getThermoSystem().getPhase(0)
Expand All @@ -290,7 +290,7 @@ public void runTransient(double dt) {
.getNumberOfMolesInPhase()
- liquidOutStream.getThermoSystem().getPhase(0).getComponent(i)
.getNumberOfMolesInPhase();
System.out.println("dn " + dn);
//System.out.println("dn " + dn);
thermoSystem.addComponent(inletStreamMixer.getOutStream().getThermoSystem().getPhase(0)
.getComponent(i).getComponentNumber(), dn * dt);
}
Expand All @@ -300,7 +300,7 @@ public void runTransient(double dt) {
setTempPres(thermoSystem.getTemperature(), thermoSystem.getPressure());

liquidLevel = thermoSystem.getPhase(1).getVolume() * 1e-5 / (liquidVolume + gasVolume);
System.out.println("liquid level " + liquidLevel);
//System.out.println("liquid level " + liquidLevel);
liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter()
* getSeparatorLength();
gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void runTransient(double dt) {
} else {
thermoOps.PHflash(enthalpy, 0);
}
thermoSystem.initPhysicalProperties("density");
outStream.setThermoSystem(thermoSystem);
// if(getPercentValveOpening()<99){
molarFlow =
Expand Down Expand Up @@ -288,7 +289,7 @@ public void runController(double dt) {
if (this.percentValveOpening < 0) {
this.percentValveOpening = 1e-10;
}
System.out.println("valve opening " + this.percentValveOpening + " %");
//System.out.println("valve opening " + this.percentValveOpening + " %");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,60 +52,55 @@ private SystemInterface getTestSystem() {
@Test
public void testDynamicCalculation() {
neqsim.thermo.system.SystemInterface testSystem = getTestSystem();

Stream stream_1 = new Stream("Stream1", testSystem);
stream_1.setFlowRate(50.0, "kg/hr");
stream_1.setPressure(10.0, "bara");

ThrottlingValve valve_1 = new ThrottlingValve(stream_1);
valve_1.setOutletPressure(5.0);
valve_1.setPercentValveOpening(50);

Separator separator_1 = new Separator();
Separator separator_1 = new Separator("sep 1");
separator_1.addStream(valve_1.getOutStream());

ThrottlingValve valve_2 = new ThrottlingValve(separator_1.getLiquidOutStream());
valve_2.setOutletPressure(1.0);
valve_2.setPercentValveOpening(50);
// valve_2.setCv(10.0);

ThrottlingValve valve_3 = new ThrottlingValve(separator_1.getGasOutStream());
valve_3.setOutletPressure(1.0);
valve_3.setPercentValveOpening(50);

VolumeFlowTransmitter flowTransmitter = new VolumeFlowTransmitter(stream_1);
flowTransmitter.setUnit("m^3/hr");
flowTransmitter.setMaximumValue(10.0);
flowTransmitter.setUnit("kg/hr");
flowTransmitter.setMaximumValue(100.0);
flowTransmitter.setMinimumValue(1.0);

ControllerDeviceInterface flowController = new ControllerDeviceBaseClass();
flowController.setTransmitter(flowTransmitter);
flowController.setReverseActing(true);
flowController.setControllerSetPoint(1.0);
flowController.setControllerParameters(0.7, 300.0, 0.0);
flowController.setControllerSetPoint(63.5);
flowController.setControllerParameters(0.1, 0.10, 0.0);

p.add(stream_1);
p.add(valve_1);
p.add(separator_1);
p.add(valve_2);
p.add(valve_3);

p.add(flowTransmitter);
valve_1.setController(flowController);

p.run();
// p.displayResult();
valve_2.setPercentValveOpening(0.1);
valve_3.setPercentValveOpening(0.1);

// transient behaviour
p.setTimeStep(1.0);
for (int i = 0; i < 460; i++) {
System.out.println("volume flow " + flowTransmitter.getMeasuredValue()
+ " valve opening " + valve_1.getPercentValveOpening() + " pressure "
+ separator_1.getGasOutStream().getPressure());
for (int i = 0; i < 5; i++) {
// System.out.println("volume flow " + flowTransmitter.getMeasuredValue()
// + " valve opening " + valve_1.getPercentValveOpening() + " pressure "
// + separator_1.getGasOutStream().getPressure());
p.runTransient();
}

// p.displayResult();
System.out.println("volume flow " + flowTransmitter.getMeasuredValue() + " valve opening "
+ valve_1.getPercentValveOpening());
}

@Test
Expand All @@ -116,7 +111,7 @@ public void testDynamicCalculation2() {
10.00);
testSystem2.addComponent("methane", 1.1);
testSystem2.addComponent("ethane", 0.10001);
testSystem2.addComponent("n-heptane", 0.001);
testSystem2.addComponent("n-heptane", 1.001);
testSystem2.setMixingRule(2);

Stream purgeStream = new Stream("Purge Stream", testSystem2);
Expand Down Expand Up @@ -184,8 +179,7 @@ public void testDynamicCalculation2() {

p.run();
// p.displayResult();
p.setTimeStep(0.001);
p.runTransient();
p.setTimeStep(0.0001);
p.runTransient();
}
}

0 comments on commit 26922fe

Please sign in to comment.