Skip to content

Commit

Permalink
refact: rename MixingRule -> EosMixingRuleType
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil committed Jan 9, 2025
1 parent 1100bd6 commit 082a8b8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import neqsim.util.exception.InvalidInputException;

/**
* Types of MixingRule, relating to different kind of mixing rules. Available types are:
* 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>
Expand All @@ -19,7 +20,7 @@
*
* @author ASMF
*/
public enum MixingRule {
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. */
Expand All @@ -28,14 +29,14 @@ public enum MixingRule {

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

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

Expand All @@ -50,34 +51,34 @@ public int getValue() {
}

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

/**
* Get MixingRule by value.
* Get EosMixingRuleTypes by value.
*
* @param value Value to get MixingRule for.
* @return MixingRule object
* @param value Value to get EosMixingRuleTypes for.
* @return EosMixingRuleTypes object
*/
public static MixingRule byValue(int value) {
for (MixingRule mr : copyOfValues) {
public static EosMixingRuleType byValue(int value) {
for (EosMixingRuleType mr : copyOfValues) {
if (mr.getValue() == (value)) {
return mr;
}
}
throw new RuntimeException(
new InvalidInputException("MixingRule", "byValue", "value", "is not valid."));
new InvalidInputException("EosMixingRuleType", "byValue", "value", "is not valid."));
}
}
6 changes: 3 additions & 3 deletions src/main/java/neqsim/thermo/system/SystemInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.characterization.WaxModelInterface;
import neqsim.thermo.component.ComponentInterface;
import neqsim.thermo.mixingrule.MixingRule;
import neqsim.thermo.mixingrule.EosMixingRuleType;
import neqsim.thermo.phase.PhaseInterface;
import neqsim.thermo.phase.PhaseType;
import neqsim.util.ExcludeFromJacocoGeneratedReport;
Expand Down Expand Up @@ -2263,9 +2263,9 @@ public void setImplementedTemperatureDeriativesofFugacity(
/**
* method to set mixing rule used for the fluid.
*
* @param mr MixingRule enum
* @param mr EosMixingRuleTypes enum
*/
public default void setMixingRule(MixingRule mr) {
public default void setMixingRule(EosMixingRuleType mr) {
setMixingRule(mr.getValue());
}

Expand Down
13 changes: 6 additions & 7 deletions src/test/java/neqsim/thermo/system/SystemThermoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.mixingrule.MixingRule;
import neqsim.thermo.mixingrule.EosMixingRuleType;
import neqsim.thermo.phase.PhaseType;
import neqsim.thermodynamicoperations.ThermodynamicOperations;

Expand Down Expand Up @@ -37,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 @@ -148,18 +147,18 @@ void TESTsetForceSinglePhase() {

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

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

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

0 comments on commit 082a8b8

Please sign in to comment.