diff --git a/src/main/java/neqsim/thermo/mixingrule/EosMixingRuleType.java b/src/main/java/neqsim/thermo/mixingrule/EosMixingRuleType.java new file mode 100644 index 000000000..2dca6514e --- /dev/null +++ b/src/main/java/neqsim/thermo/mixingrule/EosMixingRuleType.java @@ -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: + * + * + * @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.")); + } +} diff --git a/src/main/java/neqsim/thermo/system/SystemInterface.java b/src/main/java/neqsim/thermo/system/SystemInterface.java index 68e73e8c0..a5a728e08 100644 --- a/src/main/java/neqsim/thermo/system/SystemInterface.java +++ b/src/main/java/neqsim/thermo/system/SystemInterface.java @@ -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; @@ -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 */ @@ -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. * @@ -2616,7 +2627,7 @@ public default void setPhysicalPropertyModel(int type) { /** *

* setForceSinglePhase - force the fluid to be single phase of type as spesified by phasetype - * input + * input. *

* * @param phasetype a {@link neqsim.thermo.phase.PhaseType} object diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index a4384c7e8..44b49dde6 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -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; diff --git a/src/test/java/neqsim/thermo/system/SystemThermoTest.java b/src/test/java/neqsim/thermo/system/SystemThermoTest.java index 905fdd96e..bdc06ab4d 100644 --- a/src/test/java/neqsim/thermo/system/SystemThermoTest.java +++ b/src/test/java/neqsim/thermo/system/SystemThermoTest.java @@ -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; @@ -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"); @@ -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()); + } + } }