Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: replace use of phasetype as int with phasetype enum #928

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.logging.log4j.Logger;
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;
import neqsim.util.database.NeqSimDataBase;

/**
Expand Down Expand Up @@ -659,7 +660,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, 1, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.byValue(1), 1.0);
} catch (Exception ex) {
logger.error("error occured", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;

/**
* <p>
Expand Down Expand Up @@ -61,7 +62,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, 0, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.byValue(0), 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 @@ -3,6 +3,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;

/**
* <p>
Expand Down Expand Up @@ -94,7 +95,7 @@ public double fugcoef(PhaseInterface phase, int numberOfComps, double temp, doub

refPhase.setTemperature(temp);
refPhase.setPressure(pres);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, 0, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.byValue(0), 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 @@ -3,6 +3,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;
import neqsim.util.database.NeqSimDataBase;

/**
Expand Down Expand Up @@ -95,7 +96,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, 0, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.byValue(0), 1.0);

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

Expand Down Expand Up @@ -125,7 +126,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, 0, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 3, PhaseType.byValue(0), 1.0);

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

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/neqsim/thermo/component/ComponentSolid.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package neqsim.thermo.component;

import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;

/**
* <p>
Expand Down Expand Up @@ -108,7 +109,7 @@ public double fugcoef(double temp, double pres) {

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

// System.out.println("ref co2 fugcoef " +
Expand Down Expand Up @@ -138,7 +139,7 @@ public double fugcoef(double temp, double pres) {
public double fugcoef2(PhaseInterface phase1) {
refPhase.setTemperature(phase1.getTemperature());
refPhase.setPressure(phase1.getPressure());
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, 0, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.byValue(0), 1.0);
refPhase.getComponent(0).fugcoef(refPhase);

double liquidPhaseFugacity =
Expand Down Expand Up @@ -243,7 +244,7 @@ public void setSolidRefFluidPhase(PhaseInterface phase) {
}
refPhase.getComponent(componentName)
.setAttractiveTerm(phase.getComponent(componentName).getAttractiveTermNumber());
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, 1, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.byValue(1), 1.0);
}
} catch (Exception ex) {
logger.error("error occured", ex);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/neqsim/thermo/component/ComponentWax.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package neqsim.thermo.component;

import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;

/**
* <p>
Expand Down Expand Up @@ -54,7 +55,7 @@ public double fugcoef2(PhaseInterface phase1) {
logger.error(ex.getMessage(), ex);
}
refPhase.setPressure(phase1.getPressure());
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, 0, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.byValue(0), 1.0);
refPhase.getComponent(0).fugcoef(refPhase);

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

import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;

/**
* <p>
Expand Down Expand Up @@ -45,7 +46,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, 0, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.byValue(0), 1.0);
refPhase.getComponent(0).fugcoef(refPhase);

double liquidPhaseFugacity =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;

/**
* <p>
Expand Down Expand Up @@ -45,7 +46,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, 0, 1.0);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 1, PhaseType.byValue(0), 1.0);
refPhase.getComponent(0).fugcoef(refPhase);

double liquidPhaseFugacity =
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/neqsim/thermo/mixingRule/EosMixingRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import neqsim.thermo.phase.PhaseGEUnifacPSRK;
import neqsim.thermo.phase.PhaseGEUnifacUMRPRU;
import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;
import neqsim.util.database.NeqSimDataBase;

/**
Expand Down Expand Up @@ -1011,7 +1012,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(), 1);
phase.getPressure(), PhaseType.byValue(1));
gePhase.setProperties(phase);
}

Expand All @@ -1025,7 +1026,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(), 1);
phase.getPressure(), PhaseType.byValue(1));
gePhase.setProperties(phase);
}

Expand Down Expand Up @@ -1090,7 +1091,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(), 0)
phase.getTemperature(), phase.getPressure(), PhaseType.byValue(0))
/ gePhase.getNumberOfMolesInPhase() / hwfc);
Atot = A;
return A;
Expand Down Expand Up @@ -1308,8 +1309,7 @@ public void init(PhaseInterface phase, double temperature, double pressure, int
gePhase.setParams(phase, HValpha, HVDij, HVDijT, classicOrHV, intparam);

if (mixingRuleGEModel.equals("NRTL")) {
gePhase.getExcessGibbsEnergy(phase, numbcomp, temperature, pressure,
phase.getType().getValue());
gePhase.getExcessGibbsEnergy(phase, numbcomp, temperature, pressure, phase.getType());
} else {
gePhase.init((phase.getNumberOfMolesInPhase() / phase.getBeta()),
phase.getNumberOfComponents(), phase.getInitType(), phase.getType(), phase.getBeta());
Expand Down Expand Up @@ -1616,8 +1616,7 @@ public void init(PhaseInterface phase, double temperature, double pressure, int
gePhase.setProperties(phase);

if (mixingRuleGEModel.equals("NRTL")) {
gePhase.getExcessGibbsEnergy(phase, numbcomp, temperature, pressure,
phase.getType().getValue());
gePhase.getExcessGibbsEnergy(phase, numbcomp, temperature, pressure, phase.getType());
} else {
gePhase.init(phase.getNumberOfMolesInPhase(), phase.getNumberOfComponents(), 3,
phase.getType(), phase.getBeta());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/neqsim/thermo/phase/PhaseDesmukhMather.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ public double getExcessGibbsEnergy() {
/** {@inheritDoc} */
@Override
public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents,
double temperature, double pressure, int phasetype) {
double temperature, double pressure, PhaseType phasetype) {
GE = 0;
for (int i = 0; i < numberOfComponents; i++) {
GE += phase.getComponents()[i].getx() * Math.log(((ComponentDesmukhMather) componentArray[i])
.getGamma(phase, numberOfComponents, temperature, pressure, phasetype));
.getGamma(phase, numberOfComponents, temperature, pressure, phasetype.getValue()));
}
// System.out.println("ge " + GE);
return R * temperature * numberOfMolesInPhase * GE; // phase.getNumberOfMolesInPhase()*
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/neqsim/thermo/phase/PhaseDuanSun.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public double getExcessGibbsEnergy() {
/** {@inheritDoc} */
@Override
public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents,
double temperature, double pressure, int phasetype) {
double temperature, double pressure, PhaseType phasetype) {
GE = 0;
double salinity = 0.0;
// double k=0.0;
Expand Down Expand Up @@ -99,8 +99,9 @@ public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents,
// GE += phase.getComponents()[i].getx()*Math.log(((ComponentGeDuanSun)
// componentArray[i]).getGammaNRTL(phase, numberOfComponents, temperature, pressure,
// phasetype, alpha, Dij));
GE += phase.getComponents()[i].getx() * Math.log(((ComponentGeDuanSun) componentArray[i])
.getGammaPitzer(phase, numberOfComponents, temperature, pressure, phasetype, salinity));
GE += phase.getComponents()[i].getx()
* Math.log(((ComponentGeDuanSun) componentArray[i]).getGammaPitzer(phase,
numberOfComponents, temperature, pressure, phasetype.getValue(), salinity));
}

