Skip to content

Commit 796255e

Browse files
committed
feat: add EosMixingRuleType enum type and test
1 parent 9556c8b commit 796255e

File tree

4 files changed

+128
-12
lines changed

4 files changed

+128
-12
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package neqsim.thermo.mixingrule;
2+
3+
import neqsim.util.exception.InvalidInputException;
4+
5+
/**
6+
* Types of EosMixingRule, relating to different kind of mixing rules relevant for EOS type phases.
7+
* Available types are:
8+
* <ul>
9+
* <li>NO - 1 - classic mixing rule with all kij set to zero</li>
10+
* <li>CLASSIC - 2 - classic mixing rule with kij from NeqSim database</li>
11+
* <li>HV - 4 - Huron Vidal mixing rule with parameters from NeqSim database</li>
12+
* <li>WS - 5 -</li>
13+
* <li>CPA_MIX - 7 - classic mixing rule with kij of CPA from NeqSim Database</li>
14+
* <li>CLASSIC_T - 8 - classic mixing rule with temperature dependent kij</li>
15+
* <li>CLASSIC_T_CPA - 9 - classic mixing rule with temperature dependent kij of CPA from NeqSim
16+
* database</li>
17+
* <li>CLASSIC_TX_CPA - 10 - classic mixing rule with temperature and composition dependent kij of
18+
* CPA from NeqSim database</li>
19+
* </ul>
20+
*
21+
* @author ASMF
22+
*/
23+
public enum EosMixingRuleType {
24+
NO(1), CLASSIC(2), HV(4), WS(5), CPA_MIX(7), CLASSIC_T(8), CLASSIC_T_CPA(9), CLASSIC_TX_CPA(10);
25+
26+
/** Holder for old style integer pt. */
27+
private final int value;
28+
/** Holder for old style string physical property description. */
29+
30+
// We know we'll never mutate this, so we can keep
31+
// a local copy for fast lookup in forName
32+
private static final EosMixingRuleType[] copyOfValues = values();
33+
34+
/**
35+
* Constructor for EosMixingRuleType enum.
36+
*
37+
* @param value Numeric value index for mixing rule
38+
*/
39+
private EosMixingRuleType(int value) {
40+
this.value = value;
41+
}
42+
43+
/**
44+
* Getter for property value.
45+
*
46+
* @return Numeric index of phase type
47+
*/
48+
@Deprecated
49+
public int getValue() {
50+
return this.value;
51+
}
52+
53+
/**
54+
* Get EosMixingRuleType by name.
55+
*
56+
* @param name Name to get EosMixingRuleType for.
57+
* @return EosMixingRuleType object
58+
*/
59+
public static EosMixingRuleType byName(String name) {
60+
for (EosMixingRuleType mr : copyOfValues) {
61+
if (mr.name().equals(name.toUpperCase())) {
62+
return mr;
63+
}
64+
}
65+
throw new RuntimeException(
66+
new InvalidInputException("EosMixingRuleType", "byName", "name", "is not valid."));
67+
}
68+
69+
/**
70+
* Get EosMixingRuleTypes by value.
71+
*
72+
* @param value Value to get EosMixingRuleTypes for.
73+
* @return EosMixingRuleTypes object
74+
*/
75+
public static EosMixingRuleType byValue(int value) {
76+
for (EosMixingRuleType mr : copyOfValues) {
77+
if (mr.getValue() == (value)) {
78+
return mr;
79+
}
80+
}
81+
throw new RuntimeException(
82+
new InvalidInputException("EosMixingRuleType", "byValue", "value", "is not valid."));
83+
}
84+
}

