Skip to content

Commit

Permalink
fix: bug resetmixingrule was replaced with getmixingrule
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil committed Jan 11, 2025
1 parent be1a65d commit 0a56da2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/main/java/neqsim/thermo/phase/PhaseEos.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,16 @@ public void setMixingRule(MixingRuleTypeInterface mr) {
/** {@inheritDoc} */
@Override
public void setMixingRuleGEModel(String name) {
if (mixRule != null) {
if (mixRule == null) {
// do nothing or initialize?
logger.debug("mixRule is null");
} else {
mixRule.setMixingRuleGEModel(name);
}
if (mixSelect != null) {
if (mixSelect == null) {
// do nothing or initialize?
logger.debug("mixSelect is null");
} else {
mixSelect.setMixingRuleGEModel(name);
}
}
Expand All @@ -212,7 +218,9 @@ public void resetMixingRule(MixingRuleTypeInterface mr) {
if (mr == null) {
mixRule = null;
} else {
mixRule = mixSelect.getMixingRule(mr.getValue(), this);
mixRule = mixSelect.resetMixingRule(mr.getValue(), this);
// TODO: verify if should resetMixingRule or getMixingRule
// mixRule = mixSelect.getMixingRule(mr.getValue(), this);
}
}

Expand Down
44 changes: 40 additions & 4 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public void addComponent(int index, double moles) {
}
}
setTotalNumberOfMoles(getTotalNumberOfMoles() + moles);
// TODO: isInitialized = false;
}

/** {@inheritDoc} */
Expand All @@ -280,6 +281,7 @@ public void addComponent(int index, double moles, int phaseNumber) {
}

setTotalNumberOfMoles(getTotalNumberOfMoles() + moles);
// TODO: isInitialized = false;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -334,6 +336,7 @@ public void addComponent(String componentName, double moles) {
}
}
setTotalNumberOfMoles(getTotalNumberOfMoles() + moles);
// TODO: isInitialized = false;
}

