Skip to content

Commit

Permalink
bugfix and refact (#674)
Browse files Browse the repository at this point in the history
* bugfix: Mix Mole Percent is always 100%
* refact: simplify if nesting
* refact: addComponent
* refact: deprecate redundant getNumberOfMoles
  • Loading branch information
asmfstatoil authored and EvenSol committed May 22, 2023
1 parent 20f2ffb commit 4709cfb
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 98 deletions.
8 changes: 4 additions & 4 deletions src/main/java/neqsim/thermo/phase/PhaseInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -668,20 +668,20 @@ public default double getExessGibbsEnergySymetric() {

/**
* <p>
* getComponent.
* Get Component by name.
* </p>
*
* @param name a {@link java.lang.String} object
* @param name Name of component
* @return a {@link neqsim.thermo.component.ComponentInterface} object
*/
public ComponentInterface getComponent(String name);

/**
* <p>
* getComponent.
* Get Component by index.
* </p>
*
* @param i a int
* @param i Component index
* @return a {@link neqsim.thermo.component.ComponentInterface} object
*/
public ComponentInterface getComponent(int i);
Expand Down
95 changes: 52 additions & 43 deletions src/main/java/neqsim/thermo/system/SystemInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -1022,24 +1022,6 @@ public void addPlusFraction(String componentName, double numberOfMoles, double m
*/
public void resetCharacterisation();

/**
* <p>
* Getter for property <code>maxNumberOfPhases</code>.
* </p>
*
* @return a int
*/
public int getMaxNumberOfPhases();

/**
* <p>
* Setter for property <code>maxNumberOfPhases</code>.
* </p>
*
* @param maxNumberOfPhases a int
*/
public void setMaxNumberOfPhases(int maxNumberOfPhases);

/**
* <p>
* getMixingRuleName.
Expand Down Expand Up @@ -1955,7 +1937,7 @@ public double calcBeta()
* Getter for property <code>numberOfPhases</code>.
* </p>
*
* @return Number of phases in use
* @return Number of phases used
*/
public int getNumberOfPhases();

Expand All @@ -1964,10 +1946,28 @@ public double calcBeta()
* Setter for property <code>numberOfPhases</code>.
* </p>
*
* @param number Value of number of phases to use to set.
* @param number Number of phases to use.
*/
public void setNumberOfPhases(int number);

/**
* <p>
* Getter for property <code>maxNumberOfPhases</code>.
* </p>
*
* @return Gets the maximum allowed number of phases to use.
*/
public int getMaxNumberOfPhases();

/**
* <p>
* Setter for property <code>maxNumberOfPhases</code>.
* </p>
*
* @param maxNumberOfPhases The maximum allowed number of phases to use.
*/
public void setMaxNumberOfPhases(int maxNumberOfPhases);

/**
* <p>
* getGibbsEnergy.
Expand All @@ -1988,32 +1988,37 @@ public double calcBeta()

/**
* <p>
* getComponent.
* Getter for property <code>componentNames</code>.
* </p>
*
* @param name a {@link java.lang.String} object
* @return a {@link neqsim.thermo.component.ComponentInterface} object
* @return Component names in system.
*/
public ComponentInterface getComponent(String name);
public String[] getComponentNames();


/**
* <p>
* getComponent.
* Get component by name.
* </p>
*
* @param number a int
* @param name Name of component
* @return a {@link neqsim.thermo.component.ComponentInterface} object
*/
public ComponentInterface getComponent(int number);
public default ComponentInterface getComponent(String name) {
return getPhase(0).getComponent(name);
}

/**
* <p>
* getNumberOfMoles.
* Get component by index.
* </p>
*
* @return a double
* @param i Component index
* @return a {@link neqsim.thermo.component.ComponentInterface} object
*/
public double getNumberOfMoles();
public default ComponentInterface getComponent(int i) {
return getPhase(0).getComponent(i);
}

/**
* <p>
Expand All @@ -2024,15 +2029,6 @@ public double calcBeta()
*/
public SystemInterface clone();

/**
* <p>
* getComponentNames.
* </p>
*
* @return Component names in system.
*/
public String[] getComponentNames();

/**
* <p>
* getdVdPtn.
Expand Down Expand Up @@ -2336,18 +2332,31 @@ public double calcBeta()
public void addGasToLiquid(double fraction);

/**
* method to get the total molar flow rate of a fluid.
* Getter for property <code>totalNumberOfMoles</code>.
*
* @return molar flow in unit mol/sec
* @return Total molar flow rate of fluid in unit mol/sec
*/
public double getTotalNumberOfMoles();

/**
* <p>
* setTotalNumberOfMoles.
* Getter for property <code>numberOfMoles</code>.
* </p>
*
* @return a double
* @deprecated Replaced by {@link getTotalNumberOfMoles}
*/
@Deprecated
public default double getNumberOfMoles() {
return getTotalNumberOfMoles();
}

/**
* <p>
* Setter for property <code>totalNumberOfMoles</code>.
* </p>
*
* @param totalNumberOfMoles a double
* @param totalNumberOfMoles Total molar flow rate of fluid in unit mol/sec
*/
public void setTotalNumberOfMoles(double totalNumberOfMoles);

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/neqsim/thermo/system/SystemProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class SystemProperties {
private Double[] values;
private String[] names;
/** Constant <code>nCols=(16 * 4) + 6</code> */
/** Constant <code>nCols=(16 * 4) + 6</code>. */
public static final int nCols = (16 * 4) + 6;

/**
Expand All @@ -36,7 +36,7 @@ public SystemProperties(SystemInterface fluid) {
values[k] = fluid.getTemperature("K");

names[++k] = "Mix Mole Percent";
values[k] = fluid.getNumberOfMoles() * 100;
values[k] = 100.0;
names[++k] = "Mix Weight Percent";
values[k] = 100.0;
names[++k] = "Mix Molar Volume [m3/mol]";
Expand Down Expand Up @@ -184,7 +184,7 @@ public SystemProperties(SystemInterface fluid) {
}

/**
* Get property names and values as a map
* Get property names and values as a map.
*
* @return map of property name and values
*/
Expand All @@ -197,7 +197,7 @@ public HashMap<String, Double> getProperties() {
}

/**
* Getter for property values
* Getter for property values.
*
* @return Systemproperty values
*/
Expand All @@ -206,7 +206,7 @@ public Double[] getValues() {
}

/**
* Get names of properties
* Get names of properties.
*
* @return Array of names of properties
*/
Expand Down
31 changes: 7 additions & 24 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ public void addComponent(String componentName, double value, String name, int ph
@Override
public void addComponent(int index, double moles) {
if (index >= getPhase(0).getNumberOfComponents()) {
logger.error("componentIndex higher than number of components in database");
logger.error("componentIndex higher than number of components in system");
return;
}
setTotalNumberOfMoles(getTotalNumberOfMoles() + moles);
Expand All @@ -1322,7 +1322,7 @@ public void addComponent(int index, double moles) {
@Override
public void addComponent(int index, double moles, int phaseNumber) {
if (index >= getPhase(0).getNumberOfComponents()) {
logger.error("componentIndex higher than number of components in database");
logger.error("componentIndex higher than number of components in system");
return;
}
double k = 1.0;
Expand All @@ -1335,6 +1335,7 @@ public void addComponent(int index, double moles, int phaseNumber) {
}
phaseArray[phaseIndex[i]].addMolesChemReac(index, moles * k, moles);
}

setTotalNumberOfMoles(getTotalNumberOfMoles() + moles);
}

Expand Down Expand Up @@ -1743,6 +1744,7 @@ public void init(int type, int phase) {
*/
public void initAnalytic(int type) {
if (type == 0) {
// todo: should actually clear all entries in arrays?
setNumberOfPhases(getMaxNumberOfPhases());
for (int i = 0; i < numberOfPhases; i++) {
phaseType[i] = 0;
Expand All @@ -1756,7 +1758,8 @@ public void initAnalytic(int type) {
phaseType[phaseIndex[i]], beta[phaseIndex[i]]);
}
}
numberOfPhases = 2;
// todo: reduce maxnumberofphases as well? Some sort of multiphase reset here.
setNumberOfPhases(2);
} else if (type == 1) {
for (int i = 0; i < numberOfPhases; i++) {
if (isPhase(i)) {
Expand Down Expand Up @@ -2410,7 +2413,7 @@ public String[] getComponentNames() {
@Override
public void setNumberOfPhases(int number) {
this.numberOfPhases = number;
if (getMaxNumberOfPhases() < numberOfPhases) {
if (numberOfPhases > getMaxNumberOfPhases()) {
setMaxNumberOfPhases(number);
}
}
Expand Down Expand Up @@ -2818,12 +2821,6 @@ public void setTemperature(double newTemperature, String unit) {
}
}

/** {@inheritDoc} */
@Override
public double getNumberOfMoles() {
return getTotalNumberOfMoles();
}

/** {@inheritDoc} */
@Override
public void setPhaseType(int phaseToChange, int newPhaseType) {
Expand Down Expand Up @@ -4371,20 +4368,6 @@ public int getMixingRule() {
return mixingRule;
}

/** {@inheritDoc} */
@Override
public ComponentInterface getComponent(String name) {
return getPhase(0).getComponent(name);
}

/** {@inheritDoc} */
@Override
public ComponentInterface getComponent(int number) {
return getPhase(0).getComponent(number);
}



/** {@inheritDoc} */
@Override
public void orderByDensity() {
Expand Down
40 changes: 18 additions & 22 deletions src/main/java/neqsim/thermodynamicOperations/flashOps/TPflash.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,29 +324,25 @@ public void run() {
}

if (passedTests || (dgonRT > 0 && tpdx > 0 && tpdy > 0) || Double.isNaN(system.getBeta())) {
if (system.checkStability()) {
if (stabilityCheck()) {
if (system.doMultiPhaseCheck()) {
// logger.info("one phase flash is stable - checking multiphase flash....
// ");
TPmultiflash operation = new TPmultiflash(system, true);
operation.run();
// commented out by Even Solbraa 6/2-2012k
// system.orderByDensity();
// system.init(3);
}
if (solidCheck) {
this.solidPhaseFlash();
}
if (system.isMultiphaseWaxCheck()) {
TPmultiflashWAX operation = new TPmultiflashWAX(system, true);
operation.run();
}

system.orderByDensity();
system.init(1);
return;
if (system.checkStability() && stabilityCheck()) {
if (system.doMultiPhaseCheck()) {
// logger.info("one phase flash is stable - checking multiphase flash....");
TPmultiflash operation = new TPmultiflash(system, true);
operation.run();
}
if (solidCheck) {
this.solidPhaseFlash();
}
if (system.isMultiphaseWaxCheck()) {
TPmultiflashWAX operation = new TPmultiflashWAX(system, true);
operation.run();
}

system.orderByDensity();
system.init(1);
// commented out by Even Solbraa 6/2-2012k
// system.init(3);
return;
}
}

Expand Down

0 comments on commit 4709cfb

Please sign in to comment.