Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed Nov 19, 2024
1 parent 63b4e83 commit c5c5e1c
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 59 deletions.
120 changes: 61 additions & 59 deletions src/main/java/neqsim/thermo/mixingrule/EosMixingRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public class EosMixingRules implements Cloneable, ThermodynamicConstantsInterfac
* Constructor for EosMixingRules.
* </p>
*/
public EosMixingRules() {
}
public EosMixingRules() {}

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -139,8 +138,7 @@ public double[][] getBinaryInteractionParameters() {
return intparam;
}

public void prettyPrintKij() {
}
public void prettyPrintKij() {}

@Override
public double getBinaryInteractionParameterT1(int i, int j) {
Expand Down Expand Up @@ -216,8 +214,7 @@ public void setBinaryInteractionParameterT1(int i, int j, double value) {
/**
* Setter for property CalcEOSInteractionParameters.
*
* @param CalcEOSInteractionParameters2 New value of property
* CalcEOSInteractionParameters.
* @param CalcEOSInteractionParameters2 New value of property CalcEOSInteractionParameters.
*/
@Override
public void setCalcEOSInteractionParameters(boolean CalcEOSInteractionParameters2) {
Expand Down Expand Up @@ -876,7 +873,8 @@ public double calcAij(int compNumb, int compNumbj, PhaseInterface phase, double
for (int j = 0; j < numbcomp; j++) {
aij = -Math.sqrt(compArray[i].getaT() * compArray[j].getaT())
* getkijdndn(compNumb, compNumbj, phase, temperature, i, j);
A2 += compArray[i].getNumberOfMolesInPhase() * compArray[j].getNumberOfMolesInPhase() * aij;
A2 +=
compArray[i].getNumberOfMolesInPhase() * compArray[j].getNumberOfMolesInPhase() * aij;
}
}

Expand Down Expand Up @@ -1008,9 +1006,10 @@ public SRKHuronVidal(PhaseInterface phase, double[][] HValpha, double[][] HVDij,
String[][] mixRule) {
ComponentEosInterface[] compArray = (ComponentEosInterface[]) phase.getcomponentArray();
this.orgPhase = phase;
hwfc = 1.0 / (compArray[0].getDeltaEosParameters()[1] - compArray[0].getDeltaEosParameters()[0])
* Math.log((1.0 + compArray[0].getDeltaEosParameters()[1])
/ (1.0 + compArray[0].getDeltaEosParameters()[0]));
hwfc =
1.0 / (compArray[0].getDeltaEosParameters()[1] - compArray[0].getDeltaEosParameters()[0])
* Math.log((1.0 + compArray[0].getDeltaEosParameters()[1])
/ (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));
Expand All @@ -1021,9 +1020,10 @@ public SRKHuronVidal(PhaseInterface phase, double[][] HValpha, double[][] HVDij,
double[][] HVDijT, String[][] mixRule) {
ComponentEosInterface[] compArray = (ComponentEosInterface[]) phase.getcomponentArray();
this.orgPhase = phase;
hwfc = 1.0 / (compArray[0].getDeltaEosParameters()[1] - compArray[0].getDeltaEosParameters()[0])
* Math.log((1.0 + compArray[0].getDeltaEosParameters()[1])
/ (1.0 + compArray[0].getDeltaEosParameters()[0]));
hwfc =
1.0 / (compArray[0].getDeltaEosParameters()[1] - compArray[0].getDeltaEosParameters()[0])
* Math.log((1.0 + compArray[0].getDeltaEosParameters()[1])
/ (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));
Expand Down Expand Up @@ -1295,10 +1295,10 @@ public SRKHuronVidal2(PhaseInterface phase, double[][] HValpha, double[][] HVDij
/**
* init.
*
* @param phase Phase to initialize for.
* @param phase Phase to initialize for.
* @param temperature Temperature to initialize at.
* @param pressure Pressure to initialize at.
* @param numbcomp Number of components.
* @param pressure Pressure to initialize at.
* @param numbcomp Number of components.
*/
public void init(PhaseInterface phase, double temperature, double pressure, int numbcomp) {
ComponentEosInterface[] compArray = (ComponentEosInterface[]) phase.getcomponentArray();
Expand Down Expand Up @@ -1348,11 +1348,12 @@ public void init(PhaseInterface phase, double temperature, double pressure, int
if (phase.getInitType() > 1) {
qPuredT[i] = -compArray[i].getaT() / (compArray[i].getb() * R * temperature * temperature)
+ compArray[i].diffaT(temperature) / (compArray[i].getb() * R * temperature);
qPuredTdT[i] = 2.0 * compArray[i].getaT() / (compArray[i].getb() * R * Math.pow(temperature, 3.0))
- compArray[i].getaDiffT() / (compArray[i].getb() * R * temperature * temperature)
+ compArray[i].getaDiffDiffT() / (compArray[i].getb() * R * temperature)
- compArray[i].getaDiffT()
/ (compArray[i].getb() * R * temperature * temperature);
qPuredTdT[i] =
2.0 * compArray[i].getaT() / (compArray[i].getb() * R * Math.pow(temperature, 3.0))
- compArray[i].getaDiffT() / (compArray[i].getb() * R * temperature * temperature)
+ compArray[i].getaDiffDiffT() / (compArray[i].getb() * R * temperature)
- compArray[i].getaDiffT()
/ (compArray[i].getb() * R * temperature * temperature);
}
}

Expand Down Expand Up @@ -1652,10 +1653,11 @@ public void init(PhaseInterface phase, double temperature, double pressure, int
qPure[i] = compArray[i].getaT() / (compArray[i].getb() * R * temperature);
qPuredT[i] = -compArray[i].getaT() / (compArray[i].getb() * R * temperature * temperature)
+ compArray[i].diffaT(temperature) / (compArray[i].getb() * R * temperature);
qPuredTdT[i] = 2.0 * compArray[i].getaT() / (compArray[i].getb() * R * Math.pow(temperature, 3.0))
- compArray[i].getaDiffT() / (compArray[i].getb() * R * Math.pow(temperature, 2.0))
+ compArray[i].getaDiffDiffT() / (compArray[i].getb() * R * temperature)
- compArray[i].getaDiffT() / (compArray[i].getb() * R * Math.pow(temperature, 2.0));
qPuredTdT[i] =
2.0 * compArray[i].getaT() / (compArray[i].getb() * R * Math.pow(temperature, 3.0))
- compArray[i].getaDiffT() / (compArray[i].getb() * R * Math.pow(temperature, 2.0))
+ compArray[i].getaDiffDiffT() / (compArray[i].getb() * R * temperature)
- compArray[i].getaDiffT() / (compArray[i].getb() * R * Math.pow(temperature, 2.0));
}

double sd2 = (2 * hex - cpex * temperature) / Math.pow(temperature, 3.0);
Expand All @@ -1675,7 +1677,8 @@ public void init(PhaseInterface phase, double temperature, double pressure, int
ader[i] = term;
compArray[i].setAder(ader[i]);

term = qPuredT[i] + hwfc * ((ComponentGEInterface) gePhase.getComponents()[i]).getlnGammadt();
term =
qPuredT[i] + hwfc * ((ComponentGEInterface) gePhase.getComponents()[i]).getlnGammadt();
dadt += term * phase.getComponents()[i].getNumberOfMolesInPhase()
/ phase.getNumberOfMolesInPhase();
adert[i] = term;
Expand Down Expand Up @@ -1763,7 +1766,8 @@ public void init(PhaseInterface phase, double temperature, double pressure, int

for (int i = 0; i < numbcomp; i++) {
for (int j = 0; j < numbcomp; j++) {
bd2[i][j] = (qf2[i][j] + b_mix * ad2[i][j] + BDER[j] * ader[i] + BDER[i] * ader[j]) * enumr;
bd2[i][j] =
(qf2[i][j] + b_mix * ad2[i][j] + BDER[j] * ader[i] + BDER[i] * ader[j]) * enumr;
compArray[i].setdBdndn(j, ad2[i][j]);
}
}
Expand Down Expand Up @@ -1924,9 +1928,10 @@ public void calcWij(PhaseInterface phase) {
if (compArray[j].getComponentName().equals("water")
|| compArray[j].getComponentName().equals("MDEA")
|| compArray[j].getComponentName().equals("Piperazine")) { // compArray[j].getIonicCharge()==0){
wij[0][i][j] = neqsim.thermo.util.constants.FurstElectrolyteConstants.getFurstParam(2)
* compArray[i].getStokesCationicDiameter()
+ neqsim.thermo.util.constants.FurstElectrolyteConstants.getFurstParam(3);
wij[0][i][j] =
neqsim.thermo.util.constants.FurstElectrolyteConstants.getFurstParam(2)
* compArray[i].getStokesCationicDiameter()
+ neqsim.thermo.util.constants.FurstElectrolyteConstants.getFurstParam(3);
}
// if(compArray[j].getComponentName().equals("MDEA")){
// wij[0][i][j] =
Expand All @@ -1936,10 +1941,11 @@ public void calcWij(PhaseInterface phase) {
// thermo.util.constants.FurstElectrolyteConstants.getFurstParamMDEA(3));
// }
if (compArray[j].getIonicCharge() < -0.01) {
wij[0][i][j] = neqsim.thermo.util.constants.FurstElectrolyteConstants.getFurstParam(4)
* Math.pow(compArray[i].getStokesCationicDiameter()
+ compArray[j].getPaulingAnionicDiameter(), 4.0)
+ neqsim.thermo.util.constants.FurstElectrolyteConstants.getFurstParam(5);
wij[0][i][j] =
neqsim.thermo.util.constants.FurstElectrolyteConstants.getFurstParam(4)
* Math.pow(compArray[i].getStokesCationicDiameter()
+ compArray[j].getPaulingAnionicDiameter(), 4.0)
+ neqsim.thermo.util.constants.FurstElectrolyteConstants.getFurstParam(5);
}
wij[0][j][i] = wij[0][i][j];
}
Expand Down Expand Up @@ -2097,7 +2103,7 @@ public EosMixingRulesInterface getMixingRule(int i) {
* getMixingRule.
* </p>
*
* @param i a int
* @param i a int
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @return a {@link neqsim.thermo.mixingrule.EosMixingRulesInterface} object
*/
Expand Down Expand Up @@ -2150,23 +2156,20 @@ public EosMixingRulesInterface getMixingRule(int i, PhaseInterface phase) {
}
int underscoreIndex2 = component_name2.indexOf("__");
if (underscoreIndex2 != -1) {
component_name2 = component_name2.substring(0, underscoreIndex);
component_name2 = component_name2.substring(0, underscoreIndex2);
}

if (NeqSimDataBase.createTemporaryTables()) {
dataSet = database.getResultSet("SELECT * FROM intertemp WHERE (comp1='"
+ component_name + "' AND comp2='" + component_name2
+ "') OR (comp1='" + component_name2
+ "' AND comp2='" + component_name + "')");
+ component_name + "' AND comp2='" + component_name2 + "') OR (comp1='"
+ component_name2 + "' AND comp2='" + component_name + "')");
} else {
dataSet = database.getResultSet("SELECT * FROM inter WHERE (comp1='"
+ component_name + "' AND comp2='" + component_name2
+ "') OR (comp1='" + component_name2
+ "' AND comp2='" + component_name + "')");
+ component_name + "' AND comp2='" + component_name2 + "') OR (comp1='"
+ component_name2 + "' AND comp2='" + component_name + "')");
}
dataSet.next();
if (dataSet.getString("comp1").trim()
.equals(component_name2)) {
if (dataSet.getString("comp1").trim().equals(component_name2)) {
templ = k;
tempk = l;
}
Expand All @@ -2175,12 +2178,13 @@ public EosMixingRulesInterface getMixingRule(int i, PhaseInterface phase) {
classicOrHV[l][k] = classicOrHV[k][l];

if (isCalcEOSInteractionParameters()) {
intparam[k][l] = 1.0 - Math.pow(
(2.0 * Math.sqrt(Math.pow(phase.getComponent(l).getCriticalVolume(), 1 / 3)
* Math.pow(phase.getComponent(k).getCriticalVolume(), 1 / 3))
/ (Math.pow(phase.getComponent(l).getCriticalVolume(), 1 / 3)
+ Math.pow(phase.getComponent(k).getCriticalVolume(), 1 / 3))),
nEOSkij);
intparam[k][l] =
1.0 - Math.pow(
(2.0 * Math.sqrt(Math.pow(phase.getComponent(l).getCriticalVolume(), 1 / 3)
* Math.pow(phase.getComponent(k).getCriticalVolume(), 1 / 3))
/ (Math.pow(phase.getComponent(l).getCriticalVolume(), 1 / 3)
+ Math.pow(phase.getComponent(k).getCriticalVolume(), 1 / 3))),
nEOSkij);
intparamT[k][l] = 0.0;
// System.out.println("kij " + intparam[k][l]);
} else {
Expand Down Expand Up @@ -2380,10 +2384,8 @@ public EosMixingRulesInterface getMixingRule(int i, PhaseInterface phase) {
intparam[k][l] = 0.12;
intparamT[k][l] = 0.0;
}
} else if ((component_name.equals("S8")
&& phase.getComponents()[l].isIsTBPfraction())
|| (component_name2.equals("S8")
&& phase.getComponents()[k].isIsTBPfraction())) {
} else if ((component_name.equals("S8") && phase.getComponents()[l].isIsTBPfraction())
|| (component_name2.equals("S8") && phase.getComponents()[k].isIsTBPfraction())) {
intparam[k][l] = 0.05;
} else {
// if((component_name2.equals("CO2") ||
Expand Down Expand Up @@ -2489,7 +2491,7 @@ public EosMixingRulesInterface getMixingRule(int i, PhaseInterface phase) {
* resetMixingRule.
* </p>
*
* @param i a int
* @param i a int
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @return a {@link neqsim.thermo.mixingrule.EosMixingRulesInterface} object
*/
Expand Down Expand Up @@ -2550,8 +2552,7 @@ public EosMixingRulesInterface resetMixingRule(int i, PhaseInterface phase) {
* </p>
*
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @return a {@link neqsim.thermo.mixingrule.ElectrolyteMixingRulesInterface}
* object
* @return a {@link neqsim.thermo.mixingrule.ElectrolyteMixingRulesInterface} object
*/
public ElectrolyteMixingRulesInterface getElectrolyteMixingRule(PhaseInterface phase) {
return new ElectrolyteMixRule(phase);
Expand Down Expand Up @@ -2704,10 +2705,11 @@ public java.lang.String[][] getClassicOrWS() {
* </p>
*
* @param intType a {@link java.lang.String} object
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
*/
public void displayInteractionCoefficients(String intType, PhaseInterface phase) {
String[][] interactTable = new String[phase.getNumberOfComponents() + 1][phase.getNumberOfComponents() + 1];
String[][] interactTable =
new String[phase.getNumberOfComponents() + 1][phase.getNumberOfComponents() + 1];

java.text.DecimalFormat nf = new java.text.DecimalFormat();

Expand Down
62 changes: 62 additions & 0 deletions src/test/java/neqsim/thermo/mixingrule/EosMixingRulesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package neqsim.thermo.mixingrule;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import neqsim.thermo.phase.PhaseEos;

public class EosMixingRulesTest {
@Test
void testSetMixingRuleName() {

neqsim.thermo.system.SystemPrEos testSystem = new neqsim.thermo.system.SystemPrEos(298.0, 10.0);
testSystem.addComponent("nitrogen", 0.01);
testSystem.addComponent("CO2", 0.01);
testSystem.addComponent("nitrogen", 0.01);
testSystem.addComponent("CO2", 0.01);
testSystem.changeComponentName(testSystem.getComponent(0).getName(),
(testSystem.getComponent(0).getName() + "__well1"));
testSystem.changeComponentName(testSystem.getComponent(1).getName(),
(testSystem.getComponent(1).getName() + "__well1"));



testSystem.addComponent("nitrogen", 0.01);
testSystem.addComponent("CO2", 0.01);
testSystem.changeComponentName(testSystem.getComponent(2).getName(),
(testSystem.getComponent(2).getName() + "__well2"));
testSystem.changeComponentName(testSystem.getComponent(3).getName(),
(testSystem.getComponent(3).getName() + "__well2"));


testSystem.setMixingRule("classic");

double kij =
((PhaseEos) testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameter(0, 1);
double kij2 =
((PhaseEos) testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameter(3, 0);

// Print kij
assertEquals(-0.019997, kij, 1e-5);
assertTrue(kij == kij2);

}

@Test
void testMEGOil() {

neqsim.thermo.system.SystemSrkCPAstatoil testSystem =
new neqsim.thermo.system.SystemSrkCPAstatoil(298.0, 10.0);
testSystem.addTBPfraction("C8", 0.01, 90.9 / 1000.0, 0.9);
testSystem.addComponent("ethanol", 0.01);

testSystem.setMixingRule("classic");

double kij =
((PhaseEos) testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameter(0, 1);

// Print kij
assertEquals(-0.05, kij, 1e-5);

}
}

0 comments on commit c5c5e1c

Please sign in to comment.