/** {@inheritDoc} */
Expand All @@ -359,6 +362,7 @@ public void addComponent(String componentName, double moles, double TC, double P
componentNames.remove("default");
componentNames.add(componentName);
}
// TODO: isInitialized = false;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -398,6 +402,7 @@ public void addComponent(String componentName, double moles, int phaseNumber) {
getPhase(i).setAttractiveTerm(attractiveTermNumber);
}
numberOfComponents++;
// TODO: isInitialized = false;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -428,6 +433,7 @@ public void addComponent(String componentName, double value, String unitName) {
double SIval = unit.getSIvalue();
// System.out.println("number of moles " + SIval);
this.addComponent(componentName, SIval);
// TODO: isInitialized = false;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -458,6 +464,7 @@ public void addComponent(String componentName, double value, String name, int ph
double SIval = unit.getSIvalue();
// System.out.println("number of moles " + SIval);
this.addComponent(componentName, SIval, phaseNum);
// TODO: isInitialized = false;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -863,6 +870,7 @@ public void addTBPfraction(String componentName, double numberOfMoles, double mo
refSystem.setTemperature(273.15 + 15.0);
refSystem.setPressure(ThermodynamicConstantsInterface.referencePressure);
refSystem.addComponent("default", 1.0, 273.15, 50.0, 0.1);
refSystem.setMixingRule(1);
refSystem.init(0);
refSystem.setNumberOfPhases(1);
refSystem.setPhaseType(0, PhaseType.LIQUID);
Expand Down Expand Up @@ -1697,6 +1705,7 @@ public double getAntoineVaporPressure(double temp) {
/** {@inheritDoc} */
@Override
public final double getBeta() {
// TODO: verify, actually returning the heaviest?
return beta[0];
}

Expand Down Expand Up @@ -2507,6 +2516,12 @@ public double[] getMolarRate() {
/** {@inheritDoc} */
@Override
public double getMolarVolume() {
if (!this.isInitialized) {
this.init(0);
}
if (!isBetaValid()) {
logger.warn("getMolarVolume", "Calculation is wrong, as beta is not valid. Perform flash");
}
double volume = 0;
for (int i = 0; i < numberOfPhases; i++) {
volume += beta[phaseIndex[i]] * getPhase(i).getMolarVolume();
Expand All @@ -2517,6 +2532,12 @@ public double getMolarVolume() {
/** {@inheritDoc} */
@Override
public double getMolarVolume(String unit) {
if (!this.isInitialized) {
this.init(0);
}
if (!isBetaValid()) {
logger.warn("getMolarVolume", "Calculation is wrong, as beta is not valid. Perform flash");
}
double volume = 0;
for (int i = 0; i < numberOfPhases; i++) {
volume += beta[phaseIndex[i]] * getPhase(i).getMolarVolume(unit);
Expand Down Expand Up @@ -2908,6 +2929,16 @@ public final double getSumBeta() {
return sum;
}

/**
* Verify if sum of beta is 1. Used to check if System needs to be flashed.
*
* @return True if the sum of beta is close to 1.
*/
public boolean isBetaValid() {
return this.getSumBeta() > 1.0 - ThermodynamicModelSettings.phaseFractionMinimumLimit
&& this.getSumBeta() < 1.0 + ThermodynamicModelSettings.phaseFractionMinimumLimit;
}

/** {@inheritDoc} */
@Override
public final double getTC() {
Expand Down Expand Up @@ -3307,7 +3338,7 @@ public final void initBeta() {
if (!isInitialized
&& this.getSumBeta() < 1.0 - ThermodynamicModelSettings.phaseFractionMinimumLimit
|| this.getSumBeta() > 1.0 + ThermodynamicModelSettings.phaseFractionMinimumLimit) {
logger.warn("SystemThermo:initBeta - Sum of beta does not equal 1.0 ");
logger.warn("SystemThermo:initBeta - Sum of beta does not equal 1.0. " + beta);
}
}

Expand Down Expand Up @@ -3672,7 +3703,6 @@ public void normalizeBeta() {
@Override
public void orderByDensity() {
boolean change = false;
// int count = 0;

for (int i = 0; i < getNumberOfPhases(); i++) {
if (getPhase(i).getPhysicalProperties() == null) {
Expand All @@ -3683,9 +3713,9 @@ public void orderByDensity() {

do {
change = false;
// count++;
for (int i = 1; i < getNumberOfPhases(); i++) {
if (i == 4) {
// Do not sort phase 5 and 6
break;
}

Expand All @@ -3694,7 +3724,7 @@ public void orderByDensity() {
getPhase(i).initPhysicalProperties(PhysicalPropertyType.MASS_DENSITY);
}
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
logger.error(ex.getMessage());
}
if (getPhase(i).getPhysicalProperties().calcDensity() < getPhase(i - 1)
.getPhysicalProperties().calcDensity()) {
Expand Down Expand Up @@ -4002,6 +4032,7 @@ public void reset() {
addComponent(getPhase(0).getComponent(i).getComponentName(),
-getPhase(0).getComponent(i).getNumberOfmoles());
}
// TODO: isInitialized = false;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -4248,10 +4279,13 @@ public void setAttractiveTerm(int i) {
/** {@inheritDoc} */
@Override
public final void setBeta(double b) {
// TODO: if number of phases > 2, should fail
if (b < 0) {
logger.warn("setBeta - Tried to set beta < 0: " + beta);
b = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit;
}
if (b > 1) {
logger.warn("setBeta - Tried to set beta > 1: " + beta);
b = 1.0 - neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit;
}
beta[0] = b;
Expand All @@ -4262,9 +4296,11 @@ public final void setBeta(double b) {
@Override
public final void setBeta(int phaseNum, double b) {
if (b < 0) {
logger.warn("setBeta - Tried to set beta < 0: " + beta);
b = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit;
}
if (b > 1) {
logger.warn("setBeta - Tried to set beta > 1: " + beta);
b = 1.0 - neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit;
}
beta[phaseIndex[phaseNum]] = b;
Expand Down

0 comments on commit 0a56da2

Please sign in to comment.