Skip to content

Commit

Permalink
refact: replace PhaseType.byValue with PhaseType enum
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil committed Jan 11, 2025
1 parent b669d58 commit 2180e83
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ public void calcInc2(int np) {
PC2 = Math.exp(u.get(numberOfComponents + 1, 0));
system.setTC((TC1 + TC2) * 0.5);
system.setPC((PC1 + PC2) * 0.5);
system.setPhaseType(0, PhaseType.byValue(1));
system.setPhaseType(1, PhaseType.byValue(0));
system.setPhaseType(0, PhaseType.GAS);
system.setPhaseType(1, PhaseType.LIQUID);
return;
} else if ((xlnkmax < avscp && testcrit != 1) && (np != ic03p && !etterCP)) {
// System.out.println("hei fra her");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public void setSolidRefFluidPhase(PhaseInterface phase) {
refPhase.setTemperature(273.0);
refPhase.setPressure(1.0);
refPhase.addComponent("water", 10.0, 10.0, 0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.byValue(1), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.GAS, 1.0);
} catch (Exception ex) {
logger.error("error occured", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public double fugcoef(PhaseInterface phase, int numberOfComps, double temp, doub
if (componentName.equals("water")) {
refPhase.setTemperature(temp);
refPhase.setPressure(pres);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.byValue(0), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.LIQUID, 1.0);
double refWaterFugacity = refPhase.getComponent("water").fugcoef(refPhase) * pres;
double alphaWater = reffug[getComponentNumber()];
double wateralphaRef = Math.log(refWaterFugacity / alphaWater);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public double fugcoef(PhaseInterface phase, int numberOfComps, double temp, doub

refPhase.setTemperature(temp);
refPhase.setPressure(pres);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.byValue(0), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.LIQUID, 1.0);
double refWaterFugacityCoef = Math.log(refPhase.getComponent("water").fugcoef(refPhase));

double dhf = 6010.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public double fugcoef(PhaseInterface phase, int numberOfComps, double temp, doub
stableStructure = -1;
refPhase.setTemperature(temp);
refPhase.setPressure(pres);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.byValue(0), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.LIQUID, 1.0);

double refWaterFugacityCoef = Math.log(refPhase.getComponent("water").fugcoef(refPhase));

Expand Down Expand Up @@ -117,7 +117,7 @@ public double fugcoef(PhaseInterface phase, int numberOfComps, double temp, doub
if (componentName.equals("water")) {
refPhase.setTemperature(temp);
refPhase.setPressure(pres);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.byValue(0), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.LIQUID, 1.0);

double refWaterFugacity = refPhase.getComponent("water").fugcoef(refPhase) * pres;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/neqsim/thermo/component/ComponentSolid.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public double fugcoef(double temp, double pres) {

refPhase.setTemperature(temp);
refPhase.setPressure(PvapSolid);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.byValue(1), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.GAS, 1.0);
refPhase.getComponent(0).fugcoef(refPhase);

// System.out.println("ref co2 fugcoef " +
Expand Down Expand Up @@ -142,7 +142,7 @@ public double fugcoef2(PhaseInterface phase1) {
refPhase.setTemperature(phase1.getTemperature());
refPhase.setPressure(phase1.getPressure());
try {
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.byValue(0), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.LIQUID, 1.0);
} catch (Exception ex) {
logger.error(ex.getMessage());
}
Expand Down Expand Up @@ -256,7 +256,7 @@ public void setSolidRefFluidPhase(PhaseInterface phase) {
}
refPhase.getComponent(componentName)
.setAttractiveTerm(phase.getComponent(componentName).getAttractiveTermNumber());
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.byValue(1), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.GAS, 1.0);
// }
} catch (Exception ex) {
logger.error("error occured", ex);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/neqsim/thermo/component/ComponentWax.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public double fugcoef2(PhaseInterface phase1) {
logger.error(ex.getMessage(), ex);
}
refPhase.setPressure(phase1.getPressure());
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.byValue(0), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.LIQUID, 1.0);
refPhase.getComponent(0).fugcoef(refPhase);

double liquidPhaseFugacity =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public double fugcoef(PhaseInterface phase1) {
public double fugcoef2(PhaseInterface phase1) {
refPhase.setTemperature(phase1.getTemperature());
refPhase.setPressure(phase1.getPressure());
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.byValue(0), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.LIQUID, 1.0);
refPhase.getComponent(0).fugcoef(refPhase);

double liquidPhaseFugacity =
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/neqsim/thermo/component/ComponentWonWax.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public double fugcoef(PhaseInterface phase1) {
public double fugcoef2(PhaseInterface phase1) {
refPhase.setTemperature(phase1.getTemperature());
refPhase.setPressure(phase1.getPressure());
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.byValue(0), 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.LIQUID, 1.0);
refPhase.getComponent(0).fugcoef(refPhase);

double liquidPhaseFugacity =
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/neqsim/thermo/mixingrule/EosMixingRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ public SRKHuronVidal(PhaseInterface phase, double[][] HValpha, double[][] HVDij,
/ (1.0 + compArray[0].getDeltaEosParameters()[0]));
gePhase = new PhaseGENRTLmodifiedHV(orgPhase, HValpha, HVDij, mixRule, intparam);
gePhase.getExcessGibbsEnergy(phase, phase.getNumberOfComponents(), phase.getTemperature(),
phase.getPressure(), PhaseType.byValue(1));
phase.getPressure(), PhaseType.GAS);
gePhase.setProperties(phase);
}

Expand All @@ -1071,7 +1071,7 @@ public SRKHuronVidal(PhaseInterface phase, double[][] HValpha, double[][] HVDij,
/ (1.0 + compArray[0].getDeltaEosParameters()[0]));
gePhase = new PhaseGENRTLmodifiedHV(orgPhase, HValpha, HVDij, HVDijT, mixRule, intparam);
gePhase.getExcessGibbsEnergy(phase, phase.getNumberOfComponents(), phase.getTemperature(),
phase.getPressure(), PhaseType.byValue(1));
phase.getPressure(), PhaseType.GAS);
gePhase.setProperties(phase);
}

