Skip to content

Commit

Permalink
feat: introduce StateOfMatter enum (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil authored and EvenSol committed May 22, 2023
1 parent d638646 commit fad41cf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/main/java/neqsim/thermo/phase/PhaseType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
63 changes: 63 additions & 0 deletions src/main/java/neqsim/thermo/phase/StateOfMatter.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
6 changes: 3 additions & 3 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fad41cf

Please sign in to comment.