Skip to content

Commit 3fd10fb

Browse files
authored
feat: create neqsim.exception constructors with standardized error message (#365)
refact: use new neqsim.exception constructors
1 parent b2a1378 commit 3fd10fb

27 files changed

+324
-210
lines changed

src/main/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartAlternativeMapLookup.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ public CompressorCurve getCurveAtRefSpeed(double refSpeed) {
191191
return c;
192192
}
193193
}
194-
String msg = "Input ref. speed does not match any speed in the chart.";
194+
String msg = "Does not match any speed in the chart.";
195195
logger.error(msg);
196196
neqsim.util.exception.InvalidInputException e =
197-
new neqsim.util.exception.InvalidInputException(msg);
197+
new neqsim.util.exception.InvalidInputException(this, "getCurveAtRefSpeed", "refSpeed",
198+
msg);
198199
throw new RuntimeException(e);
199200
}
200201

src/main/java/neqsim/thermo/characterization/LumpingModel.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.apache.logging.log4j.LogManager;
44
import org.apache.logging.log4j.Logger;
5-
65
import neqsim.thermo.system.SystemInterface;
76

87
/**
@@ -201,7 +200,8 @@ public void generateLumpedComposition(Characterise charac) {
201200
@Override
202201
public double getFractionOfHeavyEnd(int i) {
203202
if (fractionOfHeavyEnd == null) {
204-
neqsim.util.exception.ThermoException e = new neqsim.util.exception.NotInitializedException(
203+
neqsim.util.exception.ThermoException e =
204+
new neqsim.util.exception.NotInitializedException(this, "getFractionOfHeavyEnd",
205205
"fractionOfHeavyEnd", "characterisePlusFraction or generateLumpedComposition");
206206
logger.error(e.getMessage());
207207
throw new RuntimeException(e);
@@ -316,7 +316,8 @@ public void generateLumpedComposition(Characterise charac) {
316316
@Override
317317
public double getFractionOfHeavyEnd(int i) {
318318
if (fractionOfHeavyEnd == null) {
319-
neqsim.util.exception.ThermoException e = new neqsim.util.exception.NotInitializedException(
319+
neqsim.util.exception.ThermoException e =
320+
new neqsim.util.exception.NotInitializedException(this, "getFractionOfHeavyEnd",
320321
"fractionOfHeavyEnd", "characterisePlusFraction or generateLumpedComposition");
321322
logger.error(e.getMessage());
322323
throw new RuntimeException(e);

src/main/java/neqsim/thermo/component/Component.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,13 @@ public void addMolesChemReac(double dn) {
463463
/** {@inheritDoc} */
464464
@Override
465465
public void addMolesChemReac(double dn, double totdn) {
466-
numberOfMoles += totdn;
467-
numberOfMolesInPhase += dn;
466+
numberOfMoles += totdn;
468467

469468
if (numberOfMoles < 0) {
470469
numberOfMoles = 0;
471470
}
471+
472+
numberOfMolesInPhase += dn;
472473
if (numberOfMolesInPhase < 0) {
473474
numberOfMolesInPhase = 0;
474475
}
@@ -499,8 +500,8 @@ public void init(double temperature, double pressure, double totalNumberOfMoles,
499500
int type) {
500501

501502
if (totalNumberOfMoles == 0) {
502-
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(
503-
"Component", "init", "Input totalNumberOfMoles must be larger than 0"));
503+
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, "init",
504+
"totalNumberOfMoles", "must be larger than 0"));
504505
}
505506
if (type == 0) {
506507
K = Math.exp(Math.log(criticalPressure / pressure) + 5.373 * (1.0 + srkacentricFactor)

src/main/java/neqsim/thermo/component/ComponentInterface.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,17 @@ public void createComponent(String component_name, double moles, double molesInP
642642
* addMolesChemReac.
643643
* </p>
644644
*
645-
* @param dn a double
646-
* @param totdn a double
645+
* @param dn Number of moles to add to phase and total
646+
*/
647+
public void addMolesChemReac(double dn);
648+
649+
/**
650+
* <p>
651+
* addMolesChemReac.
652+
* </p>
653+
*
654+
* @param dn Number of moles to add to phase
655+
* @param totdn Number of moles to add total
647656
*/
648657
public void addMolesChemReac(double dn, double totdn);
649658

@@ -879,15 +888,6 @@ public void Finit(PhaseInterface phase, double temperature, double pressure,
879888
*/
880889
public int getComponentNumber();
881890

882-
/**
883-
* <p>
884-
* addMolesChemReac.
885-
* </p>
886-
*
887-
* @param dn a double
888-
*/
889-
public void addMolesChemReac(double dn);
890-
891891
/**
892892
* <p>
893893
* getHeatOfVapourization.

src/main/java/neqsim/thermo/phase/Phase.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ public void addMolesChemReac(int component, double dn, double totdn) {
156156
String msg = "Negative number of moles in phase.";
157157
logger.error(msg);
158158
neqsim.util.exception.InvalidInputException e =
159-
new neqsim.util.exception.InvalidInputException(msg);
159+
new neqsim.util.exception.InvalidInputException(this, "addMolesChemReac", msg);
160160
throw new RuntimeException(e);
161161
}
162162
if (getComponent(component).getNumberOfMolesInPhase() < 0.0) {
163163
String msg = "Negative number of moles of component " + component;
164164
logger.error(msg);
165165
neqsim.util.exception.InvalidInputException e =
166-
new neqsim.util.exception.InvalidInputException(msg);
166+
new neqsim.util.exception.InvalidInputException(this, "addMolesChemReac", msg);
167167
throw new RuntimeException(e);
168168
}
169169
}
@@ -384,8 +384,9 @@ public void init() {
384384
public void init(double totalNumberOfMoles, int numberOfComponents, int type, int phase,
385385
double beta) {
386386
if (totalNumberOfMoles <= 0) {
387-
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(
388-
"Phase:init - Input totalNumberOfMoles must be larger than zero."));
387+
throw new RuntimeException(
388+
new neqsim.util.exception.InvalidInputException(this, "init", "totalNumberOfMoles",
389+
"must be larger than zero."));
389390
}
390391

391392
this.beta = beta;

src/main/java/neqsim/thermo/phase/PhaseBWRSEos.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ public double molarVolume2(double pressure, double temperature, double A, double
548548
double Btemp = getB();
549549
setMolarVolume(1.0 / BonV * Btemp);// numberOfMolesInPhase;
550550
int iterations = 0;
551+
int maxIterations = 10000;
551552
double guesPres = pressure;
552553
double guesPresdV = 0.0;
553554
do {
@@ -559,13 +560,15 @@ public double molarVolume2(double pressure, double temperature, double A, double
559560
setMolarVolume(getMolarVolume() - 1.0 / (guesPresdV * getNumberOfMolesInPhase())
560561
* (guesPres - pressure) / 50.0);
561562
Z = pressure * getMolarVolume() / (R * temperature);
562-
} while (Math.abs((guesPres - pressure) / pressure) > 1.0e-10 && iterations < 10000);
563+
} while (Math.abs((guesPres - pressure) / pressure) > 1.0e-10
564+
&& iterations < maxIterations);
563565
// System.out.println("gues pres " + guesPres);
564-
if (iterations >= 10000) {
565-
throw new neqsim.util.exception.TooManyIterationsException();
566+
if (iterations >= maxIterations) {
567+
throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume2",
568+
maxIterations);
566569
}
567570
if (Double.isNaN(getMolarVolume())) {
568-
throw new neqsim.util.exception.IsNaNException();
571+
throw new neqsim.util.exception.IsNaNException(this, "molarVolume2", "Molar Volume");
569572
}
570573
// System.out.println("Z: " + Z + " "+" itert: " +iterations);
571574
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + "

src/main/java/neqsim/thermo/phase/PhaseCSPsrkEos.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public double molarVolume(double pressure, double temperature, double A, double
232232

233233
setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase);
234234
int iterations = 0;
235-
235+
int maxIterations = 1000;
236236
do {
237237
iterations++;
238238
BonVold = BonV;
@@ -277,19 +277,20 @@ public double molarVolume(double pressure, double temperature, double A, double
277277

278278
setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase);
279279
Z = pressure * getMolarVolume() / (R * temperature);
280-
} while (Math.abs(BonV - BonVold) > 1.0e-10 && iterations < 1000);
280+
} while (Math.abs(BonV - BonVold) > 1.0e-10 && iterations < maxIterations);
281281
// molarVolume = 1.0/BonV*Btemp/numberOfMolesInPhase;
282282
// Z = pressure*molarVolume/(R*temperature);
283283
// System.out.println("BonV: " + BonV + " " + h + " " +dh + " B " + Btemp + " D
284284
// " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV());
285285
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + "
286286
// " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv"
287287
// + fVV());
288-
if (iterations >= 1000) {
289-
throw new neqsim.util.exception.TooManyIterationsException();
288+
if (iterations >= maxIterations) {
289+
throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume",
290+
maxIterations);
290291
}
291292
if (Double.isNaN(getMolarVolume())) {
292-
throw new neqsim.util.exception.IsNaNException();
293+
throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume");
293294
}
294295
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + "
295296
// " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv"

src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ public double molarVolume2(double pressure, double temperature, double A, double
10021002
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + "
10031003
// " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv"
10041004
// + fVV());
1005-
throw new neqsim.util.exception.IsNaNException();
1005+
throw new neqsim.util.exception.IsNaNException(this, "molarVolume2", "Molar volume");
10061006
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + "
10071007
// " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv"
10081008
// + fVV());
@@ -1138,7 +1138,7 @@ else if (BonV >= 1.0) {
11381138
// " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV());
11391139

11401140
if (Double.isNaN(getMolarVolume())) {
1141-
throw new neqsim.util.exception.IsNaNException();
1141+
throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume");
11421142
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + "
11431143
// " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv"
11441144
// + fVV());
@@ -1280,7 +1280,8 @@ public double molarVolumeChangePhase(double pressure, double temperature, double
12801280
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh + " B
12811281
// " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV());
12821282
if (Double.isNaN(getMolarVolume())) {
1283-
throw new neqsim.util.exception.IsNaNException();
1283+
throw new neqsim.util.exception.IsNaNException(this, "molarVolumeChangePhase",
1284+
"Molar volume");
12841285
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + "
12851286
// " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv"
12861287
// + fVV());

src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPAOld.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.apache.logging.log4j.LogManager;
44
import org.apache.logging.log4j.Logger;
5-
65
import neqsim.thermo.component.ComponentCPAInterface;
76
import neqsim.thermo.component.ComponentElectrolyteCPA;
87
import neqsim.thermo.component.ComponentEosInterface;
@@ -622,7 +621,7 @@ public double molarVolume3(double pressure, double temperature, double A, double
622621
// (-pressure+R*temperature/molarVolume-R*temperature*dFdV()) + " firstterm " +
623622
// (R*temperature/molarVolume) + " second " + R*temperature*dFdV());
624623
if (Double.isNaN(getMolarVolume())) {
625-
throw new neqsim.util.exception.IsNaNException();
624+
throw new neqsim.util.exception.IsNaNException(this, "molarVolume3", "Molar volume");
626625
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + "
627626
// " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv"
628627
// + fVV());
@@ -655,6 +654,7 @@ public double molarVolume(double pressure, double temperature, double A, double
655654
}
656655
setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase);
657656
int iterations = 0;
657+
int maxIterations = 1000;
658658
double oldVolume = getVolume();
659659
do {
660660
this.volInit();
@@ -713,7 +713,7 @@ public double molarVolume(double pressure, double temperature, double A, double
713713
Z = pressure * getMolarVolume() / (R * temperature);
714714

715715
// System.out.println("Z" + Z);
716-
} while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < 1001);
716+
} while (Math.abs((BonV - BonVold) / BonV) > 1.0e-10 && iterations < maxIterations);
717717
// System.out.println("Z" + Z + " iterations " + iterations + " h " + h);
718718
// System.out.println("pressure " + Z*R*temperature/getMolarVolume());
719719
// if(iterations>=100) throw new util.exception.TooManyIterationsException();
@@ -722,7 +722,7 @@ public double molarVolume(double pressure, double temperature, double A, double
722722
// firstterm " + (R*temperature/molarVolume) + " second " +
723723
// R*temperature*dFdV());
724724
if (Double.isNaN(getMolarVolume())) {
725-
throw new neqsim.util.exception.IsNaNException();
725+
throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume");
726726
// System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + "
727727
// " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv"
728728
// + fVV());

src/main/java/neqsim/thermo/phase/PhaseEos.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public double molarVolume2(double pressure, double temperature, double A, double
212212

213213
setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase);
214214
int iterations = 0;
215+
int maxIterations = 1000;
215216

216217
do {
217218
iterations++;
@@ -257,19 +258,20 @@ public double molarVolume2(double pressure, double temperature, double A, double
257258

258259
setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase);
259260
Z = pressure * getMolarVolume() / (R * temperature);
260-
} while (Math.abs(BonV - BonVold) > 1.0e-9 && iterations < 1000);
261+
} while (Math.abs(BonV - BonVold) > 1.0e-9 && iterations < maxIterations);
261262
// molarVolume = 1.0/BonV*Btemp/numberOfMolesInPhase;
262263
// Z = pressure*molarVolume/(R*temperature);
263264
// logger.info("BonV: " + BonV + " " + h + " " +dh + " B " + Btemp + " D " +
264265
// Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV());
265266
// logger.info("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh +
266267
// " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" +
267268
// fVV());
268-
if (iterations >= 1000) {
269-
throw new neqsim.util.exception.TooManyIterationsException();
269+
if (iterations >= maxIterations) {
270+
throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume2",
271+
maxIterations);
270272
}
271273
if (Double.isNaN(getMolarVolume())) {
272-
throw new neqsim.util.exception.IsNaNException();
274+
throw new neqsim.util.exception.IsNaNException(this, "molarVolume2", "Molar volume");
273275
// logger.info("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh +
274276
// " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" +
275277
// fVV());
@@ -293,15 +295,15 @@ public double molarVolume(double pressure, double temperature, double A, double
293295
}
294296

295297
double BonVold = BonV, Btemp = getB(), h, dh, dhh, d1, d2, BonV2;
296-
int iterations = 0;
297298

298299
if (Btemp < 0) {
299300
logger.info("b negative in volume calc");
300301
}
301302
setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase);
302303
boolean changeFase = false;
303304
double error = 1.0, errorOld = 1.0e10;
304-
305+
int iterations = 0;
306+
int maxIterations = 300;
305307
do {
306308
errorOld = error;
307309
iterations++;
@@ -354,18 +356,19 @@ public double molarVolume(double pressure, double temperature, double A, double
354356
setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase);
355357
Z = pressure * getMolarVolume() / (R * temperature);
356358
// logger.info("Math.abs((BonV - BonVold)) " + Math.abs((BonV - BonVold)));
357-
} while (Math.abs((BonV - BonVold) / BonVold) > 1.0e-10 && iterations < 300);
359+
} while (Math.abs((BonV - BonVold) / BonVold) > 1.0e-10 && iterations < maxIterations);
358360
// logger.info("pressure " + Z*R*temperature/molarVolume);
359361
// logger.info("error in volume " +
360362
// (-pressure+R*temperature/molarVolume-R*temperature*dFdV()) + " firstterm " +
361363
// (R*temperature/molarVolume) + " second " + R*temperature*dFdV());
362-
if (iterations >= 300) {
363-
throw new neqsim.util.exception.TooManyIterationsException();
364+
if (iterations >= maxIterations) {
365+
throw new neqsim.util.exception.TooManyIterationsException(this, "molarVolume",
366+
maxIterations);
364367
}
365368
if (Double.isNaN(getMolarVolume())) {
366369
// A = calcA(this, temperature, pressure, numberOfComponents);
367370
// molarVolume(pressure, temperature, A, B, phase);
368-
throw new neqsim.util.exception.IsNaNException();
371+
throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume");
369372
// logger.info("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh +
370373
// " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" +
371374
// fVV());

src/main/java/neqsim/thermo/phase/PhaseGE.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public PhaseGE() {
5656
public void init(double temperature, double pressure, double totalNumberOfMoles, double beta,
5757
int numberOfComponents, int type, int phase) {
5858
if (totalNumberOfMoles <= 0) {
59-
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(
60-
"PhaseGE", "init", "Input totalNumberOfMoles must be larger than zero."));
59+
new neqsim.util.exception.InvalidInputException(this, "init", "totalNumberOfMoles",
60+
"must be larger than zero.");
6161
}
6262
for (int i = 0; i < numberOfComponents; i++) {
6363
componentArray[i].init(temperature, pressure, totalNumberOfMoles, beta, type);

src/main/java/neqsim/thermo/phase/PhaseInterface.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,14 @@ public void removeComponent(String componentName, double moles, double molesInPh
596596
public double getPureComponentFugacity(int k, boolean pure);
597597

598598
/**
599-
* <p>
600-
* addMolesChemReac.
601-
* </p>
602-
*
603-
* @param component a int
604-
* @param dn a double
605-
* @param totdn a double
606-
*/
599+
* <p>
600+
* addMolesChemReac.
601+
* </p>
602+
*
603+
* @param component Component number
604+
* @param dn a double
605+
* @param totdn a double
606+
*/
607607
public void addMolesChemReac(int component, double dn, double totdn);
608608

609609
/**

0 commit comments

Comments
 (0)