From e00626f0b5d3febc9014e02aaf428f9f2398a152 Mon Sep 17 00:00:00 2001 From: Sviatoslav Eroshkin <109044598+Sviatose@users.noreply.github.com> Date: Fri, 12 Jan 2024 23:00:53 +0100 Subject: [PATCH] fix: add more get methods (#902) --- .../pipeline/PipeBeggsAndBrills.java | 131 ++++++++++++------ .../exception/InvalidOutputException.java | 69 +++++++++ .../pipeline/BeggsAndBrillsPipeTest.java | 27 +++- .../reservoir/WellFlowTest.java | 3 +- 4 files changed, 184 insertions(+), 46 deletions(-) create mode 100644 src/main/java/neqsim/util/exception/InvalidOutputException.java diff --git a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/PipeBeggsAndBrills.java b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/PipeBeggsAndBrills.java index 2e5a3e78ca..67b6360854 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/PipeBeggsAndBrills.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/PipeBeggsAndBrills.java @@ -129,11 +129,13 @@ public class PipeBeggsAndBrills extends Pipeline { private List mixtureViscosityProfile; private List mixtureDensityProfile; + private List liquidHoldupProfile; private List mixtureReynoldsNumber; private List lengthProfile; private List elevationProfile; + private List incrementsProfile; /** *

@@ -398,10 +400,6 @@ public String calcFlowRegime() { supGasVel = system.getPhase(0).getFlowRate("ft3/sec") / area; supMixVel = supLiquidVel + supGasVel; - liquidSuperficialVelocityProfile.add(supLiquidVel / 3.2808399); // to meters - gasSuperficialVelocityProfile.add(supGasVel / 3.2808399); - mixtureSuperficialVelocityProfile.add(supMixVel / 3.2808399); - mixtureFroudeNumber = Math.pow(supMixVel, 2) / (32.174 * insideDiameter); inputVolumeFractionLiquid = supLiquidVel / supMixVel; } else { @@ -418,6 +416,10 @@ public String calcFlowRegime() { } } + liquidSuperficialVelocityProfile.add(supLiquidVel / 3.2808399); // to meters + gasSuperficialVelocityProfile.add(supGasVel / 3.2808399); + mixtureSuperficialVelocityProfile.add(supMixVel / 3.2808399); + double L1 = 316 * Math.pow(inputVolumeFractionLiquid, 0.302); double L2 = 0.0009252 * Math.pow(inputVolumeFractionLiquid, -2.4684); double L3 = 0.1 * Math.pow(inputVolumeFractionLiquid, -1.4516); @@ -584,11 +586,11 @@ public double calcFrictionPressureLoss() { if (system.getNumberOfPhases() != 1) { if (regime != "Single Phase") { double y = inputVolumeFractionLiquid / (Math.pow(El, 2)); - if(1 < y && y < 1.2){ - S = Math.log(2.2*y - 1.2); - } - else { - S = Math.log(y) / (-0.0523 + 3.18 * Math.log(y) - 0.872 * Math.pow(Math.log(y), 2.0) + 0.01853 * Math.pow(Math.log(y), 4)); + if (1 < y && y < 1.2) { + S = Math.log(2.2 * y - 1.2); + } else { + S = Math.log(y) / (-0.0523 + 3.18 * Math.log(y) - 0.872 * Math.pow(Math.log(y), 2.0) + + 0.01853 * Math.pow(Math.log(y), 4)); } if (system.getNumberOfPhases() == 3) { rhoNoSlip = mixtureLiquidDensity * inputVolumeFractionLiquid @@ -649,7 +651,7 @@ public double calcPressureDrop() { frictionPressureLoss = calcFrictionPressureLoss(); pressureDrop = (hydrostaticPressureDrop + frictionPressureLoss); convertSystemUnitToMetric(); - iteration = iteration + 1; + iteration = iteration + 1; return pressureDrop; } @@ -677,6 +679,7 @@ public void run(UUID id) { lengthProfile = new ArrayList<>(); elevationProfile = new ArrayList<>(); + incrementsProfile = new ArrayList<>(); calculateMissingValue(); double enthalpyInlet = Double.NaN; @@ -693,12 +696,16 @@ public void run(UUID id) { double pipeInletPressure = system.getPressure(); cumulativeLength = 0.0; cumulativeElevation = 0.0; + pressureProfile.add(system.getPressure()); // pressure at segment 0 + temperatureProfile.add(system.getTemperature()); // temperature at segment 0 + pressureDropProfile.add(0.0); // DP at segment 0 for (int i = 1; i <= numberOfIncrements; i++) { - cumulativeLength += length; - cumulativeElevation += elevation; - lengthProfile.add(cumulativeLength); elevationProfile.add(cumulativeElevation); + incrementsProfile.add(i-1); + + cumulativeLength += length; + cumulativeElevation += elevation; inletPressure = system.getPressure(); pressureDrop = calcPressureDrop(); @@ -706,7 +713,7 @@ public void run(UUID id) { pressureOut = inletPressure - pressureDrop; pressureProfile.add(pressureOut); if (pressureOut < 0) { - throw new RuntimeException(new neqsim.util.exception.InvalidInputException( + throw new RuntimeException(new neqsim.util.exception.InvalidOutputException( "PipeBeggsAndBrills", "run: calcOutletPressure", "pressure out", "- Outlet pressure is negative" + pressureOut)); } @@ -719,8 +726,15 @@ public void run(UUID id) { temperatureProfile.add(system.getTemperature()); } totalPressureDrop = pipeInletPressure - system.getPressure(); + calcPressureDrop(); // to initialize final parameters + lengthProfile.add(cumulativeLength); + elevationProfile.add(cumulativeElevation); + incrementsProfile.add(getNumberOfIncrements()); + + outStream.setThermoSystem(system); outStream.setCalculationIdentifier(id); + } /** @@ -746,18 +760,44 @@ public void displayResult() { /** *

- * getSuperficialVelocity. + * getInletSuperficialVelocity. *

* * @return a double */ - public double getSuperficialVelocity() { + public double getInletSuperficialVelocity() { return getInletStream().getThermoSystem().getFlowRate("kg/sec") / getInletStream().getThermoSystem().getDensity("kg/m3") / (Math.PI / 4.0 * Math.pow(insideDiameter, 2.0)); } + /** + *

+ * getOutletSuperficialVelocity. + *

+ * + * @return a double + */ + public double getOutletSuperficialVelocity() { + return getSegmentMixtureSuperficialVelocity(numberOfIncrements); + } + + + /** + *

+ * getNumberOfIncrements + *

+ * + * @return a double + */ + public int getNumberOfIncrements() { + return numberOfIncrements; + } + + + + /** * @return angle in degrees */ @@ -850,8 +890,8 @@ public List getPressureProfile() { * @return segment pressure as double */ public Double getSegmentPressure(int index) { - if (index >= 1 && index < pressureProfile.size() + 1) { - return pressureProfile.get(index - 1); + if (index >= 0 && index < pressureProfile.size()) { + return pressureProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -873,8 +913,8 @@ public List getPressureDropProfile() { * @return Double */ public Double getSegmentPressureDrop(int index) { - if (index >= 1 && index < pressureDropProfile.size() + 1) { - return pressureDropProfile.get(index - 1); + if (index >= 0 && index < pressureDropProfile.size()) { + return pressureDropProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -894,8 +934,8 @@ public List getTemperatureProfile() { * @return Double */ public Double getSegmentTemperature(int index) { - if (index >= 1 && index < temperatureProfile.size() + 1) { - return temperatureProfile.get(index - 1); + if (index >= 0 && index < temperatureProfile.size()) { + return temperatureProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -915,8 +955,8 @@ public List getFlowRegimeProfile() { * @return String */ public String getSegmentFlowRegime(int index) { - if (index >= 1 && index < flowRegimeProfile.size() + 1) { - return flowRegimeProfile.get(index - 1); + if (index >= 0 && index < flowRegimeProfile.size()) { + return flowRegimeProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -993,6 +1033,13 @@ public List getLengthProfile() { return new ArrayList<>(lengthProfile); } + /** + * @return list of increments profile + */ + public List getIncrementsProfile() { + return new ArrayList<>(incrementsProfile); + } + /** @@ -1009,8 +1056,8 @@ public List getElevationProfile() { * @return Double */ public Double getSegmentLiquidSuperficialVelocity(int index) { - if (index >= 1 && index <= liquidSuperficialVelocityProfile.size()) { - return liquidSuperficialVelocityProfile.get(index - 1); + if (index >= 0 && index <= liquidSuperficialVelocityProfile.size()) { + return liquidSuperficialVelocityProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -1023,8 +1070,8 @@ public Double getSegmentLiquidSuperficialVelocity(int index) { * @return Double */ public Double getSegmentGasSuperficialVelocity(int index) { - if (index >= 1 && index <= gasSuperficialVelocityProfile.size()) { - return gasSuperficialVelocityProfile.get(index - 1); + if (index >= 0 && index <= gasSuperficialVelocityProfile.size()) { + return gasSuperficialVelocityProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -1037,8 +1084,8 @@ public Double getSegmentGasSuperficialVelocity(int index) { * @return Double */ public Double getSegmentMixtureSuperficialVelocity(int index) { - if (index >= 1 && index <= mixtureSuperficialVelocityProfile.size()) { - return mixtureSuperficialVelocityProfile.get(index - 1); + if (index >= 0 && index <= mixtureSuperficialVelocityProfile.size()) { + return mixtureSuperficialVelocityProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -1050,8 +1097,8 @@ public Double getSegmentMixtureSuperficialVelocity(int index) { * @return Double */ public Double getSegmentMixtureViscosity(int index) { - if (index >= 1 && index <= mixtureViscosityProfile.size()) { - return mixtureViscosityProfile.get(index - 1); + if (index >= 0 && index <= mixtureViscosityProfile.size()) { + return mixtureViscosityProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -1064,8 +1111,8 @@ public Double getSegmentMixtureViscosity(int index) { * @return Double */ public Double getSegmentMixtureDensity(int index) { - if (index >= 1 && index <= mixtureDensityProfile.size()) { - return mixtureDensityProfile.get(index - 1); + if (index >= 0 && index <= mixtureDensityProfile.size()) { + return mixtureDensityProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -1077,8 +1124,8 @@ public Double getSegmentMixtureDensity(int index) { * @return Double */ public Double getSegmentLiquidHoldup(int index) { - if (index >= 1 && index <= liquidHoldupProfile.size()) { - return liquidHoldupProfile.get(index - 1); + if (index >= 0 && index <= liquidHoldupProfile.size()) { + return liquidHoldupProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -1091,8 +1138,8 @@ public Double getSegmentLiquidHoldup(int index) { * @return Double */ public Double getSegmentMixtureReynoldsNumber(int index) { - if (index >= 1 && index <= mixtureReynoldsNumber.size()) { - return mixtureReynoldsNumber.get(index - 1); + if (index >= 0 && index <= mixtureReynoldsNumber.size()) { + return mixtureReynoldsNumber.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -1105,8 +1152,8 @@ public Double getSegmentMixtureReynoldsNumber(int index) { * @return Double */ public Double getSegmentLength(int index) { - if (index >= 1 && index <= lengthProfile.size()) { - return lengthProfile.get(index - 1); + if (index >= 0 && index <= lengthProfile.size()) { + return lengthProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } @@ -1119,8 +1166,8 @@ public Double getSegmentLength(int index) { * @return Double */ public Double getSegmentElevation(int index) { - if (index >= 1 && index <= elevationProfile.size()) { - return elevationProfile.get(index - 1); + if (index >= 0 && index <= elevationProfile.size()) { + return elevationProfile.get(index); } else { throw new IndexOutOfBoundsException("Index is out of bounds."); } diff --git a/src/main/java/neqsim/util/exception/InvalidOutputException.java b/src/main/java/neqsim/util/exception/InvalidOutputException.java new file mode 100644 index 0000000000..2c6f231f13 --- /dev/null +++ b/src/main/java/neqsim/util/exception/InvalidOutputException.java @@ -0,0 +1,69 @@ +package neqsim.util.exception; + +/** + *

+ * InvalidOutputException class. + *

+ * + * @author Even Solbraa + * @version $Id: $Id + */ +public class InvalidOutputException extends neqsim.util.exception.ThermoException { + private static final long serialVersionUID = 1000; + + /** + * Constructs an InvalidOutputException with the specified detail message. + * + * @param msg the detail message. + */ + @Deprecated + public InvalidOutputException(String msg) { + super(msg); + } + + /** + * Constructs an InvalidOutputException with a default message. + * + * @param className Class that exception is raised from + * @param methodName Method that exception is raised from + * @param outputName Name of invalid output + */ + public InvalidOutputException(String className, String methodName, String outputName) { + super(className, methodName, "output " + outputName + " was invalid."); + } + + /** + * Constructs an InvalidOutputException with the specified detail message. + * + * @param className Class that exception is raised from + * @param methodName Method that exception is raised from + * @param outputName Name of invalid output + * @param msg error message detailing output problem + */ + public InvalidOutputException(String className, String methodName, String outputName, String msg) { + super(className, methodName, "output " + outputName + " " + msg); + } + + /** + * Constructs an InvalidOutputException with a default message. + * + * @param obj Object that exception is raised from + * @param methodName Method that exception is raised from + * @param outputName Name of invalid output + */ + public InvalidOutputException(Object obj, String methodName, String outputName) { + this(obj.getClass().getSimpleName(), methodName, outputName); + } + + /** + * Constructs an InvalidOutputException with a default message. + * + * @param obj Object that exception is raised from + * @param methodName Method that exception is raised from + * @param outputName Name of invalid output + * @param msg error message detailing output problem + */ + public InvalidOutputException(Object obj, String methodName, String outputName, String msg) { + this(obj.getClass().getSimpleName(), methodName, outputName, msg); + } +} diff --git a/src/test/java/neqsim/processSimulation/processEquipment/pipeline/BeggsAndBrillsPipeTest.java b/src/test/java/neqsim/processSimulation/processEquipment/pipeline/BeggsAndBrillsPipeTest.java index 7c515a8ff1..65f5ed72d4 100644 --- a/src/test/java/neqsim/processSimulation/processEquipment/pipeline/BeggsAndBrillsPipeTest.java +++ b/src/test/java/neqsim/processSimulation/processEquipment/pipeline/BeggsAndBrillsPipeTest.java @@ -90,6 +90,7 @@ public void testPipeLineBeggsAndBrills() { Assertions.assertEquals(pressureOut, 27.5402, 1e-4); Assertions.assertEquals(temperatureOut, 39.3374, 1e-4); + Assertions.assertEquals(pipe.getOutletSuperficialVelocity(), pipe.getSegmentMixtureSuperficialVelocity(pipe.getNumberOfIncrements()), 0.1); } @@ -139,6 +140,7 @@ public void testPipeLineBeggsAndBrills2() { Assertions.assertEquals(pressureOut, 13.735508907175728, 1e-4); Assertions.assertEquals(temperatureOut, 38.82331519652632, 1e-4); + Assertions.assertEquals(pipe.getOutletSuperficialVelocity(), pipe.getSegmentMixtureSuperficialVelocity(pipe.getNumberOfIncrements()), 0.1); } @@ -196,15 +198,17 @@ public void testPipeLineBeggsAndBrills3() { Assertions.assertEquals(pipe.getSegmentPressureDrop(10), 1.5468048987983438, 1.0); Assertions.assertEquals(pipe.getSegmentTemperature(10) - 273.15, 79.80343029302054, 1.0); Assertions.assertEquals(pipe.getSegmentFlowRegime(10), "INTERMITTENT"); - Assertions.assertEquals(pipe.getSegmentMixtureDensity(10), 233.1155792052253, 1.0); + Assertions.assertEquals(pipe.getSegmentMixtureDensity(10), 224.31571593591167, 1.0); Assertions.assertEquals(pipe.getSegmentLiquidSuperficialVelocity(10), 3.357338501138603, 1.0); Assertions.assertEquals(pipe.getSegmentGasSuperficialVelocity(10), 7.109484383317198, 1.0); Assertions.assertEquals(pipe.getSegmentMixtureSuperficialVelocity(10), 10.466822884455802, 1.0); Assertions.assertEquals(pipe.getSegmentMixtureViscosity(10), 0.14329203901478244, 1.0); Assertions.assertEquals(pipe.getSegmentLiquidHoldup(10), 0.42601098053163294, 1.0); - Assertions.assertEquals(pipe.getSegmentMixtureReynoldsNumber(10), 2127138.3343691113, 1.0); + Assertions.assertEquals(pipe.getSegmentMixtureReynoldsNumber(10), 2196973.270922545, 1.0); Assertions.assertEquals(pipe.getSegmentLength(10), 410.0, 1.0); Assertions.assertEquals(pipe.getSegmentElevation(10), 300, 1.0); + Assertions.assertEquals(pipe.getOutletSuperficialVelocity(), pipe.getSegmentMixtureSuperficialVelocity(pipe.getNumberOfIncrements()), 0.1); + } @@ -253,6 +257,25 @@ public void testPipeLineBeggsAndBrills4() { Assertions.assertEquals(pressureOut, 124.04439, 1e-4); + Assertions.assertEquals(pipe.getPressureDrop(), 25.955604559293917, 1.0); + Assertions.assertEquals(pipe.getSegmentPressure(10), 124.04439544070608, 1.0); + Assertions.assertEquals(pipe.getSegmentPressure(0), 150, 1.0); + Assertions.assertEquals(pipe.getSegmentPressureDrop(10), 2.9204245897598162, 1.0); + Assertions.assertEquals(pipe.getSegmentTemperature(10) - 273.15, 75.07486781297496, 1.0); + Assertions.assertEquals(pipe.getSegmentFlowRegime(10), "Single Phase"); + Assertions.assertEquals(pipe.getSegmentMixtureDensity(10), 73.54613545016805, 1.0); + Assertions.assertEquals(pipe.getSegmentLiquidSuperficialVelocity(10), 0.0, 1.0); + Assertions.assertEquals(pipe.getSegmentGasSuperficialVelocity(10), 33.85480591912372, 1.0); + Assertions.assertEquals(pipe.getSegmentMixtureSuperficialVelocity(10), 33.85480591912372, 1.0); + Assertions.assertEquals(pipe.getSegmentMixtureViscosity(10), 0.14329203901478244, 1.0); + Assertions.assertEquals(pipe.getSegmentLiquidHoldup(10), 0.0, 0.01); + Assertions.assertEquals(pipe.getSegmentMixtureReynoldsNumber(10), 2.014803001851525E7, 1.0); + Assertions.assertEquals(pipe.getSegmentLength(10), 1500.0, 1.0); + Assertions.assertEquals(pipe.getSegmentElevation(10), -1000, 1.0); + Assertions.assertEquals(pipe.getNumberOfIncrements(), 10, 0.1); + Assertions.assertEquals(pipe.getOutletSuperficialVelocity(), pipe.getSegmentMixtureSuperficialVelocity(pipe.getNumberOfIncrements()), 0.1); + + neqsim.thermo.system.SystemInterface testSystem2 = new neqsim.thermo.system.SystemSrkEos((273.15 + 45), ThermodynamicConstantsInterface.referencePressure); diff --git a/src/test/java/neqsim/processSimulation/processEquipment/reservoir/WellFlowTest.java b/src/test/java/neqsim/processSimulation/processEquipment/reservoir/WellFlowTest.java index 1f9fa0e3fc..18cf151f5d 100644 --- a/src/test/java/neqsim/processSimulation/processEquipment/reservoir/WellFlowTest.java +++ b/src/test/java/neqsim/processSimulation/processEquipment/reservoir/WellFlowTest.java @@ -126,8 +126,7 @@ void testRunTransient() { .println("top side pressure " + pipeline.getOutletStream().getPressure("bara") + " bara"); System.out .println("Total produced gas " + reservoirOps.getGasProductionTotal("GMSm3") + " GMSm3"); - System.out.println("gas velocity " + pipeline.getSuperficialVelocity()); - + System.out.println("gas velocity " + pipeline.getInletSuperficialVelocity()); } }