Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed Dec 3, 2024
1 parent 1535886 commit b528b23
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 78 deletions.
14 changes: 8 additions & 6 deletions src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException,
for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) {
sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz()
/ clonedSystem.getPhase(0).getComponent(i).getK();
sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK()
* clonedSystem.getPhase(0).getComponent(i).getz();
if (clonedSystem.getPhase(0).getComponent(i).getz() > 0) {
sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK()
* clonedSystem.getPhase(0).getComponent(i).getz();
}
}

int start = 0;
Expand All @@ -146,7 +148,7 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException,
// for (int j = 0; j < clonedSystem.getNumberOfPhases(); j++) {
for (int j = start; j >= end; j = j + mult) {
for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) {
Wi[j][i] = clonedSystem.getPhase(j).getComponent(i).getx();
Wi[j][i] = clonedSystem.getPhase(j).getComponent(i).getx();
logWi[i] = Math.log(Wi[j][i]);
}
iterations = 0;
Expand Down Expand Up @@ -256,9 +258,9 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException,
} while ((f.norm1() > 1e-6 && iterations < maxiterations && error[j] > 1e-6)
|| (iterations % 7) == 0 || iterations < 3);
// (error[j]<oldErr && oldErr<oldOldErr) &&
// logger.info("err " + error[j]);
// logger.info("iterations " + iterations);
// logger.info("f.norm1() " + f.norm1());
logger.info("err " + error[j]);
logger.info("iterations " + iterations);
logger.info("f.norm1() " + f.norm1());
if (iterations >= maxiterations) {
// logger.error("err staability check " + error[j]);
throw new neqsim.util.exception.TooManyIterationsException("too many iterations", null,
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/neqsim/thermodynamicoperations/flashops/TPflash.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void run() {
minGibbsPhase = 1;
}
// logger.debug("minimum gibbs phase " + minGibbsPhase);

minimumGibbsEnergy = system.getPhase(minGibbsPhase).getGibbsEnergy();
if (system.getPhase(0).getNumberOfComponents() == 1 || system.getMaxNumberOfPhases() == 1) {
system.setNumberOfPhases(1);
if (minGibbsPhase == 0) {
Expand Down Expand Up @@ -468,19 +468,23 @@ public void run() {
operation.run();
} else {
// Checks if gas or oil is the most stable phase
if (system.getPhase(0).getType() == PhaseType.GAS) {
gasgib = system.getPhase(0).getGibbsEnergy();
system.setPhaseType(0, PhaseType.byValue(0));
system.init(1, 0);
liqgib = system.getPhase(0).getGibbsEnergy();
} else {
liqgib = system.getPhase(0).getGibbsEnergy();
system.setPhaseType(0, PhaseType.byValue(1));
system.init(1, 0);
gasgib = system.getPhase(0).getGibbsEnergy();
}
try {
if (system.getPhase(0).getType() == PhaseType.GAS) {
gasgib = system.getPhase(0).getGibbsEnergy();
system.setPhaseType(0, PhaseType.byValue(0));

if (gasgib * (1.0 - Math.signum(gasgib) * 1e-8) < liqgib) {
system.init(1, 0);
liqgib = system.getPhase(0).getGibbsEnergy();
} else {
liqgib = system.getPhase(0).getGibbsEnergy();
system.setPhaseType(0, PhaseType.byValue(1));
system.init(1, 0);
gasgib = system.getPhase(0).getGibbsEnergy();
}
if (gasgib * (1.0 - Math.signum(gasgib) * 1e-8) < liqgib) {
system.setPhaseType(0, PhaseType.byValue(1));
}
} catch (Exception e) {
system.setPhaseType(0, PhaseType.byValue(1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import neqsim.process.equipment.distillation.Condenser;
import neqsim.process.equipment.distillation.DistillationColumn;
import neqsim.process.equipment.stream.Stream;
import neqsim.process.equipment.stream.StreamInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import neqsim.process.equipment.pipeline.PipeBeggsAndBrills;
import neqsim.process.equipment.stream.Stream;
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermodynamicoperations.ThermodynamicOperations;
Expand Down Expand Up @@ -318,8 +317,7 @@ public void testPipeLineBeggsAndBrills4() {
ThermodynamicOperations testOps2 = new ThermodynamicOperations(testSystem3);
testOps2.TPflash();
testSystem3.initPhysicalProperties();

Assertions.assertEquals(testSystem3.hasPhaseType("oil"), true);
Assertions.assertEquals(testSystem3.hasPhaseType("gas"), true);

Stream stream_3 = new Stream("Stream1", testSystem3);
stream_3.setFlowRate(massFlowRate, "kg/hr");
Expand All @@ -343,7 +341,7 @@ public void testPipeLineBeggsAndBrills4() {

Assertions.assertEquals(testSystem3.hasPhaseType("gas"), true);

Assertions.assertEquals(temperatureOut3, -11.04463, 1);
Assertions.assertEquals(temperatureOut3, -8.81009355441591, 1);
Assertions.assertEquals(pressureOut3, 18.3429, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ public void testProcess() {
assertEquals(pressurespeedclac, seccondStageCompressor.getOutletStream().getPressure("bara"),
0.5);
assertEquals(speedcomp, seccondStageCompressor.getSpeed(), 0.5);
assertEquals(259.8380255, seccondStageCompressor.getInletStream().getFlowRate("m3/hr"), 0.2);
assertEquals(261.9994813, seccondStageCompressor.getInletStream().getFlowRate("m3/hr"), 0.2);

feedStream.setFlowRate(304094, "kg/hr");
operations.run();

assertEquals(pressurespeedclac, seccondStageCompressor.getOutletStream().getPressure("bara"),
0.5);
assertEquals(3526, seccondStageCompressor.getSpeed(), 10);
assertEquals(386.5, seccondStageCompressor.getInletStream().getFlowRate("m3/hr"), 0.2);
assertEquals(389.699822446, seccondStageCompressor.getInletStream().getFlowRate("m3/hr"), 0.2);
assertTrue(seccondStageCompressor.isSurge(seccondStageCompressor.getPolytropicFluidHead(),
seccondStageCompressor.getInletStream().getFlowRate("m3/hr")));

Expand All @@ -186,7 +186,7 @@ public void testProcess() {

assertEquals(pressurespeedclac, seccondStageCompressor.getOutletStream().getPressure("bara"),
0.5);
assertEquals(4177, seccondStageCompressor.getSpeed(), 10);
assertEquals(4191.3867368, seccondStageCompressor.getSpeed(), 10);
assertFalse(seccondStageCompressor.isSurge(seccondStageCompressor.getPolytropicFluidHead(),
seccondStageCompressor.getInletStream().getFlowRate("m3/hr")));
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/neqsim/process/processmodel/MLA_bug_test.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,15 @@ public void runProcessTEG() throws InterruptedException {

Thread runThr = p.runAsThread();
try {
runThr.join(100000);
runThr.join(300000);
} catch (Exception ex) {
logger.error("Something failed");
}
// System.out.println("water in gas " + dehydratedGas.getFluid().getComponent("water").getx());

assertEquals(-19.1886678,
p.getMeasurementDevice("water dew point analyser3").getMeasuredValue("C"), 1e-1);
assertEquals(203.024331,
assertEquals(852.343183810,
((Reboiler) ((DistillationColumn) p.getUnit("TEG regeneration column")).getReboiler())
.getDuty() / 1e3,
1e-2);
Expand Down
50 changes: 2 additions & 48 deletions src/test/java/neqsim/process/processmodel/ProcessSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public void runTEGProcessTest2() {
}


// @Test
@Test
public void testRun_step() {
neqsim.thermo.system.SystemInterface feedGas =
new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 42.0, 10.00);
Expand Down Expand Up @@ -888,52 +888,6 @@ public void testRun_step() {
operations.add(coolerhOTteg3);
operations.add(leanTEGtoabs);
operations.add(recycleLeanTEG);
operations.run();
dryFeedGasMidgard.setFlowRate(11.1, "MSm3/day");
operations.run_step();
dryFeedGasMidgard.setFlowRate(12.3, "MSm3/day");
operations.run_step();
dryFeedGasMidgard.setFlowRate(13.5, "MSm3/day");
ProcessSystem ops2 = operations.copy();
operations.setRunInSteps(true);
operations.run();
operations.run();
operations.run();
operations.run();
operations.run();
operations.run();
ProcessSystem ops3 = operations.copy();
operations.run();
operations.run();
dryFeedGasMidgard.setFlowRate(10.0, "MSm3/day");
operations.run();
operations.run();
operations.run();
operations.run();
operations.run();
operations.run();
operations.run();
operations.run();
assertEquals(1.7153448049613327E-5, dehydratedGas.getFluid().getComponent("water").getx(),
1e-6);

operations.run();
operations.run();
operations.run();
operations.run();
assertEquals(1.7153448049613327E-5, dehydratedGas.getFluid().getComponent("water").getx(),
1e-6);

// run as time step as thread
Thread thread = operations.runAsThread();
Thread thread2 = ops2.runAsThread();
Thread thread3 = ops3.runAsThread();
try {
thread.join();
thread2.join();
thread3.join();
} catch (Exception e) {
e.printStackTrace();
}
operations.run();
}
}

0 comments on commit b528b23

Please sign in to comment.