Expand Down Expand Up @@ -1145,7 +1145,7 @@ public double calcA(PhaseInterface phase, double temperature, double pressure, i
}
A = calcB(phase, temperature, pressure, numbcomp) * (A - phase.getNumberOfMolesInPhase()
* gePhase.getExcessGibbsEnergy(phase, phase.getNumberOfComponents(),
phase.getTemperature(), phase.getPressure(), PhaseType.byValue(0))
phase.getTemperature(), phase.getPressure(), PhaseType.LIQUID)
/ gePhase.getNumberOfMolesInPhase() / hwfc);
Atot = A;
return A;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/neqsim/thermo/system/SystemInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,11 @@ public default void initThermoProperties() {
public void normalizeBeta();

/**
* Order phases by density.
* Order phases 0-3, as many as there are, by density such that getPhase(0) is lightest.
*
* <p>
* Typically GAS, LIQUID for two-phase or GAS, OIL, AQUEOUS for multiphase .
* </p>
*/
public void orderByDensity();

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,8 @@ public void chemicalReactionInit() {
@Override
public void clearAll() {
setTotalNumberOfMoles(0);
phaseType[0] = PhaseType.byValue(1);
phaseType[1] = PhaseType.byValue(0);
phaseType[0] = PhaseType.GAS;
phaseType[1] = PhaseType.LIQUID;
numberOfComponents = 0;
setNumberOfPhases(2);
beta[0] = 1.0;
Expand Down Expand Up @@ -3903,10 +3903,10 @@ public void reInitPhaseInformation() {
/** {@inheritDoc} */
@Override
public void reInitPhaseType() {
phaseType[0] = PhaseType.byValue(1);
phaseType[1] = PhaseType.byValue(0);
phaseType[2] = PhaseType.byValue(0);
phaseType[3] = PhaseType.byValue(0);
phaseType[0] = PhaseType.GAS;
phaseType[1] = PhaseType.LIQUID;
phaseType[2] = PhaseType.LIQUID;
phaseType[3] = PhaseType.LIQUID;
// TODO: why stop at 3 and not iterate through MAX_PHASES elements?
}

Expand Down Expand Up @@ -4751,10 +4751,10 @@ public void invertPhaseTypes() {
*/

for (int i = 0; i < getMaxNumberOfPhases(); i++) {
if (phaseType[i] == PhaseType.byValue(0)) {
phaseType[i] = PhaseType.byValue(1);
if (phaseType[i] == PhaseType.LIQUID) {
phaseType[i] = PhaseType.GAS;
} else {
phaseType[i] = PhaseType.byValue(0);
phaseType[i] = PhaseType.LIQUID;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ public boolean stabilityCheck() {
system.setNumberOfPhases(1);

if (lowestGibbsEnergyPhase == 0) {
system.setPhaseType(0, PhaseType.byValue(1));
system.setPhaseType(0, PhaseType.GAS);
} else {
system.setPhaseType(0, PhaseType.byValue(0));
system.setPhaseType(0, PhaseType.LIQUID);
}
system.init(1);
if (solidCheck && !system.doMultiPhaseCheck()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,16 @@ public void checkGibbs() {
double gibbs1 = 0;
double gibbs2 = 0;
for (int i = 0; i < system.getNumberOfPhases() - 1; i++) {
system.setPhaseType(i, PhaseType.byValue(0));
system.setPhaseType(i, PhaseType.LIQUID);
system.init(1);
gibbs1 = system.getPhase(i).getGibbsEnergy();
system.setPhaseType(i, PhaseType.byValue(1));
system.setPhaseType(i, PhaseType.GAS);
system.init(1);
gibbs2 = system.getPhase(i).getGibbsEnergy();
if (gibbs1 < gibbs2) {
system.setPhaseType(i, PhaseType.byValue(0));
system.setPhaseType(i, PhaseType.LIQUID);
} else {
system.setPhaseType(i, PhaseType.byValue(1));
system.setPhaseType(i, PhaseType.GAS);
}
system.init(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,16 @@ public void checkGibbs() {
double gibbs1 = 0;
double gibbs2 = 0;
for (int i = 0; i < system.getNumberOfPhases() - 1; i++) {
system.setPhaseType(i, PhaseType.byValue(0));
system.setPhaseType(i, PhaseType.LIQUID);
system.init(1);
gibbs1 = system.getPhase(i).getGibbsEnergy();
system.setPhaseType(i, PhaseType.byValue(1));
system.setPhaseType(i, PhaseType.GAS);
system.init(1);
gibbs2 = system.getPhase(i).getGibbsEnergy();
if (gibbs1 < gibbs2) {
system.setPhaseType(i, PhaseType.byValue(0));
system.setPhaseType(i, PhaseType.LIQUID);
} else {
system.setPhaseType(i, PhaseType.byValue(1));
system.setPhaseType(i, PhaseType.GAS);
}
system.init(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,16 @@ public void checkGibbs() {
double gibbs1 = 0;
double gibbs2 = 0;
for (int i = 0; i < system.getNumberOfPhases() - 1; i++) {
system.setPhaseType(i, PhaseType.byValue(0));
system.setPhaseType(i, PhaseType.LIQUID);
system.init(1);
gibbs1 = system.getPhase(i).getGibbsEnergy();
system.setPhaseType(i, PhaseType.byValue(1));
system.setPhaseType(i, PhaseType.GAS);
system.init(1);
gibbs2 = system.getPhase(i).getGibbsEnergy();
if (gibbs1 < gibbs2) {
system.setPhaseType(i, PhaseType.byValue(0));
system.setPhaseType(i, PhaseType.LIQUID);
} else {
system.setPhaseType(i, PhaseType.byValue(1));
system.setPhaseType(i, PhaseType.GAS);
}
system.init(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,12 @@ public void run() {

// Checks if gas or oil is the most stable phase
double gasgib = system.getPhase(0).getGibbsEnergy();
system.setPhaseType(0, PhaseType.byValue(0));
system.setPhaseType(0, PhaseType.LIQUID);
system.init(1, 0);
double liqgib = system.getPhase(0).getGibbsEnergy();

if (gasgib * (1.0 - Math.signum(gasgib) * 1e-8) < liqgib) {
system.setPhaseType(0, PhaseType.byValue(1));
system.setPhaseType(0, PhaseType.GAS);
}
system.init(1);

Expand Down Expand Up @@ -472,25 +472,25 @@ public void run() {
TPmultiflash operation = new TPmultiflash(system, system.doSolidPhaseCheck());
operation.run();
} else {
// Checks if gas or oil is the most stable phase
try {
// 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.setPhaseType(0, PhaseType.LIQUID);

system.init(1, 0);
liqgib = system.getPhase(0).getGibbsEnergy();
} else {
liqgib = system.getPhase(0).getGibbsEnergy();
system.setPhaseType(0, PhaseType.byValue(1));
system.setPhaseType(0, PhaseType.GAS);
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));
system.setPhaseType(0, PhaseType.GAS);
}
} catch (Exception e) {
system.setPhaseType(0, PhaseType.byValue(1));
system.setPhaseType(0, PhaseType.GAS);
}

system.init(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void run() {
SystemInterface testSystem2 = new SystemSrkSchwartzentruberEos(216, 1);
ThermodynamicOperations testOps2 = new ThermodynamicOperations(testSystem2);
testSystem2.addComponent(testSystem.getPhase(0).getComponent(k).getComponentName(), 1);
testSystem2.setPhaseType(0, PhaseType.byValue(1));
testSystem2.setPhaseType(0, PhaseType.GAS);
noFreezeliq = true;
SolidFug = 0.0;
FluidFug = 0.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public FugTestConstP(SystemInterface system, double pres) {
public void initTestSystem2(int K) {
this.testSystem2 = new SystemSrkSchwartzentruberEos(temp, pres);
this.testSystem2.addComponent(compName, 1);
this.testSystem2.setPhaseType(0, PhaseType.byValue(1));
this.testSystem2.setPhaseType(0, PhaseType.GAS);
this.testOps2 = new ThermodynamicOperations(testSystem2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void run() {

if (!thermoSystem.hasPhaseType("gas")) {
thermoSystem.setPhaseType(thermoSystem.getPhaseNumberOfPhase(PhaseType.OIL),
PhaseType.byValue(1));
PhaseType.GAS);
thermoSystem.init(3);
thermoSystem.initPhysicalProperties();

Expand All @@ -176,7 +176,7 @@ public void run() {

if (!thermoSystem.hasPhaseType("oil")) {
thermoSystem.setPhaseType(thermoSystem.getPhaseNumberOfPhase(PhaseType.GAS),
PhaseType.byValue(1));
PhaseType.GAS);
thermoSystem.init(3);
thermoSystem.initPhysicalProperties();

Expand All @@ -185,7 +185,7 @@ public void run() {
}

if (!thermoSystem.hasPhaseType("aqueous")) {
thermoSystem.setPhaseType(1, PhaseType.byValue(1));
thermoSystem.setPhaseType(1, PhaseType.GAS);
thermoSystem.init(3);
thermoSystem.initPhysicalProperties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ public void run() {
} while (k < 17); // names[k] = "GAS DENSITY";
// units[k] = "KG/M3";
} else {
oilSystem.setPhaseType(0, PhaseType.byValue(0));
oilSystem.setPhaseType(0, PhaseType.LIQUID);
oilSystem.setTemperature(temperatures[j]);
oilSystem.setPressure(pressures[i]);
oilSystem.init(3);
Expand Down Expand Up @@ -715,7 +715,7 @@ public void run() {
} else {
waterSystem.setTemperature(temperatures[j]);
waterSystem.setPressure(pressures[i]);
waterSystem.setPhaseType(0, PhaseType.byValue(0));
waterSystem.setPhaseType(0, PhaseType.LIQUID);
waterSystem.init(3);
waterSystem.initPhysicalProperties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ public void run() {
} while (k < 17); // names[k] = "GAS DENSITY";
// units[k] = "KG/M3";
} else {
oilSystem.setPhaseType(0, PhaseType.byValue(0));
oilSystem.setPhaseType(0, PhaseType.LIQUID);
oilSystem.setTemperature(temperatures[j]);
oilSystem.setPressure(pressures[i]);
oilSystem.init(3);
Expand Down Expand Up @@ -935,7 +935,7 @@ public void run() {
} else {
waterSystem.setTemperature(temperatures[j]);
waterSystem.setPressure(pressures[i]);
waterSystem.setPhaseType(0, PhaseType.byValue(0));
waterSystem.setPhaseType(0, PhaseType.LIQUID);
waterSystem.init(3);
waterSystem.initPhysicalProperties();

Expand Down
Loading

0 comments on commit 2180e83

Please sign in to comment.