Skip to content

Commit

Permalink
feat: introduce enum type PhysicalPropertyModel (#1148)
Browse files Browse the repository at this point in the history
* feat: introduce enum type PhysicalPropertyModel
* renamed functions related to setting and initializing physicalproperties in phase and physicalpropertyhandler. no change in system
* test: add test
  • Loading branch information
asmfstatoil authored Oct 28, 2024
1 parent 5cc8177 commit e999736
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static void main(String[] args) {
// testSystem.chemicalReactionInit();
testSystem.createDatabase(true);
testSystem.setMixingRule(10);
// testSystem.setPhysicalPropertyModel(3);
// testSystem.setPhysicalPropertyModel(PhysicalPropertyModel.AMINE);
// testSystem.setNumericDerivatives(true);
testSystem.initPhysicalProperties();
testSystem.getPhase(0).setTemperature(273.15 + 85);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import neqsim.fluidmechanics.flownode.twophasenode.TwoPhaseFlowNode;
import neqsim.fluidmechanics.geometrydefinitions.GeometryDefinitionInterface;
import neqsim.fluidmechanics.geometrydefinitions.reactor.ReactorData;
import neqsim.physicalproperties.physicalpropertysystem.PhysicalPropertyModel;
import neqsim.thermo.system.SystemFurstElectrolyteEos;
import neqsim.thermo.system.SystemInterface;
import neqsim.thermodynamicoperations.ThermodynamicOperations;
Expand Down Expand Up @@ -232,7 +233,7 @@ public static void main(String[] args) {
testSystem.setMixingRule(4);
testOps.TPflash();
testSystem.addComponent("CO2", 2000.11152181, "Nlitre/min", 0);
testSystem.setPhysicalPropertyModel(3);
testSystem.setPhysicalPropertyModel(PhysicalPropertyModel.AMINE);
testSystem.init_x_y();
testSystem.getPhases()[1].setTemperature(313.0);
testSystem.getPhases()[0].setTemperature(325.0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package neqsim.fluidmechanics.flowsystem.twophaseflowsystem.twophasepipeflowsystem;

import neqsim.physicalproperties.physicalpropertysystem.PhysicalPropertyModel;
import neqsim.thermo.system.SystemFurstElectrolyteEos;
import neqsim.thermo.system.SystemInterface;
import neqsim.thermodynamicoperations.ThermodynamicOperations;
Expand Down Expand Up @@ -42,7 +43,7 @@ public static void main(String[] args) {
testSystem.chemicalReactionInit();
testSystem.createDatabase(true);
testSystem.setMixingRule(4);
testSystem.setPhysicalPropertyModel(3);
testSystem.setPhysicalPropertyModel(PhysicalPropertyModel.AMINE);
// testOps.TPflash();
// testSystem.display();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.physicalproperties.physicalpropertysystem.PhysicalProperties;
import neqsim.physicalproperties.physicalpropertysystem.PhysicalPropertyModel;
import neqsim.physicalproperties.physicalpropertysystem.commonphasephysicalproperties.DefaultPhysicalProperties;
import neqsim.physicalproperties.physicalpropertysystem.gasphysicalproperties.GasPhysicalProperties;
import neqsim.physicalproperties.physicalpropertysystem.liquidphysicalproperties.AminePhysicalProperties;
Expand All @@ -15,7 +16,7 @@

/**
* <p>
* PhysicalPropertyHandler class.
* PhysicalPropertyHandler class. Group together the physical property functions (density for
* </p>
*
* @author ESOL
Expand Down Expand Up @@ -44,44 +45,44 @@ public PhysicalPropertyHandler() {}
* </p>
*
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @param type 0 Orginal/default 1 Water 2 Glycol 3 Amine 4 CO2Water 6 Basic
* @param ppm PhysicalPropertyModel enum object
*/
public void setPhysicalProperties(PhaseInterface phase, int type) {
switch (type) {
case 0: // Default
public void setPhysicalProperties(PhaseInterface phase, PhysicalPropertyModel ppm) {
switch (ppm) {
case DEFAULT: // Default
gasPhysicalProperties = new GasPhysicalProperties(phase, 0, 0);
oilPhysicalProperties = new LiquidPhysicalProperties(phase, 0, 0);
aqueousPhysicalProperties = new WaterPhysicalProperties(phase, 0, 0);
break;
case 1: // Water
case WATER: // Water
gasPhysicalProperties = new GasPhysicalProperties(phase, 0, 0);
oilPhysicalProperties = new LiquidPhysicalProperties(phase, 0, 0);
aqueousPhysicalProperties = new WaterPhysicalProperties(phase, 0, 0);
break;
case 2: // Glycol
case GLYCOL: // Glycol
gasPhysicalProperties = new GasPhysicalProperties(phase, 0, 0);
oilPhysicalProperties = new LiquidPhysicalProperties(phase, 0, 0);
aqueousPhysicalProperties = new GlycolPhysicalProperties(phase, 0, 0);
break;
case 3: // Amine
case AMINE: // Amine
gasPhysicalProperties = new GasPhysicalProperties(phase, 0, 0);
oilPhysicalProperties = new LiquidPhysicalProperties(phase, 0, 0);
aqueousPhysicalProperties = new AminePhysicalProperties(phase, 0, 0);
break;
case 4: // CO2water
case CO2WATER:
gasPhysicalProperties = new GasPhysicalProperties(phase, 0, 0);
oilPhysicalProperties = new LiquidPhysicalProperties(phase, 0, 0);
aqueousPhysicalProperties = new CO2waterPhysicalProperties(phase, 0, 0);
break;
case 6: // Basic?
case BASIC:
gasPhysicalProperties = new DefaultPhysicalProperties(phase, 0, 0);
oilPhysicalProperties = new DefaultPhysicalProperties(phase, 0, 0);
aqueousPhysicalProperties = new DefaultPhysicalProperties(phase, 0, 0);
break;
default:
logger
.error("error selecting physical properties model.\n Continue using default model...");
setPhysicalProperties(phase, 0);
setPhysicalProperties(phase, PhysicalPropertyModel.DEFAULT);
break;
}
solidPhysicalProperties = new SolidPhysicalProperties(phase);
Expand All @@ -94,13 +95,13 @@ public void setPhysicalProperties(PhaseInterface phase, int type) {

/**
* <p>
* getPhysicalProperty.
* Get PhysicalProperty
* </p>
*
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @return a {@link neqsim.physicalproperties.physicalpropertysystem.PhysicalProperties} object
*/
public PhysicalProperties getPhysicalProperty(PhaseInterface phase) {
public PhysicalProperties getPhysicalProperties(PhaseInterface phase) {
switch (phase.getType()) {
case GAS:
return gasPhysicalProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
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
/** Constant <code>copyOfValues</code> */
// We know we'll never mutate this, so we can keep a local copy for fast lookup in byName
/** Constant <code>copyOfValues</code>. */
private static final PhysicalPropertyType[] copyOfValues = values();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package neqsim.physicalproperties.physicalpropertysystem;

import neqsim.util.exception.InvalidInputException;

/**
* Types of PhysicalPropertyModel. This is used when initializing PhysicalPropertyhandler.
*
* @author ASMF
*/
public enum PhysicalPropertyModel {
DEFAULT(0), WATER(1), GLYCOL(2), AMINE(3), CO2WATER(4), BASIC(6);

/** 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 PhysicalPropertyModel[] copyOfValues = values();

/**
* Constructor for PhysicalPropertyModel enum.
*
* @param value Numeric value index for phase type
*/
private PhysicalPropertyModel(int value) {
this.value = value;
}

/**
* Getter for property value.
*
* @return Numeric index of phase type
*/
@Deprecated
public int getValue() {
return this.value;
}

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

/**
* Get PhysicalPropertyModel by value.
*
* @param value Value to get PhysicalPropertyModel for.
* @return PhysicalPropertyModel object
*/
public static PhysicalPropertyModel byValue(int value) {
for (PhysicalPropertyModel pt : copyOfValues) {
if (pt.getValue() == (value)) {
return pt;
}
}
throw new RuntimeException(
new InvalidInputException("PhysicalPropertyModel", "byValue", "value", "is not valid."));
}
}
78 changes: 43 additions & 35 deletions src/main/java/neqsim/thermo/phase/Phase.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@
import neqsim.physicalproperties.PhysicalPropertyHandler;
import neqsim.physicalproperties.PhysicalPropertyType;
import neqsim.physicalproperties.physicalpropertysystem.PhysicalProperties;
import neqsim.physicalproperties.physicalpropertysystem.PhysicalPropertyModel;
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.ThermodynamicModelSettings;
import neqsim.thermo.component.ComponentInterface;
import neqsim.thermo.system.SystemInterface;
import neqsim.util.exception.InvalidInputException;

/**
* Phase class.
* Abstract Phase class. All Phase classes shall subclass this class.
*
* <p>
* From wiki: A phase is a region of a space (a thermodynamic system), in neqsim named a
* SystemInterface, throughout which all physical properties of a material are essentially uniform.
* A SystemInterface can contain a single or multiple PhaseInterface objects.
*
* See PhaseType for the types of Phases that NeqSim is aware of. See also StateOfMatter.
*
* In NeqSim, there are multiple Phase classes, each representing a specific set of Equations Of
* State. Phases have corresponding Component classes and System classes to ensure same EoS is used
* throughout.
* </p>
*
* @author Even Solbraa
*/
Expand All @@ -37,10 +50,10 @@ public abstract class Phase implements PhaseInterface {

private boolean constantPhaseVolume = false;

public int physicalPropertyType = 0;
private PhysicalPropertyModel ppm = PhysicalPropertyModel.DEFAULT;
public PhysicalPropertyHandler physicalPropertyHandler = null;

protected boolean useVolumeCorrection = true;
public neqsim.physicalproperties.PhysicalPropertyHandler physicalPropertyHandler = null;
protected double molarVolume = 1.0;
protected double phaseVolume = 1.0;

Expand All @@ -64,7 +77,11 @@ public abstract class Phase implements PhaseInterface {

private int initType = 0;
int mixingRuleNumber = 0;

/** Temperature of phase. */
double temperature = 0;

/** Pressure of phase. */
double pressure = 0;

protected PhaseInterface[] refPhase = null;
Expand Down Expand Up @@ -429,10 +446,8 @@ public void setTemperature(double temp) {
public PhysicalProperties getPhysicalProperties() {
if (physicalPropertyHandler == null) {
initPhysicalProperties();
return physicalPropertyHandler.getPhysicalProperty(this);
} else {
return physicalPropertyHandler.getPhysicalProperty(this);
}
return physicalPropertyHandler.getPhysicalProperties(this);
}

/** {@inheritDoc} */
Expand All @@ -459,20 +474,25 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType

/** {@inheritDoc} */
@Override
public void setPhysicalProperties() {
// System.out.println("Physical properties: Default model");
setPhysicalProperties(physicalPropertyType);
// physicalProperty = new
// physicalproperties.physicalPropertySystem.commonPhasePhysicalProperties.DefaultPhysicalProperties(this,0,0);
public void setPpm(PhysicalPropertyModel ppm) {
this.ppm = ppm;
}

/** {@inheritDoc} */
@Override
public void setPhysicalProperties(int type) {
public PhysicalPropertyModel getPhysicalPropertyModel() {
// todo: still inconsistent
return this.ppm;
}

/** {@inheritDoc} */
@Override
public void setPhysicalPropertyModel(PhysicalPropertyModel ppm) {
setPpm(ppm);
if (physicalPropertyHandler == null) {
physicalPropertyHandler = new PhysicalPropertyHandler();
}
physicalPropertyHandler.setPhysicalProperties(this, type);
physicalPropertyHandler.setPhysicalProperties(this, ppm);
}

/** {@inheritDoc} */
Expand All @@ -488,8 +508,8 @@ public void initPhysicalProperties() {
physicalPropertyHandler = new PhysicalPropertyHandler();
}

if (physicalPropertyHandler.getPhysicalProperty(this) == null) {
setPhysicalProperties(physicalPropertyType);
if (physicalPropertyHandler.getPhysicalProperties(this) == null) {
setPhysicalPropertyModel(ppm);
}
getPhysicalProperties().init(this);
}
Expand All @@ -500,19 +520,19 @@ public void initPhysicalProperties(PhysicalPropertyType ppt) {
if (physicalPropertyHandler == null) {
physicalPropertyHandler = new PhysicalPropertyHandler();
}
if (physicalPropertyHandler.getPhysicalProperty(this) == null) {
setPhysicalProperties(physicalPropertyType);

if (physicalPropertyHandler.getPhysicalProperties(this) == null) {
setPhysicalPropertyModel(ppm);
}
getPhysicalProperties().setPhase(this);

// if (physicalProperty == null || phaseTypeAtLastPhysPropUpdate != phaseType ||
// !phaseTypeNameAtLastPhysPropUpdate.equals(phaseTypeName)) {
// this.setPhysicalProperties();
// }
// physicalProperty.init(this, type);
getPhysicalProperties().init(this, ppt);
}

/** {@inheritDoc} */
public void setPhysicalProperties(PhysicalPropertyModel ppm) {
physicalPropertyHandler.setPhysicalProperties(this, ppm);
}

/** {@inheritDoc} */
@Override
public double geta(PhaseInterface phase, double temperature, double pressure, int numbcomp) {
Expand Down Expand Up @@ -1911,18 +1931,6 @@ public void setRefPhase(neqsim.thermo.phase.PhaseInterface[] refPhase) {
this.refPhase = refPhase;
}

/** {@inheritDoc} */
@Override
public final int getPhysicalPropertyType() {
return physicalPropertyType;
}

/** {@inheritDoc} */
@Override
public void setPhysicalPropertyType(int physicalPropertyType) {
this.physicalPropertyType = physicalPropertyType;
}

/** {@inheritDoc} */
@Override
public void setParams(PhaseInterface phase, double[][] alpha, double[][] Dij, double[][] DijT,
Expand Down
Loading

0 comments on commit e999736

Please sign in to comment.