src/main/java/neqsim/thermo/system/SystemInterface.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import neqsim.thermo.ThermodynamicConstantsInterface;
88
import neqsim.thermo.characterization.WaxModelInterface;
99
import neqsim.thermo.component.ComponentInterface;
10+
import neqsim.thermo.mixingrule.EosMixingRuleType;
1011
import neqsim.thermo.phase.PhaseInterface;
1112
import neqsim.thermo.phase.PhaseType;
1213
import neqsim.util.ExcludeFromJacocoGeneratedReport;
@@ -1596,7 +1597,7 @@ public default int getPhaseNumberOfPhase(String phaseTypeName) {
15961597
public double getZ();
15971598

15981599
/**
1599-
* method to return Z volume corrected gas compressibility
1600+
* method to return Z volume corrected gas compressibility.
16001601
*
16011602
* @return double Z volume corrected
16021603
*/
@@ -2258,6 +2259,16 @@ public void setImplementedTemperatureDeriativesofFugacity(
22582259
*/
22592260
public void setMaxNumberOfPhases(int maxNumberOfPhases);
22602261

2262+
2263+
/**
2264+
* method to set mixing rule used for the fluid.
2265+
*
2266+
* @param mr EosMixingRuleTypes enum
2267+
*/
2268+
public default void setMixingRule(EosMixingRuleType mr) {
2269+
setMixingRule(mr.getValue());
2270+
}
2271+
22612272
/**
22622273
* method to set mixing rule used for the fluid.
22632274
*
@@ -2616,7 +2627,7 @@ public default void setPhysicalPropertyModel(int type) {
26162627
/**
26172628
* <p>
26182629
* setForceSinglePhase - force the fluid to be single phase of type as spesified by phasetype
2619-
* input
2630+
* input.
26202631
* </p>
26212632
*
26222633
* @param phasetype a {@link neqsim.thermo.phase.PhaseType} object

src/main/java/neqsim/thermo/system/SystemThermo.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4434,21 +4434,23 @@ public final void setMixingRule(int type) {
44344434
@Override
44354435
public void setMixingRule(String typename) {
44364436
int var = 0;
4437-
if (typename.equals("no")) {
4437+
if (typename.equalsIgnoreCase("no")) {
44384438
var = 1;
4439-
} else if (typename.equals("classic")) {
4439+
} else if (typename.equalsIgnoreCase("classic")) {
44404440
var = 2;
4441-
} else if (typename.equals("HV")) {
4441+
} else if (typename.equalsIgnoreCase("HV")) {
44424442
var = 4;
4443-
} else if (typename.equals("WS")) {
4443+
} else if (typename.equalsIgnoreCase("WS")) {
44444444
var = 5;
4445-
} else if (typename.equals("CPA-Mix")) {
4445+
} else if (typename.equalsIgnoreCase("CPA-Mix") || typename.equalsIgnoreCase("CPA_Mix")) {
44464446
var = 7;
4447-
} else if (typename.equals("classic-T")) {
4447+
} else if (typename.equalsIgnoreCase("classic-T") || typename.equalsIgnoreCase("classic_T")) {
44484448
var = 8;
4449-
} else if (typename.equals("classic-T-cpa")) {
4449+
} else if (typename.equalsIgnoreCase("classic-T-cpa")
4450+
|| typename.equalsIgnoreCase("classic_t_cpa")) {
44504451
var = 9;
4451-
} else if (typename.equals("classic-Tx-cpa")) {
4452+
} else if (typename.equalsIgnoreCase("classic-Tx-cpa")
4453+
|| typename.equalsIgnoreCase("classic_tx_cpa")) {
44524454
var = 10;
44534455
} else {
44544456
var = 1;

src/test/java/neqsim/thermo/system/SystemThermoTest.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.jupiter.api.DisplayName;
77
import org.junit.jupiter.api.Test;
88
import neqsim.thermo.ThermodynamicConstantsInterface;
9+
import neqsim.thermo.mixingrule.EosMixingRuleType;
910
import neqsim.thermo.phase.PhaseType;
1011
import neqsim.thermodynamicoperations.ThermodynamicOperations;
1112

@@ -36,8 +37,7 @@ public static void setUp() {
3637
*/
3738
@Test
3839
public void testCp() {
39-
neqsim.thermo.system.SystemPrEos testSystem =
40-
new neqsim.thermo.system.SystemPrEos(273.15 + 40.0, 1.0);
40+
neqsim.thermo.system.SystemPrEos testSystem = new neqsim.thermo.system.SystemPrEos(273.15 + 40.0, 1.0);
4141
testSystem.addComponent("methane", 10.01);
4242
testSystem.addTBPfraction("C20", 10.68, 0.3, 0.85);
4343
testSystem.setMixingRule("classic");
@@ -144,4 +144,23 @@ void TESTsetForceSinglePhase() {
144144

145145
assertEquals(density, testSystem.getDensity("kg/m3"), 1e-4);
146146
}
147+
148+
@Test
149+
void TestMixingRuleTypes() {
150+
EosMixingRuleType[] mrNum = EosMixingRuleType.values();
151+
for (EosMixingRuleType mixingRule : mrNum) {
152+
testSystem.setMixingRule(mixingRule.getValue());
153+
assertEquals(mixingRule.getValue(), testSystem.getMixingRule());
154+
}
155+
156+
for (EosMixingRuleType mixingRule : mrNum) {
157+
testSystem.setMixingRule(mixingRule);
158+
assertEquals(mixingRule.getValue(), testSystem.getMixingRule());
159+
}
160+
161+
for (EosMixingRuleType mixingRule : mrNum) {
162+
testSystem.setMixingRule(mixingRule.name());
163+
assertEquals(mixingRule.getValue(), testSystem.getMixingRule());
164+
}
165+
}
147166
}

0 commit comments

Comments
 (0)