From adf3bfc069cb8334ac6c32a7bcb8256d5e0253bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:47:49 +0100 Subject: [PATCH] refact: reorder methods system --- checkstyle_neqsim.xml | 2 +- .../neqsim/thermo/system/SystemDuanSun.java | 26 - .../neqsim/thermo/system/SystemInterface.java | 2386 +++--- .../neqsim/thermo/system/SystemPCSAFT.java | 28 +- .../thermo/system/SystemProperties.java | 24 +- .../neqsim/thermo/system/SystemSrkCPA.java | 20 +- .../neqsim/thermo/system/SystemThermo.java | 6524 ++++++++--------- 7 files changed, 4492 insertions(+), 4518 deletions(-) diff --git a/checkstyle_neqsim.xml b/checkstyle_neqsim.xml index dc35055c5..6d83f75c4 100644 --- a/checkstyle_neqsim.xml +++ b/checkstyle_neqsim.xml @@ -232,7 +232,7 @@ - + diff --git a/src/main/java/neqsim/thermo/system/SystemDuanSun.java b/src/main/java/neqsim/thermo/system/SystemDuanSun.java index e5ece8c65..1b2c88373 100644 --- a/src/main/java/neqsim/thermo/system/SystemDuanSun.java +++ b/src/main/java/neqsim/thermo/system/SystemDuanSun.java @@ -3,7 +3,6 @@ import neqsim.thermo.phase.PhaseDuanSun; import neqsim.thermo.phase.PhasePureComponentSolid; import neqsim.thermo.phase.PhaseSrkEos; -import neqsim.thermodynamicOperations.ThermodynamicOperations; /** * This class defines a thermodynamic system using the Duan Sun method used for CO2. @@ -82,29 +81,4 @@ public SystemDuanSun clone() { return clonedSystem; } - - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - SystemInterface fluid1 = new SystemSrkCPA(298.15, 10.0); - - fluid1.addComponent("CO2", 1.0); - fluid1.addComponent("nitrogen", 1.0); - fluid1.addComponent("water", 1.0); - fluid1.addComponent("NaCl", 1.0); - fluid1.setMixingRule(2); - - try { - ThermodynamicOperations testOps = new ThermodynamicOperations(fluid1); - testOps.TPflash(); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - } - fluid1.display(); - } } diff --git a/src/main/java/neqsim/thermo/system/SystemInterface.java b/src/main/java/neqsim/thermo/system/SystemInterface.java index 784d749c8..1ffcde5d9 100644 --- a/src/main/java/neqsim/thermo/system/SystemInterface.java +++ b/src/main/java/neqsim/thermo/system/SystemInterface.java @@ -18,77 +18,130 @@ */ public interface SystemInterface extends Cloneable, java.io.Serializable { /** - *

- * saveFluid. - *

+ * return two fluid added as a new fluid. * - * @param id a int + * @param addFluid1 first fluid to add + * @param addFluid2 second fluid o add + * @return new fluid */ - public void saveFluid(int id); + public static SystemInterface addFluids(SystemInterface addFluid1, SystemInterface addFluid2) { + SystemInterface newFluid = addFluid1.clone(); + newFluid.addFluid(addFluid2); + return newFluid; + } /** *

- * saveFluid. + * addCapeOpenProperty. *

* - * @param id a int - * @param text a {@link java.lang.String} object + * @param propertyName a {@link java.lang.String} object */ - public void saveFluid(int id, String text); + public void addCapeOpenProperty(String propertyName); /** *

- * getComponentNameTag. + * addCharacterized. *

* - * @return a {@link java.lang.String} object + * @param charNames an array of {@link java.lang.String} objects + * @param charFlowrate an array of {@link double} objects + * @param molarMass an array of {@link double} objects + * @param relativedensity an array of {@link double} objects */ - public String getComponentNameTag(); + public void addCharacterized(String[] charNames, double[] charFlowrate, double[] molarMass, + double[] relativedensity); /** - *

- * setComponentNameTag. - *

+ * add a component to a fluid. If component already exists, the moles will be added to the + * existing component. * - * @param nameTag a {@link java.lang.String} object + * @param inComponent Component object to add. */ - public void setComponentNameTag(String nameTag); + public void addComponent(ComponentInterface inComponent); /** *

- * setComponentNameTagOnNormalComponents. + * addComponent. *

* - * @param nameTag a {@link java.lang.String} object + * @param index Component number to add + * @param moles number of moles (per second) of the component to be added to the fluid */ - public void setComponentNameTagOnNormalComponents(String nameTag); + public void addComponent(int index, double moles); /** *

- * addPhaseFractionToPhase. + * addComponent. *

* - * @param fraction a double - * @param specification a {@link java.lang.String} object - * @param fromPhaseName a {@link java.lang.String} object - * @param toPhaseName a {@link java.lang.String} object + * @param index Component number to add + * @param moles number of moles (per second) of the component to be added to the fluid + * @param phaseNumber Number of the phase to add the component to */ - public void addPhaseFractionToPhase(double fraction, String specification, String fromPhaseName, - String toPhaseName); + public void addComponent(int index, double moles, int phaseNumber); + + /** + * add a component to a fluid with no moles. + * + * @param name Name of the component to add. See NeqSim database for component in the database. + */ + public default void addComponent(String name) { + addComponent(name, 0); + } + + /** + * add a component to a fluid. If component already exists, the moles will be added to the + * existing component. + * + * @param name Name of the component to add. See NeqSim database for component in the database. + * @param moles number of moles (per second) of the component to be added to the fluid + */ + public void addComponent(String name, double moles); /** *

- * addPhaseFractionToPhase. + * addComponent. *

* - * @param fraction a double - * @param specification a {@link java.lang.String} object - * @param specifiedStream a {@link java.lang.String} object - * @param fromPhaseName a {@link java.lang.String} object - * @param toPhaseName a {@link java.lang.String} object + * @param name Name of the component to add. See NeqSim database for component in the database. + * @param moles number of moles (per second) of the component to be added to the fluid + * @param TC Critical temperature + * @param PC Critical pressure + * @param acs a double */ - public void addPhaseFractionToPhase(double fraction, String specification, String specifiedStream, - String fromPhaseName, String toPhaseName); + public void addComponent(String name, double moles, double TC, double PC, double acs); + + /** + * add a component to a fluid. If component already exists, the moles will be added to the + * existing component. + * + * @param name Name of the component to add. See NeqSim database for component in the database. + * @param moles number of moles (per second) of the component to be added to the fluid + * @param phaseNumber Number of the phase to add the component to + */ + public void addComponent(String name, double moles, int phaseNumber); + + /** + * add a component to a fluid. If component already exists, the amount will be added to the + * existing component. + * + * @param name Name of the component to add. See NeqSim database for component in the database. + * @param value The amount. + * @param unitName the unit of rate (sported units are kg/sec, mol/sec, Nlitre/min, kg/hr, + * Sm^3/hr, Sm^3/day, MSm^3/day .. + */ + public void addComponent(String name, double value, String unitName); + + /** + * add a component to a fluid. I component already exists, it will be added to the component + * + * @param name Name of the component to add. See NeqSim database for component in the database. + * @param value rate of the component to add to the fluid + * @param unitName the unit of the flow rate (eg. mol/sec, kg/sec, etc.) + * @param phaseNumber Number of the phase to add the component to + */ + public void addComponent(String name, double value, String unitName, int phaseNumber); /** * Add named components to a System. Does nothing if components already exist in System. @@ -118,936 +171,915 @@ public default void addComponents(String[] names, double[] moles) { /** *

- * renameComponent. + * addFluid. *

* - * @param oldName a {@link java.lang.String} object - * @param newName a {@link java.lang.String} object + * @param addSystem a {@link neqsim.thermo.system.SystemInterface} object + * @return SystemInterface */ - public void renameComponent(String oldName, String newName); + public SystemInterface addFluid(SystemInterface addSystem); /** *

- * calcResultTable. + * addFluid. *

* - * @return an array of {@link java.lang.String} objects + * @param addSystem a {@link neqsim.thermo.system.SystemInterface} object + * @param phase phase number of phase to add fluid to + * @return SystemInterface */ - public default String[][] calcResultTable() { - return createTable(""); - } + public SystemInterface addFluid(SystemInterface addSystem, int phase); /** *

- * getKinematicViscosity. + * addGasToLiquid. *

* - * @return a double + * @param fraction a double */ - public double getKinematicViscosity(); + public void addGasToLiquid(double fraction); /** - * method to return kinematic viscosity in a specified unit. + *

+ * addLiquidToGas. + *

* - * @param unit Supported units are m2/sec - * @return kinematic viscosity in specified unit + * @param fraction a double */ - public double getKinematicViscosity(String unit); + public void addLiquidToGas(double fraction); /** *

- * Get number of components added to System. + * addCharacterized. *

* - * @return the number of components in System. + * @param charNames an array of {@link java.lang.String} objects + * @param charFlowrate an array of {@link double} objects + * @param molarMass an array of {@link double} objects + * @param relativedensity an array of {@link double} objects + * @param lastIsPlusFraction True if last fraction is a Plus fraction */ - public int getNumberOfComponents(); + public void addOilFractions(String[] charNames, double[] charFlowrate, double[] molarMass, + double[] relativedensity, boolean lastIsPlusFraction); /** - * This method is used to set the total molar composition of a plus fluid. The total flow rate - * will be kept constant. The input mole fractions will be normalized. + *

+ * addCharacterized. + *

* - * @param molefractions is a double array taking the molar fraction of the components in the - * fluid. THe last molfraction is the mole fraction of the plus component + * @param charNames an array of {@link java.lang.String} objects + * @param charFlowrate an array of {@link double} objects + * @param molarMass an array of {@link double} objects + * @param relativedensity an array of {@link double} objects + * @param lastIsPlusFraction True if last fraction is a Plus fraction + * @param lumpComponents True if component should be lumped + * @param numberOfPseudoComponents number of pseudo components */ - public void setMolarCompositionPlus(double[] molefractions); + public void addOilFractions(String[] charNames, double[] charFlowrate, double[] molarMass, + double[] relativedensity, boolean lastIsPlusFraction, boolean lumpComponents, + int numberOfPseudoComponents); /** - * This method is used to set the total molar composition of a characterized fluid. The total flow - * rate will be kept constant. The input mole fractions will be normalized. - * - * @param molefractions is a double array taking the molar fraction of the components in the - * fluid. THe last fraction in the array is the total molefraction of the characterized - * components. + * Add phase to SystemInterface object. */ - public void setMolarCompositionOfPlusFluid(double[] molefractions); + public void addPhase(); /** - * method to return exergy defined as (h1-T0*s1) in a unit Joule. + *

+ * addPhaseFractionToPhase. + *

* - * @param temperatureOfSurroundings in Kelvin - * @return a double + * @param fraction a double + * @param specification a {@link java.lang.String} object + * @param fromPhaseName a {@link java.lang.String} object + * @param toPhaseName a {@link java.lang.String} object */ - public double getExergy(double temperatureOfSurroundings); + public void addPhaseFractionToPhase(double fraction, String specification, String fromPhaseName, + String toPhaseName); /** - * method to return exergy in a specified unit. + *

+ * addPhaseFractionToPhase. + *

* - * @param temperatureOfSurroundings in Kelvin - * @param exergyUnit a {@link java.lang.String} object - * @return exergy in specified unit + * @param fraction a double + * @param specification a {@link java.lang.String} object + * @param specifiedStream a {@link java.lang.String} object + * @param fromPhaseName a {@link java.lang.String} object + * @param toPhaseName a {@link java.lang.String} object */ - public double getExergy(double temperatureOfSurroundings, String exergyUnit); + public void addPhaseFractionToPhase(double fraction, String specification, String specifiedStream, + String fromPhaseName, String toPhaseName); /** - * method to get the Joule Thomson Coefficient of a system. Based on a phase mole fraction basis - * average + *

+ * addPlusFraction. + *

* - * @return Joule Thomson coefficient in K/bar + * @param componentName a {@link java.lang.String} object + * @param numberOfMoles a double + * @param molarMass a double + * @param density a double */ - public double getJouleThomsonCoefficient(); + public void addPlusFraction(String componentName, double numberOfMoles, double molarMass, + double density); /** - * method to get the Joule Thomson Coefficient of a system. Based on a phase mole fraction basis - * average. + *

+ * addSalt. + *

* - * @param unit Supported units are K/bar, C/bar - * @return Joule Thomson coefficient in specified unit + * @param componentName a {@link java.lang.String} object + * @param value a double */ - public double getJouleThomsonCoefficient(String unit); + public void addSalt(String componentName, double value); /** - * method to return mass of fluid. + *

+ * addSolidComplexPhase. + *

* - * @param unit Supported units are kg, gr, tons - * @return mass in specified unit + * @param type a {@link java.lang.String} object */ - public double getMass(String unit); + public void addSolidComplexPhase(String type); /** - *

- * Get sum of mole fractions for all components. NB! init(0) must be called first. - *

+ * method to add true boiling point fraction. * - * @return a double + * @param componentName selected name of the component to be added + * @param numberOfMoles number of moles to be added + * @param molarMass molar mass of the component in kg/mol + * @param density density of the component in g/cm3 */ - public double getMoleFractionsSum(); + public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, + double density); /** - * method to get the speed of sound of a system. The sound speed is implemented based on a molar - * average over the phases + *

+ * addTBPfraction. + *

* - * @param unit Supported units are m/s, km/h - * @return speed of sound in m/s + * @param componentName a {@link java.lang.String} object + * @param numberOfMoles a double + * @param molarMass a double + * @param density a double + * @param criticalTemperature a double + * @param criticalPressure a double + * @param acentricFactor a double */ - public double getSoundSpeed(String unit); + public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, + double density, double criticalTemperature, double criticalPressure, double acentricFactor); /** - * method to get the speed of sound of a system. The sound speed is implemented based on a molar - * average over the phases + * Add to component names. * - * @return speed of sound in m/s + * @param name Component name to add */ - public double getSoundSpeed(); + public void addToComponentNames(String name); /** *

- * removePhaseKeepTotalComposition. + * Getter for property allowPhaseShift. *

* - * @param specPhase a int - */ - public void removePhaseKeepTotalComposition(int specPhase); - - /** - * Init physical properties for all phases and interfaces. + * @return a boolean */ - public void initPhysicalProperties(); + public boolean allowPhaseShift(); /** - * Calculates physical properties of type propertyName. + *

+ * Setter for property allowPhaseShift. + *

* - * @param propertyName a {@link java.lang.String} object + * @param allowPhaseShift a boolean */ - public void initPhysicalProperties(String propertyName); + public void allowPhaseShift(boolean allowPhaseShift); /** - * Calculates thermodynamic and physical properties of a fluid using initThermoProperties() and - * initPhysicalProperties(). + *

+ * autoSelectMixingRule. + *

*/ - public void initProperties(); + public void autoSelectMixingRule(); /** - * return two fluid added as a new fluid. + *

+ * autoSelectModel. + *

* - * @param addFluid1 first fluid to add - * @param addFluid2 second fluid o add - * @return new fluid + * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public static SystemInterface addFluids(SystemInterface addFluid1, SystemInterface addFluid2) { - SystemInterface newFluid = addFluid1.clone(); - newFluid.addFluid(addFluid2); - return newFluid; - } - - /** - * method to return interfacial tension between two phases. - * - * @param phase1 phase type of phase1 as string (valid phases are gas, oil, aqueous) - * @param phase2 phase type of phase2 as string (valid phases are gas, oil, aqueous) - * @return interfacial tension with unit N/m. If one or both phases does not exist - the method - * will return NaN + public SystemInterface autoSelectModel(); + + /** + *

+ * calc_x_y. + *

*/ - public double getInterfacialTension(String phase1, String phase2); + public void calc_x_y(); /** - * method to return interfacial tension between two phases. - * - * @param phase1 phase number of phase1 - * @param phase2 phase number of phase2 - * @return interfacial tension with unit N/m + *

+ * calc_x_y_nonorm. + *

*/ - public double getInterfacialTension(int phase1, int phase2); + public void calc_x_y_nonorm(); /** *

- * getInterfacialTension. + * calcBeta. For simple gas liquid systems. *

* - * @param phase1 phase number of phase1 - * @param phase2 phase number of phase2 - * @param unit a {@link java.lang.String} object - * @return interfacial tension with specified unit + * @return Beta Mole fraction contained in the heaviest phase, i.e., liquid phase. + * @throws neqsim.util.exception.IsNaNException if any. + * @throws neqsim.util.exception.TooManyIterationsException if any. */ - public double getInterfacialTension(int phase1, int phase2, String unit); + public double calcBeta() + throws neqsim.util.exception.IsNaNException, neqsim.util.exception.TooManyIterationsException; /** - * method to return heat capacity ratio calculated as Cp/(Cp-R). + *

+ * calcHenrysConstant. + *

* - * @return kappa + * @param component a {@link java.lang.String} object + * @return a double */ - public default double getGamma2() { - return getCp() / (getCp() - ThermodynamicConstantsInterface.R * getTotalNumberOfMoles()); - } + public double calcHenrysConstant(String component); /** - * method to return heat capacity ratio/adiabatic index/Poisson constant. - * - * @return kappa + *

+ * calcInterfaceProperties. + *

*/ - public double getGamma(); + public void calcInterfaceProperties(); /** - * method to return fluid volume. + *

+ * calcKIJ. + *

* - * @return volume in unit m3*1e5 + * @param ok a boolean */ - public double getVolume(); + public void calcKIJ(boolean ok); /** - * method to return fluid volume. + *

+ * calcResultTable. + *

* - * @param unit Supported units are m3, litre, m3/kg, m3/mol - * @return volume in specified unit + * @return an array of {@link java.lang.String} objects */ - public double getVolume(String unit); + public default String[][] calcResultTable() { + return createTable(""); + } /** - * method to return flow rate of fluid. + *

+ * changeComponentName. + *

* - * @param flowunit Supported units are kg/sec, kg/min, kg/hr, kg/day, m3/sec, m3/min, m3/hr, - * idSm3/hr, Sm3/sec, Sm3/hr, Sm3/day, MSm3/day, mole/sec, mole/min, mole/hr - * @return flow rate in specified unit + * @param name a {@link java.lang.String} object + * @param newName a {@link java.lang.String} object */ - public double getFlowRate(String flowunit); + public void changeComponentName(String name, String newName); /** - * method to set the pressure of a fluid (same pressure for all phases). + *

+ * checkStability. + *

* - * @param pres pressure in unit bara (absolute pressure in bar) + * @return a boolean */ - public void setPressure(double pres); + public boolean checkStability(); /** - * method to set the pressure of a fluid (same pressure for all phases). + *

+ * checkStability. + *

* - * @param newPressure in specified unit - * @param unit unit can be bar, bara, barg or atm + * @param val a boolean */ - public void setPressure(double newPressure, String unit); + public void checkStability(boolean val); /** *

- * method to set the temperature of a fluid (same temperature for all phases). + * chemicalReactionInit. *

- * - * @param temp a double */ - public void setTemperature(double temp); + public void chemicalReactionInit(); /** *

- * setTemperature. + * clearAll. *

- * - * @param newTemperature a double - * @param phaseNumber a int */ - public void setTemperature(double newTemperature, int phaseNumber); + public void clearAll(); /** - * method to set the temperature of a fluid (same temperature for all phases). + *

+ * clone. + *

* - * @param newTemperature in specified unit - * @param unit unit can be C or K (Celsius or Kelvin) + * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public void setTemperature(double newTemperature, String unit); + public SystemInterface clone(); /** - * method to return the volume fraction of a phase note: without Peneloux volume correction. + * method to read pure component and interaction parameters from the NeqSim database and create + * temporary tables with parameters for active fluid. * - * @param phaseNumber number of the phase to get volume fraction for - * @return volume fraction + * @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 + * when setting a mixing rule) it will try to find them in the temporary tables first eg. + * COMPTEMP (for pure component parameters) and INTERTEMP (for interaction parameters). If + * reset is set to false it will not create new temporary tables. If a fluid is created + * with the same components many times, performance improvements will be obtained, if + * temporary tables are created the first time (reset=true), and then the same tables is + * used when creating new fluids with the same temporary tables (reset=false) */ - public double getVolumeFraction(int phaseNumber); + public void createDatabase(boolean reset); /** - * method to return the volume fraction of a phase note: with Peneloux volume correction. + *

+ * createTable. + *

* - * @param phaseNumber number of the phase to get volume fraction for - * @return volume fraction + * @param name a {@link java.lang.String} object + * @return an array of {@link java.lang.String} objects */ - public double getCorrectedVolumeFraction(int phaseNumber); + public String[][] createTable(String name); /** *

- * getHeatOfVaporization. + * deleteFluidPhase. *

* - * @return a double + * @param phase a int */ - public double getHeatOfVaporization(); + public void deleteFluidPhase(int phase); /** - * method to return internal energy (U) in unit J. - * - * @return internal energy in unit Joule (J) + *

+ * display. + *

*/ - public double getInternalEnergy(); + public default void display() { + display(this.getFluidName()); + } /** - * method to return internal energy (U) in a specified unit. + *

+ * display. + *

* - * @param unit Supported units are 'J', 'J/mol', 'J/kg' and 'kJ/kg' - * @return enthalpy in specified unit + * @param name a {@link java.lang.String} object */ - public double getInternalEnergy(String unit); + public void display(String name); /** *

- * isForcePhaseTypes. + * Getter for property multiPhaseCheck. *

* * @return a boolean */ - public boolean isForcePhaseTypes(); + public boolean doMultiPhaseCheck(); /** *

- * setForcePhaseTypes. + * doSolidPhaseCheck. *

* - * @param forcePhaseTypes a boolean + * @return a boolean */ - public void setForcePhaseTypes(boolean forcePhaseTypes); + public boolean doSolidPhaseCheck(); - /** - * Set the flow rate (moles) of all components to zero. - */ - public void setEmptyFluid(); + /** {@inheritDoc} */ + @Override + public boolean equals(Object o); /** *

- * setMolarFlowRates. + * Getter for property beta. + * + * Gets value for heaviest phase. *

* - * @param moles an array of {@link double} objects + * @return Beta value */ - public void setMolarFlowRates(double[] moles); + public double getBeta(); /** *

- * setComponentNames. + * Getter for property beta for a specific phase. *

* - * @param componentNames an array of {@link java.lang.String} objects + * @param phase Number of phase to get beta for. + * @return Beta value for */ - public void setComponentNames(String[] componentNames); + public double getBeta(int phase); /** *

- * calc_x_y_nonorm. + * getCapeOpenProperties10. *

+ * + * @return an array of {@link java.lang.String} objects */ - public void calc_x_y_nonorm(); + public String[] getCapeOpenProperties10(); /** *

- * saveObjectToFile. + * getCapeOpenProperties11. *

* - * @param filePath a {@link java.lang.String} object - * @param fluidName a {@link java.lang.String} object + * @return an array of {@link java.lang.String} objects */ - public void saveObjectToFile(String filePath, String fluidName); + public String[] getCapeOpenProperties11(); /** *

- * readObjectFromFile. + * getCASNumbers. *

* - * @param filePath a {@link java.lang.String} object - * @param fluidName a {@link java.lang.String} object - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @return an array of {@link java.lang.String} objects */ - public SystemInterface readObjectFromFile(String filePath, String fluidName); + public String[] getCASNumbers(); /** *

- * getLiquidVolume. + * Getter for property characterization. *

* - * @return a double + * @return a {@link neqsim.thermo.characterization.Characterise} object */ - public double getLiquidVolume(); + public neqsim.thermo.characterization.Characterise getCharacterization(); /** *

- * resetPhysicalProperties. + * getChemicalReactionOperations. *

+ * + * @return a {@link neqsim.chemicalReactions.ChemicalReactionOperations} object */ - public void resetPhysicalProperties(); + public ChemicalReactionOperations getChemicalReactionOperations(); /** *

- * phaseToSystem. + * getCompFormulaes. *

* - * @param phaseNumber a int - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @return an array of {@link java.lang.String} objects */ - public SystemInterface phaseToSystem(int phaseNumber); + public String[] getCompFormulaes(); /** *

- * phaseToSystem. + * getCompIDs. *

* - * @param newPhase a {@link neqsim.thermo.phase.PhaseInterface} object - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @return an array of {@link java.lang.String} objects */ - public SystemInterface phaseToSystem(PhaseInterface newPhase); + public String[] getCompIDs(); /** - *

- * phaseToSystem. - *

+ * Get names of all components in System. * - * @param phaseName a {@link java.lang.String} object - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @return an array of {@link java.lang.String} objects */ - public SystemInterface phaseToSystem(String phaseName); + public String[] getCompNames(); /** *

- * phaseToSystem. + * Get component by index. *

* - * @param phaseNumber1 a int - * @param phaseNumber2 a int - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @param i Component index + * @return a {@link neqsim.thermo.component.ComponentInterface} object */ - public SystemInterface phaseToSystem(int phaseNumber1, int phaseNumber2); + public default ComponentInterface getComponent(int i) { + return getPhase(0).getComponent(i); + } /** *

- * changeComponentName. + * Get component by name. *

* - * @param name a {@link java.lang.String} object - * @param newName a {@link java.lang.String} object + * @param name Name of component + * @return a {@link neqsim.thermo.component.ComponentInterface} object */ - public void changeComponentName(String name, String newName); + public default ComponentInterface getComponent(String name) { + return getPhase(0).getComponent(name); + } /** *

- * getWaxModel. + * Getter for property componentNames. *

* - * @return a {@link neqsim.thermo.characterization.WaxModelInterface} object + * @return Component names in system. */ - public WaxModelInterface getWaxModel(); + public String[] getComponentNames(); /** *

- * getWaxCharacterisation. + * getComponentNameTag. *

* - * @return a {@link neqsim.thermo.characterization.WaxCharacterise} object + * @return a {@link java.lang.String} object */ - public neqsim.thermo.characterization.WaxCharacterise getWaxCharacterisation(); + public String getComponentNameTag(); /** - * method to get the total molar flow rate of individual components in a fluid. + * method to return fluid volume with Peneloux volume correction. * - * @return molar flow of individual components in unit mol/sec + * @return volume in unit m3 */ - public double[] getMolarRate(); + public double getCorrectedVolume(); /** - * Returns true if phase exists and is not null. + * method to return the volume fraction of a phase note: with Peneloux volume correction. * - * @param i Phase number - * @return True if phase exists, false if not. + * @param phaseNumber number of the phase to get volume fraction for + * @return volume fraction */ - public boolean isPhase(int i); + public double getCorrectedVolumeFraction(int phaseNumber); /** - * Get phase number i from SystemInterface object. + * method to return specific heat capacity (Cp). * - * @param i Phase number - * @return a {@link neqsim.thermo.phase.PhaseInterface} object + * @return Cp in unit J/K */ - public PhaseInterface getPhase(int i); + public double getCp(); /** - *

- * getPhase. - *

+ * method to return specific heat capacity (Cp) in a specified unit. * - * @param phaseTypeName a {@link java.lang.String} object - * @return a {@link neqsim.thermo.phase.PhaseInterface} object + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + * @return Cp in specified unit */ - public PhaseInterface getPhase(String phaseTypeName); + public double getCp(String unit); /** - *

- * getPhase. - *

+ * method to return specific heat capacity (Cv). * - * @param pt a {@link neqsim.thermo.phase.PhaseType} object - * @return a {@link neqsim.thermo.phase.PhaseInterface} object + * @return Cv in unit J/K */ - public PhaseInterface getPhase(PhaseType pt); + public double getCv(); /** - *

- * Indexed getter for property phaseIndex. - *

+ * method to return specific heat capacity (Cp) in a specified unit. * - * @param i Phase number - * @return PhaseIndex to index into phaseArray. + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + * @return Cp in specified unit */ - public int getPhaseIndex(int i); + public double getCv(String unit); /** - * Get property phaseIndex corresponding to a phase. + * method to get density of a fluid note: without Peneloux volume correction. * - * @param phase Phase object to search for. - * @return PhaseIndex to index into phaseArray. + * @return density with unit kg/m3 */ - public int getPhaseIndex(PhaseInterface phase); + public double getDensity(); /** - *

- * Get property phaseIndex corresponding to a phase. - *

+ * method to get density of a fluid note: with Peneloux volume correction. * - * @param phaseTypeName a {@link java.lang.String} object - * @return PhaseIndex to index into phaseArray. + * @param unit Supported units are kg/m3, mol/m3 + * @return density in specified unit */ - public int getPhaseIndex(String phaseTypeName); + public double getDensity(String unit); /** *

- * setTotalFlowRate. + * getdVdPtn. *

* - * @param flowRate a double - * @param flowunit a {@link java.lang.String} object. flow units are: kg/sec, kg/min, kg/hr - * m3/sec, m3/min, m3/hr, mole/sec, mole/min, mole/hr, Sm3/hr, Sm3/day, idSm3/hr, idSm3/day + * @return a double */ - public void setTotalFlowRate(double flowRate, String flowunit); + public double getdVdPtn(); /** *

- * Returns the overall mole composition vector in unit mole fraction. + * getdVdTpn. *

* - * @return an array of {@link double} objects + * @return a double */ - public double[] getMolarComposition(); + public double getdVdTpn(); /** *

- * getNumberOfOilFractionComponents. + * getEmptySystemClone. *

* - * @return a int + * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public int getNumberOfOilFractionComponents(); + public SystemInterface getEmptySystemClone(); /** - *

- * setHeavyTBPfractionAsPlusFraction. - *

+ * method to get the total enthalpy of a fluid. * - * @return a boolean + * @return molar mass in unit J (Joule) */ - public boolean setHeavyTBPfractionAsPlusFraction(); + public double getEnthalpy(); /** - *

- * getCapeOpenProperties11. - *

+ * method to return total enthalpy in a specified unit. * - * @return an array of {@link java.lang.String} objects + * @param unit Supported units are 'J', 'J/mol', 'kJ/kmol', 'J/kg' and 'kJ/kg' + * @return enthalpy in specified unit */ - public String[] getCapeOpenProperties11(); + public double getEnthalpy(String unit); /** - *

- * getCapeOpenProperties10. - *

+ * method to return total entropy of the fluid. * - * @return an array of {@link java.lang.String} objects + * @return entropy in unit J/K (Joule/Kelvin) */ - public String[] getCapeOpenProperties10(); + public double getEntropy(); /** - *

- * getLowestGibbsEnergyPhase. - *

+ * method to return total entropy of the fluid. * - * @return a {@link neqsim.thermo.phase.PhaseInterface} object + * @param unit unit supported units are J/K, J/molK, J/kgK and kJ/kgK + * @return entropy in specified unit */ - public PhaseInterface getLowestGibbsEnergyPhase(); + public double getEntropy(String unit); /** - *

- * getOilFractionNormalBoilingPoints. - *

+ * method to return exergy defined as (h1-T0*s1) in a unit Joule. * - * @return an array of {@link double} objects + * @param temperatureOfSurroundings in Kelvin + * @return a double */ - public double[] getOilFractionNormalBoilingPoints(); + public double getExergy(double temperatureOfSurroundings); /** - *

- * getOilFractionLiquidDensityAt25C. - *

+ * method to return exergy in a specified unit. * - * @return an array of {@link double} objects + * @param temperatureOfSurroundings in Kelvin + * @param exergyUnit a {@link java.lang.String} object + * @return exergy in specified unit */ - public double[] getOilFractionLiquidDensityAt25C(); + public double getExergy(double temperatureOfSurroundings, String exergyUnit); /** - *

- * getOilFractionMolecularMass. - *

+ * method to return flow rate of fluid. * - * @return an array of {@link double} objects + * @param flowunit Supported units are kg/sec, kg/min, kg/hr, kg/day, m3/sec, m3/min, m3/hr, + * idSm3/hr, Sm3/sec, Sm3/hr, Sm3/day, MSm3/day, mole/sec, mole/min, mole/hr + * @return flow rate in specified unit */ - public double[] getOilFractionMolecularMass(); + public double getFlowRate(String flowunit); /** *

- * getOilFractionIDs. + * Getter for property info. *

* - * @return an array of {@link int} objects + * @return a {@link java.lang.String} object */ - public int[] getOilFractionIDs(); + public String getFluidInfo(); /** *

- * getMoleFraction. + * getFluidName. *

* - * @param phaseNumber a int - * @return a double + * @return a {@link java.lang.String} object */ - public double getMoleFraction(int phaseNumber); + public String getFluidName(); /** - * method to return specific heat capacity (Cv). + * method to return heat capacity ratio/adiabatic index/Poisson constant. * - * @return Cv in unit J/K + * @return kappa */ - public double getCv(); + public double getGamma(); /** - * method to return specific heat capacity (Cp) in a specified unit. + * method to return heat capacity ratio calculated as Cp/(Cp-R). * - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK - * @return Cp in specified unit + * @return kappa */ - public double getCv(String unit); + public default double getGamma2() { + return getCp() / (getCp() - ThermodynamicConstantsInterface.R * getTotalNumberOfMoles()); + } /** *

- * Getter for property characterization. + * getGasPhase. *

* - * @return a {@link neqsim.thermo.characterization.Characterise} object + * @return a {@link neqsim.thermo.phase.PhaseInterface} object */ - public neqsim.thermo.characterization.Characterise getCharacterization(); + public PhaseInterface getGasPhase(); /** *

- * readObject. + * getGibbsEnergy. *

* - * @param ID a int - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @return a double */ - public SystemInterface readObject(int ID); + public double getGibbsEnergy(); /** *

- * getCompIDs. + * getHeatOfVaporization. *

* - * @return an array of {@link java.lang.String} objects + * @return a double */ - public String[] getCompIDs(); + public double getHeatOfVaporization(); /** *

- * saveObject. + * getHelmholtzEnergy. *

* - * @param ID a int - * @param text a {@link java.lang.String} object - */ - public void saveObject(int ID, String text); - - /** - * Set mole fractions of all components to 0. + * @return a double */ - public void reset(); + public double getHelmholtzEnergy(); /** *

- * getCASNumbers. + * Getter for property hydrateCheck. *

* - * @return an array of {@link java.lang.String} objects + * @return a boolean */ - public String[] getCASNumbers(); + public boolean getHydrateCheck(); /** - *

- * getMolecularWeights. - *

+ * Get ideal liquid density of fluid in given unit. * - * @return an array of {@link double} objects + * @param unit {@link java.lang.String} Supported units are kg/m3 and gr/cm3 + * @return a double */ - public double[] getMolecularWeights(); + public double getIdealLiquidDensity(String unit); /** *

- * getNormalBoilingPointTemperatures. + * Getter for property initType. *

* - * @return an array of {@link double} objects + * @return a int */ - public double[] getNormalBoilingPointTemperatures(); + public int getInitType(); /** - * Get names of all components in System. + * method to return interfacial tension between two phases. * - * @return an array of {@link java.lang.String} objects + * @param phase1 phase number of phase1 + * @param phase2 phase number of phase2 + * @return interfacial tension with unit N/m */ - public String[] getCompNames(); + public double getInterfacialTension(int phase1, int phase2); /** *

- * getCompFormulaes. + * getInterfacialTension. *

* - * @return an array of {@link java.lang.String} objects + * @param phase1 phase number of phase1 + * @param phase2 phase number of phase2 + * @param unit a {@link java.lang.String} object + * @return interfacial tension with specified unit */ - public String[] getCompFormulaes(); + public double getInterfacialTension(int phase1, int phase2, String unit); /** - *

- * getWtFraction. - *

+ * method to return interfacial tension between two phases. * - * @param phaseNumber a int - * @return a double + * @param phase1 phase type of phase1 as string (valid phases are gas, oil, aqueous) + * @param phase2 phase type of phase2 as string (valid phases are gas, oil, aqueous) + * @return interfacial tension with unit N/m. If one or both phases does not exist - the method + * will return NaN */ - public double getWtFraction(int phaseNumber); + public double getInterfacialTension(String phase1, String phase2); /** - *

- * isMultiphaseWaxCheck. - *

+ * method to return internal energy (U) in unit J. * - * @return a boolean + * @return internal energy in unit Joule (J) */ - public boolean isMultiphaseWaxCheck(); + public double getInternalEnergy(); /** - *

- * setMultiphaseWaxCheck. - *

+ * method to return internal energy (U) in a specified unit. * - * @param multiphaseWaxCheck a boolean + * @param unit Supported units are 'J', 'J/mol', 'J/kg' and 'kJ/kg' + * @return enthalpy in specified unit */ - public void setMultiphaseWaxCheck(boolean multiphaseWaxCheck); + public double getInternalEnergy(String unit); /** *

- * This method is used to set the total molar composition of a fluid. The total flow rate will be - * kept constant. The input mole fractions will be normalized. + * getInterphaseProperties. *

* - * @param moles an array of {@link double} objects + * @return a {@link neqsim.physicalProperties.interfaceProperties.InterphasePropertiesInterface} + * object */ - public void setMolarComposition(double[] moles); + public InterphasePropertiesInterface getInterphaseProperties(); /** - * return the phase of to specified type if the phase does not exist, the method will return null. + * method to get the Joule Thomson Coefficient of a system. Based on a phase mole fraction basis + * average * - * @param phaseTypeName the phase type to be returned (gas, oil, aqueous, wax, hydrate are - * supported) - * @return a {@link neqsim.thermo.phase.PhaseInterface} object + * @return Joule Thomson coefficient in K/bar */ - public PhaseInterface getPhaseOfType(String phaseTypeName); + public double getJouleThomsonCoefficient(); /** - *

- * setUseTVasIndependentVariables. - *

+ * method to get the Joule Thomson Coefficient of a system. Based on a phase mole fraction basis + * average. * - * @param useTVasIndependentVariables a boolean + * @param unit Supported units are K/bar, C/bar + * @return Joule Thomson coefficient in specified unit */ - public void setUseTVasIndependentVariables(boolean useTVasIndependentVariables); + public double getJouleThomsonCoefficient(String unit); /** - * method to add true boiling point fraction. + * method to return heat capacity ratio/adiabatic index/Poisson constant. * - * @param componentName selected name of the component to be added - * @param numberOfMoles number of moles to be added - * @param molarMass molar mass of the component in kg/mol - * @param density density of the component in g/cm3 + * @return kappa */ - public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, - double density); + public double getKappa(); /** *

- * addTBPfraction. + * getKinematicViscosity. *

* - * @param componentName a {@link java.lang.String} object - * @param numberOfMoles a double - * @param molarMass a double - * @param density a double - * @param criticalTemperature a double - * @param criticalPressure a double - * @param acentricFactor a double + * @return a double */ - public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, - double density, double criticalTemperature, double criticalPressure, double acentricFactor); + public double getKinematicViscosity(); /** - *

- * addPlusFraction. - *

+ * method to return kinematic viscosity in a specified unit. * - * @param componentName a {@link java.lang.String} object - * @param numberOfMoles a double - * @param molarMass a double - * @param density a double + * @param unit Supported units are m2/sec + * @return kinematic viscosity in specified unit */ - public void addPlusFraction(String componentName, double numberOfMoles, double molarMass, - double density); + public double getKinematicViscosity(String unit); /** *

- * addSalt. + * getLiquidPhase. *

* - * @param componentName a {@link java.lang.String} object - * @param value a double + * @return a {@link neqsim.thermo.phase.PhaseInterface} object */ - public void addSalt(String componentName, double value); + public PhaseInterface getLiquidPhase(); /** *

- * deleteFluidPhase. + * getLiquidVolume. *

* - * @param phase a int + * @return a double */ - public void deleteFluidPhase(int phase); + public double getLiquidVolume(); /** *

- * setBmixType. + * getLowestGibbsEnergyPhase. *

* - * @param bmixType a int - */ - public void setBmixType(int bmixType); - - /** - * Verify if system has a phase of a specific type. - * - * @param pt PhaseType to look for - * @return True if system contains a phase of requested type + * @return a {@link neqsim.thermo.phase.PhaseInterface} object */ - public boolean hasPhaseType(PhaseType pt); + public PhaseInterface getLowestGibbsEnergyPhase(); /** - * Verify if system has a phase of a specific type. + * method to return mass of fluid. * - * @param phaseTypeName PhaseType to look for - * @return True if system contains a phase of requested type + * @param unit Supported units are kg, gr, tons + * @return mass in specified unit */ - public default boolean hasPhaseType(String phaseTypeName) { - return hasPhaseType(PhaseType.byDesc(phaseTypeName)); - } + public double getMass(String unit); /** *

- * hasSolidPhase. + * Getter for property maxNumberOfPhases. *

* - * @return True if system contains a solid phase + * @return Gets the maximum allowed number of phases to use. */ - public default boolean hasSolidPhase() { - return hasPhaseType(PhaseType.SOLID); // || hasPhaseType(PhaseType.SOLIDCOMPLEX); - } + public int getMaxNumberOfPhases(); /** *

- * addSolidComplexPhase. + * getMixingRule. *

* - * @param type a {@link java.lang.String} object - */ - public void addSolidComplexPhase(String type); - - /** - *

- * resetCharacterisation. - *

+ * @return a int */ - public void resetCharacterisation(); + public int getMixingRule(); /** *

@@ -1069,690 +1101,660 @@ public default boolean hasSolidPhase() { /** *

- * tuneModel. + * Returns the overall mole composition vector in unit mole fraction. *

* - * @param model a {@link java.lang.String} object - * @param val a double - * @param phase a int + * @return an array of {@link double} objects */ - public void tuneModel(String model, double val, int phase); + public double[] getMolarComposition(); /** - * add a component to a fluid. If component already exists, the moles will be added to the - * existing component. + * Get molar mass of system. * - * @param inComponent Component object to add. + * @return molar mass in unit kg/mol */ - public void addComponent(ComponentInterface inComponent); + public double getMolarMass(); /** - * add a component to a fluid with no moles. + * method to get molar mass of a fluid phase. * - * @param name Name of the component to add. See NeqSim database for component in the database. + * @param unit Supported units are kg/mol, gr/mol + * @return molar mass in specified unit */ - public default void addComponent(String name) { - addComponent(name, 0); - } + public double getMolarMass(String unit); /** - * add a component to a fluid. If component already exists, the moles will be added to the - * existing component. + * method to get the total molar flow rate of individual components in a fluid. * - * @param name Name of the component to add. See NeqSim database for component in the database. - * @param moles number of moles (per second) of the component to be added to the fluid + * @return molar flow of individual components in unit mol/sec */ - public void addComponent(String name, double moles); + public double[] getMolarRate(); /** - * add a component to a fluid. If component already exists, the amount will be added to the - * existing component. + * method to return molar volume of the fluid note: without Peneloux volume correction. * - * @param name Name of the component to add. See NeqSim database for component in the database. - * @param value The amount. - * @param unitName the unit of rate (sported units are kg/sec, mol/sec, Nlitre/min, kg/hr, - * Sm^3/hr, Sm^3/day, MSm^3/day .. + * @return molar volume volume in unit m3/mol*1e5 */ - public void addComponent(String name, double value, String unitName); + public double getMolarVolume(); + + /** + * method to return molar volume of the fluid: eventual volume correction included. + * + * @param unit Supported units are m3/mol, litre/mol + * + * @return molar volume volume in unit + */ + public double getMolarVolume(String unit); /** *

- * addComponent. + * getMolecularWeights. *

* - * @param name Name of the component to add. See NeqSim database for component in the database. - * @param moles number of moles (per second) of the component to be added to the fluid - * @param TC Critical temperature - * @param PC Critical pressure - * @param acs a double + * @return an array of {@link double} objects */ - public void addComponent(String name, double moles, double TC, double PC, double acs); + public double[] getMolecularWeights(); /** - * add a component to a fluid. If component already exists, the moles will be added to the - * existing component. + *

+ * getMoleFraction. + *

* - * @param name Name of the component to add. See NeqSim database for component in the database. - * @param moles number of moles (per second) of the component to be added to the fluid - * @param phaseNumber Number of the phase to add the component to + * @param phaseNumber a int + * @return a double */ - public void addComponent(String name, double moles, int phaseNumber); + public double getMoleFraction(int phaseNumber); /** - * add a component to a fluid. I component already exists, it will be added to the component + *

+ * Get sum of mole fractions for all components. NB! init(0) must be called first. + *

* - * @param name Name of the component to add. See NeqSim database for component in the database. - * @param value rate of the component to add to the fluid - * @param unitName the unit of the flow rate (eg. mol/sec, kg/sec, etc.) - * @param phaseNumber Number of the phase to add the component to + * @return a double */ - public void addComponent(String name, double value, String unitName, int phaseNumber); + public double getMoleFractionsSum(); /** *

- * addComponent. + * getNormalBoilingPointTemperatures. *

* - * @param index Component number to add - * @param moles number of moles (per second) of the component to be added to the fluid + * @return an array of {@link double} objects */ - public void addComponent(int index, double moles); + public double[] getNormalBoilingPointTemperatures(); /** *

- * addComponent. + * Get number of components added to System. *

* - * @param index Component number to add - * @param moles number of moles (per second) of the component to be added to the fluid - * @param phaseNumber Number of the phase to add the component to + * @return the number of components in System. */ - public void addComponent(int index, double moles, int phaseNumber); + public int getNumberOfComponents(); /** *

- * removeComponent. + * Getter for property numberOfMoles. *

* - * @param name Name of the component to remove. See NeqSim database for component in the database. + * @return a double + * @deprecated Replaced by {@link getTotalNumberOfMoles} */ - public void removeComponent(String name); + @Deprecated + public default double getNumberOfMoles() { + return getTotalNumberOfMoles(); + } /** *

- * Getter for property beta. - * - * Gets value for heaviest phase. + * getNumberOfOilFractionComponents. *

* - * @return Beta value + * @return a int */ - public double getBeta(); + public int getNumberOfOilFractionComponents(); /** *

- * Getter for property beta for a specific phase. + * Getter for property numberOfPhases. *

* - * @param phase Number of phase to get beta for. - * @return Beta value for + * @return Number of phases used */ - public double getBeta(int phase); + public int getNumberOfPhases(); /** *

- * Setter for property beta. NB! Sets beta = b for first phase and 1-b for second - * phase, not for multiphase systems. + * getOilFractionIDs. *

* - * @param b Beta value to set. + * @return an array of {@link int} objects */ - public void setBeta(double b); + public int[] getOilFractionIDs(); /** *

- * Setter for property beta for a given phase. + * getOilFractionLiquidDensityAt25C. *

* - * @param phase Phase number to set beta for. - * @param b Beta value to set. + * @return an array of {@link double} objects */ - public void setBeta(int phase, double b); + public double[] getOilFractionLiquidDensityAt25C(); /** *

- * Save System object to file. + * getOilFractionMolecularMass. *

* - * @param name File path to save to. + * @return an array of {@link double} objects */ - public void save(String name); + public double[] getOilFractionMolecularMass(); /** *

- * setModel. + * getOilFractionNormalBoilingPoints. *

* - * @param model a {@link java.lang.String} object - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @return an array of {@link double} objects */ - public SystemInterface setModel(String model); + public double[] getOilFractionNormalBoilingPoints(); /** - * method to set mixing rule used for the fluid. + *

+ * Getter for property PC. + *

* - * @param type The type of mixing rule to be used for the fluid. 1 - classic mixing rule with all - * kij set to zero 2 -classic mixing rule with kij from NeqSim database 3- classic mixing - * rule with temperature dependent kij 4- Huron Vidal mixing rule with parameters from - * NeqSim database 7 -classic mixing rule with kij of CPA from NeqSim Database 9 - * -classicmixing rule with temperature dependent kij of CPA from NeqSim database - * 10-classic mixing rule with temperature and composition dependent kij of CPA from NeqSim - * database + * @return Critical pressure */ - public void setMixingRule(int type); + public double getPC(); /** - * method to set the mixing rule for the fluid. + * Get phase number i from SystemInterface object. * - * @param typename a {@link java.lang.String} object + * @param i Phase number + * @return a {@link neqsim.thermo.phase.PhaseInterface} object */ - public void setMixingRule(String typename); + public PhaseInterface getPhase(int i); /** *

- * setMixingRule. + * getPhase. *

* - * @param typename a {@link java.lang.String} object - * @param GEmodel a {@link java.lang.String} object + * @param pt a {@link neqsim.thermo.phase.PhaseType} object + * @return a {@link neqsim.thermo.phase.PhaseInterface} object */ - public void setMixingRule(String typename, String GEmodel); + public PhaseInterface getPhase(PhaseType pt); /** *

- * normalizeBeta. + * getPhase. *

+ * + * @param phaseTypeName a {@link java.lang.String} object + * @return a {@link neqsim.thermo.phase.PhaseInterface} object */ - public void normalizeBeta(); + public PhaseInterface getPhase(String phaseTypeName); /** - *

- * Setter for property initType. - *

+ * method to return phase fraction of selected phase. * - * @param initType a int + * @param phaseTypeName gas/oil/aqueous + * @param unit mole/volume/weight + * @return phase: fraction in specified unit */ - public void setInitType(int initType); + public double getPhaseFraction(String phaseTypeName, String unit); /** *

- * checkStability. + * Indexed getter for property phaseIndex. *

* - * @return a boolean + * @param i Phase number + * @return PhaseIndex to index into phaseArray. */ - public boolean checkStability(); + public int getPhaseIndex(int i); /** - *

- * checkStability. - *

+ * Get property phaseIndex corresponding to a phase. * - * @param val a boolean + * @param phase Phase object to search for. + * @return PhaseIndex to index into phaseArray. */ - public void checkStability(boolean val); + public int getPhaseIndex(PhaseInterface phase); /** *

- * Getter for property hasPlusFraction. + * Get property phaseIndex corresponding to a phase. *

* - * @return a boolean + * @param phaseTypeName a {@link java.lang.String} object + * @return PhaseIndex to index into phaseArray. */ - public boolean hasPlusFraction(); + public int getPhaseIndex(String phaseTypeName); /** *

- * Getter for property initType. + * Get phase number of phase of specific type. *

* - * @return a int + * @param pt Phase type to look for. + * @return Phase number */ - public int getInitType(); + public int getPhaseNumberOfPhase(PhaseType pt); /** *

- * invertPhaseTypes. + * Get phase number of phase of specific type. * *

- */ - public void invertPhaseTypes(); - - /** - * method to return fluid volume with Peneloux volume correction. * - * @return volume in unit m3 + * @param phaseTypeName Name of phase type to look for + * @return Phase number */ - public double getCorrectedVolume(); + public default int getPhaseNumberOfPhase(String phaseTypeName) { + return getPhaseNumberOfPhase(PhaseType.byDesc(phaseTypeName)); + } /** - *

- * readFluid. - *

+ * return the phase of to specified type if the phase does not exist, the method will return null. * - * @param fluidName a {@link java.lang.String} object + * @param phaseTypeName the phase type to be returned (gas, oil, aqueous, wax, hydrate are + * supported) + * @return a {@link neqsim.thermo.phase.PhaseInterface} object */ - public void readFluid(String fluidName); + public PhaseInterface getPhaseOfType(String phaseTypeName); /** *

- * calcKIJ. + * getPhases. *

* - * @param ok a boolean + * @return an array of {@link neqsim.thermo.phase.PhaseInterface} objects */ - public void calcKIJ(boolean ok); + public PhaseInterface[] getPhases(); /** - *

- * write. - *

+ * method to return pressure. * - * @param name a {@link java.lang.String} object - * @param filename a {@link java.lang.String} object - * @param newfile a boolean + * @return pressure in unit bara */ - public void write(String name, String filename, boolean newfile); + public double getPressure(); /** *

- * useVolumeCorrection. + * method to return pressure of phase. *

* - * @param volcor a boolean + * @param phaseNumber Number of the phase to get pressure for + * @return pressure in unit bara */ - public void useVolumeCorrection(boolean volcor); + public double getPressure(int phaseNumber); /** - *

- * Getter for property numericDerivatives. - *

+ * method to return pressure in a specified unit. * - * @return a boolean + * @param unit Supported units are bara, barg, Pa and MPa + * @return pressure in specified unit */ - public boolean isNumericDerivatives(); + public double getPressure(String unit); /** - *

- * Setter for property numericDerivatives. - *

+ * Get physical properties of System. * - * @param numericDerivatives a boolean + * @return System properties */ - public void setNumericDerivatives(boolean numericDerivatives); + public SystemProperties getProperties(); /** *

- * Getter for property info. + * getProperty. *

* - * @return a {@link java.lang.String} object + * @param prop a {@link java.lang.String} object + * @return a double */ - public String getFluidInfo(); + public double getProperty(String prop); /** *

- * Setter for property info. . + * getProperty. *

* - * @param info a {@link java.lang.String} object + * @param prop a {@link java.lang.String} object + * @param phase a int + * @return a double */ - public void setFluidInfo(String info); + public double getProperty(String prop, int phase); /** *

- * Indexed setter for property phaseIndex. - * this.phaseIndex[index] = phaseIndex; + * getProperty. *

* - * @param index a int - * @param phaseIndex a int + * @param prop a {@link java.lang.String} object + * @param compName a {@link java.lang.String} object + * @param phase a int + * @return a double */ - public void setPhaseIndex(int index, int phaseIndex); + public double getProperty(String prop, String compName, int phase); /** *

- * Set phaseArray[phaseIndex] = phase. NB! Transfers the pressure and temperature - * from the currently existing phase object at index numb + * getResultTable. *

* - * @param phase a {@link neqsim.thermo.phase.PhaseInterface} object - * @param index Phase index to insert object at - */ - public void setPhase(PhaseInterface phase, int index); - - /** - * method to read pure component and interaction parameters from the NeqSim database and create - * temporary tables with parameters for active fluid. - * - * @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 - * when setting a mixing rule) it will try to find them in the temporary tables first eg. - * COMPTEMP (for pure component parameters) and INTERTEMP (for interaction parameters). If - * reset is set to false it will not create new temporary tables. If a fluid is created - * with the same components many times, performance improvements will be obtained, if - * temporary tables are created the first time (reset=true), and then the same tables is - * used when creating new fluids with the same temporary tables (reset=false) + * @return an array of {@link java.lang.String} objects */ - public void createDatabase(boolean reset); + public String[][] getResultTable(); /** - *

- * resetDatabase. - *

+ * method to get the speed of sound of a system. The sound speed is implemented based on a molar + * average over the phases + * + * @return speed of sound in m/s */ - public void resetDatabase(); + public double getSoundSpeed(); /** - *

- * Setter for property solidPhaseCheck. - *

+ * method to get the speed of sound of a system. The sound speed is implemented based on a molar + * average over the phases * - * @param test a boolean + * @param unit Supported units are m/s, km/h + * @return speed of sound in m/s */ - public void setSolidPhaseCheck(boolean test); + public double getSoundSpeed(String unit); /** *

- * setSolidPhaseCheck. + * Getter for property standard. *

* - * @param solidComponent a {@link java.lang.String} object + * @return a {@link neqsim.standards.StandardInterface} object */ - public void setSolidPhaseCheck(String solidComponent); + public neqsim.standards.StandardInterface getStandard(); /** *

- * doSolidPhaseCheck. + * Getter for property standard. *

* - * @return a boolean + * @param standardName a {@link java.lang.String} object + * @return a {@link neqsim.standards.StandardInterface} object */ - public boolean doSolidPhaseCheck(); + public neqsim.standards.StandardInterface getStandard(String standardName); /** *

- * Getter for property multiPhaseCheck. + * Getter for property TC. *

* - * @return a boolean + * @return Critical temperature */ - public boolean doMultiPhaseCheck(); + public double getTC(); /** - * method to specify if calculations should check for more than two fluid phases. + * method to return temperature. * - * @param doMultiPhaseCheck Specify if the calculations should check for more than two fluid - * phases. Default is two fluid phases (gas and liquid). If set to true the program will - * check for gas and multiple liquid phases (eg. gas-oil-aqueous). + * @return temperature in unit Kelvin */ - public void setMultiPhaseCheck(boolean doMultiPhaseCheck); + public double getTemperature(); /** - * Calculate thermodynamic properties of the fluid using the init type set in fluid. + *

+ * method to return temperature. + *

* - * @see getInitType + * @param phaseNumber phase to get temperature of + * @return temperature in unit Kelvin */ - public default void init() { - this.init(this.getInitType()); - } + public double getTemperature(int phaseNumber); /** - * method to calculate thermodynamic properties of the fluid. The temperature, pressure, number of - * phases and composition of the phases will be used as basis for calculation. + * method to return temperature in a specified unit. * - * @param number - The number can be 0, 1, 2 or 3. 0: Set feed composition for all phases. 1: - * Calculation of density, fugacities and Z-factor 2: 1 + calculation of enthalpy, entropy, - * Cp, Cv, and most other thermodynamic properties 3: 1+2 + Calculation of composition - * derivatives of fugacity coefficients. + * @param unit Supported units are K, C, R + * @return temperature in specified unit */ - public void init(int number); + public double getTemperature(String unit); /** - * method to calculate thermodynamic properties of the selected phase. The temperature, pressure, - * number of phases and composition of the phase will be used as basis for calculation. + * method to return conductivity of a fluid. * - * @param number - The number can be 0, 1, 2 or 3. 0: Set feed composition. 1: Calculation of - * density, fugacities and Z-factor 2: 1 + calculation of enthalpy, entropy, Cp, Cv, and - * most other thermodynamic properties 3: 1+2 + Calculation of composition derivatives of - * fugacity coefficients. - * @param phase a int + * @return conductivity in unit W/mK */ - public void init(int number, int phase); + public double getThermalConductivity(); /** - * Calculates thermodynamic properties of a fluid using the init(2) method. + * method to return thermal conductivity in a specified unit. + * + * @param unit Supported units are W/mK, W/cmK + * @return conductivity in specified unit */ - public default void initThermoProperties() { - init(2); - } + public double getThermalConductivity(String unit); /** - * initNumeric. + * Getter for property totalNumberOfMoles. + * + * @return Total molar flow rate of fluid in unit mol/sec */ - public void initNumeric(); + public double getTotalNumberOfMoles(); /** - *

- * display. - *

+ * method to return viscosity of a fluid. + * + * @return viscosity in unit kg/msec */ - public default void display() { - display(this.getFluidName()); - } + public double getViscosity(); /** - *

- * display. - *

+ * method to return viscosity in a specified unit. * - * @param name a {@link java.lang.String} object + * @param unit Supported units are kg/msec, cP (centipoise), Pas (Pascal*second) + * @return viscosity in specified unit */ - public void display(String name); + public double getViscosity(String unit); /** - * Prints the fluid in a visually appealing way. + * method to return fluid volume. + * + * @return volume in unit m3*1e5 */ - public default void prettyPrint() { - neqsim.thermo.util.readwrite.TablePrinter.printTable(createTable(getFluidName())); - } + public double getVolume(); /** - *

- * addFluid. - *

+ * method to return fluid volume. * - * @param addSystem a {@link neqsim.thermo.system.SystemInterface} object - * @return SystemInterface + * @param unit Supported units are m3, litre, m3/kg, m3/mol + * @return volume in specified unit */ - public SystemInterface addFluid(SystemInterface addSystem); + public double getVolume(String unit); /** - *

- * addFluid. - *

+ * method to return the volume fraction of a phase note: without Peneloux volume correction. * - * @param addSystem a {@link neqsim.thermo.system.SystemInterface} object - * @param phase phase number of phase to add fluid to - * @return SystemInterface + * @param phaseNumber number of the phase to get volume fraction for + * @return volume fraction */ - public SystemInterface addFluid(SystemInterface addSystem, int phase); + public double getVolumeFraction(int phaseNumber); /** *

- * Getter for property hydrateCheck. + * getWaxCharacterisation. *

* - * @return a boolean + * @return a {@link neqsim.thermo.characterization.WaxCharacterise} object */ - public boolean getHydrateCheck(); + public neqsim.thermo.characterization.WaxCharacterise getWaxCharacterisation(); /** *

- * createTable. + * getWaxModel. *

* - * @param name a {@link java.lang.String} object - * @return an array of {@link java.lang.String} objects + * @return a {@link neqsim.thermo.characterization.WaxModelInterface} object */ - public String[][] createTable(String name); + public WaxModelInterface getWaxModel(); /** *

- * setHydrateCheck. + * getWtFraction. *

* - * @param hydrateCheck a boolean + * @param phaseNumber a int + * @return a double */ - public void setHydrateCheck(boolean hydrateCheck); + public double getWtFraction(int phaseNumber); /** - *

- * calcBeta. For simple gas liquid systems. - *

+ * method to return compressibility factor of a fluid compressibility factor is defined in EoS + * from PV=ZnRT where V is total volume of fluid. * - * @return Beta Mole fraction contained in the heaviest phase, i.e., liquid phase. - * @throws neqsim.util.exception.IsNaNException if any. - * @throws neqsim.util.exception.TooManyIterationsException if any. + * @return compressibility factor Z */ - public double calcBeta() - throws neqsim.util.exception.IsNaNException, neqsim.util.exception.TooManyIterationsException; + public double getZ(); + + /** {@inheritDoc} */ + @Override + public int hashCode(); /** - *

- * setAllComponentsInPhase. - *

+ * Verify if system has a phase of a specific type. * - * @param phase a int + * @param pt PhaseType to look for + * @return True if system contains a phase of requested type */ - public void setAllComponentsInPhase(int phase); + public boolean hasPhaseType(PhaseType pt); /** - *

- * initTotalNumberOfMoles. - *

+ * Verify if system has a phase of a specific type. * - * @param change a double + * @param phaseTypeName PhaseType to look for + * @return True if system contains a phase of requested type */ - public void initTotalNumberOfMoles(double change); + public default boolean hasPhaseType(String phaseTypeName) { + return hasPhaseType(PhaseType.byDesc(phaseTypeName)); + } /** *

- * calc_x_y. + * Getter for property hasPlusFraction. *

+ * + * @return a boolean */ - public void calc_x_y(); + public boolean hasPlusFraction(); /** *

- * reset_x_y. + * hasSolidPhase. *

+ * + * @return True if system contains a solid phase */ - public void reset_x_y(); - - /** - * Add phase to SystemInterface object. - */ - public void addPhase(); + public default boolean hasSolidPhase() { + return hasPhaseType(PhaseType.SOLID); // || hasPhaseType(PhaseType.SOLIDCOMPLEX); + } /** - *

- * setAttractiveTerm. - *

+ * Calculate thermodynamic properties of the fluid using the init type set in fluid. * - * @param i a int + * @see getInitType */ - public void setAttractiveTerm(int i); + public default void init() { + this.init(this.getInitType()); + } /** - *

- * removePhase. - *

+ * method to calculate thermodynamic properties of the fluid. The temperature, pressure, number of + * phases and composition of the phases will be used as basis for calculation. * - * @param specPhase a int + * @param number - The number can be 0, 1, 2 or 3. 0: Set feed composition for all phases. 1: + * Calculation of density, fugacities and Z-factor 2: 1 + calculation of enthalpy, entropy, + * Cp, Cv, and most other thermodynamic properties 3: 1+2 + Calculation of composition + * derivatives of fugacity coefficients. */ - public void removePhase(int specPhase); + public void init(int number); // public void setPressure(double newPressure, int phaseNumber); /** - * method to return pressure. - * - * @return pressure in unit bara - */ - public double getPressure(); - - /** - * method to return pressure in a specified unit. + * method to calculate thermodynamic properties of the selected phase. The temperature, pressure, + * number of phases and composition of the phase will be used as basis for calculation. * - * @param unit Supported units are bara, barg, Pa and MPa - * @return pressure in specified unit + * @param number - The number can be 0, 1, 2 or 3. 0: Set feed composition. 1: Calculation of + * density, fugacities and Z-factor 2: 1 + calculation of enthalpy, entropy, Cp, Cv, and + * most other thermodynamic properties 3: 1+2 + Calculation of composition derivatives of + * fugacity coefficients. + * @param phase a int */ - public double getPressure(String unit); + public void init(int number, int phase); /** *

- * method to return pressure of phase. + * init_x_y. *

- * - * @param phaseNumber Number of the phase to get pressure for - * @return pressure in unit bara */ - public double getPressure(int phaseNumber); + public void init_x_y(); /** *

- * reInitPhaseType. + * Calculate system beta values using Phase.getNumberOfMolesInPhase and getTotalNumberOfMoles. *

*/ - public void reInitPhaseType(); + public void initBeta(); /** - * Set the physical property model type for each phase of the System. + * initNumeric. + */ + public void initNumeric(); + + /** + * Init physical properties for all phases and interfaces. + */ + public void initPhysicalProperties(); + + /** + * Calculates physical properties of type propertyName. * - * @param type 0 Orginal/default 1 Water 2 Glycol 3 Amine 4 CO2Water 6 Basic + * @param propertyName a {@link java.lang.String} object */ - public void setPhysicalPropertyModel(int type); + public void initPhysicalProperties(String propertyName); + + /** + * Calculates thermodynamic and physical properties of a fluid using initThermoProperties() and + * initPhysicalProperties(). + */ + public void initProperties(); /** *

- * clearAll. + * initRefPhases. *

*/ - public void clearAll(); + public void initRefPhases(); /** - * method to get density of a fluid note: without Peneloux volume correction. - * - * @return density with unit kg/m3 + * Calculates thermodynamic properties of a fluid using the init(2) method. */ - public double getDensity(); + public default void initThermoProperties() { + init(2); + } /** - * method to get density of a fluid note: with Peneloux volume correction. + *

+ * initTotalNumberOfMoles. + *

* - * @param unit Supported units are kg/m3, mol/m3 - * @return density in specified unit + * @param change a double */ - public double getDensity(String unit); + public void initTotalNumberOfMoles(double change); /** *

- * getChemicalReactionOperations. + * invertPhaseTypes. *

- * - * @return a {@link neqsim.chemicalReactions.ChemicalReactionOperations} object */ - public ChemicalReactionOperations getChemicalReactionOperations(); + public void invertPhaseTypes(); /** *

@@ -1773,406 +1775,402 @@ public double calcBeta() public void isChemicalSystem(boolean temp); /** - * method to return molar volume of the fluid note: without Peneloux volume correction. - * - * @return molar volume volume in unit m3/mol*1e5 - */ - public double getMolarVolume(); - - /** - * method to return molar volume of the fluid: eventual volume correction included. - * - * @param unit Supported units are m3/mol, litre/mol + *

+ * isForcePhaseTypes. + *

* - * @return molar volume volume in unit + * @return a boolean */ - public double getMolarVolume(String unit); + public boolean isForcePhaseTypes(); /** - * Get molar mass of system. + *

+ * isImplementedCompositionDeriativesofFugacity. + *

* - * @return molar mass in unit kg/mol + * @return a boolean */ - public double getMolarMass(); + public boolean isImplementedCompositionDeriativesofFugacity(); /** - * method to get molar mass of a fluid phase. + *

+ * isImplementedCompositionDeriativesofFugacity. + *

* - * @param unit Supported units are kg/mol, gr/mol - * @return molar mass in specified unit + * @param isImpl a boolean */ - public double getMolarMass(String unit); + public void isImplementedCompositionDeriativesofFugacity(boolean isImpl); /** - * method to get the total enthalpy of a fluid. + *

+ * isImplementedPressureDeriativesofFugacity. + *

* - * @return molar mass in unit J (Joule) + * @return a boolean */ - public double getEnthalpy(); + public boolean isImplementedPressureDeriativesofFugacity(); /** - * method to return total enthalpy in a specified unit. + *

+ * isImplementedTemperatureDeriativesofFugacity. + *

* - * @param unit Supported units are 'J', 'J/mol', 'kJ/kmol', 'J/kg' and 'kJ/kg' - * @return enthalpy in specified unit + * @return a boolean */ - public double getEnthalpy(String unit); + public boolean isImplementedTemperatureDeriativesofFugacity(); /** *

- * calcInterfaceProperties. + * isMultiphaseWaxCheck. *

+ * + * @return a boolean */ - public void calcInterfaceProperties(); + public boolean isMultiphaseWaxCheck(); /** *

- * getInterphaseProperties. + * Getter for property numericDerivatives. *

* - * @return a {@link neqsim.physicalProperties.interfaceProperties.InterphasePropertiesInterface} - * object + * @return a boolean */ - public InterphasePropertiesInterface getInterphaseProperties(); + public boolean isNumericDerivatives(); /** - *

- * Calculate system beta values using Phase.getNumberOfMolesInPhase and getTotalNumberOfMoles. - *

+ * Returns true if phase exists and is not null. + * + * @param i Phase number + * @return True if phase exists, false if not. */ - public void initBeta(); + public boolean isPhase(int i); /** *

- * init_x_y. + * normalizeBeta. *

*/ - public void init_x_y(); + public void normalizeBeta(); /** - * method to return total entropy of the fluid. - * - * @return entropy in unit J/K (Joule/Kelvin) + * Order phases by density. */ - public double getEntropy(); + public void orderByDensity(); /** - * method to return total entropy of the fluid. + *

+ * phaseToSystem. + *

* - * @param unit unit supported units are J/K, J/molK, J/kgK and kJ/kgK - * @return entropy in specified unit + * @param phaseNumber a int + * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public double getEntropy(String unit); + public SystemInterface phaseToSystem(int phaseNumber); /** - * method to return temperature. + *

+ * phaseToSystem. + *

* - * @return temperature in unit Kelvin + * @param phaseNumber1 a int + * @param phaseNumber2 a int + * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public double getTemperature(); + public SystemInterface phaseToSystem(int phaseNumber1, int phaseNumber2); /** - * method to return temperature in a specified unit. + *

+ * phaseToSystem. + *

* - * @param unit Supported units are K, C, R - * @return temperature in specified unit + * @param newPhase a {@link neqsim.thermo.phase.PhaseInterface} object + * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public double getTemperature(String unit); + public SystemInterface phaseToSystem(PhaseInterface newPhase); /** *

- * method to return temperature. + * phaseToSystem. *

* - * @param phaseNumber phase to get temperature of - * @return temperature in unit Kelvin + * @param phaseName a {@link java.lang.String} object + * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public double getTemperature(int phaseNumber); + public SystemInterface phaseToSystem(String phaseName); /** - *

- * chemicalReactionInit. - *

+ * Prints the fluid in a visually appealing way. */ - public void chemicalReactionInit(); + public default void prettyPrint() { + neqsim.thermo.util.readwrite.TablePrinter.printTable(createTable(getFluidName())); + } /** - * Change the phase type of a given phase. + *

+ * readFluid. + *

* - * @param phaseToChange the phase number of the phase to set phase type - * @param pt PhaseType to set + * @param fluidName a {@link java.lang.String} object */ - public void setPhaseType(int phaseToChange, PhaseType pt); + public void readFluid(String fluidName); /** - * Set phase type of all phases. + *

+ * readObject. + *

* - * @param pt PhaseType to set phases as. + * @param ID a int + * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public void setAllPhaseType(PhaseType pt); + public SystemInterface readObject(int ID); /** *

- * Getter for property TC. + * readObjectFromFile. *

* - * @return Critical temperature + * @param filePath a {@link java.lang.String} object + * @param fluidName a {@link java.lang.String} object + * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public double getTC(); + public SystemInterface readObjectFromFile(String filePath, String fluidName); /** *

- * Getter for property TC. + * reInitPhaseType. *

- * - * @param TC Critical temperature to set */ - public void setTC(double TC); + public void reInitPhaseType(); /** *

- * Getter for property PC. + * removeComponent. *

* - * @return Critical pressure + * @param name Name of the component to remove. See NeqSim database for component in the database. */ - public double getPC(); + public void removeComponent(String name); /** *

- * Getter for property PC. + * removePhase. *

* - * @param PC Critical pressure to set + * @param specPhase a int */ - public void setPC(double PC); + public void removePhase(int specPhase); /** *

- * getPhases. + * removePhaseKeepTotalComposition. *

* - * @return an array of {@link neqsim.thermo.phase.PhaseInterface} objects + * @param specPhase a int */ - public PhaseInterface[] getPhases(); + public void removePhaseKeepTotalComposition(int specPhase); /** *

- * Getter for property numberOfPhases. + * renameComponent. *

* - * @return Number of phases used + * @param oldName a {@link java.lang.String} object + * @param newName a {@link java.lang.String} object */ - public int getNumberOfPhases(); + public void renameComponent(String oldName, String newName); /** *

- * Setter for property numberOfPhases. + * replacePhase. *

* - * @param number Number of phases to use. + * @param repPhase a int + * @param newPhase a {@link neqsim.thermo.phase.PhaseInterface} object */ - public void setNumberOfPhases(int number); + public void replacePhase(int repPhase, PhaseInterface newPhase); /** - *

- * Getter for property maxNumberOfPhases. - *

- * - * @return Gets the maximum allowed number of phases to use. + * Set mole fractions of all components to 0. */ - public int getMaxNumberOfPhases(); + public void reset(); /** *

- * Setter for property maxNumberOfPhases. + * reset_x_y. *

- * - * @param maxNumberOfPhases The maximum allowed number of phases to use. */ - public void setMaxNumberOfPhases(int maxNumberOfPhases); + public void reset_x_y(); /** *

- * getGibbsEnergy. + * resetCharacterisation. *

- * - * @return a double */ - public double getGibbsEnergy(); + public void resetCharacterisation(); /** *

- * getHelmholtzEnergy. + * resetDatabase. *

- * - * @return a double */ - public double getHelmholtzEnergy(); + public void resetDatabase(); /** *

- * Getter for property componentNames. + * resetPhysicalProperties. *

- * - * @return Component names in system. */ - public String[] getComponentNames(); + public void resetPhysicalProperties(); /** *

- * Get component by name. + * Save System object to file. *

* - * @param name Name of component - * @return a {@link neqsim.thermo.component.ComponentInterface} object + * @param name File path to save to. */ - public default ComponentInterface getComponent(String name) { - return getPhase(0).getComponent(name); - } + public void save(String name); /** *

- * Get component by index. + * saveFluid. *

* - * @param i Component index - * @return a {@link neqsim.thermo.component.ComponentInterface} object + * @param id a int */ - public default ComponentInterface getComponent(int i) { - return getPhase(0).getComponent(i); - } + public void saveFluid(int id); /** *

- * clone. + * saveFluid. *

* - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @param id a int + * @param text a {@link java.lang.String} object */ - public SystemInterface clone(); + public void saveFluid(int id, String text); /** *

- * getdVdPtn. + * saveObject. *

* - * @return a double + * @param ID a int + * @param text a {@link java.lang.String} object */ - public double getdVdPtn(); + public void saveObject(int ID, String text); /** *

- * getdVdTpn. + * saveObjectToFile. *

* - * @return a double + * @param filePath a {@link java.lang.String} object + * @param fluidName a {@link java.lang.String} object */ - public double getdVdTpn(); + public void saveObjectToFile(String filePath, String fluidName); /** - * method to return specific heat capacity (Cp). - * - * @return Cp in unit J/K + *

+ * saveToDataBase. + *

*/ - public double getCp(); + public void saveToDataBase(); /** - * method to return specific heat capacity (Cp) in a specified unit. + *

+ * setAllComponentsInPhase. + *

* - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK - * @return Cp in specified unit + * @param phase a int */ - public double getCp(String unit); + public void setAllComponentsInPhase(int phase); /** - * method to return heat capacity ratio/adiabatic index/Poisson constant. + * Set phase type of all phases. * - * @return kappa + * @param pt PhaseType to set phases as. */ - public double getKappa(); + public void setAllPhaseType(PhaseType pt); /** *

- * replacePhase. + * setAttractiveTerm. *

* - * @param repPhase a int - * @param newPhase a {@link neqsim.thermo.phase.PhaseInterface} object + * @param i a int */ - public void replacePhase(int repPhase, PhaseInterface newPhase); + public void setAttractiveTerm(int i); /** *

- * getGasPhase. + * Setter for property beta. NB! Sets beta = b for first phase and 1-b for second + * phase, not for multiphase systems. *

* - * @return a {@link neqsim.thermo.phase.PhaseInterface} object + * @param b Beta value to set. */ - public PhaseInterface getGasPhase(); + public void setBeta(double b); /** *

- * getLiquidPhase. + * Setter for property beta for a given phase. *

* - * @return a {@link neqsim.thermo.phase.PhaseInterface} object - */ - public PhaseInterface getLiquidPhase(); - - /** - * method to return compressibility factor of a fluid compressibility factor is defined in EoS - * from PV=ZnRT where V is total volume of fluid. - * - * @return compressibility factor Z + * @param phase Phase number to set beta for. + * @param b Beta value to set. */ - public double getZ(); + public void setBeta(int phase, double b); /** - * method to return viscosity of a fluid. + *

+ * setBmixType. + *

* - * @return viscosity in unit kg/msec + * @param bmixType a int */ - public double getViscosity(); + public void setBmixType(int bmixType); /** - * method to return viscosity in a specified unit. + *

+ * setComponentNames. + *

* - * @param unit Supported units are kg/msec, cP (centipoise), Pas (Pascal*second) - * @return viscosity in specified unit + * @param componentNames an array of {@link java.lang.String} objects */ - public double getViscosity(String unit); + public void setComponentNames(String[] componentNames); /** - * method to return conductivity of a fluid. + *

+ * setComponentNameTag. + *

* - * @return conductivity in unit W/mK + * @param nameTag a {@link java.lang.String} object */ - public double getThermalConductivity(); + public void setComponentNameTag(String nameTag); /** - * method to return thermal conductivity in a specified unit. + *

+ * setComponentNameTagOnNormalComponents. + *

* - * @param unit Supported units are W/mK, W/cmK - * @return conductivity in specified unit + * @param nameTag a {@link java.lang.String} object */ - public double getThermalConductivity(String unit); + public void setComponentNameTagOnNormalComponents(String nameTag); /** - *

- * initRefPhases. - *

+ * Set the flow rate (moles) of all components to zero. */ - public void initRefPhases(); + public void setEmptyFluid(); /** *

- * getFluidName. + * Setter for property info. . *

* - * @return a {@link java.lang.String} object + * @param info a {@link java.lang.String} object */ - public String getFluidName(); + public void setFluidInfo(String info); /** *

@@ -2185,372 +2183,374 @@ public default ComponentInterface getComponent(int i) { /** *

- * Getter for property allowPhaseShift. + * setForcePhaseTypes. *

* - * @return a boolean + * @param forcePhaseTypes a boolean */ - public boolean allowPhaseShift(); + public void setForcePhaseTypes(boolean forcePhaseTypes); /** *

- * Setter for property allowPhaseShift. + * setHeavyTBPfractionAsPlusFraction. *

* - * @param allowPhaseShift a boolean - */ - public void allowPhaseShift(boolean allowPhaseShift); - - /** - * method to return phase fraction of selected phase. - * - * @param phaseTypeName gas/oil/aqueous - * @param unit mole/volume/weight - * @return phase: fraction in specified unit + * @return a boolean */ - public double getPhaseFraction(String phaseTypeName, String unit); + public boolean setHeavyTBPfractionAsPlusFraction(); /** *

- * getProperty. + * setHydrateCheck. *

* - * @param prop a {@link java.lang.String} object - * @param compName a {@link java.lang.String} object - * @param phase a int - * @return a double + * @param hydrateCheck a boolean */ - public double getProperty(String prop, String compName, int phase); + public void setHydrateCheck(boolean hydrateCheck); /** *

- * getProperty. + * setImplementedCompositionDeriativesofFugacity. *

* - * @param prop a {@link java.lang.String} object - * @param phase a int - * @return a double + * @param implementedCompositionDeriativesofFugacity a boolean */ - public double getProperty(String prop, int phase); + public void setImplementedCompositionDeriativesofFugacity( + boolean implementedCompositionDeriativesofFugacity); /** *

- * getProperty. + * setImplementedPressureDeriativesofFugacity. *

* - * @param prop a {@link java.lang.String} object - * @return a double + * @param implementedPressureDeriativesofFugacity a boolean */ - public double getProperty(String prop); + public void setImplementedPressureDeriativesofFugacity( + boolean implementedPressureDeriativesofFugacity); /** *

- * Getter for property standard. + * setImplementedTemperatureDeriativesofFugacity. *

* - * @return a {@link neqsim.standards.StandardInterface} object + * @param implementedTemperatureDeriativesofFugacity a boolean */ - public neqsim.standards.StandardInterface getStandard(); + public void setImplementedTemperatureDeriativesofFugacity( + boolean implementedTemperatureDeriativesofFugacity); /** *

- * Getter for property standard. + * Setter for property initType. *

* - * @param standardName a {@link java.lang.String} object - * @return a {@link neqsim.standards.StandardInterface} object + * @param initType a int */ - public neqsim.standards.StandardInterface getStandard(String standardName); + public void setInitType(int initType); /** *

- * Setter for property standard. + * Setter for property maxNumberOfPhases. *

* - * @param standardName a {@link java.lang.String} object + * @param maxNumberOfPhases The maximum allowed number of phases to use. */ - public void setStandard(String standardName); + public void setMaxNumberOfPhases(int maxNumberOfPhases); /** - *

- * saveToDataBase. - *

+ * method to set mixing rule used for the fluid. + * + * @param type The type of mixing rule to be used for the fluid. 1 - classic mixing rule with all + * kij set to zero 2 -classic mixing rule with kij from NeqSim database 3- classic mixing + * rule with temperature dependent kij 4- Huron Vidal mixing rule with parameters from + * NeqSim database 7 -classic mixing rule with kij of CPA from NeqSim Database 9 + * -classicmixing rule with temperature dependent kij of CPA from NeqSim database + * 10-classic mixing rule with temperature and composition dependent kij of CPA from NeqSim + * database */ - public void saveToDataBase(); + public void setMixingRule(int type); /** - *

- * getMixingRule. - *

+ * method to set the mixing rule for the fluid. * - * @return a int + * @param typename a {@link java.lang.String} object */ - public int getMixingRule(); + public void setMixingRule(String typename); /** *

- * getResultTable. + * setMixingRule. *

* - * @return an array of {@link java.lang.String} objects + * @param typename a {@link java.lang.String} object + * @param GEmodel a {@link java.lang.String} object */ - public String[][] getResultTable(); + public void setMixingRule(String typename, String GEmodel); /** *

- * autoSelectModel. + * setModel. *

* + * @param model a {@link java.lang.String} object * @return a {@link neqsim.thermo.system.SystemInterface} object */ - public SystemInterface autoSelectModel(); + public SystemInterface setModel(String model); /** *

- * autoSelectMixingRule. + * This method is used to set the total molar composition of a fluid. The total flow rate will be + * kept constant. The input mole fractions will be normalized. *

+ * + * @param moles an array of {@link double} objects */ - public void autoSelectMixingRule(); + public void setMolarComposition(double[] moles); /** - * Order phases by density. + * This method is used to set the total molar composition of a characterized fluid. The total flow + * rate will be kept constant. The input mole fractions will be normalized. + * + * @param molefractions is a double array taking the molar fraction of the components in the + * fluid. THe last fraction in the array is the total molefraction of the characterized + * components. */ - public void orderByDensity(); + public void setMolarCompositionOfPlusFluid(double[] molefractions); /** - *

- * addLiquidToGas. - *

+ * This method is used to set the total molar composition of a plus fluid. The total flow rate + * will be kept constant. The input mole fractions will be normalized. * - * @param fraction a double + * @param molefractions is a double array taking the molar fraction of the components in the + * fluid. THe last molfraction is the mole fraction of the plus component */ - public void addLiquidToGas(double fraction); + public void setMolarCompositionPlus(double[] molefractions); /** *

- * addGasToLiquid. + * setMolarFlowRates. *

* - * @param fraction a double + * @param moles an array of {@link double} objects */ - public void addGasToLiquid(double fraction); + public void setMolarFlowRates(double[] moles); /** - * Getter for property totalNumberOfMoles. + * method to specify if calculations should check for more than two fluid phases. * - * @return Total molar flow rate of fluid in unit mol/sec + * @param doMultiPhaseCheck Specify if the calculations should check for more than two fluid + * phases. Default is two fluid phases (gas and liquid). If set to true the program will + * check for gas and multiple liquid phases (eg. gas-oil-aqueous). */ - public double getTotalNumberOfMoles(); + public void setMultiPhaseCheck(boolean doMultiPhaseCheck); /** *

- * Getter for property numberOfMoles. + * setMultiphaseWaxCheck. *

* - * @return a double - * @deprecated Replaced by {@link getTotalNumberOfMoles} + * @param multiphaseWaxCheck a boolean */ - @Deprecated - public default double getNumberOfMoles() { - return getTotalNumberOfMoles(); - } + public void setMultiphaseWaxCheck(boolean multiphaseWaxCheck); /** *

- * Setter for property totalNumberOfMoles. + * Setter for property numberOfPhases. *

* - * @param totalNumberOfMoles Total molar flow rate of fluid in unit mol/sec + * @param number Number of phases to use. */ - public void setTotalNumberOfMoles(double totalNumberOfMoles); + public void setNumberOfPhases(int number); /** *

- * Get phase number of phase of specific type. + * Setter for property numericDerivatives. *

* - * @param pt Phase type to look for. - * @return Phase number + * @param numericDerivatives a boolean */ - public int getPhaseNumberOfPhase(PhaseType pt); + public void setNumericDerivatives(boolean numericDerivatives); /** *

- * Get phase number of phase of specific type. * + * Getter for property PC. *

* - * @param phaseTypeName Name of phase type to look for - * @return Phase number + * @param PC Critical pressure to set */ - public default int getPhaseNumberOfPhase(String phaseTypeName) { - return getPhaseNumberOfPhase(PhaseType.byDesc(phaseTypeName)); - } + public void setPC(double PC); /** *

- * getEmptySystemClone. + * Set phaseArray[phaseIndex] = phase. NB! Transfers the pressure and temperature + * from the currently existing phase object at index numb *

* - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @param phase a {@link neqsim.thermo.phase.PhaseInterface} object + * @param index Phase index to insert object at */ - public SystemInterface getEmptySystemClone(); + public void setPhase(PhaseInterface phase, int index); /** *

- * calcHenrysConstant. + * Indexed setter for property phaseIndex. + * this.phaseIndex[index] = phaseIndex; *

* - * @param component a {@link java.lang.String} object - * @return a double + * @param index a int + * @param phaseIndex a int */ - public double calcHenrysConstant(String component); + public void setPhaseIndex(int index, int phaseIndex); /** - *

- * isImplementedTemperatureDeriativesofFugacity. - *

+ * Change the phase type of a given phase. * - * @return a boolean + * @param phaseToChange the phase number of the phase to set phase type + * @param pt PhaseType to set */ - public boolean isImplementedTemperatureDeriativesofFugacity(); + public void setPhaseType(int phaseToChange, PhaseType pt); /** - *

- * setImplementedTemperatureDeriativesofFugacity. - *

+ * Set the physical property model type for each phase of the System. * - * @param implementedTemperatureDeriativesofFugacity a boolean + * @param type 0 Orginal/default 1 Water 2 Glycol 3 Amine 4 CO2Water 6 Basic */ - public void setImplementedTemperatureDeriativesofFugacity( - boolean implementedTemperatureDeriativesofFugacity); + public void setPhysicalPropertyModel(int type); + + /** + * method to set the pressure of a fluid (same pressure for all phases). + * + * @param pres pressure in unit bara (absolute pressure in bar) + */ + public void setPressure(double pres); + + /** + * method to set the pressure of a fluid (same pressure for all phases). + * + * @param newPressure in specified unit + * @param unit unit can be bar, bara, barg or atm + */ + public void setPressure(double newPressure, String unit); /** *

- * isImplementedPressureDeriativesofFugacity. + * Setter for property solidPhaseCheck. *

* - * @return a boolean + * @param test a boolean */ - public boolean isImplementedPressureDeriativesofFugacity(); + public void setSolidPhaseCheck(boolean test); /** *

- * setImplementedPressureDeriativesofFugacity. + * setSolidPhaseCheck. *

* - * @param implementedPressureDeriativesofFugacity a boolean + * @param solidComponent a {@link java.lang.String} object */ - public void setImplementedPressureDeriativesofFugacity( - boolean implementedPressureDeriativesofFugacity); + public void setSolidPhaseCheck(String solidComponent); /** *

- * isImplementedCompositionDeriativesofFugacity. + * Setter for property standard. *

* - * @return a boolean + * @param standardName a {@link java.lang.String} object */ - public boolean isImplementedCompositionDeriativesofFugacity(); + public void setStandard(String standardName); /** *

- * isImplementedCompositionDeriativesofFugacity. + * Getter for property TC. *

* - * @param isImpl a boolean + * @param TC Critical temperature to set */ - public void isImplementedCompositionDeriativesofFugacity(boolean isImpl); + public void setTC(double TC); /** *

- * setImplementedCompositionDeriativesofFugacity. + * method to set the temperature of a fluid (same temperature for all phases). *

* - * @param implementedCompositionDeriativesofFugacity a boolean + * @param temp a double */ - public void setImplementedCompositionDeriativesofFugacity( - boolean implementedCompositionDeriativesofFugacity); + public void setTemperature(double temp); /** *

- * addCapeOpenProperty. + * setTemperature. *

* - * @param propertyName a {@link java.lang.String} object + * @param newTemperature a double + * @param phaseNumber a int */ - public void addCapeOpenProperty(String propertyName); + public void setTemperature(double newTemperature, int phaseNumber); /** - * Get physical properties of System. + * method to set the temperature of a fluid (same temperature for all phases). * - * @return System properties + * @param newTemperature in specified unit + * @param unit unit can be C or K (Celsius or Kelvin) */ - public SystemProperties getProperties(); - - /** {@inheritDoc} */ - @Override - public boolean equals(Object o); + public void setTemperature(double newTemperature, String unit); - /** {@inheritDoc} */ - @Override - public int hashCode(); + /** + *

+ * setTotalFlowRate. + *

+ * + * @param flowRate a double + * @param flowunit a {@link java.lang.String} object. flow units are: kg/sec, kg/min, kg/hr + * m3/sec, m3/min, m3/hr, mole/sec, mole/min, mole/hr, Sm3/hr, Sm3/day, idSm3/hr, idSm3/day + */ + public void setTotalFlowRate(double flowRate, String flowunit); /** - * Add to component names. + *

+ * Setter for property totalNumberOfMoles. + *

* - * @param name Component name to add + * @param totalNumberOfMoles Total molar flow rate of fluid in unit mol/sec */ - public void addToComponentNames(String name); + public void setTotalNumberOfMoles(double totalNumberOfMoles); /** *

- * addCharacterized. + * setUseTVasIndependentVariables. *

* - * @param charNames an array of {@link java.lang.String} objects - * @param charFlowrate an array of {@link double} objects - * @param molarMass an array of {@link double} objects - * @param relativedensity an array of {@link double} objects - * @param lastIsPlusFraction True if last fraction is a Plus fraction + * @param useTVasIndependentVariables a boolean */ - public void addOilFractions(String[] charNames, double[] charFlowrate, double[] molarMass, - double[] relativedensity, boolean lastIsPlusFraction); + public void setUseTVasIndependentVariables(boolean useTVasIndependentVariables); /** *

- * addCharacterized. + * tuneModel. *

* - * @param charNames an array of {@link java.lang.String} objects - * @param charFlowrate an array of {@link double} objects - * @param molarMass an array of {@link double} objects - * @param relativedensity an array of {@link double} objects - * @param lastIsPlusFraction True if last fraction is a Plus fraction - * @param lumpComponents True if component should be lumped - * @param numberOfPseudoComponents number of pseudo components + * @param model a {@link java.lang.String} object + * @param val a double + * @param phase a int */ - public void addOilFractions(String[] charNames, double[] charFlowrate, double[] molarMass, - double[] relativedensity, boolean lastIsPlusFraction, boolean lumpComponents, - int numberOfPseudoComponents); + public void tuneModel(String model, double val, int phase); /** *

- * addCharacterized. + * useVolumeCorrection. *

* - * @param charNames an array of {@link java.lang.String} objects - * @param charFlowrate an array of {@link double} objects - * @param molarMass an array of {@link double} objects - * @param relativedensity an array of {@link double} objects + * @param volcor a boolean */ - public void addCharacterized(String[] charNames, double[] charFlowrate, double[] molarMass, - double[] relativedensity); + public void useVolumeCorrection(boolean volcor); /** - * Get ideal liquid density of fluid in given unit. + *

+ * write. + *

* - * @param unit {@link java.lang.String} Supported units are kg/m3 and gr/cm3 - * @return a double + * @param name a {@link java.lang.String} object + * @param filename a {@link java.lang.String} object + * @param newfile a boolean */ - public double getIdealLiquidDensity(String unit); + public void write(String name, String filename, boolean newfile); } diff --git a/src/main/java/neqsim/thermo/system/SystemPCSAFT.java b/src/main/java/neqsim/thermo/system/SystemPCSAFT.java index 32bdc2f5a..83fecbbf8 100644 --- a/src/main/java/neqsim/thermo/system/SystemPCSAFT.java +++ b/src/main/java/neqsim/thermo/system/SystemPCSAFT.java @@ -13,8 +13,8 @@ * @version $Id: $Id */ public class SystemPCSAFT extends SystemSrkEos { - private static final long serialVersionUID = 1000; static Logger logger = LogManager.getLogger(SystemPCSAFT.class); + private static final long serialVersionUID = 1000; /** *

@@ -76,19 +76,6 @@ public SystemPCSAFT(double T, double P, boolean checkForSolids) { this.useVolumeCorrection(false); } - /** {@inheritDoc} */ - @Override - public SystemPCSAFT clone() { - SystemPCSAFT clonedSystem = null; - try { - clonedSystem = (SystemPCSAFT) super.clone(); - } catch (Exception ex) { - logger.error("Cloning failed.", ex); - } - - return clonedSystem; - } - /** {@inheritDoc} */ @Override public void addTBPfraction(String componentName2, double numberOfMoles, double molarMass, @@ -114,6 +101,19 @@ public void addTBPfraction(String componentName2, double numberOfMoles, double m } } + /** {@inheritDoc} */ + @Override + public SystemPCSAFT clone() { + SystemPCSAFT clonedSystem = null; + try { + clonedSystem = (SystemPCSAFT) super.clone(); + } catch (Exception ex) { + logger.error("Cloning failed.", ex); + } + + return clonedSystem; + } + /** *

* commonInitialization. diff --git a/src/main/java/neqsim/thermo/system/SystemProperties.java b/src/main/java/neqsim/thermo/system/SystemProperties.java index 3a7f2858f..d1f8b06a6 100644 --- a/src/main/java/neqsim/thermo/system/SystemProperties.java +++ b/src/main/java/neqsim/thermo/system/SystemProperties.java @@ -11,10 +11,20 @@ * @version $Id: $Id */ public class SystemProperties { - private Double[] values; - private String[] names; /** Constant nCols=(16 * 4) + 6. */ public static final int nCols = (16 * 4) + 6; + /** + * Get names of properties. + * + * @return Array of names of properties + */ + public static String[] getPropertyNames() { + SystemProperties p = new SystemProperties(new SystemSrkEos()); + return p.names; + } + private String[] names; + + private Double[] values; /** * Constructur for SystemProperties. @@ -204,14 +214,4 @@ public HashMap getProperties() { public Double[] getValues() { return this.values; } - - /** - * Get names of properties. - * - * @return Array of names of properties - */ - public static String[] getPropertyNames() { - SystemProperties p = new SystemProperties(new SystemSrkEos()); - return p.names; - } } diff --git a/src/main/java/neqsim/thermo/system/SystemSrkCPA.java b/src/main/java/neqsim/thermo/system/SystemSrkCPA.java index 2c5258006..acf5c117c 100644 --- a/src/main/java/neqsim/thermo/system/SystemSrkCPA.java +++ b/src/main/java/neqsim/thermo/system/SystemSrkCPA.java @@ -70,6 +70,16 @@ public SystemSrkCPA(double T, double P, boolean checkForSolids) { } } + /** {@inheritDoc} */ + @Override + public void addComponent(String componentName, double moles) { + // if (componentName.equals("Ca++") || componentName.equals("Na+") || + // componentName.equals("Cl-")) { + // componentName = "NaCl"; + // } + super.addComponent(componentName, moles); + } + /** {@inheritDoc} */ @Override public SystemSrkCPA clone() { @@ -93,14 +103,4 @@ public void commonInitialization() { setImplementedPressureDeriativesofFugacity(true); setImplementedTemperatureDeriativesofFugacity(true); } - - /** {@inheritDoc} */ - @Override - public void addComponent(String componentName, double moles) { - // if (componentName.equals("Ca++") || componentName.equals("Na+") || - // componentName.equals("Cl-")) { - // componentName = "NaCl"; - // } - super.addComponent(componentName, moles); - } } diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index df38a4f0e..b3c91b7f9 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -33,103 +33,103 @@ * This is the base class of the System classes. */ public abstract class SystemThermo implements SystemInterface { - private static final long serialVersionUID = 1000; static Logger logger = LogManager.getLogger(SystemThermo.class); - // Class variables private static final int MAX_PHASES = 6; - // Object metadata - protected String fluidInfo = "No Information Available"; - protected String fluidName = "DefaultName"; - protected String modelName = "Default"; - - // Initialization - boolean isInitialized = false; - protected boolean numericDerivatives = false; - protected int initType = 3; - - private boolean implementedTemperatureDeriativesofFugacity = true; - private boolean implementedPressureDeriativesofFugacity = true; - private boolean implementedCompositionDeriativesofFugacity = true; - protected double criticalTemperature = 0; - protected String[][] resultTable = null; - - protected boolean allowPhaseShift = true; - - private boolean useTVasIndependentVariables = false; - protected double criticalPressure = 0; - private double totalNumberOfMoles = 0; + private static final long serialVersionUID = 1000; - // TODO: componentNameTag is not working yet, a kind of alias-postfix for - // Components from this - // system that will be passed on to other systems. used to find originator of - // specific components - // or - public String componentNameTag = ""; - protected neqsim.thermo.characterization.WaxCharacterise waxCharacterisation = null; protected int a; + protected boolean allowPhaseShift = true; + protected int attractiveTermNumber = 0; - private ArrayList componentNames = new ArrayList(); - // todo: replace numberOfComponents with length of componentNames. - protected int numberOfComponents = 0; - - // protected ArrayList resultArray1 = new ArrayList(); - protected String[] CapeOpenProperties11 = {"molecularWeight", "speedOfSound", - "jouleThomsonCoefficient", "internalEnergy", "internalEnergy.Dtemperature", "gibbsEnergy", - "helmholtzEnergy", "fugacityCoefficient", "logFugacityCoefficient", + // Fraction of moles_in_phase / moles_in_system. + protected double[] beta = new double[MAX_PHASES]; + protected String[] CapeOpenProperties10 = {"molecularWeight", "speedOfSound", + "jouleThomsonCoefficient", "energy", "energy.Dtemperature", "gibbsFreeEnergy", + "helmholtzFreeEnergy", "fugacityCoefficient", "logFugacityCoefficient", "logFugacityCoefficient.Dtemperature", "logFugacityCoefficient.Dpressure", "logFugacityCoefficient.Dmoles", "enthalpy", "enthalpy.Dmoles", "enthalpy.Dtemperature", "enthalpy.Dpressure", "entropy", "entropy.Dtemperature", "entropy.Dpressure", - "entropy.Dmoles", "heatCapacityCp", "heatCapacityCv", "density", "density.Dtemperature", + "entropy.Dmoles", "heatCapacity", "heatCapacityCv", "density", "density.Dtemperature", "density.Dpressure", "density.Dmoles", "volume", "volume.Dpressure", "volume.Dtemperature", "molecularWeight.Dtemperature", "molecularWeight.Dpressure", "molecularWeight.Dmoles", "compressibilityFactor"}; - protected String[] CapeOpenProperties10 = {"molecularWeight", "speedOfSound", - "jouleThomsonCoefficient", "energy", "energy.Dtemperature", "gibbsFreeEnergy", - "helmholtzFreeEnergy", "fugacityCoefficient", "logFugacityCoefficient", + // protected ArrayList resultArray1 = new ArrayList(); + protected String[] CapeOpenProperties11 = {"molecularWeight", "speedOfSound", + "jouleThomsonCoefficient", "internalEnergy", "internalEnergy.Dtemperature", "gibbsEnergy", + "helmholtzEnergy", "fugacityCoefficient", "logFugacityCoefficient", "logFugacityCoefficient.Dtemperature", "logFugacityCoefficient.Dpressure", "logFugacityCoefficient.Dmoles", "enthalpy", "enthalpy.Dmoles", "enthalpy.Dtemperature", "enthalpy.Dpressure", "entropy", "entropy.Dtemperature", "entropy.Dpressure", - "entropy.Dmoles", "heatCapacity", "heatCapacityCv", "density", "density.Dtemperature", + "entropy.Dmoles", "heatCapacityCp", "heatCapacityCv", "density", "density.Dtemperature", "density.Dpressure", "density.Dmoles", "volume", "volume.Dpressure", "volume.Dtemperature", "molecularWeight.Dtemperature", "molecularWeight.Dpressure", "molecularWeight.Dmoles", "compressibilityFactor"}; - protected int attractiveTermNumber = 0; - /** Number of phases in use/existing. */ - protected int numberOfPhases = 2; + public neqsim.thermo.characterization.Characterise characterization = null; + protected boolean checkStability = true; + protected ChemicalReactionOperations chemicalReactionOperations = null; + protected boolean chemicalSystem = false; + private ArrayList componentNames = new ArrayList(); + + // TODO: componentNameTag is not working yet, a kind of alias-postfix for + // Components from this + // system that will be passed on to other systems. used to find originator of + // specific components + // or + public String componentNameTag = ""; + + protected double criticalPressure = 0; + protected double criticalTemperature = 0; + // Object metadata + protected String fluidInfo = "No Information Available"; + + protected String fluidName = "DefaultName"; + private boolean forcePhaseTypes = false; + protected boolean hydrateCheck = false; + + private boolean implementedCompositionDeriativesofFugacity = true; + private boolean implementedPressureDeriativesofFugacity = true; + + private boolean implementedTemperatureDeriativesofFugacity = true; + protected int initType = 3; + protected InterphasePropertiesInterface interfaceProp = null; + + // Initialization + boolean isInitialized = false; /** Maximum allowed number of phases . */ public int maxNumberOfPhases = 2; - /** - * Array of indexes to phaseArray keeping track of the creation order of the phases where 0 is the - * first created phase and the lowest number is the phase created last. - */ - protected int[] phaseIndex; + private int mixingRule = 1; + protected String modelName = "Default"; + protected boolean multiPhaseCheck = false; + private boolean multiphaseWaxCheck = false; + + // todo: replace numberOfComponents with length of componentNames. + protected int numberOfComponents = 0; + /** Number of phases in use/existing. */ + protected int numberOfPhases = 2; + protected boolean numericDerivatives = false; + /** * Array containing all phases of System. NB! Phases are reorered according to density, use * phaseIndex to keep track of the creation order. */ protected PhaseInterface[] phaseArray = new PhaseInterface[MAX_PHASES]; + /** + * Array of indexes to phaseArray keeping track of the creation order of the phases where 0 is the + * first created phase and the lowest number is the phase created last. + */ + protected int[] phaseIndex; // PhaseType of phases belonging to system. protected PhaseType[] phaseType = new PhaseType[MAX_PHASES]; - // Fraction of moles_in_phase / moles_in_system. - protected double[] beta = new double[MAX_PHASES]; - - protected ChemicalReactionOperations chemicalReactionOperations = null; - private int mixingRule = 1; - protected boolean chemicalSystem = false; + protected String[][] resultTable = null; protected boolean solidPhaseCheck = false; - protected boolean multiPhaseCheck = false; - protected boolean hydrateCheck = false; - - protected boolean checkStability = true; - public neqsim.thermo.characterization.Characterise characterization = null; protected neqsim.standards.StandardInterface standard = null; - protected InterphasePropertiesInterface interfaceProp = null; - private boolean multiphaseWaxCheck = false; - private boolean forcePhaseTypes = false; + private double totalNumberOfMoles = 0; + private boolean useTVasIndependentVariables = false; + protected neqsim.thermo.characterization.WaxCharacterise waxCharacterisation = null; /** *

@@ -173,69 +173,308 @@ public SystemThermo(double T, double P, boolean checkForSolids) { /** {@inheritDoc} */ @Override - public int getNumberOfComponents() { - return getComponentNames().length; + public void addCapeOpenProperty(String propertyName) { + String[] tempString = new String[CapeOpenProperties11.length + 1]; + System.arraycopy(CapeOpenProperties11, 0, tempString, 0, CapeOpenProperties11.length); + tempString[CapeOpenProperties11.length] = propertyName; + CapeOpenProperties11 = tempString; + + tempString = new String[CapeOpenProperties10.length + 1]; + System.arraycopy(CapeOpenProperties10, 0, tempString, 0, CapeOpenProperties10.length); + tempString[CapeOpenProperties10.length] = propertyName; + CapeOpenProperties10 = tempString; } /** {@inheritDoc} */ @Override - public void clearAll() { - setTotalNumberOfMoles(0); - phaseType[0] = PhaseType.byValue(1); - phaseType[1] = PhaseType.byValue(0); - numberOfComponents = 0; - setNumberOfPhases(2); - beta[0] = 1.0; - beta[1] = 1.0; - beta[2] = 1.0; - beta[3] = 1.0; - beta[4] = 1.0; - beta[5] = 1.0; - chemicalSystem = false; - - double oldTemp = phaseArray[0].getTemperature(); - double oldPres = phaseArray[0].getPressure(); + public void addCharacterized(String[] charNames, double[] charFlowrate, double[] molarMass, + double[] relativedensity) { + if (charNames.length != charFlowrate.length) { + logger.error("component names and mole fractions need to be same length..."); + } + for (int i = 0; i < charNames.length; i++) { + addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); + } + } - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - try { - phaseArray[i] = phaseArray[i].getClass().getDeclaredConstructor().newInstance(); - } catch (Exception ex) { - logger.error("err ", ex); + /** {@inheritDoc} */ + @Override + public void addComponent(ComponentInterface inComponent) { + if (inComponent.isIsTBPfraction()) { + addTBPfraction(inComponent.getComponentName(), inComponent.getNumberOfmoles(), + inComponent.getMolarMass(), inComponent.getNormalLiquidDensity()); + String componentName = inComponent.getComponentName(); + changeComponentName(componentName + "_PC", componentName.replaceFirst("_PC", "")); + for (int i = 0; i < numberOfPhases; i++) { + getPhase(i).getComponent(componentName) + .setAttractiveTerm(inComponent.getAttractiveTermNumber()); + getPhase(i).getComponent(componentName).setTC(inComponent.getTC()); + getPhase(i).getComponent(componentName).setPC(inComponent.getPC()); + getPhase(i).getComponent(componentName).setMolarMass(inComponent.getMolarMass()); + getPhase(i).getComponent(componentName).setComponentType("TBPfraction"); + getPhase(i).getComponent(componentName) + .setNormalLiquidDensity(inComponent.getNormalLiquidDensity()); + getPhase(i).getComponent(componentName) + .setNormalBoilingPoint(inComponent.getNormalBoilingPoint()); + getPhase(i).getComponent(componentName).setAcentricFactor(inComponent.getAcentricFactor()); + getPhase(i).getComponent(componentName).setCriticalVolume(inComponent.getCriticalVolume()); + getPhase(i).getComponent(componentName).setRacketZ(inComponent.getRacketZ()); + getPhase(i).getComponent(componentName).setRacketZCPA(inComponent.getRacketZCPA()); + getPhase(i).getComponent(componentName).setIsTBPfraction(true); + getPhase(i).getComponent(componentName) + .setParachorParameter(inComponent.getParachorParameter()); + getPhase(i).getComponent(componentName) + .setTriplePointTemperature(inComponent.getTriplePointTemperature()); + getPhase(i).getComponent(componentName) + .setIdealGasEnthalpyOfFormation(inComponent.getIdealGasEnthalpyOfFormation()); + getPhase(i).getComponent(componentName).setCpA(inComponent.getCpA()); + getPhase(i).getComponent(componentName).setCpB(inComponent.getCpB()); + getPhase(i).getComponent(componentName).setCpC(inComponent.getCpC()); + getPhase(i).getComponent(componentName).setCpD(inComponent.getCpD()); } - phaseArray[i].setTemperature(oldTemp); - phaseArray[i].setPressure(oldPres); + } else { + addComponent(inComponent.getComponentName(), inComponent.getNumberOfmoles()); } } /** {@inheritDoc} */ @Override - public void resetCharacterisation() { - int numberOfLumpedComps = characterization.getLumpingModel().getNumberOfLumpedComponents(); - characterization = new Characterise(this); - characterization.getLumpingModel().setNumberOfLumpedComponents(numberOfLumpedComps); + public void addComponent(int index, double moles) { + if (index >= getPhase(0).getNumberOfComponents()) { + logger.error("componentIndex higher than number of components in system"); + return; + } + + for (PhaseInterface tmpPhase : phaseArray) { + // TODO: adding moles to all phases, not just the active ones. + if (tmpPhase != null) { + tmpPhase.addMolesChemReac(index, moles, moles); + } + } + setTotalNumberOfMoles(getTotalNumberOfMoles() + moles); } /** {@inheritDoc} */ @Override - public SystemInterface addFluid(SystemInterface addSystem) { - boolean addedNewComponent = false; - int index = -1; - for (int i = 0; i < addSystem.getPhase(0).getNumberOfComponents(); i++) { - if (!getPhase(0).hasComponent(addSystem.getPhase(0).getComponent(i).getComponentName())) { - index = -1; - addedNewComponent = true; + public void addComponent(int index, double moles, int phaseNumber) { + if (index >= getPhase(0).getNumberOfComponents()) { + logger.error("componentIndex higher than number of components in system"); + return; + } + double k = 1.0; + + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + if (phaseNumber == i) { + k = 1.0; } else { - index = getPhase(0).getComponent(addSystem.getPhase(0).getComponent(i).getComponentName()) - .getComponentNumber(); + k = 0.0; } + phaseArray[phaseIndex[i]].addMolesChemReac(index, moles * k, moles); + } - if (index != -1) { - addComponent(index, addSystem.getPhase(0).getComponent(i).getNumberOfmoles()); - } else if (addSystem.getPhase(0).getComponent(i).isIsTBPfraction()) { - addTBPfraction( - addSystem.getPhase(0).getComponent(i).getComponentName().replaceFirst("_PC", ""), - addSystem.getPhase(0).getComponent(i).getNumberOfmoles(), - addSystem.getPhase(0).getComponent(i).getMolarMass(), + setTotalNumberOfMoles(getTotalNumberOfMoles() + moles); + } + + /** {@inheritDoc} */ + @Override + public void addComponent(String componentName, double moles) { + componentName = ComponentInterface.getComponentNameFromAlias(componentName); + + int index = 0; + + boolean addForFirstTime = true; + for (int p = 0; p < componentNames.size(); p++) { + if (componentNames.get(p).equals(componentName)) { + addForFirstTime = false; + index = p; + break; + } + } + + if (addForFirstTime) { + if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "addComponent", "componentName", + "with value " + componentName + " not found in database.")); + } + if (moles < 0.0) { + String msg = "is negative input for component: " + componentName; + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "addComponent", "moles", msg)); + } + // System.out.println("adding " + componentName); + componentNames.add(componentName); + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + getPhase(i).addComponent(componentName, moles, moles, numberOfComponents); + getPhase(i).setAttractiveTerm(attractiveTermNumber); + } + numberOfComponents++; + } else { + for (PhaseInterface tmpPhase : phaseArray) { + if (tmpPhase != null + && (tmpPhase.getComponent(componentName).getNumberOfMolesInPhase() + moles) < 0.0) { + init(0); + break; + } + } + + // System.out.println("adding chem reac " + componentName); + for (PhaseInterface tmpPhase : phaseArray) { + // TODO: adding moles to all phases, not just the active ones. + if (tmpPhase != null) { + tmpPhase.addMolesChemReac(index, moles, moles); + } + } + } + setTotalNumberOfMoles(getTotalNumberOfMoles() + moles); + } + + /** {@inheritDoc} */ + @Override + public void addComponent(String componentName, double moles, double TC, double PC, double acs) { + componentName = ComponentInterface.getComponentNameFromAlias(componentName); + + String comNam = componentName; + if (getPhase(0).hasComponent(componentName)) { + addComponent(componentName, moles); + } else { + addComponent("default", moles); + comNam = "default"; + // componentNames.set(componentNames.indexOf("default"), componentName); + } + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + getPhase(i).getComponent(comNam).setComponentName(componentName); + getPhase(i).getComponent(componentName).setTC(TC); + getPhase(i).getComponent(componentName).setPC(PC); + getPhase(i).getComponent(componentName).setAcentricFactor(acs); + } + if (comNam.equals("default")) { + componentNames.remove("default"); + componentNames.add(componentName); + } + } + + /** {@inheritDoc} */ + @Override + public void addComponent(String componentName, double moles, int phaseNumber) { + componentName = ComponentInterface.getComponentNameFromAlias(componentName); + + if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { + throw new RuntimeException("No component with name: " + componentName + " in database"); + } + + for (int p = 0; p < componentNames.size(); p++) { + if (componentNames.get(p).equals(componentName)) { + addComponent(p, moles, phaseNumber); + return; + } + } + + // Add new component + if (moles < 0.0) { + String msg = "Negative input number of moles."; + neqsim.util.exception.InvalidInputException ex = + new neqsim.util.exception.InvalidInputException(this, "addComponent", "moles", msg); + throw new RuntimeException(ex); + } + + componentNames.add(componentName); + double k = 1.0; + setTotalNumberOfMoles(getTotalNumberOfMoles() + moles); + + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + if (phaseNumber == i) { + k = 1.0; + } else { + k = 1.0e-30; + } + getPhase(i).addComponent(componentName, moles, moles * k, numberOfComponents); + getPhase(i).setAttractiveTerm(attractiveTermNumber); + } + numberOfComponents++; + } + + /** {@inheritDoc} */ + @Override + public void addComponent(String componentName, double value, String unitName) { + componentName = ComponentInterface.getComponentNameFromAlias(componentName); + + if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { + throw new RuntimeException("No component with name: " + componentName + " in database"); + } + + double molarmass = 0.0; + double stddens = 0.0; + double boilp = 0.0; + try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); + java.sql.ResultSet dataSet = + database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'"))) { + dataSet.next(); + molarmass = Double.parseDouble(dataSet.getString("molarmass")) / 1000.0; + stddens = Double.parseDouble(dataSet.getString("stddens")); + boilp = Double.parseDouble(dataSet.getString("normboil")); + } catch (Exception ex) { + // todo: mole amount may be not set. should not be caught? + logger.error("failed ", ex); + } + neqsim.util.unit.Unit unit = + new neqsim.util.unit.RateUnit(value, unitName, molarmass, stddens, boilp); + double SIval = unit.getSIvalue(); + // System.out.println("number of moles " + SIval); + this.addComponent(componentName, SIval); + } + + /** {@inheritDoc} */ + @Override + public void addComponent(String componentName, double value, String name, int phase) { + componentName = ComponentInterface.getComponentNameFromAlias(componentName); + + if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { + throw new RuntimeException("No component with name: " + componentName + " in database"); + } + + double molarmass = 0.0; + double stddens = 0.0; + double boilp = 0.0; + try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); + java.sql.ResultSet dataSet = + database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'"))) { + dataSet.next(); + molarmass = Double.parseDouble(dataSet.getString("molarmass")) / 1000.0; + stddens = Double.parseDouble(dataSet.getString("stddens")); + boilp = Double.parseDouble(dataSet.getString("normboil")); + } catch (Exception ex) { + logger.error("failed ", ex); + throw new RuntimeException(ex); + } + neqsim.util.unit.Unit unit = + new neqsim.util.unit.RateUnit(value, name, molarmass, stddens, boilp); + double SIval = unit.getSIvalue(); + // System.out.println("number of moles " + SIval); + this.addComponent(componentName, SIval, phase); + } + + /** {@inheritDoc} */ + @Override + public SystemInterface addFluid(SystemInterface addSystem) { + boolean addedNewComponent = false; + int index = -1; + for (int i = 0; i < addSystem.getPhase(0).getNumberOfComponents(); i++) { + if (!getPhase(0).hasComponent(addSystem.getPhase(0).getComponent(i).getComponentName())) { + index = -1; + addedNewComponent = true; + } else { + index = getPhase(0).getComponent(addSystem.getPhase(0).getComponent(i).getComponentName()) + .getComponentNumber(); + } + + if (index != -1) { + addComponent(index, addSystem.getPhase(0).getComponent(i).getNumberOfmoles()); + } else if (addSystem.getPhase(0).getComponent(i).isIsTBPfraction()) { + addTBPfraction( + addSystem.getPhase(0).getComponent(i).getComponentName().replaceFirst("_PC", ""), + addSystem.getPhase(0).getComponent(i).getNumberOfmoles(), + addSystem.getPhase(0).getComponent(i).getMolarMass(), addSystem.getPhase(0).getComponent(i).getNormalLiquidDensity()); } else { if (addSystem.getPhase(0).getComponent(i).isIsTBPfraction()) { @@ -269,95 +508,20 @@ public SystemInterface addFluid(SystemInterface addSystem, int phase) { /** {@inheritDoc} */ @Override - public void addPhase() { - /* - * if (maxNumberOfPhases < 6 && !hydrateCheck) { ArrayList phaseList = new ArrayList(0); for - * (int i = 0; i < numberOfPhases; i++) { phaseList.add(phaseArray[i]); } // add the new phase - * phaseList.add(phaseArray[0].clone()); beta[phaseList.size() - 1] = 1.0e-8; // beta[1] -= - * beta[1]/1.0e5; - * - * PhaseInterface[] phaseArray2 = new PhaseInterface[numberOfPhases + 1]; - * - * for (int i = 0; i < numberOfPhases + 1; i++) { phaseArray2[i] = (PhaseInterface) - * phaseList.get(i); } - * - * phaseArray = phaseArray2; - * - * System.out.println("number of phases " + numberOfPhases); if (maxNumberOfPhases < - * numberOfPhases) { maxNumberOfPhases = numberOfPhases; } } - */ - numberOfPhases++; + public void addGasToLiquid(double fraction) { + for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { + double change = getPhase(0).getComponent(i).getNumberOfMolesInPhase() * fraction; + addComponent(i, -change, 0); + addComponent(i, change, 1); + } } /** *

- * addSolidPhase. + * addHydratePhase. *

*/ - public void addSolidPhase() { - if (!multiPhaseCheck) { - setMultiPhaseCheck(true); - } - phaseArray[3] = new PhasePureComponentSolid(); - phaseArray[3].setTemperature(phaseArray[0].getTemperature()); - phaseArray[3].setPressure(phaseArray[0].getPressure()); - for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { - if (getPhase(0).getComponent(i).isIsTBPfraction()) { - phaseArray[3].addComponent("default", getPhase(0).getComponent(i).getNumberOfmoles(), - getPhase(0).getComponent(i).getNumberOfmoles(), i); - phaseArray[3].getComponent(i).setComponentName(getPhase(0).getComponent(i).getName()); - phaseArray[3].getComponent(i).setIsPlusFraction(true); - } else { - phaseArray[3].addComponent(getPhase(0).getComponent(i).getName(), - getPhase(0).getComponent(i).getNumberOfmoles(), - getPhase(0).getComponent(i).getNumberOfmoles(), i); - } - } - ((PhaseSolid) phaseArray[3]).setSolidRefFluidPhase(phaseArray[0]); - - if (getMaxNumberOfPhases() < 4) { - setMaxNumberOfPhases(4); - } - } - - /** {@inheritDoc} */ - @Override - public void addSolidComplexPhase(String type) { - if (!multiPhaseCheck) { - setMultiPhaseCheck(true); - } - addHydratePhase(); - if (type.equalsIgnoreCase("wax")) { - phaseArray[5] = new PhaseWax(); - } else { - phaseArray[5] = new PhaseSolidComplex(); - } - - phaseArray[5].setTemperature(phaseArray[0].getTemperature()); - phaseArray[5].setPressure(phaseArray[0].getPressure()); - phaseArray[5].setType(PhaseType.WAX); - for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { - if (getPhase(0).getComponent(i).isIsTBPfraction()) { - phaseArray[5].addComponent(getPhase(0).getComponent(i).getName(), - getPhase(0).getComponent(i).getNumberOfmoles(), - getPhase(0).getComponent(i).getNumberOfmoles(), i); - phaseArray[5].getComponent(i).setIsPlusFraction(true); - } else { - phaseArray[5].addComponent(getPhase(0).getComponent(i).getName(), - getPhase(0).getComponent(i).getNumberOfmoles(), - getPhase(0).getComponent(i).getNumberOfmoles(), i); - } - } - ((PhaseSolid) phaseArray[5]).setSolidRefFluidPhase(phaseArray[0]); - setNumberOfPhases(6); - } - - /** - *

- * addHydratePhase. - *

- */ - public void addHydratePhase() { + public void addHydratePhase() { if (!multiPhaseCheck) { setMultiPhaseCheck(true); } @@ -432,356 +596,236 @@ public void addHydratePhase2() { /** {@inheritDoc} */ @Override - public void setAllComponentsInPhase(int phase) { - for (int k = 0; k < numberOfPhases; k++) { - for (int i = 0; i < numberOfComponents; i++) { - if (phase != k) { - // System.out.println("moles of comp: " + i + " " + - // phaseArray[k].getComponents()[i].getNumberOfMolesInPhase()); - phaseArray[phase].addMoles(i, - (phaseArray[k].getComponents()[i].getNumberOfMolesInPhase() * (1.0 - 0.01))); - phaseArray[k].addMoles(i, - -(phaseArray[k].getComponents()[i].getNumberOfMolesInPhase() * (1.0 - 0.01))); - phaseArray[k].getComponents()[i] - .setx(phaseArray[k].getComponents()[i].getNumberOfMolesInPhase() - / phaseArray[k].getNumberOfMolesInPhase()); - // System.out.println("moles of comp after: " + i + " " + - // phaseArray[k].getComponents()[i].getNumberOfMolesInPhase()); - } - } + public void addLiquidToGas(double fraction) { + for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { + double change = getPhase(1).getComponent(i).getNumberOfMolesInPhase() * fraction; + addComponent(i, change, 0); + addComponent(i, -change, 1); } - initBeta(); - init(1); } /** {@inheritDoc} */ @Override - public void removePhase(int specPhase) { - setTotalNumberOfMoles(getTotalNumberOfMoles() - getPhase(specPhase).getNumberOfMolesInPhase()); + public void addOilFractions(String[] charNames, double[] charFlowrate, double[] molarMass, + double[] relativedensity, boolean lastIsPlusFraction) { + addOilFractions(charNames, charFlowrate, molarMass, relativedensity, lastIsPlusFraction, true, + 12); + } - for (int j = 0; j < numberOfPhases; j++) { - for (int i = 0; i < numberOfComponents; i++) { - getPhase(j).getComponents()[i] - .setNumberOfmoles(getPhase(j).getComponents()[i].getNumberOfmoles() - - getPhase(specPhase).getComponents()[i].getNumberOfMolesInPhase()); - } + /** {@inheritDoc} */ + @Override + public void addOilFractions(String[] charNames, double[] charFlowrate, double[] molarMass, + double[] relativedensity, boolean lastIsPlusFraction, boolean lumpComponents, + int numberOfPseudoComponents) { + if (charNames.length != charFlowrate.length) { + logger.error("component names and mole fractions need to be same length..."); } - ArrayList phaseList = new ArrayList(0); - for (int i = 0; i < numberOfPhases; i++) { - if (specPhase != i) { - phaseList.add(phaseArray[phaseIndex[i]]); - } + for (int i = 0; i < charNames.length - 1; i++) { + addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); } - - // phaseArray = new PhaseInterface[numberOfPhases - 1]; - for (int i = 0; i < numberOfPhases - 1; i++) { - // phaseArray[i] = (PhaseInterface) phaseList.get(i); - if (i >= specPhase) { - phaseIndex[i] = phaseIndex[i + 1]; - phaseType[i] = phaseType[i + 1]; + int i = charNames.length - 1; + if (lastIsPlusFraction) { + addPlusFraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); + } else { + addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); + } + createDatabase(true); + if (lastIsPlusFraction) { + getCharacterization().getLumpingModel().setNumberOfPseudoComponents(numberOfPseudoComponents); + if (lumpComponents) { + getCharacterization().setLumpingModel("PVTlumpingModel"); + } else { + getCharacterization().setLumpingModel("no lumping"); } + getCharacterization().characterisePlusFraction(); } - numberOfPhases--; + setMixingRule(getMixingRule()); + setMultiPhaseCheck(true); + init(0); } /** {@inheritDoc} */ @Override - public void removePhaseKeepTotalComposition(int specPhase) { - ArrayList phaseList = new ArrayList(0); - for (int i = 0; i < numberOfPhases; i++) { - if (specPhase != i) { - phaseList.add(phaseArray[phaseIndex[i]]); - } - } - - // phaseArray = new PhaseInterface[numberOfPhases - 1]; - for (int i = 0; i < numberOfPhases - 1; i++) { - // phaseArray[i] = (PhaseInterface) phaseList.get(i); - if (i >= specPhase) { - phaseIndex[i] = phaseIndex[i + 1]; - phaseType[i] = phaseType[i + 1]; - } - } - numberOfPhases--; + public void addPhase() { + /* + * if (maxNumberOfPhases < 6 && !hydrateCheck) { ArrayList phaseList = new ArrayList(0); for + * (int i = 0; i < numberOfPhases; i++) { phaseList.add(phaseArray[i]); } // add the new phase + * phaseList.add(phaseArray[0].clone()); beta[phaseList.size() - 1] = 1.0e-8; // beta[1] -= + * beta[1]/1.0e5; + * + * PhaseInterface[] phaseArray2 = new PhaseInterface[numberOfPhases + 1]; + * + * for (int i = 0; i < numberOfPhases + 1; i++) { phaseArray2[i] = (PhaseInterface) + * phaseList.get(i); } + * + * phaseArray = phaseArray2; + * + * System.out.println("number of phases " + numberOfPhases); if (maxNumberOfPhases < + * numberOfPhases) { maxNumberOfPhases = numberOfPhases; } } + */ + numberOfPhases++; } /** {@inheritDoc} */ @Override - public void replacePhase(int repPhase, PhaseInterface newPhase) { - for (int i = 0; i < 2; i++) { - phaseArray[i] = newPhase.clone(); + public void addPhaseFractionToPhase(double fraction, String specification, String fromPhaseName, + String toPhaseName) { + if (!(hasPhaseType(fromPhaseName) && hasPhaseType(toPhaseName) || fraction < 1e-30)) { + return; } - setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); + int phaseNumbFrom = getPhaseNumberOfPhase(fromPhaseName); + int phaseNumbTo = getPhaseNumberOfPhase(toPhaseName); + for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { + double change = getPhase(phaseNumbFrom).getComponent(i).getNumberOfMolesInPhase() * fraction; + addComponent(i, change, phaseNumbTo); + addComponent(i, -change, phaseNumbFrom); + } + init_x_y(); } /** {@inheritDoc} */ @Override - public SystemThermo clone() { - SystemThermo clonedSystem = null; - try { - clonedSystem = (SystemThermo) super.clone(); - // clonedSystem.chemicalReactionOperations = (ChemicalReactionOperations) - // chemicalReactionOperations.clone(); - } catch (Exception ex) { - logger.error("Cloning failed.", ex); + public void addPhaseFractionToPhase(double fraction, String specification, String specifiedStream, + String fromPhaseName, String toPhaseName) { + double moleFraction = fraction; + if (!hasPhaseType(fromPhaseName) || !hasPhaseType(toPhaseName) || fraction < 1e-30) { + return; } + int phaseNumbFrom = getPhaseNumberOfPhase(fromPhaseName); + int phaseNumbTo = getPhaseNumberOfPhase(toPhaseName); - clonedSystem.beta = beta.clone(); - clonedSystem.attractiveTermNumber = attractiveTermNumber; - clonedSystem.phaseType = phaseType.clone(); - clonedSystem.phaseIndex = phaseIndex.clone(); + if (specifiedStream.equals("feed")) { + moleFraction = fraction; + } else if (specifiedStream.equals("product")) { + // double specFractionFrom = getPhaseFraction(specification, fromPhaseName); + double specFractionTo = getPhaseFraction(specification, toPhaseName); - clonedSystem.componentNames = new ArrayList(componentNames); - if (interfaceProp != null) { - // clonedSystem.interfaceProp = (InterphasePropertiesInterface) - // interfaceProp.clone(); - } - clonedSystem.characterization = characterization.clone(); - if (clonedSystem.waxCharacterisation != null) { - clonedSystem.waxCharacterisation = waxCharacterisation.clone(); - } + double moleFractionFrom = getMoleFraction(phaseNumbFrom); + double moleFractionTo = getMoleFraction(phaseNumbTo); - System.arraycopy(this.beta, 0, clonedSystem.beta, 0, beta.length); - System.arraycopy(this.phaseType, 0, clonedSystem.phaseType, 0, phaseType.length); - System.arraycopy(this.phaseIndex, 0, clonedSystem.phaseIndex, 0, phaseIndex.length); + if (specification.equals("volume") || specification.equals("mass")) { + double test = fraction * specFractionTo / (fraction * specFractionTo + specFractionTo); + moleFraction = test * moleFractionTo / specFractionTo; + } else if (specification.equals("mole")) { + double test = fraction * moleFractionTo / (fraction * moleFractionTo + moleFractionTo); + moleFraction = test; + } - clonedSystem.phaseArray = phaseArray.clone(); - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - clonedSystem.phaseArray[i] = phaseArray[i].clone(); + moleFraction = moleFraction * moleFractionTo / moleFractionFrom; + if (moleFraction > moleFractionFrom) { + logger.debug("error in addPhaseFractionToPhase()...to low fraction in from phase"); + moleFraction = moleFractionFrom; + } } - return clonedSystem; + for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { + double change = 0.0; + change = getPhase(phaseNumbFrom).getComponent(i).getNumberOfMolesInPhase() * moleFraction; + addComponent(i, change, phaseNumbTo); + addComponent(i, -change, phaseNumbFrom); + } + init_x_y(); } /** {@inheritDoc} */ @Override - public SystemInterface getEmptySystemClone() { - int phaseNumber = 0; - - SystemInterface newSystem = this.clone(); - - for (int j = 0; j < getMaxNumberOfPhases(); j++) { - phaseNumber = j; - for (int i = 0; i < getPhase(j).getNumberOfComponents(); i++) { - newSystem.getPhase(j).getComponents()[i].setNumberOfmoles( - getPhase(phaseNumber).getComponents()[i].getNumberOfMolesInPhase() / 1.0e30); - newSystem.getPhase(j).getComponents()[i].setNumberOfMolesInPhase( - getPhase(phaseNumber).getComponents()[i].getNumberOfMolesInPhase() / 1.0e30); - } + public void addPlusFraction(String componentName, double numberOfMoles, double molarMass, + double density) { + addTBPfraction(componentName, numberOfMoles, molarMass, density); + componentName = (componentName + "_" + "PC"); // getFluidName()); + for (int i = 0; i < numberOfPhases; i++) { + // System.out.println("comp " + componentName); + getPhase(i).getComponent(componentName).setIsPlusFraction(true); + getPhase(i).getComponent(componentName).setCriticalViscosity( + 7.94830 * Math.sqrt(1e3 * getPhase(i).getComponent(componentName).getMolarMass()) + * Math.pow(getPhase(i).getComponent(componentName).getPC(), 2.0 / 3.0) + / Math.pow(getPhase(i).getComponent(componentName).getTC(), 1.0 / 6.0) * 1e-7); } - - newSystem.setTotalNumberOfMoles(getPhase(phaseNumber).getNumberOfMolesInPhase() / 1.0e30); - - newSystem.init(0); - // newSystem.init(1); - return newSystem; } /** {@inheritDoc} */ @Override - public SystemInterface phaseToSystem(PhaseInterface newPhase) { - // TODO: other phaseToSystem functions returns clones. - for (int i = 0; i < newPhase.getNumberOfComponents(); i++) { - newPhase.getComponents()[i] - .setNumberOfmoles(newPhase.getComponents()[i].getNumberOfMolesInPhase()); - } - - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - phaseArray[i] = newPhase.clone(); - } - - setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); - this.init(0); - setNumberOfPhases(1); - setPhaseType(0, newPhase.getType()); - initBeta(); - init_x_y(); - this.init(1); - return this; - } + public void addSalt(String componentName, double value) { + double val1 = 1e-20; + double val2 = 1e-20; + try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); + java.sql.ResultSet dataSet = database + .getResultSet("SELECT * FROM compsalt WHERE SaltName='" + componentName + "'")) { + dataSet.next(); + String name1 = dataSet.getString("ion1").trim(); + val1 = Double.parseDouble(dataSet.getString("stoc1")) * value; + this.addComponent(name1, val1); - /** {@inheritDoc} */ - @Override - public SystemInterface phaseToSystem(String phaseName) { - try { - for (int j = 0; j < getMaxNumberOfPhases(); j++) { - if (this.getPhase(j).getPhaseTypeName().equals(phaseName)) { - return phaseToSystem(j); - } - } + String name2 = dataSet.getString("ion2").trim(); + val2 = Double.parseDouble(dataSet.getString("stoc2")) * value; + this.addComponent(name2, val2); + logger.info("ok adding salts. Ions: " + name1 + ", " + name2); } catch (Exception ex) { - logger.error("error....." + fluidName + " has no phase .... " + phaseName - + " ..... returning phase number 0"); + logger.error("failed ", ex); } - return phaseToSystem(0); } /** {@inheritDoc} */ @Override - public SystemInterface phaseToSystem(int phaseNumber) { - SystemInterface newSystem = this.clone(); - - for (int j = 0; j < getMaxNumberOfPhases(); j++) { - for (int i = 0; i < getPhase(j).getNumberOfComponents(); i++) { - newSystem.getPhase(j).getComponent(i) - .setNumberOfmoles(getPhase(phaseNumber).getComponent(i).getNumberOfMolesInPhase()); - newSystem.getPhase(j).getComponent(i).setNumberOfMolesInPhase( - getPhase(phaseNumber).getComponent(i).getNumberOfMolesInPhase()); - } + public void addSolidComplexPhase(String type) { + if (!multiPhaseCheck) { + setMultiPhaseCheck(true); + } + addHydratePhase(); + if (type.equalsIgnoreCase("wax")) { + phaseArray[5] = new PhaseWax(); + } else { + phaseArray[5] = new PhaseSolidComplex(); } - newSystem.setTotalNumberOfMoles(getPhase(phaseNumber).getNumberOfMolesInPhase()); - - newSystem.init(0); - newSystem.setNumberOfPhases(1); - newSystem.setPhaseType(0, getPhase(phaseNumber).getType()); // phaseType[phaseNumber]); - newSystem.init(1); - return newSystem; - } - - /** {@inheritDoc} */ - @Override - public SystemInterface phaseToSystem(int phaseNumber1, int phaseNumber2) { - SystemInterface newSystem = this.clone(); - - for (int j = 0; j < getMaxNumberOfPhases(); j++) { - for (int i = 0; i < getPhase(j).getNumberOfComponents(); i++) { - newSystem.getPhases()[j].getComponents()[i] - .setNumberOfmoles(getPhase(phaseNumber1).getComponents()[i].getNumberOfMolesInPhase() - + getPhase(phaseNumber2).getComponents()[i].getNumberOfMolesInPhase()); - newSystem.getPhases()[j].getComponents()[i].setNumberOfMolesInPhase( - getPhase(phaseNumber1).getComponents()[i].getNumberOfMolesInPhase() - + getPhase(phaseNumber2).getComponents()[i].getNumberOfMolesInPhase()); + phaseArray[5].setTemperature(phaseArray[0].getTemperature()); + phaseArray[5].setPressure(phaseArray[0].getPressure()); + phaseArray[5].setType(PhaseType.WAX); + for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { + if (getPhase(0).getComponent(i).isIsTBPfraction()) { + phaseArray[5].addComponent(getPhase(0).getComponent(i).getName(), + getPhase(0).getComponent(i).getNumberOfmoles(), + getPhase(0).getComponent(i).getNumberOfmoles(), i); + phaseArray[5].getComponent(i).setIsPlusFraction(true); + } else { + phaseArray[5].addComponent(getPhase(0).getComponent(i).getName(), + getPhase(0).getComponent(i).getNumberOfmoles(), + getPhase(0).getComponent(i).getNumberOfmoles(), i); } } - - newSystem.setTotalNumberOfMoles(getPhase(phaseNumber1).getNumberOfMolesInPhase() - + getPhase(phaseNumber2).getNumberOfMolesInPhase()); - - newSystem.init(0); - - newSystem.setNumberOfPhases(1); - // newSystem.setPhaseType(0, - // getPhase(phaseNumber1).getType()); //phaseType[phaseNumber]); - newSystem.init(1); - return newSystem; + ((PhaseSolid) phaseArray[5]).setSolidRefFluidPhase(phaseArray[0]); + setNumberOfPhases(6); } - /** {@inheritDoc} */ - @Override - public void setTotalFlowRate(double flowRate, String flowunit) { - init(0); - try { - init(1); - } catch (Exception e) { - logger.error(e.getMessage()); - } - double density = 0.0; - if (flowunit.equals("Am3/hr") || flowunit.equals("Am3/min") || flowunit.equals("Am3/sec")) { - initPhysicalProperties("density"); - } - - density = getPhase(0).getDensity("kg/m3"); - if (flowunit.equals("idSm3/hr")) { - density = getIdealLiquidDensity("kg/m3"); + /** + *

+ * addSolidPhase. + *

+ */ + public void addSolidPhase() { + if (!multiPhaseCheck) { + setMultiPhaseCheck(true); } - neqsim.util.unit.Unit unit = - new neqsim.util.unit.RateUnit(flowRate, flowunit, getMolarMass(), density, 0); - double SIval = unit.getSIvalue(); - double totalNumberOfMolesLocal = totalNumberOfMoles; - for (int i = 0; i < numberOfComponents; i++) { - if (flowRate < 1e-100) { - setEmptyFluid(); - } else if (totalNumberOfMolesLocal > 1e-100) { - // (SIval / totalNumberOfMolesLocal - 1) * ... - double change = - SIval / totalNumberOfMolesLocal * getPhase(0).getComponent(i).getNumberOfmoles() - - getPhase(0).getComponent(i).getNumberOfmoles(); - if (Math.abs(change) > 1e-12) { - addComponent(i, change); - } + phaseArray[3] = new PhasePureComponentSolid(); + phaseArray[3].setTemperature(phaseArray[0].getTemperature()); + phaseArray[3].setPressure(phaseArray[0].getPressure()); + for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { + if (getPhase(0).getComponent(i).isIsTBPfraction()) { + phaseArray[3].addComponent("default", getPhase(0).getComponent(i).getNumberOfmoles(), + getPhase(0).getComponent(i).getNumberOfmoles(), i); + phaseArray[3].getComponent(i).setComponentName(getPhase(0).getComponent(i).getName()); + phaseArray[3].getComponent(i).setIsPlusFraction(true); } else { - addComponent(i, SIval); + phaseArray[3].addComponent(getPhase(0).getComponent(i).getName(), + getPhase(0).getComponent(i).getNumberOfmoles(), + getPhase(0).getComponent(i).getNumberOfmoles(), i); } } - } - - /** {@inheritDoc} */ - @Override - public double getFlowRate(String flowunit) { - if (flowunit.equals("kg/sec")) { - return totalNumberOfMoles * getMolarMass(); - } else if (flowunit.equals("kg/min")) { - return totalNumberOfMoles * getMolarMass() * 60.0; - } else if (flowunit.equals("kg/hr")) { - return totalNumberOfMoles * getMolarMass() * 3600.0; - } else if (flowunit.equals("kg/day")) { - return totalNumberOfMoles * getMolarMass() * 3600.0 * 24.0; - } else if (flowunit.equals("m3/sec")) { - initPhysicalProperties("density"); - return totalNumberOfMoles * getMolarMass() / getDensity("kg/m3"); - // return getVolume() / 1.0e5; - } else if (flowunit.equals("m3/min")) { - initPhysicalProperties("density"); - return totalNumberOfMoles * getMolarMass() * 60.0 / getDensity("kg/m3"); - // return getVolume() / 1.0e5 * 60.0; - } else if (flowunit.equals("m3/hr")) { - // return getVolume() / 1.0e5 * 3600.0; - initPhysicalProperties("density"); - return totalNumberOfMoles * getMolarMass() * 3600.0 / getDensity("kg/m3"); - } else if (flowunit.equals("idSm3/hr")) { - return totalNumberOfMoles * getMolarMass() * 3600.0 / getIdealLiquidDensity("kg/m3"); - } else if (flowunit.equals("Sm3/sec")) { - return totalNumberOfMoles * ThermodynamicConstantsInterface.R - * ThermodynamicConstantsInterface.standardStateTemperature - / ThermodynamicConstantsInterface.atm; - } else if (flowunit.equals("Sm3/hr")) { - return totalNumberOfMoles * 3600.0 * ThermodynamicConstantsInterface.R - * ThermodynamicConstantsInterface.standardStateTemperature - / ThermodynamicConstantsInterface.atm; - } else if (flowunit.equals("Sm3/day")) { - return totalNumberOfMoles * 3600.0 * 24.0 * ThermodynamicConstantsInterface.R - * ThermodynamicConstantsInterface.standardStateTemperature - / ThermodynamicConstantsInterface.atm; - } else if (flowunit.equals("MSm3/day")) { - return totalNumberOfMoles * 3600.0 * 24.0 * ThermodynamicConstantsInterface.R - * ThermodynamicConstantsInterface.standardStateTemperature - / ThermodynamicConstantsInterface.atm / 1.0e6; - } else if (flowunit.equals("MSm3/hr")) { - return totalNumberOfMoles * 3600.0 * ThermodynamicConstantsInterface.R - * ThermodynamicConstantsInterface.standardStateTemperature - / ThermodynamicConstantsInterface.atm / 1.0e6; - } else if (flowunit.equals("mole/sec")) { - return totalNumberOfMoles; - } else if (flowunit.equals("mole/min")) { - return totalNumberOfMoles * 60.0; - } else if (flowunit.equals("mole/hr")) { - return totalNumberOfMoles * 3600.0; - } else { - throw new RuntimeException("failed.. unit: " + flowunit + " not supported"); - } - } - - /** {@inheritDoc} */ - @Override - public void addSalt(String componentName, double value) { - double val1 = 1e-20; - double val2 = 1e-20; - try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); - java.sql.ResultSet dataSet = database - .getResultSet("SELECT * FROM compsalt WHERE SaltName='" + componentName + "'")) { - dataSet.next(); - String name1 = dataSet.getString("ion1").trim(); - val1 = Double.parseDouble(dataSet.getString("stoc1")) * value; - this.addComponent(name1, val1); + ((PhaseSolid) phaseArray[3]).setSolidRefFluidPhase(phaseArray[0]); - String name2 = dataSet.getString("ion2").trim(); - val2 = Double.parseDouble(dataSet.getString("stoc2")) * value; - this.addComponent(name2, val2); - logger.info("ok adding salts. Ions: " + name1 + ", " + name2); - } catch (Exception ex) { - logger.error("failed ", ex); + if (getMaxNumberOfPhases() < 4) { + setMaxNumberOfPhases(4); } } @@ -1070,389 +1114,129 @@ public void addTBPfraction(String componentName, double numberOfMoles, double mo /** {@inheritDoc} */ @Override - public void addPlusFraction(String componentName, double numberOfMoles, double molarMass, - double density) { - addTBPfraction(componentName, numberOfMoles, molarMass, density); - componentName = (componentName + "_" + "PC"); // getFluidName()); - for (int i = 0; i < numberOfPhases; i++) { - // System.out.println("comp " + componentName); - getPhase(i).getComponent(componentName).setIsPlusFraction(true); - getPhase(i).getComponent(componentName).setCriticalViscosity( - 7.94830 * Math.sqrt(1e3 * getPhase(i).getComponent(componentName).getMolarMass()) - * Math.pow(getPhase(i).getComponent(componentName).getPC(), 2.0 / 3.0) - / Math.pow(getPhase(i).getComponent(componentName).getTC(), 1.0 / 6.0) * 1e-7); + public void addToComponentNames(String postfix) { + for (int j = 0; j < componentNames.size(); j++) { + componentNames.set(j, componentNames.get(j) + postfix); + } + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + for (int j = 0; j < componentNames.size(); j++) { + getPhase(i).getComponent(j) + .setComponentName(getPhase(i).getComponent(j).getComponentName() + postfix); + } } } /** {@inheritDoc} */ @Override - public void addComponent(ComponentInterface inComponent) { - if (inComponent.isIsTBPfraction()) { - addTBPfraction(inComponent.getComponentName(), inComponent.getNumberOfmoles(), - inComponent.getMolarMass(), inComponent.getNormalLiquidDensity()); - String componentName = inComponent.getComponentName(); - changeComponentName(componentName + "_PC", componentName.replaceFirst("_PC", "")); - for (int i = 0; i < numberOfPhases; i++) { - getPhase(i).getComponent(componentName) - .setAttractiveTerm(inComponent.getAttractiveTermNumber()); - getPhase(i).getComponent(componentName).setTC(inComponent.getTC()); - getPhase(i).getComponent(componentName).setPC(inComponent.getPC()); - getPhase(i).getComponent(componentName).setMolarMass(inComponent.getMolarMass()); - getPhase(i).getComponent(componentName).setComponentType("TBPfraction"); - getPhase(i).getComponent(componentName) - .setNormalLiquidDensity(inComponent.getNormalLiquidDensity()); - getPhase(i).getComponent(componentName) - .setNormalBoilingPoint(inComponent.getNormalBoilingPoint()); - getPhase(i).getComponent(componentName).setAcentricFactor(inComponent.getAcentricFactor()); - getPhase(i).getComponent(componentName).setCriticalVolume(inComponent.getCriticalVolume()); - getPhase(i).getComponent(componentName).setRacketZ(inComponent.getRacketZ()); - getPhase(i).getComponent(componentName).setRacketZCPA(inComponent.getRacketZCPA()); - getPhase(i).getComponent(componentName).setIsTBPfraction(true); - getPhase(i).getComponent(componentName) - .setParachorParameter(inComponent.getParachorParameter()); - getPhase(i).getComponent(componentName) - .setTriplePointTemperature(inComponent.getTriplePointTemperature()); - getPhase(i).getComponent(componentName) - .setIdealGasEnthalpyOfFormation(inComponent.getIdealGasEnthalpyOfFormation()); - getPhase(i).getComponent(componentName).setCpA(inComponent.getCpA()); - getPhase(i).getComponent(componentName).setCpB(inComponent.getCpB()); - getPhase(i).getComponent(componentName).setCpC(inComponent.getCpC()); - getPhase(i).getComponent(componentName).setCpD(inComponent.getCpD()); - } - } else { - addComponent(inComponent.getComponentName(), inComponent.getNumberOfmoles()); - } + public boolean allowPhaseShift() { + return allowPhaseShift; } /** {@inheritDoc} */ @Override - public void addComponent(String componentName, double moles) { - componentName = ComponentInterface.getComponentNameFromAlias(componentName); - - int index = 0; - - boolean addForFirstTime = true; - for (int p = 0; p < componentNames.size(); p++) { - if (componentNames.get(p).equals(componentName)) { - addForFirstTime = false; - index = p; - break; - } - } - - if (addForFirstTime) { - if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { - throw new RuntimeException( - new neqsim.util.exception.InvalidInputException(this, "addComponent", "componentName", - "with value " + componentName + " not found in database.")); - } - if (moles < 0.0) { - String msg = "is negative input for component: " + componentName; - throw new RuntimeException( - new neqsim.util.exception.InvalidInputException(this, "addComponent", "moles", msg)); - } - // System.out.println("adding " + componentName); - componentNames.add(componentName); - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - getPhase(i).addComponent(componentName, moles, moles, numberOfComponents); - getPhase(i).setAttractiveTerm(attractiveTermNumber); - } - numberOfComponents++; - } else { - for (PhaseInterface tmpPhase : phaseArray) { - if (tmpPhase != null - && (tmpPhase.getComponent(componentName).getNumberOfMolesInPhase() + moles) < 0.0) { - init(0); - break; - } - } - - // System.out.println("adding chem reac " + componentName); - for (PhaseInterface tmpPhase : phaseArray) { - // TODO: adding moles to all phases, not just the active ones. - if (tmpPhase != null) { - tmpPhase.addMolesChemReac(index, moles, moles); - } - } - } - setTotalNumberOfMoles(getTotalNumberOfMoles() + moles); + public void allowPhaseShift(boolean allowPhaseShift) { + this.allowPhaseShift = allowPhaseShift; } /** {@inheritDoc} */ @Override - public void addComponent(String componentName, double value, String unitName) { - componentName = ComponentInterface.getComponentNameFromAlias(componentName); - - if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { - throw new RuntimeException("No component with name: " + componentName + " in database"); - } - - double molarmass = 0.0; - double stddens = 0.0; - double boilp = 0.0; - try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); - java.sql.ResultSet dataSet = - database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'"))) { - dataSet.next(); - molarmass = Double.parseDouble(dataSet.getString("molarmass")) / 1000.0; - stddens = Double.parseDouble(dataSet.getString("stddens")); - boilp = Double.parseDouble(dataSet.getString("normboil")); - } catch (Exception ex) { - // todo: mole amount may be not set. should not be caught? - logger.error("failed ", ex); + public void autoSelectMixingRule() { + logger.info("setting mixing rule"); + if (modelName.equals("CPAs-SRK-EOS") || modelName.equals("CPA-SRK-EOS") + || modelName.equals("Electrolyte-CPA-EOS-statoil") + || modelName.equals("CPAs-SRK-EOS-statoil") || modelName.equals("Electrolyte-CPA-EOS")) { + this.setMixingRule(10); + // System.out.println("mix rule 10"); + } else if ((modelName.equals("ScRK-EOS-HV") || modelName.equals("SRK-EOS") + || modelName.equals("ScRK-EOS")) && this.getPhase(0).hasComponent("water")) { + this.setMixingRule(4); + } else if (modelName.equals("PR-EOS")) { + this.setMixingRule(2); + } else if (modelName.equals("Electrolyte-ScRK-EOS")) { + this.setMixingRule(4); + } else if (modelName.equals("UMR-PRU-EoS") || modelName.equals("UMR-PRU-MC-EoS")) { + this.setMixingRule("HV", "UNIFAC_UMRPRU"); + } else if (modelName.equals("GERG-water-EOS")) { + this.setMixingRule(8); + } else if (modelName.equals("GERG-2008-EOS")) { + this.setMixingRule(2); + } else if (modelName.equals("PC-SAFT")) { + this.setMixingRule(8); + } else { + this.setMixingRule(2); } - neqsim.util.unit.Unit unit = - new neqsim.util.unit.RateUnit(value, unitName, molarmass, stddens, boilp); - double SIval = unit.getSIvalue(); - // System.out.println("number of moles " + SIval); - this.addComponent(componentName, SIval); } /** {@inheritDoc} */ @Override - public void addComponent(String componentName, double moles, double TC, double PC, double acs) { - componentName = ComponentInterface.getComponentNameFromAlias(componentName); - - String comNam = componentName; - if (getPhase(0).hasComponent(componentName)) { - addComponent(componentName, moles); + public SystemInterface autoSelectModel() { + if (this.getPhase(0).hasComponent("MDEA") && this.getPhase(0).hasComponent("water") + && this.getPhase(0).hasComponent("CO2")) { + return setModel("Electrolyte-ScRK-EOS"); + } else if (this.getPhase(0).hasComponent("water") || this.getPhase(0).hasComponent("methanol") + || this.getPhase(0).hasComponent("MEG") || this.getPhase(0).hasComponent("TEG") + || this.getPhase(0).hasComponent("ethanol") || this.getPhase(0).hasComponent("DEG")) { + if (this.getPhase(0).hasComponent("Na+") || this.getPhase(0).hasComponent("K+") + || this.getPhase(0).hasComponent("Br-") || this.getPhase(0).hasComponent("Mg++") + || this.getPhase(0).hasComponent("Cl-") || this.getPhase(0).hasComponent("Ca++") + || this.getPhase(0).hasComponent("Fe++") || this.getPhase(0).hasComponent("SO4--")) { + logger.info("model elect"); + return setModel("Electrolyte-CPA-EOS-statoil"); + } else { + return setModel("CPAs-SRK-EOS-statoil"); + } + } else if (this.getPhase(0).hasComponent("water")) { + return setModel("ScRK-EOS"); + } else if (this.getPhase(0).hasComponent("mercury")) { + return setModel("SRK-TwuCoon-Statoil-EOS"); } else { - addComponent("default", moles); - comNam = "default"; - // componentNames.set(componentNames.indexOf("default"), componentName); - } - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - getPhase(i).getComponent(comNam).setComponentName(componentName); - getPhase(i).getComponent(componentName).setTC(TC); - getPhase(i).getComponent(componentName).setPC(PC); - getPhase(i).getComponent(componentName).setAcentricFactor(acs); - } - if (comNam.equals("default")) { - componentNames.remove("default"); - componentNames.add(componentName); + logger.info("no model"); + return setModel("SRK-EOS"); } } /** {@inheritDoc} */ @Override - public void addComponent(String componentName, double moles, int phaseNumber) { - componentName = ComponentInterface.getComponentNameFromAlias(componentName); - - if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { - throw new RuntimeException("No component with name: " + componentName + " in database"); - } - - for (int p = 0; p < componentNames.size(); p++) { - if (componentNames.get(p).equals(componentName)) { - addComponent(p, moles, phaseNumber); - return; + public final void calc_x_y() { + for (int j = 0; j < numberOfPhases; j++) { + for (int i = 0; i < numberOfComponents; i++) { + if (j == 0) { + getPhase(j).getComponent(i) + .setx(getPhase(0).getComponent(i).getK() * getPhase(j).getComponents()[i].getz() + / (1 - beta[phaseIndex[0]] + + beta[phaseIndex[0]] * getPhase(0).getComponent(i).getK())); + } else if (j == 1) { + getPhase(j).getComponent(i).setx(getPhase(0).getComponent(i).getz() / (1.0 + - beta[phaseIndex[0]] + beta[phaseIndex[0]] * getPhase(0).getComponent(i).getK())); + } + // phaseArray[j].getComponents()[i].setx(phaseArray[0].getComponents()[i].getx() + // / phaseArray[0].getComponents()[i].getK()); + // System.out.println("comp: " + j + i + " " + c[j][i].getx()); } + getPhase(j).normalize(); } + } - // Add new component - if (moles < 0.0) { - String msg = "Negative input number of moles."; - neqsim.util.exception.InvalidInputException ex = - new neqsim.util.exception.InvalidInputException(this, "addComponent", "moles", msg); - throw new RuntimeException(ex); - } - - componentNames.add(componentName); - double k = 1.0; - setTotalNumberOfMoles(getTotalNumberOfMoles() + moles); - - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - if (phaseNumber == i) { - k = 1.0; - } else { - k = 1.0e-30; + /** {@inheritDoc} */ + @Override + public final void calc_x_y_nonorm() { + for (int j = 0; j < numberOfPhases; j++) { + for (int i = 0; i < numberOfComponents; i++) { + if (j == 0) { + getPhase(j).getComponents()[i].setx(getPhase(j).getComponents()[i].getK() + * getPhase(j).getComponents()[i].getz() / (1 - beta[phaseIndex[0]] + + beta[phaseIndex[0]] * getPhase(0).getComponents()[i].getK())); + } + if (j == 1) { + getPhase(j).getComponents()[i].setx(getPhase(0).getComponents()[i].getz() / (1.0 + - beta[phaseIndex[0]] + beta[phaseIndex[0]] * getPhase(0).getComponents()[i].getK())); + } + // phaseArray[j].getComponents()[i].setx(phaseArray[0].getComponents()[i].getx() + // / phaseArray[0].getComponents()[i].getK()); + // System.out.println("comp: " + j + i + " " + c[j][i].getx()); } - getPhase(i).addComponent(componentName, moles, moles * k, numberOfComponents); - getPhase(i).setAttractiveTerm(attractiveTermNumber); + // getPhase(j).normalize(); } - numberOfComponents++; - } - - /** {@inheritDoc} */ - @Override - public void addComponent(String componentName, double value, String name, int phase) { - componentName = ComponentInterface.getComponentNameFromAlias(componentName); - - if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { - throw new RuntimeException("No component with name: " + componentName + " in database"); - } - - double molarmass = 0.0; - double stddens = 0.0; - double boilp = 0.0; - try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); - java.sql.ResultSet dataSet = - database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'"))) { - dataSet.next(); - molarmass = Double.parseDouble(dataSet.getString("molarmass")) / 1000.0; - stddens = Double.parseDouble(dataSet.getString("stddens")); - boilp = Double.parseDouble(dataSet.getString("normboil")); - } catch (Exception ex) { - logger.error("failed ", ex); - throw new RuntimeException(ex); - } - neqsim.util.unit.Unit unit = - new neqsim.util.unit.RateUnit(value, name, molarmass, stddens, boilp); - double SIval = unit.getSIvalue(); - // System.out.println("number of moles " + SIval); - this.addComponent(componentName, SIval, phase); - } - - /** {@inheritDoc} */ - @Override - public void addComponent(int index, double moles) { - if (index >= getPhase(0).getNumberOfComponents()) { - logger.error("componentIndex higher than number of components in system"); - return; - } - - for (PhaseInterface tmpPhase : phaseArray) { - // TODO: adding moles to all phases, not just the active ones. - if (tmpPhase != null) { - tmpPhase.addMolesChemReac(index, moles, moles); - } - } - setTotalNumberOfMoles(getTotalNumberOfMoles() + moles); - } - - /** {@inheritDoc} */ - @Override - public void addComponent(int index, double moles, int phaseNumber) { - if (index >= getPhase(0).getNumberOfComponents()) { - logger.error("componentIndex higher than number of components in system"); - return; - } - double k = 1.0; - - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - if (phaseNumber == i) { - k = 1.0; - } else { - k = 0.0; - } - phaseArray[phaseIndex[i]].addMolesChemReac(index, moles * k, moles); - } - - setTotalNumberOfMoles(getTotalNumberOfMoles() + moles); - } - - /** {@inheritDoc} */ - @Override - public void changeComponentName(String name, String newName) { - for (int i = 0; i < numberOfComponents; i++) { - if (componentNames.get(i).equals(name)) { - componentNames.set(i, newName); - } - } - - for (int i = 0; i < maxNumberOfPhases; i++) { - getPhase(i).getComponent(name).setComponentName(newName); - } - } - - /** {@inheritDoc} */ - @Override - public void removeComponent(String name) { - name = ComponentInterface.getComponentNameFromAlias(name); - - setTotalNumberOfMoles( - getTotalNumberOfMoles() - phaseArray[0].getComponent(name).getNumberOfmoles()); - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - getPhase(i).removeComponent(name, getTotalNumberOfMoles(), - getPhase(i).getComponent(name).getNumberOfMolesInPhase()); - } - - componentNames.remove(name); - numberOfComponents--; - } - - /** {@inheritDoc} */ - @Override - public String[] getComponentNames() { - ArrayList components = new ArrayList(); - - for (int j = 0; j < numberOfComponents; j++) { - components.add(phaseArray[0].getComponents()[j].getName()); - } - String[] componentList = new String[components.size()]; - for (int j = 0; j < numberOfComponents; j++) { - componentList[j] = components.get(j); - } - return componentList; - } - - /** {@inheritDoc} */ - @Override - public void setComponentNames(String[] componentNames) { - for (int i = 0; i < componentNames.length; i++) { - this.componentNames.set(i, componentNames[i]); - } - } - - /** {@inheritDoc} */ - @Override - public void renameComponent(String oldName, String newName) { - componentNames.set(getPhase(0).getComponent(oldName).getComponentNumber(), newName); - for (int i = 0; i < maxNumberOfPhases; i++) { - getPhase(i).getComponent(oldName).setComponentName(newName); - } - } - - /** {@inheritDoc} */ - @Override - public void addToComponentNames(String postfix) { - for (int j = 0; j < componentNames.size(); j++) { - componentNames.set(j, componentNames.get(j) + postfix); - } - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - for (int j = 0; j < componentNames.size(); j++) { - getPhase(i).getComponent(j) - .setComponentName(getPhase(i).getComponent(j).getComponentName() + postfix); - } - } - } - - /** {@inheritDoc} */ - @Override - public String getComponentNameTag() { - return componentNameTag; - } - - /** {@inheritDoc} */ - @Override - public void setComponentNameTag(String nameTag) { - componentNameTag = nameTag; - for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { - renameComponent(componentNames.get(i), componentNames.get(i) + nameTag); - } - } - - /** {@inheritDoc} */ - @Override - public void setComponentNameTagOnNormalComponents(String nameTag) { - componentNameTag = nameTag; - for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { - if (!getPhase(0).getComponent(i).isIsTBPfraction() - && !getPhase(0).getComponent(i).isIsPlusFraction()) { - renameComponent(componentNames.get(i), componentNames.get(i) + nameTag); - } - } - } - - /** {@inheritDoc} */ - @Override - public void setEmptyFluid() { - for (PhaseInterface tmpPhase : phaseArray) { - if (tmpPhase != null) { - tmpPhase.setEmptyFluid(); - } - } - totalNumberOfMoles = 0.0; } /** {@inheritDoc} */ @@ -1632,1423 +1416,1626 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, /** {@inheritDoc} */ @Override - public final void initBeta() { - for (int i = 0; i < numberOfPhases; i++) { - this.beta[phaseIndex[i]] = getPhase(i).getNumberOfMolesInPhase() / getTotalNumberOfMoles(); - } - if (this.getSumBeta() < 1.0 - ThermodynamicModelSettings.phaseFractionMinimumLimit - || this.getSumBeta() > 1.0 + ThermodynamicModelSettings.phaseFractionMinimumLimit) { - logger.warn("SystemThermo:initBeta - Sum of beta does not equal 1.0"); + public double calcHenrysConstant(String component) { + if (numberOfPhases != 2) { + logger.error("Can't calculate Henrys constant - two phases must be present."); + return 0; + } else { + int compNumb = getPhase(getPhaseIndex(0)).getComponent(component).getComponentNumber(); + double hc = getPhase(getPhaseIndex(0)).getFugacity(compNumb) + / getPhase(getPhaseIndex(1)).getComponent(component).getx(); + return hc; } } /** {@inheritDoc} */ @Override - public double getJouleThomsonCoefficient(String unit) { - double JTcoef = getJouleThomsonCoefficient(); - double conversionFactor = 1.0; - switch (unit) { - case "K/bar": - conversionFactor = 1.0; - break; - case "C/bar": - conversionFactor = 1.0; - break; - default: - break; - } - return JTcoef * conversionFactor; + public void calcInterfaceProperties() { + interfaceProp.init(); } /** {@inheritDoc} */ @Override - public double getJouleThomsonCoefficient() { - double JTcoef = 0; + public void calcKIJ(boolean ok) { + neqsim.thermo.mixingRule.EosMixingRules.calcEOSInteractionParameters = ok; for (int i = 0; i < numberOfPhases; i++) { - JTcoef += getBeta(i) * getPhase(i).getJouleThomsonCoefficient(); + ((PhaseEosInterface) getPhase(i)).getMixingRule().setCalcEOSInteractionParameters(ok); } - return JTcoef; } /** {@inheritDoc} */ @Override - public double getSoundSpeed(String unit) { - double refVel = getSoundSpeed(); - double conversionFactor = 1.0; - switch (unit) { - case "m/s": - conversionFactor = 1.0; - break; - case "km/hr": - conversionFactor = 3.6; - break; - default: - break; + public void changeComponentName(String name, String newName) { + for (int i = 0; i < numberOfComponents; i++) { + if (componentNames.get(i).equals(name)) { + componentNames.set(i, newName); + } + } + + for (int i = 0; i < maxNumberOfPhases; i++) { + getPhase(i).getComponent(name).setComponentName(newName); } - return refVel * conversionFactor; } /** {@inheritDoc} */ @Override - public double getSoundSpeed() { - double soundspeed = 0; - for (int i = 0; i < numberOfPhases; i++) { - soundspeed += getBeta(i) * getPhase(i).getSoundSpeed(); - } - return soundspeed; + public boolean checkStability() { + return checkStability; } /** {@inheritDoc} */ @Override - public final void initTotalNumberOfMoles(double change) { - setTotalNumberOfMoles(getTotalNumberOfMoles() + change); - // System.out.println("total moles: " + totalNumberOfMoles); - for (int j = 0; j < numberOfPhases; j++) { - for (int i = 0; i < numberOfComponents; i++) { - getPhase(j).getComponents()[i] - .setNumberOfmoles(phaseArray[phaseIndex[0]].getComponents()[i].getNumberOfmoles()); - } - } + public void checkStability(boolean val) { + checkStability = val; } /** {@inheritDoc} */ @Override - public final void init_x_y() { - // double x, z; - for (int j = 0; j < numberOfPhases; j++) { - // x = 0; - // z = 0; - for (int i = 0; i < numberOfComponents; i++) { - getPhase(j).getComponents()[i] - .setz(getPhase(j).getComponents()[i].getNumberOfmoles() / getTotalNumberOfMoles()); - getPhase(j).getComponents()[i].setx(getPhase(j).getComponents()[i].getNumberOfMolesInPhase() - / getPhase(j).getNumberOfMolesInPhase()); - } - getPhase(j).normalize(); - } + public void chemicalReactionInit() { + chemicalReactionOperations = new ChemicalReactionOperations(this); + chemicalSystem = chemicalReactionOperations.hasReactions(); } /** {@inheritDoc} */ @Override - public final void calc_x_y() { - for (int j = 0; j < numberOfPhases; j++) { - for (int i = 0; i < numberOfComponents; i++) { - if (j == 0) { - getPhase(j).getComponent(i) - .setx(getPhase(0).getComponent(i).getK() * getPhase(j).getComponents()[i].getz() - / (1 - beta[phaseIndex[0]] - + beta[phaseIndex[0]] * getPhase(0).getComponent(i).getK())); - } else if (j == 1) { - getPhase(j).getComponent(i).setx(getPhase(0).getComponent(i).getz() / (1.0 - - beta[phaseIndex[0]] + beta[phaseIndex[0]] * getPhase(0).getComponent(i).getK())); - } - // phaseArray[j].getComponents()[i].setx(phaseArray[0].getComponents()[i].getx() - // / phaseArray[0].getComponents()[i].getK()); - // System.out.println("comp: " + j + i + " " + c[j][i].getx()); - } - getPhase(j).normalize(); - } - } + public void clearAll() { + setTotalNumberOfMoles(0); + phaseType[0] = PhaseType.byValue(1); + phaseType[1] = PhaseType.byValue(0); + numberOfComponents = 0; + setNumberOfPhases(2); + beta[0] = 1.0; + beta[1] = 1.0; + beta[2] = 1.0; + beta[3] = 1.0; + beta[4] = 1.0; + beta[5] = 1.0; + chemicalSystem = false; - /** {@inheritDoc} */ - @Override - public final void calc_x_y_nonorm() { - for (int j = 0; j < numberOfPhases; j++) { - for (int i = 0; i < numberOfComponents; i++) { - if (j == 0) { - getPhase(j).getComponents()[i].setx(getPhase(j).getComponents()[i].getK() - * getPhase(j).getComponents()[i].getz() / (1 - beta[phaseIndex[0]] - + beta[phaseIndex[0]] * getPhase(0).getComponents()[i].getK())); - } - if (j == 1) { - getPhase(j).getComponents()[i].setx(getPhase(0).getComponents()[i].getz() / (1.0 - - beta[phaseIndex[0]] + beta[phaseIndex[0]] * getPhase(0).getComponents()[i].getK())); - } - // phaseArray[j].getComponents()[i].setx(phaseArray[0].getComponents()[i].getx() - // / phaseArray[0].getComponents()[i].getK()); - // System.out.println("comp: " + j + i + " " + c[j][i].getx()); - } - // getPhase(j).normalize(); - } - } + double oldTemp = phaseArray[0].getTemperature(); + double oldPres = phaseArray[0].getPressure(); - /** {@inheritDoc} */ - @Override - public void reset_x_y() { - for (int j = 0; j < numberOfPhases; j++) { - for (int i = 0; i < numberOfComponents; i++) { - getPhase(j).getComponents()[i].setx(phaseArray[phaseIndex[0]].getComponents()[i].getz()); + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + try { + phaseArray[i] = phaseArray[i].getClass().getDeclaredConstructor().newInstance(); + } catch (Exception ex) { + logger.error("err ", ex); } + phaseArray[i].setTemperature(oldTemp); + phaseArray[i].setPressure(oldPres); } } /** {@inheritDoc} */ @Override - public void reset() { - for (int i = 0; i < numberOfComponents; i++) { - // TODO: numeric issue, nearly zero - addComponent(getPhase(0).getComponent(i).getComponentName(), - -getPhase(0).getComponent(i).getNumberOfmoles()); + public SystemThermo clone() { + SystemThermo clonedSystem = null; + try { + clonedSystem = (SystemThermo) super.clone(); + // clonedSystem.chemicalReactionOperations = (ChemicalReactionOperations) + // chemicalReactionOperations.clone(); + } catch (Exception ex) { + logger.error("Cloning failed.", ex); } - } - /** {@inheritDoc} */ - @Override - public void init(int type) { - if (!this.isInitialized) { - initBeta(); - init_x_y(); + clonedSystem.beta = beta.clone(); + clonedSystem.attractiveTermNumber = attractiveTermNumber; + clonedSystem.phaseType = phaseType.clone(); + clonedSystem.phaseIndex = phaseIndex.clone(); + + clonedSystem.componentNames = new ArrayList(componentNames); + if (interfaceProp != null) { + // clonedSystem.interfaceProp = (InterphasePropertiesInterface) + // interfaceProp.clone(); } - if (this.numericDerivatives) { - initNumeric(type); - } else { - initAnalytic(type); + clonedSystem.characterization = characterization.clone(); + if (clonedSystem.waxCharacterisation != null) { + clonedSystem.waxCharacterisation = waxCharacterisation.clone(); } - this.isInitialized = true; + + System.arraycopy(this.beta, 0, clonedSystem.beta, 0, beta.length); + System.arraycopy(this.phaseType, 0, clonedSystem.phaseType, 0, phaseType.length); + System.arraycopy(this.phaseIndex, 0, clonedSystem.phaseIndex, 0, phaseIndex.length); + + clonedSystem.phaseArray = phaseArray.clone(); + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + clonedSystem.phaseArray[i] = phaseArray[i].clone(); + } + + return clonedSystem; } /** {@inheritDoc} */ @Override - public void init(int type, int phase) { - if (this.numericDerivatives) { - initNumeric(type, phase); - } else { - initAnalytic(type, phase); + public void createDatabase(boolean reset) { + if (reset) { + resetDatabase(); } - } - /** - *

- * initAnalytic. - *

- * - * @param type a int. 0 to initialize and 1 to reset, 2 to calculate T and P derivatives, 3 to - * calculate all derivatives and 4 to calculate all derivatives numerically - */ - public void initAnalytic(int type) { - if (type == 0) { - reInitPhaseInformation(); - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - if (isPhase(i)) { - getPhase(i).init(getTotalNumberOfMoles(), numberOfComponents, type, - phaseType[phaseIndex[i]], beta[phaseIndex[i]]); - } - } - setNumberOfPhases(2); - } + try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) { + String names = new String(); - if (type > 0) { - for (int i = 0; i < numberOfPhases; i++) { - if (isPhase(i)) { - // todo: possible bug here, some components check for initType >= 3 - getPhase(i).init(getTotalNumberOfMoles(), numberOfComponents, Math.min(3, type), - phaseType[phaseIndex[i]], beta[phaseIndex[i]]); - } + for (int k = 0; k < getPhase(0).getNumberOfComponents() - 1; k++) { + names += "'" + this.getComponentNames()[k] + "', "; } + names += "'" + this.getComponentNames()[getPhase(0).getNumberOfComponents() - 1] + "'"; - for (int i = 0; i < numberOfPhases; i++) { - if (isPhase(i)) { - for (int j = 0; j < numberOfComponents; j++) { - getPhase(i).getComponents()[j].fugcoef(getPhase(i)); - } - } + if (NeqSimDataBase.createTemporaryTables()) { + database.execute("insert into comptemp SELECT * FROM comp WHERE name IN (" + names + ")"); + database.execute("insert into intertemp SELECT DISTINCT * FROM inter WHERE comp1 IN (" + + names + ") AND comp2 IN (" + names + ")"); + database.execute("delete FROM intertemp WHERE comp1=comp2"); } - } + // System.out.println("ok " + names); - if (type == 4) { // special case, calculate all derivatives numerically - for (int i = 0; i < numberOfPhases; i++) { - if (isPhase(i)) { - for (int j = 0; j < numberOfComponents; j++) { - // TODO: only runs two calculations init == 3 runs three - getPhase(i).getComponents()[j].fugcoefDiffTempNumeric(getPhase(i), numberOfComponents, - getPhase(i).getTemperature(), getPhase(i).getPressure()); - getPhase(i).getComponents()[j].fugcoefDiffPresNumeric(getPhase(i), numberOfComponents, - getPhase(i).getTemperature(), getPhase(i).getPressure()); - } - } - } - } else { - if (type > 1) { // calculate T and P derivatives - for (int i = 0; i < numberOfPhases; i++) { - if (isPhase(i)) { - for (int j = 0; j < numberOfComponents; j++) { - getPhase(i).getComponents()[j].logfugcoefdT(getPhase(i)); - getPhase(i).getComponents()[j].logfugcoefdP(getPhase(i)); - } - } - } - } - if (type == 3) { // calculate all derivatives - for (int i = 0; i < numberOfPhases; i++) { - if (isPhase(i)) { - for (int j = 0; j < numberOfComponents; j++) { - getPhase(i).getComponents()[j].logfugcoefdN(getPhase(i)); - } - } - } + for (int phase = 0; phase < maxNumberOfPhases; phase++) { + getPhase(phase).setMixingRuleDefined(false); } - } - for (int i = 1; i < numberOfPhases; i++) { - if (isPhase(i)) { - if (getPhase(i).getType() == PhaseType.GAS) { - getPhase(i).setType(PhaseType.OIL); + for (int i = 0; i < numberOfComponents; i++) { + if (getPhase(0).getComponent(i).isIsTBPfraction() + || getPhase(0).getComponent(i).isIsPlusFraction()) { + getPhase(0).getComponent(i).insertComponentIntoDatabase(""); } } + } catch (Exception ex) { + logger.error("error in SystemThermo Class...createDatabase() method", ex); } - this.isInitialized = true; } - /** - *

- * initAnalytic. - *

- * - * @param type a int - * @param phase a int - */ - public void initAnalytic(int type, int phase) { - if (type == 0) { - beta[0] = 1.0; - phaseIndex[phase] = phase; - } + /** {@inheritDoc} */ + @Override + public String[][] createTable(String name) { + initProperties(); - if (isPhase(phase)) { - getPhase(phase).init(getTotalNumberOfMoles(), numberOfComponents, type, - phaseType[phaseIndex[phase]], beta[phaseIndex[phase]]); - if (type > 0) { - for (int j = 0; j < numberOfComponents; j++) { - getPhase(phase).getComponents()[j].fugcoef(getPhase(phase)); - } - } - if (type > 1) { - for (int j = 0; j < numberOfComponents; j++) { - getPhase(phase).getComponents()[j].logfugcoefdT(getPhase(phase)); - getPhase(phase).getComponents()[j].logfugcoefdP(getPhase(phase)); - } - } - if (type > 2) { - for (int j = 0; j < numberOfComponents; j++) { - getPhase(phase).getComponents()[j].logfugcoefdT(getPhase(phase)); - getPhase(phase).getComponents()[j].logfugcoefdP(getPhase(phase)); - getPhase(phase).getComponents()[j].logfugcoefdN(getPhase(phase)); - } + java.text.DecimalFormat nf = new java.text.DecimalFormat(); + + java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols(); + symbols.setDecimalSeparator('.'); + nf.setDecimalFormatSymbols(symbols); + + nf.setMaximumFractionDigits(5); + nf.applyPattern("#.#####E0"); + + // String[][] table = new String[getPhases()[0].getNumberOfComponents() + + // 30][7]; + // String[] names = {"", "Feed", "Phase 1", "Phase 2", "Phase 3", "Phase 4", + // "Unit"}; + String[][] table = new String[getPhases()[0].getNumberOfComponents() + 30][7]; + table[0][0] = ""; // getPhases()[0].getType(); //""; + + for (int i = 0; i < getPhases()[0].getNumberOfComponents() + 30; i++) { + for (int j = 0; j < 7; j++) { + table[i][j] = ""; } } + table[0][1] = "total"; + for (int i = 0; i < numberOfPhases; i++) { + table[0][i + 2] = getPhase(i).getType().toString(); + } - for (PhaseInterface tmpPhase : phaseArray) { - if (tmpPhase != null && tmpPhase.getType() == PhaseType.GAS) { - tmpPhase.setType(PhaseType.OIL); - } + StringBuffer buf = new StringBuffer(); + java.text.FieldPosition test = new java.text.FieldPosition(0); + for (int j = 0; j < getPhases()[0].getNumberOfComponents(); j++) { + buf = new StringBuffer(); + table[j + 1][1] = nf.format(getPhase(0).getComponents()[j].getz(), buf, test).toString(); } + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 4][1] = + nf.format(getMolarMass() * 1000, buf, test).toString(); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 9][1] = + nf.format(getEnthalpy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) + .toString(); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 10][1] = + nf.format(getEntropy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) + .toString(); - this.isInitialized = true; - } + for (int i = 0; i < numberOfPhases; i++) { + for (int j = 0; j < getPhases()[0].getNumberOfComponents(); j++) { + table[j + 1][0] = getPhases()[0].getComponents()[j].getName(); + buf = new StringBuffer(); + table[j + 1][i + 2] = + nf.format(getPhase(i).getComponents()[j].getx(), buf, test).toString(); + table[j + 1][6] = "[mole fraction]"; + } - /** - *

- * initNumeric. - *

- * - * @param type a int - */ - public void initNumeric(int type) { - initNumeric(type, 1); - } + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 2][0] = "Density"; + table[getPhases()[0].getNumberOfComponents() + 2][i + 2] = + nf.format(getPhase(i).getPhysicalProperties().getDensity(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 2][6] = "[kg/m^3]"; - /** - *

- * initNumeric. - *

- * - * @param type a int - * @param phasen a int - */ - public void initNumeric(int type, int phasen) { - if (type < 2) { - initAnalytic(type); - } else if (type >= 2) { - double[][] gasfug = new double[2][getPhases()[0].getNumberOfComponents()]; - double[][] liqfug = new double[2][getPhases()[0].getNumberOfComponents()]; + // Double.longValue(system.getPhase(i).getBeta()); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 3][0] = "PhaseFraction"; + table[getPhases()[0].getNumberOfComponents() + 3][i + 2] = + nf.format(getPhase(i).getBeta(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 3][6] = "[mole fraction]"; - double dt = getTemperature() / 1.0e6; - setTemperature(getTemperature() + dt); - init(1); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 4][0] = "MolarMass"; + table[getPhases()[0].getNumberOfComponents() + 4][i + 2] = + nf.format(getPhase(i).getMolarMass() * 1000, buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 4][6] = "[kg/kmol]"; - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - gasfug[0][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[0][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); - } + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 5][0] = "Z factor"; + table[getPhases()[0].getNumberOfComponents() + 5][i + 2] = + nf.format(getPhase(i).getZ(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 5][6] = "[-]"; - setTemperature(getTemperature() - 2 * dt); - init(1); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 6][0] = "Heat Capacity (Cp)"; + table[getPhases()[0].getNumberOfComponents() + 6][i + 2] = nf.format( + (getPhase(i).getCp() + / (getPhase(i).getNumberOfMolesInPhase() * getPhase(i).getMolarMass() * 1000)), + buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 6][6] = "[kJ/kg*K]"; - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - gasfug[1][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[1][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); - } + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 7][0] = "Heat Capacity (Cv)"; + table[getPhases()[0].getNumberOfComponents() + 7][i + 2] = nf.format( + (getPhase(i).getCv() + / (getPhase(i).getNumberOfMolesInPhase() * getPhase(i).getMolarMass() * 1000)), + buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 7][6] = "[kJ/kg*K]"; - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - getPhase(0).getComponent(i).setdfugdt((gasfug[0][i] - gasfug[1][i]) / (2 * dt)); - getPhase(1).getComponent(i).setdfugdt((liqfug[0][i] - liqfug[1][i]) / (2 * dt)); - } + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 8][0] = "Speed of Sound"; + table[getPhases()[0].getNumberOfComponents() + 8][i + 2] = + nf.format((getPhase(i).getSoundSpeed()), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 8][6] = "[m/sec]"; - setTemperature(getTemperature() + dt); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 9][0] = "Enthalpy"; + table[getPhases()[0].getNumberOfComponents() + 9][i + 2] = nf.format( + (getPhase(i).getEnthalpy() + / (getPhase(i).getNumberOfMolesInPhase() * getPhase(i).getMolarMass() * 1000)), + buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 9][6] = "[kJ/kg]"; - double dp = getPressure() / 1.0e6; - setPressure(getPressure() + dp); - init(1); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 10][0] = "Entropy"; + table[getPhases()[0].getNumberOfComponents() + 10][i + 2] = nf.format( + (getPhase(i).getEntropy() + / (getPhase(i).getNumberOfMolesInPhase() * getPhase(i).getMolarMass() * 1000)), + buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 10][6] = "[kJ/kg*K]"; - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - gasfug[0][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[0][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); - } + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 11][0] = "JT coefficient"; + table[getPhases()[0].getNumberOfComponents() + 11][i + 2] = + nf.format((getPhase(i).getJouleThomsonCoefficient()), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 11][6] = "[K/bar]"; - setPressure(getPressure() - 2 * dp); - init(1); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 13][0] = "Viscosity"; + table[getPhases()[0].getNumberOfComponents() + 13][i + 2] = + nf.format((getPhase(i).getPhysicalProperties().getViscosity()), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 13][6] = "[kg/m*sec]"; - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - gasfug[1][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[1][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 14][0] = "Conductivity"; + table[getPhases()[0].getNumberOfComponents() + 14][i + 2] = + nf.format(getPhase(i).getPhysicalProperties().getConductivity(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 14][6] = "[W/m*K]"; + + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 15][0] = "SurfaceTension"; + try { + if (i < numberOfPhases - 1) { + table[getPhases()[0].getNumberOfComponents() + 15][2] = + nf.format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 15][3] = + nf.format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); + buf = new StringBuffer(); + if (i == 1) { + table[getPhases()[0].getNumberOfComponents() + 17][2] = + nf.format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 17][4] = + nf.format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 17][6] = "[N/m]"; + } + if (i == 1) { + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 16][3] = + nf.format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 16][4] = + nf.format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 16][6] = "[N/m]"; + } + } + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); } + table[getPhases()[0].getNumberOfComponents() + 15][6] = "[N/m]"; - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - getPhase(0).getComponent(i).setdfugdp((gasfug[0][i] - gasfug[1][i]) / (2 * dp)); - getPhase(1).getComponent(i).setdfugdp((liqfug[0][i] - liqfug[1][i]) / (2 * dp)); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 19][0] = "Pressure"; + table[getPhases()[0].getNumberOfComponents() + 19][i + 2] = + Double.toString(getPhase(i).getPressure()); + table[getPhases()[0].getNumberOfComponents() + 19][6] = "[bar]"; + + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 20][0] = "Temperature"; + table[getPhases()[0].getNumberOfComponents() + 20][i + 2] = + Double.toString(getPhase(i).getTemperature()); + table[getPhases()[0].getNumberOfComponents() + 20][6] = "[K]"; + Double.toString(getPhase(i).getTemperature()); + + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 22][0] = "Model"; + table[getPhases()[0].getNumberOfComponents() + 22][i + 2] = getModelName(); + table[getPhases()[0].getNumberOfComponents() + 22][6] = "-"; + + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 23][0] = "Mixing Rule"; + try { + table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = + ((PhaseEosInterface) getPhase(i)).getMixingRuleName(); + } catch (Exception ex) { + table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = "?"; + // logger.error(ex.getMessage(),e); } + table[getPhases()[0].getNumberOfComponents() + 23][6] = "-"; - setPressure(getPressure() + dp); - init(1); + buf = new StringBuffer(); + table[getPhases()[0].getNumberOfComponents() + 25][0] = "Stream"; + table[getPhases()[0].getNumberOfComponents() + 25][i + 2] = name; + table[getPhases()[0].getNumberOfComponents() + 25][6] = "-"; + } - if (type == 3) { - for (int phase = 0; phase < 2; phase++) { - for (int k = 0; k < getPhases()[0].getNumberOfComponents(); k++) { - double dn = getPhases()[phase].getComponents()[k].getNumberOfMolesInPhase() / 1.0e6; + resultTable = table; + return table; + } - addComponent(k, dn, phase); - // initBeta(); - init_x_y(); - init(1); + /** {@inheritDoc} */ + @Override + public void deleteFluidPhase(int phase) { + for (int i = phase; i < numberOfPhases; i++) { + phaseIndex[i] = phaseIndex[i + 1]; + } + numberOfPhases--; + } - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - liqfug[0][i] = - Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); - } + /** {@inheritDoc} */ + @Override + public void display(String name) { + if (this.getNumberOfComponents() == 0) { + return; + } + javax.swing.JFrame dialog = new javax.swing.JFrame("System-Report"); + java.awt.Dimension screenDimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); + java.awt.Container dialogContentPane = dialog.getContentPane(); + dialogContentPane.setLayout(new java.awt.BorderLayout()); - addComponent(k, -2.0 * dn, phase); - // initBeta(); - init_x_y(); - init(1); + String[] names = {"", "Feed", "Phase 1", "Phase 2", "Phase 3", "Phase 4", "Unit"}; + String[][] table = createTable(name); + javax.swing.JTable Jtab = new javax.swing.JTable(table, names); + javax.swing.JScrollPane scrollpane = new javax.swing.JScrollPane(Jtab); + dialogContentPane.add(scrollpane); - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - // gasfug[1][i] = - // Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[1][i] = - Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); - } - addComponent(k, dn, phase); - init_x_y(); - init(1); + // setting the size of the frame and text size + dialog.setSize(screenDimension.width / 2, screenDimension.height / 2); // pack(); + Jtab.setRowHeight(dialog.getHeight() / table.length); + Jtab.setFont(new java.awt.Font("Serif", java.awt.Font.PLAIN, + dialog.getHeight() / table.length - dialog.getHeight() / table.length / 10)); - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - getPhase(phase).getComponent(k).setdfugdn(i, - (liqfug[0][i] - liqfug[1][i]) / (2 * dn)); - getPhase(phase).getComponent(k).setdfugdx(i, (liqfug[0][i] - liqfug[1][i]) / (2 * dn) - * getPhase(phase).getNumberOfMolesInPhase()); - } - // initBeta(); - } - } - } + // dialog.pack(); + dialog.setVisible(true); + } + + /** {@inheritDoc} */ + @Override + public boolean doMultiPhaseCheck() { + return multiPhaseCheck; + } + + /** {@inheritDoc} */ + @Override + public final boolean doSolidPhaseCheck() { + return solidPhaseCheck; + } + + /** + *

+ * getAntoineVaporPressure. + *

+ * + * @param temp a double + * @return a double + */ + public double getAntoineVaporPressure(double temp) { + return phaseArray[0].getAntoineVaporPressure(temp); + } + + /** {@inheritDoc} */ + @Override + public final double getBeta() { + return beta[0]; + } + + /** {@inheritDoc} */ + @Override + public final double getBeta(int phase) { + return beta[phaseIndex[phase]]; + } + + /** {@inheritDoc} */ + @Override + public String[] getCapeOpenProperties10() { + return CapeOpenProperties10; + } + + /** {@inheritDoc} */ + @Override + public String[] getCapeOpenProperties11() { + return CapeOpenProperties11; + } + + /** {@inheritDoc} */ + @Override + public String[] getCASNumbers() { + String[] names = new String[numberOfComponents]; + + for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { + names[compNumb] = getPhase(0).getComponent(compNumb).getCASnumber(); } - this.isInitialized = true; + return names; } /** {@inheritDoc} */ @Override - public void initNumeric() { - double[][] gasfug = new double[2][getPhases()[0].getNumberOfComponents()]; - double[][] liqfug = new double[2][getPhases()[0].getNumberOfComponents()]; - double[][] gasnumericDfugdt = new double[2][getPhases()[0].getNumberOfComponents()]; - double[][] liqnumericDfugdt = new double[2][getPhases()[0].getNumberOfComponents()]; - double[][] gasnumericDfugdp = new double[2][getPhases()[0].getNumberOfComponents()]; - double[][] liqnumericDfugdp = new double[2][getPhases()[0].getNumberOfComponents()]; - double[][][] gasnumericDfugdn = new double[2][getPhases()[0] - .getNumberOfComponents()][getPhases()[0].getNumberOfComponents()]; - double[][][] liqnumericDfugdn = new double[2][getPhases()[0] - .getNumberOfComponents()][getPhases()[0].getNumberOfComponents()]; + public neqsim.thermo.characterization.Characterise getCharacterization() { + return characterization; + } - double dt = getTemperature() / 1e5; - setTemperature(getTemperature() + dt); - init(1); + /** {@inheritDoc} */ + @Override + public ChemicalReactionOperations getChemicalReactionOperations() { + return chemicalReactionOperations; + } - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - gasfug[0][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[0][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); + /** {@inheritDoc} */ + @Override + public String[] getCompFormulaes() { + String[] formula = new String[numberOfComponents]; + + for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { + formula[compNumb] = getPhase(0).getComponent(compNumb).getFormulae(); } + return formula; + } - setTemperature(getTemperature() - 2 * dt); - init(1); + /** {@inheritDoc} */ + @Override + public String[] getCompIDs() { + String[] ids = new String[numberOfComponents]; - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - gasfug[1][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[1][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); - gasnumericDfugdt[0][i] = (gasfug[0][i] - gasfug[1][i]) / (2 * dt); - liqnumericDfugdt[0][i] = (liqfug[0][i] - liqfug[1][i]) / (2 * dt); - phaseArray[0].getComponents()[i].setdfugdt(gasnumericDfugdt[0][i]); - phaseArray[1].getComponents()[i].setdfugdt(liqnumericDfugdt[0][i]); + for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { + ids[compNumb] = Integer.toString(getPhase(0).getComponent(compNumb).getIndex()); } + return ids; + } - setTemperature(getTemperature() + dt); - - double dp = getPressure() / 1e5; - setPressure(getPressure() + dp); - init(1); + /** {@inheritDoc} */ + @Override + public String[] getCompNames() { + String[] names = new String[numberOfComponents]; - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - gasfug[0][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[0][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); + for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { + names[compNumb] = getPhase(0).getComponent(compNumb).getComponentName(); } + return names; + } - setPressure(getPressure() - 2 * dp); - init(1); + /** {@inheritDoc} */ + @Override + public String[] getComponentNames() { + ArrayList components = new ArrayList(); - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - gasfug[1][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[1][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); - gasnumericDfugdp[0][i] = (gasfug[0][i] - gasfug[1][i]) / (2 * dp); - liqnumericDfugdp[0][i] = (liqfug[0][i] - liqfug[1][i]) / (2 * dp); - phaseArray[0].getComponents()[i].setdfugdp(gasnumericDfugdp[0][i]); - phaseArray[1].getComponents()[i].setdfugdp(liqnumericDfugdp[0][i]); + for (int j = 0; j < numberOfComponents; j++) { + components.add(phaseArray[0].getComponents()[j].getName()); + } + String[] componentList = new String[components.size()]; + for (int j = 0; j < numberOfComponents; j++) { + componentList[j] = components.get(j); } + return componentList; + } - setPressure(getPressure() + dp); - init(1); + /** {@inheritDoc} */ + @Override + public String getComponentNameTag() { + return componentNameTag; + } - for (int phase = 0; phase < 2; phase++) { - for (int k = 0; k < getPhases()[0].getNumberOfComponents(); k++) { - double dn = getPhases()[phase].getComponents()[k].getNumberOfMolesInPhase() / 1.0e6; - if (dn < 1e-12) { - dn = 1e-12; - } + /** + * {@inheritDoc} + * + *

+ * need to call initPhysicalProperties() before this method is called + *

+ */ + @Override + public double getCorrectedVolume() { + double volume = 0; + for (int i = 0; i < numberOfPhases; i++) { + volume += getPhase(i).getMolarMass() / getPhase(i).getPhysicalProperties().getDensity() + * getPhase(i).getNumberOfMolesInPhase(); + } + return volume; + } - addComponent(k, dn, phase); - // initBeta(); - init_x_y(); - init(1); + /** {@inheritDoc} */ + @Override + public double getCorrectedVolumeFraction(int phaseNumber) { + return getPhase(phaseNumber).getCorrectedVolume() / getCorrectedVolume(); + } - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - liqfug[0][i] = Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); - } + /** {@inheritDoc} */ + @Override + public double getCp() { + double cP = 0.0; + for (int i = 0; i < numberOfPhases; i++) { + cP += getPhase(i).getCp(); + } + return cP; + } - addComponent(k, -2.0 * dn, phase); - // initBeta(); - init_x_y(); - init(1); + /** {@inheritDoc} */ + @Override + public double getCp(String unit) { + double refCp = getCp(); // Cp in J/K + double conversionFactor = 1.0; + switch (unit) { + case "J/K": + conversionFactor = 1.0; + break; + case "J/molK": + conversionFactor = 1.0 / getTotalNumberOfMoles(); + break; + case "J/kgK": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); + break; + case "kJ/kgK": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; + break; + default: + throw new RuntimeException("unit not supported " + unit); + } + return refCp * conversionFactor; + } - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - // gasfug[1][i] = - // Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[1][i] = Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); - } + /** {@inheritDoc} */ + @Override + public double getCv() { + double cv = 0.0; + for (int i = 0; i < numberOfPhases; i++) { + cv += getPhase(i).getCv(); + } + return cv; + } - for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - if (phase == 0) { - gasnumericDfugdn[0][k][i] = (liqfug[0][i] - liqfug[1][i]) / (2 * dn); - phaseArray[0].getComponents()[i].setdfugdn(k, gasnumericDfugdn[0][k][i]); - phaseArray[0].getComponents()[i].setdfugdx(k, - gasnumericDfugdn[0][k][i] * phaseArray[0].getNumberOfMolesInPhase()); - } + /** {@inheritDoc} */ + @Override + public double getCv(String unit) { + double refCv = getCv(); // enthalpy in J + double conversionFactor = 1.0; + switch (unit) { + case "J/K": + conversionFactor = 1.0; + break; + case "J/molK": + conversionFactor = 1.0 / getTotalNumberOfMoles(); + break; + case "J/kgK": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); + break; + case "kJ/kgK": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; + break; + default: + throw new RuntimeException("unit not supported " + unit); + } + return refCv * conversionFactor; + } - if (phase == 1) { - liqnumericDfugdn[0][k][i] = (liqfug[0][i] - liqfug[1][i]) / (2 * dn); - phaseArray[1].getComponents()[i].setdfugdn(k, liqnumericDfugdn[0][k][i]); - phaseArray[1].getComponents()[i].setdfugdx(k, - liqnumericDfugdn[0][k][i] * phaseArray[1].getNumberOfMolesInPhase()); - } - } + /** {@inheritDoc} */ + @Override + public double getDensity() { + double density = 0; + for (int i = 0; i < numberOfPhases; i++) { + density += + 1.0e5 * (getPhase(i).getMolarMass() * beta[phaseIndex[i]] / getPhase(i).getMolarVolume()); + } + return density; + } - addComponent(k, dn, phase); - // initBeta(); - init_x_y(); - init(1); - } + /** {@inheritDoc} */ + @Override + public double getDensity(String unit) { + double density = 0; + for (int i = 0; i < getNumberOfPhases(); i++) { + density += + getPhase(i).getVolume() / getVolume() * getPhase(i).getPhysicalProperties().getDensity(); + } + double refDensity = density; // density in kg/m3 + double conversionFactor = 1.0; + switch (unit) { + case "kg/m3": + conversionFactor = 1.0; + break; + case "lb/ft3": + conversionFactor = 0.0624279606; + break; + case "kg/Sm3": + return getMolarMass() * ThermodynamicConstantsInterface.atm + / ThermodynamicConstantsInterface.R + / ThermodynamicConstantsInterface.standardStateTemperature; + case "mol/m3": + conversionFactor = 1.0 / getMolarMass(); + break; + default: + throw new RuntimeException("unit not supported " + unit); } + return refDensity * conversionFactor; } - /** {@inheritDoc} */ - @Override - public void initProperties() { - initThermoProperties(); - initPhysicalProperties(); + /** + * getPdVtn. + * + * @return dpdv + */ + public double getdPdVtn() { + double dPdV = 0.0; + for (int i = 0; i < numberOfPhases; i++) { + if (isPhase(i)) { + dPdV += getPhase(i).getdPdVTn() * getPhase(i).getVolume() / getVolume(); + } + } + return dPdV; } /** {@inheritDoc} */ @Override - public void initPhysicalProperties() { + public double getdVdPtn() { + double dVdP = 0.0; for (int i = 0; i < numberOfPhases; i++) { - getPhase(i).initPhysicalProperties(); + if (isPhase(i)) { + dVdP += 1.0 / getPhase(i).getdPdVTn(); + } } - calcInterfaceProperties(); + return dVdP; } /** {@inheritDoc} */ @Override - public void initPhysicalProperties(String propertyName) { + public double getdVdTpn() { + double dVdT = 0.0; for (int i = 0; i < numberOfPhases; i++) { - getPhase(i).initPhysicalProperties(propertyName); + if (isPhase(i)) { + dVdT += -getPhase(i).getdPdTVn() / getPhase(i).getdPdVTn(); + } } + return dVdT; } /** {@inheritDoc} */ @Override - public void resetPhysicalProperties() { - for (PhaseInterface tmpPhase : phaseArray) { - if (tmpPhase != null) { - tmpPhase.resetPhysicalProperties(); + public SystemInterface getEmptySystemClone() { + int phaseNumber = 0; + + SystemInterface newSystem = this.clone(); + + for (int j = 0; j < getMaxNumberOfPhases(); j++) { + phaseNumber = j; + for (int i = 0; i < getPhase(j).getNumberOfComponents(); i++) { + newSystem.getPhase(j).getComponents()[i].setNumberOfmoles( + getPhase(phaseNumber).getComponents()[i].getNumberOfMolesInPhase() / 1.0e30); + newSystem.getPhase(j).getComponents()[i].setNumberOfMolesInPhase( + getPhase(phaseNumber).getComponents()[i].getNumberOfMolesInPhase() / 1.0e30); } } + + newSystem.setTotalNumberOfMoles(getPhase(phaseNumber).getNumberOfMolesInPhase() / 1.0e30); + + newSystem.init(0); + // newSystem.init(1); + return newSystem; } /** {@inheritDoc} */ @Override - public void initRefPhases() { + public double getEnthalpy() { + double enthalpy = 0; for (int i = 0; i < numberOfPhases; i++) { - getPhase(i).initRefPhases(false); + enthalpy += getPhase(i).getEnthalpy(); } + return enthalpy; } /** {@inheritDoc} */ @Override - public void setPhysicalPropertyModel(int type) { - for (int i = 0; i < numberOfPhases; i++) { - getPhase(i).setPhysicalProperties(type); + public double getEnthalpy(String unit) { + double refEnthalpy = getEnthalpy(); // enthalpy in J + double conversionFactor = 1.0; + switch (unit) { + case "J": + conversionFactor = 1.0; + break; + case "kJ/kmol": + case "J/mol": + conversionFactor = 1.0 / getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); + break; + case "kJ/kg": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; + break; + default: + throw new RuntimeException("unit not supported " + unit); } + return refEnthalpy * conversionFactor; } /** {@inheritDoc} */ @Override - public void chemicalReactionInit() { - chemicalReactionOperations = new ChemicalReactionOperations(this); - chemicalSystem = chemicalReactionOperations.hasReactions(); + public double getEntropy() { + double entropy = 0; + for (int i = 0; i < numberOfPhases; i++) { + entropy += getPhase(i).getEntropy(); + } + return entropy; } /** {@inheritDoc} */ @Override - public ChemicalReactionOperations getChemicalReactionOperations() { - return chemicalReactionOperations; - } - - /** - * Verify if system has a phase of a specific type. - * - * @param pt PhaseType to look for. - * @return True if system contains a phase of requested type. - */ - @Override - public boolean hasPhaseType(PhaseType pt) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i) == null) { - continue; - } - if (getPhase(i).getType() == pt) { - return true; - } - if (getPhase(i).getPhaseTypeName().equals(pt.getDesc())) { - logger.error( - "Bug in setting phasetype somewhere. Phasetype and phasetypename should be the same."); - return true; - } + public double getEntropy(String unit) { + double refEntropy = getEntropy(); // entropy in J/K + double conversionFactor = 1.0; + switch (unit) { + case "J/K": + conversionFactor = 1.0; + break; + case "J/molK": + conversionFactor = 1.0 / getTotalNumberOfMoles(); + break; + case "J/kgK": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); + break; + case "kJ/kgK": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; + break; + default: + throw new RuntimeException("unit not supported " + unit); } - return false; + return refEntropy * conversionFactor; } /** {@inheritDoc} */ @Override - public final PhaseInterface getGasPhase() { - for (int phase = 0; phase < numberOfPhases; phase++) { - if (phaseArray[phaseIndex[phase]].getType() == PhaseType.GAS) { - return phaseArray[phase]; - } - } - logger.info("No gas phase at current state."); - return null; + public double getExergy(double temperatureOfSurroundings) { + double getExergy = getEnthalpy() - temperatureOfSurroundings * getEntropy(); + return getExergy; } /** {@inheritDoc} */ @Override - public final PhaseInterface getLiquidPhase() { - for (int phase = 0; phase < numberOfPhases; phase++) { - if (phaseArray[phaseIndex[phase]].getType() == PhaseType.LIQUID) { - return phaseArray[phase]; - } + public double getExergy(double temperatureOfSurroundings, String exergyUnit) { + double refExergy = getExergy(temperatureOfSurroundings); // exergy in J + double conversionFactor = 1.0; + switch (exergyUnit) { + case "J": + conversionFactor = 1.0; + break; + case "J/mol": + conversionFactor = 1.0 / getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); + break; + case "kJ/kg": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; + break; + default: + break; } - logger.info("No liquid phase at current state."); - return null; + return refExergy * conversionFactor; } /** {@inheritDoc} */ @Override - public boolean isPhase(int i) { - // TODO: what if i > numberofphases? - if (i > phaseArray.length) { - return false; + public double getFlowRate(String flowunit) { + if (flowunit.equals("kg/sec")) { + return totalNumberOfMoles * getMolarMass(); + } else if (flowunit.equals("kg/min")) { + return totalNumberOfMoles * getMolarMass() * 60.0; + } else if (flowunit.equals("kg/hr")) { + return totalNumberOfMoles * getMolarMass() * 3600.0; + } else if (flowunit.equals("kg/day")) { + return totalNumberOfMoles * getMolarMass() * 3600.0 * 24.0; + } else if (flowunit.equals("m3/sec")) { + initPhysicalProperties("density"); + return totalNumberOfMoles * getMolarMass() / getDensity("kg/m3"); + // return getVolume() / 1.0e5; + } else if (flowunit.equals("m3/min")) { + initPhysicalProperties("density"); + return totalNumberOfMoles * getMolarMass() * 60.0 / getDensity("kg/m3"); + // return getVolume() / 1.0e5 * 60.0; + } else if (flowunit.equals("m3/hr")) { + // return getVolume() / 1.0e5 * 3600.0; + initPhysicalProperties("density"); + return totalNumberOfMoles * getMolarMass() * 3600.0 / getDensity("kg/m3"); + } else if (flowunit.equals("idSm3/hr")) { + return totalNumberOfMoles * getMolarMass() * 3600.0 / getIdealLiquidDensity("kg/m3"); + } else if (flowunit.equals("Sm3/sec")) { + return totalNumberOfMoles * ThermodynamicConstantsInterface.R + * ThermodynamicConstantsInterface.standardStateTemperature + / ThermodynamicConstantsInterface.atm; + } else if (flowunit.equals("Sm3/hr")) { + return totalNumberOfMoles * 3600.0 * ThermodynamicConstantsInterface.R + * ThermodynamicConstantsInterface.standardStateTemperature + / ThermodynamicConstantsInterface.atm; + } else if (flowunit.equals("Sm3/day")) { + return totalNumberOfMoles * 3600.0 * 24.0 * ThermodynamicConstantsInterface.R + * ThermodynamicConstantsInterface.standardStateTemperature + / ThermodynamicConstantsInterface.atm; + } else if (flowunit.equals("MSm3/day")) { + return totalNumberOfMoles * 3600.0 * 24.0 * ThermodynamicConstantsInterface.R + * ThermodynamicConstantsInterface.standardStateTemperature + / ThermodynamicConstantsInterface.atm / 1.0e6; + } else if (flowunit.equals("MSm3/hr")) { + return totalNumberOfMoles * 3600.0 * ThermodynamicConstantsInterface.R + * ThermodynamicConstantsInterface.standardStateTemperature + / ThermodynamicConstantsInterface.atm / 1.0e6; + } else if (flowunit.equals("mole/sec")) { + return totalNumberOfMoles; + } else if (flowunit.equals("mole/min")) { + return totalNumberOfMoles * 60.0; + } else if (flowunit.equals("mole/hr")) { + return totalNumberOfMoles * 3600.0; + } else { + throw new RuntimeException("failed.. unit: " + flowunit + " not supported"); } - - // getPhase(i) without try/catch - return phaseArray[phaseIndex[i]] != null; } /** {@inheritDoc} */ - @Override - public final PhaseInterface getPhase(int i) { - if (i < 0) { - throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, "getPhase", - "i", i + " is not valid, must be in the range 0-" + this.getNumberOfPhases())); - } else if (i >= getNumberOfPhases() && phaseArray[phaseIndex[i]] == null) { - throw new RuntimeException(new neqsim.util.exception.InvalidInputException( - this.getClass() + ":getPhase - Can not return phase number " + i - + ". Current number of phases are " + getNumberOfPhases())); - } - return phaseArray[phaseIndex[i]]; + @Override + public String getFluidInfo() { + return fluidInfo; } /** {@inheritDoc} */ @Override - public PhaseInterface getPhase(PhaseType pt) { - if (!this.hasPhaseType(pt)) { - throw new RuntimeException("Phase with phase type " + pt + " not found."); - } - - int phaseNum = getPhaseNumberOfPhase(pt); - if (phaseNum >= 0) { - return getPhase(phaseNum); - } - - return null; + public String getFluidName() { + return fluidName; } /** {@inheritDoc} */ @Override - public PhaseInterface getPhase(String phaseTypeName) { - PhaseType pt = PhaseType.byDesc(phaseTypeName); - return getPhase(pt); + public double getGamma() { + return getCp() / getCv(); } /** {@inheritDoc} */ @Override - public PhaseInterface getPhaseOfType(String phaseTypeName) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { - return getPhase(i); + public final PhaseInterface getGasPhase() { + for (int phase = 0; phase < numberOfPhases; phase++) { + if (phaseArray[phaseIndex[phase]].getType() == PhaseType.GAS) { + return phaseArray[phase]; } } + logger.info("No gas phase at current state."); return null; } /** {@inheritDoc} */ @Override - public int getPhaseNumberOfPhase(PhaseType pt) { - // TODO: returning first if not found, not same as the others. + public double getGibbsEnergy() { + double gibbsEnergy = 0; for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getType() == pt) { - return i; - } + gibbsEnergy += getPhase(i).getGibbsEnergy(); } - return 0; + return gibbsEnergy; } /** {@inheritDoc} */ @Override - public final int getPhaseIndex(int index) { - return phaseIndex[index]; + public double getHeatOfVaporization() { + if (numberOfPhases < 2) { + return 0; + } else { + return getPhase(0).getEnthalpy() / getPhase(0).getNumberOfMolesInPhase() + - getPhase(1).getEnthalpy() / getPhase(1).getNumberOfMolesInPhase(); + } } /** {@inheritDoc} */ @Override - public int getPhaseIndex(String phaseTypeName) { - // TODO: returning first if not found, not same as the others. + public double getHelmholtzEnergy() { + double helmholtzEnergy = 0; for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { - return phaseIndex[i]; - } + helmholtzEnergy += getPhase(i).getHelmholtzEnergy(); } - return phaseIndex[0]; + return helmholtzEnergy; } /** {@inheritDoc} */ @Override - public int getPhaseIndex(PhaseInterface phase) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i) == phase) { - return phaseIndex[i]; - } - } - throw new RuntimeException( - new InvalidInputException(this, "getPhaseIndex", "phase", "is not found in phaseArray.")); + public boolean getHydrateCheck() { + return hydrateCheck; } /** {@inheritDoc} */ @Override - public final void setPhaseIndex(int index, int phaseIndex) { - this.phaseIndex[index] = phaseIndex; + public double getIdealLiquidDensity(String unit) { + double normalLiquidDensity = 0.0; + double molarMass = getMolarMass(); + for (int i = 0; i < getNumberOfComponents(); i++) { + normalLiquidDensity += getComponent(i).getNormalLiquidDensity() * getComponent(i).getz() + * getComponent(i).getMolarMass() / molarMass; + } + if (unit.equals("gr/cm3")) { + return normalLiquidDensity; + } else if (unit.equals("kg/m3")) { + return normalLiquidDensity * 1000.0; + } else { + logger.error("unit not supported: " + unit); + return normalLiquidDensity; + } } /** {@inheritDoc} */ @Override - public final boolean isChemicalSystem() { - return chemicalSystem; + public int getInitType() { + return initType; } /** {@inheritDoc} */ @Override - public final void isChemicalSystem(boolean temp) { - chemicalSystem = temp; + public double getInterfacialTension(int phase1, int phase2) { + return interfaceProp.getSurfaceTension(phase1, phase2); } - /** - *

- * getAntoineVaporPressure. - *

- * - * @param temp a double - * @return a double - */ - public double getAntoineVaporPressure(double temp) { - return phaseArray[0].getAntoineVaporPressure(temp); + /** {@inheritDoc} */ + @Override + public double getInterfacialTension(int phase1, int phase2, String unit) { + return interfaceProp.getSurfaceTension(phase1, phase2, unit); } /** {@inheritDoc} */ @Override - public final double getTC() { - return criticalTemperature; + public double getInterfacialTension(String phase1, String phase2) { + if (hasPhaseType(phase1) && hasPhaseType(phase2)) { + return interfaceProp.getSurfaceTension(getPhaseNumberOfPhase(phase1), + getPhaseNumberOfPhase(phase2)); + } else { + return Double.NaN; + } } /** {@inheritDoc} */ @Override - public final double getPC() { - return criticalPressure; + public double getInternalEnergy() { + double internalEnergy = 0; + for (int i = 0; i < numberOfPhases; i++) { + internalEnergy += getPhase(i).getInternalEnergy(); + } + return internalEnergy; } /** {@inheritDoc} */ @Override - public final void setTC(double TC) { - criticalTemperature = TC; + public double getInternalEnergy(String unit) { + double refEnthalpy = getInternalEnergy(); // enthalpy in J + double conversionFactor = 1.0; + switch (unit) { + case "J": + conversionFactor = 1.0; + break; + case "J/mole": + conversionFactor = 1.0 / getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); + break; + case "kJ/kg": + conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; + break; + default: + throw new RuntimeException("unit not supported " + unit); + } + return refEnthalpy * conversionFactor; } /** {@inheritDoc} */ @Override - public final void setPC(double PC) { - criticalPressure = PC; + public InterphasePropertiesInterface getInterphaseProperties() { + return interfaceProp; } - /** - *

- * setMixingRuleGEmodel. - *

- * - * @param name a {@link java.lang.String} object - */ - public void setMixingRuleGEmodel(String name) { - for (PhaseInterface tmpPhase : phaseArray) { - if (tmpPhase != null) { - tmpPhase.setMixingRuleGEModel(name); - } + /** {@inheritDoc} */ + @Override + public double getJouleThomsonCoefficient() { + double JTcoef = 0; + for (int i = 0; i < numberOfPhases; i++) { + JTcoef += getBeta(i) * getPhase(i).getJouleThomsonCoefficient(); } + return JTcoef; } /** {@inheritDoc} */ @Override - public final void setMixingRule(int type) { - mixingRule = type; - if (numberOfPhases < 4) { - resetPhysicalProperties(); // initPhysicalProperties(); - } - for (int i = 0; i < maxNumberOfPhases; i++) { - if (isPhase(i)) { - getPhase(i).setMixingRule(type); - getPhase(i).initPhysicalProperties(); - // getPhase(i).getPhysicalProperties().getMixingRule().initMixingRules(getPhase(i)); - } + public double getJouleThomsonCoefficient(String unit) { + double JTcoef = getJouleThomsonCoefficient(); + double conversionFactor = 1.0; + switch (unit) { + case "K/bar": + conversionFactor = 1.0; + break; + case "C/bar": + conversionFactor = 1.0; + break; + default: + break; } + return JTcoef * conversionFactor; } /** {@inheritDoc} */ @Override - public void setMixingRule(String typename, String GEmodel) { - setMixingRuleGEmodel(GEmodel); - setMixingRule(typename); + public double getKappa() { + return -getCp() / getCv() * getVolume() / getPressure() * getdPdVtn(); } /** {@inheritDoc} */ @Override - public void setMixingRule(String typename) { - int var = 0; - if (typename.equals("no")) { - var = 1; - } else if (typename.equals("classic")) { - var = 2; - } else if (typename.equals("HV")) { - var = 4; - } else if (typename.equals("WS")) { - var = 5; - } else if (typename.equals("CPA-Mix")) { - var = 7; - } else if (typename.equals("classic-T")) { - var = 8; - } else if (typename.equals("classic-T-cpa")) { - var = 9; - } else if (typename.equals("classic-Tx-cpa")) { - var = 10; - } else { - var = 1; - } - this.setMixingRule(var); + public double getKinematicViscosity() { + return getViscosity() / getDensity(); } /** {@inheritDoc} */ @Override - public void setNumberOfPhases(int number) { - this.numberOfPhases = number; - if (numberOfPhases > getMaxNumberOfPhases()) { - setMaxNumberOfPhases(number); + public double getKinematicViscosity(String unit) { + double refViscosity = getViscosity("kg/msec") / getDensity("kg/m3"); // viscosity in kg/msec + double conversionFactor = 1.0; + switch (unit) { + case "m2/sec": + conversionFactor = 1.0; + break; + default: + throw new RuntimeException("unit not supported " + unit); } + return refViscosity * conversionFactor; } /** {@inheritDoc} */ @Override - public void useVolumeCorrection(boolean volcor) { - for (PhaseInterface tmpPhase : phaseArray) { - if (tmpPhase != null) { - tmpPhase.useVolumeCorrection(volcor); + public final PhaseInterface getLiquidPhase() { + for (int phase = 0; phase < numberOfPhases; phase++) { + if (phaseArray[phaseIndex[phase]].getType() == PhaseType.LIQUID) { + return phaseArray[phase]; } } + logger.info("No liquid phase at current state."); + return null; } /** {@inheritDoc} */ @Override - public final PhaseInterface[] getPhases() { - return phaseArray; + public double getLiquidVolume() { + double totFlow = 0; + + for (int kj = 0; kj < numberOfPhases; kj++) { + if (getPhase(kj).getType() != PhaseType.GAS) { + totFlow += getPhase(kj).getVolume(); + } + } + return totFlow; } /** {@inheritDoc} */ @Override - public double getGibbsEnergy() { - double gibbsEnergy = 0; - for (int i = 0; i < numberOfPhases; i++) { - gibbsEnergy += getPhase(i).getGibbsEnergy(); + public PhaseInterface getLowestGibbsEnergyPhase() { + if (getPhase(0).getGibbsEnergy() < getPhase(1).getGibbsEnergy()) { + return getPhase(0); + } else { + return getPhase(1); } - return gibbsEnergy; } /** {@inheritDoc} */ @Override - public double getExergy(double temperatureOfSurroundings, String exergyUnit) { - double refExergy = getExergy(temperatureOfSurroundings); // exergy in J + public double getMass(String unit) { double conversionFactor = 1.0; - switch (exergyUnit) { - case "J": + switch (unit) { + case "kg": conversionFactor = 1.0; break; - case "J/mol": - conversionFactor = 1.0 / getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); + + case "gr": + conversionFactor = 1000.0; break; - case "kJ/kg": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; + case "tons": + conversionFactor = 1.0e-3; break; default: - break; + throw new RuntimeException("unit not supported " + unit); } - return refExergy * conversionFactor; + return conversionFactor * getTotalNumberOfMoles() * getMolarMass(); } /** {@inheritDoc} */ @Override - public double getExergy(double temperatureOfSurroundings) { - double getExergy = getEnthalpy() - temperatureOfSurroundings * getEntropy(); - return getExergy; + public int getMaxNumberOfPhases() { + return maxNumberOfPhases; } /** {@inheritDoc} */ @Override - public double getEnthalpy() { - double enthalpy = 0; - for (int i = 0; i < numberOfPhases; i++) { - enthalpy += getPhase(i).getEnthalpy(); - } - return enthalpy; + public int getMixingRule() { + return mixingRule; } /** {@inheritDoc} */ @Override - public double getEnthalpy(String unit) { - double refEnthalpy = getEnthalpy(); // enthalpy in J - double conversionFactor = 1.0; - switch (unit) { - case "J": - conversionFactor = 1.0; - break; - case "kJ/kmol": - case "J/mol": - conversionFactor = 1.0 / getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); - break; - case "kJ/kg": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; - break; - default: - throw new RuntimeException("unit not supported " + unit); + public String getMixingRuleName() { + return ((PhaseEosInterface) getPhase(0)).getMixingRule().getMixingRuleName(); + } + + /** {@inheritDoc} */ + @Override + public String getModelName() { + return modelName; + } + + /** {@inheritDoc} */ + @Override + public double[] getMolarComposition() { + PhaseInterface phase = this.getPhase(0); + double[] comp = new double[phase.getNumberOfComponents()]; + + for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { + comp[compNumb] = phase.getComponent(compNumb).getz(); } - return refEnthalpy * conversionFactor; + return comp; } /** {@inheritDoc} */ @Override - public double getViscosity() { - double visc = 0; - for (int i = 0; i < numberOfPhases; i++) { - visc += beta[phaseIndex[i]] * getPhase(i).getPhysicalProperties().getViscosity(); + public double getMolarMass() { + double tempVar = 0; + for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { + tempVar += + phaseArray[0].getComponents()[i].getz() * phaseArray[0].getComponents()[i].getMolarMass(); } - return visc; + return tempVar; } /** {@inheritDoc} */ @Override - public double getViscosity(String unit) { - double refViscosity = getViscosity(); // viscosity in kg/msec + public double getMolarMass(String unit) { + double refMolarMass = getMolarMass(); double conversionFactor = 1.0; switch (unit) { - case "kg/msec": + case "kg/mol": conversionFactor = 1.0; break; - case "cP": - conversionFactor = 1.0e3; - break; - case "Pas": - conversionFactor = 1.0; + case "gr/mol": + conversionFactor = 1000.0; break; default: throw new RuntimeException("unit not supported " + unit); } - return refViscosity * conversionFactor; + return refMolarMass * conversionFactor; } /** {@inheritDoc} */ @Override - public double getKinematicViscosity(String unit) { - double refViscosity = getViscosity("kg/msec") / getDensity("kg/m3"); // viscosity in kg/msec - double conversionFactor = 1.0; - switch (unit) { - case "m2/sec": - conversionFactor = 1.0; - break; - default: - throw new RuntimeException("unit not supported " + unit); + public double[] getMolarRate() { + double[] comp = new double[getPhase(0).getNumberOfComponents()]; + + for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { + comp[compNumb] = getPhase(0).getComponent(compNumb).getNumberOfmoles(); } - return refViscosity * conversionFactor; + return comp; } /** {@inheritDoc} */ @Override - public double getKinematicViscosity() { - return getViscosity() / getDensity(); + public double getMolarVolume() { + double volume = 0; + for (int i = 0; i < numberOfPhases; i++) { + volume += beta[phaseIndex[i]] * getPhase(i).getMolarVolume(); + } + return volume; } /** {@inheritDoc} */ @Override - public double getThermalConductivity() { - double cond = 0; + public double getMolarVolume(String unit) { + double volume = 0; for (int i = 0; i < numberOfPhases; i++) { - cond += beta[phaseIndex[i]] * getPhase(i).getPhysicalProperties().getConductivity(); + volume += beta[phaseIndex[i]] * getPhase(i).getMolarVolume(unit); } - return cond; + return volume; } /** {@inheritDoc} */ @Override - public double getThermalConductivity(String unit) { - double refConductivity = getThermalConductivity(); // conductivity in W/m*K - double conversionFactor = 1.0; - switch (unit) { - case "W/mK": - conversionFactor = 1.0; - break; - case "W/cmK": - conversionFactor = 0.01; - break; - default: - throw new RuntimeException("unit not supported " + unit); + public double[] getMolecularWeights() { + double[] mm = new double[numberOfComponents]; + + for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { + mm[compNumb] = getPhase(0).getComponent(compNumb).getMolarMass() * 1e3; } - return refConductivity * conversionFactor; + return mm; } /** {@inheritDoc} */ @Override - public double getInternalEnergy() { - double internalEnergy = 0; - for (int i = 0; i < numberOfPhases; i++) { - internalEnergy += getPhase(i).getInternalEnergy(); - } - return internalEnergy; + public double getMoleFraction(int phaseNumber) { + return getPhase(phaseNumber).getBeta(); } /** {@inheritDoc} */ @Override - public double getInternalEnergy(String unit) { - double refEnthalpy = getInternalEnergy(); // enthalpy in J - double conversionFactor = 1.0; - switch (unit) { - case "J": - conversionFactor = 1.0; - break; - case "J/mole": - conversionFactor = 1.0 / getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); - break; - case "kJ/kg": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; - break; - default: - throw new RuntimeException("unit not supported " + unit); + public double getMoleFractionsSum() { + double sumz = 0.0; + for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { + sumz += phaseArray[0].getComponent(i).getz(); } - return refEnthalpy * conversionFactor; + return sumz; } /** {@inheritDoc} */ @Override - public double getHelmholtzEnergy() { - double helmholtzEnergy = 0; - for (int i = 0; i < numberOfPhases; i++) { - helmholtzEnergy += getPhase(i).getHelmholtzEnergy(); + public double[] getNormalBoilingPointTemperatures() { + double[] bt = new double[numberOfComponents]; + + for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { + bt[compNumb] = getPhase(0).getComponent(compNumb).getNormalBoilingPoint() + 273.15; } - return helmholtzEnergy; + return bt; } /** {@inheritDoc} */ @Override - public double getEntropy() { - double entropy = 0; - for (int i = 0; i < numberOfPhases; i++) { - entropy += getPhase(i).getEntropy(); + public int getNumberOfComponents() { + return getComponentNames().length; + } + + /** {@inheritDoc} */ + @Override + public int getNumberOfOilFractionComponents() { + int number = 0; + for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { + if (getPhase(0).getComponent(i).isIsTBPfraction() + || getPhase(0).getComponent(i).isIsPlusFraction()) { + number++; + } } - return entropy; + return number; } /** {@inheritDoc} */ @Override - public double getEntropy(String unit) { - double refEntropy = getEntropy(); // entropy in J/K - double conversionFactor = 1.0; - switch (unit) { - case "J/K": - conversionFactor = 1.0; - break; - case "J/molK": - conversionFactor = 1.0 / getTotalNumberOfMoles(); - break; - case "J/kgK": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); - break; - case "kJ/kgK": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; - break; - default: - throw new RuntimeException("unit not supported " + unit); + public final int getNumberOfPhases() { + return numberOfPhases; + } + + /** {@inheritDoc} */ + @Override + public int[] getOilFractionIDs() { + int numb = getNumberOfOilFractionComponents(); + int[] IDs = new int[numb]; + // int number = 0; + for (int i = 0; i < numb; i++) { + if (getPhase(0).getComponent(i).isIsTBPfraction() + || getPhase(0).getComponent(i).isIsPlusFraction()) { + IDs[i] = getPhase(0).getComponent(i).getIndex(); + // number++; + } } - return refEntropy * conversionFactor; + return IDs; } /** {@inheritDoc} */ @Override - public double getMolarVolume(String unit) { - double volume = 0; - for (int i = 0; i < numberOfPhases; i++) { - volume += beta[phaseIndex[i]] * getPhase(i).getMolarVolume(unit); + public double[] getOilFractionLiquidDensityAt25C() { + int numb = getNumberOfOilFractionComponents(); + int[] indexes = getOilFractionIDs(); + double[] temp = new double[numb]; + for (int i = 0; i < numb; i++) { + temp[i] = getPhase(0).getComponentWithIndex(indexes[i]).getNormalLiquidDensity(); } - return volume; + return temp; } /** {@inheritDoc} */ @Override - public double getMolarVolume() { - double volume = 0; - for (int i = 0; i < numberOfPhases; i++) { - volume += beta[phaseIndex[i]] * getPhase(i).getMolarVolume(); + public double[] getOilFractionMolecularMass() { + int numb = getNumberOfOilFractionComponents(); + int[] indexes = getOilFractionIDs(); + double[] temp = new double[numb]; + for (int i = 0; i < numb; i++) { + temp[i] = getPhase(0).getComponentWithIndex(indexes[i]).getMolarMass(); } - return volume; + return temp; } /** {@inheritDoc} */ @Override - public double getDensity() { - double density = 0; - for (int i = 0; i < numberOfPhases; i++) { - density += - 1.0e5 * (getPhase(i).getMolarMass() * beta[phaseIndex[i]] / getPhase(i).getMolarVolume()); + public double[] getOilFractionNormalBoilingPoints() { + int numb = getNumberOfOilFractionComponents(); + int[] indexes = getOilFractionIDs(); + double[] temp = new double[numb]; + for (int i = 0; i < numb; i++) { + temp[i] = getPhase(0).getComponentWithIndex(indexes[i]).getNormalBoilingPoint(); } - return density; + return temp; } /** {@inheritDoc} */ @Override - public double getDensity(String unit) { - double density = 0; - for (int i = 0; i < getNumberOfPhases(); i++) { - density += - getPhase(i).getVolume() / getVolume() * getPhase(i).getPhysicalProperties().getDensity(); - } - double refDensity = density; // density in kg/m3 - double conversionFactor = 1.0; - switch (unit) { - case "kg/m3": - conversionFactor = 1.0; - break; - case "lb/ft3": - conversionFactor = 0.0624279606; - break; - case "kg/Sm3": - return getMolarMass() * ThermodynamicConstantsInterface.atm - / ThermodynamicConstantsInterface.R - / ThermodynamicConstantsInterface.standardStateTemperature; - case "mol/m3": - conversionFactor = 1.0 / getMolarMass(); - break; - default: - throw new RuntimeException("unit not supported " + unit); - } - return refDensity * conversionFactor; + public final double getPC() { + return criticalPressure; } /** {@inheritDoc} */ @Override - public double getZ() { - double Z = 0; - for (int i = 0; i < numberOfPhases; i++) { - Z += beta[phaseIndex[i]] * getPhase(i).getZ(); + public final PhaseInterface getPhase(int i) { + if (i < 0) { + throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, "getPhase", + "i", i + " is not valid, must be in the range 0-" + this.getNumberOfPhases())); + } else if (i >= getNumberOfPhases() && phaseArray[phaseIndex[i]] == null) { + throw new RuntimeException(new neqsim.util.exception.InvalidInputException( + this.getClass() + ":getPhase - Can not return phase number " + i + + ". Current number of phases are " + getNumberOfPhases())); } - return Z; + return phaseArray[phaseIndex[i]]; } /** {@inheritDoc} */ @Override - public double getMoleFractionsSum() { - double sumz = 0.0; - for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { - sumz += phaseArray[0].getComponent(i).getz(); + public PhaseInterface getPhase(PhaseType pt) { + if (!this.hasPhaseType(pt)) { + throw new RuntimeException("Phase with phase type " + pt + " not found."); } - return sumz; - } - /** {@inheritDoc} */ - @Override - public double getMolarMass() { - double tempVar = 0; - for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { - tempVar += - phaseArray[0].getComponents()[i].getz() * phaseArray[0].getComponents()[i].getMolarMass(); + int phaseNum = getPhaseNumberOfPhase(pt); + if (phaseNum >= 0) { + return getPhase(phaseNum); } - return tempVar; + + return null; } /** {@inheritDoc} */ @Override - public double getMolarMass(String unit) { - double refMolarMass = getMolarMass(); - double conversionFactor = 1.0; - switch (unit) { - case "kg/mol": - conversionFactor = 1.0; - break; - case "gr/mol": - conversionFactor = 1000.0; - break; - default: - throw new RuntimeException("unit not supported " + unit); - } - return refMolarMass * conversionFactor; + public PhaseInterface getPhase(String phaseTypeName) { + PhaseType pt = PhaseType.byDesc(phaseTypeName); + return getPhase(pt); } /** {@inheritDoc} */ @Override - public void setTemperature(double newTemperature) { - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - getPhases()[i].setTemperature(newTemperature); + public final double getPhaseFraction(String phaseTypeName, String unit) { + int phaseNumber = getPhaseNumberOfPhase(phaseTypeName); + switch (unit) { + case "mole": + return getBeta(phaseNumber); + case "volume": + return getVolumeFraction(phaseNumber); + case "mass": + initPhysicalProperties("density"); + return getVolumeFraction(phaseNumber) * getPhase(phaseNumber).getDensity("kg/m3") + / getDensity("kg/m3"); + default: + return getBeta(phaseNumber); } } /** {@inheritDoc} */ @Override - public final void setTemperature(double newTemperature, int phase) { - getPhase(phaseIndex[phase]).setTemperature(newTemperature); + public final int getPhaseIndex(int index) { + return phaseIndex[index]; } /** {@inheritDoc} */ @Override - public void setTemperature(double newTemperature, String unit) { - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - if (unit.equals("K")) { - getPhases()[i].setTemperature(newTemperature); - } else if (unit.equals("C")) { - getPhases()[i].setTemperature(newTemperature + 273.15); - } else { - throw new RuntimeException("unit not supported " + unit); + public int getPhaseIndex(PhaseInterface phase) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i) == phase) { + return phaseIndex[i]; } } + throw new RuntimeException( + new InvalidInputException(this, "getPhaseIndex", "phase", "is not found in phaseArray.")); } /** {@inheritDoc} */ @Override - public void setPhaseType(int phaseToChange, PhaseType pt) { - // System.out.println("new phase type: cha " + pt); - if (allowPhaseShift) { - phaseType[phaseIndex[phaseToChange]] = pt; + public int getPhaseIndex(String phaseTypeName) { + // TODO: returning first if not found, not same as the others. + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { + return phaseIndex[i]; + } } + return phaseIndex[0]; } /** {@inheritDoc} */ @Override - public void setAllPhaseType(PhaseType pt) { - if (allowPhaseShift) { - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - setPhaseType(i, pt); + public int getPhaseNumberOfPhase(PhaseType pt) { + // TODO: returning first if not found, not same as the others. + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getType() == pt) { + return i; } } + return 0; } /** {@inheritDoc} */ @Override - public void invertPhaseTypes() { - // Following code was from public void setPhaseType(int phaseToChange, String phaseTypeName) { - /* - * int newPhaseType = 0; if (phaseTypeName.equals("gas")) { newPhaseType = 1; } else if - * (StateOfMatter.isLiquid(PhaseType.byDesc(phaseTypeName))) { newPhaseType = 0; } else { - * newPhaseType = 0; } - */ - - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - if (phaseType[i] == PhaseType.byValue(0)) { - phaseType[i] = PhaseType.byValue(1); - } else { - phaseType[i] = PhaseType.byValue(0); + public PhaseInterface getPhaseOfType(String phaseTypeName) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { + return getPhase(i); } } + return null; } /** {@inheritDoc} */ @Override - public void setPhase(PhaseInterface phase, int index) { - double temp = phaseArray[index].getTemperature(); - double pres = phaseArray[index].getPressure(); - this.phaseArray[index] = phase; - this.phaseArray[index].setTemperature(temp); - this.phaseArray[index].setPressure(pres); + public final PhaseInterface[] getPhases() { + return phaseArray; } /** {@inheritDoc} */ @Override - public void reInitPhaseType() { - phaseType[0] = PhaseType.byValue(1); - phaseType[1] = PhaseType.byValue(0); - phaseType[2] = PhaseType.byValue(0); - phaseType[3] = PhaseType.byValue(0); - // TODO: why stop at 3 and not iterate through MAX_PHASES elements? - } - - /** - * Re-initialize phasetype, beta and phaseindex arrays, same initialization which is used in - * constructor. - */ - public void reInitPhaseInformation() { - reInitPhaseType(); - phaseType[4] = phaseType[3]; - phaseType[5] = phaseType[3]; - - for (int i = 0; i < MAX_PHASES; i++) { - beta[i] = 1.0; - } - - phaseIndex = new int[] {0, 1, 2, 3, 4, 5}; + public final double getPressure() { + return phaseArray[0].getPressure(); } /** {@inheritDoc} */ @Override - public final boolean doSolidPhaseCheck() { - return solidPhaseCheck; + public final double getPressure(int phaseNumber) { + return getPhase(phaseIndex[phaseNumber]).getPressure(); } /** {@inheritDoc} */ @Override - public final void setPressure(double newPressure) { - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - phaseArray[i].setPressure(newPressure); - } + public final double getPressure(String unit) { + neqsim.util.unit.PressureUnit presConversion = + new neqsim.util.unit.PressureUnit(getPressure(), "bara"); + return presConversion.getValue(unit); } /** {@inheritDoc} */ @Override - public final void setPressure(double newPressure, String unit) { - neqsim.util.unit.PressureUnit presConversion = - new neqsim.util.unit.PressureUnit(newPressure, unit); - setPressure(presConversion.getValue("bara")); + public SystemProperties getProperties() { + return new SystemProperties(this); } /** {@inheritDoc} */ @Override - public final double getTemperature() { - return phaseArray[0].getTemperature(); + public double getProperty(String prop) { + if (prop.equals("numberOfPhases")) { + return numberOfPhases; + } else if (prop.equals("numberOfComponents")) { + return numberOfComponents; + } else if (prop.equals("enthalpy")) { + return getEnthalpy(); + } else if (prop.equals("entropy")) { + return getEntropy(); + } else if (prop.equals("temperature")) { + return getTemperature(); + } else if (prop.equals("pressure")) { + return getPressure(); + } else { + return 1.0; + } } /** {@inheritDoc} */ @Override - public final double getTemperature(String unit) { - neqsim.util.unit.TemperatureUnit tempConversion = - new neqsim.util.unit.TemperatureUnit(getTemperature(), "K"); - return tempConversion.getValue(unit); + public double getProperty(String prop, int phase) { + initPhysicalProperties(); + if (prop.equals("temperature")) { + return getPhase(phase).getTemperature(); + } else if (prop.equals("pressure")) { + return getPhase(phase).getPressure(); + } else if (prop.equals("compressibility")) { + return getPhase(phase).getZ(); + } else if (prop.equals("density")) { + return getPhase(phase).getPhysicalProperties().getDensity(); + } else if (prop.equals("beta")) { + return getPhase(phase).getBeta(); + } else if (prop.equals("enthalpy")) { + return getPhase(phase).getEnthalpy(); + } else if (prop.equals("entropy")) { + return getPhase(phase).getEntropy(); + } else if (prop.equals("viscosity")) { + return getPhase(phase).getPhysicalProperties().getViscosity(); + } else if (prop.equals("conductivity")) { + return getPhase(phase).getPhysicalProperties().getConductivity(); + } else { + return 1.0; + } } /** {@inheritDoc} */ @Override - public double getTemperature(int phaseNumber) { - return getPhase(phaseIndex[phaseNumber]).getTemperature(); + public double getProperty(String prop, String compName, int phase) { + if (prop.equals("molefraction")) { + return getPhase(phase).getComponent(compName).getx(); + } else if (prop.equals("fugacitycoefficient")) { + return getPhase(phase).getComponent(compName).getFugacityCoefficient(); + } else if (prop.equals("logfugdT")) { + return getPhase(phase).getComponent(compName).getdfugdt(); + } else if (prop.equals("logfugdP")) { + return getPhase(phase).getComponent(compName).getdfugdp(); + } else { + return 1.0; + } } /** {@inheritDoc} */ @Override - public final double getPressure() { - return phaseArray[0].getPressure(); + public String[][] getResultTable() { + return resultTable; } /** {@inheritDoc} */ @Override - public final double getPressure(String unit) { - neqsim.util.unit.PressureUnit presConversion = - new neqsim.util.unit.PressureUnit(getPressure(), "bara"); - return presConversion.getValue(unit); + public double getSoundSpeed() { + double soundspeed = 0; + for (int i = 0; i < numberOfPhases; i++) { + soundspeed += getBeta(i) * getPhase(i).getSoundSpeed(); + } + return soundspeed; } /** {@inheritDoc} */ @Override - public final double getPressure(int phaseNumber) { - return getPhase(phaseIndex[phaseNumber]).getPressure(); + public double getSoundSpeed(String unit) { + double refVel = getSoundSpeed(); + double conversionFactor = 1.0; + switch (unit) { + case "m/s": + conversionFactor = 1.0; + break; + case "km/hr": + conversionFactor = 3.6; + break; + default: + break; + } + return refVel * conversionFactor; } /** {@inheritDoc} */ @Override - public final double getBeta() { - return beta[0]; + public neqsim.standards.StandardInterface getStandard() { + return standard; } /** {@inheritDoc} */ @Override - public final double getBeta(int phase) { - return beta[phaseIndex[phase]]; + public neqsim.standards.StandardInterface getStandard(String standardName) { + this.setStandard(standardName); + return standard; } public final double getSumBeta() { @@ -3061,683 +3048,739 @@ public final double getSumBeta() { /** {@inheritDoc} */ @Override - public void setAttractiveTerm(int i) { - for (int k = 0; k < getMaxNumberOfPhases(); k++) { - phaseArray[k].setAttractiveTerm(i); - } + public final double getTC() { + return criticalTemperature; } /** {@inheritDoc} */ @Override - public final int getNumberOfPhases() { - return numberOfPhases; + public final double getTemperature() { + return phaseArray[0].getTemperature(); } /** {@inheritDoc} */ @Override - public final void setBeta(double b) { - if (b < 0) { - b = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; - } - if (b > 1) { - b = 1.0 - neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; - } - beta[0] = b; - beta[1] = 1.0 - b; + public double getTemperature(int phaseNumber) { + return getPhase(phaseIndex[phaseNumber]).getTemperature(); } /** {@inheritDoc} */ @Override - public final void setBeta(int phase, double b) { - if (b < 0) { - b = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; - } - if (b > 1) { - b = 1.0 - neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; - } - beta[phaseIndex[phase]] = b; + public final double getTemperature(String unit) { + neqsim.util.unit.TemperatureUnit tempConversion = + new neqsim.util.unit.TemperatureUnit(getTemperature(), "K"); + return tempConversion.getValue(unit); } /** {@inheritDoc} */ @Override - public final double getVolume() { - double volume = 0.0; + public double getThermalConductivity() { + double cond = 0; for (int i = 0; i < numberOfPhases; i++) { - volume += getPhase(i).getMolarVolume() * getPhase(i).getNumberOfMolesInPhase(); - } - return volume; - } - - /** {@inheritDoc} */ - @Override - public double getVolume(String unit) { - double conversionFactor = 1.0; - switch (unit) { - case "m3": - conversionFactor = 1.0; - break; - case "m3/kg": - conversionFactor = 1.0 / getMass("kg"); - break; - case "litre": - conversionFactor = 1000.0; - break; - case "m3/mol": - conversionFactor = 1.0 / getTotalNumberOfMoles(); - break; - default: - throw new RuntimeException("unit not supported " + unit); + cond += beta[phaseIndex[i]] * getPhase(i).getPhysicalProperties().getConductivity(); } - return conversionFactor * getVolume() / 1.0e5; + return cond; } /** {@inheritDoc} */ @Override - public double getMass(String unit) { + public double getThermalConductivity(String unit) { + double refConductivity = getThermalConductivity(); // conductivity in W/m*K double conversionFactor = 1.0; switch (unit) { - case "kg": + case "W/mK": conversionFactor = 1.0; break; - - case "gr": - conversionFactor = 1000.0; - break; - case "tons": - conversionFactor = 1.0e-3; + case "W/cmK": + conversionFactor = 0.01; break; default: throw new RuntimeException("unit not supported " + unit); } - return conversionFactor * getTotalNumberOfMoles() * getMolarMass(); - } - - /** - * {@inheritDoc} - * - *

- * need to call initPhysicalProperties() before this method is called - *

- */ - @Override - public double getCorrectedVolume() { - double volume = 0; - for (int i = 0; i < numberOfPhases; i++) { - volume += getPhase(i).getMolarMass() / getPhase(i).getPhysicalProperties().getDensity() - * getPhase(i).getNumberOfMolesInPhase(); - } - return volume; - } - - /** - * getPdVtn. - * - * @return dpdv - */ - public double getdPdVtn() { - double dPdV = 0.0; - for (int i = 0; i < numberOfPhases; i++) { - if (isPhase(i)) { - dPdV += getPhase(i).getdPdVTn() * getPhase(i).getVolume() / getVolume(); - } - } - return dPdV; - } - - /** {@inheritDoc} */ - @Override - public double getdVdPtn() { - double dVdP = 0.0; - for (int i = 0; i < numberOfPhases; i++) { - if (isPhase(i)) { - dVdP += 1.0 / getPhase(i).getdPdVTn(); - } - } - return dVdP; + return refConductivity * conversionFactor; } /** {@inheritDoc} */ @Override - public double getdVdTpn() { - double dVdT = 0.0; - for (int i = 0; i < numberOfPhases; i++) { - if (isPhase(i)) { - dVdT += -getPhase(i).getdPdTVn() / getPhase(i).getdPdVTn(); - } - } - return dVdT; + public double getTotalNumberOfMoles() { + return this.totalNumberOfMoles; } /** {@inheritDoc} */ @Override - public double getCp() { - double cP = 0.0; + public double getViscosity() { + double visc = 0; for (int i = 0; i < numberOfPhases; i++) { - cP += getPhase(i).getCp(); + visc += beta[phaseIndex[i]] * getPhase(i).getPhysicalProperties().getViscosity(); } - return cP; + return visc; } /** {@inheritDoc} */ @Override - public double getCp(String unit) { - double refCp = getCp(); // Cp in J/K + public double getViscosity(String unit) { + double refViscosity = getViscosity(); // viscosity in kg/msec double conversionFactor = 1.0; switch (unit) { - case "J/K": + case "kg/msec": conversionFactor = 1.0; break; - case "J/molK": - conversionFactor = 1.0 / getTotalNumberOfMoles(); - break; - case "J/kgK": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); + case "cP": + conversionFactor = 1.0e3; break; - case "kJ/kgK": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; + case "Pas": + conversionFactor = 1.0; break; default: throw new RuntimeException("unit not supported " + unit); } - return refCp * conversionFactor; + return refViscosity * conversionFactor; } /** {@inheritDoc} */ @Override - public double getCv() { - double cv = 0.0; + public final double getVolume() { + double volume = 0.0; for (int i = 0; i < numberOfPhases; i++) { - cv += getPhase(i).getCv(); + volume += getPhase(i).getMolarVolume() * getPhase(i).getNumberOfMolesInPhase(); } - return cv; + return volume; } /** {@inheritDoc} */ @Override - public double getCv(String unit) { - double refCv = getCv(); // enthalpy in J + public double getVolume(String unit) { double conversionFactor = 1.0; switch (unit) { - case "J/K": + case "m3": conversionFactor = 1.0; break; - case "J/molK": - conversionFactor = 1.0 / getTotalNumberOfMoles(); + case "m3/kg": + conversionFactor = 1.0 / getMass("kg"); break; - case "J/kgK": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass(); + case "litre": + conversionFactor = 1000.0; break; - case "kJ/kgK": - conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; + case "m3/mol": + conversionFactor = 1.0 / getTotalNumberOfMoles(); break; default: throw new RuntimeException("unit not supported " + unit); } - return refCv * conversionFactor; + return conversionFactor * getVolume() / 1.0e5; } /** {@inheritDoc} */ @Override - public double getKappa() { - return -getCp() / getCv() * getVolume() / getPressure() * getdPdVtn(); + public double getVolumeFraction(int phaseNumber) { + return getPhase(phaseNumber).getVolume() / getVolume(); } /** {@inheritDoc} */ @Override - public double getGamma() { - return getCp() / getCv(); + public neqsim.thermo.characterization.WaxCharacterise getWaxCharacterisation() { + return waxCharacterisation; } /** {@inheritDoc} */ @Override - public void calcInterfaceProperties() { - interfaceProp.init(); + public WaxModelInterface getWaxModel() { + if (waxCharacterisation == null) { + waxCharacterisation = new WaxCharacterise(this); + } + return waxCharacterisation.getModel(); } /** {@inheritDoc} */ @Override - public InterphasePropertiesInterface getInterphaseProperties() { - return interfaceProp; + public double getWtFraction(int phaseNumber) { + return getPhase(phaseNumber).getWtFraction(this); } /** {@inheritDoc} */ @Override - public double getInterfacialTension(int phase1, int phase2) { - return interfaceProp.getSurfaceTension(phase1, phase2); + public double getZ() { + double Z = 0; + for (int i = 0; i < numberOfPhases; i++) { + Z += beta[phaseIndex[i]] * getPhase(i).getZ(); + } + return Z; + } + + /** + * Verify if system has a phase of a specific type. + * + * @param pt PhaseType to look for. + * @return True if system contains a phase of requested type. + */ + @Override + public boolean hasPhaseType(PhaseType pt) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i) == null) { + continue; + } + if (getPhase(i).getType() == pt) { + return true; + } + if (getPhase(i).getPhaseTypeName().equals(pt.getDesc())) { + logger.error( + "Bug in setting phasetype somewhere. Phasetype and phasetypename should be the same."); + return true; + } + } + return false; } /** {@inheritDoc} */ @Override - public double getInterfacialTension(int phase1, int phase2, String unit) { - return interfaceProp.getSurfaceTension(phase1, phase2, unit); + public boolean hasPlusFraction() { + for (int i = 0; i < numberOfComponents; i++) { + if (getPhase(0).getComponent(i).isIsPlusFraction()) { + return true; + } + } + return false; + } + + /** + *

+ * hasTBPFraction. + *

+ * + * @return a boolean + */ + public boolean hasTBPFraction() { + for (int i = 0; i < numberOfComponents; i++) { + if (getPhase(0).getComponent(i).isIsTBPfraction()) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public void init(int type) { + if (!this.isInitialized) { + initBeta(); + init_x_y(); + } + if (this.numericDerivatives) { + initNumeric(type); + } else { + initAnalytic(type); + } + this.isInitialized = true; + } + + /** {@inheritDoc} */ + @Override + public void init(int type, int phase) { + if (this.numericDerivatives) { + initNumeric(type, phase); + } else { + initAnalytic(type, phase); + } + } + + /** {@inheritDoc} */ + @Override + public final void init_x_y() { + // double x, z; + for (int j = 0; j < numberOfPhases; j++) { + // x = 0; + // z = 0; + for (int i = 0; i < numberOfComponents; i++) { + getPhase(j).getComponents()[i] + .setz(getPhase(j).getComponents()[i].getNumberOfmoles() / getTotalNumberOfMoles()); + getPhase(j).getComponents()[i].setx(getPhase(j).getComponents()[i].getNumberOfMolesInPhase() + / getPhase(j).getNumberOfMolesInPhase()); + } + getPhase(j).normalize(); + } + } + + /** + *

+ * initAnalytic. + *

+ * + * @param type a int. 0 to initialize and 1 to reset, 2 to calculate T and P derivatives, 3 to + * calculate all derivatives and 4 to calculate all derivatives numerically + */ + public void initAnalytic(int type) { + if (type == 0) { + reInitPhaseInformation(); + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + if (isPhase(i)) { + getPhase(i).init(getTotalNumberOfMoles(), numberOfComponents, type, + phaseType[phaseIndex[i]], beta[phaseIndex[i]]); + } + } + setNumberOfPhases(2); + } + + if (type > 0) { + for (int i = 0; i < numberOfPhases; i++) { + if (isPhase(i)) { + // todo: possible bug here, some components check for initType >= 3 + getPhase(i).init(getTotalNumberOfMoles(), numberOfComponents, Math.min(3, type), + phaseType[phaseIndex[i]], beta[phaseIndex[i]]); + } + } + + for (int i = 0; i < numberOfPhases; i++) { + if (isPhase(i)) { + for (int j = 0; j < numberOfComponents; j++) { + getPhase(i).getComponents()[j].fugcoef(getPhase(i)); + } + } + } + } + + if (type == 4) { // special case, calculate all derivatives numerically + for (int i = 0; i < numberOfPhases; i++) { + if (isPhase(i)) { + for (int j = 0; j < numberOfComponents; j++) { + // TODO: only runs two calculations init == 3 runs three + getPhase(i).getComponents()[j].fugcoefDiffTempNumeric(getPhase(i), numberOfComponents, + getPhase(i).getTemperature(), getPhase(i).getPressure()); + getPhase(i).getComponents()[j].fugcoefDiffPresNumeric(getPhase(i), numberOfComponents, + getPhase(i).getTemperature(), getPhase(i).getPressure()); + } + } + } + } else { + if (type > 1) { // calculate T and P derivatives + for (int i = 0; i < numberOfPhases; i++) { + if (isPhase(i)) { + for (int j = 0; j < numberOfComponents; j++) { + getPhase(i).getComponents()[j].logfugcoefdT(getPhase(i)); + getPhase(i).getComponents()[j].logfugcoefdP(getPhase(i)); + } + } + } + } + if (type == 3) { // calculate all derivatives + for (int i = 0; i < numberOfPhases; i++) { + if (isPhase(i)) { + for (int j = 0; j < numberOfComponents; j++) { + getPhase(i).getComponents()[j].logfugcoefdN(getPhase(i)); + } + } + } + } + } + + for (int i = 1; i < numberOfPhases; i++) { + if (isPhase(i)) { + if (getPhase(i).getType() == PhaseType.GAS) { + getPhase(i).setType(PhaseType.OIL); + } + } + } + this.isInitialized = true; } - /** {@inheritDoc} */ - @Override - public double getInterfacialTension(String phase1, String phase2) { - if (hasPhaseType(phase1) && hasPhaseType(phase2)) { - return interfaceProp.getSurfaceTension(getPhaseNumberOfPhase(phase1), - getPhaseNumberOfPhase(phase2)); - } else { - return Double.NaN; + /** + *

+ * initAnalytic. + *

+ * + * @param type a int + * @param phase a int + */ + public void initAnalytic(int type, int phase) { + if (type == 0) { + beta[0] = 1.0; + phaseIndex[phase] = phase; + } + + if (isPhase(phase)) { + getPhase(phase).init(getTotalNumberOfMoles(), numberOfComponents, type, + phaseType[phaseIndex[phase]], beta[phaseIndex[phase]]); + if (type > 0) { + for (int j = 0; j < numberOfComponents; j++) { + getPhase(phase).getComponents()[j].fugcoef(getPhase(phase)); + } + } + if (type > 1) { + for (int j = 0; j < numberOfComponents; j++) { + getPhase(phase).getComponents()[j].logfugcoefdT(getPhase(phase)); + getPhase(phase).getComponents()[j].logfugcoefdP(getPhase(phase)); + } + } + if (type > 2) { + for (int j = 0; j < numberOfComponents; j++) { + getPhase(phase).getComponents()[j].logfugcoefdT(getPhase(phase)); + getPhase(phase).getComponents()[j].logfugcoefdP(getPhase(phase)); + getPhase(phase).getComponents()[j].logfugcoefdN(getPhase(phase)); + } + } + } + + for (PhaseInterface tmpPhase : phaseArray) { + if (tmpPhase != null && tmpPhase.getType() == PhaseType.GAS) { + tmpPhase.setType(PhaseType.OIL); + } } + + this.isInitialized = true; } /** {@inheritDoc} */ @Override - public void normalizeBeta() { - double tot = 0.0; + public final void initBeta() { for (int i = 0; i < numberOfPhases; i++) { - tot += beta[phaseIndex[i]]; + this.beta[phaseIndex[i]] = getPhase(i).getNumberOfMolesInPhase() / getTotalNumberOfMoles(); } - for (int i = 0; i < numberOfPhases; i++) { - beta[phaseIndex[i]] /= tot; + if (this.getSumBeta() < 1.0 - ThermodynamicModelSettings.phaseFractionMinimumLimit + || this.getSumBeta() > 1.0 + ThermodynamicModelSettings.phaseFractionMinimumLimit) { + logger.warn("SystemThermo:initBeta - Sum of beta does not equal 1.0"); } } /** {@inheritDoc} */ @Override - public String[][] createTable(String name) { - initProperties(); - - java.text.DecimalFormat nf = new java.text.DecimalFormat(); + public void initNumeric() { + double[][] gasfug = new double[2][getPhases()[0].getNumberOfComponents()]; + double[][] liqfug = new double[2][getPhases()[0].getNumberOfComponents()]; + double[][] gasnumericDfugdt = new double[2][getPhases()[0].getNumberOfComponents()]; + double[][] liqnumericDfugdt = new double[2][getPhases()[0].getNumberOfComponents()]; + double[][] gasnumericDfugdp = new double[2][getPhases()[0].getNumberOfComponents()]; + double[][] liqnumericDfugdp = new double[2][getPhases()[0].getNumberOfComponents()]; + double[][][] gasnumericDfugdn = new double[2][getPhases()[0] + .getNumberOfComponents()][getPhases()[0].getNumberOfComponents()]; + double[][][] liqnumericDfugdn = new double[2][getPhases()[0] + .getNumberOfComponents()][getPhases()[0].getNumberOfComponents()]; - java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols(); - symbols.setDecimalSeparator('.'); - nf.setDecimalFormatSymbols(symbols); + double dt = getTemperature() / 1e5; + setTemperature(getTemperature() + dt); + init(1); - nf.setMaximumFractionDigits(5); - nf.applyPattern("#.#####E0"); + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + gasfug[0][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[0][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); + } - // String[][] table = new String[getPhases()[0].getNumberOfComponents() + - // 30][7]; - // String[] names = {"", "Feed", "Phase 1", "Phase 2", "Phase 3", "Phase 4", - // "Unit"}; - String[][] table = new String[getPhases()[0].getNumberOfComponents() + 30][7]; - table[0][0] = ""; // getPhases()[0].getType(); //""; + setTemperature(getTemperature() - 2 * dt); + init(1); - for (int i = 0; i < getPhases()[0].getNumberOfComponents() + 30; i++) { - for (int j = 0; j < 7; j++) { - table[i][j] = ""; - } + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + gasfug[1][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[1][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); + gasnumericDfugdt[0][i] = (gasfug[0][i] - gasfug[1][i]) / (2 * dt); + liqnumericDfugdt[0][i] = (liqfug[0][i] - liqfug[1][i]) / (2 * dt); + phaseArray[0].getComponents()[i].setdfugdt(gasnumericDfugdt[0][i]); + phaseArray[1].getComponents()[i].setdfugdt(liqnumericDfugdt[0][i]); } - table[0][1] = "total"; - for (int i = 0; i < numberOfPhases; i++) { - table[0][i + 2] = getPhase(i).getType().toString(); + + setTemperature(getTemperature() + dt); + + double dp = getPressure() / 1e5; + setPressure(getPressure() + dp); + init(1); + + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + gasfug[0][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[0][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); } - StringBuffer buf = new StringBuffer(); - java.text.FieldPosition test = new java.text.FieldPosition(0); - for (int j = 0; j < getPhases()[0].getNumberOfComponents(); j++) { - buf = new StringBuffer(); - table[j + 1][1] = nf.format(getPhase(0).getComponents()[j].getz(), buf, test).toString(); + setPressure(getPressure() - 2 * dp); + init(1); + + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + gasfug[1][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[1][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); + gasnumericDfugdp[0][i] = (gasfug[0][i] - gasfug[1][i]) / (2 * dp); + liqnumericDfugdp[0][i] = (liqfug[0][i] - liqfug[1][i]) / (2 * dp); + phaseArray[0].getComponents()[i].setdfugdp(gasnumericDfugdp[0][i]); + phaseArray[1].getComponents()[i].setdfugdp(liqnumericDfugdp[0][i]); } - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 4][1] = - nf.format(getMolarMass() * 1000, buf, test).toString(); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 9][1] = - nf.format(getEnthalpy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) - .toString(); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 10][1] = - nf.format(getEntropy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) - .toString(); - for (int i = 0; i < numberOfPhases; i++) { - for (int j = 0; j < getPhases()[0].getNumberOfComponents(); j++) { - table[j + 1][0] = getPhases()[0].getComponents()[j].getName(); - buf = new StringBuffer(); - table[j + 1][i + 2] = - nf.format(getPhase(i).getComponents()[j].getx(), buf, test).toString(); - table[j + 1][6] = "[mole fraction]"; - } + setPressure(getPressure() + dp); + init(1); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 2][0] = "Density"; - table[getPhases()[0].getNumberOfComponents() + 2][i + 2] = - nf.format(getPhase(i).getPhysicalProperties().getDensity(), buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 2][6] = "[kg/m^3]"; + for (int phase = 0; phase < 2; phase++) { + for (int k = 0; k < getPhases()[0].getNumberOfComponents(); k++) { + double dn = getPhases()[phase].getComponents()[k].getNumberOfMolesInPhase() / 1.0e6; + if (dn < 1e-12) { + dn = 1e-12; + } - // Double.longValue(system.getPhase(i).getBeta()); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 3][0] = "PhaseFraction"; - table[getPhases()[0].getNumberOfComponents() + 3][i + 2] = - nf.format(getPhase(i).getBeta(), buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 3][6] = "[mole fraction]"; + addComponent(k, dn, phase); + // initBeta(); + init_x_y(); + init(1); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 4][0] = "MolarMass"; - table[getPhases()[0].getNumberOfComponents() + 4][i + 2] = - nf.format(getPhase(i).getMolarMass() * 1000, buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 4][6] = "[kg/kmol]"; + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + liqfug[0][i] = Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); + } - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 5][0] = "Z factor"; - table[getPhases()[0].getNumberOfComponents() + 5][i + 2] = - nf.format(getPhase(i).getZ(), buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 5][6] = "[-]"; + addComponent(k, -2.0 * dn, phase); + // initBeta(); + init_x_y(); + init(1); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 6][0] = "Heat Capacity (Cp)"; - table[getPhases()[0].getNumberOfComponents() + 6][i + 2] = nf.format( - (getPhase(i).getCp() - / (getPhase(i).getNumberOfMolesInPhase() * getPhase(i).getMolarMass() * 1000)), - buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 6][6] = "[kJ/kg*K]"; + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + // gasfug[1][i] = + // Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[1][i] = Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); + } - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 7][0] = "Heat Capacity (Cv)"; - table[getPhases()[0].getNumberOfComponents() + 7][i + 2] = nf.format( - (getPhase(i).getCv() - / (getPhase(i).getNumberOfMolesInPhase() * getPhase(i).getMolarMass() * 1000)), - buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 7][6] = "[kJ/kg*K]"; + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + if (phase == 0) { + gasnumericDfugdn[0][k][i] = (liqfug[0][i] - liqfug[1][i]) / (2 * dn); + phaseArray[0].getComponents()[i].setdfugdn(k, gasnumericDfugdn[0][k][i]); + phaseArray[0].getComponents()[i].setdfugdx(k, + gasnumericDfugdn[0][k][i] * phaseArray[0].getNumberOfMolesInPhase()); + } - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 8][0] = "Speed of Sound"; - table[getPhases()[0].getNumberOfComponents() + 8][i + 2] = - nf.format((getPhase(i).getSoundSpeed()), buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 8][6] = "[m/sec]"; + if (phase == 1) { + liqnumericDfugdn[0][k][i] = (liqfug[0][i] - liqfug[1][i]) / (2 * dn); + phaseArray[1].getComponents()[i].setdfugdn(k, liqnumericDfugdn[0][k][i]); + phaseArray[1].getComponents()[i].setdfugdx(k, + liqnumericDfugdn[0][k][i] * phaseArray[1].getNumberOfMolesInPhase()); + } + } - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 9][0] = "Enthalpy"; - table[getPhases()[0].getNumberOfComponents() + 9][i + 2] = nf.format( - (getPhase(i).getEnthalpy() - / (getPhase(i).getNumberOfMolesInPhase() * getPhase(i).getMolarMass() * 1000)), - buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 9][6] = "[kJ/kg]"; + addComponent(k, dn, phase); + // initBeta(); + init_x_y(); + init(1); + } + } + } + + /** + *

+ * initNumeric. + *

+ * + * @param type a int + */ + public void initNumeric(int type) { + initNumeric(type, 1); + } + + /** + *

+ * initNumeric. + *

+ * + * @param type a int + * @param phasen a int + */ + public void initNumeric(int type, int phasen) { + if (type < 2) { + initAnalytic(type); + } else if (type >= 2) { + double[][] gasfug = new double[2][getPhases()[0].getNumberOfComponents()]; + double[][] liqfug = new double[2][getPhases()[0].getNumberOfComponents()]; + + double dt = getTemperature() / 1.0e6; + setTemperature(getTemperature() + dt); + init(1); + + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + gasfug[0][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[0][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); + } + + setTemperature(getTemperature() - 2 * dt); + init(1); + + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + gasfug[1][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[1][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); + } + + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + getPhase(0).getComponent(i).setdfugdt((gasfug[0][i] - gasfug[1][i]) / (2 * dt)); + getPhase(1).getComponent(i).setdfugdt((liqfug[0][i] - liqfug[1][i]) / (2 * dt)); + } - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 10][0] = "Entropy"; - table[getPhases()[0].getNumberOfComponents() + 10][i + 2] = nf.format( - (getPhase(i).getEntropy() - / (getPhase(i).getNumberOfMolesInPhase() * getPhase(i).getMolarMass() * 1000)), - buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 10][6] = "[kJ/kg*K]"; + setTemperature(getTemperature() + dt); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 11][0] = "JT coefficient"; - table[getPhases()[0].getNumberOfComponents() + 11][i + 2] = - nf.format((getPhase(i).getJouleThomsonCoefficient()), buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 11][6] = "[K/bar]"; + double dp = getPressure() / 1.0e6; + setPressure(getPressure() + dp); + init(1); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 13][0] = "Viscosity"; - table[getPhases()[0].getNumberOfComponents() + 13][i + 2] = - nf.format((getPhase(i).getPhysicalProperties().getViscosity()), buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 13][6] = "[kg/m*sec]"; + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + gasfug[0][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[0][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); + } - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 14][0] = "Conductivity"; - table[getPhases()[0].getNumberOfComponents() + 14][i + 2] = - nf.format(getPhase(i).getPhysicalProperties().getConductivity(), buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 14][6] = "[W/m*K]"; + setPressure(getPressure() - 2 * dp); + init(1); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 15][0] = "SurfaceTension"; - try { - if (i < numberOfPhases - 1) { - table[getPhases()[0].getNumberOfComponents() + 15][2] = - nf.format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 15][3] = - nf.format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); - buf = new StringBuffer(); - if (i == 1) { - table[getPhases()[0].getNumberOfComponents() + 17][2] = - nf.format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 17][4] = - nf.format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 17][6] = "[N/m]"; - } - if (i == 1) { - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 16][3] = - nf.format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 16][4] = - nf.format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); - table[getPhases()[0].getNumberOfComponents() + 16][6] = "[N/m]"; - } - } - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + gasfug[1][i] = Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[1][i] = Math.log(getPhases()[1].getComponents()[i].getFugacityCoefficient()); } - table[getPhases()[0].getNumberOfComponents() + 15][6] = "[N/m]"; - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 19][0] = "Pressure"; - table[getPhases()[0].getNumberOfComponents() + 19][i + 2] = - Double.toString(getPhase(i).getPressure()); - table[getPhases()[0].getNumberOfComponents() + 19][6] = "[bar]"; + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + getPhase(0).getComponent(i).setdfugdp((gasfug[0][i] - gasfug[1][i]) / (2 * dp)); + getPhase(1).getComponent(i).setdfugdp((liqfug[0][i] - liqfug[1][i]) / (2 * dp)); + } - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 20][0] = "Temperature"; - table[getPhases()[0].getNumberOfComponents() + 20][i + 2] = - Double.toString(getPhase(i).getTemperature()); - table[getPhases()[0].getNumberOfComponents() + 20][6] = "[K]"; - Double.toString(getPhase(i).getTemperature()); + setPressure(getPressure() + dp); + init(1); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 22][0] = "Model"; - table[getPhases()[0].getNumberOfComponents() + 22][i + 2] = getModelName(); - table[getPhases()[0].getNumberOfComponents() + 22][6] = "-"; + if (type == 3) { + for (int phase = 0; phase < 2; phase++) { + for (int k = 0; k < getPhases()[0].getNumberOfComponents(); k++) { + double dn = getPhases()[phase].getComponents()[k].getNumberOfMolesInPhase() / 1.0e6; - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 23][0] = "Mixing Rule"; - try { - table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = - ((PhaseEosInterface) getPhase(i)).getMixingRuleName(); - } catch (Exception ex) { - table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = "?"; - // logger.error(ex.getMessage(),e); - } - table[getPhases()[0].getNumberOfComponents() + 23][6] = "-"; + addComponent(k, dn, phase); + // initBeta(); + init_x_y(); + init(1); - buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 25][0] = "Stream"; - table[getPhases()[0].getNumberOfComponents() + 25][i + 2] = name; - table[getPhases()[0].getNumberOfComponents() + 25][6] = "-"; - } + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + liqfug[0][i] = + Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); + } - resultTable = table; - return table; + addComponent(k, -2.0 * dn, phase); + // initBeta(); + init_x_y(); + init(1); + + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + // gasfug[1][i] = + // Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); + liqfug[1][i] = + Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); + } + addComponent(k, dn, phase); + init_x_y(); + init(1); + + for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { + getPhase(phase).getComponent(k).setdfugdn(i, + (liqfug[0][i] - liqfug[1][i]) / (2 * dn)); + getPhase(phase).getComponent(k).setdfugdx(i, (liqfug[0][i] - liqfug[1][i]) / (2 * dn) + * getPhase(phase).getNumberOfMolesInPhase()); + } + // initBeta(); + } + } + } + } + this.isInitialized = true; } /** {@inheritDoc} */ @Override - public void display(String name) { - if (this.getNumberOfComponents() == 0) { - return; + public void initPhysicalProperties() { + for (int i = 0; i < numberOfPhases; i++) { + getPhase(i).initPhysicalProperties(); } - javax.swing.JFrame dialog = new javax.swing.JFrame("System-Report"); - java.awt.Dimension screenDimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); - java.awt.Container dialogContentPane = dialog.getContentPane(); - dialogContentPane.setLayout(new java.awt.BorderLayout()); - - String[] names = {"", "Feed", "Phase 1", "Phase 2", "Phase 3", "Phase 4", "Unit"}; - String[][] table = createTable(name); - javax.swing.JTable Jtab = new javax.swing.JTable(table, names); - javax.swing.JScrollPane scrollpane = new javax.swing.JScrollPane(Jtab); - dialogContentPane.add(scrollpane); - - // setting the size of the frame and text size - dialog.setSize(screenDimension.width / 2, screenDimension.height / 2); // pack(); - Jtab.setRowHeight(dialog.getHeight() / table.length); - Jtab.setFont(new java.awt.Font("Serif", java.awt.Font.PLAIN, - dialog.getHeight() / table.length - dialog.getHeight() / table.length / 10)); + calcInterfaceProperties(); + } - // dialog.pack(); - dialog.setVisible(true); + /** {@inheritDoc} */ + @Override + public void initPhysicalProperties(String propertyName) { + for (int i = 0; i < numberOfPhases; i++) { + getPhase(i).initPhysicalProperties(propertyName); + } } - /** - *

- * write. - *

- * - * @return a {@link java.lang.String} object - */ - public String write() { - // create a String description of the system - return ""; + /** {@inheritDoc} */ + @Override + public void initProperties() { + initThermoProperties(); + initPhysicalProperties(); } /** {@inheritDoc} */ @Override - public void write(String name, String filename, boolean newfile) { - String[][] table = createTable(name); - neqsim.dataPresentation.fileHandeling.createTextFile.TextFile file = - new neqsim.dataPresentation.fileHandeling.createTextFile.TextFile(); - if (newfile) { - file.newFile(filename); + public void initRefPhases() { + for (int i = 0; i < numberOfPhases; i++) { + getPhase(i).initRefPhases(false); } - file.setOutputFileName(filename); - file.setValues(table); - file.createFile(); } /** {@inheritDoc} */ @Override - public void resetDatabase() { - try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) { - if (NeqSimDataBase.createTemporaryTables()) { - database.execute("delete FROM comptemp"); - database.execute("delete FROM intertemp"); + public final void initTotalNumberOfMoles(double change) { + setTotalNumberOfMoles(getTotalNumberOfMoles() + change); + // System.out.println("total moles: " + totalNumberOfMoles); + for (int j = 0; j < numberOfPhases; j++) { + for (int i = 0; i < numberOfComponents; i++) { + getPhase(j).getComponents()[i] + .setNumberOfmoles(phaseArray[phaseIndex[0]].getComponents()[i].getNumberOfmoles()); } - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); } } /** {@inheritDoc} */ @Override - public void createDatabase(boolean reset) { - if (reset) { - resetDatabase(); - } - - try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) { - String names = new String(); - - for (int k = 0; k < getPhase(0).getNumberOfComponents() - 1; k++) { - names += "'" + this.getComponentNames()[k] + "', "; - } - names += "'" + this.getComponentNames()[getPhase(0).getNumberOfComponents() - 1] + "'"; - - if (NeqSimDataBase.createTemporaryTables()) { - database.execute("insert into comptemp SELECT * FROM comp WHERE name IN (" + names + ")"); - database.execute("insert into intertemp SELECT DISTINCT * FROM inter WHERE comp1 IN (" - + names + ") AND comp2 IN (" + names + ")"); - database.execute("delete FROM intertemp WHERE comp1=comp2"); - } - // System.out.println("ok " + names); - - for (int phase = 0; phase < maxNumberOfPhases; phase++) { - getPhase(phase).setMixingRuleDefined(false); - } + public void invertPhaseTypes() { + // Following code was from public void setPhaseType(int phaseToChange, String phaseTypeName) { + /* + * int newPhaseType = 0; if (phaseTypeName.equals("gas")) { newPhaseType = 1; } else if + * (StateOfMatter.isLiquid(PhaseType.byDesc(phaseTypeName))) { newPhaseType = 0; } else { + * newPhaseType = 0; } + */ - for (int i = 0; i < numberOfComponents; i++) { - if (getPhase(0).getComponent(i).isIsTBPfraction() - || getPhase(0).getComponent(i).isIsPlusFraction()) { - getPhase(0).getComponent(i).insertComponentIntoDatabase(""); - } + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + if (phaseType[i] == PhaseType.byValue(0)) { + phaseType[i] = PhaseType.byValue(1); + } else { + phaseType[i] = PhaseType.byValue(0); } - } catch (Exception ex) { - logger.error("error in SystemThermo Class...createDatabase() method", ex); } } /** {@inheritDoc} */ @Override - public void setSolidPhaseCheck(boolean solidPhaseCheck) { - this.solidPhaseCheck = solidPhaseCheck; - - final int oldphase = numberOfPhases; - if (solidPhaseCheck && !this.hasSolidPhase()) { - addSolidPhase(); - } - // init(0); - - for (int phase = 0; phase < numberOfPhases; phase++) { - for (int k = 0; k < getPhases()[0].getNumberOfComponents(); k++) { - getPhase(phase).getComponent(k).setSolidCheck(solidPhaseCheck); - getPhase(3).getComponent(k).setSolidCheck(solidPhaseCheck); - } - } - setNumberOfPhases(oldphase); + public final boolean isChemicalSystem() { + return chemicalSystem; } /** {@inheritDoc} */ @Override - public void setSolidPhaseCheck(String solidComponent) { - init(0); - final int oldphase = numberOfPhases; - if (!solidPhaseCheck) { - addSolidPhase(); - } - this.solidPhaseCheck = true; - init(0); + public final void isChemicalSystem(boolean temp) { + chemicalSystem = temp; + } - for (int phase = 0; phase < getMaxNumberOfPhases(); phase++) { - try { - getPhase(phase).getComponent(solidComponent).setSolidCheck(true); - getPhase(3).getComponent(solidComponent).setSolidCheck(true); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - } - } - setNumberOfPhases(oldphase); + /** {@inheritDoc} */ + @Override + public boolean isForcePhaseTypes() { + return forcePhaseTypes; } /** {@inheritDoc} */ @Override - public void setHydrateCheck(boolean hydrateCheck) { - init(0); - if (hydrateCheck) { - addHydratePhase(); - } - this.hydrateCheck = hydrateCheck; - init(0); + public boolean isImplementedCompositionDeriativesofFugacity() { + return implementedCompositionDeriativesofFugacity; } /** {@inheritDoc} */ @Override - public boolean doMultiPhaseCheck() { - return multiPhaseCheck; + public void isImplementedCompositionDeriativesofFugacity(boolean isImpl) { + this.implementedCompositionDeriativesofFugacity = isImpl; } /** {@inheritDoc} */ @Override - public void setMultiPhaseCheck(boolean multiPhaseCheck) { - if (getMaxNumberOfPhases() < 3) { - if (multiPhaseCheck) { - setMaxNumberOfPhases(3); - if (phaseArray[1] != null) { - phaseArray[2] = phaseArray[1].clone(); - phaseArray[2].resetMixingRule(phaseArray[0].getMixingRuleNumber()); - phaseArray[2].resetPhysicalProperties(); - phaseArray[2].initPhysicalProperties(); - } - } else { - setMaxNumberOfPhases(2); - } - } - this.multiPhaseCheck = multiPhaseCheck; + public boolean isImplementedPressureDeriativesofFugacity() { + return implementedPressureDeriativesofFugacity; } /** {@inheritDoc} */ @Override - public int getInitType() { - return initType; + public boolean isImplementedTemperatureDeriativesofFugacity() { + return implementedTemperatureDeriativesofFugacity; } /** {@inheritDoc} */ @Override - public void setInitType(int initType) { - this.initType = initType; + public boolean isMultiphaseWaxCheck() { + return multiphaseWaxCheck; } /** {@inheritDoc} */ @@ -3748,33 +3791,189 @@ public boolean isNumericDerivatives() { /** {@inheritDoc} */ @Override - public void setNumericDerivatives(boolean numericDerivatives) { - this.numericDerivatives = numericDerivatives; + public boolean isPhase(int i) { + // TODO: what if i > numberofphases? + if (i > phaseArray.length) { + return false; + } + + // getPhase(i) without try/catch + return phaseArray[phaseIndex[i]] != null; } /** {@inheritDoc} */ @Override - public void checkStability(boolean val) { - checkStability = val; + public void normalizeBeta() { + double tot = 0.0; + for (int i = 0; i < numberOfPhases; i++) { + tot += beta[phaseIndex[i]]; + } + for (int i = 0; i < numberOfPhases; i++) { + beta[phaseIndex[i]] /= tot; + } } /** {@inheritDoc} */ @Override - public boolean checkStability() { - return checkStability; + public void orderByDensity() { + boolean change = false; + // int count = 0; + + for (int i = 0; i < getNumberOfPhases(); i++) { + if (getPhase(i).getPhysicalProperties() == null) { + getPhase(i).initPhysicalProperties("density"); + } + getPhase(i).getPhysicalProperties().setPhase(getPhase(i)); + } + + do { + change = false; + // count++; + for (int i = 1; i < getNumberOfPhases(); i++) { + if (i == 4) { + break; + } + + try { + if (change || getPhase(i).getPhysicalProperties() == null) { + getPhase(i).initPhysicalProperties("density"); + } + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + if (getPhase(i).getPhysicalProperties().calcDensity() < getPhase(i - 1) + .getPhysicalProperties().calcDensity()) { + int tempIndex1 = getPhaseIndex(i - 1); + int tempIndex2 = getPhaseIndex(i); + setPhaseIndex(i, tempIndex1); + setPhaseIndex(i - 1, tempIndex2); + change = true; + } + } + } while (change); } /** {@inheritDoc} */ @Override - public boolean getHydrateCheck() { - return hydrateCheck; + public SystemInterface phaseToSystem(int phaseNumber) { + SystemInterface newSystem = this.clone(); + + for (int j = 0; j < getMaxNumberOfPhases(); j++) { + for (int i = 0; i < getPhase(j).getNumberOfComponents(); i++) { + newSystem.getPhase(j).getComponent(i) + .setNumberOfmoles(getPhase(phaseNumber).getComponent(i).getNumberOfMolesInPhase()); + newSystem.getPhase(j).getComponent(i).setNumberOfMolesInPhase( + getPhase(phaseNumber).getComponent(i).getNumberOfMolesInPhase()); + } + } + + newSystem.setTotalNumberOfMoles(getPhase(phaseNumber).getNumberOfMolesInPhase()); + + newSystem.init(0); + newSystem.setNumberOfPhases(1); + newSystem.setPhaseType(0, getPhase(phaseNumber).getType()); // phaseType[phaseNumber]); + newSystem.init(1); + return newSystem; } /** {@inheritDoc} */ @Override - public void save(String name) { - try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(name))) { - out.writeObject(this); + public SystemInterface phaseToSystem(int phaseNumber1, int phaseNumber2) { + SystemInterface newSystem = this.clone(); + + for (int j = 0; j < getMaxNumberOfPhases(); j++) { + for (int i = 0; i < getPhase(j).getNumberOfComponents(); i++) { + newSystem.getPhases()[j].getComponents()[i] + .setNumberOfmoles(getPhase(phaseNumber1).getComponents()[i].getNumberOfMolesInPhase() + + getPhase(phaseNumber2).getComponents()[i].getNumberOfMolesInPhase()); + newSystem.getPhases()[j].getComponents()[i].setNumberOfMolesInPhase( + getPhase(phaseNumber1).getComponents()[i].getNumberOfMolesInPhase() + + getPhase(phaseNumber2).getComponents()[i].getNumberOfMolesInPhase()); + } + } + + newSystem.setTotalNumberOfMoles(getPhase(phaseNumber1).getNumberOfMolesInPhase() + + getPhase(phaseNumber2).getNumberOfMolesInPhase()); + + newSystem.init(0); + + newSystem.setNumberOfPhases(1); + // newSystem.setPhaseType(0, + // getPhase(phaseNumber1).getType()); //phaseType[phaseNumber]); + newSystem.init(1); + return newSystem; + } + + /** {@inheritDoc} */ + @Override + public SystemInterface phaseToSystem(PhaseInterface newPhase) { + // TODO: other phaseToSystem functions returns clones. + for (int i = 0; i < newPhase.getNumberOfComponents(); i++) { + newPhase.getComponents()[i] + .setNumberOfmoles(newPhase.getComponents()[i].getNumberOfMolesInPhase()); + } + + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + phaseArray[i] = newPhase.clone(); + } + + setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); + this.init(0); + setNumberOfPhases(1); + setPhaseType(0, newPhase.getType()); + initBeta(); + init_x_y(); + this.init(1); + return this; + } + + /** {@inheritDoc} */ + @Override + public SystemInterface phaseToSystem(String phaseName) { + try { + for (int j = 0; j < getMaxNumberOfPhases(); j++) { + if (this.getPhase(j).getPhaseTypeName().equals(phaseName)) { + return phaseToSystem(j); + } + } + } catch (Exception ex) { + logger.error("error....." + fluidName + " has no phase .... " + phaseName + + " ..... returning phase number 0"); + } + return phaseToSystem(0); + } + + /** {@inheritDoc} */ + @Override + public void readFluid(String fluidName) { + this.fluidName = fluidName; + try { + neqsim.util.database.NeqSimFluidDataBase database = + new neqsim.util.database.NeqSimFluidDataBase(); + java.sql.ResultSet dataSet = null; + dataSet = database.getResultSet("SELECT * FROM " + fluidName); + + while (dataSet.next()) { + String componentType = dataSet.getString("ComponentType"); + + if (componentType.equalsIgnoreCase("normal")) { + addComponent(dataSet.getString("ComponentName"), + Double.parseDouble(dataSet.getString("Rate"))); + } else if (componentType.equalsIgnoreCase("TBP")) { + addTBPfraction(dataSet.getString("ComponentName"), + Double.parseDouble(dataSet.getString("Rate")), + Double.parseDouble(dataSet.getString("MolarMass")) / 1000.0, + Double.parseDouble(dataSet.getString("Density"))); + } else if (componentType.equalsIgnoreCase("plus")) { + addPlusFraction(dataSet.getString("ComponentName"), + Double.parseDouble(dataSet.getString("Rate")), + Double.parseDouble(dataSet.getString("MolarMass")) / 1000.0, + Double.parseDouble(dataSet.getString("Density"))); + } else { + logger.error( + "component type need to be specified for ... " + dataSet.getString("ComponentName")); + } + } } catch (Exception ex) { logger.error(ex.getMessage(), ex); } @@ -3817,76 +4016,6 @@ public SystemInterface readObject(int ID) { return tempSystem; } - /** {@inheritDoc} */ - @Override - public void saveFluid(int ID) { - saveObject(ID, ""); - } - - /** {@inheritDoc} */ - @Override - public void saveFluid(int ID, String text) { - saveObject(ID, text); - } - - /** {@inheritDoc} */ - @Override - public void saveObject(int ID, String text) { - ByteArrayOutputStream fout = new ByteArrayOutputStream(); - try (ObjectOutputStream out = new ObjectOutputStream(fout)) { - out.writeObject(this); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - } - byte[] byteObject = fout.toByteArray(); - ByteArrayInputStream inpStream = new ByteArrayInputStream(byteObject); - - neqsim.util.database.NeqSimBlobDatabase database = - new neqsim.util.database.NeqSimBlobDatabase(); - - try { - java.sql.Connection con = database.openConnection(); - - java.sql.PreparedStatement ps = - con.prepareStatement("REPLACE INTO fluid_blobdb (ID, FLUID) VALUES (?,?)"); - ps.setInt(1, ID); - ps.setBlob(2, inpStream); - - ps.executeUpdate(); - /* - * if (!text.isEmpty()) { ps = con.prepareStatement( - * "REPLACE INTO fluidinfo (ID, TEXT) VALUES (?,?)"); ps.setInt(1, ID); ps.setString(2, text); - * } - * - * ps.executeUpdate(); - */ - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - } finally { - try { - if (database.getStatement() != null) { - database.getStatement().close(); - } - if (database.getConnection() != null) { - database.getConnection().close(); - } - } catch (Exception ex) { - logger.error("err closing database IN MIX...", ex); - } - } - // database.execute("INSERT INTO fluid_blobdb VALUES ('1'," + sqlString + ")"); - } - - /** {@inheritDoc} */ - @Override - public void saveObjectToFile(String filePath, String fluidName) { - try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filePath, false))) { - out.writeObject(this); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - } - } - /** {@inheritDoc} */ @Override public SystemInterface readObjectFromFile(String filePath, String fluidName) { @@ -3900,346 +4029,256 @@ public SystemInterface readObjectFromFile(String filePath, String fluidName) { return tempSystem; } - /** {@inheritDoc} */ - @Override - public String getMixingRuleName() { - return ((PhaseEosInterface) getPhase(0)).getMixingRule().getMixingRuleName(); - } - - /** {@inheritDoc} */ - @Override - public String getFluidInfo() { - return fluidInfo; - } - - /** {@inheritDoc} */ - @Override - public void setFluidInfo(String info) { - this.fluidInfo = info; - } - - /** {@inheritDoc} */ - @Override - public String getFluidName() { - return fluidName; - } - - /** {@inheritDoc} */ - @Override - public void setFluidName(String fluidName) { - this.fluidName = fluidName; - } - - /** - *

- * setLastTBPasPlus. - *

- * - * @return a boolean - */ - public boolean setLastTBPasPlus() { - neqsim.thermo.characterization.PlusCharacterize temp = - new neqsim.thermo.characterization.PlusCharacterize(this); - if (temp.hasPlusFraction()) { - return false; - } else { - temp.setHeavyTBPtoPlus(); - } - return true; - } - - /** {@inheritDoc} */ - @Override - public neqsim.thermo.characterization.Characterise getCharacterization() { - return characterization; - } - - /** {@inheritDoc} */ - @Override - public void calcKIJ(boolean ok) { - neqsim.thermo.mixingRule.EosMixingRules.calcEOSInteractionParameters = ok; - for (int i = 0; i < numberOfPhases; i++) { - ((PhaseEosInterface) getPhase(i)).getMixingRule().setCalcEOSInteractionParameters(ok); - } - } - - /** {@inheritDoc} */ - @Override - public String getModelName() { - return modelName; - } - /** - * Setter for property modelName. - * - * @param modelName New value of property modelName. + * Re-initialize phasetype, beta and phaseindex arrays, same initialization which is used in + * constructor. */ - public void setModelName(String modelName) { - this.modelName = modelName; - } - - /** {@inheritDoc} */ - @Override - public boolean allowPhaseShift() { - return allowPhaseShift; - } - - /** {@inheritDoc} */ - @Override - public void allowPhaseShift(boolean allowPhaseShift) { - this.allowPhaseShift = allowPhaseShift; - } - - /** {@inheritDoc} */ - @Override - public double getProperty(String prop, String compName, int phase) { - if (prop.equals("molefraction")) { - return getPhase(phase).getComponent(compName).getx(); - } else if (prop.equals("fugacitycoefficient")) { - return getPhase(phase).getComponent(compName).getFugacityCoefficient(); - } else if (prop.equals("logfugdT")) { - return getPhase(phase).getComponent(compName).getdfugdt(); - } else if (prop.equals("logfugdP")) { - return getPhase(phase).getComponent(compName).getdfugdp(); - } else { - return 1.0; - } - } + public void reInitPhaseInformation() { + reInitPhaseType(); + phaseType[4] = phaseType[3]; + phaseType[5] = phaseType[3]; - /** {@inheritDoc} */ - @Override - public double getProperty(String prop, int phase) { - initPhysicalProperties(); - if (prop.equals("temperature")) { - return getPhase(phase).getTemperature(); - } else if (prop.equals("pressure")) { - return getPhase(phase).getPressure(); - } else if (prop.equals("compressibility")) { - return getPhase(phase).getZ(); - } else if (prop.equals("density")) { - return getPhase(phase).getPhysicalProperties().getDensity(); - } else if (prop.equals("beta")) { - return getPhase(phase).getBeta(); - } else if (prop.equals("enthalpy")) { - return getPhase(phase).getEnthalpy(); - } else if (prop.equals("entropy")) { - return getPhase(phase).getEntropy(); - } else if (prop.equals("viscosity")) { - return getPhase(phase).getPhysicalProperties().getViscosity(); - } else if (prop.equals("conductivity")) { - return getPhase(phase).getPhysicalProperties().getConductivity(); - } else { - return 1.0; + for (int i = 0; i < MAX_PHASES; i++) { + beta[i] = 1.0; } - } - /** {@inheritDoc} */ - @Override - public double getProperty(String prop) { - if (prop.equals("numberOfPhases")) { - return numberOfPhases; - } else if (prop.equals("numberOfComponents")) { - return numberOfComponents; - } else if (prop.equals("enthalpy")) { - return getEnthalpy(); - } else if (prop.equals("entropy")) { - return getEntropy(); - } else if (prop.equals("temperature")) { - return getTemperature(); - } else if (prop.equals("pressure")) { - return getPressure(); - } else { - return 1.0; - } + phaseIndex = new int[] {0, 1, 2, 3, 4, 5}; } /** {@inheritDoc} */ @Override - public void saveToDataBase() { - // java.sql.ResultSet dataSet = database.getResultSet(("SELECT * FROM - // SYSTEMREPORT")); - // double molarmass = 0.0, stddens = 0.0, boilp = 0.0; - try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) { - database.execute("delete FROM systemreport"); - int i = 0; - for (; i < numberOfComponents; i++) { - String sqlString = - "'" + Integer.toString(i + 1) + "', '" + getPhase(0).getComponent(i).getName() + "', " - + "'molfrac[-] ', '" + Double.toString(getPhase(0).getComponent(i).getz()) + "'"; - - int j = 0; - for (; j < numberOfPhases; j++) { - sqlString += ", '" + Double.toString(getPhase(j).getComponent(i).getx()) + "'"; - } - - while (j < 3) { - j++; - sqlString += ", '0'"; - } + public void reInitPhaseType() { + phaseType[0] = PhaseType.byValue(1); + phaseType[1] = PhaseType.byValue(0); + phaseType[2] = PhaseType.byValue(0); + phaseType[3] = PhaseType.byValue(0); + // TODO: why stop at 3 and not iterate through MAX_PHASES elements? + } - logger.error(sqlString); + /** {@inheritDoc} */ + @Override + public void removeComponent(String name) { + name = ComponentInterface.getComponentNameFromAlias(name); - database.execute("INSERT INTO systemreport VALUES (" + sqlString + ")"); - } + setTotalNumberOfMoles( + getTotalNumberOfMoles() - phaseArray[0].getComponent(name).getNumberOfmoles()); + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + getPhase(i).removeComponent(name, getTotalNumberOfMoles(), + getPhase(i).getComponent(name).getNumberOfMolesInPhase()); + } - // beta - i++; + componentNames.remove(name); + numberOfComponents--; + } - String sqlString = "'" + Integer.toString(i + 1) + "', 'PhaseFraction', " + "'[-]', '1'"; + /** {@inheritDoc} */ + @Override + public void removePhase(int specPhase) { + setTotalNumberOfMoles(getTotalNumberOfMoles() - getPhase(specPhase).getNumberOfMolesInPhase()); - int j = 0; - for (; j < numberOfPhases; j++) { - sqlString += ", '" + Double.toString(getPhase(j).getBeta()) + "'"; + for (int j = 0; j < numberOfPhases; j++) { + for (int i = 0; i < numberOfComponents; i++) { + getPhase(j).getComponents()[i] + .setNumberOfmoles(getPhase(j).getComponents()[i].getNumberOfmoles() + - getPhase(specPhase).getComponents()[i].getNumberOfMolesInPhase()); } + } - while (j < 3) { - j++; - sqlString += ", '0'"; + ArrayList phaseList = new ArrayList(0); + for (int i = 0; i < numberOfPhases; i++) { + if (specPhase != i) { + phaseList.add(phaseArray[phaseIndex[i]]); } + } - logger.error(sqlString); - - database.execute("INSERT INTO systemreport VALUES (" + sqlString + ")"); - - // molarmass - i++; - - sqlString = "'" + Integer.toString(i + 1) + "', 'MolarMass', " + "'kg/mol ', '" - + Double.toString(getMolarMass()) + "'"; - - j = 0; - for (; j < numberOfPhases; j++) { - sqlString += ", '" + Double.toString(getPhase(j).getMolarMass()) + "'"; - } - while (j < 3) { - j++; - sqlString += ", '0'"; + // phaseArray = new PhaseInterface[numberOfPhases - 1]; + for (int i = 0; i < numberOfPhases - 1; i++) { + // phaseArray[i] = (PhaseInterface) phaseList.get(i); + if (i >= specPhase) { + phaseIndex[i] = phaseIndex[i + 1]; + phaseType[i] = phaseType[i + 1]; } + } + numberOfPhases--; + } - // System.out.println(sqlString); - database.execute("INSERT INTO systemreport VALUES (" + sqlString + ")"); + /** {@inheritDoc} */ + @Override + public void removePhaseKeepTotalComposition(int specPhase) { + ArrayList phaseList = new ArrayList(0); + for (int i = 0; i < numberOfPhases; i++) { + if (specPhase != i) { + phaseList.add(phaseArray[phaseIndex[i]]); + } + } - // dataSet.next(); - // dataSet.updateString("SPECIFICATION", "dette"); - // double test = dataSet.getDouble("Phase1"); - // System.out.println(test); - // dataSet.next(); - // dataSet.updateString(1,"tesst"); - } catch (Exception ex) { - logger.error("failed ", ex); + // phaseArray = new PhaseInterface[numberOfPhases - 1]; + for (int i = 0; i < numberOfPhases - 1; i++) { + // phaseArray[i] = (PhaseInterface) phaseList.get(i); + if (i >= specPhase) { + phaseIndex[i] = phaseIndex[i + 1]; + phaseType[i] = phaseType[i + 1]; + } } + numberOfPhases--; } /** {@inheritDoc} */ @Override - public neqsim.standards.StandardInterface getStandard() { - return standard; + public void renameComponent(String oldName, String newName) { + componentNames.set(getPhase(0).getComponent(oldName).getComponentNumber(), newName); + for (int i = 0; i < maxNumberOfPhases; i++) { + getPhase(i).getComponent(oldName).setComponentName(newName); + } } /** {@inheritDoc} */ @Override - public neqsim.standards.StandardInterface getStandard(String standardName) { - this.setStandard(standardName); - return standard; + public void replacePhase(int repPhase, PhaseInterface newPhase) { + for (int i = 0; i < 2; i++) { + phaseArray[i] = newPhase.clone(); + } + setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); } /** {@inheritDoc} */ @Override - public void setStandard(String standardName) { - if (standardName.equals("ISO1992")) { - this.standard = new neqsim.standards.gasQuality.Standard_ISO6976(this); - } else if (standardName.equals("Draft_ISO18453")) { - this.standard = new neqsim.standards.gasQuality.Draft_ISO18453(this); - } else { - this.standard = new neqsim.standards.gasQuality.Standard_ISO6976(this); + public void reset() { + for (int i = 0; i < numberOfComponents; i++) { + // TODO: numeric issue, nearly zero + addComponent(getPhase(0).getComponent(i).getComponentName(), + -getPhase(0).getComponent(i).getNumberOfmoles()); } } /** {@inheritDoc} */ @Override - public boolean hasPlusFraction() { - for (int i = 0; i < numberOfComponents; i++) { - if (getPhase(0).getComponent(i).isIsPlusFraction()) { - return true; + public void reset_x_y() { + for (int j = 0; j < numberOfPhases; j++) { + for (int i = 0; i < numberOfComponents; i++) { + getPhase(j).getComponents()[i].setx(phaseArray[phaseIndex[0]].getComponents()[i].getz()); } } - return false; } - /** - *

- * hasTBPFraction. - *

- * - * @return a boolean - */ - public boolean hasTBPFraction() { - for (int i = 0; i < numberOfComponents; i++) { - if (getPhase(0).getComponent(i).isIsTBPfraction()) { - return true; + /** {@inheritDoc} */ + @Override + public void resetCharacterisation() { + int numberOfLumpedComps = characterization.getLumpingModel().getNumberOfLumpedComponents(); + characterization = new Characterise(this); + characterization.getLumpingModel().setNumberOfLumpedComponents(numberOfLumpedComps); + } + + /** {@inheritDoc} */ + @Override + public void resetDatabase() { + try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) { + if (NeqSimDataBase.createTemporaryTables()) { + database.execute("delete FROM comptemp"); + database.execute("delete FROM intertemp"); } + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); } - return false; } + // public String[] getResultArray1(){ + // ArrayList list = new ArrayList(); + // for(int i=0;i 1) { + b = 1.0 - neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; + } + beta[0] = b; + beta[1] = 1.0 - b; } /** {@inheritDoc} */ @Override - public void autoSelectMixingRule() { - logger.info("setting mixing rule"); - if (modelName.equals("CPAs-SRK-EOS") || modelName.equals("CPA-SRK-EOS") - || modelName.equals("Electrolyte-CPA-EOS-statoil") - || modelName.equals("CPAs-SRK-EOS-statoil") || modelName.equals("Electrolyte-CPA-EOS")) { - this.setMixingRule(10); - // System.out.println("mix rule 10"); - } else if ((modelName.equals("ScRK-EOS-HV") || modelName.equals("SRK-EOS") - || modelName.equals("ScRK-EOS")) && this.getPhase(0).hasComponent("water")) { - this.setMixingRule(4); - } else if (modelName.equals("PR-EOS")) { - this.setMixingRule(2); - } else if (modelName.equals("Electrolyte-ScRK-EOS")) { - this.setMixingRule(4); - } else if (modelName.equals("UMR-PRU-EoS") || modelName.equals("UMR-PRU-MC-EoS")) { - this.setMixingRule("HV", "UNIFAC_UMRPRU"); - } else if (modelName.equals("GERG-water-EOS")) { - this.setMixingRule(8); - } else if (modelName.equals("GERG-2008-EOS")) { - this.setMixingRule(2); - } else if (modelName.equals("PC-SAFT")) { - this.setMixingRule(8); - } else { - this.setMixingRule(2); + public final void setBeta(int phase, double b) { + if (b < 0) { + b = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; + } + if (b > 1) { + b = 1.0 - neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; } + beta[phaseIndex[phase]] = b; } /** {@inheritDoc} */ @Override - public int getMixingRule() { - return mixingRule; + public void setBmixType(int bmixType) { + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + ((PhaseEosInterface) getPhase(i)).getMixingRule().setBmixType(bmixType); + } } /** {@inheritDoc} */ @Override - public void orderByDensity() { - boolean change = false; - // int count = 0; - - for (int i = 0; i < getNumberOfPhases(); i++) { - if (getPhase(i).getPhysicalProperties() == null) { - getPhase(i).initPhysicalProperties("density"); - } - getPhase(i).getPhysicalProperties().setPhase(getPhase(i)); + public void setComponentNames(String[] componentNames) { + for (int i = 0; i < componentNames.length; i++) { + this.componentNames.set(i, componentNames[i]); } - - do { - change = false; - // count++; - for (int i = 1; i < getNumberOfPhases(); i++) { - if (i == 4) { - break; - } - - try { - if (change || getPhase(i).getPhysicalProperties() == null) { - getPhase(i).initPhysicalProperties("density"); - } - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - } - if (getPhase(i).getPhysicalProperties().calcDensity() < getPhase(i - 1) - .getPhysicalProperties().calcDensity()) { - int tempIndex1 = getPhaseIndex(i - 1); - int tempIndex2 = getPhaseIndex(i); - setPhaseIndex(i, tempIndex1); - setPhaseIndex(i - 1, tempIndex2); - change = true; - } - } - } while (change); } /** {@inheritDoc} */ @Override - public void addLiquidToGas(double fraction) { + public void setComponentNameTag(String nameTag) { + componentNameTag = nameTag; for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { - double change = getPhase(1).getComponent(i).getNumberOfMolesInPhase() * fraction; - addComponent(i, change, 0); - addComponent(i, -change, 1); + renameComponent(componentNames.get(i), componentNames.get(i) + nameTag); } } /** {@inheritDoc} */ @Override - public void addPhaseFractionToPhase(double fraction, String specification, String fromPhaseName, - String toPhaseName) { - if (!(hasPhaseType(fromPhaseName) && hasPhaseType(toPhaseName) || fraction < 1e-30)) { - return; - } - int phaseNumbFrom = getPhaseNumberOfPhase(fromPhaseName); - int phaseNumbTo = getPhaseNumberOfPhase(toPhaseName); + public void setComponentNameTagOnNormalComponents(String nameTag) { + componentNameTag = nameTag; for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { - double change = getPhase(phaseNumbFrom).getComponent(i).getNumberOfMolesInPhase() * fraction; - addComponent(i, change, phaseNumbTo); - addComponent(i, -change, phaseNumbFrom); + if (!getPhase(0).getComponent(i).isIsTBPfraction() + && !getPhase(0).getComponent(i).isIsPlusFraction()) { + renameComponent(componentNames.get(i), componentNames.get(i) + nameTag); + } } - init_x_y(); } /** {@inheritDoc} */ @Override - public void addPhaseFractionToPhase(double fraction, String specification, String specifiedStream, - String fromPhaseName, String toPhaseName) { - double moleFraction = fraction; - if (!hasPhaseType(fromPhaseName) || !hasPhaseType(toPhaseName) || fraction < 1e-30) { - return; + public void setEmptyFluid() { + for (PhaseInterface tmpPhase : phaseArray) { + if (tmpPhase != null) { + tmpPhase.setEmptyFluid(); + } } - int phaseNumbFrom = getPhaseNumberOfPhase(fromPhaseName); - int phaseNumbTo = getPhaseNumberOfPhase(toPhaseName); + totalNumberOfMoles = 0.0; + } - if (specifiedStream.equals("feed")) { - moleFraction = fraction; - } else if (specifiedStream.equals("product")) { - // double specFractionFrom = getPhaseFraction(specification, fromPhaseName); - double specFractionTo = getPhaseFraction(specification, toPhaseName); + /** {@inheritDoc} */ + @Override + public void setFluidInfo(String info) { + this.fluidInfo = info; + } - double moleFractionFrom = getMoleFraction(phaseNumbFrom); - double moleFractionTo = getMoleFraction(phaseNumbTo); + /** {@inheritDoc} */ + @Override + public void setFluidName(String fluidName) { + this.fluidName = fluidName; + } - if (specification.equals("volume") || specification.equals("mass")) { - double test = fraction * specFractionTo / (fraction * specFractionTo + specFractionTo); - moleFraction = test * moleFractionTo / specFractionTo; - } else if (specification.equals("mole")) { - double test = fraction * moleFractionTo / (fraction * moleFractionTo + moleFractionTo); - moleFraction = test; - } + /** {@inheritDoc} */ + @Override + public void setForcePhaseTypes(boolean forcePhaseTypes) { + this.forcePhaseTypes = forcePhaseTypes; + } - moleFraction = moleFraction * moleFractionTo / moleFractionFrom; - if (moleFraction > moleFractionFrom) { - logger.debug("error in addPhaseFractionToPhase()...to low fraction in from phase"); - moleFraction = moleFractionFrom; + /** {@inheritDoc} */ + @Override + public boolean setHeavyTBPfractionAsPlusFraction() { + int compNumber = 0; + double molarMass = 0; + boolean foundTBP = false; + + for (int i = 0; i < numberOfComponents; i++) { + if (getPhase(0).getComponent(i).isIsTBPfraction() + || getPhase(0).getComponent(i).isIsPlusFraction()) { + if (getPhase(0).getComponent(i).getMolarMass() > molarMass) { + molarMass = getPhase(0).getComponent(i).getMolarMass(); + compNumber = i; + foundTBP = true; + } } } - - for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { - double change = 0.0; - change = getPhase(phaseNumbFrom).getComponent(i).getNumberOfMolesInPhase() * moleFraction; - addComponent(i, change, phaseNumbTo); - addComponent(i, -change, phaseNumbFrom); + if (foundTBP) { + for (int i = 0; i < maxNumberOfPhases; i++) { + getPhase(0).getComponent(compNumber).setIsPlusFraction(true); + } } - init_x_y(); + return foundTBP; } /** {@inheritDoc} */ @Override - public void addGasToLiquid(double fraction) { - for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { - double change = getPhase(0).getComponent(i).getNumberOfMolesInPhase() * fraction; - addComponent(i, -change, 0); - addComponent(i, change, 1); + public void setHydrateCheck(boolean hydrateCheck) { + init(0); + if (hydrateCheck) { + addHydratePhase(); } + this.hydrateCheck = hydrateCheck; + init(0); } /** {@inheritDoc} */ @Override - public double getTotalNumberOfMoles() { - return this.totalNumberOfMoles; + public void setImplementedCompositionDeriativesofFugacity( + boolean implementedCompositionDeriativesofFugacity) { + this.implementedCompositionDeriativesofFugacity = implementedCompositionDeriativesofFugacity; } /** {@inheritDoc} */ @Override - public void setTotalNumberOfMoles(double totalNumberOfMoles) { - if (totalNumberOfMoles < 0) { - /* - * throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, - * "setTotalNumberOfMoles", "totalNumberOfMoles", "can not be less than 0.")); - */ - totalNumberOfMoles = 0; - } - this.totalNumberOfMoles = totalNumberOfMoles; + public void setImplementedPressureDeriativesofFugacity( + boolean implementedPressureDeriativesofFugacity) { + this.implementedPressureDeriativesofFugacity = implementedPressureDeriativesofFugacity; } /** {@inheritDoc} */ @Override - public double calcHenrysConstant(String component) { - if (numberOfPhases != 2) { - logger.error("Can't calculate Henrys constant - two phases must be present."); - return 0; - } else { - int compNumb = getPhase(getPhaseIndex(0)).getComponent(component).getComponentNumber(); - double hc = getPhase(getPhaseIndex(0)).getFugacity(compNumb) - / getPhase(getPhaseIndex(1)).getComponent(component).getx(); - return hc; - } + public void setImplementedTemperatureDeriativesofFugacity( + boolean implementedTemperatureDeriativesofFugacity) { + this.implementedTemperatureDeriativesofFugacity = implementedTemperatureDeriativesofFugacity; + } + + /** {@inheritDoc} */ + @Override + public void setInitType(int initType) { + this.initType = initType; } /** *

- * useTVasIndependentVariables. + * setLastTBPasPlus. *

* * @return a boolean */ - public boolean useTVasIndependentVariables() { - return useTVasIndependentVariables; - } - - /** {@inheritDoc} */ - @Override - public void setUseTVasIndependentVariables(boolean useTVasIndependentVariables) { - for (int i = 0; i < numberOfPhases; i++) { - getPhase(i).setTotalVolume(getPhase(i).getVolume()); - getPhase(i).setConstantPhaseVolume(useTVasIndependentVariables); - getPhase(i).calcMolarVolume(!useTVasIndependentVariables); - } - this.useTVasIndependentVariables = useTVasIndependentVariables; - } - - /** {@inheritDoc} */ - @Override - public void setBmixType(int bmixType) { - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - ((PhaseEosInterface) getPhase(i)).getMixingRule().setBmixType(bmixType); + public boolean setLastTBPasPlus() { + neqsim.thermo.characterization.PlusCharacterize temp = + new neqsim.thermo.characterization.PlusCharacterize(this); + if (temp.hasPlusFraction()) { + return false; + } else { + temp.setHeavyTBPtoPlus(); } + return true; } /** {@inheritDoc} */ @Override - public boolean isImplementedCompositionDeriativesofFugacity() { - return implementedCompositionDeriativesofFugacity; + public void setMaxNumberOfPhases(int maxNumberOfPhases) { + this.maxNumberOfPhases = maxNumberOfPhases; } /** {@inheritDoc} */ @Override - public void isImplementedCompositionDeriativesofFugacity(boolean isImpl) { - this.implementedCompositionDeriativesofFugacity = isImpl; + public final void setMixingRule(int type) { + mixingRule = type; + if (numberOfPhases < 4) { + resetPhysicalProperties(); // initPhysicalProperties(); + } + for (int i = 0; i < maxNumberOfPhases; i++) { + if (isPhase(i)) { + getPhase(i).setMixingRule(type); + getPhase(i).initPhysicalProperties(); + // getPhase(i).getPhysicalProperties().getMixingRule().initMixingRules(getPhase(i)); + } + } } /** {@inheritDoc} */ @Override - public void setImplementedCompositionDeriativesofFugacity( - boolean implementedCompositionDeriativesofFugacity) { - this.implementedCompositionDeriativesofFugacity = implementedCompositionDeriativesofFugacity; + public void setMixingRule(String typename) { + int var = 0; + if (typename.equals("no")) { + var = 1; + } else if (typename.equals("classic")) { + var = 2; + } else if (typename.equals("HV")) { + var = 4; + } else if (typename.equals("WS")) { + var = 5; + } else if (typename.equals("CPA-Mix")) { + var = 7; + } else if (typename.equals("classic-T")) { + var = 8; + } else if (typename.equals("classic-T-cpa")) { + var = 9; + } else if (typename.equals("classic-Tx-cpa")) { + var = 10; + } else { + var = 1; + } + this.setMixingRule(var); } /** {@inheritDoc} */ @Override - public void setImplementedPressureDeriativesofFugacity( - boolean implementedPressureDeriativesofFugacity) { - this.implementedPressureDeriativesofFugacity = implementedPressureDeriativesofFugacity; + public void setMixingRule(String typename, String GEmodel) { + setMixingRuleGEmodel(GEmodel); + setMixingRule(typename); } - /** {@inheritDoc} */ - @Override - public boolean isImplementedPressureDeriativesofFugacity() { - return implementedPressureDeriativesofFugacity; + /** + *

+ * setMixingRuleGEmodel. + *

+ * + * @param name a {@link java.lang.String} object + */ + public void setMixingRuleGEmodel(String name) { + for (PhaseInterface tmpPhase : phaseArray) { + if (tmpPhase != null) { + tmpPhase.setMixingRuleGEModel(name); + } + } } /** {@inheritDoc} */ @Override - public boolean isImplementedTemperatureDeriativesofFugacity() { - return implementedTemperatureDeriativesofFugacity; - } + public SystemInterface setModel(String model) { + SystemInterface tempModel = null; + try { + if (model.equals("SRK-EOS")) { + tempModel = new SystemSrkEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("GERG2004-EOS")) { + tempModel = new SystemGERG2004Eos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("PrEos") || model.equals("PR-EOS")) { + tempModel = new SystemPrEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("ScRK-EOS") || model.equals("ScRK-EOS-HV")) { + tempModel = new SystemSrkSchwartzentruberEos(getPhase(0).getTemperature(), + getPhase(0).getPressure()); + } else if (model.equals("Electrolyte-ScRK-EOS")) { + tempModel = + new SystemFurstElectrolyteEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("GERG-water-EOS")) { + tempModel = new SystemGERGwaterEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("CPAs-SRK-EOS")) { + tempModel = new SystemSrkCPAs(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("CPAs-SRK-EOS-statoil")) { + tempModel = + new SystemSrkCPAstatoil(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("Electrolyte-CPA-EOS-statoil") + || model.equals("Electrolyte-CPA-EOS")) { + tempModel = new SystemElectrolyteCPAstatoil(getPhase(0).getTemperature(), + getPhase(0).getPressure()); + } else if (model.equals("UMR-PRU-EoS")) { + tempModel = new SystemUMRPRUMCEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("PC-SAFT")) { + tempModel = new SystemPCSAFT(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("GERG-2008-EoS")) { + tempModel = new SystemGERG2004Eos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("SRK-TwuCoon-Statoil-EOS") || model.equals("SRK-TwuCoon-EOS")) { + tempModel = + new SystemSrkTwuCoonStatoilEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("SRK-TwuCoon-Param-EOS")) { + tempModel = + new SystemSrkTwuCoonParamEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else if (model.equals("Duan-Sun")) { + tempModel = new SystemDuanSun(getPhase(0).getTemperature(), getPhase(0).getPressure()); + } else { + logger.error("model : " + model + " not defined....."); + } + // tempModel.getCharacterization().setTBPModel("RiaziDaubert"); + tempModel.useVolumeCorrection(true); - /** {@inheritDoc} */ - @Override - public void setImplementedTemperatureDeriativesofFugacity( - boolean implementedTemperatureDeriativesofFugacity) { - this.implementedTemperatureDeriativesofFugacity = implementedTemperatureDeriativesofFugacity; - } + logger.info("created class " + tempModel); + for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { + logger.info("adding " + getPhase(0).getComponent(i).getName() + " moles " + + getPhase(0).getComponent(i).getNumberOfmoles() + " isPlus " + + getPhase(0).getComponent(i).isIsPlusFraction() + " isTBP " + + getPhase(0).getComponent(i).isIsTBPfraction()); + if (getPhase(0).getComponent(i).isIsTBPfraction()) { + tempModel.addTBPfraction(getPhase(0).getComponent(i).getName(), + getPhase(0).getComponent(i).getNumberOfmoles(), + getPhase(0).getComponent(i).getMolarMass(), + getPhase(0).getComponent(i).getNormalLiquidDensity()); + } else if (getPhase(0).getComponent(i).isIsPlusFraction()) { + tempModel.addPlusFraction(getPhase(0).getComponent(i).getName(), + getPhase(0).getComponent(i).getNumberOfmoles(), + getPhase(0).getComponent(i).getMolarMass(), + getPhase(0).getComponent(i).getNormalLiquidDensity()); + } else { + tempModel.addComponent(getPhase(0).getComponent(i).getName(), + getPhase(0).getComponent(i).getNumberOfmoles()); + } + } - /** {@inheritDoc} */ - @Override - public void deleteFluidPhase(int phase) { - for (int i = phase; i < numberOfPhases; i++) { - phaseIndex[i] = phaseIndex[i + 1]; + // if (tempModel.getCharacterization().characterize()) { + // tempModel.addPlusFraction(6, 100); + // } + if (NeqSimDataBase.createTemporaryTables()) { + logger.info("done ... create database ......"); + tempModel.createDatabase(true); + } + logger.info("done ... set mixing rule ......"); + tempModel.autoSelectMixingRule(); + if (model.equals("Electrolyte-ScRK-EOS")) { // || + // model.equals("Electrolyte-CPA-EOS-statoil" + logger.info("chemical reaction init......"); + tempModel.setMultiPhaseCheck(false); + tempModel.chemicalReactionInit(); + } else { + tempModel.setMultiPhaseCheck(true); + } + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); } - numberOfPhases--; - } - - /** {@inheritDoc} */ - @Override - public int getMaxNumberOfPhases() { - return maxNumberOfPhases; + return tempModel; } - /** {@inheritDoc} */ - @Override - public void setMaxNumberOfPhases(int maxNumberOfPhases) { - this.maxNumberOfPhases = maxNumberOfPhases; + /** + * Setter for property modelName. + * + * @param modelName New value of property modelName. + */ + public void setModelName(String modelName) { + this.modelName = modelName; } /** {@inheritDoc} */ @@ -4677,14 +4755,14 @@ public void setMolarComposition(double[] molefractions) { /** {@inheritDoc} */ @Override - public void setMolarCompositionPlus(double[] molefractions) { - setMolarFractions(molefractions, "Plus"); + public void setMolarCompositionOfPlusFluid(double[] molefractions) { + setMolarFractions(molefractions, "PlusFluid"); } /** {@inheritDoc} */ @Override - public void setMolarCompositionOfPlusFluid(double[] molefractions) { - setMolarFractions(molefractions, "PlusFluid"); + public void setMolarCompositionPlus(double[] molefractions) { + setMolarFractions(molefractions, "Plus"); } /** {@inheritDoc} */ @@ -4699,33 +4777,85 @@ public void setMolarFlowRates(double[] moles) { } } + /** + * Wrapper function for addComponent to set fluid type and specify mole fractions. + * + * @param molefractions Component mole fraction of each component. + * @param type Type of fluid. Supports "PlusFluid", "Plus" and default. + */ + private void setMolarFractions(double[] molefractions, String type) { + double totalFlow = getTotalNumberOfMoles(); + if (totalFlow < 1e-100) { + String msg = "must be larger than 0 (1e-100) when setting molar composition"; + throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, + "setMolarComposition", "totalFlow", msg)); + } + double sum = 0; + for (double value : molefractions) { + sum += value; + } + setEmptyFluid(); + + switch (type) { + case "PlusFluid": + // TODO: really skip last component of molefraction? + for (int compNumb = 0; compNumb < molefractions.length - 1; compNumb++) { + addComponent(compNumb, totalFlow * molefractions[compNumb] / sum); + } + for (int j = 0; j < getCharacterization().getLumpingModel().getNumberOfLumpedComponents() + - 1; j++) { + // addComponent(compNumb, totalFlow * molefractions[molefractions.length - 1] + // * getCharacterization().getLumpingModel().getFractionOfHeavyEnd(j) / sum); + } + break; + case "Plus": + // TODO: compNumb can be negative + for (int compNumb = 0; compNumb < this.numberOfComponents + - getCharacterization().getLumpingModel().getNumberOfLumpedComponents(); compNumb++) { + addComponent(compNumb, totalFlow * molefractions[compNumb] / sum); + } + int ii = 0; + for (int compNumb = this.numberOfComponents - getCharacterization().getLumpingModel() + .getNumberOfLumpedComponents(); compNumb < this.numberOfComponents; compNumb++) { + addComponent(compNumb, + totalFlow * getCharacterization().getLumpingModel().getFractionOfHeavyEnd(ii++) + * molefractions[this.numberOfComponents + - getCharacterization().getLumpingModel().getNumberOfLumpedComponents()] + / sum); + } + break; + default: + // NB! It will allow setting composition for only the first items. + // for (int compNumb = 0; compNumb <= molefractions.length - 1; compNumb++) { + // NB! Can fail because len(molefractions) < this.numberOfComponents + for (int compNumb = 0; compNumb <= this.numberOfComponents - 1; compNumb++) { + addComponent(compNumb, totalFlow * molefractions[compNumb] / sum); + } + break; + } + + for (int i = 0; i < getNumberOfPhases(); i++) { + init(0, i); + } + } + /** {@inheritDoc} */ @Override - public double[] getMolarRate() { - double[] comp = new double[getPhase(0).getNumberOfComponents()]; - - for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { - comp[compNumb] = getPhase(0).getComponent(compNumb).getNumberOfmoles(); - } - return comp; - } - - /** {@inheritDoc} */ - @Override - public double[] getMolarComposition() { - PhaseInterface phase = this.getPhase(0); - double[] comp = new double[phase.getNumberOfComponents()]; - - for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { - comp[compNumb] = phase.getComponent(compNumb).getz(); + public void setMultiPhaseCheck(boolean multiPhaseCheck) { + if (getMaxNumberOfPhases() < 3) { + if (multiPhaseCheck) { + setMaxNumberOfPhases(3); + if (phaseArray[1] != null) { + phaseArray[2] = phaseArray[1].clone(); + phaseArray[2].resetMixingRule(phaseArray[0].getMixingRuleNumber()); + phaseArray[2].resetPhysicalProperties(); + phaseArray[2].initPhysicalProperties(); + } + } else { + setMaxNumberOfPhases(2); + } } - return comp; - } - - /** {@inheritDoc} */ - @Override - public boolean isMultiphaseWaxCheck() { - return multiphaseWaxCheck; + this.multiPhaseCheck = multiPhaseCheck; } /** {@inheritDoc} */ @@ -4736,415 +4866,285 @@ public void setMultiphaseWaxCheck(boolean multiphaseWaxCheck) { /** {@inheritDoc} */ @Override - public String[] getCompIDs() { - String[] ids = new String[numberOfComponents]; - - for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { - ids[compNumb] = Integer.toString(getPhase(0).getComponent(compNumb).getIndex()); - } - return ids; - } - - /** {@inheritDoc} */ - @Override - public String[] getCompFormulaes() { - String[] formula = new String[numberOfComponents]; - - for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { - formula[compNumb] = getPhase(0).getComponent(compNumb).getFormulae(); - } - return formula; - } - - /** {@inheritDoc} */ - @Override - public String[] getCompNames() { - String[] names = new String[numberOfComponents]; - - for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { - names[compNumb] = getPhase(0).getComponent(compNumb).getComponentName(); + public void setNumberOfPhases(int number) { + this.numberOfPhases = number; + if (numberOfPhases > getMaxNumberOfPhases()) { + setMaxNumberOfPhases(number); } - return names; } /** {@inheritDoc} */ @Override - public double[] getNormalBoilingPointTemperatures() { - double[] bt = new double[numberOfComponents]; - - for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { - bt[compNumb] = getPhase(0).getComponent(compNumb).getNormalBoilingPoint() + 273.15; - } - return bt; + public void setNumericDerivatives(boolean numericDerivatives) { + this.numericDerivatives = numericDerivatives; } /** {@inheritDoc} */ @Override - public String[] getCapeOpenProperties11() { - return CapeOpenProperties11; + public final void setPC(double PC) { + criticalPressure = PC; } /** {@inheritDoc} */ @Override - public String[] getCapeOpenProperties10() { - return CapeOpenProperties10; + public void setPhase(PhaseInterface phase, int index) { + double temp = phaseArray[index].getTemperature(); + double pres = phaseArray[index].getPressure(); + this.phaseArray[index] = phase; + this.phaseArray[index].setTemperature(temp); + this.phaseArray[index].setPressure(pres); } /** {@inheritDoc} */ @Override - public double[] getMolecularWeights() { - double[] mm = new double[numberOfComponents]; - - for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { - mm[compNumb] = getPhase(0).getComponent(compNumb).getMolarMass() * 1e3; - } - return mm; + public final void setPhaseIndex(int index, int phaseIndex) { + this.phaseIndex[index] = phaseIndex; } /** {@inheritDoc} */ @Override - public String[] getCASNumbers() { - String[] names = new String[numberOfComponents]; - - for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { - names[compNumb] = getPhase(0).getComponent(compNumb).getCASnumber(); + public void setPhaseType(int phaseToChange, PhaseType pt) { + // System.out.println("new phase type: cha " + pt); + if (allowPhaseShift) { + phaseType[phaseIndex[phaseToChange]] = pt; } - return names; } /** {@inheritDoc} */ @Override - public int getNumberOfOilFractionComponents() { - int number = 0; - for (int i = 0; i < getPhase(0).getNumberOfComponents(); i++) { - if (getPhase(0).getComponent(i).isIsTBPfraction() - || getPhase(0).getComponent(i).isIsPlusFraction()) { - number++; - } + public void setPhysicalPropertyModel(int type) { + for (int i = 0; i < numberOfPhases; i++) { + getPhase(i).setPhysicalProperties(type); } - return number; } /** {@inheritDoc} */ @Override - public int[] getOilFractionIDs() { - int numb = getNumberOfOilFractionComponents(); - int[] IDs = new int[numb]; - // int number = 0; - for (int i = 0; i < numb; i++) { - if (getPhase(0).getComponent(i).isIsTBPfraction() - || getPhase(0).getComponent(i).isIsPlusFraction()) { - IDs[i] = getPhase(0).getComponent(i).getIndex(); - // number++; - } + public final void setPressure(double newPressure) { + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + phaseArray[i].setPressure(newPressure); } - return IDs; } /** {@inheritDoc} */ @Override - public boolean setHeavyTBPfractionAsPlusFraction() { - int compNumber = 0; - double molarMass = 0; - boolean foundTBP = false; - - for (int i = 0; i < numberOfComponents; i++) { - if (getPhase(0).getComponent(i).isIsTBPfraction() - || getPhase(0).getComponent(i).isIsPlusFraction()) { - if (getPhase(0).getComponent(i).getMolarMass() > molarMass) { - molarMass = getPhase(0).getComponent(i).getMolarMass(); - compNumber = i; - foundTBP = true; - } - } - } - if (foundTBP) { - for (int i = 0; i < maxNumberOfPhases; i++) { - getPhase(0).getComponent(compNumber).setIsPlusFraction(true); - } - } - return foundTBP; + public final void setPressure(double newPressure, String unit) { + neqsim.util.unit.PressureUnit presConversion = + new neqsim.util.unit.PressureUnit(newPressure, unit); + setPressure(presConversion.getValue("bara")); } /** {@inheritDoc} */ @Override - public double[] getOilFractionNormalBoilingPoints() { - int numb = getNumberOfOilFractionComponents(); - int[] indexes = getOilFractionIDs(); - double[] temp = new double[numb]; - for (int i = 0; i < numb; i++) { - temp[i] = getPhase(0).getComponentWithIndex(indexes[i]).getNormalBoilingPoint(); - } - return temp; - } + public void setSolidPhaseCheck(boolean solidPhaseCheck) { + this.solidPhaseCheck = solidPhaseCheck; - /** {@inheritDoc} */ - @Override - public double[] getOilFractionLiquidDensityAt25C() { - int numb = getNumberOfOilFractionComponents(); - int[] indexes = getOilFractionIDs(); - double[] temp = new double[numb]; - for (int i = 0; i < numb; i++) { - temp[i] = getPhase(0).getComponentWithIndex(indexes[i]).getNormalLiquidDensity(); + final int oldphase = numberOfPhases; + if (solidPhaseCheck && !this.hasSolidPhase()) { + addSolidPhase(); } - return temp; - } + // init(0); - /** {@inheritDoc} */ - @Override - public double[] getOilFractionMolecularMass() { - int numb = getNumberOfOilFractionComponents(); - int[] indexes = getOilFractionIDs(); - double[] temp = new double[numb]; - for (int i = 0; i < numb; i++) { - temp[i] = getPhase(0).getComponentWithIndex(indexes[i]).getMolarMass(); + for (int phase = 0; phase < numberOfPhases; phase++) { + for (int k = 0; k < getPhases()[0].getNumberOfComponents(); k++) { + getPhase(phase).getComponent(k).setSolidCheck(solidPhaseCheck); + getPhase(3).getComponent(k).setSolidCheck(solidPhaseCheck); + } } - return temp; + setNumberOfPhases(oldphase); } /** {@inheritDoc} */ @Override - public PhaseInterface getLowestGibbsEnergyPhase() { - if (getPhase(0).getGibbsEnergy() < getPhase(1).getGibbsEnergy()) { - return getPhase(0); - } else { - return getPhase(1); + public void setSolidPhaseCheck(String solidComponent) { + init(0); + final int oldphase = numberOfPhases; + if (!solidPhaseCheck) { + addSolidPhase(); } - } - - /** {@inheritDoc} */ - @Override - public double getWtFraction(int phaseNumber) { - return getPhase(phaseNumber).getWtFraction(this); - } - - /** {@inheritDoc} */ - @Override - public double getVolumeFraction(int phaseNumber) { - return getPhase(phaseNumber).getVolume() / getVolume(); - } + this.solidPhaseCheck = true; + init(0); - /** {@inheritDoc} */ - @Override - public final double getPhaseFraction(String phaseTypeName, String unit) { - int phaseNumber = getPhaseNumberOfPhase(phaseTypeName); - switch (unit) { - case "mole": - return getBeta(phaseNumber); - case "volume": - return getVolumeFraction(phaseNumber); - case "mass": - initPhysicalProperties("density"); - return getVolumeFraction(phaseNumber) * getPhase(phaseNumber).getDensity("kg/m3") - / getDensity("kg/m3"); - default: - return getBeta(phaseNumber); + for (int phase = 0; phase < getMaxNumberOfPhases(); phase++) { + try { + getPhase(phase).getComponent(solidComponent).setSolidCheck(true); + getPhase(3).getComponent(solidComponent).setSolidCheck(true); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } } + setNumberOfPhases(oldphase); } /** {@inheritDoc} */ @Override - public double getCorrectedVolumeFraction(int phaseNumber) { - return getPhase(phaseNumber).getCorrectedVolume() / getCorrectedVolume(); + public void setStandard(String standardName) { + if (standardName.equals("ISO1992")) { + this.standard = new neqsim.standards.gasQuality.Standard_ISO6976(this); + } else if (standardName.equals("Draft_ISO18453")) { + this.standard = new neqsim.standards.gasQuality.Draft_ISO18453(this); + } else { + this.standard = new neqsim.standards.gasQuality.Standard_ISO6976(this); + } } /** {@inheritDoc} */ @Override - public double getMoleFraction(int phaseNumber) { - return getPhase(phaseNumber).getBeta(); + public final void setTC(double TC) { + criticalTemperature = TC; } /** {@inheritDoc} */ @Override - public void addCapeOpenProperty(String propertyName) { - String[] tempString = new String[CapeOpenProperties11.length + 1]; - System.arraycopy(CapeOpenProperties11, 0, tempString, 0, CapeOpenProperties11.length); - tempString[CapeOpenProperties11.length] = propertyName; - CapeOpenProperties11 = tempString; - - tempString = new String[CapeOpenProperties10.length + 1]; - System.arraycopy(CapeOpenProperties10, 0, tempString, 0, CapeOpenProperties10.length); - tempString[CapeOpenProperties10.length] = propertyName; - CapeOpenProperties10 = tempString; + public void setTemperature(double newTemperature) { + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + getPhases()[i].setTemperature(newTemperature); + } } /** {@inheritDoc} */ @Override - public neqsim.thermo.characterization.WaxCharacterise getWaxCharacterisation() { - return waxCharacterisation; + public final void setTemperature(double newTemperature, int phase) { + getPhase(phaseIndex[phase]).setTemperature(newTemperature); } /** {@inheritDoc} */ @Override - public WaxModelInterface getWaxModel() { - if (waxCharacterisation == null) { - waxCharacterisation = new WaxCharacterise(this); + public void setTemperature(double newTemperature, String unit) { + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + if (unit.equals("K")) { + getPhases()[i].setTemperature(newTemperature); + } else if (unit.equals("C")) { + getPhases()[i].setTemperature(newTemperature + 273.15); + } else { + throw new RuntimeException("unit not supported " + unit); + } } - return waxCharacterisation.getModel(); } /** {@inheritDoc} */ @Override - public double getLiquidVolume() { - double totFlow = 0; + public void setTotalFlowRate(double flowRate, String flowunit) { + init(0); + try { + init(1); + } catch (Exception e) { + logger.error(e.getMessage()); + } + double density = 0.0; + if (flowunit.equals("Am3/hr") || flowunit.equals("Am3/min") || flowunit.equals("Am3/sec")) { + initPhysicalProperties("density"); + } - for (int kj = 0; kj < numberOfPhases; kj++) { - if (getPhase(kj).getType() != PhaseType.GAS) { - totFlow += getPhase(kj).getVolume(); + density = getPhase(0).getDensity("kg/m3"); + if (flowunit.equals("idSm3/hr")) { + density = getIdealLiquidDensity("kg/m3"); + } + neqsim.util.unit.Unit unit = + new neqsim.util.unit.RateUnit(flowRate, flowunit, getMolarMass(), density, 0); + double SIval = unit.getSIvalue(); + double totalNumberOfMolesLocal = totalNumberOfMoles; + for (int i = 0; i < numberOfComponents; i++) { + if (flowRate < 1e-100) { + setEmptyFluid(); + } else if (totalNumberOfMolesLocal > 1e-100) { + // (SIval / totalNumberOfMolesLocal - 1) * ... + double change = + SIval / totalNumberOfMolesLocal * getPhase(0).getComponent(i).getNumberOfmoles() + - getPhase(0).getComponent(i).getNumberOfmoles(); + if (Math.abs(change) > 1e-12) { + addComponent(i, change); + } + } else { + addComponent(i, SIval); } } - return totFlow; } /** {@inheritDoc} */ @Override - public boolean isForcePhaseTypes() { - return forcePhaseTypes; + public void setTotalNumberOfMoles(double totalNumberOfMoles) { + if (totalNumberOfMoles < 0) { + /* + * throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, + * "setTotalNumberOfMoles", "totalNumberOfMoles", "can not be less than 0.")); + */ + totalNumberOfMoles = 0; + } + this.totalNumberOfMoles = totalNumberOfMoles; } /** {@inheritDoc} */ @Override - public void setForcePhaseTypes(boolean forcePhaseTypes) { - this.forcePhaseTypes = forcePhaseTypes; + public void setUseTVasIndependentVariables(boolean useTVasIndependentVariables) { + for (int i = 0; i < numberOfPhases; i++) { + getPhase(i).setTotalVolume(getPhase(i).getVolume()); + getPhase(i).setConstantPhaseVolume(useTVasIndependentVariables); + getPhase(i).calcMolarVolume(!useTVasIndependentVariables); + } + this.useTVasIndependentVariables = useTVasIndependentVariables; } /** {@inheritDoc} */ @Override - public SystemProperties getProperties() { - return new SystemProperties(this); + public void tuneModel(String model, double val, int phase) { + if (model.equals("viscosity")) { + getPhase(phase).getPhysicalProperties().getViscosityModel().tuneModel(val, + getPhase(phase).getTemperature(), getPhase(phase).getPressure()); + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + for (int j = 0; j < numberOfPhases; j++) { + getPhase(i).getComponent(j) + .setCriticalViscosity(getPhase(phase).getComponent(j).getCriticalViscosity()); + } + } + } + initPhysicalProperties(); } /** - * Wrapper function for addComponent to set fluid type and specify mole fractions. + *

+ * useTVasIndependentVariables. + *

* - * @param molefractions Component mole fraction of each component. - * @param type Type of fluid. Supports "PlusFluid", "Plus" and default. + * @return a boolean */ - private void setMolarFractions(double[] molefractions, String type) { - double totalFlow = getTotalNumberOfMoles(); - if (totalFlow < 1e-100) { - String msg = "must be larger than 0 (1e-100) when setting molar composition"; - throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, - "setMolarComposition", "totalFlow", msg)); - } - double sum = 0; - for (double value : molefractions) { - sum += value; - } - setEmptyFluid(); - - switch (type) { - case "PlusFluid": - // TODO: really skip last component of molefraction? - for (int compNumb = 0; compNumb < molefractions.length - 1; compNumb++) { - addComponent(compNumb, totalFlow * molefractions[compNumb] / sum); - } - for (int j = 0; j < getCharacterization().getLumpingModel().getNumberOfLumpedComponents() - - 1; j++) { - // addComponent(compNumb, totalFlow * molefractions[molefractions.length - 1] - // * getCharacterization().getLumpingModel().getFractionOfHeavyEnd(j) / sum); - } - break; - case "Plus": - // TODO: compNumb can be negative - for (int compNumb = 0; compNumb < this.numberOfComponents - - getCharacterization().getLumpingModel().getNumberOfLumpedComponents(); compNumb++) { - addComponent(compNumb, totalFlow * molefractions[compNumb] / sum); - } - int ii = 0; - for (int compNumb = this.numberOfComponents - getCharacterization().getLumpingModel() - .getNumberOfLumpedComponents(); compNumb < this.numberOfComponents; compNumb++) { - addComponent(compNumb, - totalFlow * getCharacterization().getLumpingModel().getFractionOfHeavyEnd(ii++) - * molefractions[this.numberOfComponents - - getCharacterization().getLumpingModel().getNumberOfLumpedComponents()] - / sum); - } - break; - default: - // NB! It will allow setting composition for only the first items. - // for (int compNumb = 0; compNumb <= molefractions.length - 1; compNumb++) { - // NB! Can fail because len(molefractions) < this.numberOfComponents - for (int compNumb = 0; compNumb <= this.numberOfComponents - 1; compNumb++) { - addComponent(compNumb, totalFlow * molefractions[compNumb] / sum); - } - break; - } - - for (int i = 0; i < getNumberOfPhases(); i++) { - init(0, i); - } - } - - /** {@inheritDoc} */ - @Override - public void addCharacterized(String[] charNames, double[] charFlowrate, double[] molarMass, - double[] relativedensity) { - if (charNames.length != charFlowrate.length) { - logger.error("component names and mole fractions need to be same length..."); - } - for (int i = 0; i < charNames.length; i++) { - addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); - } + public boolean useTVasIndependentVariables() { + return useTVasIndependentVariables; } /** {@inheritDoc} */ @Override - public void addOilFractions(String[] charNames, double[] charFlowrate, double[] molarMass, - double[] relativedensity, boolean lastIsPlusFraction, boolean lumpComponents, - int numberOfPseudoComponents) { - if (charNames.length != charFlowrate.length) { - logger.error("component names and mole fractions need to be same length..."); - } - - for (int i = 0; i < charNames.length - 1; i++) { - addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); - } - int i = charNames.length - 1; - if (lastIsPlusFraction) { - addPlusFraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); - } else { - addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); - } - createDatabase(true); - if (lastIsPlusFraction) { - getCharacterization().getLumpingModel().setNumberOfPseudoComponents(numberOfPseudoComponents); - if (lumpComponents) { - getCharacterization().setLumpingModel("PVTlumpingModel"); - } else { - getCharacterization().setLumpingModel("no lumping"); + public void useVolumeCorrection(boolean volcor) { + for (PhaseInterface tmpPhase : phaseArray) { + if (tmpPhase != null) { + tmpPhase.useVolumeCorrection(volcor); } - getCharacterization().characterisePlusFraction(); } - setMixingRule(getMixingRule()); - setMultiPhaseCheck(true); - init(0); } - /** {@inheritDoc} */ - @Override - public void addOilFractions(String[] charNames, double[] charFlowrate, double[] molarMass, - double[] relativedensity, boolean lastIsPlusFraction) { - addOilFractions(charNames, charFlowrate, molarMass, relativedensity, lastIsPlusFraction, true, - 12); + /** + *

+ * write. + *

+ * + * @return a {@link java.lang.String} object + */ + public String write() { + // create a String description of the system + return ""; } /** {@inheritDoc} */ @Override - public double getIdealLiquidDensity(String unit) { - double normalLiquidDensity = 0.0; - double molarMass = getMolarMass(); - for (int i = 0; i < getNumberOfComponents(); i++) { - normalLiquidDensity += getComponent(i).getNormalLiquidDensity() * getComponent(i).getz() - * getComponent(i).getMolarMass() / molarMass; - } - if (unit.equals("gr/cm3")) { - return normalLiquidDensity; - } else if (unit.equals("kg/m3")) { - return normalLiquidDensity * 1000.0; - } else { - logger.error("unit not supported: " + unit); - return normalLiquidDensity; + public void write(String name, String filename, boolean newfile) { + String[][] table = createTable(name); + neqsim.dataPresentation.fileHandeling.createTextFile.TextFile file = + new neqsim.dataPresentation.fileHandeling.createTextFile.TextFile(); + if (newfile) { + file.newFile(filename); } + file.setOutputFileName(filename); + file.setValues(table); + file.createFile(); } }