return R * temperature * numberOfMolesInPhase * GE; // phase.getNumberOfMolesInPhase()*
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/neqsim/thermo/phase/PhaseGE.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ public PhaseGE() {
* @param totalNumberOfMoles a double
* @param beta a double
* @param numberOfComponents a int
* @param type a int
* @param type a PhaseType enum
* @param phase a int
*/
public void init(double temperature, double pressure, double totalNumberOfMoles, double beta,
int numberOfComponents, int type, int phase) {
int numberOfComponents, PhaseType type, int phase) {
if (totalNumberOfMoles <= 0) {
new neqsim.util.exception.InvalidInputException(this, "init", "totalNumberOfMoles",
"must be larger than zero.");
}
for (int i = 0; i < numberOfComponents; i++) {
componentArray[i].init(temperature, pressure, totalNumberOfMoles, beta, type);
componentArray[i].init(temperature, pressure, totalNumberOfMoles, beta, type.getValue());
}
this.getExcessGibbsEnergy(this, numberOfComponents, temperature, pressure, type);

Expand All @@ -85,11 +85,11 @@ public void init(double temperature, double pressure, double totalNumberOfMoles,

/** {@inheritDoc} */
@Override
public void init(double totalNumberOfMoles, int numberOfComponents, int initType, PhaseType phase,
double beta) {
super.init(totalNumberOfMoles, numberOfComponents, initType, phase, beta);
public void init(double totalNumberOfMoles, int numberOfComponents, int initType,
PhaseType phaseType, double beta) {
super.init(totalNumberOfMoles, numberOfComponents, initType, phaseType, beta);
if (initType != 0) {
getExcessGibbsEnergy(this, numberOfComponents, temperature, pressure, phase.getValue());
getExcessGibbsEnergy(this, numberOfComponents, temperature, pressure, phaseType);
}

double sumHydrocarbons = 0.0;
Expand Down Expand Up @@ -190,7 +190,7 @@ public double getExcessGibbsEnergy() {
/** {@inheritDoc} */
@Override
public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents,
double temperature, double pressure, int phasetype) {
double temperature, double pressure, PhaseType phasetype) {
logger.error("this getExcessGibbsEnergy should never be used.......");
return 0;
}
Expand Down Expand Up @@ -239,7 +239,7 @@ public double getActivityCoefficientInfDilWater(int k, int p) {
refPhase[k].setPressure(pressure);
refPhase[k].init(refPhase[k].getNumberOfMolesInPhase(), 2, 1, this.getType(), 1.0);
((PhaseGEInterface) refPhase[k]).getExcessGibbsEnergy(refPhase[k], 2,
refPhase[k].getTemperature(), refPhase[k].getPressure(), refPhase[k].getType().getValue());
refPhase[k].getTemperature(), refPhase[k].getPressure(), refPhase[k].getType());
return ((ComponentGEInterface) refPhase[k].getComponent(0)).getGamma();
}

Expand All @@ -258,7 +258,7 @@ public double getActivityCoefficientInfDil(int k) {
dilphase.init(dilphase.getNumberOfMolesInPhase(), dilphase.getNumberOfComponents(), 1,
dilphase.getType(), 1.0);
((PhaseGEInterface) dilphase).getExcessGibbsEnergy(dilphase, 2, dilphase.getTemperature(),
dilphase.getPressure(), dilphase.getType().getValue());
dilphase.getPressure(), dilphase.getType());
return ((ComponentGEInterface) dilphase.getComponent(0)).getGamma();
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/neqsim/thermo/phase/PhaseGEInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public interface PhaseGEInterface {
* @param numberOfComponents a int
* @param temperature a double
* @param pressure a double
* @param phasetype a int
* @param phasetype a PhaseType enum object
* @return a double
*/
public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents,
double temperature, double pressure, int phasetype);
double temperature, double pressure, PhaseType phasetype);
}
4 changes: 2 additions & 2 deletions src/main/java/neqsim/thermo/phase/PhaseGENRTL.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ public double getExcessGibbsEnergy() {
/** {@inheritDoc} */
@Override
public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents,
double temperature, double pressure, int phasetype) {
double temperature, double pressure, PhaseType phasetype) {
GE = 0;
for (int i = 0; i < numberOfComponents; i++) {
GE += phase.getComponents()[i].getx()
* Math.log(((ComponentGEInterface) componentArray[i]).getGamma(phase, numberOfComponents,
temperature, pressure, phasetype, alpha, Dij, intparam, mixRule));
temperature, pressure, phasetype.getValue(), alpha, Dij, intparam, mixRule));
}

return R * temperature * numberOfMolesInPhase * GE; // phase.getNumberOfMolesInPhase()*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ public void setDijT(double[][] DijT) {
/** {@inheritDoc} */
@Override
public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents,
double temperature, double pressure, int phasetype) {
double temperature, double pressure, PhaseType phasetype) {
GE = 0.0;
for (int i = 0; i < numberOfComponents; i++) {
if (type == 0) {
GE += phase.getComponents()[i].getx() * Math
.log(((ComponentGEInterface) componentArray[i]).getGamma(phase, numberOfComponents,
temperature, pressure, phasetype, alpha, Dij, intparam, mixRule));
temperature, pressure, phasetype.getValue(), alpha, Dij, intparam, mixRule));
} else if (type == 1) {
GE += phase.getComponents()[i].getx() * Math
.log(((ComponentGENRTLmodifiedHV) componentArray[i]).getGamma(phase, numberOfComponents,
temperature, pressure, phasetype, alpha, Dij, DijT, intparam, mixRule));
temperature, pressure, phasetype.getValue(), alpha, Dij, DijT, intparam, mixRule));
}
}
return (R * phase.getTemperature() * GE) * phase.getNumberOfMolesInPhase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ public void addComponent(String name, double moles, double molesInPhase, int com
/** {@inheritDoc} */
@Override
public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents,
double temperature, double pressure, int phasetype) {
double temperature, double pressure, PhaseType phasetype) {
double GE = 0;
for (int i = 0; i < numberOfComponents; i++) {
if (type == 0) {
GE += phase.getComponents()[i].getx() * Math
.log(((ComponentGEInterface) componentArray[i]).getGamma(phase, numberOfComponents,
temperature, pressure, phasetype, alpha, Dij, intparam, mixRule));
temperature, pressure, phasetype.getValue(), alpha, Dij, intparam, mixRule));
}
if (type == 1) {
GE += phase.getComponents()[i].getx() * Math
.log(((ComponentGENRTLmodifiedWS) componentArray[i]).getGamma(phase, numberOfComponents,
temperature, pressure, phasetype, alpha, Dij, DijT, intparam, mixRule));
temperature, pressure, phasetype.getValue(), alpha, Dij, DijT, intparam, mixRule));
}
}
return R * temperature * GE * numberOfMolesInPhase;
Expand Down
Loading
Loading