diff --git a/src/main/java/neqsim/fluidmechanics/flownode/fluidboundary/interphasetransportcoefficient/interphasetwophase/stirredcell/InterphaseStirredCellFlow.java b/src/main/java/neqsim/fluidmechanics/flownode/fluidboundary/interphasetransportcoefficient/interphasetwophase/stirredcell/InterphaseStirredCellFlow.java index 3fcf643e43..d2839dc50e 100644 --- a/src/main/java/neqsim/fluidmechanics/flownode/fluidboundary/interphasetransportcoefficient/interphasetwophase/stirredcell/InterphaseStirredCellFlow.java +++ b/src/main/java/neqsim/fluidmechanics/flownode/fluidboundary/interphasetransportcoefficient/interphasetwophase/stirredcell/InterphaseStirredCellFlow.java @@ -59,9 +59,7 @@ public double calcInterphaseHeatTransferCoefficient(int phaseNum, double prandtl if (Math.abs(node.getReynoldsNumber()) < 2000) { return 3.66 / node.getHydraulicDiameter(phaseNum) * node.getBulkSystem().getPhase(phaseNum).getPhysicalProperties().getConductivity(); - } - // if turbulent - use chilton colburn analogy - else { + } else { // if turbulent - use chilton colburn analogy double temp = node.getBulkSystem().getPhase(phaseNum).getCp() / node.getBulkSystem().getPhase(phaseNum).getMolarMass() / node.getBulkSystem().getPhase(phaseNum).getNumberOfMolesInPhase() diff --git a/src/main/java/neqsim/process/equipment/compressor/CompressorChartAlternativeMapLookupExtrapolate.java b/src/main/java/neqsim/process/equipment/compressor/CompressorChartAlternativeMapLookupExtrapolate.java index 8edefe0f2e..1613b24b23 100644 --- a/src/main/java/neqsim/process/equipment/compressor/CompressorChartAlternativeMapLookupExtrapolate.java +++ b/src/main/java/neqsim/process/equipment/compressor/CompressorChartAlternativeMapLookupExtrapolate.java @@ -69,8 +69,10 @@ public ArrayList getClosestRefSpeeds(double speed) { /** * {@inheritDoc} * + *

* Calculates the polytropic head for a given flow and speed by interpolating or extrapolating * between reference compressor curves. + *

*/ @Override public double getPolytropicHead(double flow, double speed) { diff --git a/src/main/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchanger.java b/src/main/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchanger.java index 5edb27ca94..446a90dd35 100644 --- a/src/main/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchanger.java +++ b/src/main/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchanger.java @@ -516,9 +516,7 @@ public void run(UUID id) { // Finalize the setup run(); return; - } - - else { + } else { // Run all input and output streams to ensure they are up-to-date for (StreamInterface inStream : inStreams) { inStream.run(id); diff --git a/src/main/java/neqsim/process/equipment/pipeline/PipeBeggsAndBrills.java b/src/main/java/neqsim/process/equipment/pipeline/PipeBeggsAndBrills.java index 428d55227e..04cd65fbba 100644 --- a/src/main/java/neqsim/process/equipment/pipeline/PipeBeggsAndBrills.java +++ b/src/main/java/neqsim/process/equipment/pipeline/PipeBeggsAndBrills.java @@ -178,20 +178,21 @@ public void setPipeSpecification(double nominalDiameter, String pipeSec) { this.nominalDiameter = nominalDiameter; this.PipeSpecSet = true; - neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); - java.sql.ResultSet dataSet = - database.getResultSet("SELECT * FROM pipedata where Size='" + nominalDiameter + "'"); - try { - if (dataSet.next()) { - this.pipeThickness = Double.parseDouble(dataSet.getString(pipeSpecification)) / 1000; - this.insideDiameter = - (Double.parseDouble(dataSet.getString("OD"))) / 1000 - 2 * this.pipeThickness; + try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) { + java.sql.ResultSet dataSet = + database.getResultSet("SELECT * FROM pipedata where Size='" + nominalDiameter + "'"); + try { + if (dataSet.next()) { + this.pipeThickness = Double.parseDouble(dataSet.getString(pipeSpecification)) / 1000; + this.insideDiameter = + (Double.parseDouble(dataSet.getString("OD"))) / 1000 - 2 * this.pipeThickness; + } + } catch (NumberFormatException e) { + logger.error(e.getMessage()); + } catch (SQLException e) { + logger.error(e.getMessage()); } - } catch (NumberFormatException e) { - // TODO Auto-generated catch block - logger.error(e.getMessage()); } catch (SQLException e) { - // TODO Auto-generated catch block logger.error(e.getMessage()); } } diff --git a/src/main/java/neqsim/thermo/component/ComponentHydrate.java b/src/main/java/neqsim/thermo/component/ComponentHydrate.java index 24ba5b47a9..2f56ffc360 100644 --- a/src/main/java/neqsim/thermo/component/ComponentHydrate.java +++ b/src/main/java/neqsim/thermo/component/ComponentHydrate.java @@ -40,6 +40,8 @@ public class ComponentHydrate extends Component { private double sphericalCoreRadiusHydrate = 0.0; private double lennardJonesEnergyParameterHydrate = 0.0; private double lennardJonesMolecularDiameterHydrate = 0.0; + + /** Reference phase containing only this single component, i.e., mixing rules are not relevant. */ PhaseInterface refPhase = null; /** @@ -659,6 +661,7 @@ public void setSolidRefFluidPhase(PhaseInterface phase) { refPhase.setTemperature(273.0); refPhase.setPressure(1.0); refPhase.addComponent("water", 10.0, 10.0, 0); + refPhase.setMixingRule(null); refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.byValue(1), 1.0); } catch (Exception ex) { logger.error("error occured", ex); diff --git a/src/main/java/neqsim/thermo/component/ComponentSolid.java b/src/main/java/neqsim/thermo/component/ComponentSolid.java index 2db361c621..7418a73ddf 100644 --- a/src/main/java/neqsim/thermo/component/ComponentSolid.java +++ b/src/main/java/neqsim/thermo/component/ComponentSolid.java @@ -30,9 +30,11 @@ public class ComponentSolid extends ComponentSrk { double soldens = 0.0; boolean CCequation = true; boolean AntoineSolidequation = true; - PhaseInterface refPhase = null; double pureCompFug = 0.0; + /** Reference phase containing only this single component, i.e., mixing rules are not relevant. */ + PhaseInterface refPhase = null; + /** *

* Constructor for ComponentSolid. @@ -257,6 +259,7 @@ public void setSolidRefFluidPhase(PhaseInterface phase) { refPhase.getComponent(componentName) .setAttractiveTerm(phase.getComponent(componentName).getAttractiveTermNumber()); refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.byValue(1), 1.0); + refPhase.setMixingRule(null); // } } catch (Exception ex) { logger.error("error occured", ex); diff --git a/src/main/java/neqsim/thermo/mixingrule/CPAMixingRuleType.java b/src/main/java/neqsim/thermo/mixingrule/CPAMixingRuleType.java new file mode 100644 index 0000000000..4bced12989 --- /dev/null +++ b/src/main/java/neqsim/thermo/mixingrule/CPAMixingRuleType.java @@ -0,0 +1,76 @@ +package neqsim.thermo.mixingrule; + +import neqsim.util.exception.InvalidInputException; + +/** + * Types of CPAMixingRule, relating to different kind of mixing rules relevant for CPA type phases. + * Available types are: + *

+ * + * @author ASMF + */ +public enum CPAMixingRuleType implements MixingRuleTypeInterface { + CPA_RADOCH(1), PCSAFTA_RADOCH(3); + + /** 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 CPAMixingRuleType[] copyOfValues = values(); + + /** + * Constructor for CPAMixingRuleType enum. + * + * @param value Numeric value index for mixing rule + */ + private CPAMixingRuleType(int value) { + this.value = value; + } + + /** + * Getter for property value. + * + * @return Numeric index of phase type + */ + @Deprecated + public int getValue() { + return this.value; + } + + /** + * Get CPAMixingRuleType by name. + * + * @param name Name to get CPAMixingRuleType for. + * @return CPAMixingRuleType object + */ + public static CPAMixingRuleType byName(String name) { + for (CPAMixingRuleType mr : copyOfValues) { + if (mr.name().equals(name.toUpperCase())) { + return mr; + } + } + throw new RuntimeException( + new InvalidInputException("CPAMixingRuleType", "byName", "name", "is not valid.")); + } + + /** + * Get CPAMixingRuleType by value. + * + * @param value Value to get CPAMixingRuleType for. + * @return CPAMixingRuleType object + */ + public static CPAMixingRuleType byValue(int value) { + for (CPAMixingRuleType mr : copyOfValues) { + if (mr.getValue() == (value)) { + return mr; + } + } + throw new RuntimeException( + new InvalidInputException("CPAMixingRuleType", "byValue", "value", "is not valid.")); + } +} diff --git a/src/main/java/neqsim/thermo/mixingrule/CPAMixingRules.java b/src/main/java/neqsim/thermo/mixingrule/CPAMixingRules.java index 6a5e8cdc30..a9e417cbbf 100644 --- a/src/main/java/neqsim/thermo/mixingrule/CPAMixingRules.java +++ b/src/main/java/neqsim/thermo/mixingrule/CPAMixingRules.java @@ -617,15 +617,37 @@ public CPAMixingRulesInterface getMixingRule(int mr) { if (mr == 1) { mixingRuleName = "CPA_Radoch"; return new CPA_Radoch(); - } else if (mr == 2) { - mixingRuleName = "CPA_Radoch"; - return new CPA_Radoch(); } else if (mr == 3) { mixingRuleName = "PCSAFTa_Radoch"; return new PCSAFTa_Radoch(); - } else { - mixingRuleName = "CPA_Radoch"; - return new CPA_Radoch(); + } + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "getMixingRule", "mr")); + } + + /** + *

+ * getMixingRule. + *

+ * + * @param mr a int + * @return a {@link neqsim.thermo.mixingrule.CPAMixingRulesInterface} object + */ + public CPAMixingRulesInterface getMixingRule(MixingRuleTypeInterface mr) { + if (!CPAMixingRuleType.class.isInstance(mr)) { + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "setMixingRule", "mr")); + } + CPAMixingRuleType cmr = (CPAMixingRuleType) mr; + switch (cmr) { + case CPA_RADOCH: + mixingRuleName = "CPA_Radoch"; + return new CPA_Radoch(); + case PCSAFTA_RADOCH: + mixingRuleName = "PCSAFTa_Radoch"; + return new PCSAFTa_Radoch(); + default: + return new CPA_Radoch(); } } diff --git a/src/main/java/neqsim/thermo/mixingrule/EosMixingRuleType.java b/src/main/java/neqsim/thermo/mixingrule/EosMixingRuleType.java index 59b2ca56c9..cbb36b188d 100644 --- a/src/main/java/neqsim/thermo/mixingrule/EosMixingRuleType.java +++ b/src/main/java/neqsim/thermo/mixingrule/EosMixingRuleType.java @@ -21,7 +21,7 @@ * * @author ASMF */ -public enum EosMixingRuleType { +public enum EosMixingRuleType implements MixingRuleTypeInterface { NO(1), CLASSIC(2), CLASSIC_HV(3), HV(4), WS(5), CPA_MIX(7), CLASSIC_T(8), CLASSIC_T_CPA( 9), CLASSIC_TX_CPA(10); diff --git a/src/main/java/neqsim/thermo/mixingrule/MixingRuleTypeInterface.java b/src/main/java/neqsim/thermo/mixingrule/MixingRuleTypeInterface.java new file mode 100644 index 0000000000..1828417732 --- /dev/null +++ b/src/main/java/neqsim/thermo/mixingrule/MixingRuleTypeInterface.java @@ -0,0 +1,10 @@ +package neqsim.thermo.mixingrule; + +/** + * Dummy Interface to allow Phase object to keep either CPA or EosMixingRuleType + */ +public interface MixingRuleTypeInterface { + + + public int getValue(); +} diff --git a/src/main/java/neqsim/thermo/phase/Phase.java b/src/main/java/neqsim/thermo/phase/Phase.java index 67ae64293c..44b69fbbdf 100644 --- a/src/main/java/neqsim/thermo/phase/Phase.java +++ b/src/main/java/neqsim/thermo/phase/Phase.java @@ -16,7 +16,7 @@ import neqsim.thermo.ThermodynamicConstantsInterface; import neqsim.thermo.ThermodynamicModelSettings; import neqsim.thermo.component.ComponentInterface; -import neqsim.thermo.mixingrule.EosMixingRuleType; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; import neqsim.thermo.system.SystemInterface; import neqsim.util.exception.InvalidInputException; @@ -76,8 +76,7 @@ public abstract class Phase implements PhaseInterface { public double numberOfMolesInPhase = 0; private int initType = 0; - public boolean mixingRuleDefined = false; - private EosMixingRuleType mixingRuleType = EosMixingRuleType.NO; + protected MixingRuleTypeInterface mixingRuleType; /** Temperature of phase. */ double temperature = 0; @@ -85,6 +84,7 @@ public abstract class Phase implements PhaseInterface { /** Pressure of phase. */ double pressure = 0; + /** Reference phase per component. Relevant for solids and chemicalreactions. */ protected PhaseInterface[] refPhase = null; protected PhaseType pt = PhaseType.GAS; @@ -1328,11 +1328,10 @@ public void initRefPhases(boolean onlyPure, String name) { refPhase[i].addComponent(getComponent(i).getComponentName(), 10.0, 10.0, 0); } refPhase[i].setAttractiveTerm(this.getComponent(i).getAttractiveTermNumber()); - refPhase[i].setMixingRule(this.getEosMixingRuleType().getValue()); + refPhase[i].setMixingRule(this.getMixingRuleType()); refPhase[i].setType(this.getType()); refPhase[i].init(refPhase[i].getNumberOfMolesInPhase(), 1, 0, this.getType(), 1.0); } else { - // System.out.println("ref " + name); if (getComponent(i).isIsTBPfraction() || getComponent(i).isIsPlusFraction()) { refPhase[i].addComponent("default", 10.0, 10.0, 0); refPhase[i].getComponent(0).setMolarMass(this.getComponent(i).getMolarMass()); @@ -1346,7 +1345,7 @@ public void initRefPhases(boolean onlyPure, String name) { } refPhase[i].addComponent(name, 10.0, 10.0, 1); refPhase[i].setAttractiveTerm(this.getComponent(i).getAttractiveTermNumber()); - refPhase[i].setMixingRule(this.getEosMixingRuleType().getValue()); + refPhase[i].setMixingRule(this.getMixingRuleType()); refPhase[i].init(refPhase[i].getNumberOfMolesInPhase(), 2, 0, this.getType(), 1.0); } } @@ -1726,16 +1725,10 @@ public double getdrhodN() { /** {@inheritDoc} */ @Override - public EosMixingRuleType getEosMixingRuleType() { + public MixingRuleTypeInterface getMixingRuleType() { return mixingRuleType; } - /** {@inheritDoc} */ - @Override - public void setMixingRule(int type) { - mixingRuleType = EosMixingRuleType.byValue(type); - } - /** *

* calcDiElectricConstant. @@ -2035,20 +2028,13 @@ public final void setBeta(double b) { this.beta = b; } - /** {@inheritDoc} */ - @Override - public void setMixingRuleGEModel(String name) {} - /** {@inheritDoc} */ @Override public boolean isMixingRuleDefined() { - return mixingRuleDefined; - } - - /** {@inheritDoc} */ - @Override - public void setMixingRuleDefined(boolean mixingRuleDefined) { - this.mixingRuleDefined = mixingRuleDefined; + if (mixingRuleType == null) { + return false; + } + return true; } /** {@inheritDoc} */ diff --git a/src/main/java/neqsim/thermo/phase/PhaseDefault.java b/src/main/java/neqsim/thermo/phase/PhaseDefault.java index 9a6d7af3a3..9d46c84874 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseDefault.java +++ b/src/main/java/neqsim/thermo/phase/PhaseDefault.java @@ -1,6 +1,8 @@ package neqsim.thermo.phase; import neqsim.thermo.component.ComponentInterface; +import neqsim.thermo.mixingrule.EosMixingRulesInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -67,7 +69,21 @@ public double molarVolume(double pressure, double temperature, double A, double /** {@inheritDoc} */ @Override - public void resetMixingRule(int type) {} + public EosMixingRulesInterface getMixingRule() { + return null; + } + + /** {@inheritDoc} */ + @Override + public void setMixingRuleGEModel(String name) {} + + /** {@inheritDoc} */ + @Override + public void setMixingRule(MixingRuleTypeInterface mr) {} + + /** {@inheritDoc} */ + @Override + public void resetMixingRule(MixingRuleTypeInterface mr) {} /** {@inheritDoc} */ @Override diff --git a/src/main/java/neqsim/thermo/phase/PhaseDesmukhMather.java b/src/main/java/neqsim/thermo/phase/PhaseDesmukhMather.java index 7f9de17b63..06e99ff9e1 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseDesmukhMather.java +++ b/src/main/java/neqsim/thermo/phase/PhaseDesmukhMather.java @@ -4,6 +4,7 @@ import org.apache.logging.log4j.Logger; import neqsim.thermo.component.ComponentDesmukhMather; import neqsim.thermo.component.ComponentGEInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; import neqsim.util.exception.IsNaNException; import neqsim.util.exception.TooManyIterationsException; @@ -53,8 +54,8 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); + public void setMixingRule(MixingRuleTypeInterface mr) { + super.setMixingRule(mr); this.aij = new double[numberOfComponents][numberOfComponents]; this.bij = new double[numberOfComponents][numberOfComponents]; try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) { diff --git a/src/main/java/neqsim/thermo/phase/PhaseDuanSun.java b/src/main/java/neqsim/thermo/phase/PhaseDuanSun.java index 4f9cdca9ca..e5440fb529 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseDuanSun.java +++ b/src/main/java/neqsim/thermo/phase/PhaseDuanSun.java @@ -1,6 +1,7 @@ package neqsim.thermo.phase; import neqsim.thermo.component.ComponentGeDuanSun; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; import neqsim.util.exception.IsNaNException; import neqsim.util.exception.TooManyIterationsException; @@ -38,8 +39,8 @@ public void addComponent(String name, double moles, double molesInPhase, int com /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); + public void setMixingRule(MixingRuleTypeInterface mr) { + super.setMixingRule(mr); this.alpha = mixSelect.getNRTLalpha(); this.Dij = mixSelect.getNRTLDij(); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java index 643e2b234a..c588a59904 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java +++ b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java @@ -10,6 +10,7 @@ import neqsim.thermo.component.ComponentElectrolyteCPA; import neqsim.thermo.mixingrule.CPAMixingRules; import neqsim.thermo.mixingrule.CPAMixingRulesInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -97,9 +98,10 @@ public PhaseElectrolyteCPA clone() { /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); - // NB! Ignores input type + public void setMixingRule(MixingRuleTypeInterface mr) { + // NB! Sets EOS mixing rule in parent class PhaseEos + super.setMixingRule(mr); + // NB! Ignores input mr, uses CPA cpamix = cpaSelect.getMixingRule(1, this); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPAOld.java b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPAOld.java index e5ff32377b..b4d8605047 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPAOld.java +++ b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPAOld.java @@ -7,6 +7,7 @@ import neqsim.thermo.component.ComponentEosInterface; import neqsim.thermo.mixingrule.CPAMixingRules; import neqsim.thermo.mixingrule.CPAMixingRulesInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -96,9 +97,10 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); - // NB! Ignores input type + public void setMixingRule(MixingRuleTypeInterface mr) { + // NB! Sets EOS mixing rule in parent class PhaseEos + super.setMixingRule(mr); + // NB! Ignores input mr, uses CPA cpamix = cpaSelect.getMixingRule(1, this); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseEos.java b/src/main/java/neqsim/thermo/phase/PhaseEos.java index 4373e2d90f..642cc7ade9 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseEos.java +++ b/src/main/java/neqsim/thermo/phase/PhaseEos.java @@ -10,8 +10,10 @@ import org.apache.logging.log4j.Logger; import neqsim.thermo.ThermodynamicModelSettings; import neqsim.thermo.component.ComponentEosInterface; +import neqsim.thermo.mixingrule.EosMixingRuleType; import neqsim.thermo.mixingrule.EosMixingRules; import neqsim.thermo.mixingrule.EosMixingRulesInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; import neqsim.util.ExcludeFromJacocoGeneratedReport; /** @@ -33,6 +35,7 @@ public abstract class PhaseEos extends Phase implements PhaseEosInterface { private double g = 0; public double delta1 = 0; public double delta2 = 0; + protected EosMixingRules mixSelect = null; protected EosMixingRulesInterface mixRule = null; double uEOS = 0; @@ -66,12 +69,6 @@ public PhaseEos() { // solver = new newtonRhapson(); } - /** {@inheritDoc} */ - @Override - public EosMixingRulesInterface getEosMixingRule() { - return mixRule; - } - /** {@inheritDoc} */ @Override @ExcludeFromJacocoGeneratedReport @@ -92,8 +89,8 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType if (pt != PhaseType.GAS) { pt = PhaseType.LIQUID; } - if (!mixingRuleDefined) { - setMixingRule(1); + if (!isMixingRuleDefined()) { + setMixingRule(EosMixingRuleType.byValue(1)); } super.init(totalNumberOfMoles, numberOfComponents, initType, pt, beta); @@ -168,25 +165,55 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - mixingRuleDefined = true; - super.setMixingRule(type); - mixRule = mixSelect.getMixingRule(type, this); + public EosMixingRulesInterface getMixingRule() { + return mixRule; + } + + /** {@inheritDoc} */ + @Override + public EosMixingRulesInterface getEosMixingRule() { + return mixRule; + } + + /** {@inheritDoc} */ + @Override + public void setMixingRule(MixingRuleTypeInterface mr) { + if (!(mr == null) && !EosMixingRuleType.class.isInstance(mr)) { + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "setMixingRule", "mr")); + } + mixingRuleType = mr; + if (mr == null) { + mixRule = null; + } else { + mixRule = mixSelect.getMixingRule(mr.getValue(), this); + } } /** {@inheritDoc} */ @Override public void setMixingRuleGEModel(String name) { - mixRule.setMixingRuleGEModel(name); - mixSelect.setMixingRuleGEModel(name); + if (mixRule != null) { + mixRule.setMixingRuleGEModel(name); + } + if (mixSelect != null) { + mixSelect.setMixingRuleGEModel(name); + } } /** {@inheritDoc} */ @Override - public void resetMixingRule(int type) { - mixingRuleDefined = true; - super.setMixingRule(type); - mixRule = mixSelect.resetMixingRule(type, this); + public void resetMixingRule(MixingRuleTypeInterface mr) { + if (!(mr == null) && !EosMixingRuleType.class.isInstance(mr)) { + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "resetMixingRule", "mr")); + } + mixingRuleType = mr; + if (mr == null) { + mixRule = null; + } else { + mixRule = mixSelect.getMixingRule(mr.getValue(), this); + } } /** @@ -492,6 +519,9 @@ public double calcBij(int compNumb, int j, PhaseInterface phase, double temperat @Override public double calcBi(int compNumb, PhaseInterface phase, double temperature, double pressure, int numbcomp) { + if (mixRule == null) { + return 0; + } return mixRule.calcBi(compNumb, phase, temperature, pressure, numbcomp); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseGE.java b/src/main/java/neqsim/thermo/phase/PhaseGE.java index 08fc3d1e5e..ed716fa9bb 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseGE.java +++ b/src/main/java/neqsim/thermo/phase/PhaseGE.java @@ -11,8 +11,10 @@ import neqsim.thermo.ThermodynamicConstantsInterface; import neqsim.thermo.ThermodynamicModelSettings; import neqsim.thermo.component.ComponentGEInterface; +import neqsim.thermo.mixingrule.EosMixingRuleType; import neqsim.thermo.mixingrule.EosMixingRules; import neqsim.thermo.mixingrule.EosMixingRulesInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -29,7 +31,7 @@ public abstract class PhaseGE extends Phase implements PhaseGEInterface { static Logger logger = LogManager.getLogger(PhaseGE.class); EosMixingRules mixSelect = new EosMixingRules(); - EosMixingRulesInterface mixRuleEos; + EosMixingRulesInterface mixRule; /** *

@@ -123,20 +125,38 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - mixingRuleDefined = true; - // NB! Ignores input type - super.setMixingRule(2); - mixRuleEos = mixSelect.getMixingRule(2, this); + public void setMixingRuleGEModel(String name) { + mixRule.setMixingRuleGEModel(name); + mixSelect.setMixingRuleGEModel(name); } /** {@inheritDoc} */ @Override - public void resetMixingRule(int type) { - mixingRuleDefined = true; - // NB! Ignores input type - super.setMixingRule(2); - mixRuleEos = mixSelect.resetMixingRule(2, this); + public EosMixingRulesInterface getMixingRule() { + return mixRule; + } + + /** {@inheritDoc} */ + @Override + public void setMixingRule(MixingRuleTypeInterface mr) { + if (!(mr == null) && !EosMixingRuleType.class.isInstance(mr)) { + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "setMixingRule", "mr")); + } + mixingRuleType = EosMixingRuleType.byValue(2); + mixRule = mixSelect.getMixingRule(mixingRuleType.getValue(), this); + } + + /** {@inheritDoc} */ + @Override + public void resetMixingRule(MixingRuleTypeInterface mr) { + if (!(mr == null) && !EosMixingRuleType.class.isInstance(mr)) { + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "resetMixingRule", "mr")); + } + // NB! Ignores input mr + mixingRuleType = EosMixingRuleType.byValue(2); + mixRule = mixSelect.resetMixingRule(mixingRuleType.getValue(), this); } /** {@inheritDoc} */ diff --git a/src/main/java/neqsim/thermo/phase/PhaseGENRTL.java b/src/main/java/neqsim/thermo/phase/PhaseGENRTL.java index 5a668c0bd8..9f79542192 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseGENRTL.java +++ b/src/main/java/neqsim/thermo/phase/PhaseGENRTL.java @@ -8,6 +8,8 @@ import neqsim.thermo.component.ComponentGEInterface; import neqsim.thermo.component.ComponentGeNRTL; +import neqsim.thermo.mixingrule.EosMixingRuleType; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; import neqsim.util.exception.IsNaNException; import neqsim.util.exception.TooManyIterationsException; @@ -24,7 +26,7 @@ public class PhaseGENRTL extends PhaseGE { private static final long serialVersionUID = 1000; double[][] alpha; - String[][] mixRule; + String[][] mixRuleString; double[][] intparam; double[][] Dij; double GE = 0.0; @@ -50,7 +52,7 @@ public PhaseGENRTL() {} public PhaseGENRTL(PhaseInterface phase, double[][] alpha, double[][] Dij, String[][] mixRule, double[][] intparam) { componentArray = new ComponentGeNRTL[alpha[0].length]; - this.mixRule = mixRule; + this.mixRuleString = mixRule; this.alpha = alpha; this.Dij = Dij; this.intparam = intparam; @@ -60,7 +62,7 @@ public PhaseGENRTL(PhaseInterface phase, double[][] alpha, double[][] Dij, Strin phase.getComponent(i).getNumberOfmoles(), phase.getComponent(i).getNumberOfMolesInPhase(), phase.getComponent(i).getComponentNumber()); } - setMixingRule(2); + setMixingRule(EosMixingRuleType.byValue(2)); } /** {@inheritDoc} */ @@ -72,11 +74,11 @@ public void addComponent(String name, double moles, double molesInPhase, int com /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); + public void setMixingRule(MixingRuleTypeInterface mr) { + super.setMixingRule(mr); this.intparam = mixSelect.getSRKbinaryInteractionParameters(); this.alpha = mixSelect.getNRTLalpha(); - this.mixRule = mixSelect.getClassicOrHV(); + this.mixRuleString = mixSelect.getClassicOrHV(); this.Dij = mixSelect.getNRTLDij(); } @@ -118,7 +120,7 @@ public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents, for (int i = 0; i < numberOfComponents; i++) { GE += phase.getComponent(i).getx() * Math.log(((ComponentGEInterface) componentArray[i]).getGamma(phase, numberOfComponents, - temperature, pressure, pt, alpha, Dij, intparam, mixRule)); + temperature, pressure, pt, alpha, Dij, intparam, mixRuleString)); } return R * temperature * numberOfMolesInPhase * GE; diff --git a/src/main/java/neqsim/thermo/phase/PhaseGENRTLmodifiedHV.java b/src/main/java/neqsim/thermo/phase/PhaseGENRTLmodifiedHV.java index 0e2e171503..999853fe31 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseGENRTLmodifiedHV.java +++ b/src/main/java/neqsim/thermo/phase/PhaseGENRTLmodifiedHV.java @@ -8,6 +8,7 @@ import neqsim.thermo.component.ComponentGEInterface; import neqsim.thermo.component.ComponentGENRTLmodifiedHV; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -30,7 +31,7 @@ public class PhaseGENRTLmodifiedHV extends PhaseGENRTL { *

*/ public PhaseGENRTLmodifiedHV() { - mixRuleEos = mixSelect.getMixingRule(1); + mixRule = mixSelect.getMixingRule(1); } /** @@ -91,12 +92,12 @@ public void addComponent(String name, double moles, double molesInPhase, int com /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); + public void setMixingRule(MixingRuleTypeInterface mr) { + super.setMixingRule(mr); this.DijT = mixSelect.getHVDijT(); this.intparam = mixSelect.getSRKbinaryInteractionParameters(); this.alpha = mixSelect.getHValpha(); - this.mixRule = mixSelect.getClassicOrHV(); + this.mixRuleString = mixSelect.getClassicOrHV(); this.Dij = mixSelect.getHVDij(); } @@ -104,7 +105,7 @@ public void setMixingRule(int type) { @Override public void setParams(PhaseInterface phase, double[][] alpha, double[][] Dij, double[][] DijT, String[][] mixRule, double[][] intparam) { - this.mixRule = mixRule; + this.mixRuleString = mixRule; this.alpha = alpha; this.Dij = Dij; type = 1; @@ -127,13 +128,13 @@ public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents, GE = 0.0; for (int i = 0; i < numberOfComponents; i++) { if (type == 0) { - GE += phase.getComponent(i).getx() - * Math.log(((ComponentGEInterface) componentArray[i]).getGamma(phase, - numberOfComponents, temperature, pressure, pt, alpha, Dij, intparam, mixRule)); + GE += phase.getComponent(i).getx() * Math + .log(((ComponentGEInterface) componentArray[i]).getGamma(phase, numberOfComponents, + temperature, pressure, pt, alpha, Dij, intparam, mixRuleString)); } else if (type == 1) { GE += phase.getComponent(i).getx() * Math .log(((ComponentGENRTLmodifiedHV) componentArray[i]).getGamma(phase, numberOfComponents, - temperature, pressure, pt, alpha, Dij, DijT, intparam, mixRule)); + temperature, pressure, pt, alpha, Dij, DijT, intparam, mixRuleString)); } } return R * phase.getTemperature() * phase.getNumberOfMolesInPhase() * GE; diff --git a/src/main/java/neqsim/thermo/phase/PhaseGENRTLmodifiedWS.java b/src/main/java/neqsim/thermo/phase/PhaseGENRTLmodifiedWS.java index 147ef5befa..329c781d6c 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseGENRTLmodifiedWS.java +++ b/src/main/java/neqsim/thermo/phase/PhaseGENRTLmodifiedWS.java @@ -2,6 +2,7 @@ import neqsim.thermo.component.ComponentGEInterface; import neqsim.thermo.component.ComponentGENRTLmodifiedWS; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -70,11 +71,11 @@ public PhaseGENRTLmodifiedWS(PhaseInterface phase, double[][] alpha, double[][] /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); + public void setMixingRule(MixingRuleTypeInterface mr) { + super.setMixingRule(mr); this.intparam = mixSelect.getWSintparam(); this.alpha = mixSelect.getNRTLalpha(); - this.mixRule = mixSelect.getClassicOrHV(); + this.mixRuleString = mixSelect.getClassicOrHV(); this.Dij = mixSelect.getNRTLDij(); } @@ -94,13 +95,13 @@ public double getExcessGibbsEnergy(PhaseInterface phase, int numberOfComponents, double GE = 0; for (int i = 0; i < numberOfComponents; i++) { if (type == 0) { - GE += phase.getComponent(i).getx() - * Math.log(((ComponentGEInterface) componentArray[i]).getGamma(phase, - numberOfComponents, temperature, pressure, pt, alpha, Dij, intparam, mixRule)); + GE += phase.getComponent(i).getx() * Math + .log(((ComponentGEInterface) componentArray[i]).getGamma(phase, numberOfComponents, + temperature, pressure, pt, alpha, Dij, intparam, mixRuleString)); } else if (type == 1) { GE += phase.getComponent(i).getx() * Math .log(((ComponentGENRTLmodifiedWS) componentArray[i]).getGamma(phase, numberOfComponents, - temperature, pressure, pt, alpha, Dij, DijT, intparam, mixRule)); + temperature, pressure, pt, alpha, Dij, DijT, intparam, mixRuleString)); } } return R * temperature * numberOfMolesInPhase * GE; diff --git a/src/main/java/neqsim/thermo/phase/PhaseGEUnifac.java b/src/main/java/neqsim/thermo/phase/PhaseGEUnifac.java index 6beed8960f..e1febda819 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseGEUnifac.java +++ b/src/main/java/neqsim/thermo/phase/PhaseGEUnifac.java @@ -8,6 +8,7 @@ import neqsim.thermo.atomelement.UNIFACgroup; import neqsim.thermo.component.ComponentGEUnifac; import neqsim.thermo.component.ComponentGEUniquac; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -68,8 +69,8 @@ public void addComponent(String name, double moles, double molesInPhase, int com /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); + public void setMixingRule(MixingRuleTypeInterface mr) { + super.setMixingRule(mr); if (!checkedGroups) { checkGroups(); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseGEUnifacPSRK.java b/src/main/java/neqsim/thermo/phase/PhaseGEUnifacPSRK.java index 2527ea9475..a5e01a71bd 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseGEUnifacPSRK.java +++ b/src/main/java/neqsim/thermo/phase/PhaseGEUnifacPSRK.java @@ -6,6 +6,8 @@ import neqsim.thermo.component.ComponentGEUnifac; import neqsim.thermo.component.ComponentGEUnifacPSRK; import neqsim.thermo.component.ComponentGEUniquac; +import neqsim.thermo.mixingrule.EosMixingRuleType; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -50,7 +52,7 @@ public PhaseGEUnifacPSRK(PhaseInterface phase, double[][] alpha, double[][] Dij, phase.getComponent(i).getNumberOfmoles(), phase.getComponent(i).getNumberOfMolesInPhase(), phase.getComponent(i).getComponentNumber()); } - this.setMixingRule(2); + this.setMixingRule(EosMixingRuleType.byValue(2)); } /** {@inheritDoc} */ @@ -62,8 +64,8 @@ public void addComponent(String name, double moles, double molesInPhase, int com /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); + public void setMixingRule(MixingRuleTypeInterface mr) { + super.setMixingRule(mr); if (!checkedGroups) { checkGroups(); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseGEUnifacUMRPRU.java b/src/main/java/neqsim/thermo/phase/PhaseGEUnifacUMRPRU.java index b695d54717..a3ad28c6cb 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseGEUnifacUMRPRU.java +++ b/src/main/java/neqsim/thermo/phase/PhaseGEUnifacUMRPRU.java @@ -6,6 +6,8 @@ import neqsim.thermo.component.ComponentGEUnifac; import neqsim.thermo.component.ComponentGEUnifacUMRPRU; import neqsim.thermo.component.ComponentGEUniquac; +import neqsim.thermo.mixingrule.EosMixingRuleType; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -58,7 +60,7 @@ public PhaseGEUnifacUMRPRU(PhaseInterface phase, double[][] alpha, double[][] Di phase.getComponent(i).getComponentNumber()); componentArray[i].setAttractiveTerm(phase.getComponent(i).getAttractiveTermNumber()); } - this.setMixingRule(2); + this.setMixingRule(EosMixingRuleType.byValue(2)); } /** @@ -113,8 +115,8 @@ public void addComponent(String name, double moles, double molesInPhase, int com /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); + public void setMixingRule(MixingRuleTypeInterface mr) { + super.setMixingRule(mr); if (!checkedGroups) { checkGroups(); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseGEWilson.java b/src/main/java/neqsim/thermo/phase/PhaseGEWilson.java index fcb0fa73c2..b23f2a144a 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseGEWilson.java +++ b/src/main/java/neqsim/thermo/phase/PhaseGEWilson.java @@ -2,6 +2,7 @@ import neqsim.thermo.ThermodynamicModelSettings; import neqsim.thermo.component.ComponentGEWilson; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; import neqsim.util.exception.IsNaNException; import neqsim.util.exception.TooManyIterationsException; @@ -77,8 +78,8 @@ public void addComponent(String name, double moles, double molesInPhase, int com /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); + public void setMixingRule(MixingRuleTypeInterface mr) { + super.setMixingRule(mr); } /** {@inheritDoc} */ diff --git a/src/main/java/neqsim/thermo/phase/PhaseHydrate.java b/src/main/java/neqsim/thermo/phase/PhaseHydrate.java index 4678a51c87..d43dba147d 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseHydrate.java +++ b/src/main/java/neqsim/thermo/phase/PhaseHydrate.java @@ -9,6 +9,8 @@ import neqsim.thermo.component.ComponentHydrate; import neqsim.thermo.component.ComponentHydrateGF; import neqsim.thermo.component.ComponentHydratePVTsim; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; +import neqsim.thermo.mixingrule.MixingRulesInterface; /** *

@@ -109,9 +111,33 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType setType(PhaseType.HYDRATE); } - /** {@inheritDoc} */ @Override - public void resetMixingRule(int type) {} + public MixingRulesInterface getMixingRule() { + return null; + } + + @Override + public void setMixingRuleGEModel(String name) {} + + /** + * {@inheritDoc} + * + *

+ * Not relevant for PhaseHydrate + *

+ */ + @Override + public void resetMixingRule(MixingRuleTypeInterface mr) {} + + /** + * {@inheritDoc} + * + *

+ * Not relevant for PhaseHydrate + *

+ */ + @Override + public void setMixingRule(MixingRuleTypeInterface mr) {} /** *

diff --git a/src/main/java/neqsim/thermo/phase/PhaseInterface.java b/src/main/java/neqsim/thermo/phase/PhaseInterface.java index 78f5e9019b..9372762d79 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseInterface.java +++ b/src/main/java/neqsim/thermo/phase/PhaseInterface.java @@ -12,6 +12,8 @@ import neqsim.thermo.ThermodynamicConstantsInterface; import neqsim.thermo.component.ComponentInterface; import neqsim.thermo.mixingrule.EosMixingRuleType; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; +import neqsim.thermo.mixingrule.MixingRulesInterface; import neqsim.thermo.system.SystemInterface; /** @@ -861,14 +863,34 @@ public default void setPhysicalProperties() { */ public void setAttractiveTerm(int i); + /** + *

+ * setMixingRule. + *

+ * + * @param mr a MixingRuleTypeInterface + */ + public void setMixingRule(MixingRuleTypeInterface mr); + + /** + *

+ * setMixingRule. + *

+ * + * @param mr a int + */ + public default void setMixingRule(int mr) { + setMixingRule(EosMixingRuleType.byValue(mr)); + } + /** *

* resetMixingRule. *

* - * @param type a int + * @param mr a int */ - public void resetMixingRule(int type); + public void resetMixingRule(MixingRuleTypeInterface mr); /** * Set the temperature of a phase. @@ -1247,15 +1269,6 @@ public default void setPhysicalProperties() { */ public void setNumberOfComponents(int k); - /** - *

- * setMixingRule. - *

- * - * @param type a int - */ - public void setMixingRule(int type); - /** *

* getComponents. @@ -1805,11 +1818,18 @@ public default void setPhysicalProperties() { public double getLogInfiniteDiluteFugacity(int k); /** - * Get EOS mixing rule type. + * Get mixing rule + * + * @return a MixingRulesInterface + */ + public MixingRulesInterface getMixingRule(); + + /** + * Get mixing rule type. * - * @return a EosMixingRuleType + * @return a MixingRuleTypeInterface */ - public EosMixingRuleType getEosMixingRuleType(); + public MixingRuleTypeInterface getMixingRuleType(); /** *

@@ -1911,22 +1931,13 @@ public default void setPhaseTypeName(String phaseTypeName) { /** *

- * Getter for property mixingRuleDefined. + * Check if mixing rule is defined. *

* - * @return a boolean + * @return Returns true if MixingRule is defined and false if not. */ public boolean isMixingRuleDefined(); - /** - *

- * Setter for property mixingRuleDefined. - *

- * - * @param mixingRuleDefined a boolean - */ - public void setMixingRuleDefined(boolean mixingRuleDefined); - /** *

* getActivityCoefficientSymetric. diff --git a/src/main/java/neqsim/thermo/phase/PhasePCSAFTa.java b/src/main/java/neqsim/thermo/phase/PhasePCSAFTa.java index b658431ce9..95d65b4f0e 100644 --- a/src/main/java/neqsim/thermo/phase/PhasePCSAFTa.java +++ b/src/main/java/neqsim/thermo/phase/PhasePCSAFTa.java @@ -6,6 +6,7 @@ import neqsim.thermo.component.ComponentPCSAFTa; import neqsim.thermo.mixingrule.CPAMixingRules; import neqsim.thermo.mixingrule.CPAMixingRulesInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -60,9 +61,10 @@ public PhasePCSAFTa clone() { /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); - // NB! Ignores input type + public void setMixingRule(MixingRuleTypeInterface mr) { + // NB! Sets EOS mixing rule in parent class PhaseEos + super.setMixingRule(mr); + // NB! Ignores input mr, uses CPA cpamix = cpaSelect.getMixingRule(3, this); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java index 4af0bdb7a5..ce0ac31d33 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java +++ b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java @@ -10,6 +10,7 @@ import neqsim.thermo.component.ComponentSrkCPA; import neqsim.thermo.mixingrule.CPAMixingRules; import neqsim.thermo.mixingrule.CPAMixingRulesInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -490,9 +491,10 @@ public void initCPAMatrix(int type) { /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); - // NB! Ignores input type + public void setMixingRule(MixingRuleTypeInterface mr) { + // NB! Sets EOS mixing rule in parent class + super.setMixingRule(mr); + // NB! Ignores input mr, uses CPA cpamix = cpaSelect.getMixingRule(1, this); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java index 6d4cc06b77..7e5a7e6211 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java +++ b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java @@ -9,6 +9,7 @@ import neqsim.thermo.component.ComponentSrkCPA; import neqsim.thermo.mixingrule.CPAMixingRules; import neqsim.thermo.mixingrule.CPAMixingRulesInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -532,9 +533,10 @@ public void initCPAMatrix(int type) { /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); - // NB! Ignores input type + public void setMixingRule(MixingRuleTypeInterface mr) { + // NB! Sets EOS mixing rule in parent class + super.setMixingRule(mr); + // NB! Ignores input mr, uses CPA cpamix = cpaSelect.getMixingRule(1, this); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseUMRCPA.java b/src/main/java/neqsim/thermo/phase/PhaseUMRCPA.java index c7f31e1f06..a1f5e2f791 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseUMRCPA.java +++ b/src/main/java/neqsim/thermo/phase/PhaseUMRCPA.java @@ -11,6 +11,7 @@ import neqsim.thermo.component.ComponentUMRCPA; import neqsim.thermo.mixingrule.CPAMixingRules; import neqsim.thermo.mixingrule.CPAMixingRulesInterface; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; /** *

@@ -491,9 +492,10 @@ public void initCPAMatrix(int type) { /** {@inheritDoc} */ @Override - public void setMixingRule(int type) { - super.setMixingRule(type); - // NB! Ignores input type + public void setMixingRule(MixingRuleTypeInterface mr) { + // NB! Sets EOS mixing rule in parent class + super.setMixingRule(mr); + // NB! Ignores input mr, uses CPA cpamix = cpaSelect.getMixingRule(1, this); } diff --git a/src/main/java/neqsim/thermo/system/SystemInterface.java b/src/main/java/neqsim/thermo/system/SystemInterface.java index 0236373240..88c004b13e 100644 --- a/src/main/java/neqsim/thermo/system/SystemInterface.java +++ b/src/main/java/neqsim/thermo/system/SystemInterface.java @@ -8,6 +8,7 @@ import neqsim.thermo.characterization.WaxModelInterface; import neqsim.thermo.component.ComponentInterface; import neqsim.thermo.mixingrule.EosMixingRuleType; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; import neqsim.thermo.phase.PhaseInterface; import neqsim.thermo.phase.PhaseType; import neqsim.util.ExcludeFromJacocoGeneratedReport; @@ -480,6 +481,8 @@ public default String[][] calcResultTable() { /** * method to read pure component and interaction parameters from the NeqSim database and create * temporary tables with parameters for active fluid. + * + * NB! Resets the mixing rule of each phase. * * @param reset If reset is set to true, new temporary tables with parameters for the added * components will be created. When parameters are needed (eg. when adding components or @@ -1061,9 +1064,10 @@ public default double getGamma2() { * getMixingRule. *

* - * @return a int + * @return A MixingRuleTypeInterface */ - public int getMixingRule(); + public MixingRuleTypeInterface getMixingRule(); + /** *

@@ -2262,9 +2266,9 @@ public void setImplementedTemperatureDeriativesofFugacity( /** * method to set mixing rule used for the fluid. * - * @param emrt EosMixingRuleTypes enum + * @param emrt MixingRuleTypeInterface enum */ - public void setMixingRule(EosMixingRuleType emrt); + public void setMixingRule(MixingRuleTypeInterface emrt); /** * method to set mixing rule used for the fluid. diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index 000c58cee1..4a7a40f013 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -20,7 +20,7 @@ import neqsim.thermo.characterization.WaxCharacterise; import neqsim.thermo.characterization.WaxModelInterface; import neqsim.thermo.component.ComponentInterface; -import neqsim.thermo.mixingrule.EosMixingRuleType; +import neqsim.thermo.mixingrule.MixingRuleTypeInterface; import neqsim.thermo.phase.PhaseEosInterface; import neqsim.thermo.phase.PhaseHydrate; import neqsim.thermo.phase.PhaseInterface; @@ -110,7 +110,7 @@ public abstract class SystemThermo implements SystemInterface { /** Maximum allowed number of phases. */ public int maxNumberOfPhases = 2; - private EosMixingRuleType eosMixingRuleType = EosMixingRuleType.byValue(1); + private MixingRuleTypeInterface mixingRuleType; protected String modelName = "Default"; protected boolean multiPhaseCheck = false; @@ -1406,10 +1406,9 @@ public void createDatabase(boolean reset) { + names + ") AND comp2 IN (" + names + ")"); database.execute("delete FROM intertemp WHERE comp1=comp2"); } - // System.out.println("ok " + names); for (int phaseNum = 0; phaseNum < maxNumberOfPhases; phaseNum++) { - getPhase(phaseNum).setMixingRuleDefined(false); + getPhase(phaseNum).setMixingRule(null); } for (int i = 0; i < numberOfComponents; i++) { @@ -2434,8 +2433,8 @@ public int getMaxNumberOfPhases() { /** {@inheritDoc} */ @Override - public int getMixingRule() { - return eosMixingRuleType.getValue(); + public MixingRuleTypeInterface getMixingRule() { + return mixingRuleType; } /** {@inheritDoc} */ @@ -4420,14 +4419,14 @@ public void setMaxNumberOfPhases(int maxNumberOfPhases) { /** {@inheritDoc} */ @Override - public final void setMixingRule(EosMixingRuleType emrt) { - eosMixingRuleType = emrt; + public final void setMixingRule(MixingRuleTypeInterface mr) { + mixingRuleType = mr; if (numberOfPhases < 4) { resetPhysicalProperties(); } for (int i = 0; i < maxNumberOfPhases; i++) { if (isPhase(i)) { - getPhase(i).setMixingRule(emrt.getValue()); + getPhase(i).setMixingRule(mr); getPhase(i).initPhysicalProperties(); } } @@ -4657,7 +4656,7 @@ public void setMultiPhaseCheck(boolean multiPhaseCheck) { setMaxNumberOfPhases(3); if (phaseArray[1] != null) { phaseArray[2] = phaseArray[1].clone(); - phaseArray[2].resetMixingRule(phaseArray[0].getEosMixingRuleType().getValue()); + phaseArray[2].resetMixingRule(phaseArray[0].getMixingRuleType()); phaseArray[2].resetPhysicalProperties(); phaseArray[2].initPhysicalProperties(); } diff --git a/src/test/java/neqsim/thermo/phase/PhasePCSAFTRahmatTest.java b/src/test/java/neqsim/thermo/phase/PhasePCSAFTRahmatTest.java index 93611ddb4b..20ce968506 100644 --- a/src/test/java/neqsim/thermo/phase/PhasePCSAFTRahmatTest.java +++ b/src/test/java/neqsim/thermo/phase/PhasePCSAFTRahmatTest.java @@ -17,8 +17,8 @@ void setUp() { testSystem = new SystemPCSAFT(150.0, 10.0); testSystem.addComponent("methane", 100.0); testSystem.addComponent("n-hexane", 1000.0001); - testSystem.setMixingRule(1); testSystem.createDatabase(true); + testSystem.setMixingRule(1); testSystem.init(0); testSystem.init(3); diff --git a/src/test/java/neqsim/thermo/system/SystemThermoTest.java b/src/test/java/neqsim/thermo/system/SystemThermoTest.java index ff131185c0..edc21d104a 100644 --- a/src/test/java/neqsim/thermo/system/SystemThermoTest.java +++ b/src/test/java/neqsim/thermo/system/SystemThermoTest.java @@ -152,17 +152,17 @@ void TestMixingRuleTypes() { EosMixingRuleType[] mrNum = EosMixingRuleType.values(); for (EosMixingRuleType mixingRule : mrNum) { testSystem.setMixingRule(mixingRule.getValue()); - assertEquals(mixingRule.getValue(), testSystem.getMixingRule()); + assertEquals(mixingRule, testSystem.getMixingRule()); } for (EosMixingRuleType mixingRule : mrNum) { testSystem.setMixingRule(mixingRule); - assertEquals(mixingRule.getValue(), testSystem.getMixingRule()); + assertEquals(mixingRule, testSystem.getMixingRule()); } for (EosMixingRuleType mixingRule : mrNum) { testSystem.setMixingRule(mixingRule.name()); - assertEquals(mixingRule.getValue(), testSystem.getMixingRule()); + assertEquals(mixingRule, testSystem.getMixingRule()); } } } diff --git a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java index 84c392a9d5..b246a654de 100644 --- a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java +++ b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java @@ -279,7 +279,7 @@ public void checkPhaseEnvelope2() throws Exception { /** *

- * checkPhaseEnvelope2. + * testPseudoComptest. *

* * @throws Exception