diff --git a/src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartAlternativeMapLookup.java b/src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartAlternativeMapLookup.java index cfe95ff623..288e3e085d 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartAlternativeMapLookup.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartAlternativeMapLookup.java @@ -191,10 +191,11 @@ public CompressorCurve getCurveAtRefSpeed(double refSpeed) { return c; } } - String msg = "Input ref. speed does not match any speed in the chart."; + String msg = "Does not match any speed in the chart."; logger.error(msg); neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(msg); + new neqsim.util.exception.InvalidInputException(this, "getCurveAtRefSpeed", "refSpeed", + msg); throw new RuntimeException(e); } diff --git a/src/main/java/neqsim/thermo/characterization/LumpingModel.java b/src/main/java/neqsim/thermo/characterization/LumpingModel.java index c80ceb2486..f9c5c24d9d 100644 --- a/src/main/java/neqsim/thermo/characterization/LumpingModel.java +++ b/src/main/java/neqsim/thermo/characterization/LumpingModel.java @@ -2,7 +2,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - import neqsim.thermo.system.SystemInterface; /** @@ -201,7 +200,8 @@ public void generateLumpedComposition(Characterise charac) { @Override public double getFractionOfHeavyEnd(int i) { if (fractionOfHeavyEnd == null) { - neqsim.util.exception.ThermoException e = new neqsim.util.exception.NotInitializedException( + neqsim.util.exception.ThermoException e = + new neqsim.util.exception.NotInitializedException(this, "getFractionOfHeavyEnd", "fractionOfHeavyEnd", "characterisePlusFraction or generateLumpedComposition"); logger.error(e.getMessage()); throw new RuntimeException(e); @@ -316,7 +316,8 @@ public void generateLumpedComposition(Characterise charac) { @Override public double getFractionOfHeavyEnd(int i) { if (fractionOfHeavyEnd == null) { - neqsim.util.exception.ThermoException e = new neqsim.util.exception.NotInitializedException( + neqsim.util.exception.ThermoException e = + new neqsim.util.exception.NotInitializedException(this, "getFractionOfHeavyEnd", "fractionOfHeavyEnd", "characterisePlusFraction or generateLumpedComposition"); logger.error(e.getMessage()); throw new RuntimeException(e); diff --git a/src/main/java/neqsim/thermo/component/Component.java b/src/main/java/neqsim/thermo/component/Component.java index a80dfc6611..93cb661aca 100644 --- a/src/main/java/neqsim/thermo/component/Component.java +++ b/src/main/java/neqsim/thermo/component/Component.java @@ -463,12 +463,13 @@ public void addMolesChemReac(double dn) { /** {@inheritDoc} */ @Override public void addMolesChemReac(double dn, double totdn) { - numberOfMoles += totdn; - numberOfMolesInPhase += dn; + numberOfMoles += totdn; if (numberOfMoles < 0) { numberOfMoles = 0; } + + numberOfMolesInPhase += dn; if (numberOfMolesInPhase < 0) { numberOfMolesInPhase = 0; } @@ -499,8 +500,8 @@ public void init(double temperature, double pressure, double totalNumberOfMoles, int type) { if (totalNumberOfMoles == 0) { - throw new RuntimeException(new neqsim.util.exception.InvalidInputException( - "Component", "init", "Input totalNumberOfMoles must be larger than 0")); + throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, "init", + "totalNumberOfMoles", "must be larger than 0")); } if (type == 0) { K = Math.exp(Math.log(criticalPressure / pressure) + 5.373 * (1.0 + srkacentricFactor) diff --git a/src/main/java/neqsim/thermo/component/ComponentInterface.java b/src/main/java/neqsim/thermo/component/ComponentInterface.java index 76512d9df2..a706597294 100644 --- a/src/main/java/neqsim/thermo/component/ComponentInterface.java +++ b/src/main/java/neqsim/thermo/component/ComponentInterface.java @@ -642,8 +642,17 @@ public void createComponent(String component_name, double moles, double molesInP * addMolesChemReac. *

* - * @param dn a double - * @param totdn a double + * @param dn Number of moles to add to phase and total + */ + public void addMolesChemReac(double dn); + + /** + *

+ * addMolesChemReac. + *

+ * + * @param dn Number of moles to add to phase + * @param totdn Number of moles to add total */ public void addMolesChemReac(double dn, double totdn); @@ -879,15 +888,6 @@ public void Finit(PhaseInterface phase, double temperature, double pressure, */ public int getComponentNumber(); - /** - *

- * addMolesChemReac. - *

- * - * @param dn a double - */ - public void addMolesChemReac(double dn); - /** *

* getHeatOfVapourization. diff --git a/src/main/java/neqsim/thermo/phase/Phase.java b/src/main/java/neqsim/thermo/phase/Phase.java index fa0f14b681..a5ccd29619 100644 --- a/src/main/java/neqsim/thermo/phase/Phase.java +++ b/src/main/java/neqsim/thermo/phase/Phase.java @@ -156,14 +156,14 @@ public void addMolesChemReac(int component, double dn, double totdn) { String msg = "Negative number of moles in phase."; logger.error(msg); neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(msg); + new neqsim.util.exception.InvalidInputException(this, "addMolesChemReac", msg); throw new RuntimeException(e); } if (getComponent(component).getNumberOfMolesInPhase() < 0.0) { String msg = "Negative number of moles of component " + component; logger.error(msg); neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(msg); + new neqsim.util.exception.InvalidInputException(this, "addMolesChemReac", msg); throw new RuntimeException(e); } } @@ -384,8 +384,9 @@ public void init() { public void init(double totalNumberOfMoles, int numberOfComponents, int type, int phase, double beta) { if (totalNumberOfMoles <= 0) { - throw new RuntimeException(new neqsim.util.exception.InvalidInputException( - "Phase:init - Input totalNumberOfMoles must be larger than zero.")); + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "init", "totalNumberOfMoles", + "must be larger than zero.")); } this.beta = beta; diff --git a/src/main/java/neqsim/thermo/phase/PhaseBWRSEos.java b/src/main/java/neqsim/thermo/phase/PhaseBWRSEos.java index 3abbe48343..762ea1aed1 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseBWRSEos.java +++ b/src/main/java/neqsim/thermo/phase/PhaseBWRSEos.java @@ -548,6 +548,7 @@ public double molarVolume2(double pressure, double temperature, double A, double double Btemp = getB(); setMolarVolume(1.0 / BonV * Btemp);// numberOfMolesInPhase; int iterations = 0; + int maxIterations = 10000; double guesPres = pressure; double guesPresdV = 0.0; do { @@ -559,13 +560,15 @@ public double molarVolume2(double pressure, double temperature, double A, double setMolarVolume(getMolarVolume() - 1.0 / (guesPresdV * getNumberOfMolesInPhase()) * (guesPres - pressure) / 50.0); Z = pressure * getMolarVolume() / (R * temperature); - } while (Math.abs((guesPres - pressure) / pressure) > 1.0e-10 && iterations < 10000); + } while (Math.abs((guesPres - pressure) / pressure) > 1.0e-10 + && iterations < maxIterations); // System.out.println("gues pres " + guesPres); - if (iterations >= 10000) { - throw new neqsim.util.exception.TooManyIterationsException(); + if (iterations >= maxIterations) { + throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume2", + maxIterations); } if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume2", "Molar Volume"); } // System.out.println("Z: " + Z + " "+" itert: " +iterations); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " diff --git a/src/main/java/neqsim/thermo/phase/PhaseCSPsrkEos.java b/src/main/java/neqsim/thermo/phase/PhaseCSPsrkEos.java index 1d51cd3faa..78e5feb34b 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseCSPsrkEos.java +++ b/src/main/java/neqsim/thermo/phase/PhaseCSPsrkEos.java @@ -232,7 +232,7 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); int iterations = 0; - + int maxIterations = 1000; do { iterations++; BonVold = BonV; @@ -277,7 +277,7 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); Z = pressure * getMolarVolume() / (R * temperature); - } while (Math.abs(BonV - BonVold) > 1.0e-10 && iterations < 1000); + } while (Math.abs(BonV - BonVold) > 1.0e-10 && iterations < maxIterations); // molarVolume = 1.0/BonV*Btemp/numberOfMolesInPhase; // Z = pressure*molarVolume/(R*temperature); // System.out.println("BonV: " + BonV + " " + h + " " +dh + " B " + Btemp + " D @@ -285,11 +285,12 @@ public double molarVolume(double pressure, double temperature, double A, double // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); - if (iterations >= 1000) { - throw new neqsim.util.exception.TooManyIterationsException(); + if (iterations >= maxIterations) { + throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume", + maxIterations); } if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); } // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" diff --git a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java index 96ddae4ccb..3060764b45 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java +++ b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java @@ -1002,7 +1002,7 @@ public double molarVolume2(double pressure, double temperature, double A, double // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume2", "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); @@ -1138,7 +1138,7 @@ else if (BonV >= 1.0) { // " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); @@ -1280,7 +1280,8 @@ public double molarVolumeChangePhase(double pressure, double temperature, double // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh + " B // " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolumeChangePhase", + "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); diff --git a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPAOld.java b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPAOld.java index d6473f2bdd..e8378dc829 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPAOld.java +++ b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPAOld.java @@ -2,7 +2,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - import neqsim.thermo.component.ComponentCPAInterface; import neqsim.thermo.component.ComponentElectrolyteCPA; import neqsim.thermo.component.ComponentEosInterface; @@ -622,7 +621,7 @@ public double molarVolume3(double pressure, double temperature, double A, double // (-pressure+R*temperature/molarVolume-R*temperature*dFdV()) + " firstterm " + // (R*temperature/molarVolume) + " second " + R*temperature*dFdV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume3", "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); @@ -655,6 +654,7 @@ public double molarVolume(double pressure, double temperature, double A, double } setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); int iterations = 0; + int maxIterations = 1000; double oldVolume = getVolume(); do { this.volInit(); @@ -713,7 +713,7 @@ public double molarVolume(double pressure, double temperature, double A, double Z = pressure * getMolarVolume() / (R * temperature); // System.out.println("Z" + Z); - } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < 1001); + } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < maxIterations); // System.out.println("Z" + Z + " iterations " + iterations + " h " + h); // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); // if(iterations>=100) throw new util.exception.TooManyIterationsException(); @@ -722,7 +722,7 @@ public double molarVolume(double pressure, double temperature, double A, double // firstterm " + (R*temperature/molarVolume) + " second " + // R*temperature*dFdV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); diff --git a/src/main/java/neqsim/thermo/phase/PhaseEos.java b/src/main/java/neqsim/thermo/phase/PhaseEos.java index 2da4809b0f..b0a228cf7b 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseEos.java +++ b/src/main/java/neqsim/thermo/phase/PhaseEos.java @@ -212,6 +212,7 @@ public double molarVolume2(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); int iterations = 0; + int maxIterations = 1000; do { iterations++; @@ -257,7 +258,7 @@ public double molarVolume2(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); Z = pressure * getMolarVolume() / (R * temperature); - } while (Math.abs(BonV - BonVold) > 1.0e-9 && iterations < 1000); + } while (Math.abs(BonV - BonVold) > 1.0e-9 && iterations < maxIterations); // molarVolume = 1.0/BonV*Btemp/numberOfMolesInPhase; // Z = pressure*molarVolume/(R*temperature); // logger.info("BonV: " + BonV + " " + h + " " +dh + " B " + Btemp + " D " + @@ -265,11 +266,12 @@ public double molarVolume2(double pressure, double temperature, double A, double // logger.info("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh + // " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + // fVV()); - if (iterations >= 1000) { - throw new neqsim.util.exception.TooManyIterationsException(); + if (iterations >= maxIterations) { + throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume2", + maxIterations); } if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume2", "Molar volume"); // logger.info("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh + // " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + // fVV()); @@ -293,7 +295,6 @@ public double molarVolume(double pressure, double temperature, double A, double } double BonVold = BonV, Btemp = getB(), h, dh, dhh, d1, d2, BonV2; - int iterations = 0; if (Btemp < 0) { logger.info("b negative in volume calc"); @@ -301,7 +302,8 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); boolean changeFase = false; double error = 1.0, errorOld = 1.0e10; - + int iterations = 0; + int maxIterations = 300; do { errorOld = error; iterations++; @@ -354,18 +356,19 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); Z = pressure * getMolarVolume() / (R * temperature); // logger.info("Math.abs((BonV - BonVold)) " + Math.abs((BonV - BonVold))); - } while (Math.abs((BonV - BonVold) / BonVold) > 1.0e-10 && iterations < 300); + } while (Math.abs((BonV - BonVold) / BonVold) > 1.0e-10 && iterations < maxIterations); // logger.info("pressure " + Z*R*temperature/molarVolume); // logger.info("error in volume " + // (-pressure+R*temperature/molarVolume-R*temperature*dFdV()) + " firstterm " + // (R*temperature/molarVolume) + " second " + R*temperature*dFdV()); - if (iterations >= 300) { - throw new neqsim.util.exception.TooManyIterationsException(); + if (iterations >= maxIterations) { + throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume", + maxIterations); } if (Double.isNaN(getMolarVolume())) { // A = calcA(this, temperature, pressure, numberOfComponents); // molarVolume(pressure, temperature, A, B, phase); - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); // logger.info("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh + // " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + // fVV()); diff --git a/src/main/java/neqsim/thermo/phase/PhaseGE.java b/src/main/java/neqsim/thermo/phase/PhaseGE.java index 59d941fa65..6fe67dca43 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseGE.java +++ b/src/main/java/neqsim/thermo/phase/PhaseGE.java @@ -56,8 +56,8 @@ public PhaseGE() { public void init(double temperature, double pressure, double totalNumberOfMoles, double beta, int numberOfComponents, int type, int phase) { if (totalNumberOfMoles <= 0) { - throw new RuntimeException(new neqsim.util.exception.InvalidInputException( - "PhaseGE", "init", "Input totalNumberOfMoles must be larger than zero.")); + new neqsim.util.exception.InvalidInputException(this, "init", "totalNumberOfMoles", + "must be larger than zero."); } for (int i = 0; i < numberOfComponents; i++) { componentArray[i].init(temperature, pressure, totalNumberOfMoles, beta, type); diff --git a/src/main/java/neqsim/thermo/phase/PhaseInterface.java b/src/main/java/neqsim/thermo/phase/PhaseInterface.java index f005f78090..27ae67b3ea 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseInterface.java +++ b/src/main/java/neqsim/thermo/phase/PhaseInterface.java @@ -596,14 +596,14 @@ public void removeComponent(String componentName, double moles, double molesInPh public double getPureComponentFugacity(int k, boolean pure); /** - *

- * addMolesChemReac. - *

- * - * @param component a int - * @param dn a double - * @param totdn a double - */ + *

+ * addMolesChemReac. + *

+ * + * @param component Component number + * @param dn a double + * @param totdn a double + */ public void addMolesChemReac(int component, double dn, double totdn); /** diff --git a/src/main/java/neqsim/thermo/phase/PhaseModifiedFurstElectrolyteEos.java b/src/main/java/neqsim/thermo/phase/PhaseModifiedFurstElectrolyteEos.java index db99c3791b..a64e76b0c7 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseModifiedFurstElectrolyteEos.java +++ b/src/main/java/neqsim/thermo/phase/PhaseModifiedFurstElectrolyteEos.java @@ -503,7 +503,7 @@ public double molarVolume(double pressure, double temperature, double A, double } setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); int iterations = 0; - + int maxIterations = 1000; do { iterations++; this.volInit(); @@ -543,13 +543,14 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); Z = pressure * getMolarVolume() / (R * temperature); - } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < 1000); + } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < maxIterations); this.volInit(); - if (iterations >= 10000) { - throw new neqsim.util.exception.TooManyIterationsException(); + if (iterations >= maxIterations) { + throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume", + maxIterations); } if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); } // if(phaseType==0) System.out.println("density " + getDensity());//"BonV: " + diff --git a/src/main/java/neqsim/thermo/phase/PhaseModifiedFurstElectrolyteEosMod2004.java b/src/main/java/neqsim/thermo/phase/PhaseModifiedFurstElectrolyteEosMod2004.java index 35f17c5a9b..93ea81dc92 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseModifiedFurstElectrolyteEosMod2004.java +++ b/src/main/java/neqsim/thermo/phase/PhaseModifiedFurstElectrolyteEosMod2004.java @@ -502,7 +502,7 @@ public double molarVolume(double pressure, double temperature, double A, double } setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); int iterations = 0; - + int maxIterations = 1000; do { iterations++; this.volInit(); @@ -542,13 +542,14 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); Z = pressure * getMolarVolume() / (R * temperature); - } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < 1000); + } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < maxIterations); this.volInit(); - if (iterations >= 10000) { - throw new neqsim.util.exception.TooManyIterationsException(); + if (iterations >= maxIterations) { + throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume", + maxIterations); } if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); } // if(phaseType==0) System.out.println("density " + getDensity());//"BonV: " + diff --git a/src/main/java/neqsim/thermo/phase/PhasePCSAFT.java b/src/main/java/neqsim/thermo/phase/PhasePCSAFT.java index 2c9d550f21..ce3dbf0cd6 100644 --- a/src/main/java/neqsim/thermo/phase/PhasePCSAFT.java +++ b/src/main/java/neqsim/thermo/phase/PhasePCSAFT.java @@ -1167,7 +1167,7 @@ public double molarVolume(double pressure, double temperature, double A, double } setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); int iterations = 0; - // System.out.println("volume " + getVolume()); + int maxIterations = 2000; do { iterations++; this.volInit(); @@ -1188,7 +1188,7 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); Z = pressure * getMolarVolume() / (R * temperature); // System.out.println("Z " + Z); - } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < 2000); + } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < maxIterations); // System.out.println("error BonV " + Math.abs((BonV-BonVold)/BonV)); // System.out.println("iterations " + iterations); if (BonV < 0) { @@ -1197,11 +1197,12 @@ public double molarVolume(double pressure, double temperature, double A, double Z = pressure * getMolarVolume() / (R * temperature); } - if (iterations >= 2000) { - throw new neqsim.util.exception.TooManyIterationsException(); + if (iterations >= maxIterations) { + throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume", + maxIterations); } if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); } // if(phaseType==0) System.out.println("density " + getDensity());//"BonV: " + diff --git a/src/main/java/neqsim/thermo/phase/PhasePCSAFTa.java b/src/main/java/neqsim/thermo/phase/PhasePCSAFTa.java index 320a2e5ed0..7241fd06ce 100644 --- a/src/main/java/neqsim/thermo/phase/PhasePCSAFTa.java +++ b/src/main/java/neqsim/thermo/phase/PhasePCSAFTa.java @@ -393,6 +393,7 @@ public double molarVolume(double pressure, double temperature, double A, double } setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); int iterations = 0; + int maxIterations = 1000; // System.out.println("volume " + getVolume()); do { iterations++; @@ -434,7 +435,7 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); Z = pressure * getMolarVolume() / (R * temperature); // System.out.println("Z " + Z); - } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < 1000); + } while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < maxIterations); // System.out.println("error BonV " + Math.abs((BonV-BonVold)/BonV)); // System.out.println("iterations " + iterations); if (BonV < 0) { @@ -442,19 +443,21 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); Z = pressure * getMolarVolume() / (R * temperature); } - if (iterations >= 10000) { - throw new neqsim.util.exception.TooManyIterationsException(); + if (iterations >= maxIterations) { + throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume", + maxIterations); } if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); // if(phaseType==0) - // System.out.println("density " + - // getDensity());//"BonV: " + BonV + " - // "+" itert: " + - // iterations +" " + " phase " + - // phaseType+ " " + h + " - // " +dh + " B " + Btemp + " D " + - // Dtemp + " gv" + gV() - // + " fv " + fv() + " fvv" + fVV()); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); + // if(phaseType==0) + // System.out.println("density " + + // getDensity());//"BonV: " + BonV + " + // "+" itert: " + + // iterations +" " + " phase " + + // phaseType+ " " + h + + // " +dh + " B " + Btemp + " D " + + // Dtemp + " gv" + gV() + // + " fv " + fv() + " fvv" + fVV()); } return getMolarVolume(); } diff --git a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java index 7c7958b8ec..f70d0002d2 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java +++ b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java @@ -6,7 +6,6 @@ import org.ejml.dense.row.CommonOps_DDRM; import org.ejml.dense.row.NormOps_DDRM; import org.ejml.simple.SimpleMatrix; - // import org.ejml.data.DenseMatrix64F; import neqsim.thermo.component.ComponentCPAInterface; import neqsim.thermo.component.ComponentSrkCPA; @@ -680,7 +679,7 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); int iterations = 0; - + int maxIterations = 300; do { iterations++; gcpa = calc_g(); @@ -765,7 +764,7 @@ public double molarVolume(double pressure, double temperature, double A, double setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); Z = pressure * getMolarVolume() / (R * temperature); } while ((Math.abs((BonV - BonVold) / BonV) > 1.0e-10 || Math.abs(h) > 1e-12) - && iterations < 100); + && iterations < maxIterations); // System.out.println("h failed " + h + " Z" + Z + " iterations " + iterations + // " BonV " + BonV); @@ -787,7 +786,7 @@ public double molarVolume(double pressure, double temperature, double A, double // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); @@ -1312,7 +1311,8 @@ public double molarVolumeChangePhase(double pressure, double temperature, double // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh + " B // " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolumeChangePhase", + "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); @@ -2109,7 +2109,7 @@ public double molarVolumeOld(double pressure, double temperature, double A, doub // " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolumeOld", "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); diff --git a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java index a4f969337d..6b9640bcc3 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java +++ b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java @@ -5,7 +5,6 @@ import org.ejml.data.DMatrixRMaj; import org.ejml.dense.row.CommonOps_DDRM; import org.ejml.dense.row.NormOps_DDRM; - // import org.ejml.simple.SimpleMatrix; // import org.ejml.data.DenseMatrix64F; import neqsim.thermo.component.ComponentCPAInterface; @@ -1172,7 +1171,7 @@ public double molarVolume(double pressure, double temperature, double A, double // " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); @@ -1313,7 +1312,8 @@ public double molarVolumeChangePhase(double pressure, double temperature, double // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh + " B // " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolumeChangePhase", + "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); diff --git a/src/main/java/neqsim/thermo/phase/PhaseSrkCPAojAlgo.java b/src/main/java/neqsim/thermo/phase/PhaseSrkCPAojAlgo.java index 0e58a2cd58..9a1df4731c 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseSrkCPAojAlgo.java +++ b/src/main/java/neqsim/thermo/phase/PhaseSrkCPAojAlgo.java @@ -11,7 +11,6 @@ import org.ojalgo.matrix.Primitive64Matrix.Factory; import org.ojalgo.matrix.store.MatrixStore; import org.ojalgo.matrix.store.SparseStore; - import neqsim.thermo.component.ComponentCPAInterface; import neqsim.thermo.component.ComponentSrkCPA; import neqsim.thermo.mixingRule.CPAMixing; @@ -1107,7 +1106,7 @@ public double molarVolume(double pressure, double temperature, double A, double // " +dh + " B " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); @@ -1248,7 +1247,8 @@ public double molarVolumeChangePhase(double pressure, double temperature, double // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); if (Double.isNaN(getMolarVolume())) { - throw new neqsim.util.exception.IsNaNException(); + throw new neqsim.util.exception.IsNaNException(this, "molarVolumeChangePhase", + "Molar volume"); // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" // + fVV()); diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index f4d92a7f5f..a2083d5dfe 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -130,12 +130,22 @@ public SystemThermo() { */ public SystemThermo(double T, double P) { this(); - if (T < 0.0 || P < 0.0) { - String msg = "Negative input temperature or pressure"; - logger.error(msg); - neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(msg); - throw new RuntimeException(e); + if (T < 0.0) { + String msg = "Negative input temperature"; + logger.error(msg); + neqsim.util.exception.InvalidInputException e = + new neqsim.util.exception.InvalidInputException(this.getClass().getSimpleName(), + "SystemThermo", "T", "is negative"); + throw new RuntimeException(e); + } + + if (P < 0.0) { + String msg = "Negative input pressure"; + logger.error(msg); + neqsim.util.exception.InvalidInputException e = + new neqsim.util.exception.InvalidInputException(this.getClass().getSimpleName(), + "SystemThermo", "P", "is negative"); + throw new RuntimeException(e); } beta[0] = 1.0; beta[1] = 1.0; @@ -1431,6 +1441,7 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, } iterations = 0; + int maxIterations = 300; // System.out.println("gtest: " + gtest); double step = 1.0; do { @@ -1503,7 +1514,7 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, } step = gbeta / deriv; // System.out.println("step : " + step); - } while (((Math.abs(step)) >= 1.0e-10 && iterations < 300));// && + } while (((Math.abs(step)) >= 1.0e-10 && iterations < maxIterations));// && // (Math.abs(nybeta)-Math.abs(maxBeta))>0.1); // System.out.println("beta: " + nybeta + " iterations: " + iterations); @@ -1521,15 +1532,16 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, beta[0] = nybeta; beta[1] = 1.0 - nybeta; - if (iterations >= 300) { - throw new neqsim.util.exception.TooManyIterationsException(); + if (iterations >= maxIterations) { + throw new neqsim.util.exception.TooManyIterationsException(this, "calcBeta", + maxIterations); } if (Double.isNaN(beta[1])) { - for (i = 0; i < numberOfComponents; i++) { - // System.out.println("K " + compArray[i].getK()); - // System.out.println("z " + compArray[i].getz()); - } - throw new neqsim.util.exception.IsNaNException(); + /* + * for (i = 0; i < numberOfComponents; i++) { System.out.println("K " + + * compArray[i].getK()); System.out.println("z " + compArray[i].getz()); } + */ + throw new neqsim.util.exception.IsNaNException(this, "calcBeta", "beta"); } return beta[0]; } diff --git a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java index ec570e4b82..cf0f8773a7 100644 --- a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java +++ b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java @@ -684,8 +684,9 @@ public void bubblePointTemperatureFlash() throws Exception { constantDutyFlashInterface operation = new bubblePointTemperatureNoDer(system); operation.run(); if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException( - "error in bubblePointTemperatureFlash() - could not find solution - possible no bubble point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "bubblePointTemperatureFlash", + "Could not find solution - possible no bubble point exists"); } } @@ -700,8 +701,9 @@ public void freezingPointTemperatureFlash() throws Exception { operation = new freezingPointTemperatureFlash(system); getOperation().run(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in freezingPointTemperatureFlash() - could not find solution - possible no freezing point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "freezingPointTemperatureFlash", + "Could not find solution - possible no freezing point exists"); } } @@ -717,8 +719,9 @@ public void freezingPointTemperatureFlash(String phaseName) throws Exception { operation = new freezingPointTemperatureFlash(system); getOperation().run(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in freezingPointTemperatureFlash() - could not find solution - possible no freezing point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "freezingPointTemperatureFlash", + "Could not find solution - possible no freezing point exists"); } } @@ -733,8 +736,9 @@ public void waterDewPointTemperatureFlash() throws Exception { operation = new waterDewPointTemperatureFlash(system); getOperation().run(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in freezingPointTemperatureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "waterDewPointTemperatureFlash", + "Could not find solution - possible no dew point exists"); } } @@ -784,8 +788,9 @@ public void waterPrecipitationTemperature() throws Exception { // TPflash(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in freezingPointTemperatureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "waterPrecipitationTemperature", + "Could not find solution - possible no dew point exists"); } } @@ -801,8 +806,8 @@ public void calcSaltSaturation(String saltName) throws Exception { operation = new calcSaltSatauration(system, saltName); getOperation().run(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in calcSaltSaturation() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "calcSaltSaturation", "Could not find solution - possible no dew point exists"); } } @@ -819,8 +824,8 @@ public void checkScalePotential(int phaseNumber) throws Exception { getOperation().run(); resultTable = getOperation().getResultTable(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in checkScalePotential() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "checkScalePotential", "Could not find solution - possible no dew point exists"); } } @@ -840,8 +845,8 @@ public void addIonToScaleSaturation(int phaseNumber, String scaleSaltName, getOperation().run(); resultTable = getOperation().getResultTable(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in checkScalePotential() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "addIonToScaleSaturation", "Could not find solution - possible no dew point exists"); } } @@ -856,8 +861,8 @@ public void hydrateFormationPressure() throws Exception { operation = new HydrateFormationPressureFlash(system); getOperation().run(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in hydrateFormationPressure() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "hydrateFormationPressure", "Could not find solution - possible no dew point exists"); } } @@ -872,8 +877,8 @@ public void calcWAT() throws Exception { operation = new WATcalc(system); getOperation().run(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in WAT() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), "calcWAT", + "Could not find solution - possible no dew point exists"); } } @@ -931,7 +936,8 @@ public void calcSolidComlexTemperature() throws Exception { operation = new SolidComplexTemperatureCalc(system); getOperation().run(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "calcSolidComlexTemperature", "error in WAT() - could not find solution - possible no dew point exists"); } } @@ -951,7 +957,8 @@ public void calcSolidComlexTemperature(String comp1, String comp2) throws Except } getOperation().run(); if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "calcSolidComlexTemperature", "error in WAT() - could not find solution - possible no dew point exists"); } } @@ -1221,8 +1228,9 @@ public void hydrateFormationTemperature(int structure) throws Exception { } if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException( - "error in freezingPointTemperatureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "hydrateFormationTemperature", + "Could not find solution - possible no dew point exists"); } } @@ -1257,8 +1265,8 @@ public void bubblePointPressureFlash() throws Exception { system.setBeta(0, 1e-10); operation.run(); if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException( - "error in bubblePointPressureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); } } @@ -1283,8 +1291,9 @@ public void constantPhaseFractionPressureFlash(double fraction) throws Exception system.setBeta(0, fraction); operation.run(); if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException( - "error in bubblePointPressureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "constantPhaseFractionPressureFlash", + "Could not find solution - possible no dew point exists"); } } @@ -1309,8 +1318,9 @@ public void constantPhaseFractionTemperatureFlash(double fraction) throws Except system.setBeta(0, fraction); operation.run(); if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException( - "error in bubblePointPressureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "constantPhaseFractionTemperatureFlash", + "Could not find solution - possible no dew point exists"); } } @@ -1331,8 +1341,8 @@ public void bubblePointPressureFlash(boolean derivatives) throws Exception { } operation.run(); if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException( - "error in bubblePointPressureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); } } @@ -1356,9 +1366,8 @@ public void dewPointMach(String componentName, String specification, double spec dn = system.getNumberOfMoles() / 1.0e6; system.addComponent(componentName, dn); } else { - throw new neqsim.util.exception.IsNaNException( - "error in dewPointMach(String componentName) - specified component is not precent in mixture: " - + componentName); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointMach", "Specified component is not present in mixture: " + componentName); } double newTemperature = system.getTemperature(), oldTemperature = newTemperature; int iterations = 0; @@ -1387,8 +1396,8 @@ public void dewPointMach(String componentName, String specification, double spec } if (Double.isNaN(system.getPressure())) { - throw new neqsim.util.exception.IsNaNException( - "error in bubblePointPressureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointMach", "Could not find solution - possible no dew point exists"); } } @@ -1404,8 +1413,8 @@ public void dewPointTemperatureFlash() throws Exception { system); operation.run(); if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException( - "error in dewPointTemperatureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); } } @@ -1425,8 +1434,8 @@ public void dewPointTemperatureFlash(boolean derivatives) throws Exception { } operation.run(); if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException( - "error in dewPointTemperatureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); } } @@ -1443,8 +1452,8 @@ public void dewPointPressureFlashHC() throws Exception { constantDutyFlashInterface operation = new HCdewPointPressureFlash(system); operation.run(); if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException( - "error in dewPointPressureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointPressureFlashHC", "Could not find solution - possible no dew point exists"); } // } } @@ -1462,8 +1471,8 @@ public void dewPointPressureFlash() throws Exception { constantDutyFlashInterface operation = new dewPointPressureFlash(system); operation.run(); if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException( - "error in dewPointPressureFlash() - could not find solution - possible no dew point exists"); + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointPressureFlash", "Could not find solution - possible no dew point exists"); } // } } @@ -2008,8 +2017,7 @@ public CalculationResult propertyFlash(List Spec1, List Spec2, i this.PSflash(Sp2, "J/molK"); } else { throw new RuntimeException(new neqsim.util.exception.InvalidInputException( - "ThermodynamicOperations", "propertyFlash", - "Input mode must be 1, 2 or 3")); + "ThermodynamicOperations", "propertyFlash", "mode", "must be 1, 2 or 3")); } this.system.init(2); this.system.initPhysicalProperties(); diff --git a/src/main/java/neqsim/util/exception/InvalidInputException.java b/src/main/java/neqsim/util/exception/InvalidInputException.java index 60ec3bcf70..184ee56287 100644 --- a/src/main/java/neqsim/util/exception/InvalidInputException.java +++ b/src/main/java/neqsim/util/exception/InvalidInputException.java @@ -11,30 +11,60 @@ public class InvalidInputException extends neqsim.util.exception.ThermoException { private static final long serialVersionUID = 1000; - /** - *

- * Constructor for InvalidInputException. - *

- */ - public InvalidInputException() {} - /** * Constructs an InvalidInputException with the specified detail message. * * @param msg the detail message. */ + @Deprecated public InvalidInputException(String msg) { super(msg); } + /** + * Constructs an InvalidInputException with a default message. + * + * @param className Class that exception is raised from + * @param methodName Method that exception is raised from + * @param inputName Name of invalid input + */ + public InvalidInputException(String className, String methodName, String inputName) { + super(className, methodName, "Input " + inputName + " was invalid."); + } + /** * Constructs an InvalidInputException with the specified detail message. * * @param className Class that exception is raised from * @param methodName Method that exception is raised from - * @param msg the detail message. + * @param inputName Name of invalid input + * @param msg error message detailing input problem + */ + public InvalidInputException(String className, String methodName, String inputName, + String msg) { + super(className, methodName, "Input " + inputName + " " + msg); + } + + /** + * Constructs an InvalidInputException with a default message. + * + * @param obj Object that exception is raised from + * @param methodName Method that exception is raised from + * @param inputName Name of invalid input + */ + public InvalidInputException(Object obj, String methodName, String inputName) { + this(obj.getClass().getSimpleName(), methodName, inputName); + } + + /** + * Constructs an InvalidInputException with a default message. + * + * @param obj Object that exception is raised from + * @param methodName Method that exception is raised from + * @param inputName Name of invalid input + * @param msg error message detailing input problem */ - public InvalidInputException(String className, String methodName, String msg) { - super(className + ":" + methodName + " - " + msg); + public InvalidInputException(Object obj, String methodName, String inputName, String msg) { + this(obj.getClass().getSimpleName(), methodName, inputName, msg); } } diff --git a/src/main/java/neqsim/util/exception/IsNaNException.java b/src/main/java/neqsim/util/exception/IsNaNException.java index 77005c96b7..7c018ef911 100644 --- a/src/main/java/neqsim/util/exception/IsNaNException.java +++ b/src/main/java/neqsim/util/exception/IsNaNException.java @@ -11,19 +11,35 @@ public class IsNaNException extends neqsim.util.exception.ThermoException { private static final long serialVersionUID = 1000; - /** - *

- * Constructor for IsNaNException. - *

- */ - public IsNaNException() {} - /** * Constructs an IsNaNException with the specified detail message. * * @param msg the detail message. */ + @Deprecated public IsNaNException(String msg) { super(msg); } + + /** + * Constructs an IsNaNException with a detailed message. + * + * @param className Class that exception is raised from + * @param methodName Method that exception is raised from + * @param msg detailed message + */ + public IsNaNException(String className, String methodName, String msg) { + super(className, methodName, "Variable " + msg); + } + + /** + * Constructs an IsNaNException with a default detail message. + * + * @param obj object that exception is raised from + * @param methodName Method that exception is raised from + * @param param the parameter that is NaN + */ + public IsNaNException(Object obj, String methodName, String param) { + this(obj.getClass().getSimpleName(), methodName, param + " is NaN"); + } } diff --git a/src/main/java/neqsim/util/exception/NotInitializedException.java b/src/main/java/neqsim/util/exception/NotInitializedException.java index 24e6489232..6acc743a5c 100644 --- a/src/main/java/neqsim/util/exception/NotInitializedException.java +++ b/src/main/java/neqsim/util/exception/NotInitializedException.java @@ -12,31 +12,51 @@ public class NotInitializedException extends neqsim.util.exception.ThermoExcepti private static final long serialVersionUID = 1000; /** - *

- * Constructor for NotInitializedException. - *

+ * Constructs an NotInitializedException with the specified detail message. + * + * @param className Class exception is raised from + * @param methodName Method exception is raised from + * @param msg Detailed error message */ - public NotInitializedException() { + public NotInitializedException(String className, String methodName, String msg) { + super(className, methodName, msg); } /** - * Constructs an NotInitializedException with the specified detail - * message. + * Constructs an NotInitializedException with default detail message. * - * @param msg the detail message. + * @param className Class exception is raised from + * @param methodName Method exception is raised from + * @param parameter Parameter not initialized + * @param initMethod Method to call to initialize parameter */ - public NotInitializedException(String msg) { - super(msg); + public NotInitializedException(String className, String methodName, String parameter, + String initMethod) { + this(className, methodName, + "Parameter " + parameter + " not initialized. Method " + initMethod + " must be called."); } /** - * Constructs an NotInitializedException with default detail - * message. - * - * @param parameter - * @param initMethod + * Constructs an NotInitializedException with the specified detail message. + * + * @param obj Object exception is raised from + * @param methodName Method exception is raised from + * @param msg Detailed error message + */ + public NotInitializedException(Object obj, String methodName, String msg) { + this(obj.getClass().getSimpleName(), methodName, msg); + } + + /** + * Constructs an NotInitializedException with default detail message. + * + * @param obj Object exception is raised from + * @param methodName Method exception is raised from + * @param parameter Parameter not initialized + * @param initMethod Method to call to initialize parameter */ - public NotInitializedException(String parameter, String initMethod) { - this("Parameter " + parameter + " not initialized. Method " + initMethod + " must be called."); + public NotInitializedException(Object obj, String methodName, String parameter, + String initMethod) { + this(obj.getClass().getSimpleName(), methodName, parameter, initMethod); } } diff --git a/src/main/java/neqsim/util/exception/ThermoException.java b/src/main/java/neqsim/util/exception/ThermoException.java index f33e581c0c..5c86bdf164 100644 --- a/src/main/java/neqsim/util/exception/ThermoException.java +++ b/src/main/java/neqsim/util/exception/ThermoException.java @@ -16,13 +16,6 @@ public class ThermoException extends java.lang.Exception { private static final long serialVersionUID = 1000; - /** - *

- * Constructor for ThermoException. - *

- */ - public ThermoException() {} - /** * Constructs an ThermoException with the specified detail message. * @@ -31,4 +24,15 @@ public ThermoException() {} public ThermoException(String msg) { super(msg); } + + /** + * Constructs an ThermoException with the specified detail message. + * + * @param className Class that exception is raised from + * @param methodName Method that exception is raised from + * @param msg specific error message + */ + public ThermoException(String className, String methodName, String msg) { + super(className + ":" + methodName + " - " + msg); + } } diff --git a/src/main/java/neqsim/util/exception/TooManyIterationsException.java b/src/main/java/neqsim/util/exception/TooManyIterationsException.java index d3558a2f88..97191e0374 100644 --- a/src/main/java/neqsim/util/exception/TooManyIterationsException.java +++ b/src/main/java/neqsim/util/exception/TooManyIterationsException.java @@ -12,18 +12,24 @@ public class TooManyIterationsException extends neqsim.util.exception.ThermoExce private static final long serialVersionUID = 1000; /** - *

- * Constructor for TooManyIterationsException. - *

+ * Constructs a TooManyIterationsException with a standard error message. + * + * @param className Class that exception is raised from + * @param methodName Method that exception is raised from + * @param maxIterations the maximum number of iterations */ - public TooManyIterationsException() {} + public TooManyIterationsException(String className, String methodName, long maxIterations) { + super(className, methodName, "Exceeded maximum iterations " + maxIterations); + } /** - * Constructs an TooManyIterationsException with the specified detail message. - * - * @param msg the detail message. + * Constructs a TooManyIterationsException with a standard error message. + * + * @param obj object that exception is raised from + * @param methodName method that exception is raised from + * @param maxIterations the maximum number of iterations */ - public TooManyIterationsException(String msg) { - super(msg); + public TooManyIterationsException(Object obj, String methodName, long maxIterations) { + this(obj.getClass().getSimpleName(), methodName, maxIterations); } } diff --git a/src/test/java/neqsim/processSimulation/processEquipment/stream/StreamTest.java b/src/test/java/neqsim/processSimulation/processEquipment/stream/StreamTest.java index 32640b44fd..193d8604b4 100644 --- a/src/test/java/neqsim/processSimulation/processEquipment/stream/StreamTest.java +++ b/src/test/java/neqsim/processSimulation/processEquipment/stream/StreamTest.java @@ -51,7 +51,7 @@ public void testNoFlow() { testSystem.initProperties(); }); Assertions.assertEquals( - "neqsim.util.exception.InvalidInputException: Phase:init - Input totalNumberOfMoles must be larger than zero.", + "neqsim.util.exception.InvalidInputException: PhaseSrkEos:init - Input totalNumberOfMoles must be larger than zero.", thrown.getMessage()); } }