Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create neqsim.exception constructors with standardized error message #365

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import neqsim.thermo.system.SystemInterface;

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/neqsim/thermo/component/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/neqsim/thermo/component/ComponentInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,17 @@ public void createComponent(String component_name, double moles, double molesInP
* addMolesChemReac.
* </p>
*
* @param dn a double
* @param totdn a double
* @param dn Number of moles to add to phase and total
*/
public void addMolesChemReac(double dn);

/**
* <p>
* addMolesChemReac.
* </p>
*
* @param dn Number of moles to add to phase
* @param totdn Number of moles to add total
*/
public void addMolesChemReac(double dn, double totdn);

Expand Down Expand Up @@ -879,15 +888,6 @@ public void Finit(PhaseInterface phase, double temperature, double pressure,
*/
public int getComponentNumber();

/**
* <p>
* addMolesChemReac.
* </p>
*
* @param dn a double
*/
public void addMolesChemReac(double dn);

/**
* <p>
* getHeatOfVapourization.
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/neqsim/thermo/phase/Phase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/neqsim/thermo/phase/PhaseBWRSEos.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 + "
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/neqsim/thermo/phase/PhaseCSPsrkEos.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -277,19 +277,20 @@ 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
// " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV());
// 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"
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/neqsim/thermo/phase/PhaseEos.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -257,19 +258,20 @@ 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 " +
// Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV());
// 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());
Expand All @@ -293,15 +295,15 @@ 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");
}
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++;
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/neqsim/thermo/phase/PhaseGE.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/neqsim/thermo/phase/PhaseInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,14 @@ public void removeComponent(String componentName, double moles, double molesInPh
public double getPureComponentFugacity(int k, boolean pure);

/**
* <p>
* addMolesChemReac.
* </p>
*
* @param component a int
* @param dn a double
* @param totdn a double
*/
* <p>
* addMolesChemReac.
* </p>
*
* @param component Component number
* @param dn a double
* @param totdn a double
*/
public void addMolesChemReac(int component, double dn, double totdn);

/**
Expand Down
Loading