diff --git a/pom.xml b/pom.xml index 5661e44a97..2302fbf11c 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ ${revision}${sha1}${changelist} - 2.5.9 + 2.5.10 UTF-8 UTF-8 diff --git a/pomJava8.xml b/pomJava8.xml index d069e08646..9d43e81ab0 100644 --- a/pomJava8.xml +++ b/pomJava8.xml @@ -10,7 +10,7 @@ ${revision}${sha1}${changelist}-Java8 - 2.5.9 + 2.5.10 UTF-8 UTF-8 diff --git a/src/main/java/neqsim/processSimulation/processEquipment/distillation/DistillationColumn.java b/src/main/java/neqsim/processSimulation/processEquipment/distillation/DistillationColumn.java index b82e038aa8..f945e8de79 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/distillation/DistillationColumn.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/distillation/DistillationColumn.java @@ -56,8 +56,8 @@ public class DistillationColumn extends ProcessEquipmentBaseClass implements Dis *

* * @param numberOfTraysLocal a int - * @param hasReboiler a boolean - * @param hasCondenser a boolean + * @param hasReboiler a boolean + * @param hasCondenser a boolean */ public DistillationColumn(int numberOfTraysLocal, boolean hasReboiler, boolean hasCondenser) { super("DistillationColumn"); @@ -86,8 +86,9 @@ public DistillationColumn(int numberOfTraysLocal, boolean hasReboiler, boolean h * addFeedStream. *

* - * @param inputStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object + * @param inputStream a + * {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object * @param feedTrayNumber a int */ public void addFeedStream(StreamInterface inputStream, int feedTrayNumber) { @@ -154,20 +155,18 @@ public void init() { // ((Runnable) trays.get(numberOfTrays - 1)).run(); ((Runnable) trays.get(0)).run(); - double feedTrayTemperature = getTray(getFeedTrayNumber()).getTemperature(); if (trays.get(numberOfTrays - 1).getNumberOfInputStreams() > 0) { - condenserTemperature = - ((MixerInterface) trays.get(numberOfTrays - 1)).getThermoSystem().getTemperature(); + condenserTemperature = ((MixerInterface) trays.get(numberOfTrays - 1)).getThermoSystem().getTemperature(); } else { condenserTemperature = feedTrayTemperature - 1.0; } reboilerTemperature = ((MixerInterface) trays.get(0)).getThermoSystem().getTemperature(); - double deltaTempCondenser = - (feedTrayTemperature - condenserTemperature) / (numberOfTrays * 1.0 - feedTrayNumber - 1); + double deltaTempCondenser = (feedTrayTemperature - condenserTemperature) + / (numberOfTrays * 1.0 - feedTrayNumber - 1); double deltaTempReboiler = (reboilerTemperature - feedTrayTemperature) / (feedTrayNumber * 1.0); double delta = 0; @@ -208,7 +207,9 @@ public void init() { * Getter for the field gasOutStream. *

* - * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + * @return a + * {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object */ public StreamInterface getGasOutStream() { return gasOutStream; @@ -219,7 +220,9 @@ public StreamInterface getGasOutStream() { * Getter for the field liquidOutStream. *

* - * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + * @return a + * {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object */ public StreamInterface getLiquidOutStream() { return liquidOutStream; @@ -231,7 +234,9 @@ public StreamInterface getLiquidOutStream() { *

* * @param trayNumber a int - * @return a {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} object + * @return a + * {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} + * object */ public SimpleTray getTray(int trayNumber) { return trays.get(trayNumber); @@ -498,12 +503,15 @@ public boolean massBalanceCheck() { + trays.get(i).getGasOutStream().getPressure() + " temperature " + trays.get(i).getGasOutStream().getTemperature("C")); /* - * System.out.println( "tray " + i + " number of input streams " + numberOfInputStreams + + * System.out.println( "tray " + i + " number of input streams " + + * numberOfInputStreams + * " water in gasout " + * trays.get(i).getGasOutStream().getFluid().getPhase(0).getComponent("water") * .getNumberOfmoles() + " water in liquidout " + - * trays.get(i).getLiquidOutStream().getFluid().getPhase(0).getComponent( "water") - * .getNumberOfmoles() + " pressure " + trays.get(i).getGasOutStream().getPressure() + + * trays.get(i).getLiquidOutStream().getFluid().getPhase(0).getComponent( + * "water") + * .getNumberOfmoles() + " pressure " + + * trays.get(i).getGasOutStream().getPressure() + * " temperature " + trays.get(i).getGasOutStream().getTemperature("C")); */ } @@ -554,8 +562,7 @@ public void energyBalanceCheck() { * @param args an array of {@link java.lang.String} objects */ public static void main(String[] args) { - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos((273.15 - 0.0), 15.000); + neqsim.thermo.system.SystemInterface testSystem = new neqsim.thermo.system.SystemSrkEos((273.15 - 0.0), 15.000); // testSystem.addComponent("methane", 10.00); testSystem.addComponent("ethane", 10.0); testSystem.addComponent("CO2", 10.0); @@ -579,8 +586,7 @@ public static void main(String[] args) { // column.getCondenser().setHeatInput(-70000.0); // ((Condenser) column.getCondenser()).setRefluxRatio(0.2); - neqsim.processSimulation.processSystem.ProcessSystem operations = - new neqsim.processSimulation.processSystem.ProcessSystem(); + neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem(); operations.add(stream_1); operations.add(column); operations.run(); @@ -595,7 +601,9 @@ public static void main(String[] args) { * getReboiler. *

* - * @return a {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} object + * @return a + * {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} + * object */ public SimpleTray getReboiler() { return trays.get(0); @@ -606,7 +614,9 @@ public SimpleTray getReboiler() { * getCondenser. *

* - * @return a {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} object + * @return a + * {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} + * object */ public SimpleTray getCondenser() { return trays.get(trays.size() - 1); diff --git a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java index 18c08aa989..bdd1c095f9 100644 --- a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java +++ b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java @@ -86,7 +86,8 @@ public class ThermodynamicOperations implements java.io.Serializable, Cloneable * Constructor for ThermodynamicOperations. *

*/ - public ThermodynamicOperations() {} + public ThermodynamicOperations() { + } /** *

@@ -121,11 +122,12 @@ public void TPSolidflash() { } /** - * Method to perform a flash at given temperature, pressure and specified volume The number of + * Method to perform a flash at given temperature, pressure and specified volume + * The number of * moles in the system are changed to match the specified volume. * * @param volumeSpec is the specified volume - * @param unit Supported units are m3 + * @param unit Supported units are m3 */ public void TPVflash(double volumeSpec, String unit) { unit = "m3"; @@ -147,8 +149,7 @@ public void TPflash() { system.setTotalNumberOfMoles(1.0); system.init(1); } - operation = - new neqsim.thermodynamicOperations.flashOps.TPflash(system, system.doSolidPhaseCheck()); + operation = new neqsim.thermodynamicOperations.flashOps.TPflash(system, system.doSolidPhaseCheck()); if (!isRunAsThread()) { getOperation().run(); } else { @@ -169,7 +170,8 @@ public void TPflash() { * TPflash. *

* - * @param checkForSolids Set true to check for solid phase and do solid phase calculations. + * @param checkForSolids Set true to check for solid phase and do solid phase + * calculations. */ public void TPflash(boolean checkForSolids) { operation = new neqsim.thermodynamicOperations.flashOps.TPflash(system, checkForSolids); @@ -181,7 +183,7 @@ public void TPflash(boolean checkForSolids) { * TPgradientFlash. *

* - * @param height a double + * @param height a double * @param temperature a double * @return a {@link neqsim.thermo.system.SystemInterface} object */ @@ -220,8 +222,7 @@ public void saturateWithWater() { */ public void chemicalEquilibrium() { if (system.isChemicalSystem()) { - operation = - new neqsim.thermodynamicOperations.chemicalEquilibrium.ChemicalEquilibrium(system); + operation = new neqsim.thermodynamicOperations.chemicalEquilibrium.ChemicalEquilibrium(system); getOperation().run(); } } @@ -232,7 +233,7 @@ public void chemicalEquilibrium() { *

* * @param Hspec a double - * @param type a int + * @param type a int */ public void PHflash(double Hspec, int type) { if (system.getPhase(0).getNumberOfComponents() == 1) { @@ -246,7 +247,7 @@ public void PHflash(double Hspec, int type) { /** * Method to perform a PH flash calculation. * - * @param Hspec is the enthalpy in the specified unit + * @param Hspec is the enthalpy in the specified unit * @param enthalpyUnit Supported units are J, J/mol, J/kg and kJ/kg */ public void PHflash(double Hspec, String enthalpyUnit) { @@ -306,10 +307,10 @@ public void PUflash(double Uspec) { * PUflash. *

* - * @param Pspec a double - * @param Uspec a double + * @param Pspec a double + * @param Uspec a double * @param unitPressure a {@link java.lang.String} object - * @param unitEnergy a {@link java.lang.String} object + * @param unitEnergy a {@link java.lang.String} object */ public void PUflash(double Pspec, double Uspec, String unitPressure, String unitEnergy) { system.setPressure(Pspec, unitPressure); @@ -321,7 +322,7 @@ public void PUflash(double Pspec, double Uspec, String unitPressure, String unit * PUflash. *

* - * @param Uspec a double + * @param Uspec a double * @param unitEnergy a {@link java.lang.String} object */ public void PUflash(double Uspec, String unitEnergy) { @@ -337,8 +338,7 @@ public void PUflash(double Uspec, String unitEnergy) { conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); break; case "kJ/kg": - conversionFactorEntr = - 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; default: break; @@ -352,7 +352,7 @@ public void PUflash(double Uspec, String unitEnergy) { *

* * @param Hspec a double - * @param type a int + * @param type a int */ public void PHflash2(double Hspec, int type) { operation = new PHflash(system, Hspec, type); @@ -398,10 +398,11 @@ public void PSflash(double Sspec) { } /** - * Method to perform a PS flash calculation for a specified entropy and pressure. + * Method to perform a PS flash calculation for a specified entropy and + * pressure. * * @param Sspec is the entropy in the specified unit - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK */ public void PSflash(double Sspec, String unit) { double conversionFactor = 1.0; @@ -436,10 +437,11 @@ public void TSflash(double Sspec) { } /** - * Method to perform a TS flash calculation for a specified entropy and pressure. + * Method to perform a TS flash calculation for a specified entropy and + * pressure. * * @param Sspec is the entropy in the specified unit - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK */ public void TSflash(double Sspec, String unit) { double conversionFactor = 1.0; @@ -492,9 +494,9 @@ public void PSflash2(double Sspec) { * VSflash. *

* - * @param volume a double - * @param entropy a double - * @param unitVol a {@link java.lang.String} object + * @param volume a double + * @param entropy a double + * @param unitVol a {@link java.lang.String} object * @param unitEntropy a {@link java.lang.String} object */ public void VSflash(double volume, double entropy, String unitVol, String unitEntropy) { @@ -520,8 +522,7 @@ public void VSflash(double volume, double entropy, String unitVol, String unitEn conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); break; case "kJ/kgK": - conversionFactorEntr = - 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; default: break; @@ -534,7 +535,7 @@ public void VSflash(double volume, double entropy, String unitVol, String unitEn * VSflash. *

* - * @param volume a double + * @param volume a double * @param entropy a double */ public void VSflash(double volume, double entropy) { @@ -548,7 +549,7 @@ public void VSflash(double volume, double entropy) { *

* * @param Vspec a double - * @param unit a {@link java.lang.String} object + * @param unit a {@link java.lang.String} object */ public void TVflash(double Vspec, String unit) { double conversionFactor = 1.0; @@ -579,7 +580,7 @@ public void TVflash(double Vspec) { * PVrefluxFlash. *

* - * @param refluxspec a double + * @param refluxspec a double * @param refluxPhase a int */ public void PVrefluxFlash(double refluxspec, int refluxPhase) { @@ -605,9 +606,9 @@ public void VHflash(double Vspec, double Hspec) { * VHflash. *

* - * @param volume a double - * @param enthalpy a double - * @param unitVol a {@link java.lang.String} object + * @param volume a double + * @param enthalpy a double + * @param unitVol a {@link java.lang.String} object * @param unitEnthalpy a {@link java.lang.String} object */ public void VHflash(double volume, double enthalpy, String unitVol, String unitEnthalpy) { @@ -633,8 +634,7 @@ public void VHflash(double volume, double enthalpy, String unitVol, String unitE conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); break; case "kJ/kg": - conversionFactorEntr = - 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; default: break; @@ -647,9 +647,9 @@ public void VHflash(double volume, double enthalpy, String unitVol, String unitE * VUflash. *

* - * @param volume a double - * @param energy a double - * @param unitVol a {@link java.lang.String} object + * @param volume a double + * @param energy a double + * @param unitVol a {@link java.lang.String} object * @param unitEnergy a {@link java.lang.String} object */ public void VUflash(double volume, double energy, String unitVol, String unitEnergy) { @@ -675,8 +675,7 @@ public void VUflash(double volume, double energy, String unitVol, String unitEne conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); break; case "kJ/kg": - conversionFactorEntr = - 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; default: break; @@ -858,8 +857,8 @@ public void checkScalePotential(int phaseNumber) throws Exception { * addIonToScaleSaturation. *

* - * @param phaseNumber a int - * @param scaleSaltName a {@link java.lang.String} object + * @param phaseNumber a int + * @param scaleSaltName a {@link java.lang.String} object * @param nameOfIonToBeAdded a {@link java.lang.String} object * @throws java.lang.Exception if any. */ @@ -993,7 +992,7 @@ public void calcSolidComlexTemperature(String comp1, String comp2) throws Except *

* * @param temperature an array of {@link double} objects - * @param pressure an array of {@link double} objects + * @param pressure an array of {@link double} objects * @return an array of {@link double} objects */ public double[] calcImobilePhaseHydrateTemperature(double[] temperature, double[] pressure) { @@ -1005,9 +1004,12 @@ public double[] calcImobilePhaseHydrateTemperature(double[] temperature, double[ for (int i = 0; i < temperature.length; i++) { /* * opsTemp = new ThermodynamicOperations(systemTemp); - * systemTemp.setTemperature(temperature[i]); systemTemp.setPressure(pressure[i]); - * systemTemp.init(0); systemTemp.display(); try { opsTemp.hydrateFormationTemperature(); } - * catch (Exception ex) { logger.error(ex.getMessage(),e); } systemTemp.display(); hydTemps[i] + * systemTemp.setTemperature(temperature[i]); + * systemTemp.setPressure(pressure[i]); + * systemTemp.init(0); systemTemp.display(); try { + * opsTemp.hydrateFormationTemperature(); } + * catch (Exception ex) { logger.error(ex.getMessage(),e); } + * systemTemp.display(); hydTemps[i] * = systemTemp.getTemperature(); * */ @@ -1060,7 +1062,7 @@ public double calcTOLHydrateFormationTemperature() { * hydrateInhibitorConcentration. *

* - * @param inhibitorName a {@link java.lang.String} object + * @param inhibitorName a {@link java.lang.String} object * @param hydEqTemperature a double * @throws java.lang.Exception if any. */ @@ -1076,7 +1078,7 @@ public void hydrateInhibitorConcentration(String inhibitorName, double hydEqTemp *

* * @param inhibitorName a {@link java.lang.String} object - * @param wtfrac a double + * @param wtfrac a double * @throws java.lang.Exception if any. */ public void hydrateInhibitorConcentrationSet(String inhibitorName, double wtfrac) @@ -1204,7 +1206,7 @@ public void hydrateEquilibriumLine(double minimumPressure, double maximumPressur * calcCricoP. *

* - * @param cricondenBar an array of {@link double} objects + * @param cricondenBar an array of {@link double} objects * @param cricondenBarX an array of {@link double} objects * @param cricondenBarY an array of {@link double} objects */ @@ -1222,7 +1224,7 @@ public void calcCricoP(double[] cricondenBar, double[] cricondenBarX, double[] c * calcCricoT. *

* - * @param cricondenTherm an array of {@link double} objects + * @param cricondenTherm an array of {@link double} objects * @param cricondenThermX an array of {@link double} objects * @param cricondenThermY an array of {@link double} objects */ @@ -1373,7 +1375,7 @@ public void constantPhaseFractionTemperatureFlash(double fraction) throws Except * * @param componentName a {@link java.lang.String} object * @param specification a {@link java.lang.String} object - * @param spec a double + * @param spec a double * @throws java.lang.Exception if any. */ public void dewPointMach(String componentName, String specification, double spec) @@ -1430,8 +1432,8 @@ public void dewPointMach(String componentName, String specification, double spec * @throws java.lang.Exception if any. */ public void dewPointTemperatureFlash() throws Exception { - ConstantDutyFlashInterface operation = - new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash(system); + ConstantDutyFlashInterface operation = new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash( + system); operation.run(); if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), @@ -1448,8 +1450,8 @@ public void dewPointTemperatureFlash() throws Exception { * @throws java.lang.Exception if any. */ public void dewPointTemperatureFlash(boolean derivatives) throws Exception { - ConstantDutyFlashInterface operation = - new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash(system); + ConstantDutyFlashInterface operation = new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash( + system); if (derivatives) { operation = new dewPointTemperatureFlashDer(system); } @@ -1532,7 +1534,7 @@ public void calcPTphaseEnvelope() { *

* * @param bubfirst a boolean - * @param lowPres a double + * @param lowPres a double */ public void calcPTphaseEnvelope(boolean bubfirst, double lowPres) { double phasefraction = 1.0 - 1e-10; @@ -1588,7 +1590,7 @@ public void calcPTphaseEnvelope(boolean bubfirst) { * calcPTphaseEnvelope. *

* - * @param lowPres a double + * @param lowPres a double * @param phasefraction a double */ public void calcPTphaseEnvelope(double lowPres, double phasefraction) { @@ -1615,14 +1617,14 @@ public void calcPTphaseEnvelopeNew() { * OLGApropTable. *

* - * @param minTemp a double - * @param maxTemp a double + * @param minTemp a double + * @param maxTemp a double * @param temperatureSteps a int - * @param minPres a double - * @param maxPres a double - * @param pressureSteps a int - * @param filename a {@link java.lang.String} object - * @param TABtype a int + * @param minPres a double + * @param maxPres a double + * @param pressureSteps a int + * @param filename a {@link java.lang.String} object + * @param TABtype a int */ public void OLGApropTable(double minTemp, double maxTemp, int temperatureSteps, double minPres, double maxPres, int pressureSteps, String filename, int TABtype) { @@ -1640,14 +1642,14 @@ public void OLGApropTable(double minTemp, double maxTemp, int temperatureSteps, * OLGApropTablePH. *

* - * @param minEnthalpy a double - * @param maxEnthalpy a double + * @param minEnthalpy a double + * @param maxEnthalpy a double * @param enthalpySteps a int - * @param minPres a double - * @param maxPres a double + * @param minPres a double + * @param maxPres a double * @param pressureSteps a int - * @param filename a {@link java.lang.String} object - * @param TABtype a int + * @param filename a {@link java.lang.String} object + * @param TABtype a int */ public void OLGApropTablePH(double minEnthalpy, double maxEnthalpy, int enthalpySteps, double minPres, double maxPres, int pressureSteps, String filename, int TABtype) { @@ -1717,8 +1719,7 @@ public double[][] getData() { * @return an array of {@link java.lang.String} objects */ public String[][] getDataPoints() { - String[][] str = - new String[getOperation().getPoints(0).length][getOperation().getPoints(0)[0].length]; + String[][] str = new String[getOperation().getPoints(0).length][getOperation().getPoints(0)[0].length]; for (int i = 0; i < getOperation().getPoints(0).length; i++) { for (int j = 0; j < getOperation().getPoints(0)[0].length; j++) { str[i][j] = Double.toString(getOperation().getPoints(0)[i][j]); @@ -1907,8 +1908,8 @@ public void calcIonComposition(int phaseNumber) { *

* * @param flashType Type of flash. - * @param spec1 Value of spec1 - * @param spec2 Value of spec2 + * @param spec1 Value of spec1 + * @param spec2 Value of spec2 * @param unitSpec1 Unit of spec1 * @param unitSpec2 Unit of spec2 */ @@ -1943,16 +1944,19 @@ public void flash(FlashType flashType, double spec1, double spec2, String unitSp } /** - * Perform flashes and return System properties per set of Spec1 and Spec2. Possible to specify + * Perform flashes and return System properties per set of Spec1 and Spec2. + * Possible to specify * fractions for each value of Spec1. * - * @param Spec1 Flash pressure in bar absolute. - * @param Spec2 Flash specification. Depends on FlashMode. Temperature in Kelvin, entalphy in - * J/mol or entropy in J/molK. - * @param FlashMode 1 - PT 2 - PH 3 - PS - * @param components Not yet in use. - * @param onlineFractions Specify fractions per sample instance or null to use static composition - * specified in system. + * @param Spec1 Flash pressure in bar absolute. + * @param Spec2 Flash specification. Depends on FlashMode. Temperature + * in Kelvin, entalphy in + * J/mol or entropy in J/molK. + * @param FlashMode 1 - PT 2 - PH 3 - PS + * @param components Not yet in use. + * @param onlineFractions Specify fractions per sample instance or null to use + * static composition + * specified in system. * @return Object CalculationResult object */ public CalculationResult propertyFlash(List Spec1, List Spec2, int FlashMode, @@ -2046,12 +2050,14 @@ public CalculationResult propertyFlash(List Spec1, List Spec2, i * * this.system.setEmptyFluid(); * - * // Components in system with no corresponding value in onlineFractions will be zero. + * // Components in system with no corresponding value in onlineFractions will + * be zero. * for (int componentNumber = 0; componentNumber < onlineFractions .size(); * componentNumber++) { this.system.addComponent(componentNumber, * onlineFractions.get(componentNumber).get(t).doubleValue()); } * - * if (this.system.getTotalNumberOfMoles() < 1e-5) { this.system.setTotalNumberOfMoles(1); + * if (this.system.getTotalNumberOfMoles() < 1e-5) { + * this.system.setTotalNumberOfMoles(1); * } */ diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java index 8290b78704..75a72a378d 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java @@ -371,14 +371,17 @@ public void stabilityAnalysis() { int iter = 0; double errOld = 1.0e100; boolean useaccsubst = true; + int maxsucssubiter = 150; + int maxiter = 200; do { errOld = err; iter++; err = 0; - if (iter <= 150 || !system.isImplementedCompositionDeriativesofFugacity()) { + if (iter <= maxsucssubiter || !system.isImplementedCompositionDeriativesofFugacity()) { if (iter % 7 == 0 && useaccsubst) { double vec1 = 0.0; + double vec2 = 0.0; double prod1 = 0.0; double prod2 = 0.0; @@ -512,7 +515,7 @@ public void stabilityAnalysis() { clonedSystem.get(0).getPhase(1).getComponents()[i].setx(1e-50); } } - } while ((Math.abs(err) > 1e-9 || err > errOld) && iter < 600); + } while ((Math.abs(err) > 1e-9 || err > errOld) && iter < maxiter); // logger.info("err: " + err + " ITER " + iter); double xTrivialCheck0 = 0.0; double xTrivialCheck1 = 0.0; @@ -529,7 +532,353 @@ public void stabilityAnalysis() { xTrivialCheck0 += Math.abs(x[j][i] - system.getPhase(0).getComponent(i).getx()); xTrivialCheck1 += Math.abs(x[j][i] - system.getPhase(1).getComponent(i).getx()); } - if (iter >= 599) { + if (iter >= maxiter) { + // logger.info("iter > maxiter multiphase stability "); + // logger.info("error " + Math.abs(err)); + // logger.info("tm: " + tm[j]); + } + + if (Math.abs(xTrivialCheck0) < 1e-4 || Math.abs(xTrivialCheck1) < 1e-4) { + tm[j] = 10.0; + } + + if (tm[j] < -1e-8) { + break; + } + } + + int unstabcomp = 0; + for (int k = system.getPhase(0).getNumberOfComponents() - 1; k >= 0; k--) { + if (tm[k] < -1e-8 && !(Double.isNaN(tm[k]))) { + system.addPhase(); + unstabcomp = k; + for (int i = 0; i < system.getPhase(1).getNumberOfComponents(); i++) { + system.getPhase(system.getNumberOfPhases() - 1).getComponents()[i].setx(x[k][i]); + } + system.getPhases()[system.getNumberOfPhases() - 1].normalize(); + multiPhaseTest = true; + system.setBeta(system.getNumberOfPhases() - 1, + system.getPhase(0).getComponent(unstabcomp).getz()); + system.init(1); + system.normalizeBeta(); + + // logger.info("STABILITY ANALYSIS: "); + // logger.info("tm1: " + k + " "+ tm[k]); + // system.display(); + return; + } + } + + system.normalizeBeta(); + // logger.info("STABILITY ANALYSIS: "); + // logger.info("tm1: " + tm[0] + " tm2: " + tm[1]); + // system.display(); + } + + public void stabilityAnalysis3() { + double[] logWi = new double[system.getPhase(0).getNumberOfComponents()]; + double[][] Wi = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) + .getNumberOfComponents()]; + + double[] deltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] sumw = new double[system.getPhase(0).getNumberOfComponents()]; + double err = 0; + double[] oldlogw = new double[system.getPhase(0).getNumberOfComponents()]; + double[] oldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] d = new double[system.getPhase(0).getNumberOfComponents()]; + double[][] x = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) + .getNumberOfComponents()]; + tm = new double[system.getPhase(0).getNumberOfComponents()]; + + double[] alpha = null; + // SystemInterface minimumGibbsEnergySystem; + ArrayList clonedSystem = new ArrayList(1); + // if (minimumGibbsEnergySystem == null) { + // minimumGibbsEnergySystem = system.clone(); + // } + minimumGibbsEnergySystem = system; + clonedSystem.add(system.clone()); + /* + * for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { if + * (system.getPhase(0).getComponent(i).getx() < 1e-100) { clonedSystem.add(null); continue; } + * double numb = 0; clonedSystem.add(system.clone()); + * + * // (clonedSystem.get(i)).init(0); commented out sept 2005, Even S. for (int j = 0; j < + * system.getPhase(0).getNumberOfComponents(); j++) { numb = i == j ? 1.0 : 1.0e-12; // set to 0 + * by Even Solbraa 23.01.2013 - chaged back to 1.0e-12 27.04.13 if + * (system.getPhase(0).getComponent(j).getz() < 1e-100) { numb = 0; } ( + * clonedSystem.get(i)).getPhase(1).getComponents()[j].setx(numb); } if + * (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { ( clonedSystem.get(i)).init(1); + * } } + */ + + lowestGibbsEnergyPhase = 0; + /* + * // logger.info("low gibbs phase " + lowestGibbsEnergyPhase); for (int k = 0; k < + * minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); k++) { for (int i = 0; i < + * minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); i++) { if (!(( + * clonedSystem.get(k)) == null)) { sumw[k] += ( + * clonedSystem.get(k)).getPhase(1).getComponents()[i].getx(); } } } + * + * for (int k = 0; k < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); k++) { for + * (int i = 0; i < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); i++) { if (!(( + * clonedSystem.get(k)) == null) && system.getPhase(0).getComponent(k).getx() > 1e-100) { ( + * clonedSystem.get(k)).getPhase(1).getComponents()[i].setx(( + * clonedSystem.get(k)).getPhase(1).getComponents()[i].getx() / sumw[0]); } logger.info("x: " + + * ( clonedSystem.get(k)).getPhase(0).getComponents()[i].getx()); } if + * (system.getPhase(0).getComponent(k).getx() > 1e-100) { d[k] = + * Math.log(system.getPhase(0).getComponents()[k].getx()) + + * system.getPhase(0).getComponents()[k].getLogFugacityCoefficient(); + * if(minimumGibbsEnergySystem.getPhases()[lowestGibbsEnergyPhase].getComponents + * ()[k].getIonicCharge()!=0) d[k]=0; } //logger.info("dk: " + d[k]); } + */ + for (int k = 0; k < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); k++) { + if (system.getPhase(0).getComponent(k).getx() > 1e-100) { + d[k] = Math.log(system.getPhase(0).getComponents()[k].getx()) + + system.getPhase(0).getComponents()[k].getLogFugacityCoefficient(); + // if(minimumGibbsEnergySystem.getPhases()[lowestGibbsEnergyPhase].getComponents()[k].getIonicCharge()!=0) + // d[k]=0; + } + } + + for (int j = 0; j < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); j++) { + if (system.getPhase(0).getComponent(j).getz() > 1e-100) { + logWi[j] = 1.0; + } else { + logWi[j] = -10000.0; + } + } + + int hydrocarbonTestCompNumb = 0; + int lightTestCompNumb = 0; + double Mmax = 0; + double Mmin = 1e10; + for (int i = 0; i < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); i++) { + if (minimumGibbsEnergySystem.getPhase(0).getComponent(i).isHydrocarbon()) { + if ((minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass()) > Mmax) { + Mmax = minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass(); + } + if ((minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass()) < Mmin) { + Mmin = minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass(); + } + } + } + + for (int i = 0; i < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); i++) { + if (minimumGibbsEnergySystem.getPhase(0).getComponent(i).isHydrocarbon() + && minimumGibbsEnergySystem.getPhase(0).getComponent(i).getz() > 1e-50) { + if (Math.abs( + (minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass()) - Mmax) < 1e-5) { + hydrocarbonTestCompNumb = i; + // logger.info("CHECKING heavy component " + hydrocarbonTestCompNumb); + } + } + + if (minimumGibbsEnergySystem.getPhase(0).getComponent(i).isHydrocarbon() + && minimumGibbsEnergySystem.getPhase(0).getComponent(i).getz() > 1e-50) { + if (Math.abs( + (minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass()) - Mmin) < 1e-5) { + lightTestCompNumb = i; + // logger.info("CHECKING light component " + lightTestCompNumb); + } + } + } + + for (int j = 0; j < system.getNumberOfComponents(); j++) { + if (minimumGibbsEnergySystem.getPhase(0).getComponent(j).getx() < 1e-100 + || (minimumGibbsEnergySystem.getPhase(0).getComponent(j).getIonicCharge() != 0) + || (minimumGibbsEnergySystem.getPhase(0).getComponent(j).isHydrocarbon() + && j != hydrocarbonTestCompNumb && j != lightTestCompNumb)) { + continue; + } + + double nomb = 0.0; + for (int cc = 0; cc < system.getPhase(0).getNumberOfComponents(); cc++) { + nomb = cc == j ? 1.0 : 1.0e-12; + if (system.getPhase(0).getComponent(cc).getz() < 1e-100) { + nomb = 0.0; + } + + if (clonedSystem.get(0).isPhase(1)) { + try { + clonedSystem.get(0).getPhase(1).getComponents()[cc].setx(nomb); + } catch (Exception ex) { + logger.warn(ex.getMessage()); + } + } + } + // if(minimumGibbsEnergySystem.getPhase(0).getComponent(j).getName().equals("water") + // && minimumGibbsEnergySystem.isChemicalSystem()) continue; + // logger.info("STAB CHECK COMP " + + // system.getPhase(0).getComponent(j).getComponentName()); + // if(minimumGibbsEnergySystem.getPhase(0).getComponent(j).isInert()) break; + int iter = 0; + double errOld = 1.0e100; + boolean useaccsubst = true; + int maxsucssubiter = 50; + int maxiter = 100; + do { + errOld = err; + iter++; + err = 0; + + if (iter <= maxsucssubiter || !system.isImplementedCompositionDeriativesofFugacity()) { + if (iter % 7 == 0 && useaccsubst) { + double vec1 = 0.0; + double vec2 = 0.0; + double prod1 = 0.0; + double prod2 = 0.0; + for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + vec1 = oldDeltalogWi[i] * oldoldDeltalogWi[i]; + vec2 = Math.pow(oldoldDeltalogWi[i], 2.0); + prod1 += vec1 * vec2; + prod2 += vec2 * vec2; + } + + double lambda = prod1 / prod2; + // logger.info("lambda " + lambda); + for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + logWi[i] += lambda / (1.0 - lambda) * deltalogWi[i]; + err += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); + Wi[j][i] = Math.exp(logWi[i]); + } + } else { + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + oldoldoldlogw[i] = oldoldlogw[i]; + oldoldlogw[i] = oldlogw[i]; + oldlogw[i] = logWi[i]; + oldoldDeltalogWi[i] = oldoldlogw[i] - oldoldoldlogw[i]; + oldDeltalogWi[i] = oldlogw[i] - oldoldlogw[i]; + } + clonedSystem.get(0).init(1, 1); + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + // oldlogw[i] = logWi[i]; + if (!Double.isInfinite( + clonedSystem.get(0).getPhase(1).getComponents()[i].getLogFugacityCoefficient()) + && system.getPhase(0).getComponent(i).getx() > 1e-100) { + logWi[i] = d[i] - clonedSystem.get(0).getPhase(1).getComponents()[i] + .getLogFugacityCoefficient(); + if (clonedSystem.get(0).getPhase(1).getComponents()[i].getIonicCharge() != 0) { + logWi[i] = -1000.0; + } + } + deltalogWi[i] = logWi[i] - oldlogw[i]; + err += Math.abs(logWi[i] - oldlogw[i]); + Wi[j][i] = Math.exp(logWi[i]); + useaccsubst = true; + } + if (iter > 2 && err > errOld) { + useaccsubst = false; + } + } + + } else { + SimpleMatrix f = new SimpleMatrix(system.getPhases()[0].getNumberOfComponents(), 1); + SimpleMatrix df = null; + SimpleMatrix identitytimesConst = null; + // if (!secondOrderStabilityAnalysis) { + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + oldoldoldlogw[i] = oldoldlogw[i]; + oldoldlogw[i] = oldlogw[i]; + oldlogw[i] = logWi[i]; + oldoldDeltalogWi[i] = oldoldlogw[i] - oldoldoldlogw[i]; + oldDeltalogWi[i] = oldlogw[i] - oldoldlogw[i]; + } + clonedSystem.get(0).init(3, 1); + alpha = new double[clonedSystem.get(0).getPhases()[0].getNumberOfComponents()]; + df = new SimpleMatrix(system.getPhases()[0].getNumberOfComponents(), + system.getPhases()[0].getNumberOfComponents()); + identitytimesConst = SimpleMatrix.identity(system.getPhases()[0].getNumberOfComponents()); + // , + // system.getPhases()[0].getNumberOfComponents()); + // secondOrderStabilityAnalysis = true; + // } + + for (int i = 0; i < clonedSystem.get(0).getPhases()[0].getNumberOfComponents(); i++) { + alpha[i] = 2.0 * Math.sqrt(Wi[j][i]); + } + + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getz() > 1e-100) { + f.set(i, 0, + Math.sqrt(Wi[j][i]) + * (Math.log(Wi[j][i]) + clonedSystem.get(0).getPhases()[1].getComponents()[i] + .getLogFugacityCoefficient() - d[i])); + } + for (int k = 0; k < clonedSystem.get(0).getPhases()[0].getNumberOfComponents(); k++) { + double kronDelt = (i == k) ? 1.0 : 0.0; + if (system.getPhase(0).getComponent(i).getz() > 1e-100) { + df.set(i, k, kronDelt + Math.sqrt(Wi[j][k] * Wi[j][i]) + * clonedSystem.get(0).getPhases()[1].getComponents()[i].getdfugdn(k)); + // * clonedSystem.getPhases()[j].getNumberOfMolesInPhase()); + } else { + df.set(i, k, 0); + // * clonedSystem.getPhases()[j].getNumberOfMolesInPhase()); + } + } + } + + // f.print(10, 10); + // df.print(10, 10); + SimpleMatrix dx = null; + try { + dx = df.plus(identitytimesConst).solve(f).negative(); + } catch (Exception e) { + dx = df.plus(identitytimesConst.scale(0.5)).solve(f).negative(); + } + + // dx.print(10, 10); + + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + double alphaNew = alpha[i] + dx.get(i, 0); + Wi[j][i] = Math.pow(alphaNew / 2.0, 2.0); + if (system.getPhase(0).getComponent(i).getz() > 1e-100) { + logWi[i] = Math.log(Wi[j][i]); + } + if (system.getPhase(0).getComponent(i).getIonicCharge() != 0) { + logWi[i] = -1000.0; + } + err += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); + } + + // logger.info("err newton " + err); + } + // logger.info("err: " + err); + sumw[j] = 0; + + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + sumw[j] += Math.exp(logWi[i]); + } + + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getx() > 1e-100) { + clonedSystem.get(0).getPhase(1).getComponents()[i].setx(Math.exp(logWi[i]) / sumw[j]); + } + if (system.getPhase(0).getComponent(i).getIonicCharge() != 0) { + clonedSystem.get(0).getPhase(1).getComponents()[i].setx(1e-50); + } + } + } while ((Math.abs(err) > 1e-9 || err > errOld) && iter < maxiter); + // logger.info("err: " + err + " ITER " + iter); + double xTrivialCheck0 = 0.0; + double xTrivialCheck1 = 0.0; + + tm[j] = 1.0; + + for (int i = 0; i < system.getPhase(1).getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getx() > 1e-100) { + tm[j] -= Math.exp(logWi[i]); + } + x[j][i] = clonedSystem.get(0).getPhase(1).getComponents()[i].getx(); + // logger.info("txji: " + x[j][i]); + + xTrivialCheck0 += Math.abs(x[j][i] - system.getPhase(0).getComponent(i).getx()); + xTrivialCheck1 += Math.abs(x[j][i] - system.getPhase(1).getComponent(i).getx()); + } + if (iter >= maxiter - 1) { // logger.info("iter > maxiter multiphase stability "); // logger.info("error " + Math.abs(err)); // logger.info("tm: " + tm[j]); @@ -714,7 +1063,7 @@ public void stabilityAnalysis2() { iter++; err = 0; - if (iter <= 20 || !system.isImplementedCompositionDeriativesofFugacity()) { + if (iter <= 150 || !system.isImplementedCompositionDeriativesofFugacity()) { if (iter % 7 == 0) { double vec1 = 0.0; @@ -841,7 +1190,8 @@ public void stabilityAnalysis2() { } } while ((Math.abs(err) > 1e-9 || err > errOld) && iter < 200); if (iter > 198) { - System.out.println("too many iterations....." + err); + System.out.println("too many iterations....." + err + " temperature " + + system.getTemperature("C") + " C " + system.getPressure("bara") + " bara"); new Exception("to many iterations "); } // logger.info("err: " + err + " ITER " + iter); @@ -931,6 +1281,7 @@ public void run() { double oldDiff = 1.0e10; double chemdev = 0; int iterOut = 0; + double maxerr = 1e-12; do { iterOut++; if (system.isChemicalSystem()) { @@ -972,11 +1323,16 @@ public void run() { // diff = Math.abs((system.getBeta(system.getNumberOfPhases() - 1) - oldBeta) / // oldBeta); // logger.info("diff multiphase " + diff); - } while (diff > 1e-12 && !removePhase && (diff < oldDiff || iterations < 50) + if (iterations % 50 == 0) { + maxerr *= 100.0; + } + } while (diff > maxerr && !removePhase && (diff < oldDiff || iterations < 50) && iterations < 200); // this.solveBeta(true); if (iterations >= 199) { logger.error("error in multiphase flash..did not solve in 200 iterations"); + logger.error("diff " + diff + " temperaure " + system.getTemperature("C") + " pressure " + + system.getPressure("bara")); diff = this.solveBeta(); } } while ((Math.abs(chemdev) > 1e-10 && iterOut < 100) @@ -1020,6 +1376,7 @@ public void run() { */ if (hasRemovedPhase && !secondTime) { secondTime = true; + stabilityAnalysis3(); run(); } /* diff --git a/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTest.java b/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTest.java index 6fff851397..fcff3e2630 100644 --- a/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTest.java +++ b/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTest.java @@ -139,4 +139,35 @@ void testRun6() { assertEquals(0.27697023508525664, testSystem5.getBeta(), 1e-6); assertEquals(3, testSystem5.getNumberOfPhases()); } + + @Test + void testTPflash1() { + testSystem = new neqsim.thermo.system.SystemSrkEos(273.15 + 290, 400.0); + testSystem.addComponent("water", 65.93229747922976); + testSystem.addComponent("NaCl", 0.784426208131475); + testSystem.addComponent("nitrogen", 0.578509157534656); + testSystem.addComponent("methane", 22.584113183429718); + testSystem.addComponent("ethane", 3.43870686718215); + testSystem.addComponent("propane", 0.26487350163523365); + testSystem.addComponent("i-butane", 0.04039429848533373); + testSystem.addComponent("n-butane", 0.1543856425679738); + testSystem.addComponent("i-pentane", 0.04039429848533373); + testSystem.addComponent("n-pentane", 0.1543856425679738); + testSystem.addTBPfraction("C6", 0.568724470114871, 84.93298402237961 / 1000.0, + 666.591171644071 / 1000.0); + testSystem.addTBPfraction("C7", 0.9478147516962493, 90.01311937418495 / 1000.0, + 746.9101810251765 / 1000.0); + testSystem.addTBPfraction("C8", 0.974840433764089, 102.34691375809437 / 1000.0, + 776.2927119017166 / 1000.0); + testSystem.addTBPfraction("C9", 0.5505907716430188, 116.06055719132209 / 1000.0, + 791.2983315058531 / 1000.0); + testSystem.addTBPfraction("C10", 1.9704404325720026, 221.831957 / 1000.0, 842.802708 / 1000.0); + testSystem.setMixingRule("classic"); + testSystem.setMultiPhaseCheck(true); + testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + assertEquals(2, testSystem.getNumberOfPhases()); + // testSystem.prettyPrint(); + + } }