From a133a5bfe7340f7459dcd4277c19d6527e0bf9f9 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Thu, 16 Nov 2023 19:22:27 +0100 Subject: [PATCH] Process new tp flash problem (#852) * bug: TPflash problem * fixed bug in flash * comment out method --------- Co-authored-by: Sviatoslav Eroshkin <109044598+Sviatose@users.noreply.github.com> --- .../flashOps/TPmultiflash.java | 10 +-- .../{GudrunDegasser.java => Degasser.java} | 63 +++++++++++++++---- 2 files changed, 56 insertions(+), 17 deletions(-) rename src/test/java/neqsim/thermodynamicOperations/flashOps/{GudrunDegasser.java => Degasser.java} (66%) diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java index 5e63916e54..7d18355b6e 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java @@ -370,13 +370,14 @@ public void stabilityAnalysis() { // if(minimumGibbsEnergySystem.getPhase(0).getComponent(j).isInert()) break; int iter = 0; double errOld = 1.0e100; + boolean useaccsubst = true; do { errOld = err; iter++; err = 0; if (iter <= 150 || !system.isImplementedCompositionDeriativesofFugacity()) { - if (iter % 7 == 0 && iter < 150) { + if (iter % 7 == 0 && iter < 150 && useaccsubst) { double vec1 = 0.0; double vec2 = 0.0; @@ -396,9 +397,6 @@ public void stabilityAnalysis() { err += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); Wi[j][i] = Math.exp(logWi[i]); } - if (err > errOld) { - continue; - } } else { for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { oldoldoldlogw[i] = oldoldlogw[i]; @@ -423,7 +421,11 @@ public void stabilityAnalysis() { err += Math.abs(logWi[i] - oldlogw[i]); Wi[j][i] = Math.exp(logWi[i]); } + if (iter > 2 && err > errOld) { + useaccsubst = false; + } } + } else { SimpleMatrix f = new SimpleMatrix(system.getPhases()[0].getNumberOfComponents(), 1); SimpleMatrix df = null; diff --git a/src/test/java/neqsim/thermodynamicOperations/flashOps/GudrunDegasser.java b/src/test/java/neqsim/thermodynamicOperations/flashOps/Degasser.java similarity index 66% rename from src/test/java/neqsim/thermodynamicOperations/flashOps/GudrunDegasser.java rename to src/test/java/neqsim/thermodynamicOperations/flashOps/Degasser.java index 95a3d11523..e0d040f75f 100644 --- a/src/test/java/neqsim/thermodynamicOperations/flashOps/GudrunDegasser.java +++ b/src/test/java/neqsim/thermodynamicOperations/flashOps/Degasser.java @@ -11,7 +11,7 @@ * @author ESOL * */ -class GudrunDegasser { +class Degasser { static neqsim.thermo.system.SystemInterface testSystem = null; static ThermodynamicOperations testOps = null; @@ -35,11 +35,11 @@ void setUp() throws Exception { /** * Test method for - * {@link neqsim.thermodynamicOperations.flashOps.PHFlash#run()}. */ @Test void testRun() { - neqsim.thermo.system.SystemInterface fluid1 = new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 42.0, 10.00); + neqsim.thermo.system.SystemInterface fluid1 = + new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 42.0, 10.00); fluid1.addComponent("nitrogen", 0.110282450914383); fluid1.addComponent("CO2", 8.92014980316162); @@ -121,27 +121,30 @@ void testRun() { molarComposition.add(2.732003176453634); molarComposition.add(27.978388438425913); - double[] molarCompositionArray = molarComposition.stream().mapToDouble(Double::doubleValue).toArray(); + double[] molarCompositionArray = + molarComposition.stream().mapToDouble(Double::doubleValue).toArray(); neqsim.thermo.system.SystemInterface fluid_test_separator = fluid1.clone(); fluid_test_separator.setMolarComposition(molarCompositionArray); - neqsim.processSimulation.processEquipment.stream.Stream inlet_stream_test_sep = new neqsim.processSimulation.processEquipment.stream.Stream( - "TEST_SEPARATOR_INLET", - fluid_test_separator); + neqsim.processSimulation.processEquipment.stream.Stream inlet_stream_test_sep = + new neqsim.processSimulation.processEquipment.stream.Stream("TEST_SEPARATOR_INLET", + fluid_test_separator); inlet_stream_test_sep.setTemperature(72.6675872802734, "C"); inlet_stream_test_sep.setPressure(10.6767892837524, "bara"); inlet_stream_test_sep.setFlowRate(721.3143271348611, "kg/hr"); inlet_stream_test_sep.run(); - neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator test_separator = new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator( - inlet_stream_test_sep); + neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator test_separator = + new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator( + inlet_stream_test_sep); test_separator.setName("TEST_SEPARATOR"); test_separator.run(); test_separator.getWaterOutStream().getThermoSystem().prettyPrint(); - neqsim.processSimulation.processEquipment.heatExchanger.Heater heater_TP_setter_test_stream = new neqsim.processSimulation.processEquipment.heatExchanger.Heater( - "TP_SETTER_FOR_THE_DEGASSER_TEST_SEP_STREAM", test_separator.getWaterOutStream()); + neqsim.processSimulation.processEquipment.heatExchanger.Heater heater_TP_setter_test_stream = + new neqsim.processSimulation.processEquipment.heatExchanger.Heater( + "TP_SETTER_FOR_THE_DEGASSER_TEST_SEP_STREAM", test_separator.getWaterOutStream()); heater_TP_setter_test_stream.setOutPressure(5.9061164855957 - 0.01, "bara"); heater_TP_setter_test_stream.setOutTemperature(79.8487854003906, "C"); heater_TP_setter_test_stream.run(); @@ -149,8 +152,9 @@ void testRun() { .getFluid().getPhase("gas").getFlowRate("kg/hr")); heater_TP_setter_test_stream.getOutStream().getThermoSystem().prettyPrint(); - neqsim.processSimulation.processEquipment.heatExchanger.Heater heater_TP_setter_test_stream2 = new neqsim.processSimulation.processEquipment.heatExchanger.Heater( - "TP_SETTER_FOR_THE_DEGASSER_TEST_SEP_STREAM", test_separator.getWaterOutStream()); + neqsim.processSimulation.processEquipment.heatExchanger.Heater heater_TP_setter_test_stream2 = + new neqsim.processSimulation.processEquipment.heatExchanger.Heater( + "TP_SETTER_FOR_THE_DEGASSER_TEST_SEP_STREAM", test_separator.getWaterOutStream()); heater_TP_setter_test_stream2.setOutPressure(5.9061164855957, "bara"); heater_TP_setter_test_stream2.setOutTemperature(79.8487854003906, "C"); heater_TP_setter_test_stream2.run(); @@ -174,4 +178,37 @@ private int findComponentIndex(String[] componentNames, String componentName) { return -1; // Component not found } + + + /** + * Test method for + */ + void testRun2() { + /* + * XStream xstream = new XStream(); xstream.addPermission(AnyTypePermission.ANY); // Specify the + * file path to read Path filePath = Paths.get( + * "/workspaces/neqsim/src/test/java/neqsim/thermodynamicOperations/flashOps/my_process.xml"); + * String xmlContents = ""; try { //xmlContents = Files.readString(filePath); } catch + * (IOException e) { e.printStackTrace(); } + * + * // Deserialize from xml neqsim.processSimulation.processSystem.ProcessSystem operationsCopy = + * (neqsim.processSimulation.processSystem.ProcessSystem) xstream.fromXML(xmlContents); + * operationsCopy.run(); neqsim.processSimulation.processEquipment.separator.Separator + * VD02Separator = (neqsim.processSimulation.processEquipment.separator.Separator) + * operationsCopy .getUnit("Separator after CFU gas"); + * neqsim.processSimulation.processEquipment.separator.Separator VD01Separator = + * (neqsim.processSimulation.processEquipment.separator.Separator) operationsCopy + * .getUnit("Separator after degasser gas"); + * neqsim.processSimulation.processEquipment.separator.Separator Degasser = + * (neqsim.processSimulation.processEquipment.separator.Separator) operationsCopy + * .getUnit("Degasser"); + * System.out.println("The gas flow rate should be < 200 kg/hr, the actual value is " + + * Degasser.getGasOutStream().getFlowRate("kg/hr")); + * System.out.println("The gas flow rate should be < 200 kg/hr, the actual value is " + + * VD01Separator.getGasOutStream().getFlowRate("kg/hr")); VD02Separator.getGasOutStream().run(); + * System.out.println("The gas flow rate should be < 200 kg/hr, the actual value is " + + * VD02Separator.getGasOutStream().getFlowRate("kg/hr")); + */ + + } }