diff --git a/src/main/java/neqsim/thermo/phase/PhaseType.java b/src/main/java/neqsim/thermo/phase/PhaseType.java index 27991e0b56..95e69efe97 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseType.java +++ b/src/main/java/neqsim/thermo/phase/PhaseType.java @@ -6,7 +6,6 @@ * Types of phases. */ public enum PhaseType { - LIQUID("liquid", 0), GAS("gas", 1), OIL("oil", 2), AQUEOUS("aqueous", 3), HYDRATE("hydrate", 4), WAX("wax", 5), SOLID("solid", 6), SOLIDCOMPLEX("solidComplex", 7); diff --git a/src/main/java/neqsim/thermo/phase/StateOfMatter.java b/src/main/java/neqsim/thermo/phase/StateOfMatter.java new file mode 100644 index 0000000000..777f4db24f --- /dev/null +++ b/src/main/java/neqsim/thermo/phase/StateOfMatter.java @@ -0,0 +1,63 @@ +package neqsim.thermo.phase; + +/** + * States of matter, a way of relating the PhaseTypes to classical states of matter. + */ +public enum StateOfMatter { + GAS, LIQUID, SOLID; + + /** + * Get StateOfMatter value from Phasetype object. + * + * @param pt PhaseType object + * @return StateOfMatter object + */ + public static StateOfMatter fromPhaseType(PhaseType pt) { + switch (pt) { + case GAS: + return StateOfMatter.GAS; + case LIQUID: + case OIL: + case AQUEOUS: + return StateOfMatter.LIQUID; + case SOLID: + case SOLIDCOMPLEX: + case WAX: + return StateOfMatter.LIQUID; + default: + new RuntimeException(new neqsim.util.exception.InvalidInputException(StateOfMatter.class, + "fromPhaseType", "pt", "Conversion not configured for")); + } + return null; + } + + /** + * Check if PhaseType object is a gas state of matter. + * + * @param pt PhaseType object to check. + * @return True if pt converts to StateOfMatter.GAS + */ + public static boolean isGas(PhaseType pt) { + return StateOfMatter.fromPhaseType(pt) == StateOfMatter.GAS; + } + + /** + * Check if PhaseType object is a liquid state of matter. + * + * @param pt PhaseType object to check. + * @return True if pt converts to StateOfMatter.LIQUID + */ + public static boolean isLiquid(PhaseType pt) { + return StateOfMatter.fromPhaseType(pt) == StateOfMatter.LIQUID; + } + + /** + * Check if PhaseType object is a solid state of matter. + * + * @param pt PhaseType object to check. + * @return True if pt converts to StateOfMatter.SOLID + */ + public static boolean isSolid(PhaseType pt) { + return StateOfMatter.fromPhaseType(pt) == StateOfMatter.SOLID; + } +} diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index f82105f2b8..d8e2a63074 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -35,6 +35,7 @@ import neqsim.thermo.phase.PhaseSolidComplex; import neqsim.thermo.phase.PhaseType; import neqsim.thermo.phase.PhaseWax; +import neqsim.thermo.phase.StateOfMatter; import neqsim.util.database.NeqSimDataBase; /* @@ -2838,10 +2839,9 @@ public void setPhaseType(int phaseToChange, String phaseTypeName) { // System.out.println("new phase type: cha " + newPhaseType); int newPhaseType = 1; if (allowPhaseShift) { - if (phaseTypeName.equals("gas") || phaseTypeName.equals("vapour")) { + if (phaseTypeName.equals("gas")) { newPhaseType = 1; - } else if (phaseTypeName.equals("liquid") || phaseTypeName.equals("oil") - || phaseTypeName.equals("aqueous")) { + } else if (StateOfMatter.isLiquid(PhaseType.byDesc(phaseTypeName))) { newPhaseType = 0; } else { newPhaseType = 0;