Skip to content

Commit

Permalink
feat: add EosMixingRuleType enum type and test
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil committed Jan 9, 2025
1 parent 9a34746 commit 05bc993
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 12 deletions.
84 changes: 84 additions & 0 deletions src/main/java/neqsim/thermo/mixingrule/EosMixingRuleType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package neqsim.thermo.mixingrule;

import neqsim.util.exception.InvalidInputException;

/**
* Types of EosMixingRule, relating to different kind of mixing rules relevant for EOS type phases.
* Available types are:
* <ul>
* <li>NO - 1 - classic mixing rule with all kij set to zero</li>
* <li>CLASSIC - 2 - classic mixing rule with kij from NeqSim database</li>
* <li>HV - 4 - Huron Vidal mixing rule with parameters from NeqSim database</li>
* <li>WS - 5 -</li>
* <li>CPA_MIX - 7 - classic mixing rule with kij of CPA from NeqSim Database</li>
* <li>CLASSIC_T - 8 - classic mixing rule with temperature dependent kij</li>
* <li>CLASSIC_T_CPA - 9 - classic mixing rule with temperature dependent kij of CPA from NeqSim
* database</li>
* <li>CLASSIC_TX_CPA - 10 - classic mixing rule with temperature and composition dependent kij of
* CPA from NeqSim database</li>
* </ul>
*
* @author ASMF
*/
public enum EosMixingRuleType {
NO(1), CLASSIC(2), HV(4), WS(5), CPA_MIX(7), CLASSIC_T(8), CLASSIC_T_CPA(9), CLASSIC_TX_CPA(10);

/** Holder for old style integer pt. */
private final int value;
/** Holder for old style string physical property description. */

// We know we'll never mutate this, so we can keep
// a local copy for fast lookup in forName
private static final EosMixingRuleType[] copyOfValues = values();

/**
* Constructor for EosMixingRuleType enum.
*
* @param value Numeric value index for mixing rule
*/
private EosMixingRuleType(int value) {
this.value = value;
}

/**
* Getter for property value.
*
* @return Numeric index of phase type
*/
@Deprecated
public int getValue() {
return this.value;
}

/**
* Get EosMixingRuleType by name.
*
* @param name Name to get EosMixingRuleType for.
* @return EosMixingRuleType object
*/
public static EosMixingRuleType byName(String name) {
for (EosMixingRuleType mr : copyOfValues) {
if (mr.name().equals(name.toUpperCase())) {
return mr;
}
}
throw new RuntimeException(
new InvalidInputException("EosMixingRuleType", "byName", "name", "is not valid."));
}

/**
* Get EosMixingRuleTypes by value.
*
* @param value Value to get EosMixingRuleTypes for.
* @return EosMixingRuleTypes object
*/
public static EosMixingRuleType byValue(int value) {
for (EosMixingRuleType mr : copyOfValues) {
if (mr.getValue() == (value)) {
return mr;
}
}
throw new RuntimeException(
new InvalidInputException("EosMixingRuleType", "byValue", "value", "is not valid."));
}
}
15 changes: 13 additions & 2 deletions src/main/java/neqsim/thermo/system/SystemInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.characterization.WaxModelInterface;
import neqsim.thermo.component.ComponentInterface;
import neqsim.thermo.mixingrule.EosMixingRuleType;
import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;
import neqsim.util.ExcludeFromJacocoGeneratedReport;
Expand Down Expand Up @@ -1596,7 +1597,7 @@ public default int getPhaseNumberOfPhase(String phaseTypeName) {
public double getZ();

/**
* method to return Z volume corrected gas compressibility
* method to return Z volume corrected gas compressibility.
*
* @return double Z volume corrected
*/
Expand Down Expand Up @@ -2258,6 +2259,16 @@ public void setImplementedTemperatureDeriativesofFugacity(
*/
public void setMaxNumberOfPhases(int maxNumberOfPhases);


/**
* method to set mixing rule used for the fluid.
*
* @param mr EosMixingRuleTypes enum
*/
public default void setMixingRule(EosMixingRuleType mr) {
setMixingRule(mr.getValue());
}

/**
* method to set mixing rule used for the fluid.
*
Expand Down Expand Up @@ -2616,7 +2627,7 @@ public default void setPhysicalPropertyModel(int type) {
/**
* <p>
* setForceSinglePhase - force the fluid to be single phase of type as spesified by phasetype
* input
* input.
* </p>
*
* @param phasetype a {@link neqsim.thermo.phase.PhaseType} object
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4434,21 +4434,23 @@ public final void setMixingRule(int type) {
@Override
public void setMixingRule(String typename) {
int var = 0;
if (typename.equals("no")) {
if (typename.equalsIgnoreCase("no")) {
var = 1;
} else if (typename.equals("classic")) {
} else if (typename.equalsIgnoreCase("classic")) {
var = 2;
} else if (typename.equals("HV")) {
} else if (typename.equalsIgnoreCase("HV")) {
var = 4;
} else if (typename.equals("WS")) {
} else if (typename.equalsIgnoreCase("WS")) {
var = 5;
} else if (typename.equals("CPA-Mix")) {
} else if (typename.equalsIgnoreCase("CPA-Mix") || typename.equalsIgnoreCase("CPA_Mix")) {
var = 7;
} else if (typename.equals("classic-T")) {
} else if (typename.equalsIgnoreCase("classic-T") || typename.equalsIgnoreCase("classic_T")) {
var = 8;
} else if (typename.equals("classic-T-cpa")) {
} else if (typename.equalsIgnoreCase("classic-T-cpa")
|| typename.equalsIgnoreCase("classic_t_cpa")) {
var = 9;
} else if (typename.equals("classic-Tx-cpa")) {
} else if (typename.equalsIgnoreCase("classic-Tx-cpa")
|| typename.equalsIgnoreCase("classic_tx_cpa")) {
var = 10;
} else {
var = 1;
Expand Down
23 changes: 21 additions & 2 deletions src/test/java/neqsim/thermo/system/SystemThermoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.mixingrule.EosMixingRuleType;
import neqsim.thermo.phase.PhaseType;
import neqsim.thermodynamicoperations.ThermodynamicOperations;

Expand Down Expand Up @@ -36,8 +37,7 @@ public static void setUp() {
*/
@Test
public void testCp() {
neqsim.thermo.system.SystemPrEos testSystem =
new neqsim.thermo.system.SystemPrEos(273.15 + 40.0, 1.0);
neqsim.thermo.system.SystemPrEos testSystem = new neqsim.thermo.system.SystemPrEos(273.15 + 40.0, 1.0);
testSystem.addComponent("methane", 10.01);
testSystem.addTBPfraction("C20", 10.68, 0.3, 0.85);
testSystem.setMixingRule("classic");
Expand Down Expand Up @@ -144,4 +144,23 @@ void TESTsetForceSinglePhase() {

assertEquals(density, testSystem.getDensity("kg/m3"), 1e-4);
}

@Test
void TestMixingRuleTypes() {
EosMixingRuleType[] mrNum = EosMixingRuleType.values();
for (EosMixingRuleType mixingRule : mrNum) {
testSystem.setMixingRule(mixingRule.getValue());
assertEquals(mixingRule.getValue(), testSystem.getMixingRule());
}

for (EosMixingRuleType mixingRule : mrNum) {
testSystem.setMixingRule(mixingRule);
assertEquals(mixingRule.getValue(), testSystem.getMixingRule());
}

for (EosMixingRuleType mixingRule : mrNum) {
testSystem.setMixingRule(mixingRule.name());
assertEquals(mixingRule.getValue(), testSystem.getMixingRule());
}
}
}

0 comments on commit 05bc993

Please sign in to comment.