Skip to content

Commit

Permalink
feat: Created physical property enum type to replace string (#1149)
Browse files Browse the repository at this point in the history
* feat: Created physical property enum type to replace string
* test: add test
* feat: support the old names
* doc
  • Loading branch information
asmfstatoil authored Oct 27, 2024
1 parent e8e19d8 commit 793eea2
Show file tree
Hide file tree
Showing 20 changed files with 276 additions and 117 deletions.
46 changes: 46 additions & 0 deletions src/main/java/neqsim/physicalproperties/PhysicalPropertyType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package neqsim.physicalproperties;

import neqsim.util.exception.InvalidInputException;

/**
* Types of PhysicalProperties, e.g. mass density, dynamic viscosity, thermal conductivity.
*
* @author ASMF
*/

public enum PhysicalPropertyType {
MASS_DENSITY, DYNAMIC_VISCOSITY, THERMAL_CONDUCTIVITY;

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

/**
* Get PhysicalPropertyType by name.
*
* @param name Name to get PhysicalPropertyType for.
* @return PhysicalPropertyType object
*/
public static PhysicalPropertyType byName(String name) {
// suport old names
name = name.toUpperCase();
if (name.equals("DENSITY")) {
name = "MASS_DENSITY";
}
if (name.equals("VISCOSITY")) {
name = "DYNAMIC_VISCOSITY";
}
if (name.equals("CONDUCTIVITY")) {
name = "THERMAL_CONDUCTIVITY";
}

// todo: consider replacing this function with built-in valueOf
for (PhysicalPropertyType pt : copyOfValues) {
if (pt.name().equals(name)) {
return pt;
}
}
throw new RuntimeException(
new InvalidInputException("PhysicalPropertyType", "byName", "name", "is not valid."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

/**
* <p>
* PhysicalPropertyMethod class.
* Abstract PhysicalPropertyMethod class.
* </p>
*
* @author esol
* @version $Id: $Id
*/
public class PhysicalPropertyMethod implements PhysicalPropertyMethodInterface {
public abstract class PhysicalPropertyMethod implements PhysicalPropertyMethodInterface {
private static final long serialVersionUID = 1000;
static Logger logger = LogManager.getLogger(PhysicalPropertyMethod.class);

Expand All @@ -42,15 +42,9 @@ public PhysicalPropertyMethod clone() {
return properties;
}

/** {@inheritDoc} */
@Override
public void setPhase(
neqsim.physicalproperties.physicalpropertysystem.PhysicalPropertiesInterface phase) {}

/** {@inheritDoc} */
@Override
public void tuneModel(double val, double temperature, double pressure) {
throw new UnsupportedOperationException("Unimplemented method 'tuneModel'");
}
// should contain phase objects ++ get diffusivity methods .. more ?
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.physicalproperties.PhysicalPropertyType;
import neqsim.physicalproperties.physicalpropertymethods.commonphasephysicalproperties.conductivity.PFCTConductivityMethodMod86;
import neqsim.physicalproperties.physicalpropertymethods.commonphasephysicalproperties.diffusivity.CorrespondingStatesDiffusivity;
import neqsim.physicalproperties.physicalpropertymethods.commonphasephysicalproperties.viscosity.FrictionTheoryViscosityMethod;
Expand Down Expand Up @@ -35,7 +36,7 @@ public abstract class PhysicalProperties
private static final long serialVersionUID = 1000;
static Logger logger = LogManager.getLogger(PhysicalProperties.class);

public PhaseInterface phase;
protected PhaseInterface phase;
protected int binaryDiffusionCoefficientMethod;
protected int multicomponentDiffusionMethod;
private neqsim.physicalproperties.mixingrule.PhysicalPropertyMixingRuleInterface mixingRule =
Expand All @@ -58,7 +59,7 @@ public abstract class PhysicalProperties
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
*/
public PhysicalProperties(PhaseInterface phase) {
this.phase = phase;
setPhase(phase);
}

/**
Expand All @@ -72,7 +73,7 @@ public PhysicalProperties(PhaseInterface phase) {
*/
public PhysicalProperties(PhaseInterface phase, int binaryDiffusionCoefficientMethod,
int multicomponentDiffusionMethod) {
this.phase = phase;
this(phase);
this.binaryDiffusionCoefficientMethod = binaryDiffusionCoefficientMethod;
this.multicomponentDiffusionMethod = multicomponentDiffusionMethod;
}
Expand Down Expand Up @@ -227,14 +228,25 @@ public double calcKinematicViscosity() {

/**
* <p>
* setPhases.
* Set phase information for all physical property calc methods, i.e., subclasses of
* physicalpropertymethods using setPhase(this). NB! Safe even if calc methods are null, e.g.,
* from constructors.
* </p>
*/
public void setPhases() {
conductivityCalc.setPhase(this);
densityCalc.setPhase(this);
viscosityCalc.setPhase(this);
diffusivityCalc.setPhase(this);
// Check for null to make it safe to call this function from subclass constructors.
if (conductivityCalc != null) {
conductivityCalc.setPhase(this);
}
if (densityCalc != null) {
densityCalc.setPhase(this);
}
if (viscosityCalc != null) {
viscosityCalc.setPhase(this);
}
if (diffusivityCalc != null) {
diffusivityCalc.setPhase(this);
}
}

/** {@inheritDoc} */
Expand All @@ -247,8 +259,7 @@ public void setPhase(PhaseInterface phase) {
/** {@inheritDoc} */
@Override
public void init(PhaseInterface phase) {
this.phase = phase;
this.setPhases();
this.setPhase(phase);
try {
density = densityCalc.calcDensity();
viscosity = viscosityCalc.calcViscosity();
Expand All @@ -266,15 +277,26 @@ public void init(PhaseInterface phase) {

/** {@inheritDoc} */
@Override
public void init(PhaseInterface phase, String type) {
if (type.equalsIgnoreCase("density")) {
density = densityCalc.calcDensity();
} else if (type.equalsIgnoreCase("viscosity")) {
viscosity = viscosityCalc.calcViscosity();
} else if (type.equalsIgnoreCase("conductivity")) {
conductivity = conductivityCalc.calcConductivity();
} else {
init(phase);
public void init(PhaseInterface phase, PhysicalPropertyType ppt) {
switch (ppt) {
case MASS_DENSITY:
densityCalc.setPhase(this);
density = densityCalc.calcDensity();
break;
case DYNAMIC_VISCOSITY:
viscosityCalc.setPhase(this);
viscosity = viscosityCalc.calcViscosity();
break;
case THERMAL_CONDUCTIVITY:
conductivityCalc.setPhase(this);
conductivity = conductivityCalc.calcConductivity();
break;
// case DIFFUSIVITY:
// diffusivityCalc.setPhase(this);
// diffusivity = diffusivityCalc.calcDiffusionCoefficients();
default:
init(phase);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package neqsim.physicalproperties.physicalpropertysystem;

import neqsim.physicalproperties.PhysicalPropertyType;
import neqsim.thermo.phase.PhaseInterface;

/**
Expand All @@ -27,15 +28,6 @@ public interface PhysicalPropertiesInterface extends Cloneable {
*/
public double getPureComponentViscosity(int i);

/**
* <p>
* setDensityModel.
* </p>
*
* @param model a {@link java.lang.String} object
*/
public void setDensityModel(String model);

/**
* <p>
* setMixingRule.
Expand Down Expand Up @@ -142,6 +134,15 @@ public void setMixingRule(
*/
public void setConductivityModel(String model);

/**
* <p>
* calcDensity.
* </p>
*
* @return a double
*/
public double calcDensity();

/**
* <p>
* getDensity.
Expand All @@ -153,30 +154,31 @@ public void setMixingRule(

/**
* <p>
* getPhase.
* setDensityModel.
* </p>
*
* @return a {@link neqsim.thermo.phase.PhaseInterface} object
* @param model a {@link java.lang.String} object
*/
public PhaseInterface getPhase();
public void setDensityModel(String model);

/**
* <p>
* setPhase.
* Getter for property <code>phase</code>.
* </p>
*
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @return a {@link neqsim.thermo.phase.PhaseInterface} object
*/
public void setPhase(PhaseInterface phase);
public PhaseInterface getPhase();

/**
* <p>
* calcDensity.
* Setter for property <code>phase</code>. Will also set the phase for all physicalpropertymethods
* using setPhases. Safe to call from constructor.
* </p>
*
* @return a double
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
*/
public double calcDensity();
public void setPhase(PhaseInterface phase);

/**
* <p>
Expand Down Expand Up @@ -228,7 +230,7 @@ public void setMixingRule(

/**
* <p>
* Initialize / calculate all physical properties of object.
* Initialize / calculate all physical properties of phase.
* </p>
*
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
Expand All @@ -237,13 +239,25 @@ public void setMixingRule(

/**
* <p>
* init.
* Initialize / calculate a specific physical property of phase.
* </p>
*
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @param ppt PhysicalPropertyType enum object.
*/
public void init(PhaseInterface phase, PhysicalPropertyType ppt);

/**
* <p>
* Initialize / calculate a specific physical property of phase.
* </p>
*
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @param type a {@link java.lang.String} object
* @param name Name of physical property.
*/
public void init(PhaseInterface phase, String type);
public default void init(PhaseInterface phase, String name) {
init(phase, PhysicalPropertyType.byName(name));
}

/**
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.physicalproperties.PhysicalPropertyType;
import neqsim.processsimulation.processequipment.stream.StreamInterface;
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.system.SystemInterface;
Expand Down Expand Up @@ -136,7 +137,7 @@ public double getMeasuredValue(String measurement, String unit) {
if (!tempFluid.hasPhaseType("oil")) {
return Double.NaN;
}
tempFluid.initPhysicalProperties("density");
tempFluid.initPhysicalProperties(PhysicalPropertyType.MASS_DENSITY);
return tempFluid.getPhase("gas").getCorrectedVolume()
/ tempFluid.getPhase("oil").getCorrectedVolume();
}
Expand All @@ -155,7 +156,7 @@ public double getMeasuredValue(String measurement, String unit) {
if (!tempFluid.hasPhaseType("gas")) {
return Double.NaN;
}
tempFluid.initPhysicalProperties("density");
tempFluid.initPhysicalProperties(PhysicalPropertyType.MASS_DENSITY);
return tempFluid.getPhase("gas").getFlowRate(unit);
}
if (measurement.equals("Oil Flow Rate")) {
Expand All @@ -173,7 +174,7 @@ public double getMeasuredValue(String measurement, String unit) {
if (!tempFluid.hasPhaseType("oil")) {
return Double.NaN;
}
tempFluid.initPhysicalProperties("density");
tempFluid.initPhysicalProperties(PhysicalPropertyType.MASS_DENSITY);
return tempFluid.getPhase("oil").getFlowRate(unit);
}
if (measurement.equals("Water Flow Rate")) {
Expand All @@ -191,7 +192,7 @@ public double getMeasuredValue(String measurement, String unit) {
if (!tempFluid.hasPhaseType("aqueous")) {
return Double.NaN;
}
tempFluid.initPhysicalProperties("density");
tempFluid.initPhysicalProperties(PhysicalPropertyType.MASS_DENSITY);
return tempFluid.getPhase("aqueous").getFlowRate(unit);
}
if (measurement.equals("gasDensity") || measurement.equals("oilDensity")
Expand Down Expand Up @@ -246,7 +247,7 @@ public double getMeasuredValue(String measurement, String unit) {
if (!tempFluid.hasPhaseType("oil")) {
return Double.NaN;
}
tempFluid.initPhysicalProperties("density");
tempFluid.initPhysicalProperties(PhysicalPropertyType.MASS_DENSITY);

double GOR_in_sm3_sm3 = tempFluid.getPhase("gas").getFlowRate("Sm3/hr")
/ tempFluid.getPhase("oil").getFlowRate("m3/hr");
Expand Down
Loading

0 comments on commit 793eea2

Please sign in to comment.