From db5385cba4d68e432a8c033db8e7cef02e078b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Thu, 21 Jul 2022 19:02:38 +0200 Subject: [PATCH 1/9] refact: clean out empty/unused cdf code (#487) * refact: clean out empty/unused cdf code --- .vscode/settings.json | 2 +- .../createTextFile/TextFile.java | 163 +- .../stirredCellSystem/StirredCellSystem.java | 283 +- .../TwoPhasePipeFlowSystem.java | 303 +- .../TwoPhasePipeFlowSystemReac.java | 135 +- .../TwoPhaseReactorFlowSystem.java | 1 - .../FlowSystemVisualization.java | 123 +- .../FlowSystemVisualizationInterface.java | 9 - .../PipeFlowVisualization.java | 301 +- .../TwoPhasePipeFlowVisualization.java | 348 +- .../pipeline/OnePhasePipeLine.java | 115 +- .../processEquipment/pipeline/Pipeline.java | 545 ++- .../pipeline/TwoPhasePipeLine.java | 109 +- .../parameterFitting/StatisticsInterface.java | 153 +- ...stIonicInteractionParameterFittingCH4.java | 186 +- ...stCPAParameterFittingToSolubilityData.java | 172 +- ...arameterFittingToSolubilityData_Lucia.java | 313 +- ...AParameterFittingToSolubilityGlycolHC.java | 208 +- ...osParameterFittingToMercurySolubility.java | 123 +- ...ParameterFittingToSolubilityDataEinar.java | 112 +- ...inaryHVParameterFittingToDewPointData.java | 171 +- ...aryHVParameterFittingToSolubilityData.java | 180 +- ...arameterFittingToSolubilityData_Lucia.java | 461 +- ...rFittingToSolubilityData_LuciaPropane.java | 320 +- ...ameterFittingToSolubilityDatawaterCO2.java | 206 +- ...stBinaryUMRPRUFittingToSolubilityData.java | 557 ++- ...arameterFittingToSolubilityData_Lucia.java | 373 +- .../TestSolidAntoine.java | 101 +- .../TestIonicInteractionParameterFitting.java | 485 +-- ...stIonicInteractionParameterFittingCH4.java | 249 +- ...nicInteractionParameterFittingCo2nacl.java | 138 +- ...ractionParameterFittingMDEAPiperazine.java | 127 +- ...InteractionParameterFittingPiperazine.java | 126 +- .../AntoineParameter/TestSolidAntoine.java | 111 +- .../AntoineParameter/TestSolidAntoine_S8.java | 91 +- .../TestAcentricSchwartzentruber.java | 149 +- .../TestFitToAntoineVapPres.java | 106 +- .../TestMathiasCopeman.java | 211 +- .../TestMathiasCopemanToDewPoint.java | 291 +- .../acentricFactorFitting/TestTwuCoon.java | 213 +- .../TestFurstIonicParameterFunction.java | 307 +- .../hydrate/TestHydrateFunction.java | 151 +- .../BaseOperation.java | 82 +- .../OperationInterface.java | 9 - .../ThermodynamicOperations.java | 3877 ++++++++--------- .../ChemicalEquilibrium.java | 138 +- .../flashOps/Flash.java | 839 ++-- .../saturationOps/constantDutyFlash.java | 276 +- .../saturationOps/cricondenBarTemp1.java | 9 - .../HPTphaseEnvelope.java | 179 +- .../pTphaseEnvelope.java | 8 - .../pTphaseEnvelope1.java | 853 ++-- .../pTphaseEnvelopeMay.java | 1446 +++--- .../pTphaseEnvelopeNew.java | 733 ++-- .../reactiveCurves/pLoadingCurve2.java | 341 +- .../pipeFlowSystem/PipeFlowSystemTest.java | 11 +- .../util/example/PressureLoadingCurve.java | 108 +- 57 files changed, 8725 insertions(+), 9012 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 14a6208281..4e980e2539 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "java.configuration.updateBuildConfiguration": "interactive", "[java]": { - "editor.defaultFormatter": "serikb.google-java-format", + "editor.defaultFormatter": "redhat.java", "editor.formatOnSave": true, }, "java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml", diff --git a/src/main/java/neqsim/dataPresentation/fileHandeling/createTextFile/TextFile.java b/src/main/java/neqsim/dataPresentation/fileHandeling/createTextFile/TextFile.java index 0c975642dc..e1ac4c1465 100644 --- a/src/main/java/neqsim/dataPresentation/fileHandeling/createTextFile/TextFile.java +++ b/src/main/java/neqsim/dataPresentation/fileHandeling/createTextFile/TextFile.java @@ -12,98 +12,97 @@ * @version $Id: $Id */ public class TextFile implements java.io.Serializable { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - String fileName = "c:/example.txt"; - String[][] values; - // NetcdfFileWriteable ncfile; + String fileName = "c:/example.txt"; + String[][] values; - /** - *
- * Constructor for TextFile. - *
- */ - public TextFile() {} + /** + *+ * Constructor for TextFile. + *
+ */ + public TextFile() {} - /** - *- * setOutputFileName. - *
- * - * @param name a {@link java.lang.String} object - */ - public void setOutputFileName(String name) { - this.fileName = name; - } + /** + *+ * setOutputFileName. + *
+ * + * @param name a {@link java.lang.String} object + */ + public void setOutputFileName(String name) { + this.fileName = name; + } - /** - *- * newFile. - *
- * - * @param name a {@link java.lang.String} object - */ - public void newFile(String name) { - try (FileWriter out = new FileWriter(new File(name))) { - out.write(""); - } catch (Exception e) { - System.out.println(e.toString()); - } + /** + *+ * newFile. + *
+ * + * @param name a {@link java.lang.String} object + */ + public void newFile(String name) { + try (FileWriter out = new FileWriter(new File(name))) { + out.write(""); + } catch (Exception e) { + System.out.println(e.toString()); } + } - /** - *
- * Setter for the field values
.
- *
+ * Setter for the field values
.
+ *
- * Setter for the field values
.
- *
+ * Setter for the field values
.
+ *
- * createFile. - *
- */ - public void createFile() { - System.out.println("writing " + values[0][0] + " data"); - System.out.println("length " + values.length); - System.out.println("length2 " + values[0].length); + /** + *+ * createFile. + *
+ */ + public void createFile() { + System.out.println("writing " + values[0][0] + " data"); + System.out.println("length " + values.length); + System.out.println("length2 " + values[0].length); - try (FileWriter out = new FileWriter(new File(fileName), true)) { - for (int i = 0; i < values.length; i++) { - for (int j = 0; j < values[0].length; j++) { - if (values[i][j] != null) { - out.write(values[i][j]); - } - out.write("\t"); - } - out.write("\n"); - } - out.flush(); - } catch (Exception e) { - System.err.println("error writing file: " + e.toString()); + try (FileWriter out = new FileWriter(new File(fileName), true)) { + for (int i = 0; i < values.length; i++) { + for (int j = 0; j < values[0].length; j++) { + if (values[i][j] != null) { + out.write(values[i][j]); + } + out.write("\t"); } - System.out.println("writing data to file: " + fileName + " ... ok"); + out.write("\n"); + } + out.flush(); + } catch (Exception e) { + System.err.println("error writing file: " + e.toString()); } + System.out.println("writing data to file: " + fileName + " ... ok"); + } } diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/stirredCellSystem/StirredCellSystem.java b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/stirredCellSystem/StirredCellSystem.java index fbcc61469e..24bc8c906d 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/stirredCellSystem/StirredCellSystem.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/stirredCellSystem/StirredCellSystem.java @@ -11,154 +11,153 @@ * @version $Id: $Id */ public class StirredCellSystem - extends neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.TwoPhaseFlowSystem { - private static final long serialVersionUID = 1000; - - /** - *- * Constructor for StirredCellSystem. - *
- */ - public StirredCellSystem() {} - - /** {@inheritDoc} */ - @Override - public void createSystem() { - flowLeg = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg[this.getNumberOfLegs()]; - - for (int i = 0; i < getNumberOfLegs(); i++) { - flowLeg[i] = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg(); - } - - flowNode = new neqsim.fluidMechanics.flowNode.FlowNodeInterface[totalNumberOfNodes]; - flowNode[0] = - new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhaseStirredCellNode.StirredCellNode( - thermoSystem, equipmentGeometry[0]); - - flowNode[totalNumberOfNodes - 1] = flowNode[0].getNextNode(); - - super.createSystem(); - this.setNodes(); + extends neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.TwoPhaseFlowSystem { + private static final long serialVersionUID = 1000; + + /** + *+ * Constructor for StirredCellSystem. + *
+ */ + public StirredCellSystem() {} + + /** {@inheritDoc} */ + @Override + public void createSystem() { + flowLeg = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg[this.getNumberOfLegs()]; + + for (int i = 0; i < getNumberOfLegs(); i++) { + flowLeg[i] = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg(); } - /** {@inheritDoc} */ - @Override - public void init() { - for (int j = 0; j < getTotalNumberOfNodes(); j++) { - flowNode[j].init(); - } - - for (int j = 0; j < getTotalNumberOfNodes(); j++) { - for (int phase = 0; phase < 2; phase++) { - flowNode[j].setVelocityOut(phase, this.flowNode[j].getVelocity(phase)); - } - } - - for (int k = 1; k < getTotalNumberOfNodes(); k++) { - for (int phase = 0; phase < 2; phase++) { - this.flowNode[k].setVelocityIn(phase, this.flowNode[k - 1].getVelocityOut(phase)); - } - } - } + flowNode = new neqsim.fluidMechanics.flowNode.FlowNodeInterface[totalNumberOfNodes]; + flowNode[0] = + new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhaseStirredCellNode.StirredCellNode( + thermoSystem, equipmentGeometry[0]); + + flowNode[totalNumberOfNodes - 1] = flowNode[0].getNextNode(); + + super.createSystem(); + this.setNodes(); + } - /** {@inheritDoc} */ - @Override - public void solveSteadyState(int solverType) { - flowSolver = - new neqsim.fluidMechanics.flowSolver.twoPhaseFlowSolver.stirredCellSolver.StirredCellSolver( - this, getSystemLength(), getTotalNumberOfNodes(), false); + /** {@inheritDoc} */ + @Override + public void init() { + for (int j = 0; j < getTotalNumberOfNodes(); j++) { + flowNode[j].init(); } - /** {@inheritDoc} */ - @Override - public void solveTransient(int solverType) { - getTimeSeries().init(this); - display = - new neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.twoPhaseFlowVisualization.twoPhasePipeFlowVisualization.TwoPhasePipeFlowVisualization( - this.getTotalNumberOfNodes(), getTimeSeries().getTime().length); - for (int i = 0; i < this.getTimeSeries().getTime().length; i++) { - getNode(0).setBulkSystem(this.getTimeSeries().getThermoSystem()[i]); - flowNode[0].initFlowCalc(); - flowNode[0].init(); - flowNode[0].setVelocityIn(this.flowNode[0].getVelocity()); - flowNode[getTotalNumberOfNodes() - 1] - .setVelocity(this.getTimeSeries().getOutletMolarFlowRates()[i]); - // System.out.println("vel: " + this.flowNode[0].getVelocity()); - // getSolver().setTimeStep(this.getTimeSeries().getTimeStep()[i]); - // System.out.println("time step: " + i + " " + - // this.getTimeSeries().getTimeStep()[i]); - System.out.println("time: " + i + " " + this.getTimeSeries().getTime()[i]); - flowSolver.solveTDMA(); - display.setNextData(this, this.getTimeSeries().getTime(i)); - } + for (int j = 0; j < getTotalNumberOfNodes(); j++) { + for (int phase = 0; phase < 2; phase++) { + flowNode[j].setVelocityOut(phase, this.flowNode[j].getVelocity(phase)); + } } - /** - *- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - // Initierer et nyt rorsystem - neqsim.fluidMechanics.flowSystem.FlowSystemInterface pipe = new StirredCellSystem(); - - // Definerer termodyanmikken5 - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos(295.3, 5.0); - testSystem.addComponent("methane", 0.11152181, 0); - // testSystem.addComponent("ethane", 0.0011152181, 0); - testSystem.addComponent("water", 0.04962204876, 1); - // testSystem.addComponent("TEG", 0.4962204876, 1); - testSystem.setMixingRule(2); - // benytter klassiske blandingsregler - - pipe.setInletThermoSystem(testSystem); // setter termodyanmikken for rorsystemet - pipe.setNumberOfLegs(1); // deler inn roret i et gitt antall legger - pipe.setNumberOfNodesInLeg(10); // setter antall nodepunkter (beregningspunkter/grid) pr. - // leg - double[] height = {0, 0}; - double[] length = {0.0, 10.0}; - double[] outerTemperature = {278.0, 278.0}; - double[] outerHeatTransferCoef = {2.0, 2.0}; - double[] wallHeatTransferCoef = {2.0, 2.0}; - - pipe.setLegHeights(height); // setter inn hoyde for hver leg-ende - pipe.setLegPositions(length); // setter avstand til hver leg-ende - pipe.setLegOuterTemperatures(outerTemperature); - pipe.setLegOuterHeatTransferCoefficients(outerHeatTransferCoef); - pipe.setLegWallHeatTransferCoefficients(wallHeatTransferCoef); - - neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGemometry = - new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData[6]; // Deffinerer - // geometrien - // for - // roret - double[] pipeDiameter = {0.02588, 0.02588}; - for (int i = 0; i < pipeDiameter.length; i++) { - pipeGemometry[i] = - new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData(pipeDiameter[i]); - } - pipe.setEquipmentGeometry(pipeGemometry); // setter inn rorgeometrien for hver leg - // utforer bergninger - pipe.createSystem(); - pipe.init(); - - double[] times = {0, 10}; - pipe.getTimeSeries().setTimes(times); - SystemInterface[] systems = {testSystem, testSystem, testSystem}; - pipe.getTimeSeries().setInletThermoSystems(systems); - pipe.getTimeSeries().setNumberOfTimeStepsInInterval(5); - pipe.solveSteadyState(2); - pipe.solveTransient(2); - System.out.println("disp"); - pipe.getNode(0).display(); - // pipe.solveTransient(2); - // pipe.solveTransient(2); - - pipe.getNode(0).display(); - pipe.getNode(10).display(); - // pipe.getDisplay().createNetCdfFile("c:/temp5.nc"); + for (int k = 1; k < getTotalNumberOfNodes(); k++) { + for (int phase = 0; phase < 2; phase++) { + this.flowNode[k].setVelocityIn(phase, this.flowNode[k - 1].getVelocityOut(phase)); + } + } + } + + /** {@inheritDoc} */ + @Override + public void solveSteadyState(int solverType) { + flowSolver = + new neqsim.fluidMechanics.flowSolver.twoPhaseFlowSolver.stirredCellSolver.StirredCellSolver( + this, getSystemLength(), getTotalNumberOfNodes(), false); + } + + /** {@inheritDoc} */ + @Override + public void solveTransient(int solverType) { + getTimeSeries().init(this); + display = + new neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.twoPhaseFlowVisualization.twoPhasePipeFlowVisualization.TwoPhasePipeFlowVisualization( + this.getTotalNumberOfNodes(), getTimeSeries().getTime().length); + for (int i = 0; i < this.getTimeSeries().getTime().length; i++) { + getNode(0).setBulkSystem(this.getTimeSeries().getThermoSystem()[i]); + flowNode[0].initFlowCalc(); + flowNode[0].init(); + flowNode[0].setVelocityIn(this.flowNode[0].getVelocity()); + flowNode[getTotalNumberOfNodes() - 1] + .setVelocity(this.getTimeSeries().getOutletMolarFlowRates()[i]); + // System.out.println("vel: " + this.flowNode[0].getVelocity()); + // getSolver().setTimeStep(this.getTimeSeries().getTimeStep()[i]); + // System.out.println("time step: " + i + " " + + // this.getTimeSeries().getTimeStep()[i]); + System.out.println("time: " + i + " " + this.getTimeSeries().getTime()[i]); + flowSolver.solveTDMA(); + display.setNextData(this, this.getTimeSeries().getTime(i)); + } + } + + /** + *+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + // Initierer et nyt rorsystem + neqsim.fluidMechanics.flowSystem.FlowSystemInterface pipe = new StirredCellSystem(); + + // Definerer termodyanmikken5 + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos(295.3, 5.0); + testSystem.addComponent("methane", 0.11152181, 0); + // testSystem.addComponent("ethane", 0.0011152181, 0); + testSystem.addComponent("water", 0.04962204876, 1); + // testSystem.addComponent("TEG", 0.4962204876, 1); + testSystem.setMixingRule(2); + // benytter klassiske blandingsregler + + pipe.setInletThermoSystem(testSystem); // setter termodyanmikken for rorsystemet + pipe.setNumberOfLegs(1); // deler inn roret i et gitt antall legger + pipe.setNumberOfNodesInLeg(10); // setter antall nodepunkter (beregningspunkter/grid) pr. + // leg + double[] height = {0, 0}; + double[] length = {0.0, 10.0}; + double[] outerTemperature = {278.0, 278.0}; + double[] outerHeatTransferCoef = {2.0, 2.0}; + double[] wallHeatTransferCoef = {2.0, 2.0}; + + pipe.setLegHeights(height); // setter inn hoyde for hver leg-ende + pipe.setLegPositions(length); // setter avstand til hver leg-ende + pipe.setLegOuterTemperatures(outerTemperature); + pipe.setLegOuterHeatTransferCoefficients(outerHeatTransferCoef); + pipe.setLegWallHeatTransferCoefficients(wallHeatTransferCoef); + + neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGemometry = + new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData[6]; // Deffinerer + // geometrien + // for + // roret + double[] pipeDiameter = {0.02588, 0.02588}; + for (int i = 0; i < pipeDiameter.length; i++) { + pipeGemometry[i] = + new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData(pipeDiameter[i]); } + pipe.setEquipmentGeometry(pipeGemometry); // setter inn rorgeometrien for hver leg + // utforer bergninger + pipe.createSystem(); + pipe.init(); + + double[] times = {0, 10}; + pipe.getTimeSeries().setTimes(times); + SystemInterface[] systems = {testSystem, testSystem, testSystem}; + pipe.getTimeSeries().setInletThermoSystems(systems); + pipe.getTimeSeries().setNumberOfTimeStepsInInterval(5); + pipe.solveSteadyState(2); + pipe.solveTransient(2); + System.out.println("disp"); + pipe.getNode(0).display(); + // pipe.solveTransient(2); + // pipe.solveTransient(2); + + pipe.getNode(0).display(); + pipe.getNode(10).display(); + } } diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhasePipeFlowSystem/TwoPhasePipeFlowSystem.java b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhasePipeFlowSystem/TwoPhasePipeFlowSystem.java index ffebbde898..5ffc04a681 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhasePipeFlowSystem/TwoPhasePipeFlowSystem.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhasePipeFlowSystem/TwoPhasePipeFlowSystem.java @@ -1,166 +1,171 @@ package neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.twoPhasePipeFlowSystem; /** - *TwoPhasePipeFlowSystem class.
+ *+ * TwoPhasePipeFlowSystem class. + *
* * @author asmund * @version $Id: $Id */ public class TwoPhasePipeFlowSystem - extends neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.TwoPhaseFlowSystem { - private static final long serialVersionUID = 1000; - - /** - *Constructor for TwoPhasePipeFlowSystem.
- */ - public TwoPhasePipeFlowSystem() {} - - /** {@inheritDoc} */ - @Override - public void createSystem() { - // thermoSystem.init(1); - flowLeg = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg[this.getNumberOfLegs()]; - - for (int i = 0; i < getNumberOfLegs(); i++) { - flowLeg[i] = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg(); - } - - flowNode = new neqsim.fluidMechanics.flowNode.FlowNodeInterface[totalNumberOfNodes]; - if (initFlowPattern.equals("stratified")) { - flowNode[0] = - new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.StratifiedFlowNode( - thermoSystem, equipmentGeometry[0]); - } else if (initFlowPattern.equals("annular")) { - flowNode[0] = - new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.AnnularFlow( - thermoSystem, equipmentGeometry[0]); - } else { - flowNode[0] = - new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.StratifiedFlowNode( - thermoSystem, equipmentGeometry[0]); - } - flowNode[totalNumberOfNodes - 1] = flowNode[0].getNextNode(); - - super.createSystem(); - this.setNodes(); + extends neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.TwoPhaseFlowSystem { + private static final long serialVersionUID = 1000; + + /** + *+ * Constructor for TwoPhasePipeFlowSystem. + *
+ */ + public TwoPhasePipeFlowSystem() {} + + /** {@inheritDoc} */ + @Override + public void createSystem() { + // thermoSystem.init(1); + flowLeg = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg[this.getNumberOfLegs()]; + + for (int i = 0; i < getNumberOfLegs(); i++) { + flowLeg[i] = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg(); } - /** {@inheritDoc} */ - @Override - public void init() { - for (int j = 0; j < getTotalNumberOfNodes(); j++) { - flowNode[j].initFlowCalc(); - flowNode[j].init(); - } - - for (int j = 0; j < getTotalNumberOfNodes(); j++) { - for (int phase = 0; phase < 2; phase++) { - flowNode[j].setVelocityOut(phase, this.flowNode[j].getVelocity(phase)); - } - } - - for (int k = 1; k < getTotalNumberOfNodes(); k++) { - for (int phase = 0; phase < 2; phase++) { - this.flowNode[k].setVelocityIn(phase, this.flowNode[k - 1].getVelocityOut(phase)); - } - } + flowNode = new neqsim.fluidMechanics.flowNode.FlowNodeInterface[totalNumberOfNodes]; + if (initFlowPattern.equals("stratified")) { + flowNode[0] = + new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.StratifiedFlowNode( + thermoSystem, equipmentGeometry[0]); + } else if (initFlowPattern.equals("annular")) { + flowNode[0] = + new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.AnnularFlow( + thermoSystem, equipmentGeometry[0]); + } else { + flowNode[0] = + new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.StratifiedFlowNode( + thermoSystem, equipmentGeometry[0]); } - - /** {@inheritDoc} */ - @Override - public void solveSteadyState(int solverType) { - double[] times = {0.0}; - display = - new neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.twoPhaseFlowVisualization.twoPhasePipeFlowVisualization.TwoPhasePipeFlowVisualization( - this.getTotalNumberOfNodes(), 1); - getTimeSeries().setTimes(times); - neqsim.thermo.system.SystemInterface[] systems = {flowNode[0].getBulkSystem()}; - getTimeSeries().setInletThermoSystems(systems); - getTimeSeries().setNumberOfTimeStepsInInterval(1); - double[] outletFlowRates = {0.0, 0.0}; - getTimeSeries().setOutletMolarFlowRate(outletFlowRates); - - flowSolver = - new neqsim.fluidMechanics.flowSolver.twoPhaseFlowSolver.twoPhasePipeFlowSolver.TwoPhaseFixedStaggeredGridSolver( - this, getSystemLength(), this.getTotalNumberOfNodes(), false); - flowSolver.setSolverType(solverType); - flowSolver.solveTDMA(); - - getTimeSeries().init(this); - display.setNextData(this); + flowNode[totalNumberOfNodes - 1] = flowNode[0].getNextNode(); + + super.createSystem(); + this.setNodes(); + } + + /** {@inheritDoc} */ + @Override + public void init() { + for (int j = 0; j < getTotalNumberOfNodes(); j++) { + flowNode[j].initFlowCalc(); + flowNode[j].init(); } - /** {@inheritDoc} */ - @Override - public void solveTransient(int type) { - // pipeSolver pipeSolve = new pipeSolver(this, getSystemLength(), - // getTotalNumberOfNodes()); - // pipeSolve.solveTDMA(); + for (int j = 0; j < getTotalNumberOfNodes(); j++) { + for (int phase = 0; phase < 2; phase++) { + flowNode[j].setVelocityOut(phase, this.flowNode[j].getVelocity(phase)); + } } - /** - *main.
- * - * @param args an array of {@link java.lang.String} objects - */ - @SuppressWarnings("unused") - public static void main(String[] args) { - // Initierer et nyt rorsystem - neqsim.fluidMechanics.flowSystem.FlowSystemInterface pipe = new TwoPhasePipeFlowSystem(); - - // Definerer termodyanmikken5 - initierer et system som benytter SRK tilstandsligning - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos(295.3, 5.0); - - // med trykk 305.3 K og 125 bar - // gjor termodynamiske Flash rutiner tilgjengelige - neqsim.thermodynamicOperations.ThermodynamicOperations testOps = - new neqsim.thermodynamicOperations.ThermodynamicOperations(testSystem); - testSystem.addComponent("methane", 0.11152181, 0); - // testSystem.addComponent("ethane", 0.0011152181, 0); - testSystem.addComponent("water", 0.04962204876, 1); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - // benytter klassiske blandingsregler - - pipe.setInletThermoSystem(testSystem); // setter termodyanmikken for rorsystemet - pipe.setNumberOfLegs(5); // deler inn roret i et gitt antall legger - pipe.setNumberOfNodesInLeg(10); // setter antall nodepunkter (beregningspunkter/grid) pr. - // leg - double[] height = {0, 0, 0, 0, 0, 0}; - double[] length = {0.0, 1.7, 3.5, 5.0, 7.5, 10.4}; - double[] outerTemperature = {278.0, 278.0, 278.0, 278.0, 278.0, 278.0};// , 278.0, 275.0, - // 275.0, 275.0, - // 275.0}; - double[] roughness = {1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5}; - double[] outHeatCoef = {5.0, 5.0, 5.0, 5.0, 5.0, 5.0}; - double[] wallHeacCoef = {15.0, 15.0, 15.0, 15.0, 15.0, 15.0}; - - pipe.setLegHeights(height); // setter inn hoyde for hver leg-ende - pipe.setLegPositions(length); // setter avstand til hver leg-ende - pipe.setLegOuterTemperatures(outerTemperature); - pipe.setLegWallHeatTransferCoefficients(wallHeacCoef); - pipe.setLegOuterHeatTransferCoefficients(outHeatCoef); - - // Definerer geometrien for roret - neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGemometry = - new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData[6]; - double[] pipeDiameter = {0.02588, 0.02588, 0.02588, 0.02588, 0.02588, 0.02588}; - for (int i = 0; i < pipeDiameter.length; i++) { - pipeGemometry[i] = - new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData(pipeDiameter[i]); - } - pipe.setEquipmentGeometry(pipeGemometry); // setter inn rorgeometrien for hver leg - // utforer bergninger - pipe.createSystem(); - pipe.init(); - - pipe.solveSteadyState(2); - pipe.getNode(30).display(); - // pipe.calcFluxes(); - // pipe.getDisplay().displayResult("temperature"); - // pipe.getDisplay().createNetCdfFile("c:/temp5.nc"); - // pipe.displayResults(); - // testOps.TPflash(); - // testOps.displayResult(); + for (int k = 1; k < getTotalNumberOfNodes(); k++) { + for (int phase = 0; phase < 2; phase++) { + this.flowNode[k].setVelocityIn(phase, this.flowNode[k - 1].getVelocityOut(phase)); + } + } + } + + /** {@inheritDoc} */ + @Override + public void solveSteadyState(int solverType) { + double[] times = {0.0}; + display = + new neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.twoPhaseFlowVisualization.twoPhasePipeFlowVisualization.TwoPhasePipeFlowVisualization( + this.getTotalNumberOfNodes(), 1); + getTimeSeries().setTimes(times); + neqsim.thermo.system.SystemInterface[] systems = {flowNode[0].getBulkSystem()}; + getTimeSeries().setInletThermoSystems(systems); + getTimeSeries().setNumberOfTimeStepsInInterval(1); + double[] outletFlowRates = {0.0, 0.0}; + getTimeSeries().setOutletMolarFlowRate(outletFlowRates); + + flowSolver = + new neqsim.fluidMechanics.flowSolver.twoPhaseFlowSolver.twoPhasePipeFlowSolver.TwoPhaseFixedStaggeredGridSolver( + this, getSystemLength(), this.getTotalNumberOfNodes(), false); + flowSolver.setSolverType(solverType); + flowSolver.solveTDMA(); + + getTimeSeries().init(this); + display.setNextData(this); + } + + /** {@inheritDoc} */ + @Override + public void solveTransient(int type) { + // pipeSolver pipeSolve = new pipeSolver(this, getSystemLength(), + // getTotalNumberOfNodes()); + // pipeSolve.solveTDMA(); + } + + /** + *+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + @SuppressWarnings("unused") + public static void main(String[] args) { + // Initierer et nyt rorsystem + neqsim.fluidMechanics.flowSystem.FlowSystemInterface pipe = new TwoPhasePipeFlowSystem(); + + // Definerer termodyanmikken5 - initierer et system som benytter SRK tilstandsligning + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos(295.3, 5.0); + + // med trykk 305.3 K og 125 bar - // gjor termodynamiske Flash rutiner tilgjengelige + neqsim.thermodynamicOperations.ThermodynamicOperations testOps = + new neqsim.thermodynamicOperations.ThermodynamicOperations(testSystem); + testSystem.addComponent("methane", 0.11152181, 0); + // testSystem.addComponent("ethane", 0.0011152181, 0); + testSystem.addComponent("water", 0.04962204876, 1); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + // benytter klassiske blandingsregler + + pipe.setInletThermoSystem(testSystem); // setter termodyanmikken for rorsystemet + pipe.setNumberOfLegs(5); // deler inn roret i et gitt antall legger + pipe.setNumberOfNodesInLeg(10); // setter antall nodepunkter (beregningspunkter/grid) pr. + // leg + double[] height = {0, 0, 0, 0, 0, 0}; + double[] length = {0.0, 1.7, 3.5, 5.0, 7.5, 10.4}; + double[] outerTemperature = {278.0, 278.0, 278.0, 278.0, 278.0, 278.0};// , 278.0, 275.0, + // 275.0, 275.0, + // 275.0}; + double[] roughness = {1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5}; + double[] outHeatCoef = {5.0, 5.0, 5.0, 5.0, 5.0, 5.0}; + double[] wallHeacCoef = {15.0, 15.0, 15.0, 15.0, 15.0, 15.0}; + + pipe.setLegHeights(height); // setter inn hoyde for hver leg-ende + pipe.setLegPositions(length); // setter avstand til hver leg-ende + pipe.setLegOuterTemperatures(outerTemperature); + pipe.setLegWallHeatTransferCoefficients(wallHeacCoef); + pipe.setLegOuterHeatTransferCoefficients(outHeatCoef); + + // Definerer geometrien for roret + neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGemometry = + new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData[6]; + double[] pipeDiameter = {0.02588, 0.02588, 0.02588, 0.02588, 0.02588, 0.02588}; + for (int i = 0; i < pipeDiameter.length; i++) { + pipeGemometry[i] = + new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData(pipeDiameter[i]); } + pipe.setEquipmentGeometry(pipeGemometry); // setter inn rorgeometrien for hver leg + // utforer bergninger + pipe.createSystem(); + pipe.init(); + + pipe.solveSteadyState(2); + pipe.getNode(30).display(); + // pipe.calcFluxes(); + // pipe.getDisplay().displayResult("temperature"); + // pipe.displayResults(); + // testOps.TPflash(); + // testOps.displayResult(); + } } diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhasePipeFlowSystem/TwoPhasePipeFlowSystemReac.java b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhasePipeFlowSystem/TwoPhasePipeFlowSystemReac.java index ac541a3cd2..e0af65a0d6 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhasePipeFlowSystem/TwoPhasePipeFlowSystemReac.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhasePipeFlowSystem/TwoPhasePipeFlowSystemReac.java @@ -13,84 +13,81 @@ * @version $Id: $Id */ public class TwoPhasePipeFlowSystemReac extends TwoPhasePipeFlowSystem { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - /** - *- * Constructor for TwoPhasePipeFlowSystemReac. - *
- */ - public TwoPhasePipeFlowSystemReac() {} + /** + *+ * Constructor for TwoPhasePipeFlowSystemReac. + *
+ */ + public TwoPhasePipeFlowSystemReac() {} - /** - *- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - // Initierer et nyt rorsystem - neqsim.fluidMechanics.flowSystem.FlowSystemInterface pipe = - new TwoPhasePipeFlowSystemReac(); + /** + *+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + // Initierer et nyt rorsystem + neqsim.fluidMechanics.flowSystem.FlowSystemInterface pipe = new TwoPhasePipeFlowSystemReac(); - SystemInterface testSystem = new SystemFurstElectrolyteEos(295.3, 50.01325); - testSystem.addComponent("methane", 50.11152187, "Nlitre/min", 0); - testSystem.addComponent("CO2", 50.11152181, "Nlitre/min", 0); - testSystem.addComponent("water", 0.5662204876, "kg/min", 1); - testSystem.addComponent("MDEA", 0.5662204876, "kg/min", 1); + SystemInterface testSystem = new SystemFurstElectrolyteEos(295.3, 50.01325); + testSystem.addComponent("methane", 50.11152187, "Nlitre/min", 0); + testSystem.addComponent("CO2", 50.11152181, "Nlitre/min", 0); + testSystem.addComponent("water", 0.5662204876, "kg/min", 1); + testSystem.addComponent("MDEA", 0.5662204876, "kg/min", 1); - testSystem.chemicalReactionInit(); - testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.setPhysicalPropertyModel(3); - // testOps.TPflash(); - // testSystem.display(); + testSystem.chemicalReactionInit(); + testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.setPhysicalPropertyModel(3); + // testOps.TPflash(); + // testSystem.display(); - // testSystem.setNumericDerivatives(true); - testSystem.initPhysicalProperties(); + // testSystem.setNumericDerivatives(true); + testSystem.initPhysicalProperties(); - pipe.setInletThermoSystem(testSystem); // setter termodyanmikken for rorsystemet - pipe.setNumberOfLegs(3); // deler inn roret i et gitt antall legger - pipe.setNumberOfNodesInLeg(10); // setter antall nodepunkter (beregningspunkter/grid) pr. - // leg + pipe.setInletThermoSystem(testSystem); // setter termodyanmikken for rorsystemet + pipe.setNumberOfLegs(3); // deler inn roret i et gitt antall legger + pipe.setNumberOfNodesInLeg(10); // setter antall nodepunkter (beregningspunkter/grid) pr. + // leg - double[] height = {0, 0, 0, 0, 0, 0}; - double[] length = {0.0, 0.03, 0.07, 0.13, 2.5, 3.7}; - double[] outerTemperature = - {278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 275.0, 275.0, 275.0, 275.0}; + double[] height = {0, 0, 0, 0, 0, 0}; + double[] length = {0.0, 0.03, 0.07, 0.13, 2.5, 3.7}; + double[] outerTemperature = + {278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 275.0, 275.0, 275.0, 275.0}; - pipe.setLegHeights(height); // setter inn hoyde for hver leg-ende - pipe.setLegPositions(length); // setter avstand til hver leg-ende - pipe.setLegOuterTemperatures(outerTemperature); + pipe.setLegHeights(height); // setter inn hoyde for hver leg-ende + pipe.setLegPositions(length); // setter avstand til hver leg-ende + pipe.setLegOuterTemperatures(outerTemperature); - neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGemometry = - new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData[5]; // Deffinerer - // geometrien - // for - // roret - double[] pipeDiameter = {0.025, 0.025, 0.025, 0.025, 0.025}; - for (int i = 0; i < pipeDiameter.length; i++) { - pipeGemometry[i] = - new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData(pipeDiameter[i]); - } - pipe.setEquipmentGeometry(pipeGemometry); // setter inn rorgeometrien for hver leg - // utforer bergninger - pipe.createSystem(); - pipe.setEquilibriumMassTransfer(false); - pipe.setEquilibriumHeatTransfer(false); - pipe.init(); + neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGemometry = + new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData[5]; // Deffinerer + // geometrien + // for + // roret + double[] pipeDiameter = {0.025, 0.025, 0.025, 0.025, 0.025}; + for (int i = 0; i < pipeDiameter.length; i++) { + pipeGemometry[i] = + new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData(pipeDiameter[i]); + } + pipe.setEquipmentGeometry(pipeGemometry); // setter inn rorgeometrien for hver leg + // utforer bergninger + pipe.createSystem(); + pipe.setEquilibriumMassTransfer(false); + pipe.setEquilibriumHeatTransfer(false); + pipe.init(); - pipe.solveSteadyState(2); - ThermodynamicOperations testOps = - new ThermodynamicOperations(pipe.getNode(2).getBulkSystem()); - testOps.TPflash(); + pipe.solveSteadyState(2); + ThermodynamicOperations testOps = new ThermodynamicOperations(pipe.getNode(2).getBulkSystem()); + testOps.TPflash(); - // pipe.calcFluxes(); - // pipe.print(); - pipe.getDisplay().createNetCdfFile("c:/temp5.nc"); - // pipe.displayResult(); - // testOps.TPflash(); - // testOps.displayResult(); - } + // pipe.calcFluxes(); + // pipe.print(); + // pipe.displayResult(); + // testOps.TPflash(); + // testOps.displayResult(); + } } diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhaseReactorFlowSystem/TwoPhaseReactorFlowSystem.java b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhaseReactorFlowSystem/TwoPhaseReactorFlowSystem.java index e405fa2505..4f28059db9 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhaseReactorFlowSystem/TwoPhaseReactorFlowSystem.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhaseReactorFlowSystem/TwoPhaseReactorFlowSystem.java @@ -159,7 +159,6 @@ public static void main(String[] args) { pipe.solveSteadyState(2); // pipe.calcFluxes(); // pipe.getDisplay().displayResult("temperature"); - pipe.getDisplay().createNetCdfFile("c:/temp5.nc"); // pipe.displayResults(); // testOps.TPflash(); // testOps.displayResult(); diff --git a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/FlowSystemVisualization.java b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/FlowSystemVisualization.java index a504ca6d3b..104846ebf3 100644 --- a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/FlowSystemVisualization.java +++ b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/FlowSystemVisualization.java @@ -13,78 +13,73 @@ * @version $Id: $Id */ public class FlowSystemVisualization implements FlowSystemVisualizationInterface { - protected FlowNodeVisualizationInterface[][] flowNodes; - protected FlowSystemInterface[] flowSystem; - protected int time = 0; - protected double[] absTime; + protected FlowNodeVisualizationInterface[][] flowNodes; + protected FlowSystemInterface[] flowSystem; + protected int time = 0; + protected double[] absTime; - /** - *- * Constructor for FlowSystemVisualization. - *
- */ - public FlowSystemVisualization() {} + /** + *+ * Constructor for FlowSystemVisualization. + *
+ */ + public FlowSystemVisualization() {} - /** - *- * Constructor for FlowSystemVisualization. - *
- * - * @param nodes a int - * @param timeSteps a int - */ - public FlowSystemVisualization(int nodes, int timeSteps) { - flowNodes = new FlowNodeVisualization[timeSteps][nodes]; - flowSystem = new FlowSystemInterface[timeSteps]; - absTime = new double[timeSteps]; - for (int i = 0; i < timeSteps; i++) { - for (int j = 0; j < nodes; j++) { - flowNodes[i][j] = new FlowNodeVisualization(); - } - } - // System.out.println("nodes " + nodes); - // System.out.println("times " + time); + /** + *+ * Constructor for FlowSystemVisualization. + *
+ * + * @param nodes a int + * @param timeSteps a int + */ + public FlowSystemVisualization(int nodes, int timeSteps) { + flowNodes = new FlowNodeVisualization[timeSteps][nodes]; + flowSystem = new FlowSystemInterface[timeSteps]; + absTime = new double[timeSteps]; + for (int i = 0; i < timeSteps; i++) { + for (int j = 0; j < nodes; j++) { + flowNodes[i][j] = new FlowNodeVisualization(); + } } + // System.out.println("nodes " + nodes); + // System.out.println("times " + time); + } - /** {@inheritDoc} */ - @Override - public void setNextData(FlowSystemInterface system) { - flowSystem[time] = system; - absTime[time] = 0; - for (int i = 0; i < flowNodes[time].length; i++) { - flowNodes[time][i].setData(system.getNode(i)); - } - time++; - // System.out.println("time " + time); + /** {@inheritDoc} */ + @Override + public void setNextData(FlowSystemInterface system) { + flowSystem[time] = system; + absTime[time] = 0; + for (int i = 0; i < flowNodes[time].length; i++) { + flowNodes[time][i].setData(system.getNode(i)); } + time++; + // System.out.println("time " + time); + } - /** {@inheritDoc} */ - @Override - public void setNextData(FlowSystemInterface system, double abstime) { - flowSystem[time] = system; - absTime[time] = abstime; - for (int i = 0; i < flowNodes[time].length; i++) { - flowNodes[time][i].setData(system.getNode(i)); - } - time++; + /** {@inheritDoc} */ + @Override + public void setNextData(FlowSystemInterface system, double abstime) { + flowSystem[time] = system; + absTime[time] = abstime; + for (int i = 0; i < flowNodes[time].length; i++) { + flowNodes[time][i].setData(system.getNode(i)); } + time++; + } - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) { - System.out.println("ok..."); - for (int j = 0; j < time; j++) { - for (int i = 0; i < flowNodes[j].length; i++) { - System.out.println("time " + time + " pres " + flowNodes[j][i].getPressure(0)); - } - } - } + /* + * public void createNetCdfFile(String name) { System.out.println("ok..."); for (int j = 0; j < + * time; j++) { for (int i = 0; i < flowNodes[j].length; i++) { System.out.println("time " + time + * + " pres " + flowNodes[j][i].getPressure(0)); } } } + */ - /** {@inheritDoc} */ - @Override - public void setPoints() {} + /** {@inheritDoc} */ + @Override + public void setPoints() {} - /** {@inheritDoc} */ - @Override - public void displayResult(String name) {} + /** {@inheritDoc} */ + @Override + public void displayResult(String name) {} } diff --git a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/FlowSystemVisualizationInterface.java b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/FlowSystemVisualizationInterface.java index e760598231..5040f13dee 100644 --- a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/FlowSystemVisualizationInterface.java +++ b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/FlowSystemVisualizationInterface.java @@ -45,13 +45,4 @@ public interface FlowSystemVisualizationInterface { * @param abstime a double */ public void setNextData(FlowSystemInterface system, double abstime); - - /** - *- * createNetCdfFile. - *
- * - * @param name a {@link java.lang.String} object - */ - public void createNetCdfFile(String name); } diff --git a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/onePhaseFlowVisualization/pipeFlowVisualization/PipeFlowVisualization.java b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/onePhaseFlowVisualization/pipeFlowVisualization/PipeFlowVisualization.java index ca4759d384..991072c028 100644 --- a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/onePhaseFlowVisualization/pipeFlowVisualization/PipeFlowVisualization.java +++ b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/onePhaseFlowVisualization/pipeFlowVisualization/PipeFlowVisualization.java @@ -14,184 +14,153 @@ * @version $Id: $Id */ public class PipeFlowVisualization extends - neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.onePhaseFlowVisualization.OnePhaseFlowVisualization { - double[][] pressurePoint = new double[10][10]; - double[][] velocityPoint = new double[10][10]; - double[][] temperaturePoint = new double[10][10]; - public double[][][] bulkComposition; - double[] xPlace = new double[10]; - double[] timeArray = new double[10]; + neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.onePhaseFlowVisualization.OnePhaseFlowVisualization { + double[][] pressurePoint = new double[10][10]; + double[][] velocityPoint = new double[10][10]; + double[][] temperaturePoint = new double[10][10]; + public double[][][] bulkComposition; + double[] xPlace = new double[10]; + double[] timeArray = new double[10]; - /** - *- * Constructor for PipeFlowVisualization. - *
- */ - public PipeFlowVisualization() {} + /** + *+ * Constructor for PipeFlowVisualization. + *
+ */ + public PipeFlowVisualization() {} - /** - *- * Constructor for PipeFlowVisualization. - *
- * - * @param nodes a int - * @param timeSteps a int - */ - public PipeFlowVisualization(int nodes, int timeSteps) { - flowSystem = new neqsim.fluidMechanics.flowSystem.FlowSystemInterface[timeSteps]; - flowNodes = - new neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowNodeVisualization.onePhaseFlowNodeVisualization.onePhasePipeFlowNodeVisualization.OnePhasePipeFlowNodeVisualization[timeSteps][nodes]; - absTime = new double[timeSteps]; - for (int i = 0; i < timeSteps; i++) { - for (int j = 0; j < nodes; j++) { - flowNodes[i][j] = - new neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowNodeVisualization.onePhaseFlowNodeVisualization.onePhasePipeFlowNodeVisualization.OnePhasePipeFlowNodeVisualization(); - } - } - // System.out.println("nodes " + nodes); - // System.out.println("times " + time); + /** + *+ * Constructor for PipeFlowVisualization. + *
+ * + * @param nodes a int + * @param timeSteps a int + */ + public PipeFlowVisualization(int nodes, int timeSteps) { + flowSystem = new neqsim.fluidMechanics.flowSystem.FlowSystemInterface[timeSteps]; + flowNodes = + new neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowNodeVisualization.onePhaseFlowNodeVisualization.onePhasePipeFlowNodeVisualization.OnePhasePipeFlowNodeVisualization[timeSteps][nodes]; + absTime = new double[timeSteps]; + for (int i = 0; i < timeSteps; i++) { + for (int j = 0; j < nodes; j++) { + flowNodes[i][j] = + new neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowNodeVisualization.onePhaseFlowNodeVisualization.onePhasePipeFlowNodeVisualization.OnePhasePipeFlowNodeVisualization(); + } } + // System.out.println("nodes " + nodes); + // System.out.println("times " + time); + } - /** {@inheritDoc} */ - @Override - public void setPoints() { - pressurePoint = new double[time][flowNodes[0].length]; - temperaturePoint = new double[time][flowNodes[0].length]; - velocityPoint = new double[time][flowNodes[0].length]; - xPlace = new double[flowNodes[0].length]; - timeArray = new double[time]; - bulkComposition = - new double[flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; + /** {@inheritDoc} */ + @Override + public void setPoints() { + pressurePoint = new double[time][flowNodes[0].length]; + temperaturePoint = new double[time][flowNodes[0].length]; + velocityPoint = new double[time][flowNodes[0].length]; + xPlace = new double[flowNodes[0].length]; + timeArray = new double[time]; + bulkComposition = + new double[flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; - for (int j = 0; j < time; j++) { - timeArray[j] = absTime[j]; - for (int i = 0; i < flowNodes[j].length; i++) { - xPlace[i] = flowNodes[j][i].getDistanceToCenterOfNode(); - pressurePoint[j][i] = flowNodes[j][i].getPressure(0); - temperaturePoint[j][i] = flowNodes[j][i].getTemperature(0); - velocityPoint[j][i] = flowNodes[j][i].getVelocity(0); - for (int p = 0; p < flowNodes[0][0].getNumberOfComponents(); p++) { - bulkComposition[p][j][i] = flowNodes[j][i].getBulkComposition(p, 0); - } - } + for (int j = 0; j < time; j++) { + timeArray[j] = absTime[j]; + for (int i = 0; i < flowNodes[j].length; i++) { + xPlace[i] = flowNodes[j][i].getDistanceToCenterOfNode(); + pressurePoint[j][i] = flowNodes[j][i].getPressure(0); + temperaturePoint[j][i] = flowNodes[j][i].getTemperature(0); + velocityPoint[j][i] = flowNodes[j][i].getVelocity(0); + for (int p = 0; p < flowNodes[0][0].getNumberOfComponents(); p++) { + bulkComposition[p][j][i] = flowNodes[j][i].getBulkComposition(p, 0); } + } } + } - /** - *- * calcPoints. - *
- * - * @param name a {@link java.lang.String} object - */ - public void calcPoints(String name) { - double[][] points = new double[1][1]; - setPoints(); - - if (name.equals("pressure")) { - points = pressurePoint; - } - if (name.equals("temperature")) { - points = temperaturePoint; - } - if (name.equals("velocity")) { - points = velocityPoint; - } - if (name.equals("composition")) { - points = bulkComposition[0]; - } -/* - try { - System.out.println("points: " + points.length); + /** + *+ * calcPoints. + *
+ * + * @param name a {@link java.lang.String} object + */ + public void calcPoints(String name) { + double[][] points = new double[1][1]; + setPoints(); - if (pressurePoint.length > 1) { - System.out.println("3D plot "); - plot = new neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot("title[0]", "title[1]", - "title[2]"); - ((neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot) plot).setXYvals(150, 160, - points[0].length, 10, 20, points.length); - ((neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot) plot).setZvals(points); - } else { - System.out.println("2D plot "); - plot = new neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass("title[1]", - "title[2]"); - ((neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass) plot) - .setLineXYVals(xPlace, points[0]); - ((neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass) plot).setXYVals(xPlace, - points[0]); - } - } catch (Exception e) { - System.out.println(e.toString()); - System.out.println("plotting failed"); - } - */ + if (name.equals("pressure")) { + points = pressurePoint; } + if (name.equals("temperature")) { + points = temperaturePoint; + } + if (name.equals("velocity")) { + points = velocityPoint; + } + if (name.equals("composition")) { + points = bulkComposition[0]; + } + /* + * try { System.out.println("points: " + points.length); + * + * if (pressurePoint.length > 1) { System.out.println("3D plot "); plot = new + * neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot("title[0]", "title[1]", "title[2]"); + * ((neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot) plot).setXYvals(150, 160, + * points[0].length, 10, 20, points.length); + * ((neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot) plot).setZvals(points); } else { + * System.out.println("2D plot "); plot = new + * neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass("title[1]", "title[2]"); + * ((neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass) plot) .setLineXYVals(xPlace, + * points[0]); ((neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass) plot).setXYVals(xPlace, + * points[0]); } } catch (Exception e) { System.out.println(e.toString()); + * System.out.println("plotting failed"); } + */ + } - /** {@inheritDoc} */ - @Override - public void displayResult(String name) { - double[][] points = new double[1][1]; - setPoints(); - - if (name.equals("pressure")) { - points = pressurePoint; - } - if (name.equals("temperature")) { - points = temperaturePoint; - } - if (name.equals("velocity")) { - points = velocityPoint; - } - if (name.equals("composition")) { - points = bulkComposition[0]; - } -/* - try { - System.out.println("points: " + points.length); + /** {@inheritDoc} */ + @Override + public void displayResult(String name) { + double[][] points = new double[1][1]; + setPoints(); - if (pressurePoint.length > 1) { - System.out.println("3D plot "); - plot = new neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot("title[0]", "title[1]", - "title[2]"); - ((neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot) plot).setXYvals(150, 160, - points[0].length, 10, 20, points.length); - ((neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot) plot).setZvals(points); - } else { - System.out.println("2D plot "); - plot = new neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass("title[1]", - "title[2]"); - ((neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass) plot) - .setLineXYVals(xPlace, points[0]); - ((neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass) plot).setXYVals(xPlace, - points[0]); - } - plot.init(); - } catch (Exception e) { - System.out.println(e.toString()); - System.out.println("plotting failed"); - } - */ + if (name.equals("pressure")) { + points = pressurePoint; } - - /** {@inheritDoc} */ - /* - @Override - public void createNetCdfFile(String name) { - calcPoints(name); - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF3D.NetCdf3D file = - new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF3D.NetCdf3D(); - file.setOutputFileName(name); - file.setXvalues(timeArray, "time", "sec"); - file.setYvalues(xPlace, "length", "meter"); - file.setZvalues(temperaturePoint, "temperature [K]", "sec"); - file.setZvalues(pressurePoint, "pressure [bar]", "sec"); - file.setZvalues(velocityPoint, "velocity [m/sec]", "sec"); - if (absTime.length > 1) { - for (int p = 0; p < flowNodes[0][0].getNumberOfComponents(); p++) { - file.setZvalues(bulkComposition[p], ("comp " + p), "sec"); - } - } - file.createFile(); + if (name.equals("temperature")) { + points = temperaturePoint; + } + if (name.equals("velocity")) { + points = velocityPoint; + } + if (name.equals("composition")) { + points = bulkComposition[0]; } - */ + /* + * try { System.out.println("points: " + points.length); + * + * if (pressurePoint.length > 1) { System.out.println("3D plot "); plot = new + * neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot("title[0]", "title[1]", "title[2]"); + * ((neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot) plot).setXYvals(150, 160, + * points[0].length, 10, 20, points.length); + * ((neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot) plot).setZvals(points); } else { + * System.out.println("2D plot "); plot = new + * neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass("title[1]", "title[2]"); + * ((neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass) plot) .setLineXYVals(xPlace, + * points[0]); ((neqsim.dataPresentation.visAD.visAd2D.visAd2dBaseClass) plot).setXYVals(xPlace, + * points[0]); } plot.init(); } catch (Exception e) { System.out.println(e.toString()); + * System.out.println("plotting failed"); } + */ + } + + /* + * public void createNetCdfFile(String name) { calcPoints(name); + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF3D.NetCdf3D file = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF3D.NetCdf3D(); + * file.setOutputFileName(name); file.setXvalues(timeArray, "time", "sec"); + * file.setYvalues(xPlace, "length", "meter"); file.setZvalues(temperaturePoint, + * "temperature [K]", "sec"); file.setZvalues(pressurePoint, "pressure [bar]", "sec"); + * file.setZvalues(velocityPoint, "velocity [m/sec]", "sec"); if (absTime.length > 1) { for (int p + * = 0; p < flowNodes[0][0].getNumberOfComponents(); p++) { file.setZvalues(bulkComposition[p], + * ("comp " + p), "sec"); } } file.createFile(); } + */ } diff --git a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/twoPhaseFlowVisualization/twoPhasePipeFlowVisualization/TwoPhasePipeFlowVisualization.java b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/twoPhaseFlowVisualization/twoPhasePipeFlowVisualization/TwoPhasePipeFlowVisualization.java index 1a4ec9c527..c3aeeb9529 100644 --- a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/twoPhaseFlowVisualization/twoPhasePipeFlowVisualization/TwoPhasePipeFlowVisualization.java +++ b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/twoPhaseFlowVisualization/twoPhasePipeFlowVisualization/TwoPhasePipeFlowVisualization.java @@ -12,199 +12,187 @@ * @version $Id: $Id */ public class TwoPhasePipeFlowVisualization extends - neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.twoPhaseFlowVisualization.TwoPhaseFlowVisualization { - double[][][] pressurePoint = new double[2][10][10]; - double[][][] velocityPoint = new double[2][10][10]; - double[][][] reynoldsNumber = new double[2][10][10]; - double[][][] phaseFraction = new double[2][10][10]; - double[][][] temperaturePoint = new double[2][10][10]; - double[][][] interphaseContactLength = new double[2][10][10]; - double[][][] interfaceTemperaturePoint = new double[2][10][10]; - public double[][][][] bulkComposition, interfaceComposition, effectiveMassTransferCoefficient; // phase, - // time, - // component, - // node - public double[][][][] molarFlux, schmidtNumber; - public double[][][][] totalMolarMassTransferRate; - public double[][][][] totalVolumetricMassTransferRate; - double[] xPlace = new double[10]; - double[] timeArray = new double[10]; + neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.twoPhaseFlowVisualization.TwoPhaseFlowVisualization { + double[][][] pressurePoint = new double[2][10][10]; + double[][][] velocityPoint = new double[2][10][10]; + double[][][] reynoldsNumber = new double[2][10][10]; + double[][][] phaseFraction = new double[2][10][10]; + double[][][] temperaturePoint = new double[2][10][10]; + double[][][] interphaseContactLength = new double[2][10][10]; + double[][][] interfaceTemperaturePoint = new double[2][10][10]; + public double[][][][] bulkComposition, interfaceComposition, effectiveMassTransferCoefficient; // phase, + // time, + // component, + // node + public double[][][][] molarFlux, schmidtNumber; + public double[][][][] totalMolarMassTransferRate; + public double[][][][] totalVolumetricMassTransferRate; + double[] xPlace = new double[10]; + double[] timeArray = new double[10]; - /** - *- * Constructor for TwoPhasePipeFlowVisualization. - *
- */ - public TwoPhasePipeFlowVisualization() {} + /** + *+ * Constructor for TwoPhasePipeFlowVisualization. + *
+ */ + public TwoPhasePipeFlowVisualization() {} - /** - *- * Constructor for TwoPhasePipeFlowVisualization. - *
- * - * @param nodes a int - * @param timeSteps a int - */ - public TwoPhasePipeFlowVisualization(int nodes, int timeSteps) { - flowNodes = new TwoPhaseFlowNodeVisualization[timeSteps][nodes]; - flowSystem = new FlowSystem[timeSteps]; - absTime = new double[timeSteps]; - for (int i = 0; i < timeSteps; i++) { - for (int j = 0; j < nodes; j++) { - flowNodes[i][j] = new TwoPhaseFlowNodeVisualization(); - } - } - // System.out.println("nodes " + nodes); - // System.out.println("times " + time); + /** + *+ * Constructor for TwoPhasePipeFlowVisualization. + *
+ * + * @param nodes a int + * @param timeSteps a int + */ + public TwoPhasePipeFlowVisualization(int nodes, int timeSteps) { + flowNodes = new TwoPhaseFlowNodeVisualization[timeSteps][nodes]; + flowSystem = new FlowSystem[timeSteps]; + absTime = new double[timeSteps]; + for (int i = 0; i < timeSteps; i++) { + for (int j = 0; j < nodes; j++) { + flowNodes[i][j] = new TwoPhaseFlowNodeVisualization(); + } } + // System.out.println("nodes " + nodes); + // System.out.println("times " + time); + } - /** {@inheritDoc} */ - @Override - public void setPoints() { - pressurePoint = new double[2][time][flowNodes[0].length]; - temperaturePoint = new double[2][time][flowNodes[0].length]; - interphaseContactLength = new double[2][time][flowNodes[0].length]; - velocityPoint = new double[2][time][flowNodes[0].length]; - reynoldsNumber = new double[2][time][flowNodes[0].length]; - phaseFraction = new double[2][time][flowNodes[0].length]; - interfaceTemperaturePoint = new double[2][time][flowNodes[0].length]; - bulkComposition = - new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; - effectiveMassTransferCoefficient = - new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; - interfaceComposition = - new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; - molarFlux = - new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; - schmidtNumber = - new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; - totalMolarMassTransferRate = - new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; - totalVolumetricMassTransferRate = - new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; - xPlace = new double[flowNodes[0].length]; - timeArray = new double[time]; + /** {@inheritDoc} */ + @Override + public void setPoints() { + pressurePoint = new double[2][time][flowNodes[0].length]; + temperaturePoint = new double[2][time][flowNodes[0].length]; + interphaseContactLength = new double[2][time][flowNodes[0].length]; + velocityPoint = new double[2][time][flowNodes[0].length]; + reynoldsNumber = new double[2][time][flowNodes[0].length]; + phaseFraction = new double[2][time][flowNodes[0].length]; + interfaceTemperaturePoint = new double[2][time][flowNodes[0].length]; + bulkComposition = + new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; + effectiveMassTransferCoefficient = + new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; + interfaceComposition = + new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; + molarFlux = new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; + schmidtNumber = + new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; + totalMolarMassTransferRate = + new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; + totalVolumetricMassTransferRate = + new double[2][flowNodes[0][0].getNumberOfComponents()][time][flowNodes[0].length]; + xPlace = new double[flowNodes[0].length]; + timeArray = new double[time]; - for (int k = 0; k < 2; k++) { - for (int j = 0; j < time; j++) { - timeArray[j] = j; - for (int i = 0; i < flowNodes[j].length; i++) { - xPlace[i] = flowNodes[j][i].getDistanceToCenterOfNode(); - pressurePoint[k][j][i] = flowNodes[j][i].getPressure(k); - interphaseContactLength[k][j][i] = flowNodes[j][i].getInterphaseContactLength(); - temperaturePoint[k][j][i] = flowNodes[j][i].getTemperature(k); - velocityPoint[k][j][i] = flowNodes[j][i].getVelocity(k); - reynoldsNumber[k][j][i] = flowNodes[j][i].getReynoldsNumber(k); - phaseFraction[k][j][i] = flowNodes[j][i].getPhaseFraction(k); - interfaceTemperaturePoint[k][j][i] = flowNodes[j][i].getInterfaceTemperature(k); - for (int p = 0; p < flowNodes[0][0].getNumberOfComponents(); p++) { - effectiveMassTransferCoefficient[k][p][j][i] = - flowNodes[j][i].getEffectiveMassTransferCoefficient(p, k); - bulkComposition[k][p][j][i] = flowNodes[j][i].getBulkComposition(p, k); - interfaceComposition[k][p][j][i] = - flowNodes[j][i].getInterfaceComposition(p, k); - molarFlux[k][p][j][i] = flowNodes[j][i].getEffectiveSchmidtNumber(p, k); - schmidtNumber[k][p][j][i] = flowNodes[j][i].getEffectiveSchmidtNumber(p, k); - totalMolarMassTransferRate[k][p][j][i] = - flowSystem[j].getTotalMolarMassTransferRate(p, i); - totalVolumetricMassTransferRate[k][p][j][i] = - totalMolarMassTransferRate[k][p][j][i] * 60.0 / 40.87631889 - * 1000.0; - } - } - } + for (int k = 0; k < 2; k++) { + for (int j = 0; j < time; j++) { + timeArray[j] = j; + for (int i = 0; i < flowNodes[j].length; i++) { + xPlace[i] = flowNodes[j][i].getDistanceToCenterOfNode(); + pressurePoint[k][j][i] = flowNodes[j][i].getPressure(k); + interphaseContactLength[k][j][i] = flowNodes[j][i].getInterphaseContactLength(); + temperaturePoint[k][j][i] = flowNodes[j][i].getTemperature(k); + velocityPoint[k][j][i] = flowNodes[j][i].getVelocity(k); + reynoldsNumber[k][j][i] = flowNodes[j][i].getReynoldsNumber(k); + phaseFraction[k][j][i] = flowNodes[j][i].getPhaseFraction(k); + interfaceTemperaturePoint[k][j][i] = flowNodes[j][i].getInterfaceTemperature(k); + for (int p = 0; p < flowNodes[0][0].getNumberOfComponents(); p++) { + effectiveMassTransferCoefficient[k][p][j][i] = + flowNodes[j][i].getEffectiveMassTransferCoefficient(p, k); + bulkComposition[k][p][j][i] = flowNodes[j][i].getBulkComposition(p, k); + interfaceComposition[k][p][j][i] = flowNodes[j][i].getInterfaceComposition(p, k); + molarFlux[k][p][j][i] = flowNodes[j][i].getEffectiveSchmidtNumber(p, k); + schmidtNumber[k][p][j][i] = flowNodes[j][i].getEffectiveSchmidtNumber(p, k); + totalMolarMassTransferRate[k][p][j][i] = + flowSystem[j].getTotalMolarMassTransferRate(p, i); + totalVolumetricMassTransferRate[k][p][j][i] = + totalMolarMassTransferRate[k][p][j][i] * 60.0 / 40.87631889 * 1000.0; + } } + } } + } - /** {@inheritDoc} */ - @Override - public void displayResult(String name) { - // double[][] points = new double[1][1]; - setPoints(); - - // if(name.equals("pressure")) points = pressurePoint; - // if(name.equals("temperature")) points = temperaturePoint; - // if(name.equals("velocity")) points = velocityPoint; + /** {@inheritDoc} */ + @Override + public void displayResult(String name) { + // double[][] points = new double[1][1]; + setPoints(); - // try{ - // System.out.println("points: " + points.length); + // if(name.equals("pressure")) points = pressurePoint; + // if(name.equals("temperature")) points = temperaturePoint; + // if(name.equals("velocity")) points = velocityPoint; - // if(pressurePoint.length>1){ - // System.out.println("3D plot "); - // plot = new visAd3DPlot("title[0]", "title[1]", "title[2]"); - // ((visAd3DPlot) plot).setXYvals(150, 160, points[0].length, 10, 20, - // points.length); - // ((visAd3DPlot) plot).setZvals(points); - // } - // else{ - // System.out.println("2D plot "); - // plot = new visAd2dBaseClass("title[1]", "title[2]"); - // ((visAd2dBaseClass) plot).setLineXYVals(xPlace, points[0]); - // ((visAd2dBaseClass) plot).setXYVals(xPlace, points[0]); - // } - // plot.init(); - // } - // catch(Exception e){ - // System.out.println(e.toString()); - // System.out.println("plotting failed"); - // } - } + // try{ + // System.out.println("points: " + points.length); - // public void createNetCdfFile(String name){ - // dataPresentation.fileHandeling.createNetCDF.NetCdf file = new - // dataPresentation.fileHandeling.createNetCDF.NetCdf(); - // file.setOutputFileName(name); - // file.setXvalues(timeArray,"time","sec"); - // file.setYvalues(xPlace, "length","meter"); - // // file.setZvalues(temperaturePoint, "time","sec"); - // file.createFile(); + // if(pressurePoint.length>1){ + // System.out.println("3D plot "); + // plot = new visAd3DPlot("title[0]", "title[1]", "title[2]"); + // ((visAd3DPlot) plot).setXYvals(150, 160, points[0].length, 10, 20, + // points.length); + // ((visAd3DPlot) plot).setZvals(points); + // } + // else{ + // System.out.println("2D plot "); + // plot = new visAd2dBaseClass("title[1]", "title[2]"); + // ((visAd2dBaseClass) plot).setLineXYVals(xPlace, points[0]); + // ((visAd2dBaseClass) plot).setXYVals(xPlace, points[0]); // } + // plot.init(); + // } + // catch(Exception e){ + // System.out.println(e.toString()); + // System.out.println("plotting failed"); + // } + } + // public void createNetCdfFile(String name){ + // dataPresentation.fileHandeling.createNetCDF.NetCdf file = new + // dataPresentation.fileHandeling.createNetCDF.NetCdf(); + // file.setOutputFileName(name); + // file.setXvalues(timeArray,"time","sec"); + // file.setYvalues(xPlace, "length","meter"); + // // file.setZvalues(temperaturePoint, "time","sec"); + // file.createFile(); + // } - /** {@inheritDoc} */ - /* - @Override - public void createNetCdfFile(String name) { - setPoints(); - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file = - new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file.setOutputFileName(name); - file.setXvalues(xPlace, "length", "meter"); - file.setYvalues(pressurePoint[0][0], "gas pressure", "sec"); - file.setYvalues(pressurePoint[1][0], "liquid pressure", "sec"); - file.setYvalues(velocityPoint[0][0], "gas velocity", "sec"); - file.setYvalues(velocityPoint[1][0], "liquid velocity", "sec"); - file.setYvalues(reynoldsNumber[0][0], "gas reynolds number", "sec"); - file.setYvalues(reynoldsNumber[1][0], "liquid reynolds number", "sec"); - file.setYvalues(temperaturePoint[0][0], "gas temperature", "sec"); - file.setYvalues(temperaturePoint[1][0], "liquid temperature", "sec"); - file.setYvalues(phaseFraction[0][0], "void fraction", "sec"); - file.setYvalues(phaseFraction[1][0], "holdup", "sec"); - file.setYvalues(interfaceTemperaturePoint[0][0], "gas interface temperature", "sec"); - file.setYvalues(interfaceTemperaturePoint[1][0], "liquid interface temperature", "sec"); - file.setYvalues(interphaseContactLength[0][0], "interphase contact length", "sec"); - for (int p = 0; p < flowNodes[0][0].getNumberOfComponents(); p++) { - String comp = "component molefraction " + p; - file.setYvalues(bulkComposition[0][p][0], ("gas " + comp + p), "sec"); - file.setYvalues(bulkComposition[1][p][0], ("liquid " + comp + p), "sec"); - file.setYvalues(interfaceComposition[0][p][0], ("gas (interphase) " + comp), "sec"); - file.setYvalues(interfaceComposition[1][p][0], ("liquid (interphase) " + comp), "sec"); - file.setYvalues(molarFlux[0][p][0], ("gas molar flux " + comp + p), "sec"); - file.setYvalues(molarFlux[1][p][0], ("liquid molar flux " + comp + p), "sec"); - file.setYvalues(totalVolumetricMassTransferRate[0][p][0], - ("total gas Volumetric Mass Transfer " + comp + p), "sec"); - file.setYvalues(totalVolumetricMassTransferRate[1][p][0], - ("total liq Volumetric Mass Transfer " + comp + p), "sec"); - file.setYvalues(effectiveMassTransferCoefficient[0][p][0], - ("eff. masstransfer coef gas " + comp + p), "sec"); - file.setYvalues(effectiveMassTransferCoefficient[1][p][0], - ("eff. masstransfer coef liq " + comp + p), "sec"); - file.setYvalues(schmidtNumber[0][p][0], ("gas scmidtnumber " + comp + p), "-"); - file.setYvalues(schmidtNumber[1][p][0], ("liquid scmidtnumber " + comp + p), "-"); - } - // file.setYvalues(temperaturePoint[0][0], "time","sec"); - file.createFile(); - } - */ + /* + * public void createNetCdfFile(String name) { setPoints(); + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file.setOutputFileName(name); file.setXvalues(xPlace, "length", "meter"); + * file.setYvalues(pressurePoint[0][0], "gas pressure", "sec"); + * file.setYvalues(pressurePoint[1][0], "liquid pressure", "sec"); + * file.setYvalues(velocityPoint[0][0], "gas velocity", "sec"); + * file.setYvalues(velocityPoint[1][0], "liquid velocity", "sec"); + * file.setYvalues(reynoldsNumber[0][0], "gas reynolds number", "sec"); + * file.setYvalues(reynoldsNumber[1][0], "liquid reynolds number", "sec"); + * file.setYvalues(temperaturePoint[0][0], "gas temperature", "sec"); + * file.setYvalues(temperaturePoint[1][0], "liquid temperature", "sec"); + * file.setYvalues(phaseFraction[0][0], "void fraction", "sec"); + * file.setYvalues(phaseFraction[1][0], "holdup", "sec"); + * file.setYvalues(interfaceTemperaturePoint[0][0], "gas interface temperature", "sec"); + * file.setYvalues(interfaceTemperaturePoint[1][0], "liquid interface temperature", "sec"); + * file.setYvalues(interphaseContactLength[0][0], "interphase contact length", "sec"); + * + * for (int p = 0; p < flowNodes[0][0].getNumberOfComponents(); p++) { String comp = + * "component molefraction " + p; file.setYvalues(bulkComposition[0][p][0], ("gas " + comp + p), + * "sec"); file.setYvalues(bulkComposition[1][p][0], ("liquid " + comp + p), "sec"); + * file.setYvalues(interfaceComposition[0][p][0], ("gas (interphase) " + comp), "sec"); + * file.setYvalues(interfaceComposition[1][p][0], ("liquid (interphase) " + comp), "sec"); + * file.setYvalues(molarFlux[0][p][0], ("gas molar flux " + comp + p), "sec"); + * file.setYvalues(molarFlux[1][p][0], ("liquid molar flux " + comp + p), "sec"); + * file.setYvalues(totalVolumetricMassTransferRate[0][p][0], + * ("total gas Volumetric Mass Transfer " + comp + p), "sec"); + * file.setYvalues(totalVolumetricMassTransferRate[1][p][0], + * ("total liq Volumetric Mass Transfer " + comp + p), "sec"); + * file.setYvalues(effectiveMassTransferCoefficient[0][p][0], ("eff. masstransfer coef gas " + + * comp + p), "sec"); file.setYvalues(effectiveMassTransferCoefficient[1][p][0], + * ("eff. masstransfer coef liq " + comp + p), "sec"); file.setYvalues(schmidtNumber[0][p][0], + * ("gas scmidtnumber " + comp + p), "-"); file.setYvalues(schmidtNumber[1][p][0], + * ("liquid scmidtnumber " + comp + p), "-"); } // file.setYvalues(temperaturePoint[0][0], + * "time","sec"); file.createFile(); } + */ } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/OnePhasePipeLine.java b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/OnePhasePipeLine.java index 21f0ba4626..12d2ad2d7a 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/OnePhasePipeLine.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/OnePhasePipeLine.java @@ -17,69 +17,68 @@ * @version $Id: $Id */ public class OnePhasePipeLine extends Pipeline { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - /** - *- * Constructor for OnePhasePipeLine. - *
- */ - @Deprecated - public OnePhasePipeLine() { - this("OnePhasePipeLine"); - } + /** + *+ * Constructor for OnePhasePipeLine. + *
+ */ + @Deprecated + public OnePhasePipeLine() { + this("OnePhasePipeLine"); + } - /** - *- * Constructor for OnePhasePipeLine. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - public OnePhasePipeLine(StreamInterface inStream) { - this("OnePhasePipeLine", inStream); - } + /** + *+ * Constructor for OnePhasePipeLine. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + public OnePhasePipeLine(StreamInterface inStream) { + this("OnePhasePipeLine", inStream); + } - /** - * Constructor for OnePhasePipeLine. - * - * @param name name of pipe - */ - public OnePhasePipeLine(String name) { - super(name); - } + /** + * Constructor for OnePhasePipeLine. + * + * @param name name of pipe + */ + public OnePhasePipeLine(String name) { + super(name); + } - /** - * Constructor for OnePhasePipeLine. - * - * @param name name of pipe - * @param inStream input stream - */ - public OnePhasePipeLine(String name, StreamInterface inStream) { - super(name, inStream); - pipe = new PipeFlowSystem(); - } + /** + * Constructor for OnePhasePipeLine. + * + * @param name name of pipe + * @param inStream input stream + */ + public OnePhasePipeLine(String name, StreamInterface inStream) { + super(name, inStream); + pipe = new PipeFlowSystem(); + } - /** - *- * createSystem. - *
- */ - public void createSystem() {} + /** + *+ * createSystem. + *
+ */ + public void createSystem() {} - /** {@inheritDoc} */ - @Override - public void run() { - super.run(); - pipe.solveSteadyState(10); - // pipe.print(); - // pipe.getDisplay().createNetCdfFile(fileName); - outStream.setThermoSystem(pipe.getNode(pipe.getTotalNumberOfNodes() - 1).getBulkSystem()); - } + /** {@inheritDoc} */ + @Override + public void run() { + super.run(); + pipe.solveSteadyState(10); + // pipe.print(); + outStream.setThermoSystem(pipe.getNode(pipe.getTotalNumberOfNodes() - 1).getBulkSystem()); + } - /** {@inheritDoc} */ - @Override - public void runTransient(double dt) { - super.runTransient(dt); - } + /** {@inheritDoc} */ + @Override + public void runTransient(double dt) { + super.runTransient(dt); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/Pipeline.java b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/Pipeline.java index 4b2ab5766a..9daef31934 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/Pipeline.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/Pipeline.java @@ -3,6 +3,7 @@ * * Created on 14. mars 2001, 22:30 */ + package neqsim.processSimulation.processEquipment.pipeline; import neqsim.fluidMechanics.flowSystem.FlowSystemInterface; @@ -22,320 +23,304 @@ * @version $Id: $Id */ public class Pipeline extends TwoPortEquipment implements PipeLineInterface { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - protected String fileName = "c:/test5.nc"; - protected FlowSystemInterface pipe; - protected SystemInterface system; - String flowPattern = "stratified"; - double[] times; - boolean equilibriumHeatTransfer = true, equilibriumMassTransfer = false; - // default variables - int numberOfLegs = 1, numberOfNodesInLeg = 30; - double[] legHeights = {0, 0};// ,0,0,0}; - double[] legPositions = {0.0, 1.0};// 10.0,20.0,30.0,40.0}; - double[] pipeDiameters = {0.1507588, 0.1507588};// , 1.207588, 1.207588, 1.207588}; - double[] outerTemperature = {278.0, 278.0};// , 278.0, 278.0, 278.0}; - double[] pipeWallRoughness = {1e-5, 1e-5};// , 1e-5, 1e-5, 1e-5}; - double[] outerHeatTransferCoeffs = {1e-5, 1e-5};// , 1e-5, 1e-5, 1e-5}; - double[] wallHeatTransferCoeffs = {1e-5, 1e-5};// , 1e-5, 1e-5, 1e-5}; + protected String fileName = "c:/test5.nc"; + protected FlowSystemInterface pipe; + protected SystemInterface system; + String flowPattern = "stratified"; + double[] times; + boolean equilibriumHeatTransfer = true, equilibriumMassTransfer = false; + // default variables + int numberOfLegs = 1, numberOfNodesInLeg = 30; + double[] legHeights = {0, 0}; // ,0,0,0}; + double[] legPositions = {0.0, 1.0}; // 10.0,20.0,30.0,40.0}; + double[] pipeDiameters = {0.1507588, 0.1507588}; // , 1.207588, 1.207588, 1.207588}; + double[] outerTemperature = {278.0, 278.0}; // , 278.0, 278.0, 278.0}; + double[] pipeWallRoughness = {1e-5, 1e-5}; // , 1e-5, 1e-5, 1e-5}; + double[] outerHeatTransferCoeffs = {1e-5, 1e-5}; // , 1e-5, 1e-5, 1e-5}; + double[] wallHeatTransferCoeffs = {1e-5, 1e-5}; // , 1e-5, 1e-5, 1e-5}; - /** - *- * Constructor for Pipeline. - *
- */ - @Deprecated - public Pipeline() { - this("Pipeline"); - } + /** + *+ * Constructor for Pipeline. + *
+ */ + @Deprecated + public Pipeline() { + this("Pipeline"); + } - /** - *- * Constructor for Pipeline. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public Pipeline(StreamInterface inStream) { - this("Pipeline", inStream); - } + /** + *+ * Constructor for Pipeline. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public Pipeline(StreamInterface inStream) { + this("Pipeline", inStream); + } - /** - *- * Constructor for Pipeline. - *
- * - * @param name a {@link java.lang.String} object - */ - public Pipeline(String name) { - super(name); - } + /** + *+ * Constructor for Pipeline. + *
+ * + * @param name a {@link java.lang.String} object + */ + public Pipeline(String name) { + super(name); + } - /** - *- * Constructor for Pipeline. - *
- * - * @param name a {@link java.lang.String} object - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public Pipeline(String name, StreamInterface inStream) { - super(name, inStream); - } + /** + *+ * Constructor for Pipeline. + *
+ * + * @param name a {@link java.lang.String} object + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public Pipeline(String name, StreamInterface inStream) { + super(name, inStream); + } - public PipelineMechanicalDesign getMechanicalDesign() { - return new PipelineMechanicalDesign(this); - } + public PipelineMechanicalDesign getMechanicalDesign() { + return new PipelineMechanicalDesign(this); + } - /** {@inheritDoc} */ - @Override - public void setOutputFileName(String name) { - this.fileName = name; - } + /** {@inheritDoc} */ + @Override + public void setOutputFileName(String name) { + this.fileName = name; + } - /** {@inheritDoc} */ - @Override - public void setNumberOfLegs(int number) { - this.numberOfLegs = number; - } + /** {@inheritDoc} */ + @Override + public void setNumberOfLegs(int number) { + this.numberOfLegs = number; + } - /** {@inheritDoc} */ - @Override - public void setNumberOfNodesInLeg(int number) { - this.numberOfNodesInLeg = number; - } + /** {@inheritDoc} */ + @Override + public void setNumberOfNodesInLeg(int number) { + this.numberOfNodesInLeg = number; + } - /** {@inheritDoc} */ - @Override - public void setHeightProfile(double[] heights) { - if (heights.length != this.numberOfLegs + 1) { - System.out.println("Wrong number of heights specified."); - System.out.println("Number of heights must be number of legs + 1 "); - System.out.println( - "Remember to specify number of legs first (default 5) - than set the leg heights (default 6)."); - return; - } - legHeights = new double[heights.length]; - System.arraycopy(heights, 0, legHeights, 0, legHeights.length); + /** {@inheritDoc} */ + @Override + public void setHeightProfile(double[] heights) { + if (heights.length != this.numberOfLegs + 1) { + System.out.println("Wrong number of heights specified."); + System.out.println("Number of heights must be number of legs + 1 "); + return; } + legHeights = new double[heights.length]; + System.arraycopy(heights, 0, legHeights, 0, legHeights.length); + } - /** {@inheritDoc} */ - @Override - public void setLegPositions(double[] positions) { - if (positions.length != this.numberOfLegs + 1) { - System.out.println("Wrong number of legpositions specified."); - System.out.println("Number of heights must be number of legs + 1 "); - System.out.println( - "Remember to specify number of legs first (default 5) - than set the leg heights (default 6)."); - return; - } - legPositions = new double[positions.length]; - System.arraycopy(positions, 0, legPositions, 0, legPositions.length); + /** {@inheritDoc} */ + @Override + public void setLegPositions(double[] positions) { + if (positions.length != this.numberOfLegs + 1) { + System.out.println("Wrong number of legpositions specified."); + System.out.println("Number of heights must be number of legs + 1 "); + return; } + legPositions = new double[positions.length]; + System.arraycopy(positions, 0, legPositions, 0, legPositions.length); + } - /** {@inheritDoc} */ - @Override - public void setPipeDiameters(double[] diameter) { - if (diameter.length != this.numberOfLegs + 1) { - System.out.println("Wrong number of diameters specified."); - System.out.println("Number of diameters must be number of legs + 1 "); - System.out.println( - "Remember to specify number of legs first (default 5) - than set the leg heights (default 6)."); - return; - } - pipeDiameters = new double[diameter.length]; - System.arraycopy(diameter, 0, pipeDiameters, 0, pipeDiameters.length); + /** {@inheritDoc} */ + @Override + public void setPipeDiameters(double[] diameter) { + if (diameter.length != this.numberOfLegs + 1) { + System.out.println("Wrong number of diameters specified."); + System.out.println("Number of diameters must be number of legs + 1 "); + return; } + pipeDiameters = new double[diameter.length]; + System.arraycopy(diameter, 0, pipeDiameters, 0, pipeDiameters.length); + } - /** - *- * setPipeOuterHeatTransferCoefficients. - *
- * - * @param heatCoefs an array of {@link double} objects - */ - public void setPipeOuterHeatTransferCoefficients(double[] heatCoefs) { - if (heatCoefs.length != this.numberOfLegs + 1) { - System.out.println("Wrong number of diameters specified."); - System.out.println("Number of diameters must be number of legs + 1 "); - System.out.println( - "Remember to specify number of legs first (default 5) - than set the leg heights (default 6)."); - return; - } - outerHeatTransferCoeffs = new double[heatCoefs.length]; - System.arraycopy(heatCoefs, 0, outerHeatTransferCoeffs, 0, outerHeatTransferCoeffs.length); + /** + *+ * setPipeOuterHeatTransferCoefficients. + *
+ * + * @param heatCoefs an array of {@link double} objects + */ + public void setPipeOuterHeatTransferCoefficients(double[] heatCoefs) { + if (heatCoefs.length != this.numberOfLegs + 1) { + System.out.println("Wrong number of diameters specified."); + System.out.println("Number of diameters must be number of legs + 1 "); + return; } + outerHeatTransferCoeffs = new double[heatCoefs.length]; + System.arraycopy(heatCoefs, 0, outerHeatTransferCoeffs, 0, outerHeatTransferCoeffs.length); + } - /** - *- * setPipeWallHeatTransferCoefficients. - *
- * - * @param heatCoefs an array of {@link double} objects - */ - public void setPipeWallHeatTransferCoefficients(double[] heatCoefs) { - if (heatCoefs.length != this.numberOfLegs + 1) { - System.out.println("Wrong number of diameters specified."); - System.out.println("Number of diameters must be number of legs + 1 "); - System.out.println( - "Remember to specify number of legs first (default 5) - than set the leg heights (default 6)."); - return; - } - wallHeatTransferCoeffs = new double[heatCoefs.length]; - System.arraycopy(heatCoefs, 0, wallHeatTransferCoeffs, 0, wallHeatTransferCoeffs.length); + /** + *+ * setPipeWallHeatTransferCoefficients. + *
+ * + * @param heatCoefs an array of {@link double} objects + */ + public void setPipeWallHeatTransferCoefficients(double[] heatCoefs) { + if (heatCoefs.length != this.numberOfLegs + 1) { + System.out.println("Wrong number of diameters specified."); + System.out.println("Number of diameters must be number of legs + 1 "); + return; } + wallHeatTransferCoeffs = new double[heatCoefs.length]; + System.arraycopy(heatCoefs, 0, wallHeatTransferCoeffs, 0, wallHeatTransferCoeffs.length); + } - /** {@inheritDoc} */ - @Override - public void setPipeWallRoughness(double[] rough) { - if (rough.length != this.numberOfLegs + 1) { - System.out.println("Wrong number of roghuness points specified."); - System.out.println("Number of heights must be number of legs + 1 "); - System.out.println( - "Remember to specify number of legs first (default 5) - than set the leg heights (default 6)."); - return; - } - pipeWallRoughness = new double[rough.length]; - System.arraycopy(rough, 0, pipeWallRoughness, 0, pipeWallRoughness.length); + /** {@inheritDoc} */ + @Override + public void setPipeWallRoughness(double[] rough) { + if (rough.length != this.numberOfLegs + 1) { + System.out.println("Wrong number of roghuness points specified."); + System.out.println("Number of heights must be number of legs + 1 "); + return; } + pipeWallRoughness = new double[rough.length]; + System.arraycopy(rough, 0, pipeWallRoughness, 0, pipeWallRoughness.length); + } - /** {@inheritDoc} */ - @Override - public void setOuterTemperatures(double[] outerTemp) { - if (outerTemp.length != this.numberOfLegs + 1) { - System.out.println("Wrong number of outer temperature points specified."); - System.out.println("Number of heights must be number of legs + 1 "); - System.out.println( - "Remember to specify number of legs first (default 5) - than set the leg heights (default 6)."); - return; - } - outerTemperature = new double[outerTemp.length]; - System.arraycopy(outerTemp, 0, outerTemperature, 0, outerTemperature.length); + /** {@inheritDoc} */ + @Override + public void setOuterTemperatures(double[] outerTemp) { + if (outerTemp.length != this.numberOfLegs + 1) { + System.out.println("Wrong number of outer temperature points specified."); + System.out.println("Number of heights must be number of legs + 1 "); + return; } + outerTemperature = new double[outerTemp.length]; + System.arraycopy(outerTemp, 0, outerTemperature, 0, outerTemperature.length); + } - /** - *
- * Setter for the field equilibriumMassTransfer
.
- *
+ * Setter for the field equilibriumMassTransfer
.
+ *
- * Setter for the field equilibriumHeatTransfer
.
- *
+ * Setter for the field equilibriumHeatTransfer
.
+ *
- * getSuperficialVelocity. - *
- * - * @param phase a int - * @param node a int - * @return a double - */ - public double getSuperficialVelocity(int phase, int node) { - try { - return outStream.getThermoSystem().getPhase(phase).getNumberOfMolesInPhase() - * outStream.getThermoSystem().getPhase(phase).getMolarMass() - / outStream.getThermoSystem().getPhase(phase).getPhysicalProperties() - .getDensity() - / (3.14 * pipeDiameters[node] * pipeDiameters[node] / 4.0); - } catch (Exception e) { - e.printStackTrace(); - } finally { - } - return 0.0; + /** + *+ * getSuperficialVelocity. + *
+ * + * @param phase a int + * @param node a int + * @return a double + */ + public double getSuperficialVelocity(int phase, int node) { + try { + return outStream.getThermoSystem().getPhase(phase).getNumberOfMolesInPhase() + * outStream.getThermoSystem().getPhase(phase).getMolarMass() + / outStream.getThermoSystem().getPhase(phase).getPhysicalProperties().getDensity() + / (3.14 * pipeDiameters[node] * pipeDiameters[node] / 4.0); + } catch (Exception e) { + e.printStackTrace(); + } finally { } + return 0.0; + } - /** - * Setter for property times. - * - * @param times New value of property times. - * @param systems an array of {@link neqsim.thermo.system.SystemInterface} objects - * @param timestepininterval a int - */ - public void setTimeSeries(double[] times, SystemInterface[] systems, int timestepininterval) { - this.times = times; - pipe.getTimeSeries().setTimes(times); - pipe.getTimeSeries().setInletThermoSystems(systems); - pipe.getTimeSeries().setNumberOfTimeStepsInInterval(timestepininterval); - } + /** + * Setter for property times. + * + * @param times New value of property times. + * @param systems an array of {@link neqsim.thermo.system.SystemInterface} objects + * @param timestepininterval a int + */ + public void setTimeSeries(double[] times, SystemInterface[] systems, int timestepininterval) { + this.times = times; + pipe.getTimeSeries().setTimes(times); + pipe.getTimeSeries().setInletThermoSystems(systems); + pipe.getTimeSeries().setNumberOfTimeStepsInInterval(timestepininterval); + } - /** {@inheritDoc} */ - @Override - public double getEntropyProduction(String unit) { - return outStream.getThermoSystem().getEntropy(unit) - - inStream.getThermoSystem().getEntropy(unit); - } + /** {@inheritDoc} */ + @Override + public double getEntropyProduction(String unit) { + return outStream.getThermoSystem().getEntropy(unit) + - inStream.getThermoSystem().getEntropy(unit); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/TwoPhasePipeLine.java b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/TwoPhasePipeLine.java index 6f4602c9fc..e5baf3cc26 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/TwoPhasePipeLine.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/TwoPhasePipeLine.java @@ -17,65 +17,64 @@ * @version $Id: $Id */ public class TwoPhasePipeLine extends Pipeline { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - /** - *- * Constructor for TwoPhasePipeLine. - *
- */ - @Deprecated - public TwoPhasePipeLine() { - this("TwoPhasePipeLine"); - } + /** + *+ * Constructor for TwoPhasePipeLine. + *
+ */ + @Deprecated + public TwoPhasePipeLine() { + this("TwoPhasePipeLine"); + } - /** - *- * Constructor for TwoPhasePipeLine. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - @Deprecated - public TwoPhasePipeLine(StreamInterface inStream) { - this("TwoPhasePipeLine", inStream); - } + /** + *+ * Constructor for TwoPhasePipeLine. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + @Deprecated + public TwoPhasePipeLine(StreamInterface inStream) { + this("TwoPhasePipeLine", inStream); + } - /** - * Constructor for TwoPhasePipeLine. - * - * @param name name of pipeline - */ - public TwoPhasePipeLine(String name) { - super(name); - } + /** + * Constructor for TwoPhasePipeLine. + * + * @param name name of pipeline + */ + public TwoPhasePipeLine(String name) { + super(name); + } - /** - *- * Constructor for TwoPhasePipeLine. - *
- * - * @param name a {@link java.lang.String} object - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - public TwoPhasePipeLine(String name, StreamInterface inStream) { - super(name, inStream); - pipe = new TwoPhasePipeFlowSystem(); - } + /** + *+ * Constructor for TwoPhasePipeLine. + *
+ * + * @param name a {@link java.lang.String} object + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + public TwoPhasePipeLine(String name, StreamInterface inStream) { + super(name, inStream); + pipe = new TwoPhasePipeFlowSystem(); + } - /** - *- * createSystem. - *
- */ - public void createSystem() {} + /** + *+ * createSystem. + *
+ */ + public void createSystem() {} - /** {@inheritDoc} */ - @Override - public void run() { - super.run(); - pipe.solveSteadyState(2); - pipe.print(); - pipe.getDisplay().createNetCdfFile(fileName); - } + /** {@inheritDoc} */ + @Override + public void run() { + super.run(); + pipe.solveSteadyState(2); + pipe.print(); + } } diff --git a/src/main/java/neqsim/statistics/parameterFitting/StatisticsInterface.java b/src/main/java/neqsim/statistics/parameterFitting/StatisticsInterface.java index ca6ac8f765..d21b3cd739 100644 --- a/src/main/java/neqsim/statistics/parameterFitting/StatisticsInterface.java +++ b/src/main/java/neqsim/statistics/parameterFitting/StatisticsInterface.java @@ -14,94 +14,85 @@ * @version $Id: $Id */ public interface StatisticsInterface { - /** - *- * createNewRandomClass. - *
- * - * @return a {@link neqsim.statistics.parameterFitting.StatisticsBaseClass} object - */ - public StatisticsBaseClass createNewRandomClass(); + /** + *+ * createNewRandomClass. + *
+ * + * @return a {@link neqsim.statistics.parameterFitting.StatisticsBaseClass} object + */ + public StatisticsBaseClass createNewRandomClass(); - /** - *- * solve. - *
- */ - public void solve(); + /** + *+ * solve. + *
+ */ + public void solve(); - /** - *- * init. - *
- */ - public void init(); + /** + *+ * init. + *
+ */ + public void init(); - /** - *- * getSampleSet. - *
- * - * @return a {@link neqsim.statistics.parameterFitting.SampleSet} object - */ - public SampleSet getSampleSet(); + /** + *+ * getSampleSet. + *
+ * + * @return a {@link neqsim.statistics.parameterFitting.SampleSet} object + */ + public SampleSet getSampleSet(); - /** - *- * displayResult. - *
- */ - public void displayResult(); + /** + *+ * displayResult. + *
+ */ + public void displayResult(); - /** - *- * displayCurveFit. - *
- */ - public void displayCurveFit(); + /** + *+ * displayCurveFit. + *
+ */ + public void displayCurveFit(); - /** - *- * writeToTextFile. - *
- * - * @param name a {@link java.lang.String} object - */ - public void writeToTextFile(String name); + /** + *+ * writeToTextFile. + *
+ * + * @param name a {@link java.lang.String} object + */ + public void writeToTextFile(String name); - /** - *- * writeToCdfFile. - *
- * - * @param name a {@link java.lang.String} object - */ - //public void writeToCdfFile(String name); + /** + *+ * getNumberOfTuningParameters. + *
+ * + * @return a int + */ + public int getNumberOfTuningParameters(); - /** - *- * getNumberOfTuningParameters. - *
- * - * @return a int - */ - public int getNumberOfTuningParameters(); + /** + *+ * setNumberOfTuningParameters. + *
+ * + * @param numberOfTuningParameters a int + */ + public void setNumberOfTuningParameters(int numberOfTuningParameters); - /** - *- * setNumberOfTuningParameters. - *
- * - * @param numberOfTuningParameters a int - */ - public void setNumberOfTuningParameters(int numberOfTuningParameters); - - /** - *- * runMonteCarloSimulation. - *
- * - * @param numberOfRuns a int - */ - public void runMonteCarloSimulation(int numberOfRuns); + /** + *+ * runMonteCarloSimulation. + *
+ * + * @param numberOfRuns a int + */ + public void runMonteCarloSimulation(int numberOfRuns); } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/Procede/CH4CO2WaterMDEA/TestIonicInteractionParameterFittingCH4.java b/src/main/java/neqsim/thermo/util/parameterFitting/Procede/CH4CO2WaterMDEA/TestIonicInteractionParameterFittingCH4.java index 6365a16361..b37ddd59ca 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/Procede/CH4CO2WaterMDEA/TestIonicInteractionParameterFittingCH4.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/Procede/CH4CO2WaterMDEA/TestIonicInteractionParameterFittingCH4.java @@ -12,103 +12,105 @@ import neqsim.util.database.NeqSimDataBase; /** - *TestIonicInteractionParameterFittingCH4 class.
+ *+ * TestIonicInteractionParameterFittingCH4 class. + *
* * @author Even Solbraa * @version $Id: $Id */ public class TestIonicInteractionParameterFittingCH4 { - static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFittingCH4.class); - - /** - *main.
- * - * @param args an array of {@link java.lang.String} objects - */ - @SuppressWarnings("unused") - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + @SuppressWarnings("unused") + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - @SuppressWarnings("unused") - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + @SuppressWarnings("unused") + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * Constructor for BaseOperation. - *
- */ - public BaseOperation() {} + /** + *+ * Constructor for BaseOperation. + *
+ */ + public BaseOperation() {} - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - return new double[3]; - } + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + return new double[3]; + } - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return new String[10][3]; - } + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return new String[10][3]; + } - /** {@inheritDoc} */ - @Override - public SystemInterface getThermoSystem() { - return null; - } + /** {@inheritDoc} */ + @Override + public SystemInterface getThermoSystem() { + return null; + } - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} - /** {@inheritDoc} */ - // @Override - // public void createNetCdfFile(String name) {} + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return null; + } - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return null; - } - - /** {@inheritDoc} */ - @Override - public void addData(String name, double[][] data) {} + /** {@inheritDoc} */ + @Override + public void addData(String name, double[][] data) {} } diff --git a/src/main/java/neqsim/thermodynamicOperations/OperationInterface.java b/src/main/java/neqsim/thermodynamicOperations/OperationInterface.java index 80d9f3a8ba..18a6103b86 100644 --- a/src/main/java/neqsim/thermodynamicOperations/OperationInterface.java +++ b/src/main/java/neqsim/thermodynamicOperations/OperationInterface.java @@ -52,15 +52,6 @@ public interface OperationInterface extends Runnable, java.io.Serializable { */ public String[][] getResultTable(); - /** - *- * createNetCdfFile. - *
- * - * @param name a {@link java.lang.String} object - */ - //public void createNetCdfFile(String name); - /** ** printToFile. diff --git a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java index 27ed545ab0..1e734d6db5 100644 --- a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java +++ b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java @@ -70,1968 +70,1949 @@ * @version $Id: $Id */ public class ThermodynamicOperations implements java.io.Serializable, Cloneable { - private static final long serialVersionUID = 1000; - - private Thread thermoOperationThread = new Thread(); - private OperationInterface operation = null; - SystemInterface system = null; - boolean writeFile = false; - String fileName = null; - private boolean runAsThread = false; - protected String[][] resultTable = null; - static Logger logger = LogManager.getLogger(ThermodynamicOperations.class); - - /** - *
- * Constructor for ThermodynamicOperations. - *
- */ - public ThermodynamicOperations() { - } - - /** - *- * Constructor for ThermodynamicOperations. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public ThermodynamicOperations(SystemInterface system) { - this.system = system; - } - - /** - *
- * Setter for the field system
.
- *
- * TPSolidflash. - *
- */ - public void TPSolidflash() { - operation = new SolidFlash1(system); - getOperation().run(); - } - - /** - * Method to perform a flash at given temperature, pressure and specified volume - * The number of - * moles in the system are changed to match the specified volume. - * - * @param volumeSpec is the specified volume - * @param unit Supported units are m3 - */ - public void TPVflash(double volumeSpec, String unit) { - unit = "m3"; - TPflash(); - double startVolume = system.getVolume(unit); - system.setTotalNumberOfMoles(system.getNumberOfMoles() * volumeSpec / startVolume); - system.init(3); - } - - /** - *- * TPflash. - *
- */ - public void TPflash() { - double flowRate = system.getTotalNumberOfMoles(); - double minimumFlowRate = 1e-50; - if (flowRate < 1e-3) { - system.setTotalNumberOfMoles(1.0); - system.init(1); - } - operation = new neqsim.thermodynamicOperations.flashOps.TPflash(system, - system.doSolidPhaseCheck()); - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - if (flowRate < 1e-3) { - if (flowRate < minimumFlowRate) { - system.setTotalNumberOfMoles(minimumFlowRate); - } else { - system.setTotalNumberOfMoles(flowRate); - } - system.init(2); - } - } - - /** - *- * saturateWithWater. - *
- */ - public void saturateWithWater() { - operation = new SaturateWithWater(system); - getOperation().run(); - } - - /** - *- * TPflash. - *
- * - * @param checkSolids a boolean - */ - public void TPflash(boolean checkSolids) { - operation = new neqsim.thermodynamicOperations.flashOps.TPflash(system, checkSolids); - getOperation().run(); - } - - /** - *- * TPgradientFlash. - *
- * - * @param height a double - * @param temperature a double - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface TPgradientFlash(double height, double temperature) { - operation = new TPgradientFlash(system, height, temperature); - getOperation().run(); - return operation.getThermoSystem(); - } - - /** - *- * dTPflash. - *
- * - * @param comps an array of {@link java.lang.String} objects - */ - public void dTPflash(String[] comps) { - operation = new dTPflash(system, comps); - getOperation().run(); - } - - /** - *- * chemicalEquilibrium. - *
- */ - public void chemicalEquilibrium() { - if (system.isChemicalSystem()) { - operation = new neqsim.thermodynamicOperations.chemicalEquilibrium.ChemicalEquilibrium( - system); - getOperation().run(); - } - } - - /** - *- * PHflash. - *
- * - * @param Hspec a double - * @param type a int - */ - public void PHflash(double Hspec, int type) { - if (system.getPhase(0).getNumberOfComponents() == 1) { - operation = new PHflashSingleComp(system, Hspec, type); - } else { - operation = new PHflash(system, Hspec, type); - } - getOperation().run(); - } - - /** - * Method to perform a PH flash calculation - * - * @param Hspec is the enthalpy in the specified unit - * @param enthalpyUnit Supported units are J, J/mol, J/kg and kJ/kg - */ - public void PHflash(double Hspec, String enthalpyUnit) { - double conversionFactor = 1.0; - switch (enthalpyUnit) { - case "J": - conversionFactor = 1.0; - break; - case "J/mol": - conversionFactor = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kg": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - PHflash(Hspec / conversionFactor); - } - - /** - * Method to perform a PH flash calculation - * - * @param Hspec is the enthalpy in unit Joule to be held constant - */ - public void PHflash(double Hspec) { - this.PHflash(Hspec, 0); - } - - /** - * Method to perform a PH flash calculation based on GERG2008 EoS - * - * @param Hspec is the enthalpy in unit Joule to be held constant - */ - public void PHflashGERG2008(double Hspec) { - operation = new neqsim.thermodynamicOperations.flashOps.PHflashGERG2008(system, Hspec); - getOperation().run(); - } - - /** - *- * PUflash. - *
- * - * @param Uspec a double - */ - public void PUflash(double Uspec) { - operation = new neqsim.thermodynamicOperations.flashOps.PUflash(system, Uspec); - getOperation().run(); - } - - /** - *- * PUflash. - *
- * - * @param Pspec a double - * @param Uspec a double - * @param unitPressure a {@link java.lang.String} object - * @param unitEnergy a {@link java.lang.String} object - */ - public void PUflash(double Pspec, double Uspec, String unitPressure, String unitEnergy) { - system.setPressure(Pspec, unitPressure); - PUflash(Uspec, unitEnergy); - } - - /** - *- * PUflash. - *
- * - * @param Uspec a double - * @param unitEnergy a {@link java.lang.String} object - */ - public void PUflash(double Uspec, String unitEnergy) { - double conversionFactorEntr = 1.0; - switch (unitEnergy) { - case "J": - conversionFactorEntr = 1.0; - break; - case "J/mol": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - PUflash(Uspec / conversionFactorEntr); - } - - /** - *- * PHflash2. - *
- * - * @param Hspec a double - * @param type a int - */ - public void PHflash2(double Hspec, int type) { - operation = new PHflash(system, Hspec, type); - getOperation().run(); - } - - /** - *- * criticalPointFlash. - *
- */ - public void criticalPointFlash() { - operation = new CriticalPointFlash(system); - getOperation().run(); - } - - /** - *- * PHsolidFlash. - *
- * - * @param Hspec a double - */ - public void PHsolidFlash(double Hspec) { - operation = new PHsolidFlash(system, Hspec); - getOperation().run(); - } - - /** - * Method to perform a PS flash calculation for a specified entropy and pressure - * - * @param Sspec is the entropy in the specified unit - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK - */ - public void PSflash(double Sspec, String unit) { - double conversionFactor = 1.0; - switch (unit) { - case "J/K": - conversionFactor = 1.0; - break; - case "J/molK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kgK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kgK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - PSflash(Sspec / conversionFactor); - } - - /** - * Method to perform a TS flash calculation for a specified entropy and pressure - * - * @param Sspec is the entropy in the specified unit - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK - */ - public void TSflash(double Sspec, String unit) { - double conversionFactor = 1.0; - switch (unit) { - case "J/K": - conversionFactor = 1.0; - break; - case "J/molK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kgK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kgK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - TSflash(Sspec / conversionFactor); - } - - /** - *- * PSflash. - *
- * - * @param Sspec a double - */ - public void PSflash(double Sspec) { - if (system.getPhase(0).getNumberOfComponents() == 1) { - operation = new PSflashSingleComp(system, Sspec, 0); - } else { - operation = new PSFlash(system, Sspec, 0); - } - getOperation().run(); - } - - /** - *- * PSflashGERG2008. - *
- * Run a flash at constant pressure and entropy using the GERG2008 EoS - * - * @param Sspec is the specidfied entropy - */ - public void PSflashGERG2008(double Sspec) { - operation = new PSFlashGERG2008(system, Sspec); - getOperation().run(); - } - - /** - *- * TSflash. - *
- * - * @param Sspec a double - */ - public void TSflash(double Sspec) { - operation = new TSFlash(system, Sspec); - getOperation().run(); - } - - /** - *- * PSflash2. - *
- * - * @param Sspec a double - */ - public void PSflash2(double Sspec) { - operation = new PSFlash(system, Sspec, 0); - getOperation().run(); - } - - /** - *- * VSflash. - *
- * - * @param volume a double - * @param entropy a double - * @param unitVol a {@link java.lang.String} object - * @param unitEntropy a {@link java.lang.String} object - */ - public void VSflash(double volume, double entropy, String unitVol, String unitEntropy) { - double conversionFactorV = 1.0; - double conversionFactorEntr = 1.0; - - switch (unitVol) { - case "m3": - conversionFactorV = 1.0e5; - break; - } - - switch (unitEntropy) { - case "J/K": - conversionFactorEntr = 1.0; - break; - case "J/molK": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kgK": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kgK": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - VSflash(volume * conversionFactorV, entropy / conversionFactorEntr); - } - - /** - *- * VSflash. - *
- * - * @param volume a double - * @param entropy a double - */ - public void VSflash(double volume, double entropy) { - operation = new neqsim.thermodynamicOperations.flashOps.VSflash(system, volume, entropy); - getOperation().run(); - } - - /** - *- * TVflash. - *
- * - * @param Vspec a double - * @param unit a {@link java.lang.String} object - */ - public void TVflash(double Vspec, String unit) { - double conversionFactor = 1.0; - switch (unit) { - case "m3": - conversionFactor = 1.0e5; - break; - } - TVflash(Vspec * conversionFactor); - } - - /** - *- * TVflash. - *
- * - * @param Vspec a double - */ - public void TVflash(double Vspec) { - operation = new TVflash(system, Vspec); - getOperation().run(); - } - - /** - *- * PVrefluxFlash. - *
- * - * @param refluxspec a double - * @param refluxPhase a int - */ - public void PVrefluxFlash(double refluxspec, int refluxPhase) { - operation = new PVrefluxflash(system, refluxspec, refluxPhase); - getOperation().run(); - } - - /** - *- * VHflash. - *
- * - * @param Vspec a double - * @param Hspec a double - */ - public void VHflash(double Vspec, double Hspec) { - operation = new VHflashQfunc(system, Vspec, Hspec); - getOperation().run(); - } - - /** - *- * VHflash. - *
- * - * @param volume a double - * @param enthalpy a double - * @param unitVol a {@link java.lang.String} object - * @param unitEnthalpy a {@link java.lang.String} object - */ - public void VHflash(double volume, double enthalpy, String unitVol, String unitEnthalpy) { - double conversionFactorV = 1.0; - double conversionFactorEntr = 1.0; - - switch (unitVol) { - case "m3": - conversionFactorV = 1.0e5; - break; - } - - switch (unitEnthalpy) { - case "J/K": - conversionFactorEntr = 1.0; - break; - case "J/mol": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - VHflash(volume * conversionFactorV, enthalpy / conversionFactorEntr); - } - - /** - *- * VUflash. - *
- * - * @param volume a double - * @param energy a double - * @param unitVol a {@link java.lang.String} object - * @param unitEnergy a {@link java.lang.String} object - */ - public void VUflash(double volume, double energy, String unitVol, String unitEnergy) { - double conversionFactorV = 1.0; - double conversionFactorEntr = 1.0; - - switch (unitVol) { - case "m3": - conversionFactorV = 1.0e5; - break; - } - - switch (unitEnergy) { - case "J/K": - conversionFactorEntr = 1.0; - break; - case "J/mol": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - VUflash(volume * conversionFactorV, energy / conversionFactorEntr); - } - - /** - *- * VUflash. - *
- * - * @param Vspec a double - * @param Uspec a double - */ - public void VUflash(double Vspec, double Uspec) { - operation = new VUflashQfunc(system, Vspec, Uspec); - getOperation().run(); - } - - /** - *- * bubblePointTemperatureFlash. - *
- * - * @throws java.lang.Exception if any. - */ - 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(this.getClass().getSimpleName(), - "bubblePointTemperatureFlash", - "Could not find solution - possible no bubble point exists"); - } - } - - /** - *- * freezingPointTemperatureFlash. - *
- * - * @throws java.lang.Exception if any. - */ - public void freezingPointTemperatureFlash() throws Exception { - operation = new freezingPointTemperatureFlash(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "freezingPointTemperatureFlash", - "Could not find solution - possible no freezing point exists"); - } - } - - /** - *- * freezingPointTemperatureFlash. - *
- * - * @param phaseName a {@link java.lang.String} object - * @throws java.lang.Exception if any. - */ - public void freezingPointTemperatureFlash(String phaseName) throws Exception { - operation = new freezingPointTemperatureFlash(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "freezingPointTemperatureFlash", - "Could not find solution - possible no freezing point exists"); - } - } - - /** - *- * waterDewPointTemperatureFlash. - *
- * - * @throws java.lang.Exception if any. - */ - public void waterDewPointTemperatureFlash() throws Exception { - operation = new waterDewPointTemperatureFlash(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "waterDewPointTemperatureFlash", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * waterDewPointTemperatureMultiphaseFlash. - *
- * - * @throws java.lang.Exception if any. - */ - public void waterDewPointTemperatureMultiphaseFlash() throws Exception { - operation = new waterDewPointTemperatureMultiphaseFlash(system); - getOperation().run(); - } - - /** - *- * waterPrecipitationTemperature. - *
- * - * @throws java.lang.Exception if any. - */ - public void waterPrecipitationTemperature() throws Exception { - double lowTemperature = 0.0; - dewPointTemperatureFlash(); - - if (system.getTemperature() > lowTemperature) { - lowTemperature = system.getTemperature(); - } - - // if(lowTemperature<273.15 && system.doSolidPhaseCheck()){ - // hydrateFormationTemperature(0); - // if(system.getTemperature()>lowTemperature) lowTemperature = - // system.getTemperature(); - // } - - // if(system.doHydrateCheck()){ - // hydrateFormationTemperature(1); - // if(system.getTemperature()>lowTemperature) lowTemperature = - // system.getTemperature(); - // hydrateFormationTemperature(2); - // if(system.getTemperature()>lowTemperature) lowTemperature = - // system.getTemperature(); - // } - - system.setTemperature(lowTemperature); - // TPflash(); - - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "waterPrecipitationTemperature", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * calcSaltSaturation. - *
- * - * @param saltName a {@link java.lang.String} object - * @throws java.lang.Exception if any. - */ - 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(this.getClass().getSimpleName(), - "calcSaltSaturation", "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * checkScalePotential. - *
- * - * @param phaseNumber a int - * @throws java.lang.Exception if any. - */ - public void checkScalePotential(int phaseNumber) throws Exception { - operation = new checkScalePotential(system, phaseNumber); - getOperation().run(); - resultTable = getOperation().getResultTable(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "checkScalePotential", "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * addIonToScaleSaturation. - *
- * - * @param phaseNumber a int - * @param scaleSaltName a {@link java.lang.String} object - * @param nameOfIonToBeAdded a {@link java.lang.String} object - * @throws java.lang.Exception if any. - */ - public void addIonToScaleSaturation(int phaseNumber, String scaleSaltName, - String nameOfIonToBeAdded) throws Exception { - operation = new addIonToScaleSaturation(system, phaseNumber, scaleSaltName, nameOfIonToBeAdded); - getOperation().run(); - resultTable = getOperation().getResultTable(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "addIonToScaleSaturation", "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * hydrateFormationPressure. - *
- * - * @throws java.lang.Exception if any. - */ - public void hydrateFormationPressure() throws Exception { - operation = new HydrateFormationPressureFlash(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "hydrateFormationPressure", "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * calcWAT. - *
- * - * @throws java.lang.Exception if any. - */ - public void calcWAT() throws Exception { - operation = new WATcalc(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), "calcWAT", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * run. - *
- */ - public void run() { - setThermoOperationThread(new Thread(operation)); - getThermoOperationThread().start(); - } - - /** - *- * waitAndCheckForFinishedCalculation. - *
- * - * @param maxTime a int - * @return a boolean - */ - public boolean waitAndCheckForFinishedCalculation(int maxTime) { - try { - getThermoOperationThread().join(maxTime); - getThermoOperationThread().interrupt(); - } catch (Exception e) { - logger.error("error", e); - } - boolean didFinish = !getThermoOperationThread().isInterrupted(); - // getThermoOperationThread().stop(); - return didFinish; - } - - /** - *- * waitToFinishCalculation. - *
- */ - public void waitToFinishCalculation() { - try { - getThermoOperationThread().join(); - } catch (Exception e) { - logger.error("error", e); - } - } - - /** - *- * calcSolidComlexTemperature. - *
- * - * @throws java.lang.Exception if any. - */ - public void calcSolidComlexTemperature() throws Exception { - operation = new SolidComplexTemperatureCalc(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "calcSolidComlexTemperature", - "error in WAT() - could not find solution - possible no dew point exists"); - } - } - - /** - *- * calcSolidComlexTemperature. - *
- * - * @param comp1 a {@link java.lang.String} object - * @param comp2 a {@link java.lang.String} object - * @throws java.lang.Exception if any. - */ - public void calcSolidComlexTemperature(String comp1, String comp2) throws Exception { - if (operation == null) { - operation = new SolidComplexTemperatureCalc(system, comp1, comp2); - } - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "calcSolidComlexTemperature", - "error in WAT() - could not find solution - possible no dew point exists"); - } - } - - /** - *- * calcImobilePhaseHydrateTemperature. - *
- * - * @param temperature an array of {@link double} objects - * @param pressure an array of {@link double} objects - * @return an array of {@link double} objects - */ - public double[] calcImobilePhaseHydrateTemperature(double[] temperature, double[] pressure) { - double[] hydTemps = new double[temperature.length]; - SystemInterface systemTemp; - ThermodynamicOperations opsTemp; - systemTemp = system.clone(); - - for (int i = 0; i < temperature.length; i++) { - /* - * opsTemp = new ThermodynamicOperations(systemTemp); - * systemTemp.setTemperature(temperature[i]); - * systemTemp.setPressure(pressure[i]); - * systemTemp.init(0); systemTemp.display(); try { - * opsTemp.hydrateFormationTemperature(); } catch (Exception e) { - * logger.error("error",e); } systemTemp.display(); hydTemps[i] = - * systemTemp.getTemperature(); - * - */ - opsTemp = new ThermodynamicOperations(systemTemp); - systemTemp.setTemperature(temperature[i]); - systemTemp.setPressure(pressure[i]); - - opsTemp.TPflash(); - systemTemp.display(); - systemTemp = systemTemp.phaseToSystem(0); - } - - opsTemp = new ThermodynamicOperations(systemTemp); - systemTemp.setHydrateCheck(true); - systemTemp.setMixingRule(9); - try { - opsTemp.hydrateFormationTemperature(); - } catch (Exception e) { - logger.error("error", e); - } - systemTemp.display(); - return hydTemps; - } - - /** - *- * calcTOLHydrateFormationTemperature. - *
- * - * @return a double - */ - public double calcTOLHydrateFormationTemperature() { - TPflash(); - - SystemInterface systemTemp = system.phaseToSystem(0); - ThermodynamicOperations opsTemp = new ThermodynamicOperations(systemTemp); - try { - opsTemp.hydrateFormationTemperature(); - } catch (Exception e) { - logger.error("error", e); - } - systemTemp.display(); - system.setTemperature(systemTemp.getTemperature()); - TPflash(); - return system.getTemperature(); - } - - /** - *- * hydrateInhibitorConcentration. - *
- * - * @param inhibitorName a {@link java.lang.String} object - * @param hydEqTemperature a double - * @throws java.lang.Exception if any. - */ - public void hydrateInhibitorConcentration(String inhibitorName, double hydEqTemperature) - throws Exception { - operation = new HydrateInhibitorConcentrationFlash(system, inhibitorName, hydEqTemperature); - operation.run(); - } - - /** - *- * hydrateInhibitorConcentrationSet. - *
- * - * @param inhibitorName a {@link java.lang.String} object - * @param wtfrac a double - * @throws java.lang.Exception if any. - */ - public void hydrateInhibitorConcentrationSet(String inhibitorName, double wtfrac) - throws Exception { - operation = new HydrateInhibitorwtFlash(system, inhibitorName, wtfrac); - operation.run(); - } - - /** - *- * hydrateFormationTemperature. - *
- * - * @param initialTemperatureGuess a double - * @throws java.lang.Exception if any. - */ - public void hydrateFormationTemperature(double initialTemperatureGuess) throws Exception { - system.setTemperature(initialTemperatureGuess); - operation = new HydrateFormationTemperatureFlash(system); - for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { - ((ComponentHydrate) system.getPhase(4).getComponent(i)).getHydrateStructure(); - } - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - } - - /** - *- * hydrateFormationTemperature. - *
- * - * @throws java.lang.Exception if any. - */ - public void hydrateFormationTemperature() throws Exception { - // guessing temperature - double factor = 1.0; - if (system.getPhase(0).hasComponent("methanol")) { - factor -= 2 * system.getPhase(0).getComponent("methanol").getz() - / system.getPhase(0).getComponent("water").getz(); - } - if (system.getPhase(0).hasComponent("MEG")) { - factor -= 2 * system.getPhase(0).getComponent("MEG").getz() - / system.getPhase(0).getComponent("water").getz(); - } - if (factor < 2) { - factor = 2; - } - - system.setTemperature(273.0 + system.getPressure() / 100.0 * 20.0 * factor - 20.0); - if (system.getTemperature() > 298.15) { - system.setTemperature(273.0 + 25.0); - } - // logger.info("guess hydrate temperature " + system.getTemperature()); - operation = new HydrateFormationTemperatureFlash(system); - - for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { - ((ComponentHydrate) system.getPhase(4).getComponent(i)).getHydrateStructure(); - } - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - // logger.info("Hydrate structure " + (((ComponentHydrate) - // system.getPhase(4).getComponent("water")).getHydrateStructure() + 1)); - } - - /** - *- * hydrateEquilibriumLine. - *
- * - * @param minimumPressure a double - * @param maximumPressure a double - * @throws java.lang.Exception if any. - */ - public void hydrateEquilibriumLine(double minimumPressure, double maximumPressure) - throws Exception { - operation = new HydrateEquilibriumLine(system, minimumPressure, maximumPressure); - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - } - - /** - *- * calcCricoP. - *
- * - * @param cricondenBar an array of {@link double} objects - * @param cricondenBarX an array of {@link double} objects - * @param cricondenBarY an array of {@link double} objects - */ - public void calcCricoP(double[] cricondenBar, double[] cricondenBarX, double[] cricondenBarY) { - double phasefraction = 1.0 - 1e-10; - - operation = new CricondenBarFlash(system, fileName, phasefraction, cricondenBar, - cricondenBarX, cricondenBarY); - - getOperation().run(); - } - - /** - *- * calcCricoT. - *
- * - * @param cricondenTherm an array of {@link double} objects - * @param cricondenThermX an array of {@link double} objects - * @param cricondenThermY an array of {@link double} objects - */ - public void calcCricoT(double[] cricondenTherm, double[] cricondenThermX, - double[] cricondenThermY) { - double phasefraction = 1.0 - 1e-10; - - operation = new CricondenThermFlash(system, fileName, phasefraction, cricondenTherm, - cricondenThermX, cricondenThermY); - - getOperation().run(); - } - - /** - *- * waterDewPointLine. - *
- * - * @param minimumPressure a double - * @param maximumPressure a double - * @throws java.lang.Exception if any. - */ - public void waterDewPointLine(double minimumPressure, double maximumPressure) throws Exception { - operation = new WaterDewPointEquilibriumLine(system, minimumPressure, maximumPressure); - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - } - - /** - *- * hydrateFormationTemperature. - *
- * - * @param structure a int - * @throws java.lang.Exception if any. - */ - public void hydrateFormationTemperature(int structure) throws Exception { - system.setTemperature(273.0 + 1.0); - if (structure == 0) { - system.setSolidPhaseCheck("water"); - system.setHydrateCheck(true); - operation = new freezingPointTemperatureFlash(system); - } else { - operation = new HydrateFormationTemperatureFlash(system); - } - - for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { - ((ComponentHydrate) system.getPhases()[4].getComponent(i)) - .setHydrateStructure(structure - 1); - } - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "hydrateFormationTemperature", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * calcCricondenBar. - *
- * - * @return a double - */ - public double calcCricondenBar() { - system.init(0); - operation = new cricondebarFlash(system); - // operation = new CricondenBarFlash(system); - - // operation = new cricondenBarTemp1(system); - operation.run(); - return system.getPressure(); - } - - /** - *- * bubblePointPressureFlash. - *
- * - * @throws java.lang.Exception if any. - */ - public void bubblePointPressureFlash() throws Exception { - system.init(0); - constantDutyFlashInterface operation = new constantDutyPressureFlash(system); - system.setBeta(1, 1.0 - 1e-10); - system.setBeta(0, 1e-10); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); - } - } + private static final long serialVersionUID = 1000; + + private Thread thermoOperationThread = new Thread(); + private OperationInterface operation = null; + SystemInterface system = null; + boolean writeFile = false; + String fileName = null; + private boolean runAsThread = false; + protected String[][] resultTable = null; + static Logger logger = LogManager.getLogger(ThermodynamicOperations.class); + + /** + *+ * Constructor for ThermodynamicOperations. + *
+ */ + public ThermodynamicOperations() {} + + /** + *+ * Constructor for ThermodynamicOperations. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public ThermodynamicOperations(SystemInterface system) { + this.system = system; + } + + /** + *
+ * Setter for the field system
.
+ *
+ * TPSolidflash. + *
+ */ + public void TPSolidflash() { + operation = new SolidFlash1(system); + getOperation().run(); + } + + /** + * Method to perform a flash at given temperature, pressure and specified volume The number of + * moles in the system are changed to match the specified volume. + * + * @param volumeSpec is the specified volume + * @param unit Supported units are m3 + */ + public void TPVflash(double volumeSpec, String unit) { + unit = "m3"; + TPflash(); + double startVolume = system.getVolume(unit); + system.setTotalNumberOfMoles(system.getNumberOfMoles() * volumeSpec / startVolume); + system.init(3); + } + + /** + *+ * TPflash. + *
+ */ + public void TPflash() { + double flowRate = system.getTotalNumberOfMoles(); + double minimumFlowRate = 1e-50; + if (flowRate < 1e-3) { + system.setTotalNumberOfMoles(1.0); + system.init(1); + } + operation = + new neqsim.thermodynamicOperations.flashOps.TPflash(system, system.doSolidPhaseCheck()); + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + if (flowRate < 1e-3) { + if (flowRate < minimumFlowRate) { + system.setTotalNumberOfMoles(minimumFlowRate); + } else { + system.setTotalNumberOfMoles(flowRate); + } + system.init(2); + } + } + + /** + *+ * saturateWithWater. + *
+ */ + public void saturateWithWater() { + operation = new SaturateWithWater(system); + getOperation().run(); + } + + /** + *+ * TPflash. + *
+ * + * @param checkSolids a boolean + */ + public void TPflash(boolean checkSolids) { + operation = new neqsim.thermodynamicOperations.flashOps.TPflash(system, checkSolids); + getOperation().run(); + } + + /** + *+ * TPgradientFlash. + *
+ * + * @param height a double + * @param temperature a double + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface TPgradientFlash(double height, double temperature) { + operation = new TPgradientFlash(system, height, temperature); + getOperation().run(); + return operation.getThermoSystem(); + } + + /** + *+ * dTPflash. + *
+ * + * @param comps an array of {@link java.lang.String} objects + */ + public void dTPflash(String[] comps) { + operation = new dTPflash(system, comps); + getOperation().run(); + } + + /** + *+ * chemicalEquilibrium. + *
+ */ + public void chemicalEquilibrium() { + if (system.isChemicalSystem()) { + operation = + new neqsim.thermodynamicOperations.chemicalEquilibrium.ChemicalEquilibrium(system); + getOperation().run(); + } + } + + /** + *+ * PHflash. + *
+ * + * @param Hspec a double + * @param type a int + */ + public void PHflash(double Hspec, int type) { + if (system.getPhase(0).getNumberOfComponents() == 1) { + operation = new PHflashSingleComp(system, Hspec, type); + } else { + operation = new PHflash(system, Hspec, type); + } + getOperation().run(); + } + + /** + * Method to perform a PH flash calculation + * + * @param Hspec is the enthalpy in the specified unit + * @param enthalpyUnit Supported units are J, J/mol, J/kg and kJ/kg + */ + public void PHflash(double Hspec, String enthalpyUnit) { + double conversionFactor = 1.0; + switch (enthalpyUnit) { + case "J": + conversionFactor = 1.0; + break; + case "J/mol": + conversionFactor = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kg": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + } + PHflash(Hspec / conversionFactor); + } + + /** + * Method to perform a PH flash calculation + * + * @param Hspec is the enthalpy in unit Joule to be held constant + */ + public void PHflash(double Hspec) { + this.PHflash(Hspec, 0); + } + + /** + * Method to perform a PH flash calculation based on GERG2008 EoS + * + * @param Hspec is the enthalpy in unit Joule to be held constant + */ + public void PHflashGERG2008(double Hspec) { + operation = new neqsim.thermodynamicOperations.flashOps.PHflashGERG2008(system, Hspec); + getOperation().run(); + } + + /** + *+ * PUflash. + *
+ * + * @param Uspec a double + */ + public void PUflash(double Uspec) { + operation = new neqsim.thermodynamicOperations.flashOps.PUflash(system, Uspec); + getOperation().run(); + } + + /** + *+ * PUflash. + *
+ * + * @param Pspec a double + * @param Uspec a double + * @param unitPressure a {@link java.lang.String} object + * @param unitEnergy a {@link java.lang.String} object + */ + public void PUflash(double Pspec, double Uspec, String unitPressure, String unitEnergy) { + system.setPressure(Pspec, unitPressure); + PUflash(Uspec, unitEnergy); + } + + /** + *+ * PUflash. + *
+ * + * @param Uspec a double + * @param unitEnergy a {@link java.lang.String} object + */ + public void PUflash(double Uspec, String unitEnergy) { + double conversionFactorEntr = 1.0; + switch (unitEnergy) { + case "J": + conversionFactorEntr = 1.0; + break; + case "J/mol": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kg": + conversionFactorEntr = + 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + } + PUflash(Uspec / conversionFactorEntr); + } + + /** + *+ * PHflash2. + *
+ * + * @param Hspec a double + * @param type a int + */ + public void PHflash2(double Hspec, int type) { + operation = new PHflash(system, Hspec, type); + getOperation().run(); + } + + /** + *+ * criticalPointFlash. + *
+ */ + public void criticalPointFlash() { + operation = new CriticalPointFlash(system); + getOperation().run(); + } + + /** + *+ * PHsolidFlash. + *
+ * + * @param Hspec a double + */ + public void PHsolidFlash(double Hspec) { + operation = new PHsolidFlash(system, Hspec); + getOperation().run(); + } + + /** + * Method to perform a PS flash calculation for a specified entropy and pressure + * + * @param Sspec is the entropy in the specified unit + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + */ + public void PSflash(double Sspec, String unit) { + double conversionFactor = 1.0; + switch (unit) { + case "J/K": + conversionFactor = 1.0; + break; + case "J/molK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kgK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kgK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + } + PSflash(Sspec / conversionFactor); + } + + /** + * Method to perform a TS flash calculation for a specified entropy and pressure + * + * @param Sspec is the entropy in the specified unit + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + */ + public void TSflash(double Sspec, String unit) { + double conversionFactor = 1.0; + switch (unit) { + case "J/K": + conversionFactor = 1.0; + break; + case "J/molK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kgK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kgK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + } + TSflash(Sspec / conversionFactor); + } + + /** + *+ * PSflash. + *
+ * + * @param Sspec a double + */ + public void PSflash(double Sspec) { + if (system.getPhase(0).getNumberOfComponents() == 1) { + operation = new PSflashSingleComp(system, Sspec, 0); + } else { + operation = new PSFlash(system, Sspec, 0); + } + getOperation().run(); + } + + /** + *+ * PSflashGERG2008. + *
+ * Run a flash at constant pressure and entropy using the GERG2008 EoS + * + * @param Sspec is the specidfied entropy + */ + public void PSflashGERG2008(double Sspec) { + operation = new PSFlashGERG2008(system, Sspec); + getOperation().run(); + } + + /** + *+ * TSflash. + *
+ * + * @param Sspec a double + */ + public void TSflash(double Sspec) { + operation = new TSFlash(system, Sspec); + getOperation().run(); + } + + /** + *+ * PSflash2. + *
+ * + * @param Sspec a double + */ + public void PSflash2(double Sspec) { + operation = new PSFlash(system, Sspec, 0); + getOperation().run(); + } + + /** + *+ * VSflash. + *
+ * + * @param volume a double + * @param entropy a double + * @param unitVol a {@link java.lang.String} object + * @param unitEntropy a {@link java.lang.String} object + */ + public void VSflash(double volume, double entropy, String unitVol, String unitEntropy) { + double conversionFactorV = 1.0; + double conversionFactorEntr = 1.0; + + switch (unitVol) { + case "m3": + conversionFactorV = 1.0e5; + break; + } + + switch (unitEntropy) { + case "J/K": + conversionFactorEntr = 1.0; + break; + case "J/molK": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kgK": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kgK": + conversionFactorEntr = + 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + } + VSflash(volume * conversionFactorV, entropy / conversionFactorEntr); + } + + /** + *+ * VSflash. + *
+ * + * @param volume a double + * @param entropy a double + */ + public void VSflash(double volume, double entropy) { + operation = new neqsim.thermodynamicOperations.flashOps.VSflash(system, volume, entropy); + getOperation().run(); + } + + /** + *+ * TVflash. + *
+ * + * @param Vspec a double + * @param unit a {@link java.lang.String} object + */ + public void TVflash(double Vspec, String unit) { + double conversionFactor = 1.0; + switch (unit) { + case "m3": + conversionFactor = 1.0e5; + break; + } + TVflash(Vspec * conversionFactor); + } + + /** + *+ * TVflash. + *
+ * + * @param Vspec a double + */ + public void TVflash(double Vspec) { + operation = new TVflash(system, Vspec); + getOperation().run(); + } + + /** + *+ * PVrefluxFlash. + *
+ * + * @param refluxspec a double + * @param refluxPhase a int + */ + public void PVrefluxFlash(double refluxspec, int refluxPhase) { + operation = new PVrefluxflash(system, refluxspec, refluxPhase); + getOperation().run(); + } + + /** + *+ * VHflash. + *
+ * + * @param Vspec a double + * @param Hspec a double + */ + public void VHflash(double Vspec, double Hspec) { + operation = new VHflashQfunc(system, Vspec, Hspec); + getOperation().run(); + } + + /** + *+ * VHflash. + *
+ * + * @param volume a double + * @param enthalpy a double + * @param unitVol a {@link java.lang.String} object + * @param unitEnthalpy a {@link java.lang.String} object + */ + public void VHflash(double volume, double enthalpy, String unitVol, String unitEnthalpy) { + double conversionFactorV = 1.0; + double conversionFactorEntr = 1.0; + + switch (unitVol) { + case "m3": + conversionFactorV = 1.0e5; + break; + } + + switch (unitEnthalpy) { + case "J/K": + conversionFactorEntr = 1.0; + break; + case "J/mol": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kg": + conversionFactorEntr = + 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + } + VHflash(volume * conversionFactorV, enthalpy / conversionFactorEntr); + } + + /** + *+ * VUflash. + *
+ * + * @param volume a double + * @param energy a double + * @param unitVol a {@link java.lang.String} object + * @param unitEnergy a {@link java.lang.String} object + */ + public void VUflash(double volume, double energy, String unitVol, String unitEnergy) { + double conversionFactorV = 1.0; + double conversionFactorEntr = 1.0; + + switch (unitVol) { + case "m3": + conversionFactorV = 1.0e5; + break; + } + + switch (unitEnergy) { + case "J/K": + conversionFactorEntr = 1.0; + break; + case "J/mol": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kg": + conversionFactorEntr = + 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + } + VUflash(volume * conversionFactorV, energy / conversionFactorEntr); + } + + /** + *+ * VUflash. + *
+ * + * @param Vspec a double + * @param Uspec a double + */ + public void VUflash(double Vspec, double Uspec) { + operation = new VUflashQfunc(system, Vspec, Uspec); + getOperation().run(); + } + + /** + *+ * bubblePointTemperatureFlash. + *
+ * + * @throws java.lang.Exception if any. + */ + 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(this.getClass().getSimpleName(), + "bubblePointTemperatureFlash", + "Could not find solution - possible no bubble point exists"); + } + } + + /** + *+ * freezingPointTemperatureFlash. + *
+ * + * @throws java.lang.Exception if any. + */ + public void freezingPointTemperatureFlash() throws Exception { + operation = new freezingPointTemperatureFlash(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "freezingPointTemperatureFlash", + "Could not find solution - possible no freezing point exists"); + } + } + + /** + *+ * freezingPointTemperatureFlash. + *
+ * + * @param phaseName a {@link java.lang.String} object + * @throws java.lang.Exception if any. + */ + public void freezingPointTemperatureFlash(String phaseName) throws Exception { + operation = new freezingPointTemperatureFlash(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "freezingPointTemperatureFlash", + "Could not find solution - possible no freezing point exists"); + } + } + + /** + *+ * waterDewPointTemperatureFlash. + *
+ * + * @throws java.lang.Exception if any. + */ + public void waterDewPointTemperatureFlash() throws Exception { + operation = new waterDewPointTemperatureFlash(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "waterDewPointTemperatureFlash", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * waterDewPointTemperatureMultiphaseFlash. + *
+ * + * @throws java.lang.Exception if any. + */ + public void waterDewPointTemperatureMultiphaseFlash() throws Exception { + operation = new waterDewPointTemperatureMultiphaseFlash(system); + getOperation().run(); + } + + /** + *+ * waterPrecipitationTemperature. + *
+ * + * @throws java.lang.Exception if any. + */ + public void waterPrecipitationTemperature() throws Exception { + double lowTemperature = 0.0; + dewPointTemperatureFlash(); + + if (system.getTemperature() > lowTemperature) { + lowTemperature = system.getTemperature(); + } + + // if(lowTemperature<273.15 && system.doSolidPhaseCheck()){ + // hydrateFormationTemperature(0); + // if(system.getTemperature()>lowTemperature) lowTemperature = + // system.getTemperature(); + // } - /** - *- * constantPhaseFractionPressureFlash. - *
- * - * @param fraction a double - * @throws java.lang.Exception if any. - */ - public void constantPhaseFractionPressureFlash(double fraction) throws Exception { - system.init(0); - if (fraction < 1e-10) { - fraction = 1e-10; - } - if (fraction > 1.0 - 1e-10) { - fraction = 1.0 - 1.0e-10; - } - constantDutyFlashInterface operation = new constantDutyPressureFlash(system); - system.setBeta(1, 1.0 - fraction); - system.setBeta(0, fraction); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "constantPhaseFractionPressureFlash", - "Could not find solution - possible no dew point exists"); - } - } + // if(system.doHydrateCheck()){ + // hydrateFormationTemperature(1); + // if(system.getTemperature()>lowTemperature) lowTemperature = + // system.getTemperature(); + // hydrateFormationTemperature(2); + // if(system.getTemperature()>lowTemperature) lowTemperature = + // system.getTemperature(); + // } - /** - *- * constantPhaseFractionTemperatureFlash. - *
- * - * @param fraction a double - * @throws java.lang.Exception if any. - */ - public void constantPhaseFractionTemperatureFlash(double fraction) throws Exception { + system.setTemperature(lowTemperature); + // TPflash(); + + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "waterPrecipitationTemperature", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * calcSaltSaturation. + *
+ * + * @param saltName a {@link java.lang.String} object + * @throws java.lang.Exception if any. + */ + 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(this.getClass().getSimpleName(), + "calcSaltSaturation", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * checkScalePotential. + *
+ * + * @param phaseNumber a int + * @throws java.lang.Exception if any. + */ + public void checkScalePotential(int phaseNumber) throws Exception { + operation = new checkScalePotential(system, phaseNumber); + getOperation().run(); + resultTable = getOperation().getResultTable(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "checkScalePotential", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * addIonToScaleSaturation. + *
+ * + * @param phaseNumber a int + * @param scaleSaltName a {@link java.lang.String} object + * @param nameOfIonToBeAdded a {@link java.lang.String} object + * @throws java.lang.Exception if any. + */ + public void addIonToScaleSaturation(int phaseNumber, String scaleSaltName, + String nameOfIonToBeAdded) throws Exception { + operation = new addIonToScaleSaturation(system, phaseNumber, scaleSaltName, nameOfIonToBeAdded); + getOperation().run(); + resultTable = getOperation().getResultTable(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "addIonToScaleSaturation", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * hydrateFormationPressure. + *
+ * + * @throws java.lang.Exception if any. + */ + public void hydrateFormationPressure() throws Exception { + operation = new HydrateFormationPressureFlash(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "hydrateFormationPressure", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * calcWAT. + *
+ * + * @throws java.lang.Exception if any. + */ + public void calcWAT() throws Exception { + operation = new WATcalc(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), "calcWAT", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * run. + *
+ */ + public void run() { + setThermoOperationThread(new Thread(operation)); + getThermoOperationThread().start(); + } + + /** + *+ * waitAndCheckForFinishedCalculation. + *
+ * + * @param maxTime a int + * @return a boolean + */ + public boolean waitAndCheckForFinishedCalculation(int maxTime) { + try { + getThermoOperationThread().join(maxTime); + getThermoOperationThread().interrupt(); + } catch (Exception e) { + logger.error("error", e); + } + boolean didFinish = !getThermoOperationThread().isInterrupted(); + // getThermoOperationThread().stop(); + return didFinish; + } + + /** + *+ * waitToFinishCalculation. + *
+ */ + public void waitToFinishCalculation() { + try { + getThermoOperationThread().join(); + } catch (Exception e) { + logger.error("error", e); + } + } + + /** + *+ * calcSolidComlexTemperature. + *
+ * + * @throws java.lang.Exception if any. + */ + public void calcSolidComlexTemperature() throws Exception { + operation = new SolidComplexTemperatureCalc(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "calcSolidComlexTemperature", + "error in WAT() - could not find solution - possible no dew point exists"); + } + } + + /** + *+ * calcSolidComlexTemperature. + *
+ * + * @param comp1 a {@link java.lang.String} object + * @param comp2 a {@link java.lang.String} object + * @throws java.lang.Exception if any. + */ + public void calcSolidComlexTemperature(String comp1, String comp2) throws Exception { + if (operation == null) { + operation = new SolidComplexTemperatureCalc(system, comp1, comp2); + } + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "calcSolidComlexTemperature", + "error in WAT() - could not find solution - possible no dew point exists"); + } + } + + /** + *+ * calcImobilePhaseHydrateTemperature. + *
+ * + * @param temperature an array of {@link double} objects + * @param pressure an array of {@link double} objects + * @return an array of {@link double} objects + */ + public double[] calcImobilePhaseHydrateTemperature(double[] temperature, double[] pressure) { + double[] hydTemps = new double[temperature.length]; + SystemInterface systemTemp; + ThermodynamicOperations opsTemp; + systemTemp = system.clone(); + + for (int i = 0; i < temperature.length; i++) { + /* + * opsTemp = new ThermodynamicOperations(systemTemp); + * systemTemp.setTemperature(temperature[i]); systemTemp.setPressure(pressure[i]); + * systemTemp.init(0); systemTemp.display(); try { opsTemp.hydrateFormationTemperature(); } + * catch (Exception e) { logger.error("error",e); } systemTemp.display(); hydTemps[i] = + * systemTemp.getTemperature(); + * + */ + opsTemp = new ThermodynamicOperations(systemTemp); + systemTemp.setTemperature(temperature[i]); + systemTemp.setPressure(pressure[i]); + + opsTemp.TPflash(); + systemTemp.display(); + systemTemp = systemTemp.phaseToSystem(0); + } + + opsTemp = new ThermodynamicOperations(systemTemp); + systemTemp.setHydrateCheck(true); + systemTemp.setMixingRule(9); + try { + opsTemp.hydrateFormationTemperature(); + } catch (Exception e) { + logger.error("error", e); + } + systemTemp.display(); + return hydTemps; + } + + /** + *+ * calcTOLHydrateFormationTemperature. + *
+ * + * @return a double + */ + public double calcTOLHydrateFormationTemperature() { + TPflash(); + + SystemInterface systemTemp = system.phaseToSystem(0); + ThermodynamicOperations opsTemp = new ThermodynamicOperations(systemTemp); + try { + opsTemp.hydrateFormationTemperature(); + } catch (Exception e) { + logger.error("error", e); + } + systemTemp.display(); + system.setTemperature(systemTemp.getTemperature()); + TPflash(); + return system.getTemperature(); + } + + /** + *+ * hydrateInhibitorConcentration. + *
+ * + * @param inhibitorName a {@link java.lang.String} object + * @param hydEqTemperature a double + * @throws java.lang.Exception if any. + */ + public void hydrateInhibitorConcentration(String inhibitorName, double hydEqTemperature) + throws Exception { + operation = new HydrateInhibitorConcentrationFlash(system, inhibitorName, hydEqTemperature); + operation.run(); + } + + /** + *+ * hydrateInhibitorConcentrationSet. + *
+ * + * @param inhibitorName a {@link java.lang.String} object + * @param wtfrac a double + * @throws java.lang.Exception if any. + */ + public void hydrateInhibitorConcentrationSet(String inhibitorName, double wtfrac) + throws Exception { + operation = new HydrateInhibitorwtFlash(system, inhibitorName, wtfrac); + operation.run(); + } + + /** + *+ * hydrateFormationTemperature. + *
+ * + * @param initialTemperatureGuess a double + * @throws java.lang.Exception if any. + */ + public void hydrateFormationTemperature(double initialTemperatureGuess) throws Exception { + system.setTemperature(initialTemperatureGuess); + operation = new HydrateFormationTemperatureFlash(system); + for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { + ((ComponentHydrate) system.getPhase(4).getComponent(i)).getHydrateStructure(); + } + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + } + + /** + *+ * hydrateFormationTemperature. + *
+ * + * @throws java.lang.Exception if any. + */ + public void hydrateFormationTemperature() throws Exception { + // guessing temperature + double factor = 1.0; + if (system.getPhase(0).hasComponent("methanol")) { + factor -= 2 * system.getPhase(0).getComponent("methanol").getz() + / system.getPhase(0).getComponent("water").getz(); + } + if (system.getPhase(0).hasComponent("MEG")) { + factor -= 2 * system.getPhase(0).getComponent("MEG").getz() + / system.getPhase(0).getComponent("water").getz(); + } + if (factor < 2) { + factor = 2; + } + + system.setTemperature(273.0 + system.getPressure() / 100.0 * 20.0 * factor - 20.0); + if (system.getTemperature() > 298.15) { + system.setTemperature(273.0 + 25.0); + } + // logger.info("guess hydrate temperature " + system.getTemperature()); + operation = new HydrateFormationTemperatureFlash(system); + + for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { + ((ComponentHydrate) system.getPhase(4).getComponent(i)).getHydrateStructure(); + } + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + // logger.info("Hydrate structure " + (((ComponentHydrate) + // system.getPhase(4).getComponent("water")).getHydrateStructure() + 1)); + } + + /** + *+ * hydrateEquilibriumLine. + *
+ * + * @param minimumPressure a double + * @param maximumPressure a double + * @throws java.lang.Exception if any. + */ + public void hydrateEquilibriumLine(double minimumPressure, double maximumPressure) + throws Exception { + operation = new HydrateEquilibriumLine(system, minimumPressure, maximumPressure); + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + } + + /** + *+ * calcCricoP. + *
+ * + * @param cricondenBar an array of {@link double} objects + * @param cricondenBarX an array of {@link double} objects + * @param cricondenBarY an array of {@link double} objects + */ + public void calcCricoP(double[] cricondenBar, double[] cricondenBarX, double[] cricondenBarY) { + double phasefraction = 1.0 - 1e-10; + + operation = new CricondenBarFlash(system, fileName, phasefraction, cricondenBar, cricondenBarX, + cricondenBarY); + + getOperation().run(); + } + + /** + *+ * calcCricoT. + *
+ * + * @param cricondenTherm an array of {@link double} objects + * @param cricondenThermX an array of {@link double} objects + * @param cricondenThermY an array of {@link double} objects + */ + public void calcCricoT(double[] cricondenTherm, double[] cricondenThermX, + double[] cricondenThermY) { + double phasefraction = 1.0 - 1e-10; + + operation = new CricondenThermFlash(system, fileName, phasefraction, cricondenTherm, + cricondenThermX, cricondenThermY); + + getOperation().run(); + } + + /** + *+ * waterDewPointLine. + *
+ * + * @param minimumPressure a double + * @param maximumPressure a double + * @throws java.lang.Exception if any. + */ + public void waterDewPointLine(double minimumPressure, double maximumPressure) throws Exception { + operation = new WaterDewPointEquilibriumLine(system, minimumPressure, maximumPressure); + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + } + + /** + *+ * hydrateFormationTemperature. + *
+ * + * @param structure a int + * @throws java.lang.Exception if any. + */ + public void hydrateFormationTemperature(int structure) throws Exception { + system.setTemperature(273.0 + 1.0); + if (structure == 0) { + system.setSolidPhaseCheck("water"); + system.setHydrateCheck(true); + operation = new freezingPointTemperatureFlash(system); + } else { + operation = new HydrateFormationTemperatureFlash(system); + } + + for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { + ((ComponentHydrate) system.getPhases()[4].getComponent(i)).setHydrateStructure(structure - 1); + } + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "hydrateFormationTemperature", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * calcCricondenBar. + *
+ * + * @return a double + */ + public double calcCricondenBar() { + system.init(0); + operation = new cricondebarFlash(system); + // operation = new CricondenBarFlash(system); + + // operation = new cricondenBarTemp1(system); + operation.run(); + return system.getPressure(); + } + + /** + *+ * bubblePointPressureFlash. + *
+ * + * @throws java.lang.Exception if any. + */ + public void bubblePointPressureFlash() throws Exception { + system.init(0); + constantDutyFlashInterface operation = new constantDutyPressureFlash(system); + system.setBeta(1, 1.0 - 1e-10); + system.setBeta(0, 1e-10); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * constantPhaseFractionPressureFlash. + *
+ * + * @param fraction a double + * @throws java.lang.Exception if any. + */ + public void constantPhaseFractionPressureFlash(double fraction) throws Exception { + system.init(0); + if (fraction < 1e-10) { + fraction = 1e-10; + } + if (fraction > 1.0 - 1e-10) { + fraction = 1.0 - 1.0e-10; + } + constantDutyFlashInterface operation = new constantDutyPressureFlash(system); + system.setBeta(1, 1.0 - fraction); + system.setBeta(0, fraction); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "constantPhaseFractionPressureFlash", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * constantPhaseFractionTemperatureFlash. + *
+ * + * @param fraction a double + * @throws java.lang.Exception if any. + */ + public void constantPhaseFractionTemperatureFlash(double fraction) throws Exception { + system.init(0); + if (fraction < 1e-10) { + fraction = 1e-10; + } + if (fraction > 1.0 - 1e-10) { + fraction = 1.0 - 1.0e-10; + } + constantDutyFlashInterface operation = new constantDutyTemperatureFlash(system); + system.setBeta(1, fraction); + system.setBeta(0, fraction); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "constantPhaseFractionTemperatureFlash", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * bubblePointPressureFlash. + *
+ * + * @param derivatives a boolean + * @throws java.lang.Exception if any. + */ + public void bubblePointPressureFlash(boolean derivatives) throws Exception { + constantDutyFlashInterface operation = null; + if (derivatives == true) { + operation = new bubblePointPressureFlashDer(system); + } else { + operation = new bubblePointPressureFlash(system); + } + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * dewPointMach. + *
+ * + * @param componentName a {@link java.lang.String} object + * @param specification a {@link java.lang.String} object + * @param spec a double + * @throws java.lang.Exception if any. + */ + public void dewPointMach(String componentName, String specification, double spec) + throws Exception { + // int componentNumber = + // system.getPhase(0).getComponent(componentName).getComponentNumber(); + + double dn = 0; + if (system.getPhase(0).hasComponent(componentName)) { + dn = system.getNumberOfMoles() / 1.0e6; + system.addComponent(componentName, dn); + } else { + 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; + if (specification.equals("dewPointTemperature")) { + // logger.info("new temperature " + newTemperature); + do { + iterations++; system.init(0); - if (fraction < 1e-10) { - fraction = 1e-10; - } - if (fraction > 1.0 - 1e-10) { - fraction = 1.0 - 1.0e-10; - } - constantDutyFlashInterface operation = new constantDutyTemperatureFlash(system); - system.setBeta(1, fraction); - system.setBeta(0, fraction); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "constantPhaseFractionTemperatureFlash", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * bubblePointPressureFlash. - *
- * - * @param derivatives a boolean - * @throws java.lang.Exception if any. - */ - public void bubblePointPressureFlash(boolean derivatives) throws Exception { - constantDutyFlashInterface operation = null; - if (derivatives == true) { - operation = new bubblePointPressureFlashDer(system); - } else { - operation = new bubblePointPressureFlash(system); - } - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * dewPointMach. - *
- * - * @param componentName a {@link java.lang.String} object - * @param specification a {@link java.lang.String} object - * @param spec a double - * @throws java.lang.Exception if any. - */ - public void dewPointMach(String componentName, String specification, double spec) - throws Exception { - // int componentNumber = - // system.getPhase(0).getComponent(componentName).getComponentNumber(); - - double dn = 0; - if (system.getPhase(0).hasComponent(componentName)) { - dn = system.getNumberOfMoles() / 1.0e6; - system.addComponent(componentName, dn); + dewPointTemperatureFlash(); + newTemperature = system.getTemperature(); + // logger.info("new temperature " + newTemperature); + double oldMoles = system.getPhase(0).getComponent(componentName).getNumberOfmoles(); + if (iterations > 1) { + system.addComponent(componentName, -(iterations / (30.0 + iterations)) + * (newTemperature - spec) / ((newTemperature - oldTemperature) / dn)); } else { - 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; - if (specification.equals("dewPointTemperature")) { - // logger.info("new temperature " + newTemperature); - do { - iterations++; - system.init(0); - dewPointTemperatureFlash(); - newTemperature = system.getTemperature(); - // logger.info("new temperature " + newTemperature); - double oldMoles = system.getPhase(0).getComponent(componentName).getNumberOfmoles(); - if (iterations > 1) { - system.addComponent(componentName, -(iterations / (30.0 + iterations)) - * (newTemperature - spec) / ((newTemperature - oldTemperature) / dn)); - } else { - system.addComponent(componentName, system.getNumberOfMoles() / 1.0e6); - } - dn = system.getPhase(0).getComponent(componentName).getNumberOfmoles() - oldMoles; - oldTemperature = newTemperature; - } while (Math.abs( - dn / system.getPhase(0).getComponent(componentName).getNumberOfmoles()) > 1e-9 - || iterations < 5 || iterations > 105); - - dewPointTemperatureFlash(); - } - - if (Double.isNaN(system.getPressure())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointMach", "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * dewPointTemperatureFlash. - *
- * - * @throws java.lang.Exception if any. - */ - public void dewPointTemperatureFlash() throws Exception { - constantDutyFlashInterface operation = new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash( - system); - operation.run(); - if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); - } - } - - /** - *- * dewPointTemperatureFlash. - *
- * - * @param derivatives a boolean - * @throws java.lang.Exception if any. - */ - public void dewPointTemperatureFlash(boolean derivatives) throws Exception { - constantDutyFlashInterface operation = new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash( - system); - if (derivatives) { - operation = new dewPointTemperatureFlashDer(system); - } - operation.run(); - if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); - } + system.addComponent(componentName, system.getNumberOfMoles() / 1.0e6); + } + dn = system.getPhase(0).getComponent(componentName).getNumberOfmoles() - oldMoles; + oldTemperature = newTemperature; + } while (Math + .abs(dn / system.getPhase(0).getComponent(componentName).getNumberOfmoles()) > 1e-9 + || iterations < 5 || iterations > 105); + + dewPointTemperatureFlash(); + } + + if (Double.isNaN(system.getPressure())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointMach", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * dewPointTemperatureFlash. + *
+ * + * @throws java.lang.Exception if any. + */ + public void dewPointTemperatureFlash() throws Exception { + constantDutyFlashInterface operation = + new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash(system); + operation.run(); + if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * dewPointTemperatureFlash. + *
+ * + * @param derivatives a boolean + * @throws java.lang.Exception if any. + */ + public void dewPointTemperatureFlash(boolean derivatives) throws Exception { + constantDutyFlashInterface operation = + new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash(system); + if (derivatives) { + operation = new dewPointTemperatureFlashDer(system); + } + operation.run(); + if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); + } + } + + /** + *+ * dewPointPressureFlashHC. + *
+ * + * @throws java.lang.Exception if any. + */ + public void dewPointPressureFlashHC() throws Exception { + // try{ + system.init(0); + constantDutyFlashInterface operation = new HCdewPointPressureFlash(system); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointPressureFlashHC", "Could not find solution - possible no dew point exists"); } - - /** - *- * dewPointPressureFlashHC. - *
- * - * @throws java.lang.Exception if any. - */ - public void dewPointPressureFlashHC() throws Exception { - // try{ - system.init(0); - constantDutyFlashInterface operation = new HCdewPointPressureFlash(system); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointPressureFlashHC", "Could not find solution - possible no dew point exists"); - } - // } - } - - /** - *- * dewPointPressureFlash. - *
- * - * @throws java.lang.Exception if any. - */ - public void dewPointPressureFlash() throws Exception { - // try{ - system.init(0); - constantDutyFlashInterface operation = new dewPointPressureFlash(system); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointPressureFlash", "Could not find solution - possible no dew point exists"); - } - // } - } - - // public void dewPointPressureFlash(){ - // constantDutyFlashInterface operation = new constantDutyPressureFlash(system); - // operation.setBeta((1-1e-7)); - // operation.run(); // } - /** - *- * calcPTphaseEnvelope. - *
- */ - public void calcPTphaseEnvelope() { - operation = new pTphaseEnvelope(system, fileName, (1.0 - 1e-10), 1.0, false); - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *- * calcPTphaseEnvelope. - *
- * - * @param bubfirst a boolean - * @param lowPres a double - */ - public void calcPTphaseEnvelope(boolean bubfirst, double lowPres) { - double phasefraction = 1.0 - 1e-10; - if (bubfirst) { - phasefraction = 1.0e-10; - } - operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, bubfirst); - - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *- * calcPTphaseEnvelope. - *
- * - * @param lowPres a double - */ - public void calcPTphaseEnvelope(double lowPres) { - operation = new pTphaseEnvelope(system, fileName, 1e-10, lowPres, true); - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *- * calcPTphaseEnvelope. - *
- * - * @param bubfirst a boolean - */ - public void calcPTphaseEnvelope(boolean bubfirst) { - double phasefraction = 1.0 - 1e-10; - if (bubfirst) { - phasefraction = 1.0e-10; - } - operation = new pTphaseEnvelope(system, fileName, phasefraction, 1.0, bubfirst); - - // thisThread = new Thread(operation); - // thisThread.start(); - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } + } + + /** + *+ * dewPointPressureFlash. + *
+ * + * @throws java.lang.Exception if any. + */ + public void dewPointPressureFlash() throws Exception { + // try{ + system.init(0); + constantDutyFlashInterface operation = new dewPointPressureFlash(system); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointPressureFlash", "Could not find solution - possible no dew point exists"); } - - /** - *- * getJfreeChart. - *
- * - * @return a {@link org.jfree.chart.JFreeChart} object - */ - public org.jfree.chart.JFreeChart getJfreeChart() { - return getOperation().getJFreeChart(""); - } - - /** - *- * calcPTphaseEnvelopeNew. - *
- */ - public void calcPTphaseEnvelopeNew() { - // double phasefraction = 1.0 - 1e-10; - // operation = new pTphaseEnvelope(system, fileName, phasefraction, 1.0); - getOperation().run(); - } - - /** - *- * calcPTphaseEnvelope. - *
- * - * @param lowPres a double - * @param phasefraction a double - */ - public void calcPTphaseEnvelope(double lowPres, double phasefraction) { - operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, true); - - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *- * OLGApropTable. - *
- * - * @param minTemp a double - * @param maxTemp a double - * @param temperatureSteps a int - * @param minPres a double - * @param maxPres a double - * @param pressureSteps a int - * @param filename a {@link java.lang.String} object - * @param TABtype a int - */ - public void OLGApropTable(double minTemp, double maxTemp, int temperatureSteps, double minPres, - double maxPres, int pressureSteps, String filename, int TABtype) { - operation = new OLGApropertyTableGeneratorWaterStudents(system); - ((OLGApropertyTableGeneratorWaterStudents) operation).setFileName(filename); - ((OLGApropertyTableGeneratorWaterStudents) operation).setPressureRange(minPres, maxPres, - pressureSteps); - ((OLGApropertyTableGeneratorWaterStudents) operation).setTemperatureRange(minTemp, maxTemp, - temperatureSteps); - getOperation().run(); - } - - /** - *- * OLGApropTablePH. - *
- * - * @param minEnthalpy a double - * @param maxEnthalpy a double - * @param enthalpySteps a int - * @param minPres a double - * @param maxPres a double - * @param pressureSteps a int - * @param filename a {@link java.lang.String} object - * @param TABtype a int - */ - public void OLGApropTablePH(double minEnthalpy, double maxEnthalpy, int enthalpySteps, - double minPres, double maxPres, int pressureSteps, String filename, int TABtype) { - operation = new OLGApropertyTableGeneratorWaterStudentsPH(system); - ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setFileName(filename); - ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setPressureRange(minPres, maxPres, - pressureSteps); - ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setEnthalpyRange(minEnthalpy, - maxEnthalpy, enthalpySteps); - getOperation().run(); - } - - /** - *- * calcPloadingCurve. - *
- */ - public void calcPloadingCurve() { - operation = new pLoadingCurve2(system); - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *- * calcHPTphaseEnvelope. - *
- */ - public void calcHPTphaseEnvelope() { - operation = new HPTphaseEnvelope(system); - // thisThread = new Thread(getOperation()); - // thisThread.start(); - operation.run(); - } - - /** - *- * printToFile. - *
- * - * @param name a {@link java.lang.String} object - */ - public void printToFile(String name) { - getOperation().printToFile(name); - } - - // public double[] get(String name){ - // return operation.get(name); // } - /** - *- * getData. - *
- * - * @return an array of {@link double} objects - */ - public double[][] getData() { - return getOperation().getPoints(0); - } - - /** - *- * getDataPoints. - *
- * - * @return an array of {@link java.lang.String} objects - */ - public String[][] getDataPoints() { - String[][] str = new String[getOperation() - .getPoints(0).length][getOperation().getPoints(0)[0].length]; - for (int i = 0; i < getOperation().getPoints(0).length; i++) { - for (int j = 0; j < getOperation().getPoints(0)[0].length; j++) { - str[i][j] = Double.toString(getOperation().getPoints(0)[i][j]); - } - } - return str; - } - - /** - *
- * Getter for the field resultTable
.
- *
- * dewPointTemperatureCondensationRate. - *
- * - * @return a double - */ - public double dewPointTemperatureCondensationRate() { - double dT = 1.1; - try { - dewPointTemperatureFlash(); - } catch (Exception e) { - logger.error("error", e); + } + + // public void dewPointPressureFlash(){ + // constantDutyFlashInterface operation = new constantDutyPressureFlash(system); + // operation.setBeta((1-1e-7)); + // operation.run(); + // } + /** + *+ * calcPTphaseEnvelope. + *
+ */ + public void calcPTphaseEnvelope() { + operation = new pTphaseEnvelope(system, fileName, (1.0 - 1e-10), 1.0, false); + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *+ * calcPTphaseEnvelope. + *
+ * + * @param bubfirst a boolean + * @param lowPres a double + */ + public void calcPTphaseEnvelope(boolean bubfirst, double lowPres) { + double phasefraction = 1.0 - 1e-10; + if (bubfirst) { + phasefraction = 1.0e-10; + } + operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, bubfirst); + + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *+ * calcPTphaseEnvelope. + *
+ * + * @param lowPres a double + */ + public void calcPTphaseEnvelope(double lowPres) { + operation = new pTphaseEnvelope(system, fileName, 1e-10, lowPres, true); + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *+ * calcPTphaseEnvelope. + *
+ * + * @param bubfirst a boolean + */ + public void calcPTphaseEnvelope(boolean bubfirst) { + double phasefraction = 1.0 - 1e-10; + if (bubfirst) { + phasefraction = 1.0e-10; + } + operation = new pTphaseEnvelope(system, fileName, phasefraction, 1.0, bubfirst); + + // thisThread = new Thread(operation); + // thisThread.start(); + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + } + + /** + *+ * getJfreeChart. + *
+ * + * @return a {@link org.jfree.chart.JFreeChart} object + */ + public org.jfree.chart.JFreeChart getJfreeChart() { + return getOperation().getJFreeChart(""); + } + + /** + *+ * calcPTphaseEnvelopeNew. + *
+ */ + public void calcPTphaseEnvelopeNew() { + // double phasefraction = 1.0 - 1e-10; + // operation = new pTphaseEnvelope(system, fileName, phasefraction, 1.0); + getOperation().run(); + } + + /** + *+ * calcPTphaseEnvelope. + *
+ * + * @param lowPres a double + * @param phasefraction a double + */ + public void calcPTphaseEnvelope(double lowPres, double phasefraction) { + operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, true); + + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *+ * OLGApropTable. + *
+ * + * @param minTemp a double + * @param maxTemp a double + * @param temperatureSteps a int + * @param minPres a double + * @param maxPres a double + * @param pressureSteps a int + * @param filename a {@link java.lang.String} object + * @param TABtype a int + */ + public void OLGApropTable(double minTemp, double maxTemp, int temperatureSteps, double minPres, + double maxPres, int pressureSteps, String filename, int TABtype) { + operation = new OLGApropertyTableGeneratorWaterStudents(system); + ((OLGApropertyTableGeneratorWaterStudents) operation).setFileName(filename); + ((OLGApropertyTableGeneratorWaterStudents) operation).setPressureRange(minPres, maxPres, + pressureSteps); + ((OLGApropertyTableGeneratorWaterStudents) operation).setTemperatureRange(minTemp, maxTemp, + temperatureSteps); + getOperation().run(); + } + + /** + *+ * OLGApropTablePH. + *
+ * + * @param minEnthalpy a double + * @param maxEnthalpy a double + * @param enthalpySteps a int + * @param minPres a double + * @param maxPres a double + * @param pressureSteps a int + * @param filename a {@link java.lang.String} object + * @param TABtype a int + */ + public void OLGApropTablePH(double minEnthalpy, double maxEnthalpy, int enthalpySteps, + double minPres, double maxPres, int pressureSteps, String filename, int TABtype) { + operation = new OLGApropertyTableGeneratorWaterStudentsPH(system); + ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setFileName(filename); + ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setPressureRange(minPres, maxPres, + pressureSteps); + ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setEnthalpyRange(minEnthalpy, + maxEnthalpy, enthalpySteps); + getOperation().run(); + } + + /** + *+ * calcPloadingCurve. + *
+ */ + public void calcPloadingCurve() { + operation = new pLoadingCurve2(system); + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *+ * calcHPTphaseEnvelope. + *
+ */ + public void calcHPTphaseEnvelope() { + operation = new HPTphaseEnvelope(system); + // thisThread = new Thread(getOperation()); + // thisThread.start(); + operation.run(); + } + + /** + *+ * printToFile. + *
+ * + * @param name a {@link java.lang.String} object + */ + public void printToFile(String name) { + getOperation().printToFile(name); + } + + // public double[] get(String name){ + // return operation.get(name); + // } + /** + *+ * getData. + *
+ * + * @return an array of {@link double} objects + */ + public double[][] getData() { + return getOperation().getPoints(0); + } + + /** + *+ * getDataPoints. + *
+ * + * @return an array of {@link java.lang.String} objects + */ + public String[][] getDataPoints() { + String[][] str = + new String[getOperation().getPoints(0).length][getOperation().getPoints(0)[0].length]; + for (int i = 0; i < getOperation().getPoints(0).length; i++) { + for (int j = 0; j < getOperation().getPoints(0)[0].length; j++) { + str[i][j] = Double.toString(getOperation().getPoints(0)[i][j]); + } + } + return str; + } + + /** + *
+ * Getter for the field resultTable
.
+ *
+ * dewPointTemperatureCondensationRate. + *
+ * + * @return a double + */ + public double dewPointTemperatureCondensationRate() { + double dT = 1.1; + try { + dewPointTemperatureFlash(); + } catch (Exception e) { + logger.error("error", e); + } + system.setTemperature(system.getTemperature() - dT); + TPflash(); + double condensationRate = system.getPhase(1).getMass() / (system.getVolume() * 1.0e-5); + try { + dewPointTemperatureFlash(); + } catch (Exception e) { + logger.error("error", e); + } + return condensationRate / dT; + } + + /** + *+ * displayResult. + *
+ */ + public void displayResult() { + try { + getThermoOperationThread().join(); + } catch (Exception e) { + logger.error("Thread did not finish"); + } + getOperation().displayResult(); + } + + /** + *
+ * Setter for the field resultTable
.
+ *
+ * display. + *
+ */ + public void display() { + JFrame dialog = new JFrame("System-Report"); + Container dialogContentPane = dialog.getContentPane(); + dialogContentPane.setLayout(new BorderLayout()); + + String[] names = new String[resultTable[0].length];// {"", "", ""}; + for (int i = 0; i < names.length; i++) { + names[i] = ""; + } + JTable Jtab = new JTable(resultTable, names); + JScrollPane scrollpane = new JScrollPane(Jtab); + dialogContentPane.add(scrollpane); + dialog.pack(); + dialog.setVisible(true); + } + + /** + *+ * get. + *
+ * + * @param name a {@link java.lang.String} object + * @return an array of {@link double} objects + */ + public double[] get(String name) { + return getOperation().get(name); + } + + /** + *
+ * Getter for the field operation
.
+ *
+ * isRunAsThread. + *
+ * + * @return the runAsThread + */ + public boolean isRunAsThread() { + return runAsThread; + } + + /** + *
+ * Setter for the field runAsThread
.
+ *
+ * Getter for the field thermoOperationThread
.
+ *
+ * Setter for the field thermoOperationThread
.
+ *
+ * addData. + *
+ * + * @param name a {@link java.lang.String} object + * @param data an array of {@link double} objects + */ + public void addData(String name, double[][] data) { + operation.addData(name, data); + } + + /** + *+ * calcIonComposition. + *
+ * + * @param phaseNumber a int + */ + public void calcIonComposition(int phaseNumber) { + operation = new calcIonicComposition(system, phaseNumber); + getOperation().run(); + resultTable = getOperation().getResultTable(); + } + + /** + *+ * flash. + *
+ * + * @param flashType a {@link java.lang.String} object + * @param spec1 a double + * @param spec2 a double + * @param unitSpec1 a {@link java.lang.String} object + * @param unitSpec2 a {@link java.lang.String} object + */ + public void flash(String flashType, double spec1, double spec2, String unitSpec1, + String unitSpec2) { + if (flashType.equals("TP")) { + system.setTemperature(spec1, unitSpec1); + system.setPressure(spec2, unitSpec2); + } else if (flashType.equals("TV")) { + system.setTemperature(spec1, unitSpec1); + TVflash(spec2, unitSpec2); + } else if (flashType.equals("PH")) { + system.setPressure(spec1, unitSpec1); + PHflash(spec2, unitSpec2); + } else if (flashType.equals("TS")) { + system.setTemperature(spec1, unitSpec1); + TSflash(spec2, unitSpec2); + } + } + + /** + * Perform flashes and return System properties per set of Spec1 and Spec2. + * + * Possible to specify fractions for each value of Spec1. + * + * + * @param Spec1 Flash pressure in bar absolute. + * @param Spec2 Flash specification. Depends on FlashMode. Temperature in Kelvin, entalphy in + * J/mol or entropy in J/molK. + * @param FlashMode 1 - PT 2 - PH 3 - PS + * @param components Not yet in use. + * @param onlineFractions Specify fractions per sample instance or null to use static composition + * specified in system. + * @return Object CalculationResult object + */ + public CalculationResult propertyFlash(List- * displayResult. - *
- */ - public void displayResult() { - try { - getThermoOperationThread().join(); - } catch (Exception e) { - logger.error("Thread did not finish"); - } - getOperation().displayResult(); - } - - /** - *- * writeNetCDF. - *
- * - * @param name a {@link java.lang.String} object - */ - /* - public void writeNetCDF(String name) { - fileName = name; - getOperation().createNetCdfFile(name); - } - */ - - /** - *
- * Setter for the field resultTable
.
- *
- * display. - *
- */ - public void display() { - JFrame dialog = new JFrame("System-Report"); - Container dialogContentPane = dialog.getContentPane(); - dialogContentPane.setLayout(new BorderLayout()); - - String[] names = new String[resultTable[0].length];// {"", "", ""}; - for (int i = 0; i < names.length; i++) { - names[i] = ""; - } - JTable Jtab = new JTable(resultTable, names); - JScrollPane scrollpane = new JScrollPane(Jtab); - dialogContentPane.add(scrollpane); - dialog.pack(); - dialog.setVisible(true); - } - - /** - *- * get. - *
- * - * @param name a {@link java.lang.String} object - * @return an array of {@link double} objects - */ - public double[] get(String name) { - return getOperation().get(name); - } - - /** - *
- * Getter for the field operation
.
- *
- * isRunAsThread. - *
- * - * @return the runAsThread - */ - public boolean isRunAsThread() { - return runAsThread; - } - - /** - *
- * Setter for the field runAsThread
.
- *
- * Getter for the field thermoOperationThread
.
- *
- * Setter for the field thermoOperationThread
.
- *
- * addData. - *
- * - * @param name a {@link java.lang.String} object - * @param data an array of {@link double} objects - */ - public void addData(String name, double[][] data) { - operation.addData(name, data); - } - - /** - *- * calcIonComposition. - *
- * - * @param phaseNumber a int - */ - public void calcIonComposition(int phaseNumber) { - operation = new calcIonicComposition(system, phaseNumber); - getOperation().run(); - resultTable = getOperation().getResultTable(); - } - - /** - *- * flash. - *
- * - * @param flashType a {@link java.lang.String} object - * @param spec1 a double - * @param spec2 a double - * @param unitSpec1 a {@link java.lang.String} object - * @param unitSpec2 a {@link java.lang.String} object - */ - public void flash(String flashType, double spec1, double spec2, String unitSpec1, - String unitSpec2) { - if (flashType.equals("TP")) { - system.setTemperature(spec1, unitSpec1); - system.setPressure(spec2, unitSpec2); - } else if (flashType.equals("TV")) { - system.setTemperature(spec1, unitSpec1); - TVflash(spec2, unitSpec2); - } else if (flashType.equals("PH")) { - system.setPressure(spec1, unitSpec1); - PHflash(spec2, unitSpec2); - } else if (flashType.equals("TS")) { - system.setTemperature(spec1, unitSpec1); - TSflash(spec2, unitSpec2); - } - } - - /** - * Perform flashes and return System properties per set of Spec1 and Spec2. - * - * Possible to specify fractions for each value of Spec1. - * - * - * @param Spec1 Flash pressure in bar absolute. - * @param Spec2 Flash specification. Depends on FlashMode. Temperature in Kelvin, entalphy in - * J/mol or entropy in J/molK. - * @param FlashMode 1 - PT 2 - PH 3 - PS - * @param components Not yet in use. - * @param onlineFractions Specify fractions per sample instance or null to use static - * composition specified in system. - * @return Object CalculationResult object - */ - public CalculationResult propertyFlash(List- * Constructor for ChemicalEquilibrium. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public ChemicalEquilibrium(SystemInterface system) { - this.system = system; - } + /** + *+ * Constructor for ChemicalEquilibrium. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public ChemicalEquilibrium(SystemInterface system) { + this.system = system; + } - /** {@inheritDoc} */ - @Override - public void run() { - double chemdev = 0; - int iter = 1; - if (system.isChemicalSystem()) { - double oldHeat = system.getChemicalReactionOperations().getReactionList() - .reacHeat(system.getPhase(1), "HCO3-"); - do { - iter++; - for (int phase = 1; phase < system.getNumberOfPhases(); phase++) { - chemdev = 0.0; - double xchem[] = new double[system.getPhases()[phase].getNumberOfComponents()]; + /** {@inheritDoc} */ + @Override + public void run() { + double chemdev = 0; + int iter = 1; + if (system.isChemicalSystem()) { + double oldHeat = system.getChemicalReactionOperations().getReactionList() + .reacHeat(system.getPhase(1), "HCO3-"); + do { + iter++; + for (int phase = 1; phase < system.getNumberOfPhases(); phase++) { + chemdev = 0.0; + double xchem[] = new double[system.getPhases()[phase].getNumberOfComponents()]; - for (int i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { - xchem[i] = system.getPhases()[phase].getComponents()[i].getx(); - } + for (int i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { + xchem[i] = system.getPhases()[phase].getComponents()[i].getx(); + } - system.init(1); - system.getChemicalReactionOperations().solveChemEq(phase); + system.init(1); + system.getChemicalReactionOperations().solveChemEq(phase); - for (int i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { - chemdev += Math.abs( - xchem[i] - system.getPhases()[phase].getComponents()[i].getx()); - } - } - } while (Math.abs(chemdev) > 1e-4 && iter < 100); - double newHeat = system.getChemicalReactionOperations().getReactionList() - .reacHeat(system.getPhase(1), "HCO3-"); - system.getChemicalReactionOperations().setDeltaReactionHeat(newHeat - oldHeat); - } - if (iter > 50) { - logger.info("iter : " + iter + " in chemicalequilibrium"); + for (int i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { + chemdev += Math.abs(xchem[i] - system.getPhases()[phase].getComponents()[i].getx()); + } } + } while (Math.abs(chemdev) > 1e-4 && iter < 100); + double newHeat = system.getChemicalReactionOperations().getReactionList() + .reacHeat(system.getPhase(1), "HCO3-"); + system.getChemicalReactionOperations().setDeltaReactionHeat(newHeat - oldHeat); } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - system.display(); + if (iter > 50) { + logger.info("iter : " + iter + " in chemicalequilibrium"); } + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} + /** {@inheritDoc} */ + @Override + public void displayResult() { + system.display(); + } - /** {@inheritDoc} */ - /* - @Override - public void createNetCdfFile(String name) {} -*/ - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return null; - } + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return null; + } - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; - } + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/Flash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/Flash.java index 9c035f516e..ec5b05aad1 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/Flash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/Flash.java @@ -15,464 +15,453 @@ * @author Even Solbraa */ abstract class Flash extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(Flash.class); - - SystemInterface system; - SystemInterface minimumGibbsEnergySystem; - - public double[] minGibsPhaseLogZ; - public double[] minGibsLogFugCoef; - int i = 0, j = 0, iterations = 0, maxNumberOfIterations = 100; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold = 0, deviation = 0, g0 = 0, g1 = 0; - double lnOldOldOldK[], lnOldOldK[], lnK[], lnOldK[]; - double oldoldDeltalnK[], oldDeltalnK[], deltalnK[]; - double tm[]; - int lowestGibbsEnergyPhase = 0; - sysNewtonRhapsonTPflash secondOrderSolver; - protected boolean solidCheck = false, stabilityCheck = false; - boolean findLowesGibsPhaseIsChecked = false; - - /** - *- * Constructor for Flash. - *
- */ - public Flash() {} - - /** - *- * findLowestGibbsEnergyPhase. - *
- * - * @return a int - */ - public int findLowestGibbsEnergyPhase() { - if (!findLowesGibsPhaseIsChecked) { - minimumGibbsEnergySystem = system.clone(); - minimumGibbsEnergySystem.init(0); - minimumGibbsEnergySystem.init(1); - if ((minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy() - * (1.0 - Math.signum(minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy()) - * 1e-8)) < minimumGibbsEnergySystem.getPhase(1).getGibbsEnergy()) { - lowestGibbsEnergyPhase = 0; - } else { - lowestGibbsEnergyPhase = 1; - } - findLowesGibsPhaseIsChecked = true; - } - return lowestGibbsEnergyPhase; + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(Flash.class); + + SystemInterface system; + SystemInterface minimumGibbsEnergySystem; + + public double[] minGibsPhaseLogZ; + public double[] minGibsLogFugCoef; + int i = 0, j = 0, iterations = 0, maxNumberOfIterations = 100; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold = 0, deviation = 0, g0 = 0, g1 = 0; + double lnOldOldOldK[], lnOldOldK[], lnK[], lnOldK[]; + double oldoldDeltalnK[], oldDeltalnK[], deltalnK[]; + double tm[]; + int lowestGibbsEnergyPhase = 0; + sysNewtonRhapsonTPflash secondOrderSolver; + protected boolean solidCheck = false, stabilityCheck = false; + boolean findLowesGibsPhaseIsChecked = false; + + /** + *+ * Constructor for Flash. + *
+ */ + public Flash() {} + + /** + *+ * findLowestGibbsEnergyPhase. + *
+ * + * @return a int + */ + public int findLowestGibbsEnergyPhase() { + if (!findLowesGibsPhaseIsChecked) { + minimumGibbsEnergySystem = system.clone(); + minimumGibbsEnergySystem.init(0); + minimumGibbsEnergySystem.init(1); + if ((minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy() + * (1.0 - Math.signum(minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy()) + * 1e-8)) < minimumGibbsEnergySystem.getPhase(1).getGibbsEnergy()) { + lowestGibbsEnergyPhase = 0; + } else { + lowestGibbsEnergyPhase = 1; + } + findLowesGibsPhaseIsChecked = true; + } + return lowestGibbsEnergyPhase; + } + + /** + *+ * stabilityAnalysis. + *
+ * + * @throws neqsim.util.exception.IsNaNException if any. + * @throws neqsim.util.exception.TooManyIterationsException if any. + */ + public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, + neqsim.util.exception.TooManyIterationsException { + double[] logWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] deltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[][] Wi = new double[2][system.getPhases()[0].getNumberOfComponents()]; + double[] sumw = new double[2]; + boolean secondOrderStabilityAnalysis = false; + double[] oldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] d = new double[system.getPhases()[0].getNumberOfComponents()]; + double[][] x = new double[2][system.getPhases()[0].getNumberOfComponents()]; + double[] error = new double[2]; + tm = new double[system.getPhase(0).getNumberOfComponents()]; + double[] alpha = null; + Matrix f = new Matrix(system.getPhases()[0].getNumberOfComponents(), 1); + Matrix df = null; + int maxiterations = 50; + double fNorm = 1.0e10, fNormOld = 0.0; + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + d[i] = minGibsPhaseLogZ[i] + minGibsLogFugCoef[i]; } - /** - *- * stabilityAnalysis. - *
- * - * @throws neqsim.util.exception.IsNaNException if any. - * @throws neqsim.util.exception.TooManyIterationsException if any. - */ - public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, - neqsim.util.exception.TooManyIterationsException { - double[] logWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] deltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[][] Wi = new double[2][system.getPhases()[0].getNumberOfComponents()]; - double[] sumw = new double[2]; - boolean secondOrderStabilityAnalysis = false; - double[] oldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] d = new double[system.getPhases()[0].getNumberOfComponents()]; - double[][] x = new double[2][system.getPhases()[0].getNumberOfComponents()]; - double[] error = new double[2]; - tm = new double[system.getPhase(0).getNumberOfComponents()]; - double[] alpha = null; - Matrix f = new Matrix(system.getPhases()[0].getNumberOfComponents(), 1); - Matrix df = null; - int maxiterations = 50; - double fNorm = 1.0e10, fNormOld = 0.0; - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - d[i] = minGibsPhaseLogZ[i] + minGibsLogFugCoef[i]; - } + SystemInterface clonedSystem = minimumGibbsEnergySystem; + clonedSystem.setTotalNumberOfMoles(1.0); + sumw[1] = 0.0; + sumw[0] = 0.0; - SystemInterface clonedSystem = minimumGibbsEnergySystem; - clonedSystem.setTotalNumberOfMoles(1.0); - sumw[1] = 0.0; - sumw[0] = 0.0; + for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { + sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() + / clonedSystem.getPhase(0).getComponent(i).getK(); + sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK() + * clonedSystem.getPhase(0).getComponent(i).getz(); + } - for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { - sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() - / clonedSystem.getPhase(0).getComponent(i).getK(); - sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK() - * clonedSystem.getPhase(0).getComponent(i).getz(); - } + // System.out.println("sumw0 " + sumw[0]); + // System.out.println("sumw1 " + sumw[1]); + + int start = 0; + int end = 1;// clonedSystem.getNumberOfPhases()-1; + int mult = 1; + // if (sumw[1] > sumw[0]) { + if (lowestGibbsEnergyPhase == 0) { + start = end; + end = 0; + mult = -1; + } - // System.out.println("sumw0 " + sumw[0]); - // System.out.println("sumw1 " + sumw[1]); - - int start = 0; - int end = 1;// clonedSystem.getNumberOfPhases()-1; - int mult = 1; - // if (sumw[1] > sumw[0]) { - if (lowestGibbsEnergyPhase == 0) { - start = end; - end = 0; - mult = -1; - } + for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { + clonedSystem.getPhase(1).getComponent(i).setx(clonedSystem.getPhase(0).getComponent(i).getz() + / clonedSystem.getPhase(0).getComponent(i).getK() / sumw[1]); + clonedSystem.getPhase(0).getComponent(i).setx(clonedSystem.getPhase(0).getComponent(i).getK() + * clonedSystem.getPhase(0).getComponent(i).getz() / sumw[0]); + } - for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { - clonedSystem.getPhase(1).getComponent(i) - .setx(clonedSystem.getPhase(0).getComponent(i).getz() - / clonedSystem.getPhase(0).getComponent(i).getK() / sumw[1]); - clonedSystem.getPhase(0).getComponent(i) - .setx(clonedSystem.getPhase(0).getComponent(i).getK() - * clonedSystem.getPhase(0).getComponent(i).getz() / sumw[0]); + // for (int j = 0; j < clonedSystem.getNumberOfPhases(); j++) { + for (int j = start; j >= end; j = j + mult) { + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + Wi[j][i] = clonedSystem.getPhase(j).getComponent(i).getx(); + logWi[i] = Math.log(Wi[j][i]); + } + iterations = 0; + fNorm = 1.0e10; + + do { + iterations++; + error[j] = 0.0; + + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + oldoldoldlogw[i] = oldoldlogw[i]; + oldoldlogw[i] = oldlogw[i]; + oldlogw[i] = logWi[i]; + + oldoldDeltalogWi[i] = oldoldlogw[i] - oldoldoldlogw[i]; + oldDeltalogWi[i] = oldlogw[i] - oldoldlogw[i]; } - // for (int j = 0; j < clonedSystem.getNumberOfPhases(); j++) { - for (int j = start; j >= end; j = j + mult) { - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - Wi[j][i] = clonedSystem.getPhase(j).getComponent(i).getx(); - logWi[i] = Math.log(Wi[j][i]); - } - iterations = 0; - fNorm = 1.0e10; - - do { - iterations++; - error[j] = 0.0; - - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - oldoldoldlogw[i] = oldoldlogw[i]; - oldoldlogw[i] = oldlogw[i]; - oldlogw[i] = logWi[i]; - - oldoldDeltalogWi[i] = oldoldlogw[i] - oldoldoldlogw[i]; - oldDeltalogWi[i] = oldlogw[i] - oldoldlogw[i]; - } - - if ((iterations <= maxiterations - 10) - || !system.isImplementedCompositionDeriativesofFugacity()) { - clonedSystem.init(1, j); - fNormOld = fNorm; - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - f.set(i, 0, Math.sqrt(Wi[j][i]) * (Math.log(Wi[j][i]) + clonedSystem - .getPhase(j).getComponent(i).getLogFugacityCoefficient() - d[i])); - } - fNorm = f.norm2(); - if (fNorm > fNormOld && iterations > 3 || (iterations + 1) % 7 != 0) { - break; - } - if (iterations % 7 == 0 && fNorm < fNormOld && !secondOrderStabilityAnalysis) { - double vec1 = 0.0, vec2 = 0.0, prod1 = 0.0, prod2 = 0.0; - - for (i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - vec1 = oldDeltalogWi[i] * oldoldDeltalogWi[i]; - vec2 = Math.pow(oldoldDeltalogWi[i], 2.0); - prod1 += vec1 * vec2; - prod2 += vec2 * vec2; - } - - double lambda = prod1 / prod2; - // logger.info("lambda " + lambda); - for (i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - logWi[i] += lambda / (1.0 - lambda) * deltalogWi[i]; - error[j] += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); - Wi[j][i] = Math.exp(logWi[i]); - } - } else { - // succsessive substitution - for (int i = 0; i < clonedSystem.getPhases()[0] - .getNumberOfComponents(); i++) { - logWi[i] = d[i] - clonedSystem.getPhase(j).getComponent(i) - .getLogFugacityCoefficient(); - error[j] += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); - Wi[j][i] = Math.exp(logWi[i]); - } - } - } else { - if (!secondOrderStabilityAnalysis) { - alpha = new double[system.getPhases()[0].getNumberOfComponents()]; - df = new Matrix(system.getPhases()[0].getNumberOfComponents(), - system.getPhases()[0].getNumberOfComponents()); - secondOrderStabilityAnalysis = true; - } - - clonedSystem.init(3, j); - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - alpha[i] = 2.0 * Math.sqrt(Wi[j][i]); - } - - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - f.set(i, 0, Math.sqrt(Wi[j][i]) * (Math.log(Wi[j][i]) + clonedSystem - .getPhase(j).getComponent(i).getLogFugacityCoefficient() - d[i])); - for (int k = 0; k < clonedSystem.getPhases()[0] - .getNumberOfComponents(); k++) { - double kronDelt = (i == k) ? 1.5 : 0.0; // adding 0.5 to diagonal - df.set(i, k, kronDelt + Math.sqrt(Wi[j][k] * Wi[j][i]) - * clonedSystem.getPhase(j).getComponent(i).getdfugdn(k));// * - // clonedSystem.getPhases()[j].getNumberOfMolesInPhase()); - } - } - - Matrix dx = df.solve(f).times(-1.0); - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - Wi[j][i] = Math.pow((alpha[i] + dx.get(i, 0)) / 2.0, 2.0); - logWi[i] = Math.log(Wi[j][i]); - error[j] += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); - } - - // logger.info("err newton " + error[j]); - } - - // logger.info("norm f " + f.norm1()); - // clonedSystem.display(); - sumw[j] = 0.0; - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - sumw[j] += Wi[j][i]; - } - - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - deltalogWi[i] = logWi[i] - oldlogw[i]; - clonedSystem.getPhase(j).getComponent(i).setx(Wi[j][i] / sumw[j]); - } - // logger.info("fnorm " + f.norm1() + " err " + error[j] + " iterations " + - // iterations + " phase " + j); - } while ((f.norm1() > 1e-6 && iterations < maxiterations) || (iterations % 7) == 0 - || iterations < 3); - // (error[j]- * stabilityCheck. - *
- * - * @return a boolean - */ - public boolean stabilityCheck() { - boolean stable = false; - // logger.info("starting stability analysis...."); - lowestGibbsEnergyPhase = findLowestGibbsEnergyPhase(); - if (system.getPhase(lowestGibbsEnergyPhase).getNumberOfComponents() > 1) { - try { - stabilityAnalysis(); - } catch (Exception e) { - logger.error("error ", e); - } + if (((tm[0] < -1e-4) || (tm[1] < -1e-4)) && !(Double.isNaN(tm[0]) || (Double.isNaN(tm[1])))) { + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + if (system.getPhases()[1].getComponents()[i].getx() < 1e-100) { + continue; } - if (!(tm[0] < -1e-4) && !(tm[1] < -1e-4) - || system.getPhase(0).getNumberOfComponents() == 1) { - stable = true; - system.init(0); - // logger.info("system is stable"); - // logger.info("Stable phase is : " + lowestGibbsEnergyPhase); - system.setNumberOfPhases(1); - - if (lowestGibbsEnergyPhase == 0) { - system.setPhaseType(0, 1); - } else { - system.setPhaseType(0, 0); - } - system.init(1); - if (solidCheck && !system.doMultiPhaseCheck()) { - this.solidPhaseFlash(); - } + if (tm[0] < -1e-4) { + system.getPhases()[1].getComponents()[i] + .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); + system.getPhases()[0].getComponents()[i] + .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); + } else if (tm[1] < -1e-4) { + system.getPhases()[1].getComponents()[i] + .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); + system.getPhases()[0].getComponents()[i] + .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); } else { - try { - system.calcBeta(); - } catch (Exception e) { - logger.error("error", e); - } - system.calc_x_y(); - system.init(1); + logger.info("error in stability anlysis"); + system.init(0); } - return stable; + if (Double.isNaN(tm[j])) { + tm[j] = 0; + } + } } - /** {@inheritDoc} */ - @Override - public void displayResult() { - system.display(); + // logger.info("STABILITY ANALYSIS: "); + // logger.info("tm1: " + tm[0] + " tm2: " + tm[1]); + } + + /** + *+ * stabilityCheck. + *
+ * + * @return a boolean + */ + public boolean stabilityCheck() { + boolean stable = false; + // logger.info("starting stability analysis...."); + lowestGibbsEnergyPhase = findLowestGibbsEnergyPhase(); + if (system.getPhase(lowestGibbsEnergyPhase).getNumberOfComponents() > 1) { + try { + stabilityAnalysis(); + } catch (Exception e) { + logger.error("error ", e); + } + } + if (!(tm[0] < -1e-4) && !(tm[1] < -1e-4) || system.getPhase(0).getNumberOfComponents() == 1) { + stable = true; + system.init(0); + // logger.info("system is stable"); + // logger.info("Stable phase is : " + lowestGibbsEnergyPhase); + system.setNumberOfPhases(1); + + if (lowestGibbsEnergyPhase == 0) { + system.setPhaseType(0, 1); + } else { + system.setPhaseType(0, 0); + } + system.init(1); + if (solidCheck && !system.doMultiPhaseCheck()) { + this.solidPhaseFlash(); + } + } else { + try { + system.calcBeta(); + } catch (Exception e) { + logger.error("error", e); + } + system.calc_x_y(); + system.init(1); } - /** - *- * solidPhaseFlash. - *
- */ - public void solidPhaseFlash() { - boolean solidPhase = false; - double frac = 0; - int solid = 0; - double[] tempVar = new double[system.getPhases()[0].getNumberOfComponents()]; - - if (!system.hasSolidPhase()) { - system.setNumberOfPhases(system.getNumberOfPhases() + 1); - system.setPhaseIndex(system.getNumberOfPhases() - 1, 3); - } - // logger.info("numb " + system.getNumberOfPhases()); - system.init(1); - - for (int k = 0; k < system.getPhase(0).getNumberOfComponents(); k++) { - if (system.getPhase(0).getComponent(k).doSolidCheck()) { - tempVar[k] = system.getPhase(0).getComponents()[k].getz(); - for (int i = 0; i < system.getNumberOfPhases() - 1; i++) { - tempVar[k] -= system.getBeta(i) - * system.getPhases()[3].getComponent(k).getFugacityCoefficient() - / system.getPhase(i).getComponent(k).getFugacityCoefficient(); - } - - if (tempVar[k] > 0.0 && tempVar[k] > frac) { - solidPhase = true; - solid = k; - frac = tempVar[k]; - for (int p = 0; p < system.getPhases()[0].getNumberOfComponents(); p++) { - system.getPhases()[3].getComponents()[p].setx(1.0e-20); - } - system.getPhases()[3].getComponents()[solid].setx(1.0); - } - // logger.info("tempVar: " + tempVar[k]); - } + return stable; + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + system.display(); + } + + /** + *+ * solidPhaseFlash. + *
+ */ + public void solidPhaseFlash() { + boolean solidPhase = false; + double frac = 0; + int solid = 0; + double[] tempVar = new double[system.getPhases()[0].getNumberOfComponents()]; + + if (!system.hasSolidPhase()) { + system.setNumberOfPhases(system.getNumberOfPhases() + 1); + system.setPhaseIndex(system.getNumberOfPhases() - 1, 3); + } + // logger.info("numb " + system.getNumberOfPhases()); + system.init(1); + + for (int k = 0; k < system.getPhase(0).getNumberOfComponents(); k++) { + if (system.getPhase(0).getComponent(k).doSolidCheck()) { + tempVar[k] = system.getPhase(0).getComponents()[k].getz(); + for (int i = 0; i < system.getNumberOfPhases() - 1; i++) { + tempVar[k] -= + system.getBeta(i) * system.getPhases()[3].getComponent(k).getFugacityCoefficient() + / system.getPhase(i).getComponent(k).getFugacityCoefficient(); } - if (solidPhase) { - if (frac < system.getPhases()[0].getComponents()[solid].getz() + 1e10) { - for (int i = 0; i < system.getNumberOfPhases() - 1; i++) { - // system.getPhases()[i].getComponents()[solid].setx(1.0e-10); - } - system.init(1); - // logger.info("solid phase will form..." + system.getNumberOfPhases()); - // logger.info("freezing component " + solid); - system.setBeta(system.getNumberOfPhases() - 1, frac); - system.initBeta(); - system.setBeta(system.getNumberOfPhases() - 1, - system.getPhases()[3].getComponent(solid).getNumberOfmoles() - / system.getNumberOfMoles()); - // double phasetot=0.0; - // for(int ph=0;ph- * Constructor for constantDutyFlash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public constantDutyFlash(SystemInterface system) { - this.system = system; - lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnK = new double[system.getPhases()[0].getNumberOfComponents()]; - oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - } - - /** {@inheritDoc} */ - @Override - public void setBeta(double beta) { - this.beta = beta; - } - - /** {@inheritDoc} */ - @Override - public void run() { - system.init(0); - system.init(2); - - // int iterations = 0, maxNumberOfIterations = 10000; - // double yold = 0, ytotal = 1; - double deriv = 0, funk = 0, dkidt = 0, dyidt = 0, dxidt = 0, Told = 0; - - do { - // system.setBeta(beta+0.65); - system.init(2); - - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - system.getPhases()[0].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() - / system.getPhases()[1].getComponents()[i] - .getFugacityCoefficient()); - system.getPhases()[1].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() - / system.getPhases()[1].getComponents()[i] - .getFugacityCoefficient()); - } - - system.calc_x_y(); - - funk = 0e0; - deriv = 0e0; - - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - dkidt = (system.getPhases()[0].getComponents()[i].getdfugdt() - - system.getPhases()[1].getComponents()[i].getdfugdt()) - * system.getPhases()[0].getComponents()[i].getK(); - dxidt = -system.getPhases()[0].getComponents()[i].getx() - * system.getPhases()[0].getComponents()[i].getx() * 1.0 - / system.getPhases()[0].getComponents()[i].getz() * system.getBeta() - * dkidt; - dyidt = dkidt * system.getPhases()[0].getComponents()[i].getx() - + system.getPhases()[0].getComponents()[i].getK() * dxidt; - funk = funk + system.getPhases()[1].getComponents()[i].getx() - - system.getPhases()[0].getComponents()[i].getx(); - deriv = deriv + dyidt - dxidt; - } - - Told = system.getTemperature(); - system.setTemperature((Told - funk / deriv * 0.9)); - logger.info("Temp: " + system.getTemperature()); - } while (Math.abs((system.getTemperature() - Told) / system.getTemperature()) > 1e-7); - } - - /** {@inheritDoc} */ - /* - @Override - public void createNetCdfFile(String name) {} -*/ - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return null; - } - - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - return null; - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - system.display(); - } - - /** {@inheritDoc} */ - @Override - public boolean isSuperCritical() { - return superCritical; - } - - /** - * Setter for property superCritical. - * - * @param superCritical New value of property superCritical. - */ - public void setSuperCritical(boolean superCritical) { - this.superCritical = superCritical; - } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; - } - - /** {@inheritDoc} */ - @Override - public void addData(String name, double[][] data) {} + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(constantDutyFlash.class); + + SystemInterface system; + protected boolean superCritical = false; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold, deviation = 0, g0 = 0, g1 = 0; + double lnOldOldK[], lnK[]; + double lnOldK[]; + double oldDeltalnK[], deltalnK[]; + double tm[] = {1, 1}; + double beta = 1e-5; + int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase + + /** + *+ * Constructor for constantDutyFlash. + *
+ */ + public constantDutyFlash() {} + + /** + *+ * Constructor for constantDutyFlash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public constantDutyFlash(SystemInterface system) { + this.system = system; + lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnK = new double[system.getPhases()[0].getNumberOfComponents()]; + oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + } + + /** {@inheritDoc} */ + @Override + public void setBeta(double beta) { + this.beta = beta; + } + + /** {@inheritDoc} */ + @Override + public void run() { + system.init(0); + system.init(2); + + // int iterations = 0, maxNumberOfIterations = 10000; + // double yold = 0, ytotal = 1; + double deriv = 0, funk = 0, dkidt = 0, dyidt = 0, dxidt = 0, Told = 0; + + do { + // system.setBeta(beta+0.65); + system.init(2); + + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + system.getPhases()[0].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() + / system.getPhases()[1].getComponents()[i].getFugacityCoefficient()); + system.getPhases()[1].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() + / system.getPhases()[1].getComponents()[i].getFugacityCoefficient()); + } + + system.calc_x_y(); + + funk = 0e0; + deriv = 0e0; + + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + dkidt = (system.getPhases()[0].getComponents()[i].getdfugdt() + - system.getPhases()[1].getComponents()[i].getdfugdt()) + * system.getPhases()[0].getComponents()[i].getK(); + dxidt = -system.getPhases()[0].getComponents()[i].getx() + * system.getPhases()[0].getComponents()[i].getx() * 1.0 + / system.getPhases()[0].getComponents()[i].getz() * system.getBeta() * dkidt; + dyidt = dkidt * system.getPhases()[0].getComponents()[i].getx() + + system.getPhases()[0].getComponents()[i].getK() * dxidt; + funk = funk + system.getPhases()[1].getComponents()[i].getx() + - system.getPhases()[0].getComponents()[i].getx(); + deriv = deriv + dyidt - dxidt; + } + + Told = system.getTemperature(); + system.setTemperature((Told - funk / deriv * 0.9)); + logger.info("Temp: " + system.getTemperature()); + } while (Math.abs((system.getTemperature() - Told) / system.getTemperature()) > 1e-7); + } + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return null; + } + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + return null; + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + system.display(); + } + + /** {@inheritDoc} */ + @Override + public boolean isSuperCritical() { + return superCritical; + } + + /** + * Setter for property superCritical. + * + * @param superCritical New value of property superCritical. + */ + public void setSuperCritical(boolean superCritical) { + this.superCritical = superCritical; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } + + /** {@inheritDoc} */ + @Override + public void addData(String name, double[][] data) {} } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp1.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp1.java index da1d4a17e1..8569a03781 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp1.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp1.java @@ -236,15 +236,6 @@ public String[][] getResultTable() { return null; } - /** - *- * createNetCdfFile. - *
- * - * @param name a {@link java.lang.String} object - */ - public void createNetCdfFile(String name) {} - /** ** getThermoSystem. diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/HPTphaseEnvelope.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/HPTphaseEnvelope.java index 9cccf27d17..bc8cf04432 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/HPTphaseEnvelope.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/HPTphaseEnvelope.java @@ -24,111 +24,100 @@ * @version $Id: $Id */ public class HPTphaseEnvelope extends BaseOperation { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - double[][] points = new double[10][10]; - SystemInterface system; - ThermodynamicOperations testOps; - JProgressBar monitor; - JFrame mainFrame; - JPanel mainPanel; - double startPressure = 1, endPressure = 0, startTemperature = 160, endTemperature = 0; - static Logger logger = LogManager.getLogger(HPTphaseEnvelope.class); + double[][] points = new double[10][10]; + SystemInterface system; + ThermodynamicOperations testOps; + JProgressBar monitor; + JFrame mainFrame; + JPanel mainPanel; + double startPressure = 1, endPressure = 0, startTemperature = 160, endTemperature = 0; + static Logger logger = LogManager.getLogger(HPTphaseEnvelope.class); - /** - *
- * Constructor for HPTphaseEnvelope. - *
- */ - public HPTphaseEnvelope() {} - - /** - *- * Constructor for HPTphaseEnvelope. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public HPTphaseEnvelope(SystemInterface system) { - testOps = new ThermodynamicOperations(system); - this.system = system; - mainFrame = new JFrame("Progress Bar"); - mainPanel = new JPanel(); - mainPanel.setSize(200, 100); - mainFrame.getContentPane().setLayout(new FlowLayout()); - mainPanel.setLayout(new FlowLayout()); - mainFrame.setSize(200, 100); - monitor = new JProgressBar(0, 1000); - monitor.setSize(200, 100); - monitor.setStringPainted(true); - mainPanel.add(monitor); - mainFrame.getContentPane().add(mainPanel); - mainFrame.setVisible(true); - } + /** + *+ * Constructor for HPTphaseEnvelope. + *
+ */ + public HPTphaseEnvelope() {} - /** {@inheritDoc} */ - @Override - public void run() { - int np = 0; + /** + *+ * Constructor for HPTphaseEnvelope. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public HPTphaseEnvelope(SystemInterface system) { + testOps = new ThermodynamicOperations(system); + this.system = system; + mainFrame = new JFrame("Progress Bar"); + mainPanel = new JPanel(); + mainPanel.setSize(200, 100); + mainFrame.getContentPane().setLayout(new FlowLayout()); + mainPanel.setLayout(new FlowLayout()); + mainFrame.setSize(200, 100); + monitor = new JProgressBar(0, 1000); + monitor.setSize(200, 100); + monitor.setStringPainted(true); + mainPanel.add(monitor); + mainFrame.getContentPane().add(mainPanel); + mainFrame.setVisible(true); + } - for (int i = 0; i < 10; i++) { - system.setPressure(i * 0.5 + startPressure); - for (int j = 0; j < 10; j++) { - np++; - if (np % 2 == 0) { - monitor.setValue(np); - monitor.setString("Calculated points: " + np); - } + /** {@inheritDoc} */ + @Override + public void run() { + int np = 0; - system.setTemperature(startTemperature + j); - testOps.TPflash(); - system.init(3); - points[i][j] = system.getEnthalpy(); - } + for (int i = 0; i < 10; i++) { + system.setPressure(i * 0.5 + startPressure); + for (int j = 0; j < 10; j++) { + np++; + if (np % 2 == 0) { + monitor.setValue(np); + monitor.setString("Calculated points: " + np); } - } - /** {@inheritDoc} */ - @Override - public void displayResult() { - /* - try { - mainFrame.setVisible(false); - visAd3DPlot plot = - new visAd3DPlot("pressure[bar]", "temperature[K]", "enthalpy[J/mol]"); - plot.setXYvals(150, 160, 10, 10, 20, 10); - plot.setZvals(points); - plot.init(); - } catch (Exception e) { - logger.error("plotting failed"); - } - */ + system.setTemperature(startTemperature + j); + testOps.TPflash(); + system.init(3); + points[i][j] = system.getEnthalpy(); + } } + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} + /** {@inheritDoc} */ + @Override + public void displayResult() { + /* + * try { mainFrame.setVisible(false); visAd3DPlot plot = new visAd3DPlot("pressure[bar]", + * "temperature[K]", "enthalpy[J/mol]"); plot.setXYvals(150, 160, 10, 10, 20, 10); + * plot.setZvals(points); plot.init(); } catch (Exception e) { logger.error("plotting failed"); + * } + */ + } - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points; - } + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} - /** {@inheritDoc} */ - /* - @Override - public void createNetCdfFile(String name) {} -*/ - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points; + } - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; - } + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java index 3d7e7a63ed..d6a116ea16 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java @@ -722,14 +722,6 @@ public double[] get(String name) { } } - /** {@inheritDoc} */ - /* - @Override - public void createNetCdfFile(String name) { - fileName = name; - } - */ - /** * Getter for property bubblePointFirst. * diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope1.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope1.java index fc49ed29aa..ce360ac5d3 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope1.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope1.java @@ -21,461 +21,442 @@ * @version $Id: $Id */ public class pTphaseEnvelope1 extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(pTphaseEnvelope1.class); - - graph2b graph2 = null; - SystemInterface system; - boolean bubblePointFirst = true; - double[] cricondenTherm = new double[3]; - double[] cricondenBar = new double[3]; - double phaseFraction = 1e-10; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; - double lnOldOldK[], lnK[]; - boolean outputToFile = false; - double lnOldK[]; - double oldDeltalnK[], deltalnK[]; - double tm[] = {1, 1}; - double beta = 1e-5; - int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase - JProgressBar monitor; - JFrame mainFrame; - String fileName = "c:/file"; - JPanel mainPanel; - double temp = 0, pres = 0, startPres = 0; - double[][] points = new double[2][]; - double[] pointsH; - double[][] pointsH2 = new double[4][]; - double[] pointsV; - double[][] pointsV2 = new double[4][]; - double[] pointsS; - double[][] pointsS2 = new double[4][]; - public double[][] points2 = new double[4][]; - double[][] points3 = new double[8][]; - boolean moreLines = false; - int np = 0; - // points[2] = new double[1000]; - int speceq = 0; - - /** - *- * Constructor for pTphaseEnvelope1. - *
- */ - public pTphaseEnvelope1() {} - - /** - *- * Constructor for pTphaseEnvelope1. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param name a {@link java.lang.String} object - * @param phaseFraction a double - * @param lowPres a double - * @param bubfirst a boolean - */ - public pTphaseEnvelope1(SystemInterface system, String name, double phaseFraction, - double lowPres, boolean bubfirst) { - this.bubblePointFirst = bubfirst; - if (name != null) { - outputToFile = true; - fileName = name; - } - this.system = system; - this.phaseFraction = phaseFraction; - lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnK = new double[system.getPhase(0).getNumberOfComponents()]; - this.lowPres = lowPres; - oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; - deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; - mainFrame = new JFrame("Progress Bar"); - mainPanel = new JPanel(); - mainPanel.setSize(200, 100); - mainFrame.getContentPane().setLayout(new FlowLayout()); - mainPanel.setLayout(new FlowLayout()); - mainFrame.setSize(200, 100); - monitor = new JProgressBar(0, 00); - monitor.setSize(200, 100); - monitor.setStringPainted(true); - mainPanel.add(monitor); - mainFrame.getContentPane().add(mainPanel); - mainFrame.setVisible(true); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(pTphaseEnvelope1.class); + + graph2b graph2 = null; + SystemInterface system; + boolean bubblePointFirst = true; + double[] cricondenTherm = new double[3]; + double[] cricondenBar = new double[3]; + double phaseFraction = 1e-10; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; + double lnOldOldK[], lnK[]; + boolean outputToFile = false; + double lnOldK[]; + double oldDeltalnK[], deltalnK[]; + double tm[] = {1, 1}; + double beta = 1e-5; + int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase + JProgressBar monitor; + JFrame mainFrame; + String fileName = "c:/file"; + JPanel mainPanel; + double temp = 0, pres = 0, startPres = 0; + double[][] points = new double[2][]; + double[] pointsH; + double[][] pointsH2 = new double[4][]; + double[] pointsV; + double[][] pointsV2 = new double[4][]; + double[] pointsS; + double[][] pointsS2 = new double[4][]; + public double[][] points2 = new double[4][]; + double[][] points3 = new double[8][]; + boolean moreLines = false; + int np = 0; + // points[2] = new double[1000]; + int speceq = 0; + + /** + *+ * Constructor for pTphaseEnvelope1. + *
+ */ + public pTphaseEnvelope1() {} + + /** + *+ * Constructor for pTphaseEnvelope1. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param name a {@link java.lang.String} object + * @param phaseFraction a double + * @param lowPres a double + * @param bubfirst a boolean + */ + public pTphaseEnvelope1(SystemInterface system, String name, double phaseFraction, double lowPres, + boolean bubfirst) { + this.bubblePointFirst = bubfirst; + if (name != null) { + outputToFile = true; + fileName = name; } + this.system = system; + this.phaseFraction = phaseFraction; + lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnK = new double[system.getPhase(0).getNumberOfComponents()]; + this.lowPres = lowPres; + oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + mainFrame = new JFrame("Progress Bar"); + mainPanel = new JPanel(); + mainPanel.setSize(200, 100); + mainFrame.getContentPane().setLayout(new FlowLayout()); + mainPanel.setLayout(new FlowLayout()); + mainFrame.setSize(200, 100); + monitor = new JProgressBar(0, 00); + monitor.setSize(200, 100); + monitor.setStringPainted(true); + mainPanel.add(monitor); + mainFrame.getContentPane().add(mainPanel); + mainFrame.setVisible(true); + } + + /** {@inheritDoc} */ + @Override + public void run() { + try { + points[0] = new double[10000]; + points[1] = new double[10000]; + + pointsH = new double[10000]; + pointsV = new double[10000]; + pointsS = new double[10000]; + system.init(0); + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { + if (system.getPhase(0).getComponents()[i].getTC() < system.getPhase(0).getComponents()[i] + .getTC()) { + speceq = system.getPhase(0).getComponent(i).getComponentNumber(); + } + } + } + + pres = lowPres; + temp = system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); + // temp = system.getTemperature(); + system.setPressure(pres); - /** {@inheritDoc} */ - @Override - public void run() { + system.setBeta(1e-10); + + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + + system.init(0); + for (int i = 0; i < 1000; i++) { + temp += i * 4; + system.setTemperature(temp); try { - points[0] = new double[10000]; - points[1] = new double[10000]; - - pointsH = new double[10000]; - pointsV = new double[10000]; - pointsS = new double[10000]; - system.init(0); - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { - if (system.getPhase(0).getComponents()[i] - .getTC() < system.getPhase(0).getComponents()[i].getTC()) { - speceq = system.getPhase(0).getComponent(i).getComponentNumber(); - } - } - } - - pres = lowPres; - temp = system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); - // temp = system.getTemperature(); - system.setPressure(pres); - - system.setBeta(1e-10); - - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - - system.init(0); - for (int i = 0; i < 1000; i++) { - temp += i * 4; - system.setTemperature(temp); - try { - if (bubblePointFirst) { - testOps.bubblePointTemperatureFlash(); - } else { - testOps.dewPointTemperatureFlash(); - } - } catch (Exception e) { - e.toString(); - } - double tempNy = system.getTemperature(); - - if (!Double.isNaN(tempNy)) { - temp = tempNy; - break; - } - } - - system.setPressure(pres); - system.setTemperature(temp); - logger.info("temp: " + system.getTemperature()); - - system.setBeta(phaseFraction); - - sysNewtonRhapsonPhaseEnvelope nonLinSolver = new sysNewtonRhapsonPhaseEnvelope(system, - 2, system.getPhase(0).getNumberOfComponents()); - nonLinSolver.solve(1); - - startPres = system.getPressure(); - - for (np = 1; np < 9500; np++) { - if (np % 5 == 0) { - monitor.setValue(np); - monitor.setString("Calculated points: " + np); - } - - nonLinSolver.calcInc(np); - nonLinSolver.solve(np); - - if (system.getTemperature() > cricondenTherm[0]) { - cricondenTherm[1] = system.getPressure(); - cricondenTherm[0] = system.getTemperature(); - } - if (system.getPressure() > cricondenBar[1]) { - cricondenBar[0] = system.getTemperature(); - cricondenBar[1] = system.getPressure(); - } - - if (Double.isNaN(system.getTemperature()) || Double.isNaN(system.getTemperature()) - || system.getPressure() < startPres) { - points[0][np - 1] = points[0][np - 3]; - points[1][np - 1] = points[1][np - 3]; - pointsH[np - 1] = pointsH[np - 3]; - pointsV[np - 1] = pointsV[np - 3]; - pointsS[np - 1] = pointsS[np - 3]; - - // logger.info("avbryter" + np); - break; - } - // logger.info("Ideal pres: " + getPressure()); - // logger.info("temp: " + system.getTemperature()); - points[0][np - 1] = system.getTemperature(); - points[1][np - 1] = system.getPressure(); - pointsH[np - 1] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV[np - 1] = system.getPhase(1).getDensity(); - pointsS[np - 1] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - } - - int ncr = nonLinSolver.getNpCrit(); - int ncr2 = np - ncr; - - logger.info("ncr: " + ncr + " ncr2 . " + ncr2); - points2[0] = new double[ncr + 1]; - points2[1] = new double[ncr + 1]; - pointsH2[0] = new double[ncr + 1]; - pointsH2[1] = new double[ncr + 1]; - pointsS2[0] = new double[ncr + 1]; - pointsS2[1] = new double[ncr + 1]; - pointsV2[0] = new double[ncr + 1]; - pointsV2[1] = new double[ncr + 1]; - if (ncr2 > 2) { - points2[2] = new double[ncr2 - 2]; - points2[3] = new double[ncr2 - 2]; - pointsH2[2] = new double[ncr2 - 2]; - pointsH2[3] = new double[ncr2 - 2]; - pointsV2[2] = new double[ncr2 - 2]; - pointsV2[3] = new double[ncr2 - 2]; - pointsS2[2] = new double[ncr2 - 2]; - pointsS2[3] = new double[ncr2 - 2]; - } else { - points2[2] = new double[0]; - points2[3] = new double[0]; - pointsH2[2] = new double[0]; - pointsH2[3] = new double[0]; - pointsV2[2] = new double[0]; - pointsV2[3] = new double[0]; - pointsS2[2] = new double[0]; - pointsS2[3] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - points2[0][i] = points[0][i]; - points2[1][i] = points[1][i]; - - pointsH2[1][i] = points[1][i]; - pointsH2[0][i] = pointsH[i]; - - pointsS2[1][i] = points[1][i]; - pointsS2[0][i] = pointsS[i]; - - pointsV2[1][i] = points[1][i]; - pointsV2[0][i] = pointsV[i]; - } - - system.setTemperature(system.getTC() + 0.001); - system.setPressure(system.getPC() + 0.001); - system.init(3); - - points2[0][ncr] = system.getTC(); - points2[1][ncr] = system.getPC(); - - pointsH2[1][ncr] = system.getPC(); - pointsH2[0][ncr] = - system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - - pointsS2[1][ncr] = system.getPC(); - pointsS2[0][ncr] = - system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - - pointsV2[1][ncr] = system.getPC(); - pointsV2[0][ncr] = system.getPhase(1).getDensity(); - - if (ncr2 > 2) { - points2[2][0] = system.getTC(); - points2[3][0] = system.getPC(); - pointsH2[3][0] = system.getPC(); - pointsH2[2][0] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsS2[3][0] = system.getPC(); - pointsS2[2][0] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV2[3][0] = system.getPC(); - pointsV2[2][0] = system.getPhase(1).getDensity(); - - for (int i = 1; i < (ncr2 - 2); i++) { - points2[2][i] = points[0][i + ncr - 1]; - points2[3][i] = points[1][i + ncr - 1]; - - pointsH2[3][i] = points[1][i + ncr - 1]; - pointsH2[2][i] = pointsH[i + ncr - 1]; - - pointsS2[3][i] = points[1][i + ncr - 1]; - pointsS2[2][i] = pointsS[i + ncr - 1]; - - pointsV2[3][i] = points[1][i + ncr - 1]; - pointsV2[2][i] = pointsV[i + ncr - 1]; - } - } - // monitor.close(); - mainFrame.setVisible(false); -/* - if (outputToFile) { - String name1 = new String(); - name1 = fileName + "Dew.nc"; - file1 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file1.setOutputFileName(name1); - file1.setXvalues(points2[2], "temp", "sec"); - file1.setYvalues(points2[3], "pres", "meter"); - file1.createFile(); - - String name2 = new String(); - name2 = fileName + "Bub.nc"; - file2 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file2.setOutputFileName(name2); - file2.setXvalues(points2[0], "temp", "sec"); - file2.setYvalues(points2[1], "pres", "meter"); - file2.createFile(); - } - */ + if (bubblePointFirst) { + testOps.bubblePointTemperatureFlash(); + } else { + testOps.dewPointTemperatureFlash(); + } } catch (Exception e) { - logger.error("error", e); + e.toString(); } - } + double tempNy = system.getTemperature(); - /** {@inheritDoc} */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title3 = "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title5 = "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - - // logger.info("start flash"); - // logger.info("Tferdig.."); - - graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); - graph3.setVisible(true); - graph3.saveFigure((neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig4.png")); - - graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); - graph4.setVisible(true); - graph4.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig2.png"); - - graph2b graph5 = - new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); - graph5.setVisible(true); - graph5.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig3.png"); - - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - graph2.setVisible(true); - graph2.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig1.png"); - - /* - * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); - * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = - * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); - */ - } + if (!Double.isNaN(tempNy)) { + temp = tempNy; + break; + } + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} - - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" - + String.valueOf(nf.format(PC) + " bara"); - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - return graph2.getChart(); - } + system.setPressure(pres); + system.setTemperature(temp); + logger.info("temp: " + system.getTemperature()); - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points2; - } + system.setBeta(phaseFraction); - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - if (name.equals("bubT")) { - return points2[0]; - } - if (name.equals("bubP")) { - return points2[1]; - } - if (name.equals("dewT")) { - return points2[2]; - } - if (name.equals("dewP")) { - return points2[3]; - } - if (name.equals("dewH")) { - return pointsH2[2]; - } - if (name.equals("dewDens")) { - return pointsV2[2]; - } - if (name.equals("dewS")) { - return pointsS2[2]; - } - if (name.equals("bubH")) { - return pointsH2[0]; + sysNewtonRhapsonPhaseEnvelope nonLinSolver = + new sysNewtonRhapsonPhaseEnvelope(system, 2, system.getPhase(0).getNumberOfComponents()); + nonLinSolver.solve(1); + + startPres = system.getPressure(); + + for (np = 1; np < 9500; np++) { + if (np % 5 == 0) { + monitor.setValue(np); + monitor.setString("Calculated points: " + np); } - if (name.equals("bubDens")) { - return pointsV2[0]; + + nonLinSolver.calcInc(np); + nonLinSolver.solve(np); + + if (system.getTemperature() > cricondenTherm[0]) { + cricondenTherm[1] = system.getPressure(); + cricondenTherm[0] = system.getTemperature(); } - if (name.equals("bubS")) { - return pointsS2[0]; + if (system.getPressure() > cricondenBar[1]) { + cricondenBar[0] = system.getTemperature(); + cricondenBar[1] = system.getPressure(); } - if (name.equals("cricondentherm")) { - return cricondenTherm; + + if (Double.isNaN(system.getTemperature()) || Double.isNaN(system.getTemperature()) + || system.getPressure() < startPres) { + points[0][np - 1] = points[0][np - 3]; + points[1][np - 1] = points[1][np - 3]; + pointsH[np - 1] = pointsH[np - 3]; + pointsV[np - 1] = pointsV[np - 3]; + pointsS[np - 1] = pointsS[np - 3]; + + // logger.info("avbryter" + np); + break; } - if (name.equals("cricondenbar")) { - return cricondenBar; - } else { - return null; + // logger.info("Ideal pres: " + getPressure()); + // logger.info("temp: " + system.getTemperature()); + points[0][np - 1] = system.getTemperature(); + points[1][np - 1] = system.getPressure(); + pointsH[np - 1] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV[np - 1] = system.getPhase(1).getDensity(); + pointsS[np - 1] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + } + + int ncr = nonLinSolver.getNpCrit(); + int ncr2 = np - ncr; + + logger.info("ncr: " + ncr + " ncr2 . " + ncr2); + points2[0] = new double[ncr + 1]; + points2[1] = new double[ncr + 1]; + pointsH2[0] = new double[ncr + 1]; + pointsH2[1] = new double[ncr + 1]; + pointsS2[0] = new double[ncr + 1]; + pointsS2[1] = new double[ncr + 1]; + pointsV2[0] = new double[ncr + 1]; + pointsV2[1] = new double[ncr + 1]; + if (ncr2 > 2) { + points2[2] = new double[ncr2 - 2]; + points2[3] = new double[ncr2 - 2]; + pointsH2[2] = new double[ncr2 - 2]; + pointsH2[3] = new double[ncr2 - 2]; + pointsV2[2] = new double[ncr2 - 2]; + pointsV2[3] = new double[ncr2 - 2]; + pointsS2[2] = new double[ncr2 - 2]; + pointsS2[3] = new double[ncr2 - 2]; + } else { + points2[2] = new double[0]; + points2[3] = new double[0]; + pointsH2[2] = new double[0]; + pointsH2[3] = new double[0]; + pointsV2[2] = new double[0]; + pointsV2[3] = new double[0]; + pointsS2[2] = new double[0]; + pointsS2[3] = new double[0]; + } + + for (int i = 0; i < ncr; i++) { + points2[0][i] = points[0][i]; + points2[1][i] = points[1][i]; + + pointsH2[1][i] = points[1][i]; + pointsH2[0][i] = pointsH[i]; + + pointsS2[1][i] = points[1][i]; + pointsS2[0][i] = pointsS[i]; + + pointsV2[1][i] = points[1][i]; + pointsV2[0][i] = pointsV[i]; + } + + system.setTemperature(system.getTC() + 0.001); + system.setPressure(system.getPC() + 0.001); + system.init(3); + + points2[0][ncr] = system.getTC(); + points2[1][ncr] = system.getPC(); + + pointsH2[1][ncr] = system.getPC(); + pointsH2[0][ncr] = system.getPhase(1).getEnthalpy() + / system.getPhase(1).getNumberOfMolesInPhase() / system.getPhase(1).getMolarMass() / 1e3; + + pointsS2[1][ncr] = system.getPC(); + pointsS2[0][ncr] = system.getPhase(1).getEntropy() + / system.getPhase(1).getNumberOfMolesInPhase() / system.getPhase(1).getMolarMass() / 1e3; + + pointsV2[1][ncr] = system.getPC(); + pointsV2[0][ncr] = system.getPhase(1).getDensity(); + + if (ncr2 > 2) { + points2[2][0] = system.getTC(); + points2[3][0] = system.getPC(); + pointsH2[3][0] = system.getPC(); + pointsH2[2][0] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsS2[3][0] = system.getPC(); + pointsS2[2][0] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV2[3][0] = system.getPC(); + pointsV2[2][0] = system.getPhase(1).getDensity(); + + for (int i = 1; i < (ncr2 - 2); i++) { + points2[2][i] = points[0][i + ncr - 1]; + points2[3][i] = points[1][i + ncr - 1]; + + pointsH2[3][i] = points[1][i + ncr - 1]; + pointsH2[2][i] = pointsH[i + ncr - 1]; + + pointsS2[3][i] = points[1][i + ncr - 1]; + pointsS2[2][i] = pointsS[i + ncr - 1]; + + pointsV2[3][i] = points[1][i + ncr - 1]; + pointsV2[2][i] = pointsV[i + ncr - 1]; } + } + // monitor.close(); + mainFrame.setVisible(false); + /* + * if (outputToFile) { String name1 = new String(); name1 = fileName + "Dew.nc"; file1 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file1.setOutputFileName(name1); file1.setXvalues(points2[2], "temp", "sec"); + * file1.setYvalues(points2[3], "pres", "meter"); file1.createFile(); + * + * String name2 = new String(); name2 = fileName + "Bub.nc"; file2 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file2.setOutputFileName(name2); file2.setXvalues(points2[0], "temp", "sec"); + * file2.setYvalues(points2[1], "pres", "meter"); file2.createFile(); } + */ + } catch (Exception e) { + logger.error("error", e); } + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = + "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title3 = + "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + + String.valueOf(nf.format(PC)); + String title5 = + "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + + // logger.info("start flash"); + // logger.info("Tferdig.."); + + graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); + graph3.setVisible(true); + graph3.saveFigure((neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig4.png")); + + graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); + graph4.setVisible(true); + graph4.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig2.png"); + + graph2b graph5 = new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); + graph5.setVisible(true); + graph5.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig3.png"); + + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + graph2.setVisible(true); + graph2.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig1.png"); - /** {@inheritDoc} */ /* - @Override - public void createNetCdfFile(String name) { - fileName = name; - } - */ - - /** - * Getter for property bubblePointFirst. - * - * @return Value of property bubblePointFirst. + * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); + * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = + * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); */ - public boolean isBubblePointFirst() { - return bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" + + String.valueOf(nf.format(PC) + " bara"); + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + return graph2.getChart(); + } + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points2; + } + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + if (name.equals("bubT")) { + return points2[0]; } - - /** - * Setter for property bubblePointFirst. - * - * @param bubblePointFirst New value of property bubblePointFirst. - */ - public void setBubblePointFirst(boolean bubblePointFirst) { - this.bubblePointFirst = bubblePointFirst; + if (name.equals("bubP")) { + return points2[1]; } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; + if (name.equals("dewT")) { + return points2[2]; + } + if (name.equals("dewP")) { + return points2[3]; + } + if (name.equals("dewH")) { + return pointsH2[2]; + } + if (name.equals("dewDens")) { + return pointsV2[2]; + } + if (name.equals("dewS")) { + return pointsS2[2]; + } + if (name.equals("bubH")) { + return pointsH2[0]; + } + if (name.equals("bubDens")) { + return pointsV2[0]; + } + if (name.equals("bubS")) { + return pointsS2[0]; + } + if (name.equals("cricondentherm")) { + return cricondenTherm; + } + if (name.equals("cricondenbar")) { + return cricondenBar; + } else { + return null; } + } + + /** + * Getter for property bubblePointFirst. + * + * @return Value of property bubblePointFirst. + */ + public boolean isBubblePointFirst() { + return bubblePointFirst; + } + + /** + * Setter for property bubblePointFirst. + * + * @param bubblePointFirst New value of property bubblePointFirst. + */ + public void setBubblePointFirst(boolean bubblePointFirst) { + this.bubblePointFirst = bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeMay.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeMay.java index 1724eb7e68..02c54b233c 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeMay.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeMay.java @@ -20,778 +20,756 @@ * @version $Id: $Id */ public class pTphaseEnvelopeMay extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(pTphaseEnvelopeMay.class); - - double maxPressure = 1000.0; - double minPressure = 1.0; - double[][] copiedPoints = null; - graph2b graph2 = null; - SystemInterface system; - boolean bubblePointFirst = true; - boolean hascopiedPoints = false; - double[] cricondenTherm = new double[3]; - double[] cricondenBar = new double[3]; - double phaseFraction = 1e-10; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; - double lnOldOldK[], lnK[]; - boolean outputToFile = false; - double lnOldK[]; - double lnKwil[]; - double oldDeltalnK[], deltalnK[]; - double tm[] = {1, 1}; - double beta = 1e-5; - int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase - JProgressBar monitor; - JFrame mainFrame; - String fileName = "c:/file"; - JPanel mainPanel; - double temp = 0, pres = 0, startPres = 0; - double[][] points = new double[2][]; - double[] pointsH; - double[][] pointsH2 = new double[4][]; - double[] pointsV; - double[][] pointsV2 = new double[4][]; - double[] pointsS; - double[][] pointsS2 = new double[4][]; - public double[][] points2 = new double[4][]; - double[][] points3 = new double[8][]; - boolean moreLines = false; - boolean restart = true; - int np = 0; - // points[2] = new double[1000]; - int speceq = 0; - String[] navn = {"bubble point", "dew point", "bubble point", "dew point", "dew points"}; - int npfirst; - int ncrfirst; - double Tcfirst; - double Pcfirst; - double Tmin = 0.0; - - /** - *- * Constructor for pTphaseEnvelopeMay. - *
- */ - public pTphaseEnvelopeMay() {} - - /** - *- * Constructor for pTphaseEnvelopeMay. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param name a {@link java.lang.String} object - * @param phaseFraction a double - * @param lowPres a double - * @param bubfirst a boolean - */ - public pTphaseEnvelopeMay(SystemInterface system, String name, double phaseFraction, - double lowPres, boolean bubfirst) { - this.bubblePointFirst = bubfirst; - if (name != null) { - outputToFile = true; - fileName = name; - } - this.system = system; - this.phaseFraction = phaseFraction; - lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnK = new double[system.getPhase(0).getNumberOfComponents()]; - this.lowPres = lowPres; - oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; - deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(pTphaseEnvelopeMay.class); + + double maxPressure = 1000.0; + double minPressure = 1.0; + double[][] copiedPoints = null; + graph2b graph2 = null; + SystemInterface system; + boolean bubblePointFirst = true; + boolean hascopiedPoints = false; + double[] cricondenTherm = new double[3]; + double[] cricondenBar = new double[3]; + double phaseFraction = 1e-10; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; + double lnOldOldK[], lnK[]; + boolean outputToFile = false; + double lnOldK[]; + double lnKwil[]; + double oldDeltalnK[], deltalnK[]; + double tm[] = {1, 1}; + double beta = 1e-5; + int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase + JProgressBar monitor; + JFrame mainFrame; + String fileName = "c:/file"; + JPanel mainPanel; + double temp = 0, pres = 0, startPres = 0; + double[][] points = new double[2][]; + double[] pointsH; + double[][] pointsH2 = new double[4][]; + double[] pointsV; + double[][] pointsV2 = new double[4][]; + double[] pointsS; + double[][] pointsS2 = new double[4][]; + public double[][] points2 = new double[4][]; + double[][] points3 = new double[8][]; + boolean moreLines = false; + boolean restart = true; + int np = 0; + // points[2] = new double[1000]; + int speceq = 0; + String[] navn = {"bubble point", "dew point", "bubble point", "dew point", "dew points"}; + int npfirst; + int ncrfirst; + double Tcfirst; + double Pcfirst; + double Tmin = 0.0; + + /** + *+ * Constructor for pTphaseEnvelopeMay. + *
+ */ + public pTphaseEnvelopeMay() {} + + /** + *+ * Constructor for pTphaseEnvelopeMay. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param name a {@link java.lang.String} object + * @param phaseFraction a double + * @param lowPres a double + * @param bubfirst a boolean + */ + public pTphaseEnvelopeMay(SystemInterface system, String name, double phaseFraction, + double lowPres, boolean bubfirst) { + this.bubblePointFirst = bubfirst; + if (name != null) { + outputToFile = true; + fileName = name; } - - /** {@inheritDoc} */ - @Override - public void run() { - speceq = 0; // initialization + this.system = system; + this.phaseFraction = phaseFraction; + lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnK = new double[system.getPhase(0).getNumberOfComponents()]; + this.lowPres = lowPres; + oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + } + + /** {@inheritDoc} */ + @Override + public void run() { + speceq = 0; // initialization + try { + points[0] = new double[10000]; // declarations for points + points[1] = new double[10000]; // declarations for points + + pointsH = new double[10000]; // declarations for points + pointsV = new double[10000]; // declarations for points + pointsS = new double[10000]; // declarations for points + system.init(0); // initialization + + // selects the most volatile and least volatile component based on Tc values + // afterwards it uses them to define the speceq of the first point + // based on the desired first point, dew/bubble + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { + if (bubblePointFirst == true && system.getPhase(0).getComponents()[speceq] + .getTC() > system.getPhase(0).getComponents()[i].getTC()) { + speceq = system.getPhase(0).getComponent(i).getComponentNumber(); + } + if (bubblePointFirst == false && system.getPhase(0).getComponents()[speceq] + .getTC() < system.getPhase(0).getComponents()[i].getTC()) { + speceq = system.getPhase(0).getComponent(i).getComponentNumber(); + } + } + } + + // initialized the first step of the phase envelope + // pressure is already defined + // temperature is the Antoine vapor pressure of the selected component + // (least or most volatile. + pres = lowPres; + // temp = + // system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); + temp = tempKWilson(phaseFraction, pres); + + if (Double.isNaN(temp)) { + temp = system.getPhase(0).getComponent(speceq).getTC() - 20.0; + } + system.setTemperature(temp); + system.setPressure(pres); + + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + + // this part converges the first phase envelope point. + // if the phase fraction is more than 0.5 it does a dew point initialization + // else a bubble point initialization + + for (int i = 0; i < 5; i++) { try { - points[0] = new double[10000]; // declarations for points - points[1] = new double[10000]; // declarations for points - - pointsH = new double[10000]; // declarations for points - pointsV = new double[10000]; // declarations for points - pointsS = new double[10000]; // declarations for points - system.init(0); // initialization - - // selects the most volatile and least volatile component based on Tc values - // afterwards it uses them to define the speceq of the first point - // based on the desired first point, dew/bubble - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { - if (bubblePointFirst == true && system.getPhase(0).getComponents()[speceq] - .getTC() > system.getPhase(0).getComponents()[i].getTC()) { - speceq = system.getPhase(0).getComponent(i).getComponentNumber(); - } - if (bubblePointFirst == false && system.getPhase(0).getComponents()[speceq] - .getTC() < system.getPhase(0).getComponents()[i].getTC()) { - speceq = system.getPhase(0).getComponent(i).getComponentNumber(); - } - } - } - - // initialized the first step of the phase envelope - // pressure is already defined - // temperature is the Antoine vapor pressure of the selected component - // (least or most volatile. - pres = lowPres; - // temp = - // system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); - temp = tempKWilson(phaseFraction, pres); - - if (Double.isNaN(temp)) { - temp = system.getPhase(0).getComponent(speceq).getTC() - 20.0; - } + if (phaseFraction < 0.5) { + temp += i * 2; system.setTemperature(temp); - system.setPressure(pres); - - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - - // this part converges the first phase envelope point. - // if the phase fraction is more than 0.5 it does a dew point initialization - // else a bubble point initialization - - for (int i = 0; i < 5; i++) { - try { - if (phaseFraction < 0.5) { - temp += i * 2; - system.setTemperature(temp); - testOps.bubblePointTemperatureFlash(); - } else { - temp += i * 2; - system.setTemperature(temp); - testOps.dewPointTemperatureFlash(); - } - } catch (Exception e) { - e.toString(); - } - double tempNy = system.getTemperature(); - - if (!Double.isNaN(tempNy)) { - temp = tempNy; - break; - } - } - - // this part sets the first envelope point into the system - system.setBeta(phaseFraction); - system.setPressure(pres); + testOps.bubblePointTemperatureFlash(); + } else { + temp += i * 2; system.setTemperature(temp); + testOps.dewPointTemperatureFlash(); + } + } catch (Exception e) { + e.toString(); + } + double tempNy = system.getTemperature(); - sysNewtonRhapsonPhaseEnvelope nonLinSolver = new sysNewtonRhapsonPhaseEnvelope(system, - 2, system.getPhase(0).getNumberOfComponents()); - startPres = system.getPressure(); - nonLinSolver.setu(); - for (np = 1; np < 9980; np++) { - try { - // solves the np point of the envelope - nonLinSolver.calcInc(np); - nonLinSolver.solve(np); - - // double TT = system.getPhase(0).getTemperature(); - // double PP = system.getPhase(0).getPressure(); - } catch (Exception e0) { - // the envelope crushed. - // this part keeps the old values - // restarts the envelope from the other side - // and then stops - - if (restart) { - restart = false; - // keep values - Tmin = points[0][np - 2]; - npfirst = np - 1; - ncrfirst = nonLinSolver.getNpCrit(); - if (ncrfirst == 0) { - ncrfirst = npfirst; - } - Tcfirst = system.getTC(); - Pcfirst = system.getPC(); - hascopiedPoints = true; - copiedPoints = new double[5][np - 1]; - for (int i = 0; i < np - 1; i++) { - copiedPoints[0][i] = points[0][i]; - copiedPoints[1][i] = points[1][i]; - copiedPoints[2][i] = pointsH[i]; - copiedPoints[3][i] = pointsS[i]; - copiedPoints[4][i] = pointsV[i]; - } - // new settings - phaseFraction = 1.0 - phaseFraction; - if (bubblePointFirst) { - bubblePointFirst = false; - } else { - bubblePointFirst = true; - } - run(); - break; - } else { - np = np - 1; - break; - } - } - - // check for critical point - double Kvallc = system.getPhase(0).getComponent(nonLinSolver.lc).getx() - / system.getPhase(1).getComponent(nonLinSolver.lc).getx(); - double Kvalhc = system.getPhase(0).getComponent(nonLinSolver.hc).getx() - / system.getPhase(1).getComponent(nonLinSolver.hc).getx(); - // double densV = system.getPhase(0).getDensity(); - // double densL = system.getPhase(1).getDensity(); - - // System.out.println(np + " " + system.getTemperature() + " " + - // system.getPressure() + " " + densV + " " + densL ); - - if ((nonLinSolver.etterCP == false)) { - if (Kvallc < 1.05 && Kvalhc > 0.95) { - // close to the critical point - // invert phase types and find the CP Temp and Press - - // System.out.println("critical point"); - nonLinSolver.npCrit = np; - system.invertPhaseTypes(); - nonLinSolver.etterCP = true; - // the critical point is found from interpolation plynimials based on K=1 of - // the - // most or least volatile component - nonLinSolver.calcCrit(); - } - } - if (nonLinSolver.calcCP) { - nonLinSolver.calcCP = false; - nonLinSolver.npCrit = np; - nonLinSolver.calcCrit(); - } - - // stores cricondenbar and cricondentherm - // HERE the new cricoT and crico P values will be called instead - if (system.getTemperature() > cricondenTherm[0]) { - cricondenTherm[1] = system.getPressure(); - cricondenTherm[0] = system.getTemperature(); - } else { - nonLinSolver.ettercricoT = true; - } - if (system.getPressure() > cricondenBar[1]) { - cricondenBar[0] = system.getTemperature(); - cricondenBar[1] = system.getPressure(); - } - - // Exit criteria - if ((system.getPressure() < minPressure && nonLinSolver.ettercricoT)) { - break; - } - if (system.getPressure() > maxPressure) { - break; - } - if (system.getTemperature() > Tmin && !restart) { - break; - } - - // Keeps the calculated points - points[0][np - 1] = system.getTemperature(); - points[1][np - 1] = system.getPressure(); - pointsH[np - 1] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV[np - 1] = system.getPhase(1).getDensity(); - pointsS[np - 1] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; + if (!Double.isNaN(tempNy)) { + temp = tempNy; + break; + } + } + + // this part sets the first envelope point into the system + system.setBeta(phaseFraction); + system.setPressure(pres); + system.setTemperature(temp); + + sysNewtonRhapsonPhaseEnvelope nonLinSolver = + new sysNewtonRhapsonPhaseEnvelope(system, 2, system.getPhase(0).getNumberOfComponents()); + startPres = system.getPressure(); + nonLinSolver.setu(); + for (np = 1; np < 9980; np++) { + try { + // solves the np point of the envelope + nonLinSolver.calcInc(np); + nonLinSolver.solve(np); + + // double TT = system.getPhase(0).getTemperature(); + // double PP = system.getPhase(0).getPressure(); + } catch (Exception e0) { + // the envelope crushed. + // this part keeps the old values + // restarts the envelope from the other side + // and then stops + + if (restart) { + restart = false; + // keep values + Tmin = points[0][np - 2]; + npfirst = np - 1; + ncrfirst = nonLinSolver.getNpCrit(); + if (ncrfirst == 0) { + ncrfirst = npfirst; } - - try { - int ncr = nonLinSolver.getNpCrit(); - if (ncr == 0) { - ncr = np; - } - int ncr2 = np - ncr; - if (hascopiedPoints) { - // if it enters here the envelope crashed and restarted - // reallocate to have all values - points2 = new double[8][]; - pointsH2 = new double[8][]; - pointsS2 = new double[8][]; - pointsV2 = new double[8][]; - } - - // points2 are plotted - points2[0] = new double[ncr + 1]; - points2[1] = new double[ncr + 1]; - pointsH2[0] = new double[ncr + 1]; - pointsH2[1] = new double[ncr + 1]; - pointsS2[0] = new double[ncr + 1]; - pointsS2[1] = new double[ncr + 1]; - pointsV2[0] = new double[ncr + 1]; - pointsV2[1] = new double[ncr + 1]; - - if (ncr2 > 2) { - points2[2] = new double[ncr2 - 2]; - points2[3] = new double[ncr2 - 2]; - pointsH2[2] = new double[ncr2 - 2]; - pointsH2[3] = new double[ncr2 - 2]; - pointsS2[2] = new double[ncr2 - 2]; - pointsS2[3] = new double[ncr2 - 2]; - pointsV2[2] = new double[ncr2 - 2]; - pointsV2[3] = new double[ncr2 - 2]; - } else { - points2[2] = new double[0]; - points2[3] = new double[0]; - pointsH2[2] = new double[0]; - pointsH2[3] = new double[0]; - pointsS2[2] = new double[0]; - pointsS2[3] = new double[0]; - pointsV2[2] = new double[0]; - pointsV2[3] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - // second branch up to critical point - points2[0][i] = points[0][i]; - points2[1][i] = points[1][i]; - pointsH2[1][i] = points[1][i]; - pointsH2[0][i] = pointsH[i]; - pointsS2[1][i] = points[1][i]; - pointsS2[0][i] = pointsS[i]; - pointsV2[1][i] = points[1][i]; - pointsV2[0][i] = pointsV[i]; - } - if (ncr2 > 2) { - for (int i = 1; i < (ncr2 - 2); i++) { - // second branch after the critical point - points2[2][i] = points[0][i + ncr - 1]; - points2[3][i] = points[1][i + ncr - 1]; - pointsH2[3][i] = points[1][i + ncr - 1]; - pointsH2[2][i] = pointsH[i + ncr - 1]; - pointsS2[3][i] = points[1][i + ncr - 1]; - pointsS2[2][i] = pointsS[i + ncr - 1]; - pointsV2[3][i] = points[1][i + ncr - 1]; - pointsV2[2][i] = pointsV[i + ncr - 1]; - } - } - - if (hascopiedPoints) { - if (ncrfirst > npfirst) { - ncr = copiedPoints[0].length - 1; - ncr2 = npfirst - ncr; - npfirst = npfirst - 1; - } else { - ncr = ncrfirst; - ncr2 = npfirst - ncr; - } - - points2[4] = new double[ncr + 1]; - points2[5] = new double[ncr + 1]; - pointsH2[4] = new double[ncr + 1]; - pointsH2[5] = new double[ncr + 1]; - pointsS2[4] = new double[ncr + 1]; - pointsS2[5] = new double[ncr + 1]; - pointsV2[4] = new double[ncr + 1]; - pointsV2[5] = new double[ncr + 1]; - - if (ncr2 > 2) { - points2[6] = new double[ncr2 - 2]; - points2[7] = new double[ncr2 - 2]; - pointsH2[6] = new double[ncr2 - 2]; - pointsH2[7] = new double[ncr2 - 2]; - pointsS2[6] = new double[ncr2 - 2]; - pointsS2[7] = new double[ncr2 - 2]; - pointsV2[6] = new double[ncr2 - 2]; - pointsV2[7] = new double[ncr2 - 2]; - } else { - points2[6] = new double[0]; - points2[7] = new double[0]; - pointsH2[6] = new double[0]; - pointsH2[7] = new double[0]; - pointsS2[6] = new double[0]; - pointsS2[7] = new double[0]; - pointsV2[6] = new double[0]; - pointsV2[7] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - // first branch up to the critical point - points2[4][i] = copiedPoints[0][i]; - points2[5][i] = copiedPoints[1][i]; - pointsH2[5][i] = copiedPoints[1][i]; - pointsH2[4][i] = copiedPoints[2][i]; - pointsS2[5][i] = copiedPoints[1][i]; - pointsS2[4][i] = copiedPoints[3][i]; - pointsV2[5][i] = copiedPoints[1][i]; - pointsV2[4][i] = copiedPoints[4][i]; - } - if (ncr2 > 2) { - for (int i = 1; i < (ncr2 - 2); i++) { - // first branch after the critical point - points2[6][i] = copiedPoints[0][i + ncr - 1]; - points2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsH2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsH2[6][i] = copiedPoints[2][i + ncr - 1]; - pointsS2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsS2[6][i] = copiedPoints[3][i + ncr - 1]; - pointsV2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsV2[6][i] = copiedPoints[4][i + ncr - 1]; - } - } - } - - // critical point - system.setTemperature(system.getTC()); - system.setPressure(system.getPC()); - - system.init(3); - - points2[0][ncr] = system.getTC(); - points2[1][ncr] = system.getPC(); - - if (ncr2 > 2) { - points2[2][0] = system.getTC(); - points2[3][0] = system.getPC(); - } - } catch (Exception e2) { - // double nef = 0.; - logger.error("error", e2); + Tcfirst = system.getTC(); + Pcfirst = system.getPC(); + hascopiedPoints = true; + copiedPoints = new double[5][np - 1]; + for (int i = 0; i < np - 1; i++) { + copiedPoints[0][i] = points[0][i]; + copiedPoints[1][i] = points[1][i]; + copiedPoints[2][i] = pointsH[i]; + copiedPoints[3][i] = pointsS[i]; + copiedPoints[4][i] = pointsV[i]; } -/* - try { - if (outputToFile) { - // update this - String name1 = new String(); - name1 = fileName + "Dew.nc"; - file1 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file1.setOutputFileName(name1); - file1.setXvalues(points2[2], "temp", "sec"); - file1.setYvalues(points2[3], "pres", "meter"); - file1.createFile(); - - String name2 = new String(); - name2 = fileName + "Bub.nc"; - file2 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file2.setOutputFileName(name2); - file2.setXvalues(points2[0], "temp", "sec"); - file2.setYvalues(points2[1], "pres", "meter"); - file2.createFile(); - } - } catch (Exception e3) { - // double nef = 0.; - logger.error("error", e3); + // new settings + phaseFraction = 1.0 - phaseFraction; + if (bubblePointFirst) { + bubblePointFirst = false; + } else { + bubblePointFirst = true; } - */ - } catch (Exception e4) { - // double nef = 0.; - logger.error("error", e4); + run(); + break; + } else { + np = np - 1; + break; + } } - } - /** - *- * calcHydrateLine. - *
- */ - public void calcHydrateLine() { - ThermodynamicOperations opsHyd = new ThermodynamicOperations(system); - try { - opsHyd.hydrateEquilibriumLine(10.0, 300.0); - } catch (Exception e) { - logger.error("error", e); + // check for critical point + double Kvallc = system.getPhase(0).getComponent(nonLinSolver.lc).getx() + / system.getPhase(1).getComponent(nonLinSolver.lc).getx(); + double Kvalhc = system.getPhase(0).getComponent(nonLinSolver.hc).getx() + / system.getPhase(1).getComponent(nonLinSolver.hc).getx(); + // double densV = system.getPhase(0).getDensity(); + // double densL = system.getPhase(1).getDensity(); + + // System.out.println(np + " " + system.getTemperature() + " " + + // system.getPressure() + " " + densV + " " + densL ); + + if ((nonLinSolver.etterCP == false)) { + if (Kvallc < 1.05 && Kvalhc > 0.95) { + // close to the critical point + // invert phase types and find the CP Temp and Press + + // System.out.println("critical point"); + nonLinSolver.npCrit = np; + system.invertPhaseTypes(); + nonLinSolver.etterCP = true; + // the critical point is found from interpolation plynimials based on K=1 of + // the + // most or least volatile component + nonLinSolver.calcCrit(); + } } - - // double[][] hydData = opsHyd.getData(); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - if (bubblePointFirst) { - // bubble point side - navn[0] = "bubble point 2"; - navn[1] = "dew point 2"; - navn[2] = "dew point 1"; - navn[3] = "bubble point 1"; - } else { - // dew point side and does not crash - navn[0] = "dew point"; - navn[1] = "bubble point"; - navn[2] = "dew point"; - navn[3] = "bubbl point"; + if (nonLinSolver.calcCP) { + nonLinSolver.calcCP = false; + nonLinSolver.npCrit = np; + nonLinSolver.calcCrit(); } - double TC = system.getTC(); - double PC = system.getPC(); - - String title = "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title3 = "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title5 = "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - - graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); - graph3.setVisible(true); - // graph3.saveFigure(new String(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig4.png")); - - graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); - graph4.setVisible(true); - // graph4.saveFigure(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig2.png"); - - graph2b graph5 = - new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); - graph5.setVisible(true); - // graph5.saveFigure(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig3.png"); - - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - graph2.setVisible(true); - // graph2.saveFigure(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig1.png"); - - /* - * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); - * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = - * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); - */ - } - - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} - - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points2; - } - - /** {@inheritDoc} */ - @Override - public void addData(String name, double[][] data) { - double[][] localPoints = new double[points2.length + data.length][]; - navn[localPoints.length / 2 - 1] = name; - System.arraycopy(points2, 0, localPoints, 0, points2.length); - System.arraycopy(data, 0, localPoints, points2.length, data.length); - points2 = localPoints; - } - - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - if (name.equals("dewT")) { - return points2[0]; - } - if (name.equals("dewP")) { - return points2[1]; - } - if (name.equals("bubT")) { - return points2[2]; - } - if (name.equals("bubP")) { - return points2[3]; - } - if (name.equals("dewT2")) { - return points2[4]; - } - if (name.equals("dewP2")) { - return points2[5]; - } - if (name.equals("bubT2")) { - return points2[6]; + // stores cricondenbar and cricondentherm + // HERE the new cricoT and crico P values will be called instead + if (system.getTemperature() > cricondenTherm[0]) { + cricondenTherm[1] = system.getPressure(); + cricondenTherm[0] = system.getTemperature(); + } else { + nonLinSolver.ettercricoT = true; } - if (name.equals("bubP2")) { - return points2[7]; + if (system.getPressure() > cricondenBar[1]) { + cricondenBar[0] = system.getTemperature(); + cricondenBar[1] = system.getPressure(); } - if (name.equals("dewH")) { - return pointsH2[2]; + + // Exit criteria + if ((system.getPressure() < minPressure && nonLinSolver.ettercricoT)) { + break; } - if (name.equals("dewDens")) { - return pointsV2[2]; + if (system.getPressure() > maxPressure) { + break; } - if (name.equals("dewS")) { - return pointsS2[2]; + if (system.getTemperature() > Tmin && !restart) { + break; } - if (name.equals("bubH")) { - return pointsH2[0]; + + // Keeps the calculated points + points[0][np - 1] = system.getTemperature(); + points[1][np - 1] = system.getPressure(); + pointsH[np - 1] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV[np - 1] = system.getPhase(1).getDensity(); + pointsS[np - 1] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + } + + try { + int ncr = nonLinSolver.getNpCrit(); + if (ncr == 0) { + ncr = np; } - if (name.equals("bubDens")) { - return pointsV2[0]; + int ncr2 = np - ncr; + if (hascopiedPoints) { + // if it enters here the envelope crashed and restarted + // reallocate to have all values + points2 = new double[8][]; + pointsH2 = new double[8][]; + pointsS2 = new double[8][]; + pointsV2 = new double[8][]; } - if (name.equals("bubS")) { - return pointsS2[0]; + + // points2 are plotted + points2[0] = new double[ncr + 1]; + points2[1] = new double[ncr + 1]; + pointsH2[0] = new double[ncr + 1]; + pointsH2[1] = new double[ncr + 1]; + pointsS2[0] = new double[ncr + 1]; + pointsS2[1] = new double[ncr + 1]; + pointsV2[0] = new double[ncr + 1]; + pointsV2[1] = new double[ncr + 1]; + + if (ncr2 > 2) { + points2[2] = new double[ncr2 - 2]; + points2[3] = new double[ncr2 - 2]; + pointsH2[2] = new double[ncr2 - 2]; + pointsH2[3] = new double[ncr2 - 2]; + pointsS2[2] = new double[ncr2 - 2]; + pointsS2[3] = new double[ncr2 - 2]; + pointsV2[2] = new double[ncr2 - 2]; + pointsV2[3] = new double[ncr2 - 2]; + } else { + points2[2] = new double[0]; + points2[3] = new double[0]; + pointsH2[2] = new double[0]; + pointsH2[3] = new double[0]; + pointsS2[2] = new double[0]; + pointsS2[3] = new double[0]; + pointsV2[2] = new double[0]; + pointsV2[3] = new double[0]; } - if (name.equals("cricondentherm")) { - return cricondenTherm; + + for (int i = 0; i < ncr; i++) { + // second branch up to critical point + points2[0][i] = points[0][i]; + points2[1][i] = points[1][i]; + pointsH2[1][i] = points[1][i]; + pointsH2[0][i] = pointsH[i]; + pointsS2[1][i] = points[1][i]; + pointsS2[0][i] = pointsS[i]; + pointsV2[1][i] = points[1][i]; + pointsV2[0][i] = pointsV[i]; } - if (name.equals("cricondenbar")) { - return cricondenBar; + if (ncr2 > 2) { + for (int i = 1; i < (ncr2 - 2); i++) { + // second branch after the critical point + points2[2][i] = points[0][i + ncr - 1]; + points2[3][i] = points[1][i + ncr - 1]; + pointsH2[3][i] = points[1][i + ncr - 1]; + pointsH2[2][i] = pointsH[i + ncr - 1]; + pointsS2[3][i] = points[1][i + ncr - 1]; + pointsS2[2][i] = pointsS[i + ncr - 1]; + pointsV2[3][i] = points[1][i + ncr - 1]; + pointsV2[2][i] = pointsV[i + ncr - 1]; + } } - if (name.equals("criticalPoint1")) { - return new double[] {system.getTC(), system.getPC()}; + + if (hascopiedPoints) { + if (ncrfirst > npfirst) { + ncr = copiedPoints[0].length - 1; + ncr2 = npfirst - ncr; + npfirst = npfirst - 1; + } else { + ncr = ncrfirst; + ncr2 = npfirst - ncr; + } + + points2[4] = new double[ncr + 1]; + points2[5] = new double[ncr + 1]; + pointsH2[4] = new double[ncr + 1]; + pointsH2[5] = new double[ncr + 1]; + pointsS2[4] = new double[ncr + 1]; + pointsS2[5] = new double[ncr + 1]; + pointsV2[4] = new double[ncr + 1]; + pointsV2[5] = new double[ncr + 1]; + + if (ncr2 > 2) { + points2[6] = new double[ncr2 - 2]; + points2[7] = new double[ncr2 - 2]; + pointsH2[6] = new double[ncr2 - 2]; + pointsH2[7] = new double[ncr2 - 2]; + pointsS2[6] = new double[ncr2 - 2]; + pointsS2[7] = new double[ncr2 - 2]; + pointsV2[6] = new double[ncr2 - 2]; + pointsV2[7] = new double[ncr2 - 2]; + } else { + points2[6] = new double[0]; + points2[7] = new double[0]; + pointsH2[6] = new double[0]; + pointsH2[7] = new double[0]; + pointsS2[6] = new double[0]; + pointsS2[7] = new double[0]; + pointsV2[6] = new double[0]; + pointsV2[7] = new double[0]; + } + + for (int i = 0; i < ncr; i++) { + // first branch up to the critical point + points2[4][i] = copiedPoints[0][i]; + points2[5][i] = copiedPoints[1][i]; + pointsH2[5][i] = copiedPoints[1][i]; + pointsH2[4][i] = copiedPoints[2][i]; + pointsS2[5][i] = copiedPoints[1][i]; + pointsS2[4][i] = copiedPoints[3][i]; + pointsV2[5][i] = copiedPoints[1][i]; + pointsV2[4][i] = copiedPoints[4][i]; + } + if (ncr2 > 2) { + for (int i = 1; i < (ncr2 - 2); i++) { + // first branch after the critical point + points2[6][i] = copiedPoints[0][i + ncr - 1]; + points2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsH2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsH2[6][i] = copiedPoints[2][i + ncr - 1]; + pointsS2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsS2[6][i] = copiedPoints[3][i + ncr - 1]; + pointsV2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsV2[6][i] = copiedPoints[4][i + ncr - 1]; + } + } } - if (name.equals("criticalPoint2")) { - return new double[] {0, 0}; - } else { - return null; + + // critical point + system.setTemperature(system.getTC()); + system.setPressure(system.getPC()); + + system.init(3); + + points2[0][ncr] = system.getTC(); + points2[1][ncr] = system.getPC(); + + if (ncr2 > 2) { + points2[2][0] = system.getTC(); + points2[3][0] = system.getPC(); } + } catch (Exception e2) { + // double nef = 0.; + logger.error("error", e2); + } + /* + * try { if (outputToFile) { // update this String name1 = new String(); name1 = fileName + + * "Dew.nc"; file1 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file1.setOutputFileName(name1); file1.setXvalues(points2[2], "temp", "sec"); + * file1.setYvalues(points2[3], "pres", "meter"); file1.createFile(); + * + * String name2 = new String(); name2 = fileName + "Bub.nc"; file2 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file2.setOutputFileName(name2); file2.setXvalues(points2[0], "temp", "sec"); + * file2.setYvalues(points2[1], "pres", "meter"); file2.createFile(); } } catch (Exception e3) + * { // double nef = 0.; logger.error("error", e3); } + */ + } catch (Exception e4) { + // double nef = 0.; + logger.error("error", e4); } - - /** {@inheritDoc} */ - /* - @Override - public void createNetCdfFile(String name) { - fileName = name; + } + + /** + *+ * calcHydrateLine. + *
+ */ + public void calcHydrateLine() { + ThermodynamicOperations opsHyd = new ThermodynamicOperations(system); + try { + opsHyd.hydrateEquilibriumLine(10.0, 300.0); + } catch (Exception e) { + logger.error("error", e); } - */ - /** - * Getter for property bubblePointFirst. - * - * @return Value of property bubblePointFirst. - */ - public boolean isBubblePointFirst() { - return bubblePointFirst; + // double[][] hydData = opsHyd.getData(); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + if (bubblePointFirst) { + // bubble point side + navn[0] = "bubble point 2"; + navn[1] = "dew point 2"; + navn[2] = "dew point 1"; + navn[3] = "bubble point 1"; + } else { + // dew point side and does not crash + navn[0] = "dew point"; + navn[1] = "bubble point"; + navn[2] = "dew point"; + navn[3] = "bubbl point"; } - /** - * Setter for property bubblePointFirst. - * - * @param bubblePointFirst New value of property bubblePointFirst. + double TC = system.getTC(); + double PC = system.getPC(); + + String title = + "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title3 = + "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + + String.valueOf(nf.format(PC)); + String title5 = + "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + + graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); + graph3.setVisible(true); + // graph3.saveFigure(new String(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig4.png")); + + graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); + graph4.setVisible(true); + // graph4.saveFigure(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig2.png"); + + graph2b graph5 = new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); + graph5.setVisible(true); + // graph5.saveFigure(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig3.png"); + + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + graph2.setVisible(true); + // graph2.saveFigure(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig1.png"); + + /* + * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); + * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = + * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); */ - public void setBubblePointFirst(boolean bubblePointFirst) { - this.bubblePointFirst = bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points2; + } + + /** {@inheritDoc} */ + @Override + public void addData(String name, double[][] data) { + double[][] localPoints = new double[points2.length + data.length][]; + navn[localPoints.length / 2 - 1] = name; + System.arraycopy(points2, 0, localPoints, 0, points2.length); + System.arraycopy(data, 0, localPoints, points2.length, data.length); + points2 = localPoints; + } + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + if (name.equals("dewT")) { + return points2[0]; } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; + if (name.equals("dewP")) { + return points2[1]; + } + if (name.equals("bubT")) { + return points2[2]; + } + if (name.equals("bubP")) { + return points2[3]; + } + if (name.equals("dewT2")) { + return points2[4]; + } + if (name.equals("dewP2")) { + return points2[5]; + } + if (name.equals("bubT2")) { + return points2[6]; + } + if (name.equals("bubP2")) { + return points2[7]; + } + if (name.equals("dewH")) { + return pointsH2[2]; + } + if (name.equals("dewDens")) { + return pointsV2[2]; + } + if (name.equals("dewS")) { + return pointsS2[2]; + } + if (name.equals("bubH")) { + return pointsH2[0]; + } + if (name.equals("bubDens")) { + return pointsV2[0]; + } + if (name.equals("bubS")) { + return pointsS2[0]; + } + if (name.equals("cricondentherm")) { + return cricondenTherm; + } + if (name.equals("cricondenbar")) { + return cricondenBar; + } + if (name.equals("criticalPoint1")) { + return new double[] {system.getTC(), system.getPC()}; + } + if (name.equals("criticalPoint2")) { + return new double[] {0, 0}; + } else { + return null; + } + } + + /** + * Getter for property bubblePointFirst. + * + * @return Value of property bubblePointFirst. + */ + public boolean isBubblePointFirst() { + return bubblePointFirst; + } + + /** + * Setter for property bubblePointFirst. + * + * @param bubblePointFirst New value of property bubblePointFirst. + */ + public void setBubblePointFirst(boolean bubblePointFirst) { + this.bubblePointFirst = bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } + + /** + *+ * tempKWilson. + *
+ * + * @param beta a double + * @param P a double + * @return a double + */ + public double tempKWilson(double beta, double P) { + // Initiallizes the temperature of a saturation point for given pressure + // based on K values of Wilson + // see Michelsen book thermodynamics & computational aspects + + double initTc = 0.; + double initPc = 0.; + double initAc = 0.; + double Tstart = 0.; + double Tstartold = 0.; + double initT = 0; + double dinitT = 0; + int numberOfComponents = system.getPhase(0).getNumberOfComponents(); + int lc = 0; + int hc = 0; + + double[] Kwil = new double[numberOfComponents]; + + double min = 100000.; + double max = 0.; + + for (int i = 0; i < numberOfComponents; i++) { + if (system.getPhase(0).getComponents()[i].getTC() > max) { + max = system.getPhase(0).getComponents()[i].getTC(); + hc = i; + } + if (system.getPhase(0).getComponents()[i].getTC() < min) { + min = system.getPhase(0).getComponents()[i].getTC(); + lc = i; + } } - /** - *- * tempKWilson. - *
- * - * @param beta a double - * @param P a double - * @return a double - */ - public double tempKWilson(double beta, double P) { - // Initiallizes the temperature of a saturation point for given pressure - // based on K values of Wilson - // see Michelsen book thermodynamics & computational aspects - - double initTc = 0.; - double initPc = 0.; - double initAc = 0.; - double Tstart = 0.; - double Tstartold = 0.; - double initT = 0; - double dinitT = 0; - int numberOfComponents = system.getPhase(0).getNumberOfComponents(); - int lc = 0; - int hc = 0; - - double[] Kwil = new double[numberOfComponents]; - - double min = 100000.; - double max = 0.; - - for (int i = 0; i < numberOfComponents; i++) { - if (system.getPhase(0).getComponents()[i].getTC() > max) { - max = system.getPhase(0).getComponents()[i].getTC(); - hc = i; - } - if (system.getPhase(0).getComponents()[i].getTC() < min) { - min = system.getPhase(0).getComponents()[i].getTC(); - lc = i; - } - } - - if (beta <= 0.5) { - initTc = system.getPhase(0).getComponents()[lc].getTC(); // closer to bubble point get - // the lightest - // component - initPc = system.getPhase(0).getComponents()[lc].getPC(); - initAc = system.getPhase(0).getComponents()[lc].getAcentricFactor(); - } else if (beta > 0.5) { - initTc = system.getPhase(0).getComponents()[hc].getTC(); // closer to dew point get the - // heaviest component - initPc = system.getPhase(0).getComponents()[hc].getPC(); - initAc = system.getPhase(0).getComponents()[hc].getAcentricFactor(); + if (beta <= 0.5) { + initTc = system.getPhase(0).getComponents()[lc].getTC(); // closer to bubble point get + // the lightest + // component + initPc = system.getPhase(0).getComponents()[lc].getPC(); + initAc = system.getPhase(0).getComponents()[lc].getAcentricFactor(); + } else if (beta > 0.5) { + initTc = system.getPhase(0).getComponents()[hc].getTC(); // closer to dew point get the + // heaviest component + initPc = system.getPhase(0).getComponents()[hc].getPC(); + initAc = system.getPhase(0).getComponents()[hc].getAcentricFactor(); + } + Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); // initial + // T + // based + // on + // the + // lighterst/heaviest + // component + + // solve for Tstart with Newton + for (int i = 0; i < 1000; i++) { + initT = 0.; + dinitT = 0.; + for (int j = 0; j < numberOfComponents; j++) { + Kwil[j] = system.getPhase(0).getComponents()[j].getPC() / P + * Math.exp(5.373 * (1. + system.getPhase(0).getComponents()[j].getAcentricFactor()) + * (1. - system.getPhase(0).getComponents()[j].getTC() / Tstart)); + system.getPhases()[0].getComponents()[j].setK(Math.log(Kwil[j])); + } + + for (int j = 0; j < numberOfComponents; j++) { + if (beta < 0.5) { + initT = initT + system.getPhase(0).getComponents()[j].getz() * Kwil[j]; + dinitT = dinitT + system.getPhase(0).getComponents()[j].getz() * Kwil[j] * 5.373 + * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) + * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); + } else { + initT = initT + system.getPhase(0).getComponents()[j].getz() / Kwil[j]; + dinitT = dinitT - system.getPhase(0).getComponents()[j].getz() / Kwil[j] * 5.373 + * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) + * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); } - Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); // initial - // T - // based - // on - // the - // lighterst/heaviest - // component - - // solve for Tstart with Newton - for (int i = 0; i < 1000; i++) { - initT = 0.; - dinitT = 0.; - for (int j = 0; j < numberOfComponents; j++) { - Kwil[j] = system.getPhase(0).getComponents()[j].getPC() / P - * Math.exp(5.373 - * (1. + system.getPhase(0).getComponents()[j].getAcentricFactor()) - * (1. - system.getPhase(0).getComponents()[j].getTC() / Tstart)); - system.getPhases()[0].getComponents()[j].setK(Math.log(Kwil[j])); - } + } - for (int j = 0; j < numberOfComponents; j++) { - if (beta < 0.5) { - initT = initT + system.getPhase(0).getComponents()[j].getz() * Kwil[j]; - dinitT = dinitT + system.getPhase(0).getComponents()[j].getz() * Kwil[j] * 5.373 - * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) - * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); - } else { - initT = initT + system.getPhase(0).getComponents()[j].getz() / Kwil[j]; - dinitT = dinitT - system.getPhase(0).getComponents()[j].getz() / Kwil[j] * 5.373 - * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) - * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); - } - } - - initT = initT - 1.; - if (Math.abs(initT / dinitT) > 0.1 * Tstart) { - Tstart = Tstart - 0.001 * initT / dinitT; - } else { - Tstart = Tstart - initT / dinitT; - } - - if (Math.abs(Tstart - Tstartold) < 1.e-5) { - return Tstart; - } - Tstartold = Tstart; - } + initT = initT - 1.; + if (Math.abs(initT / dinitT) > 0.1 * Tstart) { + Tstart = Tstart - 0.001 * initT / dinitT; + } else { + Tstart = Tstart - initT / dinitT; + } + if (Math.abs(Tstart - Tstartold) < 1.e-5) { return Tstart; + } + Tstartold = Tstart; } - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" - + String.valueOf(nf.format(PC) + " bara"); - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - return graph2.getChart(); - } + return Tstart; + } + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" + + String.valueOf(nf.format(PC) + " bara"); + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + return graph2.getChart(); + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeNew.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeNew.java index 8bd63f78dc..2e882d5c3f 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeNew.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeNew.java @@ -21,393 +21,374 @@ * @version $Id: $Id */ public class pTphaseEnvelopeNew extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(pTphaseEnvelopeNew.class); - - graph2b graph2 = null; - SystemInterface system; - double[] cricondenTherm = new double[3]; - double[] cricondenBar = new double[3]; - double phaseFraction = 1e-10; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double lowPres = 1.0; - boolean outputToFile = false; - JProgressBar monitor; - JFrame mainFrame; - String fileName = "c:/file"; - JPanel mainPanel; - double temp = 0, pres = 0; - double[][] points = new double[2][]; - double[] pointsH = new double[10000]; - double[][] pointsH2 = new double[4][]; - double[] pointsV = new double[10000]; - - ; - double[][] pointsV2 = new double[4][]; - double[] pointsS = new double[10000]; - double[][] pointsS2 = new double[4][]; - public double[][] points2 = new double[4][]; - int np = 0; - int speceq = 0; - - /** - *- * Constructor for pTphaseEnvelopeNew. - *
- */ - public pTphaseEnvelopeNew() {} - - /** - *- * Constructor for pTphaseEnvelopeNew. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param name a {@link java.lang.String} object - * @param phaseFraction a double - * @param lowPres a double - */ - public pTphaseEnvelopeNew(SystemInterface system, String name, double phaseFraction, - double lowPres) { - this.system = system; - this.phaseFraction = phaseFraction; - - this.lowPres = lowPres; - - if (name != null) { - outputToFile = true; - fileName = name; - } - mainFrame = new JFrame("Progress Bar"); - mainPanel = new JPanel(); - mainPanel.setSize(200, 100); - mainFrame.getContentPane().setLayout(new FlowLayout()); - mainPanel.setLayout(new FlowLayout()); - mainFrame.setSize(200, 100); - monitor = new JProgressBar(0, 00); - monitor.setSize(200, 100); - monitor.setStringPainted(true); - mainPanel.add(monitor); - mainFrame.getContentPane().add(mainPanel); - mainFrame.setVisible(true); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(pTphaseEnvelopeNew.class); + + graph2b graph2 = null; + SystemInterface system; + double[] cricondenTherm = new double[3]; + double[] cricondenBar = new double[3]; + double phaseFraction = 1e-10; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double lowPres = 1.0; + boolean outputToFile = false; + JProgressBar monitor; + JFrame mainFrame; + String fileName = "c:/file"; + JPanel mainPanel; + double temp = 0, pres = 0; + double[][] points = new double[2][]; + double[] pointsH = new double[10000]; + double[][] pointsH2 = new double[4][]; + double[] pointsV = new double[10000]; + + ; + double[][] pointsV2 = new double[4][]; + double[] pointsS = new double[10000]; + double[][] pointsS2 = new double[4][]; + public double[][] points2 = new double[4][]; + int np = 0; + int speceq = 0; + + /** + *+ * Constructor for pTphaseEnvelopeNew. + *
+ */ + public pTphaseEnvelopeNew() {} + + /** + *+ * Constructor for pTphaseEnvelopeNew. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param name a {@link java.lang.String} object + * @param phaseFraction a double + * @param lowPres a double + */ + public pTphaseEnvelopeNew(SystemInterface system, String name, double phaseFraction, + double lowPres) { + this.system = system; + this.phaseFraction = phaseFraction; + + this.lowPres = lowPres; + + if (name != null) { + outputToFile = true; + fileName = name; } - - /** {@inheritDoc} */ - @Override - public void run() { - try { - points[0] = new double[10000]; - points[1] = new double[10000]; - - system.setPressure(lowPres); - - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - - try { - testOps.bubblePointTemperatureFlash(); - } catch (Exception e) { - e.toString(); - return; - } - logger.info("temperature bubT = " + system.getTemperature()); - - sysNewtonRhapsonPhaseEnvelope2 nonLinSolver = - new sysNewtonRhapsonPhaseEnvelope2(system); - nonLinSolver.solve(1); - nonLinSolver.calcInc(1); - - for (np = 1; np < 5; np++) { - if (np % 5 == 0) { - monitor.setValue(np); - monitor.setString("Calculated points: " + np); - } - - nonLinSolver.calcInc(np); - nonLinSolver.solve(np); - - if (system.getTemperature() > cricondenTherm[0]) { - cricondenTherm[1] = system.getPressure(); - cricondenTherm[0] = system.getTemperature(); - } - if (system.getPressure() > cricondenBar[1]) { - cricondenBar[0] = system.getTemperature(); - cricondenBar[1] = system.getPressure(); - } - - if (Double.isNaN(system.getTemperature()) - || Double.isNaN(system.getTemperature())) {// || - // system.getPressure() - // < lowPres) { - points[0][np - 1] = points[0][np - 3]; - points[1][np - 1] = points[1][np - 3]; - pointsH[np - 1] = pointsH[np - 3]; - pointsV[np - 1] = pointsV[np - 3]; - pointsS[np - 1] = pointsS[np - 3]; - - // logger.info("avbryter" + np); - break; - } - // logger.info("Ideal pres: " + getPressure()); - // logger.info("temp: " + system.getTemperature()); - points[0][np - 1] = system.getTemperature(); - points[1][np - 1] = system.getPressure(); - pointsH[np - 1] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV[np - 1] = system.getPhase(1).getDensity(); - pointsS[np - 1] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - } - - int ncr = nonLinSolver.getNpCrit(); - int ncr2 = np - ncr; - - logger.info("ncr: " + ncr + " ncr2 . " + ncr2); - points2[0] = new double[ncr + 1]; - points2[1] = new double[ncr + 1]; - pointsH2[0] = new double[ncr + 1]; - pointsH2[1] = new double[ncr + 1]; - pointsS2[0] = new double[ncr + 1]; - pointsS2[1] = new double[ncr + 1]; - pointsV2[0] = new double[ncr + 1]; - pointsV2[1] = new double[ncr + 1]; - if (ncr2 > 2) { - points2[2] = new double[ncr2 - 2]; - points2[3] = new double[ncr2 - 2]; - pointsH2[2] = new double[ncr2 - 2]; - pointsH2[3] = new double[ncr2 - 2]; - pointsV2[2] = new double[ncr2 - 2]; - pointsV2[3] = new double[ncr2 - 2]; - pointsS2[2] = new double[ncr2 - 2]; - pointsS2[3] = new double[ncr2 - 2]; - } else { - points2[2] = new double[0]; - points2[3] = new double[0]; - pointsH2[2] = new double[0]; - pointsH2[3] = new double[0]; - pointsV2[2] = new double[0]; - pointsV2[3] = new double[0]; - pointsS2[2] = new double[0]; - pointsS2[3] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - points2[0][i] = points[0][i]; - points2[1][i] = points[1][i]; - - pointsH2[1][i] = points[1][i]; - pointsH2[0][i] = pointsH[i]; - - pointsS2[1][i] = points[1][i]; - pointsS2[0][i] = pointsS[i]; - - pointsV2[1][i] = points[1][i]; - pointsV2[0][i] = pointsV[i]; - } - - system.setTemperature(system.getTC() + 0.001); - system.setPressure(system.getPC() + 0.001); - system.init(3); - - points2[0][ncr] = system.getTC(); - points2[1][ncr] = system.getPC(); - - pointsH2[1][ncr] = system.getPC(); - pointsH2[0][ncr] = - system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - - pointsS2[1][ncr] = system.getPC(); - pointsS2[0][ncr] = - system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - - pointsV2[1][ncr] = system.getPC(); - pointsV2[0][ncr] = system.getPhase(1).getDensity(); - - if (ncr2 > 2) { - points2[2][0] = system.getTC(); - points2[3][0] = system.getPC(); - pointsH2[3][0] = system.getPC(); - pointsH2[2][0] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsS2[3][0] = system.getPC(); - pointsS2[2][0] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV2[3][0] = system.getPC(); - pointsV2[2][0] = system.getPhase(1).getDensity(); - - for (int i = 1; i < (ncr2 - 2); i++) { - points2[2][i] = points[0][i + ncr - 1]; - points2[3][i] = points[1][i + ncr - 1]; - - pointsH2[3][i] = points[1][i + ncr - 1]; - pointsH2[2][i] = pointsH[i + ncr - 1]; - - pointsS2[3][i] = points[1][i + ncr - 1]; - pointsS2[2][i] = pointsS[i + ncr - 1]; - - pointsV2[3][i] = points[1][i + ncr - 1]; - pointsV2[2][i] = pointsV[i + ncr - 1]; - } - } - // monitor.close(); - mainFrame.setVisible(false); -/* - if (outputToFile) { - String name1 = new String(); - name1 = fileName + "Dew.nc"; - file1 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file1.setOutputFileName(name1); - file1.setXvalues(points2[2], "temp", "sec"); - file1.setYvalues(points2[3], "pres", "meter"); - file1.createFile(); - - String name2 = new String(); - name2 = fileName + "Bub.nc"; - file2 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file2.setOutputFileName(name2); - file2.setXvalues(points2[0], "temp", "sec"); - file2.setYvalues(points2[1], "pres", "meter"); - file2.createFile(); - } - */ - } catch (Exception e) { - logger.error("error", e); + mainFrame = new JFrame("Progress Bar"); + mainPanel = new JPanel(); + mainPanel.setSize(200, 100); + mainFrame.getContentPane().setLayout(new FlowLayout()); + mainPanel.setLayout(new FlowLayout()); + mainFrame.setSize(200, 100); + monitor = new JProgressBar(0, 00); + monitor.setSize(200, 100); + monitor.setStringPainted(true); + mainPanel.add(monitor); + mainFrame.getContentPane().add(mainPanel); + mainFrame.setVisible(true); + } + + /** {@inheritDoc} */ + @Override + public void run() { + try { + points[0] = new double[10000]; + points[1] = new double[10000]; + + system.setPressure(lowPres); + + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + + try { + testOps.bubblePointTemperatureFlash(); + } catch (Exception e) { + e.toString(); + return; + } + logger.info("temperature bubT = " + system.getTemperature()); + + sysNewtonRhapsonPhaseEnvelope2 nonLinSolver = new sysNewtonRhapsonPhaseEnvelope2(system); + nonLinSolver.solve(1); + nonLinSolver.calcInc(1); + + for (np = 1; np < 5; np++) { + if (np % 5 == 0) { + monitor.setValue(np); + monitor.setString("Calculated points: " + np); } - } - /** {@inheritDoc} */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title3 = "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title5 = "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - - // logger.info("start flash"); - // logger.info("Tferdig.."); - - graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); - graph3.setVisible(true); - graph3.saveFigure((neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig4.png")); - - graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); - graph4.setVisible(true); - graph4.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig2.png"); - - graph2b graph5 = - new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); - graph5.setVisible(true); - graph5.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig3.png"); - - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - graph2.setVisible(true); - graph2.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig1.png"); - - /* - * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); - * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = - * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); - */ - } + nonLinSolver.calcInc(np); + nonLinSolver.solve(np); - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} - - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" - + String.valueOf(nf.format(PC) + " bara"); - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - return graph2.getChart(); - } - - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points2; - } - - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - if (name.equals("bubT")) { - return points2[0]; - } - if (name.equals("bubP")) { - return points2[1]; - } - if (name.equals("dewT")) { - return points2[2]; - } - if (name.equals("dewP")) { - return points2[3]; - } - if (name.equals("dewH")) { - return pointsH2[2]; - } - if (name.equals("dewDens")) { - return pointsV2[2]; + if (system.getTemperature() > cricondenTherm[0]) { + cricondenTherm[1] = system.getPressure(); + cricondenTherm[0] = system.getTemperature(); } - if (name.equals("dewS")) { - return pointsS2[2]; + if (system.getPressure() > cricondenBar[1]) { + cricondenBar[0] = system.getTemperature(); + cricondenBar[1] = system.getPressure(); } - if (name.equals("bubH")) { - return pointsH2[0]; - } - if (name.equals("bubDens")) { - return pointsV2[0]; - } - if (name.equals("bubS")) { - return pointsS2[0]; - } - if (name.equals("cricondentherm")) { - return cricondenTherm; + + if (Double.isNaN(system.getTemperature()) || Double.isNaN(system.getTemperature())) {// || + // system.getPressure() + // < + // lowPres) + // { + points[0][np - 1] = points[0][np - 3]; + points[1][np - 1] = points[1][np - 3]; + pointsH[np - 1] = pointsH[np - 3]; + pointsV[np - 1] = pointsV[np - 3]; + pointsS[np - 1] = pointsS[np - 3]; + + // logger.info("avbryter" + np); + break; } - if (name.equals("cricondenbar")) { - return cricondenBar; - } else { - return null; + // logger.info("Ideal pres: " + getPressure()); + // logger.info("temp: " + system.getTemperature()); + points[0][np - 1] = system.getTemperature(); + points[1][np - 1] = system.getPressure(); + pointsH[np - 1] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV[np - 1] = system.getPhase(1).getDensity(); + pointsS[np - 1] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + } + + int ncr = nonLinSolver.getNpCrit(); + int ncr2 = np - ncr; + + logger.info("ncr: " + ncr + " ncr2 . " + ncr2); + points2[0] = new double[ncr + 1]; + points2[1] = new double[ncr + 1]; + pointsH2[0] = new double[ncr + 1]; + pointsH2[1] = new double[ncr + 1]; + pointsS2[0] = new double[ncr + 1]; + pointsS2[1] = new double[ncr + 1]; + pointsV2[0] = new double[ncr + 1]; + pointsV2[1] = new double[ncr + 1]; + if (ncr2 > 2) { + points2[2] = new double[ncr2 - 2]; + points2[3] = new double[ncr2 - 2]; + pointsH2[2] = new double[ncr2 - 2]; + pointsH2[3] = new double[ncr2 - 2]; + pointsV2[2] = new double[ncr2 - 2]; + pointsV2[3] = new double[ncr2 - 2]; + pointsS2[2] = new double[ncr2 - 2]; + pointsS2[3] = new double[ncr2 - 2]; + } else { + points2[2] = new double[0]; + points2[3] = new double[0]; + pointsH2[2] = new double[0]; + pointsH2[3] = new double[0]; + pointsV2[2] = new double[0]; + pointsV2[3] = new double[0]; + pointsS2[2] = new double[0]; + pointsS2[3] = new double[0]; + } + + for (int i = 0; i < ncr; i++) { + points2[0][i] = points[0][i]; + points2[1][i] = points[1][i]; + + pointsH2[1][i] = points[1][i]; + pointsH2[0][i] = pointsH[i]; + + pointsS2[1][i] = points[1][i]; + pointsS2[0][i] = pointsS[i]; + + pointsV2[1][i] = points[1][i]; + pointsV2[0][i] = pointsV[i]; + } + + system.setTemperature(system.getTC() + 0.001); + system.setPressure(system.getPC() + 0.001); + system.init(3); + + points2[0][ncr] = system.getTC(); + points2[1][ncr] = system.getPC(); + + pointsH2[1][ncr] = system.getPC(); + pointsH2[0][ncr] = system.getPhase(1).getEnthalpy() + / system.getPhase(1).getNumberOfMolesInPhase() / system.getPhase(1).getMolarMass() / 1e3; + + pointsS2[1][ncr] = system.getPC(); + pointsS2[0][ncr] = system.getPhase(1).getEntropy() + / system.getPhase(1).getNumberOfMolesInPhase() / system.getPhase(1).getMolarMass() / 1e3; + + pointsV2[1][ncr] = system.getPC(); + pointsV2[0][ncr] = system.getPhase(1).getDensity(); + + if (ncr2 > 2) { + points2[2][0] = system.getTC(); + points2[3][0] = system.getPC(); + pointsH2[3][0] = system.getPC(); + pointsH2[2][0] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsS2[3][0] = system.getPC(); + pointsS2[2][0] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV2[3][0] = system.getPC(); + pointsV2[2][0] = system.getPhase(1).getDensity(); + + for (int i = 1; i < (ncr2 - 2); i++) { + points2[2][i] = points[0][i + ncr - 1]; + points2[3][i] = points[1][i + ncr - 1]; + + pointsH2[3][i] = points[1][i + ncr - 1]; + pointsH2[2][i] = pointsH[i + ncr - 1]; + + pointsS2[3][i] = points[1][i + ncr - 1]; + pointsS2[2][i] = pointsS[i + ncr - 1]; + + pointsV2[3][i] = points[1][i + ncr - 1]; + pointsV2[2][i] = pointsV[i + ncr - 1]; } + } + // monitor.close(); + mainFrame.setVisible(false); + /* + * if (outputToFile) { String name1 = new String(); name1 = fileName + "Dew.nc"; file1 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file1.setOutputFileName(name1); file1.setXvalues(points2[2], "temp", "sec"); + * file1.setYvalues(points2[3], "pres", "meter"); file1.createFile(); + * + * String name2 = new String(); name2 = fileName + "Bub.nc"; file2 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file2.setOutputFileName(name2); file2.setXvalues(points2[0], "temp", "sec"); + * file2.setYvalues(points2[1], "pres", "meter"); file2.createFile(); } + */ + } catch (Exception e) { + logger.error("error", e); } + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = + "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title3 = + "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + + String.valueOf(nf.format(PC)); + String title5 = + "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + + // logger.info("start flash"); + // logger.info("Tferdig.."); + + graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); + graph3.setVisible(true); + graph3.saveFigure((neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig4.png")); + + graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); + graph4.setVisible(true); + graph4.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig2.png"); + + graph2b graph5 = new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); + graph5.setVisible(true); + graph5.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig3.png"); + + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + graph2.setVisible(true); + graph2.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig1.png"); - /** {@inheritDoc} */ /* - @Override - public void createNetCdfFile(String name) { - fileName = name; + * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); + * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = + * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); + */ + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" + + String.valueOf(nf.format(PC) + " bara"); + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + return graph2.getChart(); + } + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points2; + } + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + if (name.equals("bubT")) { + return points2[0]; } - */ - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; + if (name.equals("bubP")) { + return points2[1]; + } + if (name.equals("dewT")) { + return points2[2]; + } + if (name.equals("dewP")) { + return points2[3]; + } + if (name.equals("dewH")) { + return pointsH2[2]; } + if (name.equals("dewDens")) { + return pointsV2[2]; + } + if (name.equals("dewS")) { + return pointsS2[2]; + } + if (name.equals("bubH")) { + return pointsH2[0]; + } + if (name.equals("bubDens")) { + return pointsV2[0]; + } + if (name.equals("bubS")) { + return pointsS2[0]; + } + if (name.equals("cricondentherm")) { + return cricondenTherm; + } + if (name.equals("cricondenbar")) { + return cricondenBar; + } else { + return null; + } + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve2.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve2.java index 5990112903..aa2372274b 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve2.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve2.java @@ -21,182 +21,173 @@ * @version $Id: $Id */ public class pLoadingCurve2 extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(pLoadingCurve2.class); - - SystemInterface system; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold, deviation = 0, g0 = 0, g1 = 0; - double lnOldOldK[], lnK[]; - double lnOldK[]; - double oldDeltalnK[], deltalnK[]; - double tm[] = {1, 1}; - double beta = 1e-5; - int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase - JProgressBar monitor; - JFrame mainFrame; - JPanel mainPanel; - - double temp = 0, pres = 0, startPres = 0; - double[][] points = new double[35][]; - - boolean moreLines = false; - int np = 0; - // points[2] = new double[1000]; - int speceq = 0; - - /** - *- * Constructor for pLoadingCurve2. - *
- */ - public pLoadingCurve2() {} - - /** - *- * Constructor for pLoadingCurve2. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public pLoadingCurve2(SystemInterface system) { - this.system = system; - lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnK = new double[system.getPhases()[0].getNumberOfComponents()]; - oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - mainFrame = new JFrame("Progress Bar"); - mainPanel = new JPanel(); - mainPanel.setSize(200, 100); - mainFrame.getContentPane().setLayout(new FlowLayout()); - mainPanel.setLayout(new FlowLayout()); - mainFrame.setSize(200, 100); - monitor = new JProgressBar(0, 1000); - monitor.setSize(200, 100); - monitor.setStringPainted(true); - mainPanel.add(monitor); - mainFrame.getContentPane().add(mainPanel); - mainFrame.setVisible(true); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(pLoadingCurve2.class); + + SystemInterface system; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold, deviation = 0, g0 = 0, g1 = 0; + double lnOldOldK[], lnK[]; + double lnOldK[]; + double oldDeltalnK[], deltalnK[]; + double tm[] = {1, 1}; + double beta = 1e-5; + int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase + JProgressBar monitor; + JFrame mainFrame; + JPanel mainPanel; + + double temp = 0, pres = 0, startPres = 0; + double[][] points = new double[35][]; + + boolean moreLines = false; + int np = 0; + // points[2] = new double[1000]; + int speceq = 0; + + /** + *+ * Constructor for pLoadingCurve2. + *
+ */ + public pLoadingCurve2() {} + + /** + *+ * Constructor for pLoadingCurve2. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public pLoadingCurve2(SystemInterface system) { + this.system = system; + lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnK = new double[system.getPhases()[0].getNumberOfComponents()]; + oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + mainFrame = new JFrame("Progress Bar"); + mainPanel = new JPanel(); + mainPanel.setSize(200, 100); + mainFrame.getContentPane().setLayout(new FlowLayout()); + mainPanel.setLayout(new FlowLayout()); + mainFrame.setSize(200, 100); + monitor = new JProgressBar(0, 1000); + monitor.setSize(200, 100); + monitor.setStringPainted(true); + mainPanel.add(monitor); + mainFrame.getContentPane().add(mainPanel); + mainFrame.setVisible(true); + } + + /** {@inheritDoc} */ + @Override + public void run() { + int numbPoints = 50; + double inscr = 0.2103842275; + points[0] = new double[numbPoints]; + points[1] = new double[numbPoints]; + points[2] = new double[numbPoints]; + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + + for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { + points[k + 3] = new double[numbPoints]; + points[k + 3 + system.getPhases()[1].getNumberOfComponents()] = new double[numbPoints]; } - /** {@inheritDoc} */ - @Override - public void run() { - int numbPoints = 50; - double inscr = 0.2103842275; - points[0] = new double[numbPoints]; - points[1] = new double[numbPoints]; - points[2] = new double[numbPoints]; - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - - for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { - points[k + 3] = new double[numbPoints]; - points[k + 3 + system.getPhases()[1].getNumberOfComponents()] = new double[numbPoints]; - } - - double molMDEA = system.getPhases()[1].getComponents()[2].getNumberOfMolesInPhase(); - system.getChemicalReactionOperations().solveChemEq(1); - - for (int i = 1; i < points[0].length; i++) { - system.initBeta(); - system.init_x_y(); - try { - testOps.bubblePointPressureFlash(false); - } catch (Exception e) { - logger.info(e.toString()); - } - logger.info("beta " + system.getBeta()); - points[0][i] = (inscr * (i - 1)) / molMDEA; - points[1][i] = (system.getPressure()); - points[2][i] = (system.getPressure() * system.getPhase(0).getComponent(0).getx()); - - for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { - points[k + 3][i] = system.getPhases()[1].getComponents()[k].getx(); - points[k + 3 + system.getPhases()[1].getNumberOfComponents()][i] = - system.getPhase(1).getActivityCoefficient(k, 1);// ,1); - } - logger.info("point: " + points[0][i] + " tot pres " + points[1][i] + " CO2 pres " - + points[2][i]); - system.setPressure(points[1][i]); - logger.info("ph: " + system.getPhases()[1].getpH()); - system.addComponent("CO2", inscr); - } - mainFrame.setVisible(false); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"CO2 fugacity", "", "", ""}; - String title = "CO2 vapour pressure"; - - graph2b graph2 = new graph2b(points, navn, title, "loading [-]", "Fugacity CO2 [bar]"); - graph2.setVisible(true); - } - - /** {@inheritDoc} */ - @Override - public void printToFile(String name) { - neqsim.dataPresentation.dataHandeling printDat = - new neqsim.dataPresentation.dataHandeling(); - printDat.printToFile(points, name); - } - - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points; - } - - /** {@inheritDoc} */ - /* - @Override - public void createNetCdfFile(String name) { - NetCdf2D file = new NetCdf2D(); - file.setOutputFileName(name); - file.setXvalues(points[0], "loading", ""); - file.setYvalues(points[1], "total pressure", ""); - file.setYvalues(points[2], " CO2 pressure", ""); - for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { - file.setYvalues(points[k + 3], - "mol frac " + system.getPhases()[1].getComponents()[k].getComponentName(), ""); - file.setYvalues(points[k + 3 + system.getPhases()[1].getNumberOfComponents()], - ("activity " + system.getPhases()[1].getComponents()[k].getComponentName()), - ""); - } - file.createFile(); - } -*/ - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - return null; - } - - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; - } - - /** {@inheritDoc} */ - @Override - public SystemInterface getThermoSystem() { - return system; + double molMDEA = system.getPhases()[1].getComponents()[2].getNumberOfMolesInPhase(); + system.getChemicalReactionOperations().solveChemEq(1); + + for (int i = 1; i < points[0].length; i++) { + system.initBeta(); + system.init_x_y(); + try { + testOps.bubblePointPressureFlash(false); + } catch (Exception e) { + logger.info(e.toString()); + } + logger.info("beta " + system.getBeta()); + points[0][i] = (inscr * (i - 1)) / molMDEA; + points[1][i] = (system.getPressure()); + points[2][i] = (system.getPressure() * system.getPhase(0).getComponent(0).getx()); + + for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { + points[k + 3][i] = system.getPhases()[1].getComponents()[k].getx(); + points[k + 3 + system.getPhases()[1].getNumberOfComponents()][i] = + system.getPhase(1).getActivityCoefficient(k, 1);// ,1); + } + logger.info( + "point: " + points[0][i] + " tot pres " + points[1][i] + " CO2 pres " + points[2][i]); + system.setPressure(points[1][i]); + logger.info("ph: " + system.getPhases()[1].getpH()); + system.addComponent("CO2", inscr); } + mainFrame.setVisible(false); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"CO2 fugacity", "", "", ""}; + String title = "CO2 vapour pressure"; + + graph2b graph2 = new graph2b(points, navn, title, "loading [-]", "Fugacity CO2 [bar]"); + graph2.setVisible(true); + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) { + neqsim.dataPresentation.dataHandeling printDat = new neqsim.dataPresentation.dataHandeling(); + printDat.printToFile(points, name); + } + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points; + } + + /* + * public void createNetCdfFile(String name) { NetCdf2D file = new NetCdf2D(); + * file.setOutputFileName(name); file.setXvalues(points[0], "loading", ""); + * file.setYvalues(points[1], "total pressure", ""); file.setYvalues(points[2], " CO2 pressure", + * ""); for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { + * file.setYvalues(points[k + 3], "mol frac " + + * system.getPhases()[1].getComponents()[k].getComponentName(), ""); file.setYvalues(points[k + 3 + * + system.getPhases()[1].getNumberOfComponents()], ("activity " + + * system.getPhases()[1].getComponents()[k].getComponentName()), ""); } file.createFile(); } + */ + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + return null; + } + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } + + /** {@inheritDoc} */ + @Override + public SystemInterface getThermoSystem() { + return system; + } } diff --git a/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java b/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java index 3fff720421..c5750fb974 100644 --- a/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java +++ b/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java @@ -72,7 +72,7 @@ void testSolveSteadyStateConstantFrictionFactor() { pipe.getNode(i).setWallFrictionFactor(0, 0.00725); } pipe.solveSteadyState(10); - //System.out.println("pressure out set friction " + // System.out.println("pressure out set friction " } @Test @@ -80,12 +80,12 @@ void testSolveSteadyState() { testInit(); pipe.solveSteadyState(10); for (int i = 0; i < pipe.getFlowNodes().length; i++) { - //System.out.println("wall friction " + pipe.getNode(i).getWallFrictionFactor(0)); + // System.out.println("wall friction " + pipe.getNode(i).getWallFrictionFactor(0)); } - // System.out.println("pressure out calc friction " - // + pipe.getNode(pipe.getFlowNodes().length - 1).getBulkSystem().getPressure() + " bara"); - + // System.out.println("pressure out calc friction " + // + pipe.getNode(pipe.getFlowNodes().length - 1).getBulkSystem().getPressure() + " bara"); + // pipe.print(); } @@ -126,7 +126,6 @@ void testSolveTransient() { // pipe.getDisplay().displayResult("composition"); // pipe.getDisplay().displayResult("pressure"); // pipe.getDisplay().displayResult("composition"); - // pipe.getDisplay().createNetCdfFile("c:/temp5.nc"); // pipe.getDisplay(1).displayResult(); } } diff --git a/src/test/java/neqsim/thermo/util/example/PressureLoadingCurve.java b/src/test/java/neqsim/thermo/util/example/PressureLoadingCurve.java index 9488fab173..f59e5e74c5 100644 --- a/src/test/java/neqsim/thermo/util/example/PressureLoadingCurve.java +++ b/src/test/java/neqsim/thermo/util/example/PressureLoadingCurve.java @@ -7,68 +7,68 @@ import neqsim.thermodynamicOperations.ThermodynamicOperations; /** - *PressureLoadingCurve class.
+ *+ * PressureLoadingCurve class. + *
* * @author asmund * @version $Id: $Id * @since 2.2.3 */ public class PressureLoadingCurve { - static Logger logger = LogManager.getLogger(PressureLoadingCurve.class); + static Logger logger = LogManager.getLogger(PressureLoadingCurve.class); - /** - * This method is just meant to test the thermo package. - * - * @param args an array of {@link java.lang.String} objects - */ - @SuppressWarnings("unused") - public static void main(String args[]) { - double[][] points; - SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 75.0), 1.3); + /** + * This method is just meant to test the thermo package. + * + * @param args an array of {@link java.lang.String} objects + */ + @SuppressWarnings("unused") + public static void main(String args[]) { + double[][] points; + SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 75.0), 1.3); - double loading = 0.65; - double molProsMDEA = 11.21; - testSystem.addComponent("CO2", loading * molProsMDEA); - testSystem.addComponent("water", 100.0 - molProsMDEA - loading * molProsMDEA); - testSystem.addComponent("MDEA", molProsMDEA); - // testSystem.addComponent("Piperazine", loading*molProsMDEA*0.1); - testSystem.chemicalReactionInit(); - testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.init(0); - ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); - // testOps.calcPloadingCurve(); - long time = System.currentTimeMillis(); + double loading = 0.65; + double molProsMDEA = 11.21; + testSystem.addComponent("CO2", loading * molProsMDEA); + testSystem.addComponent("water", 100.0 - molProsMDEA - loading * molProsMDEA); + testSystem.addComponent("MDEA", molProsMDEA); + // testSystem.addComponent("Piperazine", loading*molProsMDEA*0.1); + testSystem.chemicalReactionInit(); + testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.init(0); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + // testOps.calcPloadingCurve(); + long time = System.currentTimeMillis(); - try { - testOps.bubblePointPressureFlash(true); - } catch (Exception e) { - logger.error(e.toString()); - } - logger.info("Time taken for benchmark flash = " + (System.currentTimeMillis() - time)); - testSystem.display(); - logger.info("pressure " + testSystem.getPressure()); - int reactionNumber = 0; - logger.info("K " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcK(testSystem, 1)); - logger.info("Kx " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcKx(testSystem, 1)); - logger.info("Kgamma " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcKgamma(testSystem, 1)); - testSystem.setPressure(100.0); - testSystem.getChemicalReactionOperations().solveChemEq(1); - logger.info("K " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcK(testSystem, 1)); - logger.info("Kx " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcKx(testSystem, 1)); - logger.info("Kgamma " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcKgamma(testSystem, 1)); - - testSystem.display(); - // thermo.ThermodynamicModelTest testModel = new - // thermo.ThermodynamicModelTest(testSystem); - // testModel.runTest(); - // write data to netcdf - // testOps.writeNetCDF("c:/testloading.nc"); + try { + testOps.bubblePointPressureFlash(true); + } catch (Exception e) { + logger.error(e.toString()); } + logger.info("Time taken for benchmark flash = " + (System.currentTimeMillis() - time)); + testSystem.display(); + logger.info("pressure " + testSystem.getPressure()); + int reactionNumber = 0; + logger.info("K " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcK(testSystem, 1)); + logger.info("Kx " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcKx(testSystem, 1)); + logger.info("Kgamma " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcKgamma(testSystem, 1)); + testSystem.setPressure(100.0); + testSystem.getChemicalReactionOperations().solveChemEq(1); + logger.info("K " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcK(testSystem, 1)); + logger.info("Kx " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcKx(testSystem, 1)); + logger.info("Kgamma " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcKgamma(testSystem, 1)); + + testSystem.display(); + // thermo.ThermodynamicModelTest testModel = new + // thermo.ThermodynamicModelTest(testSystem); + // testModel.runTest(); + } } From 55adc69b57dab3082e64a20316c48ba90bd55f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Thu, 21 Jul 2022 20:55:28 +0200 Subject: [PATCH 2/9] refact: auto format and auto fix snyk (#488) --- .../processEquipment/util/Recycle.java | 862 +++++++++--------- .../util/RecycleController.java | 399 ++++---- 2 files changed, 636 insertions(+), 625 deletions(-) diff --git a/src/main/java/neqsim/processSimulation/processEquipment/util/Recycle.java b/src/main/java/neqsim/processSimulation/processEquipment/util/Recycle.java index 9152150e1d..640b05084c 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/util/Recycle.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/util/Recycle.java @@ -1,7 +1,6 @@ package neqsim.processSimulation.processEquipment.util; import java.util.ArrayList; - import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass; import neqsim.processSimulation.processEquipment.mixer.MixerInterface; import neqsim.processSimulation.processEquipment.stream.Stream; @@ -18,451 +17,452 @@ * @version $Id: $Id */ public class Recycle extends ProcessEquipmentBaseClass implements MixerInterface { - private static final long serialVersionUID = 1000; - - protected ArrayList- * Constructor for Recycle. - *
- */ - @Deprecated - public Recycle() { - this("Recycle"); - } - - /** - *- * Constructor for Recycle. - *
- * - * @param name a {@link java.lang.String} object - */ - public Recycle(String name) { - super(name); - } - - /** {@inheritDoc} */ - @Override - public SystemInterface getThermoSystem() { - return mixedStream.getThermoSystem(); - } - - /** - *
- * Setter for the field downstreamProperty
.
- *
+ * Constructor for Recycle. + *
+ */ + @Deprecated + public Recycle() { + this("Recycle"); + } + + /** + *+ * Constructor for Recycle. + *
+ * + * @param name a {@link java.lang.String} object + */ + public Recycle(String name) { + super(name); + } + + /** {@inheritDoc} */ + @Override + public SystemInterface getThermoSystem() { + return mixedStream.getThermoSystem(); + } + + /** + *
+ * Setter for the field downstreamProperty
.
+ *
+ * getStream. + *
+ * + * @param i a int + * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + public StreamInterface getStream(int i) { + return streams.get(i); + } + + /** + *+ * mixStream. + *
+ */ + public void mixStream() { + int index = 0; + // String compName = new String(); + + for (int k = 1; k < streams.size(); k++) { + for (int i = 0; i < streams.get(k).getThermoSystem().getPhase(0) + .getNumberOfComponents(); i++) { + boolean gotComponent = false; + String componentName = + streams.get(k).getThermoSystem().getPhase(0).getComponent(i).getName(); + // System.out.println("adding: " + componentName); + // int numberOfPhases = streams.get(k).getThermoSystem().getNumberOfPhases(); + + double moles = + streams.get(k).getThermoSystem().getPhase(0).getComponent(i).getNumberOfmoles(); + // System.out.println("moles: " + moles + " " + + // mixedStream.getThermoSystem().getPhase(0).getNumberOfComponents()); + for (int p = 0; p < mixedStream.getThermoSystem().getPhase(0) + .getNumberOfComponents(); p++) { + if (mixedStream.getThermoSystem().getPhase(0).getComponent(p).getName() + .equals(componentName)) { + gotComponent = true; + index = + streams.get(0).getThermoSystem().getPhase(0).getComponent(p).getComponentNumber(); + // compName = streams.get(0).getThermoSystem().getPhase(0).getComponent(p) + // .getComponentName(); + } } - mixedStream.setEmptyThermoSystem(streams.get(0).getThermoSystem()); - numberOfInputStreams++; - lastIterationStream = mixedStream.clone(); - } - /** - *- * getStream. - *
- * - * @param i a int - * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object - */ - public StreamInterface getStream(int i) { - return streams.get(i); - } - - /** - *- * mixStream. - *
- */ - public void mixStream() { - int index = 0; - // String compName = new String(); - - for (int k = 1; k < streams.size(); k++) { - for (int i = 0; i < streams.get(k).getThermoSystem().getPhase(0) - .getNumberOfComponents(); i++) { - boolean gotComponent = false; - String componentName = - streams.get(k).getThermoSystem().getPhase(0).getComponent(i).getName(); - // System.out.println("adding: " + componentName); - // int numberOfPhases = streams.get(k).getThermoSystem().getNumberOfPhases(); - - double moles = streams.get(k).getThermoSystem().getPhase(0).getComponent(i) - .getNumberOfmoles(); - // System.out.println("moles: " + moles + " " + - // mixedStream.getThermoSystem().getPhase(0).getNumberOfComponents()); - for (int p = 0; p < mixedStream.getThermoSystem().getPhase(0) - .getNumberOfComponents(); p++) { - if (mixedStream.getThermoSystem().getPhase(0).getComponent(p).getName() - .equals(componentName)) { - gotComponent = true; - index = streams.get(0).getThermoSystem().getPhase(0).getComponent(p) - .getComponentNumber(); - // compName = streams.get(0).getThermoSystem().getPhase(0).getComponent(p) - // .getComponentName(); - } - } - - if (gotComponent) { - // System.out.println("adding moles starting...."); - mixedStream.getThermoSystem().addComponent(index, moles); - // mixedStream.getThermoSystem().init_x_y(); - // System.out.println("adding moles finished"); - } else { - System.out.println("ikke gaa hit"); - mixedStream.getThermoSystem().addComponent(index, moles); - } - } - } - // mixedStream.getThermoSystem().init_x_y(); - // mixedStream.getThermoSystem().initBeta(); - // mixedStream.getThermoSystem().init(2); - } - - /** - *- * guessTemperature. - *
- * - * @return a double - */ - public double guessTemperature() { - double gtemp = 0; - for (int k = 0; k < streams.size(); k++) { - gtemp += streams.get(k).getThermoSystem().getTemperature() - * streams.get(k).getThermoSystem().getNumberOfMoles() - / mixedStream.getThermoSystem().getNumberOfMoles(); - } - return gtemp; - } - - /** - *- * calcMixStreamEnthalpy. - *
- * - * @return a double - */ - public double calcMixStreamEnthalpy() { - double enthalpy = 0; - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); - // System.out.println("total enthalpy k : " + ( ((Stream) - // streams.get(k)).getThermoSystem()).getEnthalpy()); - } - // System.out.println("total enthalpy of streams: " + enthalpy); - return enthalpy; - } - - /** {@inheritDoc} */ - @Deprecated - public StreamInterface getOutStream() { - return mixedStream; - } - - /** - *- * initiateDownstreamProperties. - *
- * - * @param outstream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public void initiateDownstreamProperties(StreamInterface outstream) { - lastIterationStream = outstream.clone(); - } - - /** - *- * setDownstreamProperties. - *
- */ - public void setDownstreamProperties() { - if (downstreamProperty.size() > 0) { - for (int i = 0; i < downstreamProperty.size(); i++) { - if (downstreamProperty.get(i).equals("flow rate")) - mixedStream.setFlowRate(outletStream.getFlowRate("kg/hr"), "kg/hr"); - } - } - } - - /** {@inheritDoc} */ - @Override - public void run() { - iterations++; - /* - * if(firstTime || iterations>maxIterations) { firstTime=false; return; - * - * } - */ - double enthalpy = 0.0; - // System.out.println("flow rate old in recycle " + - // outletStream.getFlowRate("kg/hr")); - // ((Stream) streams.get(0)).getThermoSystem().display(); - SystemInterface thermoSystem2 = streams.get(0).getThermoSystem().clone(); - // System.out.println("total number of moles " + - // thermoSystem2.getTotalNumberOfMoles()); - mixedStream.setThermoSystem(thermoSystem2); - ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem2); - if (streams.size() > 1) { - mixedStream.getThermoSystem().setNumberOfPhases(2); - mixedStream.getThermoSystem().reInitPhaseType(); - mixedStream.getThermoSystem().init(0); - - mixStream(); - - setDownstreamProperties(); - try { - enthalpy = calcMixStreamEnthalpy(); - } catch (Exception e) { - // String error = e.getMessage(); - return; - } - // System.out.println("temp guess " + guessTemperature()); - mixedStream.getThermoSystem().setTemperature(guessTemperature()); - testOps.PHflash(enthalpy, 0); - // System.out.println("filan temp " + mixedStream.getTemperature()); + if (gotComponent) { + // System.out.println("adding moles starting...."); + mixedStream.getThermoSystem().addComponent(index, moles); + // mixedStream.getThermoSystem().init_x_y(); + // System.out.println("adding moles finished"); } else { - setDownstreamProperties(); - testOps.TPflash(); + System.out.println("ikke gaa hit"); + mixedStream.getThermoSystem().addComponent(index, moles); } - setError(massBalanceCheck()); - System.out.println(name + " recycle error: " + getError()); - lastIterationStream = (Stream) mixedStream.clone(); - outletStream.setThermoSystem(mixedStream.getThermoSystem()); - // System.out.println("flow rate new in recycle " + - // outletStream.getFlowRate("kg/hr")); - - // System.out.println("enthalpy: " + - // mixedStream.getThermoSystem().getEnthalpy()); - // System.out.println("enthalpy: " + enthalpy); - // System.out.println("temperature: " + - // mixedStream.getThermoSystem().getTemperature()); - - // System.out.println("beta " + mixedStream.getThermoSystem().getBeta()); - // outStream.setThermoSystem(mixedStream.getThermoSystem()); + } } - - /** - *- * massBalanceCheck. - *
- * - * @return a double - */ - public double massBalanceCheck() { - double error = 0.0; - // System.out.println("flow rate new " + - // mixedStream.getThermoSystem().getFlowRate("kg/hr")); - // System.out.println("temperature " + - // mixedStream.getThermoSystem().getTemperature("C")); - // System.out.println("pressure " + - // mixedStream.getThermoSystem().getPressure("bara")); - if (lastIterationStream.getFluid().getNumberOfComponents() != mixedStream.getFluid() - .getNumberOfComponents()) { - return 10.0; - } - for (int i = 0; i < mixedStream.getThermoSystem().getPhase(0) - .getNumberOfComponents(); i++) { - // System.out.println("x last " + - // lastIterationStream.getThermoSystem().getPhase(0).getComponent(i).getx()); - // System.out.println("x new " + - // mixedStream.getThermoSystem().getPhase(0).getComponent(i).getx()); - error += Math.abs(mixedStream.getThermoSystem().getPhase(0).getComponent(i).getx() - - lastIterationStream.getThermoSystem().getPhase(0).getComponent(i).getx()); - } - return Math.abs(error); + // mixedStream.getThermoSystem().init_x_y(); + // mixedStream.getThermoSystem().initBeta(); + // mixedStream.getThermoSystem().init(2); + } + + /** + *+ * guessTemperature. + *
+ * + * @return a double + */ + public double guessTemperature() { + double gtemp = 0; + for (int k = 0; k < streams.size(); k++) { + gtemp += streams.get(k).getThermoSystem().getTemperature() + * streams.get(k).getThermoSystem().getNumberOfMoles() + / mixedStream.getThermoSystem().getNumberOfMoles(); } - - /** {@inheritDoc} */ - @Override - public void displayResult() {} - - /** {@inheritDoc} */ - @Override - public void setPressure(double pres) { - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().setPressure(pres); - } - mixedStream.getThermoSystem().setPressure(pres); + return gtemp; + } + + /** + *+ * calcMixStreamEnthalpy. + *
+ * + * @return a double + */ + public double calcMixStreamEnthalpy() { + double enthalpy = 0; + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); + // System.out.println("total enthalpy k : " + ( ((Stream) + // streams.get(k)).getThermoSystem()).getEnthalpy()); } - - /** - *- * setTemperature. - *
- * - * @param temp a double - */ - public void setTemperature(double temp) { - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().setTemperature(temp); + // System.out.println("total enthalpy of streams: " + enthalpy); + return enthalpy; + } + + /** {@inheritDoc} */ + @Deprecated + public StreamInterface getOutStream() { + return mixedStream; + } + + /** + *+ * initiateDownstreamProperties. + *
+ * + * @param outstream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public void initiateDownstreamProperties(StreamInterface outstream) { + lastIterationStream = outstream.clone(); + } + + /** + *+ * setDownstreamProperties. + *
+ */ + public void setDownstreamProperties() { + if (downstreamProperty.size() > 0) { + for (int i = 0; i < downstreamProperty.size(); i++) { + if (downstreamProperty.get(i).equals("flow rate")) { + mixedStream.setFlowRate(outletStream.getFlowRate("kg/hr"), "kg/hr"); } - mixedStream.getThermoSystem().setTemperature(temp); - } - - /** - *
- * Getter for the field tolerance
.
- *
- * Setter for the field tolerance
.
- *
- * Getter for the field error
.
- *
- * Setter for the field error
.
- *
- * Getter for the field priority
.
- *
- * Setter for the field priority
.
- *
- * Getter for the field downstreamProperty
.
- *
+ * massBalanceCheck. + *
+ * + * @return a double + */ + public double massBalanceCheck() { + double error = 0.0; + // System.out.println("flow rate new " + + // mixedStream.getThermoSystem().getFlowRate("kg/hr")); + // System.out.println("temperature " + + // mixedStream.getThermoSystem().getTemperature("C")); + // System.out.println("pressure " + + // mixedStream.getThermoSystem().getPressure("bara")); + if (lastIterationStream.getFluid().getNumberOfComponents() != mixedStream.getFluid() + .getNumberOfComponents()) { + return 10.0; } - - /** - *
- * Setter for the field downstreamProperty
.
- *
- * Getter for the field outletStream
.
- *
- * Setter for the field outletStream
.
- *
+ * setTemperature. + *
+ * + * @param temp a double + */ + public void setTemperature(double temp) { + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().setTemperature(temp); } - - /** {@inheritDoc} */ - @Override - public void removeInputStream(int i) { - streams.remove(i); + mixedStream.getThermoSystem().setTemperature(temp); + } + + /** + *
+ * Getter for the field tolerance
.
+ *
+ * Setter for the field tolerance
.
+ *
+ * Getter for the field error
.
+ *
+ * Setter for the field error
.
+ *
+ * Getter for the field priority
.
+ *
+ * Setter for the field priority
.
+ *
+ * Getter for the field downstreamProperty
.
+ *
+ * Setter for the field downstreamProperty
.
+ *
+ * Getter for the field outletStream
.
+ *
+ * Setter for the field outletStream
.
+ *
- * Constructor for RecycleController. - *
- */ - public RecycleController() {} - - /** - *- * init. - *
- */ - public void init() { - for (Recycle recyc : recycleArray) { - if (recyc.getPriority() < minimumPriorityLevel) - minimumPriorityLevel = recyc.getPriority(); - if (recyc.getPriority() > maximumPriorityLevel) - maximumPriorityLevel = recyc.getPriority(); - } - - currentPriorityLevel = minimumPriorityLevel; - } - - /** - *- * resetPriorityLevel. - *
- */ - public void resetPriorityLevel() { - currentPriorityLevel = minimumPriorityLevel; + private static final long serialVersionUID = 1000; + + ArrayList+ * Constructor for RecycleController. + *
+ */ + public RecycleController() {} + + /** + *+ * init. + *
+ */ + public void init() { + for (Recycle recyc : recycleArray) { + if (recyc.getPriority() < minimumPriorityLevel) { + minimumPriorityLevel = recyc.getPriority(); + } + if (recyc.getPriority() > maximumPriorityLevel) { + maximumPriorityLevel = recyc.getPriority(); + } } - /** - *- * addRecycle. - *
- * - * @param recycle a {@link neqsim.processSimulation.processEquipment.util.Recycle} object - */ - public void addRecycle(Recycle recycle) { - recycleArray.add(recycle); - priorityArray.add(recycle.getPriority()); + currentPriorityLevel = minimumPriorityLevel; + } + + /** + *+ * resetPriorityLevel. + *
+ */ + public void resetPriorityLevel() { + currentPriorityLevel = minimumPriorityLevel; + } + + /** + *+ * addRecycle. + *
+ * + * @param recycle a {@link neqsim.processSimulation.processEquipment.util.Recycle} object + */ + public void addRecycle(Recycle recycle) { + recycleArray.add(recycle); + priorityArray.add(recycle.getPriority()); + } + + /** + *+ * doSolveRecycle. + *
+ * + * @param recycle a {@link neqsim.processSimulation.processEquipment.util.Recycle} object + * @return a boolean + */ + public boolean doSolveRecycle(Recycle recycle) { + if (recycle.getPriority() == getCurrentPriorityLevel()) { + return true; + } else { + return false; } - - /** - *- * doSolveRecycle. - *
- * - * @param recycle a {@link neqsim.processSimulation.processEquipment.util.Recycle} object - * @return a boolean - */ - public boolean doSolveRecycle(Recycle recycle) { - if (recycle.getPriority() == getCurrentPriorityLevel()) - return true; - else - return false; + } + + /** + *+ * isHighestPriority. + *
+ * + * @param recycle a {@link neqsim.processSimulation.processEquipment.util.Recycle} object + * @return a boolean + */ + public boolean isHighestPriority(Recycle recycle) { + if (recycle.getPriority() == maximumPriorityLevel) { + return true; + } else { + return false; } - - /** - *- * isHighestPriority. - *
- * - * @param recycle a {@link neqsim.processSimulation.processEquipment.util.Recycle} object - * @return a boolean - */ - public boolean isHighestPriority(Recycle recycle) { - if (recycle.getPriority() == maximumPriorityLevel) - return true; - else - return false; - } - - /** - *- * solvedCurrentPriorityLevel. - *
- * - * @return a boolean - */ - public boolean solvedCurrentPriorityLevel() { - for (Recycle recyc : recycleArray) { - if (recyc.getPriority() == currentPriorityLevel) { - if (!recyc.solved()) - return false; - } + } + + /** + *+ * solvedCurrentPriorityLevel. + *
+ * + * @return a boolean + */ + public boolean solvedCurrentPriorityLevel() { + for (Recycle recyc : recycleArray) { + if (recyc.getPriority() == currentPriorityLevel) { + if (!recyc.solved()) { + return false; } - return true; + } } - - /** - *- * nextPriorityLevel. - *
- */ - public void nextPriorityLevel() { - currentPriorityLevel = maximumPriorityLevel; + return true; + } + + /** + *+ * nextPriorityLevel. + *
+ */ + public void nextPriorityLevel() { + currentPriorityLevel = maximumPriorityLevel; + } + + /** + *+ * hasLoverPriorityLevel. + *
+ * + * @return a boolean + */ + public boolean hasLoverPriorityLevel() { + if (currentPriorityLevel > minimumPriorityLevel) { + return true; + } else { + return false; } - - /** - *- * hasLoverPriorityLevel. - *
- * - * @return a boolean - */ - public boolean hasLoverPriorityLevel() { - if (currentPriorityLevel > minimumPriorityLevel) { - return true; - } else - return false; + } + + /** + *+ * hasHigherPriorityLevel. + *
+ * + * @return a boolean + */ + public boolean hasHigherPriorityLevel() { + if (currentPriorityLevel < maximumPriorityLevel) { + return true; + } else { + return false; } - - /** - *- * hasHigherPriorityLevel. - *
- * - * @return a boolean - */ - public boolean hasHigherPriorityLevel() { - if (currentPriorityLevel < maximumPriorityLevel) { - return true; - } else - return false; + } + + /** + *+ * solvedAll. + *
+ * + * @return a boolean + */ + public boolean solvedAll() { + for (Recycle recyc : recycleArray) { + if (!recyc.solved()) { + return false; + } } - - /** - *- * solvedAll. - *
- * - * @return a boolean - */ - public boolean solvedAll() { - for (Recycle recyc : recycleArray) { - if (!recyc.solved()) - return false; - } - return true; - } - - /** - *- * clear. - *
- */ - public void clear() { - recycleArray.clear(); - priorityArray.clear(); - } - - /** - *
- * Getter for the field currentPriorityLevel
.
- *
+ * clear. + *
+ */ + public void clear() { + recycleArray.clear(); + priorityArray.clear(); + } + + /** + *
+ * Getter for the field currentPriorityLevel
.
+ *
+ * Setter for the field currentPriorityLevel
.
+ *
- * Setter for the field currentPriorityLevel
.
- *
* display. diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/FlowSystem.java b/src/main/java/neqsim/fluidMechanics/flowSystem/FlowSystem.java index ed296c6566..7814155f82 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/FlowSystem.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/FlowSystem.java @@ -1,5 +1,6 @@ package neqsim.fluidMechanics.flowSystem; +import java.util.UUID; import neqsim.fluidMechanics.flowLeg.FlowLegInterface; import neqsim.fluidMechanics.flowNode.FlowNodeInterface; import neqsim.fluidMechanics.flowSolver.FlowSolverInterface; @@ -19,440 +20,437 @@ * @version $Id: $Id */ public abstract class FlowSystem implements FlowSystemInterface, java.io.Serializable { - private static final long serialVersionUID = 1000; - - protected FlowNodeInterface[] flowNode; - protected FlowLegInterface[] flowLeg; - protected FileWriterInterface[] fileWriter; - protected String initFlowPattern = "annular"; - protected FlowSystemVisualizationInterface display; - protected TimeSeries timeSeries = new TimeSeries(); - protected GeometryDefinitionInterface[] equipmentGeometry; - protected SystemInterface thermoSystem; - protected ThermodynamicOperations thermoOperations; - protected double inletTemperature = 0, inletPressure = 0, endPressure = 0, systemLength = 0; - protected int numberOfFlowLegs = 0, totalNumberOfNodes = 25; - int[] numberOfNodesInLeg; - double[] legHeights, legPositions, legOuterTemperatures, legOuterHeatTransferCoefficients, - legWallHeatTransferCoefficients; - protected FlowSolverInterface flowSolver; - double inletMolarLiquidFlowRate = 0, inletMolarGasFlowRate = 0; - boolean equilibriumHeatTransfer = true, equilibriumMassTransfer = false; - - /** - *
- * Constructor for FlowSystem. - *
- */ - public FlowSystem() {} - - /** - *- * Constructor for FlowSystem. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public FlowSystem(SystemInterface system) { - System.out.println("Hei der"); - } - - /** {@inheritDoc} */ - @Override - public void init() {} - - /** {@inheritDoc} */ - @Override - public void createSystem() { - thermoOperations = new ThermodynamicOperations(thermoSystem); - this.flowLegInit(); - } - - /** {@inheritDoc} */ - @Override - public FlowSolverInterface getSolver() { - return flowSolver; - } - - /** {@inheritDoc} */ - @Override - public TimeSeries getTimeSeries() { - return timeSeries; - } - - /** - *- * flowLegInit. - *
- */ - public void flowLegInit() { - // TODO: add checks that input arguments have correct size to avoid generic - // IndexOutOfBoundsException - for (int i = 0; i < numberOfFlowLegs; i++) { - this.flowLeg[i].setThermoSystem(thermoSystem); - this.flowLeg[i].setEquipmentGeometry(equipmentGeometry[i]); - this.flowLeg[i].setNumberOfNodes(numberOfNodesInLeg[i]); - this.flowLeg[i].setHeightCoordinates(legHeights[i], legHeights[i + 1]); - this.flowLeg[i].setOuterTemperatures(legOuterTemperatures[i], - legOuterTemperatures[i + 1]); - this.flowLeg[i].setLongitudionalCoordinates(legPositions[i], legPositions[i + 1]); - this.flowLeg[i].setOuterHeatTransferCoefficients(legOuterHeatTransferCoefficients[i], - legOuterHeatTransferCoefficients[i + 1]); - this.flowLeg[i].setWallHeatTransferCoefficients(legWallHeatTransferCoefficients[i], - legWallHeatTransferCoefficients[i + 1]); - this.flowLeg[i].createFlowNodes(flowNode[0]); - } - - totalNumberOfNodes = this.calcTotalNumberOfNodes(); - // System.out.println("total number of nodes : " + totalNumberOfNodes); - } - - /** {@inheritDoc} */ - @Override - public void setNodes() { - flowNode[0].setDistanceToCenterOfNode(0.0); - flowNode[0].setVerticalPositionOfNode(legHeights[0]); - flowNode[0].setLengthOfNode(systemLength / 1000.0); - flowNode[0].init(); - - int k = 1; - for (int i = 0; i < numberOfFlowLegs; i++) { - for (int j = 0; j < getNumberOfNodesInLeg(i); j++) { - this.flowNode[k++] = flowLeg[i].getNode(j); - } - } - flowNode[totalNumberOfNodes - 1] = flowNode[totalNumberOfNodes - 2].getNextNode(); - flowNode[totalNumberOfNodes - 1].setLengthOfNode(systemLength / 1000.0); - flowNode[totalNumberOfNodes - 1].setDistanceToCenterOfNode(legPositions[numberOfFlowLegs] - + flowNode[totalNumberOfNodes - 1].getLengthOfNode() / 2.0); - flowNode[totalNumberOfNodes - 1].setVerticalPositionOfNode(legHeights[numberOfFlowLegs]); - if (endPressure != 0) { - flowNode[totalNumberOfNodes - 1].getBulkSystem().setPressure(endPressure); - } - flowNode[totalNumberOfNodes - 1].init(); - } - - /** {@inheritDoc} */ - @Override - public void setInletThermoSystem(SystemInterface thermoSystem) { - this.thermoSystem = thermoSystem; - this.inletPressure = thermoSystem.getPressure(); - this.inletTemperature = thermoSystem.getTemperature(); - } - - /** {@inheritDoc} */ - @Override - public double getSystemLength() { - return systemLength; - } - - /** - *- * calcTotalNumberOfNodes. - *
- * - * @return a int - */ - public int calcTotalNumberOfNodes() { - int number = 0; - for (int i = 0; i < this.numberOfFlowLegs; i++) { - number += flowLeg[i].getNumberOfNodes(); - } - this.totalNumberOfNodes = number + 2; - return this.totalNumberOfNodes; - } - - /** {@inheritDoc} */ - @Override - public int getTotalNumberOfNodes() { - return this.totalNumberOfNodes; - } - - /** {@inheritDoc} */ - @Override - public double getInletTemperature() { - return this.inletTemperature; - } - - /** {@inheritDoc} */ - @Override - public void setEquipmentGeometry(GeometryDefinitionInterface[] equipmentGeometry) { - this.equipmentGeometry = equipmentGeometry; - } - - /** {@inheritDoc} */ - @Override - public void setEndPressure(double endPressure) { - this.endPressure = endPressure; - } - - /** {@inheritDoc} */ - @Override - public double getInletPressure() { - return this.inletPressure; - } - - /** {@inheritDoc} */ - @Override - public void setNumberOfLegs(int numberOfFlowLegs) { - this.numberOfFlowLegs = numberOfFlowLegs; - } - - /** {@inheritDoc} */ - @Override - public FlowNodeInterface getNode(int i) { - return this.flowNode[i]; - } - - /** {@inheritDoc} */ - @Override - public FlowNodeInterface[] getFlowNodes() { - return this.flowNode; - } - - /** {@inheritDoc} */ - @Override - public int getNumberOfLegs() { - return this.numberOfFlowLegs; - } - - /** {@inheritDoc} */ - @Override - public FlowSystemVisualizationInterface getDisplay() { - return display; - } - - /** {@inheritDoc} */ - @Override - public FileWriterInterface getFileWriter(int i) { - return fileWriter[i]; - } - - /** {@inheritDoc} */ - @Override - public void setNumberOfNodesInLeg(int numberOfNodesInLeg) { - this.numberOfNodesInLeg = new int[this.getNumberOfLegs()]; - for (int i = 0; i < this.getNumberOfLegs(); i++) { - this.numberOfNodesInLeg[i] = numberOfNodesInLeg; - } - totalNumberOfNodes = numberOfNodesInLeg * this.getNumberOfLegs() + 2; - } - - /** {@inheritDoc} */ - @Override - public int getNumberOfNodesInLeg(int i) { - return this.numberOfNodesInLeg[i]; - } - - /** {@inheritDoc} */ - @Override - public void setLegHeights(double[] legHeights) { - this.legHeights = legHeights; - } - - /** {@inheritDoc} */ - @Override - public void setLegPositions(double[] legPositions) { - this.legPositions = legPositions; - this.systemLength = legPositions[legPositions.length - 1]; - } - - /** {@inheritDoc} */ - @Override - public void setLegOuterTemperatures(double[] temps) { - this.legOuterTemperatures = temps; - } - - /** {@inheritDoc} */ - @Override - public void setLegOuterHeatTransferCoefficients(double[] coefs) { - this.legOuterHeatTransferCoefficients = coefs; - } - - /** {@inheritDoc} */ - @Override - public void setLegWallHeatTransferCoefficients(double[] coefs) { - this.legWallHeatTransferCoefficients = coefs; - } - - /** {@inheritDoc} */ - @Override - public double[] getLegHeights() { - return this.legHeights; - } - - /** {@inheritDoc} */ - @Override - public void print() { - for (int i = 0; i < getTotalNumberOfNodes() - 1; i++) { - System.out.println("node " + flowNode[i].getDistanceToCenterOfNode() + " pressure: " - + flowNode[i].getBulkSystem().getPhases()[0].getPressure() + " temperature: " - + flowNode[i].getBulkSystem().getPhases()[1].getTemperature() + " flow: " - + flowNode[i].getMassFlowRate(0) + " velocity: " + flowNode[i].getVelocity() - + " reynolds number " + flowNode[i].getReynoldsNumber() + " friction : " - + flowNode[i].getWallFrictionFactor() + " x1 : " - + flowNode[i].getBulkSystem().getPhases()[0].getComponents()[1].getx()); - } - } - - /** {@inheritDoc} */ - @Override - public void calcFluxes() {} - - /** - *- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - System.out.println("Hei der!"); - } - - /** - *- * solveTransient. - *
- */ - public void solveTransient() {} - - /** {@inheritDoc} */ - @Override - public double getTotalMolarMassTransferRate(int component) { - double tot = 0.0; - for (int i = 0; i < getTotalNumberOfNodes() - 1; i++) { - tot += flowNode[i].getFluidBoundary().getInterphaseMolarFlux(component) - * flowNode[i].getInterphaseContactArea(); - } - return tot; - } - - /** {@inheritDoc} */ - @Override - public double getTotalMolarMassTransferRate(int component, int lastNode) { - double tot = 0.0; - for (int i = 0; i < lastNode; i++) { - tot += flowNode[i].getFluidBoundary().getInterphaseMolarFlux(component) - * flowNode[i].getInterphaseContactArea(); - } - return tot; - } - - /** {@inheritDoc} */ - @Override - public double getTotalPressureDrop() { - return flowNode[0].getBulkSystem().getPressure() - - flowNode[getTotalNumberOfNodes() - 1].getBulkSystem().getPressure(); - } - - /** {@inheritDoc} */ - @Override - public double getTotalPressureDrop(int lastNode) { - return flowNode[0].getBulkSystem().getPressure() - - flowNode[lastNode].getBulkSystem().getPressure(); - } - - /** {@inheritDoc} */ - @Override - public void setInitialFlowPattern(String flowPattern) { - this.initFlowPattern = flowPattern; - } - - /** {@inheritDoc} */ - @Override - public void setFlowPattern(String flowPattern) { - this.initFlowPattern = flowPattern; - for (int i = 0; i < this.getNumberOfLegs(); i++) { - flowLeg[i].setFlowPattern(flowPattern); - } - } - - /** - *- * setEquilibriumMassTransferModel. - *
- * - * @param startNode a int - * @param endNode a int - */ - public void setEquilibriumMassTransferModel(int startNode, int endNode) { - for (int i = startNode; i < endNode; i++) { - if (flowNode[i].getBulkSystem().isChemicalSystem()) { - flowNode[i].setInterphaseModelType(0); - } else { - flowNode[i].setInterphaseModelType(0); - } - flowNode[i].getFluidBoundary().setMassTransferCalc(false); - } - } - - /** - *- * setNonEquilibriumMassTransferModel. - *
- * - * @param startNode a int - * @param endNode a int - */ - public void setNonEquilibriumMassTransferModel(int startNode, int endNode) { - for (int i = startNode; i < endNode; i++) { - if (flowNode[i].getBulkSystem().isChemicalSystem()) { - flowNode[i].setInterphaseModelType(10); - } else { - flowNode[i].setInterphaseModelType(1); - } - flowNode[i].getFluidBoundary().setMassTransferCalc(true); - } - } - - /** - *- * setNonEquilibriumHeatTransferModel. - *
- * - * @param startNode a int - * @param endNode a int - */ - public void setNonEquilibriumHeatTransferModel(int startNode, int endNode) { - for (int i = startNode; i < endNode; i++) { - flowNode[i].getFluidBoundary().setHeatTransferCalc(true); - } - } - - /** - *- * setEquilibriumHeatTransferModel. - *
- * - * @param startNode a int - * @param endNode a int - */ - public void setEquilibriumHeatTransferModel(int startNode, int endNode) { - for (int i = startNode; i < endNode; i++) { - flowNode[i].getFluidBoundary().setHeatTransferCalc(false); - } - } - - /** {@inheritDoc} */ - @Override - public void setEquilibriumMassTransfer(boolean test) { - equilibriumMassTransfer = test; - if (equilibriumMassTransfer) { - setEquilibriumMassTransferModel(0, getTotalNumberOfNodes()); - } else { - setNonEquilibriumMassTransferModel(0, getTotalNumberOfNodes()); - } - } - - /** {@inheritDoc} */ - @Override - public void setEquilibriumHeatTransfer(boolean test) { - equilibriumHeatTransfer = test; - if (equilibriumHeatTransfer) { - setEquilibriumHeatTransferModel(0, getTotalNumberOfNodes()); - } else { - setNonEquilibriumHeatTransferModel(0, getTotalNumberOfNodes()); - } - } + private static final long serialVersionUID = 1000; + + /** + * Unique identifier of which solve/run call was last called successfully. + */ + protected UUID calcIdentifier; + + protected FlowNodeInterface[] flowNode; + protected FlowLegInterface[] flowLeg; + protected FileWriterInterface[] fileWriter; + protected String initFlowPattern = "annular"; + protected FlowSystemVisualizationInterface display; + protected TimeSeries timeSeries = new TimeSeries(); + protected GeometryDefinitionInterface[] equipmentGeometry; + protected SystemInterface thermoSystem; + protected ThermodynamicOperations thermoOperations; + protected double inletTemperature = 0, inletPressure = 0, endPressure = 0, systemLength = 0; + protected int numberOfFlowLegs = 0, totalNumberOfNodes = 25; + int[] numberOfNodesInLeg; + double[] legHeights, legPositions, legOuterTemperatures, legOuterHeatTransferCoefficients, + legWallHeatTransferCoefficients; + protected FlowSolverInterface flowSolver; + double inletMolarLiquidFlowRate = 0, inletMolarGasFlowRate = 0; + boolean equilibriumHeatTransfer = true, equilibriumMassTransfer = false; + + /** + *+ * Constructor for FlowSystem. + *
+ */ + public FlowSystem() {} + + /** + *+ * Constructor for FlowSystem. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public FlowSystem(SystemInterface system) { + System.out.println("Hei der"); + } + + /** {@inheritDoc} */ + @Override + public void init() {} + + /** {@inheritDoc} */ + @Override + public void createSystem() { + thermoOperations = new ThermodynamicOperations(thermoSystem); + this.flowLegInit(); + } + + /** {@inheritDoc} */ + @Override + public FlowSolverInterface getSolver() { + return flowSolver; + } + + /** {@inheritDoc} */ + @Override + public TimeSeries getTimeSeries() { + return timeSeries; + } + + /** + *+ * flowLegInit. + *
+ */ + public void flowLegInit() { + // TODO: add checks that input arguments have correct size to avoid generic + // IndexOutOfBoundsException + for (int i = 0; i < numberOfFlowLegs; i++) { + this.flowLeg[i].setThermoSystem(thermoSystem); + this.flowLeg[i].setEquipmentGeometry(equipmentGeometry[i]); + this.flowLeg[i].setNumberOfNodes(numberOfNodesInLeg[i]); + this.flowLeg[i].setHeightCoordinates(legHeights[i], legHeights[i + 1]); + this.flowLeg[i].setOuterTemperatures(legOuterTemperatures[i], legOuterTemperatures[i + 1]); + this.flowLeg[i].setLongitudionalCoordinates(legPositions[i], legPositions[i + 1]); + this.flowLeg[i].setOuterHeatTransferCoefficients(legOuterHeatTransferCoefficients[i], + legOuterHeatTransferCoefficients[i + 1]); + this.flowLeg[i].setWallHeatTransferCoefficients(legWallHeatTransferCoefficients[i], + legWallHeatTransferCoefficients[i + 1]); + this.flowLeg[i].createFlowNodes(flowNode[0]); + } + + totalNumberOfNodes = this.calcTotalNumberOfNodes(); + // System.out.println("total number of nodes : " + totalNumberOfNodes); + } + + /** {@inheritDoc} */ + @Override + public void setNodes() { + flowNode[0].setDistanceToCenterOfNode(0.0); + flowNode[0].setVerticalPositionOfNode(legHeights[0]); + flowNode[0].setLengthOfNode(systemLength / 1000.0); + flowNode[0].init(); + + int k = 1; + for (int i = 0; i < numberOfFlowLegs; i++) { + for (int j = 0; j < getNumberOfNodesInLeg(i); j++) { + this.flowNode[k++] = flowLeg[i].getNode(j); + } + } + flowNode[totalNumberOfNodes - 1] = flowNode[totalNumberOfNodes - 2].getNextNode(); + flowNode[totalNumberOfNodes - 1].setLengthOfNode(systemLength / 1000.0); + flowNode[totalNumberOfNodes - 1].setDistanceToCenterOfNode( + legPositions[numberOfFlowLegs] + flowNode[totalNumberOfNodes - 1].getLengthOfNode() / 2.0); + flowNode[totalNumberOfNodes - 1].setVerticalPositionOfNode(legHeights[numberOfFlowLegs]); + if (endPressure != 0) { + flowNode[totalNumberOfNodes - 1].getBulkSystem().setPressure(endPressure); + } + flowNode[totalNumberOfNodes - 1].init(); + } + + /** {@inheritDoc} */ + @Override + public void setInletThermoSystem(SystemInterface thermoSystem) { + this.thermoSystem = thermoSystem; + this.inletPressure = thermoSystem.getPressure(); + this.inletTemperature = thermoSystem.getTemperature(); + } + + /** {@inheritDoc} */ + @Override + public double getSystemLength() { + return systemLength; + } + + /** + *+ * calcTotalNumberOfNodes. + *
+ * + * @return a int + */ + public int calcTotalNumberOfNodes() { + int number = 0; + for (int i = 0; i < this.numberOfFlowLegs; i++) { + number += flowLeg[i].getNumberOfNodes(); + } + this.totalNumberOfNodes = number + 2; + return this.totalNumberOfNodes; + } + + /** {@inheritDoc} */ + @Override + public int getTotalNumberOfNodes() { + return this.totalNumberOfNodes; + } + + /** {@inheritDoc} */ + @Override + public double getInletTemperature() { + return this.inletTemperature; + } + + /** {@inheritDoc} */ + @Override + public void setEquipmentGeometry(GeometryDefinitionInterface[] equipmentGeometry) { + this.equipmentGeometry = equipmentGeometry; + } + + /** {@inheritDoc} */ + @Override + public void setEndPressure(double endPressure) { + this.endPressure = endPressure; + } + + /** {@inheritDoc} */ + @Override + public double getInletPressure() { + return this.inletPressure; + } + + /** {@inheritDoc} */ + @Override + public void setNumberOfLegs(int numberOfFlowLegs) { + this.numberOfFlowLegs = numberOfFlowLegs; + } + + /** {@inheritDoc} */ + @Override + public FlowNodeInterface getNode(int i) { + return this.flowNode[i]; + } + + /** {@inheritDoc} */ + @Override + public FlowNodeInterface[] getFlowNodes() { + return this.flowNode; + } + + /** {@inheritDoc} */ + @Override + public int getNumberOfLegs() { + return this.numberOfFlowLegs; + } + + /** {@inheritDoc} */ + @Override + public FlowSystemVisualizationInterface getDisplay() { + return display; + } + + /** {@inheritDoc} */ + @Override + public FileWriterInterface getFileWriter(int i) { + return fileWriter[i]; + } + + /** {@inheritDoc} */ + @Override + public void setNumberOfNodesInLeg(int numberOfNodesInLeg) { + this.numberOfNodesInLeg = new int[this.getNumberOfLegs()]; + for (int i = 0; i < this.getNumberOfLegs(); i++) { + this.numberOfNodesInLeg[i] = numberOfNodesInLeg; + } + totalNumberOfNodes = numberOfNodesInLeg * this.getNumberOfLegs() + 2; + } + + /** {@inheritDoc} */ + @Override + public int getNumberOfNodesInLeg(int i) { + return this.numberOfNodesInLeg[i]; + } + + /** {@inheritDoc} */ + @Override + public void setLegHeights(double[] legHeights) { + this.legHeights = legHeights; + } + + /** {@inheritDoc} */ + @Override + public void setLegPositions(double[] legPositions) { + this.legPositions = legPositions; + this.systemLength = legPositions[legPositions.length - 1]; + } + + /** {@inheritDoc} */ + @Override + public void setLegOuterTemperatures(double[] temps) { + this.legOuterTemperatures = temps; + } + + /** {@inheritDoc} */ + @Override + public void setLegOuterHeatTransferCoefficients(double[] coefs) { + this.legOuterHeatTransferCoefficients = coefs; + } + + /** {@inheritDoc} */ + @Override + public void setLegWallHeatTransferCoefficients(double[] coefs) { + this.legWallHeatTransferCoefficients = coefs; + } + + /** {@inheritDoc} */ + @Override + public double[] getLegHeights() { + return this.legHeights; + } + + /** {@inheritDoc} */ + @Override + public void print() { + for (int i = 0; i < getTotalNumberOfNodes() - 1; i++) { + System.out.println("node " + flowNode[i].getDistanceToCenterOfNode() + " pressure: " + + flowNode[i].getBulkSystem().getPhases()[0].getPressure() + " temperature: " + + flowNode[i].getBulkSystem().getPhases()[1].getTemperature() + " flow: " + + flowNode[i].getMassFlowRate(0) + " velocity: " + flowNode[i].getVelocity() + + " reynolds number " + flowNode[i].getReynoldsNumber() + " friction : " + + flowNode[i].getWallFrictionFactor() + " x1 : " + + flowNode[i].getBulkSystem().getPhases()[0].getComponents()[1].getx()); + } + } + + /** {@inheritDoc} */ + @Override + public void calcFluxes() {} + + /** + *+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + System.out.println("Hei der!"); + } + + /** {@inheritDoc} */ + @Override + public double getTotalMolarMassTransferRate(int component) { + double tot = 0.0; + for (int i = 0; i < getTotalNumberOfNodes() - 1; i++) { + tot += flowNode[i].getFluidBoundary().getInterphaseMolarFlux(component) + * flowNode[i].getInterphaseContactArea(); + } + return tot; + } + + /** {@inheritDoc} */ + @Override + public double getTotalMolarMassTransferRate(int component, int lastNode) { + double tot = 0.0; + for (int i = 0; i < lastNode; i++) { + tot += flowNode[i].getFluidBoundary().getInterphaseMolarFlux(component) + * flowNode[i].getInterphaseContactArea(); + } + return tot; + } + + /** {@inheritDoc} */ + @Override + public double getTotalPressureDrop() { + return flowNode[0].getBulkSystem().getPressure() + - flowNode[getTotalNumberOfNodes() - 1].getBulkSystem().getPressure(); + } + + /** {@inheritDoc} */ + @Override + public double getTotalPressureDrop(int lastNode) { + return flowNode[0].getBulkSystem().getPressure() + - flowNode[lastNode].getBulkSystem().getPressure(); + } + + /** {@inheritDoc} */ + @Override + public void setInitialFlowPattern(String flowPattern) { + this.initFlowPattern = flowPattern; + } + + /** {@inheritDoc} */ + @Override + public void setFlowPattern(String flowPattern) { + this.initFlowPattern = flowPattern; + for (int i = 0; i < this.getNumberOfLegs(); i++) { + flowLeg[i].setFlowPattern(flowPattern); + } + } + + /** + *+ * setEquilibriumMassTransferModel. + *
+ * + * @param startNode a int + * @param endNode a int + */ + public void setEquilibriumMassTransferModel(int startNode, int endNode) { + for (int i = startNode; i < endNode; i++) { + if (flowNode[i].getBulkSystem().isChemicalSystem()) { + flowNode[i].setInterphaseModelType(0); + } else { + flowNode[i].setInterphaseModelType(0); + } + flowNode[i].getFluidBoundary().setMassTransferCalc(false); + } + } + + /** + *+ * setNonEquilibriumMassTransferModel. + *
+ * + * @param startNode a int + * @param endNode a int + */ + public void setNonEquilibriumMassTransferModel(int startNode, int endNode) { + for (int i = startNode; i < endNode; i++) { + if (flowNode[i].getBulkSystem().isChemicalSystem()) { + flowNode[i].setInterphaseModelType(10); + } else { + flowNode[i].setInterphaseModelType(1); + } + flowNode[i].getFluidBoundary().setMassTransferCalc(true); + } + } + + /** + *+ * setNonEquilibriumHeatTransferModel. + *
+ * + * @param startNode a int + * @param endNode a int + */ + public void setNonEquilibriumHeatTransferModel(int startNode, int endNode) { + for (int i = startNode; i < endNode; i++) { + flowNode[i].getFluidBoundary().setHeatTransferCalc(true); + } + } + + /** + *+ * setEquilibriumHeatTransferModel. + *
+ * + * @param startNode a int + * @param endNode a int + */ + public void setEquilibriumHeatTransferModel(int startNode, int endNode) { + for (int i = startNode; i < endNode; i++) { + flowNode[i].getFluidBoundary().setHeatTransferCalc(false); + } + } + + /** {@inheritDoc} */ + @Override + public void setEquilibriumMassTransfer(boolean test) { + equilibriumMassTransfer = test; + if (equilibriumMassTransfer) { + setEquilibriumMassTransferModel(0, getTotalNumberOfNodes()); + } else { + setNonEquilibriumMassTransferModel(0, getTotalNumberOfNodes()); + } + } + + /** {@inheritDoc} */ + @Override + public void setEquilibriumHeatTransfer(boolean test) { + equilibriumHeatTransfer = test; + if (equilibriumHeatTransfer) { + setEquilibriumHeatTransferModel(0, getTotalNumberOfNodes()); + } else { + setNonEquilibriumHeatTransferModel(0, getTotalNumberOfNodes()); + } + } } diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/FlowSystemInterface.java b/src/main/java/neqsim/fluidMechanics/flowSystem/FlowSystemInterface.java index 18356fdaff..e5a5a5f9f0 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/FlowSystemInterface.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/FlowSystemInterface.java @@ -3,8 +3,10 @@ * * Created on 11. desember 2000, 17:17 */ + package neqsim.fluidMechanics.flowSystem; +import java.util.UUID; import neqsim.fluidMechanics.flowNode.FlowNodeInterface; import neqsim.fluidMechanics.flowSolver.FlowSolverInterface; import neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface; @@ -22,346 +24,372 @@ * @version $Id: $Id */ public interface FlowSystemInterface { - /** - *- * init. - *
- */ - public void init(); - - /** - *- * setNodes. - *
- */ - public void setNodes(); - - /** - *- * solveTransient. - *
- * - * @param type a int - */ - public void solveTransient(int type); - - /** - *- * getTimeSeries. - *
- * - * @return a {@link neqsim.fluidMechanics.util.timeSeries.TimeSeries} object - */ - public TimeSeries getTimeSeries(); - - /** - *- * getDisplay. - *
- * - * @return a - * {@link neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.FlowSystemVisualizationInterface} - * object - */ - public FlowSystemVisualizationInterface getDisplay(); - - /** - *- * getFileWriter. - *
- * - * @param i a int - * @return a {@link neqsim.fluidMechanics.util.fluidMechanicsDataHandeling.FileWriterInterface} - * object - */ - public FileWriterInterface getFileWriter(int i); - - /** - *- * getSolver. - *
- * - * @return a {@link neqsim.fluidMechanics.flowSolver.FlowSolverInterface} object - */ - public FlowSolverInterface getSolver(); - - /** - *- * getInletTemperature. - *
- * - * @return a double - */ - public double getInletTemperature(); - - /** - *- * getInletPressure. - *
- * - * @return a double - */ - public double getInletPressure(); - - /** - *- * setNumberOfLegs. - *
- * - * @param numberOfLegs a int - */ - public void setNumberOfLegs(int numberOfLegs); - - /** - *- * getNumberOfLegs. - *
- * - * @return a int - */ - public int getNumberOfLegs(); - - /** - *- * setNumberOfNodesInLeg. - *
- * - * @param numberOfNodesInLeg a int - */ - public void setNumberOfNodesInLeg(int numberOfNodesInLeg); - - /** - *- * getNumberOfNodesInLeg. - *
- * - * @param i a int - * @return a int - */ - public int getNumberOfNodesInLeg(int i); - - /** - *- * setLegHeights. - *
- * - * @param legHeights an array of {@link double} objects - */ - public void setLegHeights(double[] legHeights); - - /** - *- * getLegHeights. - *
- * - * @return an array of {@link double} objects - */ - public double[] getLegHeights(); - - /** - *- * setLegPositions. - *
- * - * @param legPositions an array of {@link double} objects - */ - public void setLegPositions(double[] legPositions); - - /** - *- * createSystem. - *
- */ - public void createSystem(); - - /** - *- * getNode. - *
- * - * @param i a int - * @return a {@link neqsim.fluidMechanics.flowNode.FlowNodeInterface} object - */ - public FlowNodeInterface getNode(int i); - - /** - *- * getSystemLength. - *
- * - * @return a double - */ - public double getSystemLength(); - - /** - *- * setLegOuterHeatTransferCoefficients. - *
- * - * @param coefs an array of {@link double} objects - */ - public void setLegOuterHeatTransferCoefficients(double[] coefs); - - /** - *- * setLegWallHeatTransferCoefficients. - *
- * - * @param coefs an array of {@link double} objects - */ - public void setLegWallHeatTransferCoefficients(double[] coefs); - - /** - *- * setEquipmentGeometry. - *
- * - * @param equipmentGeometry an array of - * {@link neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface} objects - */ - public void setEquipmentGeometry(GeometryDefinitionInterface[] equipmentGeometry); - - /** - *- * getTotalNumberOfNodes. - *
- * - * @return a int - */ - public int getTotalNumberOfNodes(); - - /** - *- * calcFluxes. - *
- */ - public void calcFluxes(); - - /** - *- * setEndPressure. - *
- * - * @param inletPressure a double - */ - public void setEndPressure(double inletPressure); - - /** - *- * setInletThermoSystem. - *
- * - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - public void setInletThermoSystem(SystemInterface thermoSystem); - - /** - *- * solveSteadyState. - *
- * - * @param type a int - */ - public void solveSteadyState(int type); - - /** - *- * getFlowNodes. - *
- * - * @return an array of {@link neqsim.fluidMechanics.flowNode.FlowNodeInterface} objects - */ - public FlowNodeInterface[] getFlowNodes(); - - /** - *- * print. - *
- */ - public void print(); - - /** - *- * setLegOuterTemperatures. - *
- * - * @param temps an array of {@link double} objects - */ - public void setLegOuterTemperatures(double[] temps); - - /** - *- * getTotalMolarMassTransferRate. - *
- * - * @param component a int - * @return a double - */ - public double getTotalMolarMassTransferRate(int component); - - /** - *- * getTotalMolarMassTransferRate. - *
- * - * @param component a int - * @param lastNode a int - * @return a double - */ - public double getTotalMolarMassTransferRate(int component, int lastNode); - - /** - *- * getTotalPressureDrop. - *
- * - * @return a double - */ - public double getTotalPressureDrop(); - - /** - *- * getTotalPressureDrop. - *
- * - * @param lastNode a int - * @return a double - */ - public double getTotalPressureDrop(int lastNode); - - /** - *- * setInitialFlowPattern. - *
- * - * @param flowPattern a {@link java.lang.String} object - */ - public void setInitialFlowPattern(String flowPattern); - - /** - *- * setFlowPattern. - *
- * - * @param flowPattern a {@link java.lang.String} object - */ - public void setFlowPattern(String flowPattern); - - /** - *- * setEquilibriumMassTransfer. - *
- * - * @param test a boolean - */ - public void setEquilibriumMassTransfer(boolean test); - - /** - *- * setEquilibriumHeatTransfer. - *
- * - * @param test a boolean - */ - public void setEquilibriumHeatTransfer(boolean test); + /** + *+ * init. + *
+ */ + public void init(); + + /** + *+ * setNodes. + *
+ */ + public void setNodes(); + + /** + *+ * solveTransient. + *
+ * + * @param type a int + */ + public default void solveTransient(int type) { + solveTransient(type, UUID.randomUUID()); + } + + /** + *+ * solveTransient. + *
+ * + * @param type a int + * @param id Calculation identifier + */ + public void solveTransient(int type, UUID id); + + /** + *+ * getTimeSeries. + *
+ * + * @return a {@link neqsim.fluidMechanics.util.timeSeries.TimeSeries} object + */ + public TimeSeries getTimeSeries(); + + /** + *+ * getDisplay. + *
+ * + * @return a + * {@link neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.FlowSystemVisualizationInterface} + * object + */ + public FlowSystemVisualizationInterface getDisplay(); + + /** + *+ * getFileWriter. + *
+ * + * @param i a int + * @return a {@link neqsim.fluidMechanics.util.fluidMechanicsDataHandeling.FileWriterInterface} + * object + */ + public FileWriterInterface getFileWriter(int i); + + /** + *+ * getSolver. + *
+ * + * @return a {@link neqsim.fluidMechanics.flowSolver.FlowSolverInterface} object + */ + public FlowSolverInterface getSolver(); + + /** + *+ * getInletTemperature. + *
+ * + * @return a double + */ + public double getInletTemperature(); + + /** + *+ * getInletPressure. + *
+ * + * @return a double + */ + public double getInletPressure(); + + /** + *+ * setNumberOfLegs. + *
+ * + * @param numberOfLegs a int + */ + public void setNumberOfLegs(int numberOfLegs); + + /** + *+ * getNumberOfLegs. + *
+ * + * @return a int + */ + public int getNumberOfLegs(); + + /** + *+ * setNumberOfNodesInLeg. + *
+ * + * @param numberOfNodesInLeg a int + */ + public void setNumberOfNodesInLeg(int numberOfNodesInLeg); + + /** + *+ * getNumberOfNodesInLeg. + *
+ * + * @param i a int + * @return a int + */ + public int getNumberOfNodesInLeg(int i); + + /** + *+ * setLegHeights. + *
+ * + * @param legHeights an array of {@link double} objects + */ + public void setLegHeights(double[] legHeights); + + /** + *+ * getLegHeights. + *
+ * + * @return an array of {@link double} objects + */ + public double[] getLegHeights(); + + /** + *+ * setLegPositions. + *
+ * + * @param legPositions an array of {@link double} objects + */ + public void setLegPositions(double[] legPositions); + + /** + *+ * createSystem. + *
+ */ + public void createSystem(); + + /** + *+ * getNode. + *
+ * + * @param i a int + * @return a {@link neqsim.fluidMechanics.flowNode.FlowNodeInterface} object + */ + public FlowNodeInterface getNode(int i); + + /** + *+ * getSystemLength. + *
+ * + * @return a double + */ + public double getSystemLength(); + + /** + *+ * setLegOuterHeatTransferCoefficients. + *
+ * + * @param coefs an array of {@link double} objects + */ + public void setLegOuterHeatTransferCoefficients(double[] coefs); + + /** + *+ * setLegWallHeatTransferCoefficients. + *
+ * + * @param coefs an array of {@link double} objects + */ + public void setLegWallHeatTransferCoefficients(double[] coefs); + + /** + *+ * setEquipmentGeometry. + *
+ * + * @param equipmentGeometry an array of + * {@link neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface} objects + */ + public void setEquipmentGeometry(GeometryDefinitionInterface[] equipmentGeometry); + + /** + *+ * getTotalNumberOfNodes. + *
+ * + * @return a int + */ + public int getTotalNumberOfNodes(); + + /** + *+ * calcFluxes. + *
+ */ + public void calcFluxes(); + + /** + *+ * setEndPressure. + *
+ * + * @param inletPressure a double + */ + public void setEndPressure(double inletPressure); + + /** + *+ * setInletThermoSystem. + *
+ * + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + public void setInletThermoSystem(SystemInterface thermoSystem); + + /** + *+ * solveSteadyState. + *
+ * + * @param type a int 1: just mass, 2: mass and energy, 3: mass, energy and energy impulse and + * components + */ + public default void solveSteadyState(int type) { + solveSteadyState(type, UUID.randomUUID()); + } + + /** + *+ * solveSteadyState. + *
+ * + * @param type a int 1: just mass, 2: mass and energy, 3: mass, energy and energy impulse and + * components + * @param id Calculation identifier + */ + public void solveSteadyState(int type, UUID id); + + /** + *+ * getFlowNodes. + *
+ * + * @return an array of {@link neqsim.fluidMechanics.flowNode.FlowNodeInterface} objects + */ + public FlowNodeInterface[] getFlowNodes(); + + /** + *+ * print. + *
+ */ + public void print(); + + /** + *+ * setLegOuterTemperatures. + *
+ * + * @param temps an array of {@link double} objects + */ + public void setLegOuterTemperatures(double[] temps); + + /** + *+ * getTotalMolarMassTransferRate. + *
+ * + * @param component a int + * @return a double + */ + public double getTotalMolarMassTransferRate(int component); + + /** + *+ * getTotalMolarMassTransferRate. + *
+ * + * @param component a int + * @param lastNode a int + * @return a double + */ + public double getTotalMolarMassTransferRate(int component, int lastNode); + + /** + *+ * getTotalPressureDrop. + *
+ * + * @return a double + */ + public double getTotalPressureDrop(); + + /** + *+ * getTotalPressureDrop. + *
+ * + * @param lastNode a int + * @return a double + */ + public double getTotalPressureDrop(int lastNode); + + /** + *+ * setInitialFlowPattern. + *
+ * + * @param flowPattern a {@link java.lang.String} object + */ + public void setInitialFlowPattern(String flowPattern); + + /** + *+ * setFlowPattern. + *
+ * + * @param flowPattern a {@link java.lang.String} object + */ + public void setFlowPattern(String flowPattern); + + /** + *+ * setEquilibriumMassTransfer. + *
+ * + * @param test a boolean + */ + public void setEquilibriumMassTransfer(boolean test); + + /** + *+ * setEquilibriumHeatTransfer. + *
+ * + * @param test a boolean + */ + public void setEquilibriumHeatTransfer(boolean test); } diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystem.java b/src/main/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystem.java index a8534d2d0e..c54558ced2 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystem.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystem.java @@ -1,5 +1,6 @@ package neqsim.fluidMechanics.flowSystem.onePhaseFlowSystem.pipeFlowSystem; +import java.util.UUID; import neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.onePhaseFlowVisualization.pipeFlowVisualization.PipeFlowVisualization; import neqsim.thermo.system.SystemInterface; @@ -12,99 +13,99 @@ * @version $Id: $Id */ public class PipeFlowSystem - extends neqsim.fluidMechanics.flowSystem.onePhaseFlowSystem.OnePhaseFlowSystem { - private static final long serialVersionUID = 1000; + extends neqsim.fluidMechanics.flowSystem.onePhaseFlowSystem.OnePhaseFlowSystem { + private static final long serialVersionUID = 1000; - /** - *- * Constructor for PipeFlowSystem. - *
- */ - public PipeFlowSystem() {} + /** + *+ * Constructor for PipeFlowSystem. + *
+ */ + public PipeFlowSystem() {} - /** {@inheritDoc} */ - @Override - public void createSystem() { - thermoSystem.init(0); - thermoSystem.init(1); - flowLeg = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg[this.getNumberOfLegs()]; + /** {@inheritDoc} */ + @Override + public void createSystem() { + thermoSystem.init(0); + thermoSystem.init(1); + flowLeg = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg[this.getNumberOfLegs()]; - for (int i = 0; i < getNumberOfLegs(); i++) { - flowLeg[i] = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg(); - } - - flowNode = - new neqsim.fluidMechanics.flowNode.onePhaseNode.onePhasePipeFlowNode.onePhasePipeFlowNode[totalNumberOfNodes]; - // System.out.println("nodes: " + totalNumberOfNodes); - flowNode[0] = - new neqsim.fluidMechanics.flowNode.onePhaseNode.onePhasePipeFlowNode.onePhasePipeFlowNode( - thermoSystem, this.equipmentGeometry[0]); - flowNode[0].initFlowCalc(); - super.createSystem(); - this.setNodes(); + for (int i = 0; i < getNumberOfLegs(); i++) { + flowLeg[i] = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg(); } - /** {@inheritDoc} */ - @Override - public void init() { - for (int j = 0; j < getTotalNumberOfNodes(); j++) { - flowNode[j].initFlowCalc(); - flowNode[j].setVelocityIn(this.flowNode[j].getVelocity()); - } + flowNode = + new neqsim.fluidMechanics.flowNode.onePhaseNode.onePhasePipeFlowNode.onePhasePipeFlowNode[totalNumberOfNodes]; + // System.out.println("nodes: " + totalNumberOfNodes); + flowNode[0] = + new neqsim.fluidMechanics.flowNode.onePhaseNode.onePhasePipeFlowNode.onePhasePipeFlowNode( + thermoSystem, this.equipmentGeometry[0]); + flowNode[0].initFlowCalc(); + super.createSystem(); + this.setNodes(); + } - for (int k = 0; k < getTotalNumberOfNodes() - 1; k++) { - this.flowNode[k].setVelocityOut(this.flowNode[k + 1].getVelocityIn()); - } + /** {@inheritDoc} */ + @Override + public void init() { + for (int j = 0; j < getTotalNumberOfNodes(); j++) { + flowNode[j].initFlowCalc(); + flowNode[j].setVelocityIn(this.flowNode[j].getVelocity()); } - /** {@inheritDoc} */ - @Override - public void solveSteadyState(int solverType) { // should set solve-type: int 1-bare masse og - // impuls 2 energi og - // impuls 3 energi impuls og komponenter - double[] times = {0.0}; - display = new PipeFlowVisualization(this.getTotalNumberOfNodes(), 1); - getTimeSeries().setTimes(times); - SystemInterface[] systems = {flowNode[0].getBulkSystem()}; - getTimeSeries().setInletThermoSystems(systems); - getTimeSeries().setNumberOfTimeStepsInInterval(1); - double[] outletFlowRates = {0.0, 0.0}; // this is not yet implemented - getTimeSeries().setOutletMolarFlowRate(outletFlowRates); - // SteadystateOnePhasePipeFlowSolver pipeSolve = new - // SteadystateOnePhasePipeFlowSolver(this, getSystemLength(), - // getTotalNumberOfNodes()); - flowSolver = - new neqsim.fluidMechanics.flowSolver.onePhaseFlowSolver.onePhasePipeFlowSolver.OnePhaseFixedStaggeredGrid( - this, getSystemLength(), getTotalNumberOfNodes(), false); - flowSolver.setSolverType(solverType); - flowSolver.solveTDMA(); - getTimeSeries().init(this); - display.setNextData(this); + for (int k = 0; k < getTotalNumberOfNodes() - 1; k++) { + this.flowNode[k].setVelocityOut(this.flowNode[k + 1].getVelocityIn()); } + } + + /** {@inheritDoc} */ + @Override + public void solveSteadyState(int type, UUID id) { + double[] times = {0.0}; + display = new PipeFlowVisualization(this.getTotalNumberOfNodes(), 1); + getTimeSeries().setTimes(times); + SystemInterface[] systems = {flowNode[0].getBulkSystem()}; + getTimeSeries().setInletThermoSystems(systems); + getTimeSeries().setNumberOfTimeStepsInInterval(1); + double[] outletFlowRates = {0.0, 0.0}; // this is not yet implemented + getTimeSeries().setOutletMolarFlowRate(outletFlowRates); + // SteadystateOnePhasePipeFlowSolver pipeSolve = new + // SteadystateOnePhasePipeFlowSolver(this, getSystemLength(), + // getTotalNumberOfNodes()); + flowSolver = + new neqsim.fluidMechanics.flowSolver.onePhaseFlowSolver.onePhasePipeFlowSolver.OnePhaseFixedStaggeredGrid( + this, getSystemLength(), getTotalNumberOfNodes(), false); + flowSolver.setSolverType(type); + flowSolver.solveTDMA(); + getTimeSeries().init(this); + display.setNextData(this); + calcIdentifier = id; + } - /** {@inheritDoc} */ - @Override - public void solveTransient(int solverType) { - getTimeSeries().init(this); - display = new PipeFlowVisualization(this.getTotalNumberOfNodes(), - getTimeSeries().getTime().length); - flowSolver.setDynamic(true); - flowSolver.setSolverType(solverType); - for (int i = 0; i < this.getTimeSeries().getTime().length; i++) { - getNode(0).setBulkSystem(this.getTimeSeries().getThermoSystem()[i]); - // getNode(0).getBulkSystem().setPressure(); - getNode(0).initFlowCalc(); - getNode(0).setVelocityIn(getNode(0).getVelocity()); - flowNode[0].setVelocityOut(this.flowNode[0].getVelocity()); - // flowNode[1].setVelocityIn(this.flowNode[0].getVelocity()); - // flowNode[getTotalNumberOfNodes()-1].setVelocity(this.getTimeSeries().getOutletMolarFlowRates()[i]); - System.out.println("vel: " + this.flowNode[0].getVelocity()); - getSolver().setTimeStep(this.getTimeSeries().getTimeStep()[i]); - // System.out.println("time step: " + i + " " + - // this.getTimeSeries().getTimeStep()[i]); - // System.out.println("time: " + i + " " + this.getTimeSeries().getTime()[i]); - // flowSolver.solveTDMA(); - display.setNextData(this, this.getTimeSeries().getTime(i)); - } + /** {@inheritDoc} */ + @Override + public void solveTransient(int type, UUID id) { + getTimeSeries().init(this); + display = + new PipeFlowVisualization(this.getTotalNumberOfNodes(), getTimeSeries().getTime().length); + flowSolver.setDynamic(true); + flowSolver.setSolverType(type); + for (int i = 0; i < this.getTimeSeries().getTime().length; i++) { + getNode(0).setBulkSystem(this.getTimeSeries().getThermoSystem()[i]); + // getNode(0).getBulkSystem().setPressure(); + getNode(0).initFlowCalc(); + getNode(0).setVelocityIn(getNode(0).getVelocity()); + flowNode[0].setVelocityOut(this.flowNode[0].getVelocity()); + // flowNode[1].setVelocityIn(this.flowNode[0].getVelocity()); + // flowNode[getTotalNumberOfNodes()-1].setVelocity(this.getTimeSeries().getOutletMolarFlowRates()[i]); + System.out.println("vel: " + this.flowNode[0].getVelocity()); + getSolver().setTimeStep(this.getTimeSeries().getTimeStep()[i]); + // System.out.println("time step: " + i + " " + + // this.getTimeSeries().getTimeStep()[i]); + // System.out.println("time: " + i + " " + this.getTimeSeries().getTime()[i]); + // flowSolver.solveTDMA(); + display.setNextData(this, this.getTimeSeries().getTime(i)); } + calcIdentifier = id; + } } diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/shipSystem/LNGship.java b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/shipSystem/LNGship.java index 58aae622a4..bd6d4b4336 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/shipSystem/LNGship.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/shipSystem/LNGship.java @@ -1,6 +1,7 @@ package neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.shipSystem; import java.text.DecimalFormat; +import java.util.UUID; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import neqsim.standards.StandardInterface; @@ -19,571 +20,568 @@ * @version $Id: $Id */ public class LNGship - extends neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.TwoPhaseFlowSystem { - private static final long serialVersionUID = 1000; - - double[] temperature = null; - double dailyBoilOffRatio = 0.005, totalTankVolume = 140000; - private double liquidDensity = 0.7; - int numberOffTimeSteps = 100; - private double initialTemperature = 111.0; - private boolean setInitialTemperature = false; - private neqsim.thermo.system.SystemInterface thermoSystem = null; - double initialNumberOffMoles; - double molarBoilOffRate = 0.0, dailyBoilOffVolume = 0.0; - private double endTime = 960;// 24.0 * 10; - private Standard_ISO6976 standardISO6976 = null; - StandardInterface standardDensity = null; - double[] WI = null, density = null, volume = null, xmethane, xethane, xpropane, xiC4, xnC4, - xiC5, xnC5, xnC6, xnitrogen; - double[] ymethane, yethane, ypropane, yiC4, ynC4, yiC5, ynC5, ynC6, ynitrogen; - double[] GCV, GCVmass, totalEnergy; - double[] time; - double[] tankTemperature = null; - double timeStep = 0; - private String[][] resultTable = null; - private boolean backCalculate = false; - double endVolume = 0.0; - static Logger logger = LogManager.getLogger(LNGship.class); - - /** - *- * Constructor for LNGship. - *
- * - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - * @param totalTankVolume a double - * @param dailyBoilOffRatio a double - */ - public LNGship(neqsim.thermo.system.SystemInterface thermoSystem, double totalTankVolume, - double dailyBoilOffRatio) { - this.thermoSystem = thermoSystem; - this.totalTankVolume = totalTankVolume; - this.dailyBoilOffRatio = dailyBoilOffRatio; - - setStandardISO6976(new Standard_ISO6976_2016(thermoSystem, 0, 25, "volume")); + extends neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.TwoPhaseFlowSystem { + private static final long serialVersionUID = 1000; + + double[] temperature = null; + double dailyBoilOffRatio = 0.005, totalTankVolume = 140000; + private double liquidDensity = 0.7; + int numberOffTimeSteps = 100; + private double initialTemperature = 111.0; + private boolean setInitialTemperature = false; + private neqsim.thermo.system.SystemInterface thermoSystem = null; + double initialNumberOffMoles; + double molarBoilOffRate = 0.0, dailyBoilOffVolume = 0.0; + private double endTime = 960;// 24.0 * 10; + private Standard_ISO6976 standardISO6976 = null; + StandardInterface standardDensity = null; + double[] WI = null, density = null, volume = null, xmethane, xethane, xpropane, xiC4, xnC4, xiC5, + xnC5, xnC6, xnitrogen; + double[] ymethane, yethane, ypropane, yiC4, ynC4, yiC5, ynC5, ynC6, ynitrogen; + double[] GCV, GCVmass, totalEnergy; + double[] time; + double[] tankTemperature = null; + double timeStep = 0; + private String[][] resultTable = null; + private boolean backCalculate = false; + double endVolume = 0.0; + static Logger logger = LogManager.getLogger(LNGship.class); + + /** + *+ * Constructor for LNGship. + *
+ * + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + * @param totalTankVolume a double + * @param dailyBoilOffRatio a double + */ + public LNGship(neqsim.thermo.system.SystemInterface thermoSystem, double totalTankVolume, + double dailyBoilOffRatio) { + this.thermoSystem = thermoSystem; + this.totalTankVolume = totalTankVolume; + this.dailyBoilOffRatio = dailyBoilOffRatio; + + setStandardISO6976(new Standard_ISO6976_2016(thermoSystem, 0, 25, "volume")); + } + + /** + *+ * useStandardVersion. + *
+ * + * @param isoName a {@link java.lang.String} object + * @param version a {@link java.lang.String} object + */ + public void useStandardVersion(String isoName, String version) { + if (version.equals("2016")) { + setStandardISO6976(new Standard_ISO6976(thermoSystem, getStandardISO6976().getVolRefT(), + getStandardISO6976().getEnergyRefT(), "volume")); + logger.info("using ISO6976 version 2016"); + } else { + setStandardISO6976(new Standard_ISO6976_2016(thermoSystem, getStandardISO6976().getVolRefT(), + getStandardISO6976().getEnergyRefT(), "volume")); + logger.info("using ISO6976 version 1995"); } - - /** - *- * useStandardVersion. - *
- * - * @param isoName a {@link java.lang.String} object - * @param version a {@link java.lang.String} object - */ - public void useStandardVersion(String isoName, String version) { - if (version.equals("2016")) { - setStandardISO6976(new Standard_ISO6976(thermoSystem, getStandardISO6976().getVolRefT(), - getStandardISO6976().getEnergyRefT(), "volume")); - logger.info("using ISO6976 version 2016"); - } else { - setStandardISO6976( - new Standard_ISO6976_2016(thermoSystem, getStandardISO6976().getVolRefT(), - getStandardISO6976().getEnergyRefT(), "volume")); - logger.info("using ISO6976 version 1995"); - } + } + + /** {@inheritDoc} */ + @Override + public void createSystem() { + getThermoSystem().init(0); + thermoOperations = new ThermodynamicOperations(getThermoSystem()); + try { + if (isSetInitialTemperature()) { + getThermoSystem().setTemperature(getInitialTemperature()); + } else { + thermoOperations.bubblePointTemperatureFlash(); + } + } catch (Exception e) { + e.printStackTrace(); } + getThermoSystem().init(0); - /** {@inheritDoc} */ - @Override - public void createSystem() { - getThermoSystem().init(0); - thermoOperations = new ThermodynamicOperations(getThermoSystem()); - try { - if (isSetInitialTemperature()) { - getThermoSystem().setTemperature(getInitialTemperature()); - } else { - thermoOperations.bubblePointTemperatureFlash(); - } - } catch (Exception e) { - e.printStackTrace(); - } - getThermoSystem().init(0); + standardDensity = new Standard_ISO6578(getThermoSystem()); + standardDensity.calculate(); - standardDensity = new Standard_ISO6578(getThermoSystem()); - standardDensity.calculate(); + liquidDensity = standardDensity.getValue("density"); + logger.info("density start " + standardDensity.getValue("density")); + timeStep = getEndTime() / (numberOffTimeSteps * 1.0 - 1.0); + dailyBoilOffVolume = totalTankVolume * dailyBoilOffRatio; - liquidDensity = standardDensity.getValue("density"); - logger.info("density start " + standardDensity.getValue("density")); - timeStep = getEndTime() / (numberOffTimeSteps * 1.0 - 1.0); - dailyBoilOffVolume = totalTankVolume * dailyBoilOffRatio; + logger.info("daily boiloff volume " + dailyBoilOffVolume); + initialNumberOffMoles = + totalTankVolume * getLiquidDensity() / getThermoSystem().getPhase(1).getMolarMass(); + double oldMoles = getThermoSystem().getTotalNumberOfMoles(); - logger.info("daily boiloff volume " + dailyBoilOffVolume); - initialNumberOffMoles = - totalTankVolume * getLiquidDensity() / getThermoSystem().getPhase(1).getMolarMass(); - double oldMoles = getThermoSystem().getTotalNumberOfMoles(); - - for (int i = 0; i < getThermoSystem().getPhase(0).getNumberOfComponents(); i++) { - getThermoSystem().addComponent(getThermoSystem().getPhase(0).getComponent(i).getName(), - (initialNumberOffMoles - oldMoles) - * getThermoSystem().getPhase(0).getComponent(i).getz()); - } + for (int i = 0; i < getThermoSystem().getPhase(0).getNumberOfComponents(); i++) { + getThermoSystem().addComponent(getThermoSystem().getPhase(0).getComponent(i).getName(), + (initialNumberOffMoles - oldMoles) + * getThermoSystem().getPhase(0).getComponent(i).getz()); } - - /** {@inheritDoc} */ - @Override - public void init() {} - - /** {@inheritDoc} */ - @Override - public void solveSteadyState(int solverType) { - try { - if (!isSetInitialTemperature()) { - thermoOperations.bubblePointTemperatureFlash(); - } - } catch (Exception e) { - e.printStackTrace(); - } - logger.info("temperature start " + getThermoSystem().getTemperature()); + } + + /** {@inheritDoc} */ + @Override + public void init() {} + + /** {@inheritDoc} */ + @Override + public void solveSteadyState(int type, UUID id) { + // todo: double[] times = {0.0}; ? + try { + if (!isSetInitialTemperature()) { + thermoOperations.bubblePointTemperatureFlash(); + } + } catch (Exception e) { + e.printStackTrace(); } - - /** {@inheritDoc} */ - @Override - public void solveTransient(int type) { - SystemInterface tempThermoSystem = getThermoSystem().clone(); - WI = new double[numberOffTimeSteps]; - GCV = new double[numberOffTimeSteps]; - GCVmass = new double[numberOffTimeSteps]; - totalEnergy = new double[numberOffTimeSteps]; - time = new double[numberOffTimeSteps]; - density = new double[numberOffTimeSteps]; - tankTemperature = new double[numberOffTimeSteps]; - volume = new double[numberOffTimeSteps]; - - xnitrogen = new double[numberOffTimeSteps]; - xmethane = new double[numberOffTimeSteps]; - xethane = new double[numberOffTimeSteps]; - xpropane = new double[numberOffTimeSteps]; - xiC4 = new double[numberOffTimeSteps]; - xnC4 = new double[numberOffTimeSteps]; - xiC5 = new double[numberOffTimeSteps]; - xnC5 = new double[numberOffTimeSteps]; - xnC6 = new double[numberOffTimeSteps]; - - ynitrogen = new double[numberOffTimeSteps]; - ymethane = new double[numberOffTimeSteps]; - yethane = new double[numberOffTimeSteps]; - ypropane = new double[numberOffTimeSteps]; - yiC4 = new double[numberOffTimeSteps]; - ynC4 = new double[numberOffTimeSteps]; - yiC5 = new double[numberOffTimeSteps]; - ynC5 = new double[numberOffTimeSteps]; - ynC6 = new double[numberOffTimeSteps]; - - double error = 100.0; - double mulitplicator = 1.0; - if (backCalculate) { - mulitplicator = -1.0; - } - endVolume = totalTankVolume - mulitplicator * dailyBoilOffVolume * getEndTime() / 24.0; - molarBoilOffRate = dailyBoilOffVolume * liquidDensity - / getThermoSystem().getPhase(1).getMolarMass() / 24.0 * timeStep; - if (backCalculate) { - molarBoilOffRate = -molarBoilOffRate; - } - // double orginalMolarBoilOff = molarBoilOffRate; - logger.info("end Volume " + endVolume); - int iterations = 0; - double boilOffCorrection = 0.0; - do { - setThermoSystem(tempThermoSystem.clone()); - thermoOperations = new ThermodynamicOperations(getThermoSystem()); - standardDensity = new Standard_ISO6578(getThermoSystem()); - getStandardISO6976().setThermoSystem(getThermoSystem()); - iterations++; - for (int j = 0; j < numberOffTimeSteps; j++) { - time[j] = j * timeStep; - try { - if (!(j == 0 && isSetInitialTemperature())) { - thermoOperations.bubblePointTemperatureFlash(); - } - } catch (Exception e) { - e.printStackTrace(); - } - double[] xgas = new double[getThermoSystem().getPhase(0).getNumberOfComponents()]; - - for (int kk = 0; kk < getThermoSystem().getPhase(0).getNumberOfComponents(); kk++) { - xgas[kk] = getThermoSystem().getPhase(0).getComponent(kk).getx(); - } - - if (getThermoSystem().getPhase(0).hasComponent("nitrogen")) { - xnitrogen[j] = getThermoSystem().getPhase(1).getComponent("nitrogen").getx(); - ynitrogen[j] = getThermoSystem().getPhase(0).getComponent("nitrogen").getx(); - } - if (getThermoSystem().getPhase(0).hasComponent("methane")) { - xmethane[j] = getThermoSystem().getPhase(1).getComponent("methane").getx(); - ymethane[j] = getThermoSystem().getPhase(0).getComponent("methane").getx(); - } - if (getThermoSystem().getPhase(0).hasComponent("ethane")) { - xethane[j] = getThermoSystem().getPhase(1).getComponent("ethane").getx(); - yethane[j] = getThermoSystem().getPhase(0).getComponent("ethane").getx(); - } - if (getThermoSystem().getPhase(0).hasComponent("propane")) { - xpropane[j] = getThermoSystem().getPhase(1).getComponent("propane").getx(); - ypropane[j] = getThermoSystem().getPhase(0).getComponent("propane").getx(); - } - if (getThermoSystem().getPhase(0).hasComponent("i-butane")) { - xiC4[j] = getThermoSystem().getPhase(1).getComponent("i-butane").getx(); - yiC4[j] = getThermoSystem().getPhase(0).getComponent("i-butane").getx(); - } - if (getThermoSystem().getPhase(0).hasComponent("n-butane")) { - xnC4[j] = getThermoSystem().getPhase(1).getComponent("n-butane").getx(); - ynC4[j] = getThermoSystem().getPhase(0).getComponent("n-butane").getx(); - } - if (getThermoSystem().getPhase(0).hasComponent("i-pentane")) { - xiC5[j] = getThermoSystem().getPhase(1).getComponent("i-pentane").getx(); - yiC5[j] = getThermoSystem().getPhase(0).getComponent("i-pentane").getx(); - } - if (getThermoSystem().getPhase(0).hasComponent("n-pentane")) { - xnC5[j] = getThermoSystem().getPhase(1).getComponent("n-pentane").getx(); - ynC5[j] = getThermoSystem().getPhase(0).getComponent("n-pentane").getx(); - } - if (getThermoSystem().getPhase(0).hasComponent("n-hexane")) { - xnC6[j] = getThermoSystem().getPhase(1).getComponent("n-hexane").getx(); - ynC6[j] = getThermoSystem().getPhase(0).getComponent("n-hexane").getx(); - } - // System.out.println("time " + time[j] + " Superior Wobbe " + - // getStandardISO6976().getValue("SuperiorWobbeIndex") + " temperature " + - // getThermoSystem().getTemperature() + " density " + density[j] + " volume " + - // volume[j] + " total energy " + totalEnergy[j]); - getThermoSystem().init(0); - - standardDensity.calculate(); - density[j] = standardDensity.getValue("density"); - getStandardISO6976().calculate(); - // getStandardISO6976().display(""); - WI[j] = getStandardISO6976().getValue("SuperiorWobbeIndex"); - GCV[j] = getStandardISO6976().getValue("SuperiorCalorificValue"); - - tankTemperature[j] = getThermoSystem().getTemperature(); - volume[j] = getThermoSystem().getNumberOfMoles() - * getThermoSystem().getPhase(1).getMolarMass() / density[j];// density[0]; - - this.standardISO6976.setReferenceType("mass"); - totalEnergy[j] = getStandardISO6976().getValue("SuperiorCalorificValue") * volume[j] - * density[j]; - GCVmass[j] = getStandardISO6976().getValue("SuperiorCalorificValue"); - this.standardISO6976.setReferenceType("volume"); - - for (int i = 0; i < getThermoSystem().getPhase(0).getNumberOfComponents(); i++) { - getThermoSystem().addComponent( - getThermoSystem().getPhase(0).getComponent(i).getName(), - -xgas[i] * molarBoilOffRate); - } - } - double oldVolume = 0; - double oldoldVolume = oldVolume; - oldVolume = volume[0] - volume[numberOffTimeSteps - 1]; - double oldmolarBoilOffRate = 0; - double oldoldmolarBoilOffRate = oldmolarBoilOffRate; - oldmolarBoilOffRate = molarBoilOffRate; - error = volume[numberOffTimeSteps - 1] / endVolume - 1.0; - double derrordn = - (oldVolume - oldoldVolume) / (oldmolarBoilOffRate - oldoldmolarBoilOffRate); - boilOffCorrection = (volume[numberOffTimeSteps - 1] - endVolume) / derrordn; - if (iterations > 1) { - molarBoilOffRate += boilOffCorrection;// (volume[numberOffTimeSteps - 1] - - // endVolume) / derrordn; - } else { - molarBoilOffRate = molarBoilOffRate * volume[numberOffTimeSteps - 1] / endVolume; - } - // logger.info("error " + error + " iteration " + iterations + " molarboiloff " - // + molarBoilOffRate + " endVolume " + endVolume + " orginalMolarBoilOff " + - // orginalMolarBoilOff); - } while (Math.abs(error) > 1e-8 && iterations < 100); + logger.info("temperature start " + getThermoSystem().getTemperature()); + // todo: getTimeSeries().init(this); + calcIdentifier = id; + } + + /** {@inheritDoc} */ + @Override + public void solveTransient(int type, UUID id) { + SystemInterface tempThermoSystem = getThermoSystem().clone(); + WI = new double[numberOffTimeSteps]; + GCV = new double[numberOffTimeSteps]; + GCVmass = new double[numberOffTimeSteps]; + totalEnergy = new double[numberOffTimeSteps]; + time = new double[numberOffTimeSteps]; + density = new double[numberOffTimeSteps]; + tankTemperature = new double[numberOffTimeSteps]; + volume = new double[numberOffTimeSteps]; + + xnitrogen = new double[numberOffTimeSteps]; + xmethane = new double[numberOffTimeSteps]; + xethane = new double[numberOffTimeSteps]; + xpropane = new double[numberOffTimeSteps]; + xiC4 = new double[numberOffTimeSteps]; + xnC4 = new double[numberOffTimeSteps]; + xiC5 = new double[numberOffTimeSteps]; + xnC5 = new double[numberOffTimeSteps]; + xnC6 = new double[numberOffTimeSteps]; + + ynitrogen = new double[numberOffTimeSteps]; + ymethane = new double[numberOffTimeSteps]; + yethane = new double[numberOffTimeSteps]; + ypropane = new double[numberOffTimeSteps]; + yiC4 = new double[numberOffTimeSteps]; + ynC4 = new double[numberOffTimeSteps]; + yiC5 = new double[numberOffTimeSteps]; + ynC5 = new double[numberOffTimeSteps]; + ynC6 = new double[numberOffTimeSteps]; + + double error = 100.0; + double mulitplicator = 1.0; + if (backCalculate) { + mulitplicator = -1.0; + } + endVolume = totalTankVolume - mulitplicator * dailyBoilOffVolume * getEndTime() / 24.0; + molarBoilOffRate = dailyBoilOffVolume * liquidDensity + / getThermoSystem().getPhase(1).getMolarMass() / 24.0 * timeStep; + if (backCalculate) { + molarBoilOffRate = -molarBoilOffRate; + } + // double orginalMolarBoilOff = molarBoilOffRate; + logger.info("end Volume " + endVolume); + int iterations = 0; + double boilOffCorrection = 0.0; + do { + setThermoSystem(tempThermoSystem.clone()); + thermoOperations = new ThermodynamicOperations(getThermoSystem()); + standardDensity = new Standard_ISO6578(getThermoSystem()); + getStandardISO6976().setThermoSystem(getThermoSystem()); + iterations++; + for (int j = 0; j < numberOffTimeSteps; j++) { + time[j] = j * timeStep; try { + if (!(j == 0 && isSetInitialTemperature())) { thermoOperations.bubblePointTemperatureFlash(); + } } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); } - } + double[] xgas = new double[getThermoSystem().getPhase(0).getNumberOfComponents()]; - /** - *
- * Getter for the field resultTable
.
- *
- * getResults. - *
- * - * @param name a {@link java.lang.String} object - * @return an array of {@link java.lang.String} objects - */ - public String[][] getResults(String name) { - String[][] table = new String[numberOffTimeSteps + 1][26]; - String[] names = {"Time", "temperature", "WI", "GCV", "density", "volume", "energy"}; - - for (int i = 0; i < 13; i++) { - for (int j = 0; j < numberOffTimeSteps + 1; j++) { - table[j][i] = ""; - } + for (int kk = 0; kk < getThermoSystem().getPhase(0).getNumberOfComponents(); kk++) { + xgas[kk] = getThermoSystem().getPhase(0).getComponent(kk).getx(); } - System.arraycopy(names, 0, table[0], 0, 7); - - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(5); - - for (int j = 0; j < numberOffTimeSteps; j++) { - table[j + 1][0] = nf.format(time[j]); - table[j + 1][1] = nf.format(tankTemperature[j] - 273.15); - table[j + 1][2] = nf.format(WI[j] / 1000.0); - table[j + 1][3] = nf.format(GCV[j] / 1000.0); - table[j + 1][4] = nf.format(density[j]); - table[j + 1][5] = nf.format(volume[j]); - table[j + 1][15] = nf.format(totalEnergy[j] / 1000.0); - - table[j + 1][6] = nf.format(xmethane[j]); - table[j + 1][7] = nf.format(xethane[j]); - table[j + 1][8] = nf.format(xpropane[j]); - table[j + 1][9] = nf.format(xiC4[j]); - table[j + 1][10] = nf.format(xnC4[j]); - table[j + 1][11] = nf.format(xiC5[j]); - table[j + 1][12] = nf.format(xnC5[j]); - table[j + 1][13] = nf.format(xnC6[j]); - table[j + 1][14] = nf.format(xnitrogen[j]); - - table[j + 1][16] = nf.format(GCVmass[j] / 1000.0); - - table[j + 1][17] = nf.format(ymethane[j]); - table[j + 1][18] = nf.format(yethane[j]); - table[j + 1][19] = nf.format(ypropane[j]); - table[j + 1][20] = nf.format(yiC4[j]); - table[j + 1][21] = nf.format(ynC4[j]); - table[j + 1][22] = nf.format(yiC5[j]); - table[j + 1][23] = nf.format(ynC5[j]); - table[j + 1][24] = nf.format(ynC6[j]); - table[j + 1][25] = nf.format(ynitrogen[j]); + if (getThermoSystem().getPhase(0).hasComponent("nitrogen")) { + xnitrogen[j] = getThermoSystem().getPhase(1).getComponent("nitrogen").getx(); + ynitrogen[j] = getThermoSystem().getPhase(0).getComponent("nitrogen").getx(); } - setResultTable(table); - - /* - * // for (int i = 0; i < 4; i++) { for (int j = 0; j < numberOffTimeSteps + 1; j++) { - * logger.info(resultTable[j][25]); logger.info(resultTable[j][14]); } //// } - */ - return table; - } - - /** - *- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - // thermo.system.SystemInterface testSystem = new - // thermo.system.SystemGERG2004Eos(273.15 - 161.4, 1.0); - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos(273.15 - 161.4, 1.013); - /* - * testSystem.addComponent("nitrogen", 0.0136); testSystem.addComponent("methane", 0.9186); - * testSystem.addComponent("ethane", 0.0526); testSystem.addComponent("propane", 0.0115); - */ - testSystem.addComponent("nitrogen", 0.691);// 0.93041); - testSystem.addComponent("methane", 91.93);// 92.637); - testSystem.addComponent("ethane", 5.651);// 4.876); - testSystem.addComponent("propane", 1.296);// 1.093); - testSystem.addComponent("i-butane", 0.122); - testSystem.addComponent("n-butane", 0.289); - testSystem.addComponent("i-pentane", 0.018); - testSystem.addComponent("n-pentane", 0.003); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - - neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.shipSystem.LNGship ship = - new neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.shipSystem.LNGship( - testSystem, 140000, 0.0015); - // ship.setInitialTemperature(111.0); - // ship.useStandardVersion("","2016"); - ship.useStandardVersion("", "2016"); - ship.getStandardISO6976().setEnergyRefT(15); - ship.getStandardISO6976().setVolRefT(15); - ship.createSystem(); - ship.init(); - // ship.setBackCalculate(true); - ship.solveSteadyState(0); - ship.solveTransient(0); - ship.getResults("test"); - ship.getThermoSystem().display(); - } - - /** - *
- * Setter for the field resultTable
.
- *
- * Getter for the field liquidDensity
.
- *
- * Setter for the field liquidDensity
.
- *
- * Getter for the field endTime
.
- *
- * Setter for the field endTime
.
- *
- * Getter for the field standardISO6976
.
- *
- * Setter for the field standardISO6976
.
- *
- * isBackCalculate. - *
- * - * @return the backCalculate - */ - public boolean isBackCalculate() { - return backCalculate; - } - - /** - *
- * Setter for the field backCalculate
.
- *
- * Getter for the field thermoSystem
.
- *
- * Setter for the field thermoSystem
.
- *
- * isSetInitialTemperature. - *
- * - * @return the setInitialTemperature - */ - public boolean isSetInitialTemperature() { - return setInitialTemperature; + for (int i = 0; i < getThermoSystem().getPhase(0).getNumberOfComponents(); i++) { + getThermoSystem().addComponent(getThermoSystem().getPhase(0).getComponent(i).getName(), + -xgas[i] * molarBoilOffRate); + } + } + double oldVolume = 0; + double oldoldVolume = oldVolume; + oldVolume = volume[0] - volume[numberOffTimeSteps - 1]; + double oldmolarBoilOffRate = 0; + double oldoldmolarBoilOffRate = oldmolarBoilOffRate; + oldmolarBoilOffRate = molarBoilOffRate; + error = volume[numberOffTimeSteps - 1] / endVolume - 1.0; + double derrordn = (oldVolume - oldoldVolume) / (oldmolarBoilOffRate - oldoldmolarBoilOffRate); + boilOffCorrection = (volume[numberOffTimeSteps - 1] - endVolume) / derrordn; + if (iterations > 1) { + molarBoilOffRate += boilOffCorrection;// (volume[numberOffTimeSteps - 1] - + // endVolume) / derrordn; + } else { + molarBoilOffRate = molarBoilOffRate * volume[numberOffTimeSteps - 1] / endVolume; + } + // logger.info("error " + error + " iteration " + iterations + " molarboiloff " + // + molarBoilOffRate + " endVolume " + endVolume + " orginalMolarBoilOff " + + // orginalMolarBoilOff); + } while (Math.abs(error) > 1e-8 && iterations < 100); + try { + thermoOperations.bubblePointTemperatureFlash(); + calcIdentifier = id; + } catch (Exception e) { + e.printStackTrace(); } - - /** - *
- * Setter for the field initialTemperature
.
- *
+ * Getter for the field resultTable
.
+ *
+ * getResults. + *
+ * + * @param name a {@link java.lang.String} object + * @return an array of {@link java.lang.String} objects + */ + public String[][] getResults(String name) { + String[][] table = new String[numberOffTimeSteps + 1][26]; + String[] names = {"Time", "temperature", "WI", "GCV", "density", "volume", "energy"}; + + for (int i = 0; i < 13; i++) { + for (int j = 0; j < numberOffTimeSteps + 1; j++) { + table[j][i] = ""; + } } - /** - *
- * Getter for the field initialTemperature
.
- *
- * Setter for the field initialTemperature
.
- *
+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + // thermo.system.SystemInterface testSystem = new + // thermo.system.SystemGERG2004Eos(273.15 - 161.4, 1.0); + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos(273.15 - 161.4, 1.013); + /* + * testSystem.addComponent("nitrogen", 0.0136); testSystem.addComponent("methane", 0.9186); + * testSystem.addComponent("ethane", 0.0526); testSystem.addComponent("propane", 0.0115); */ + testSystem.addComponent("nitrogen", 0.691);// 0.93041); + testSystem.addComponent("methane", 91.93);// 92.637); + testSystem.addComponent("ethane", 5.651);// 4.876); + testSystem.addComponent("propane", 1.296);// 1.093); + testSystem.addComponent("i-butane", 0.122); + testSystem.addComponent("n-butane", 0.289); + testSystem.addComponent("i-pentane", 0.018); + testSystem.addComponent("n-pentane", 0.003); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + + neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.shipSystem.LNGship ship = + new neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.shipSystem.LNGship(testSystem, + 140000, 0.0015); + // ship.setInitialTemperature(111.0); + // ship.useStandardVersion("","2016"); + ship.useStandardVersion("", "2016"); + ship.getStandardISO6976().setEnergyRefT(15); + ship.getStandardISO6976().setVolRefT(15); + ship.createSystem(); + ship.init(); + // ship.setBackCalculate(true); + ship.solveSteadyState(0); + ship.solveTransient(0); + ship.getResults("test"); + ship.getThermoSystem().display(); + } + + /** + *
+ * Setter for the field resultTable
.
+ *
+ * Getter for the field liquidDensity
.
+ *
+ * Setter for the field liquidDensity
.
+ *
+ * Getter for the field endTime
.
+ *
+ * Setter for the field endTime
.
+ *
+ * Getter for the field standardISO6976
.
+ *
+ * Setter for the field standardISO6976
.
+ *
+ * isBackCalculate. + *
+ * + * @return the backCalculate + */ + public boolean isBackCalculate() { + return backCalculate; + } + + /** + *
+ * Setter for the field backCalculate
.
+ *
+ * Getter for the field thermoSystem
.
+ *
+ * Setter for the field thermoSystem
.
+ *
+ * isSetInitialTemperature. + *
+ * + * @return the setInitialTemperature + */ + public boolean isSetInitialTemperature() { + return setInitialTemperature; + } + + /** + *
+ * Getter for the field initialTemperature
.
+ *
+ * Setter for the field initialTemperature
.
+ *
+ * Setter for the field initialTemperature
.
+ *
* TwoPhasePipeFlowSystem class. @@ -72,7 +74,7 @@ public void init() { /** {@inheritDoc} */ @Override - public void solveSteadyState(int solverType) { + public void solveSteadyState(int type, UUID id) { double[] times = {0.0}; display = new neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.twoPhaseFlowVisualization.twoPhasePipeFlowVisualization.TwoPhasePipeFlowVisualization( @@ -87,8 +89,9 @@ public void solveSteadyState(int solverType) { flowSolver = new neqsim.fluidMechanics.flowSolver.twoPhaseFlowSolver.twoPhasePipeFlowSolver.TwoPhaseFixedStaggeredGridSolver( this, getSystemLength(), this.getTotalNumberOfNodes(), false); - flowSolver.setSolverType(solverType); + flowSolver.setSolverType(type); flowSolver.solveTDMA(); + calcIdentifier = id; getTimeSeries().init(this); display.setNextData(this); @@ -96,10 +99,11 @@ public void solveSteadyState(int solverType) { /** {@inheritDoc} */ @Override - public void solveTransient(int type) { + public void solveTransient(int type, UUID id) { // pipeSolver pipeSolve = new pipeSolver(this, getSystemLength(), // getTotalNumberOfNodes()); // pipeSolve.solveTDMA(); + calcIdentifier = id; } /** diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhaseReactorFlowSystem/TwoPhaseReactorFlowSystem.java b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhaseReactorFlowSystem/TwoPhaseReactorFlowSystem.java index 4f28059db9..c56bcf52e4 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhaseReactorFlowSystem/TwoPhaseReactorFlowSystem.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/twoPhaseReactorFlowSystem/TwoPhaseReactorFlowSystem.java @@ -1,5 +1,6 @@ package neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.twoPhaseReactorFlowSystem; +import java.util.UUID; import neqsim.fluidMechanics.util.fluidMechanicsVisualization.flowSystemVisualization.twoPhaseFlowVisualization.twoPhasePipeFlowVisualization.TwoPhasePipeFlowVisualization; /** @@ -11,156 +12,157 @@ * @version $Id: $Id */ public class TwoPhaseReactorFlowSystem - extends neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.TwoPhaseFlowSystem { - private static final long serialVersionUID = 1000; - - /** - *
- * Constructor for TwoPhaseReactorFlowSystem. - *
- */ - public TwoPhaseReactorFlowSystem() {} - - /** {@inheritDoc} */ - @Override - public void createSystem() { - // thermoSystem.init(1); - flowLeg = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg[this.getNumberOfLegs()]; - - for (int i = 0; i < getNumberOfLegs(); i++) { - flowLeg[i] = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg(); - } - - flowNode = new neqsim.fluidMechanics.flowNode.FlowNodeInterface[totalNumberOfNodes]; - flowNode[0] = - new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.StratifiedFlowNode( - thermoSystem, equipmentGeometry[0]); - flowNode[totalNumberOfNodes - 1] = flowNode[0].getNextNode(); - - super.createSystem(); - this.setNodes(); + extends neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.TwoPhaseFlowSystem { + private static final long serialVersionUID = 1000; + + /** + *+ * Constructor for TwoPhaseReactorFlowSystem. + *
+ */ + public TwoPhaseReactorFlowSystem() {} + + /** {@inheritDoc} */ + @Override + public void createSystem() { + // thermoSystem.init(1); + flowLeg = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg[this.getNumberOfLegs()]; + + for (int i = 0; i < getNumberOfLegs(); i++) { + flowLeg[i] = new neqsim.fluidMechanics.flowLeg.pipeLeg.PipeLeg(); } - /** {@inheritDoc} */ - @Override - public void init() { - for (int j = 0; j < getTotalNumberOfNodes(); j++) { - flowNode[j].setInterphaseModelType(1); - flowNode[j].getGeometry();// setPackingType() - flowNode[j].initFlowCalc(); - flowNode[j].init(); - } - - for (int j = 0; j < getTotalNumberOfNodes(); j++) { - for (int phase = 0; phase < 2; phase++) { - flowNode[j].setVelocityOut(phase, this.flowNode[j].getVelocity(phase)); - } - } - - for (int k = 1; k < getTotalNumberOfNodes(); k++) { - for (int phase = 0; phase < 2; phase++) { - this.flowNode[k].setVelocityIn(phase, this.flowNode[k - 1].getVelocityOut(phase)); - } - } + flowNode = new neqsim.fluidMechanics.flowNode.FlowNodeInterface[totalNumberOfNodes]; + flowNode[0] = + new neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.StratifiedFlowNode( + thermoSystem, equipmentGeometry[0]); + flowNode[totalNumberOfNodes - 1] = flowNode[0].getNextNode(); + + super.createSystem(); + this.setNodes(); + } + + /** {@inheritDoc} */ + @Override + public void init() { + for (int j = 0; j < getTotalNumberOfNodes(); j++) { + flowNode[j].setInterphaseModelType(1); + flowNode[j].getGeometry();// setPackingType() + flowNode[j].initFlowCalc(); + flowNode[j].init(); } - /** {@inheritDoc} */ - @Override - public void solveSteadyState(int solverType) { - double[] times = {0.0}; - display = new TwoPhasePipeFlowVisualization(this.getTotalNumberOfNodes(), 1); - getTimeSeries().setTimes(times); - neqsim.thermo.system.SystemInterface[] systems = {flowNode[0].getBulkSystem()}; - getTimeSeries().setInletThermoSystems(systems); - getTimeSeries().setNumberOfTimeStepsInInterval(1); - double[] outletFlowRates = {0.0, 0.0}; - getTimeSeries().setOutletMolarFlowRate(outletFlowRates); - - flowSolver = - new neqsim.fluidMechanics.flowSolver.twoPhaseFlowSolver.twoPhasePipeFlowSolver.TwoPhaseFixedStaggeredGridSolver( - this, getSystemLength(), this.getTotalNumberOfNodes(), false); - flowSolver.setSolverType(solverType); - flowSolver.solveTDMA(); - getTimeSeries().init(this); - display.setNextData(this); + for (int j = 0; j < getTotalNumberOfNodes(); j++) { + for (int phase = 0; phase < 2; phase++) { + flowNode[j].setVelocityOut(phase, this.flowNode[j].getVelocity(phase)); + } } - /** {@inheritDoc} */ - @Override - public void solveTransient(int type) { - // pipeSolver pipeSolve = new pipeSolver(this, getSystemLength(), - // getTotalNumberOfNodes()); - // pipeSolve.solveTDMA(); + for (int k = 1; k < getTotalNumberOfNodes(); k++) { + for (int phase = 0; phase < 2; phase++) { + this.flowNode[k].setVelocityIn(phase, this.flowNode[k - 1].getVelocityOut(phase)); + } } - - /** - *- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - @SuppressWarnings("unused") - public static void main(String[] args) { - // Initierer et nyt rorsystem - neqsim.fluidMechanics.flowSystem.FlowSystemInterface pipe = new TwoPhaseReactorFlowSystem(); - - // Definerer termodyanmikken5 - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos(295.3, 5.0); // initierer - // et - // system - // som - // benytter - // SRK - // tilstandsligning - // med trykk 305.3 K og 125 bar - neqsim.thermodynamicOperations.ThermodynamicOperations testOps = - new neqsim.thermodynamicOperations.ThermodynamicOperations(testSystem); // gjor - // termodyanmiske - // Flash - // rutiner - // tilgjengelige - testSystem.addComponent("methane", 0.11152181, 0); - // testSystem.addComponent("ethane", 0.0011152181, 0); - testSystem.addComponent("water", 0.04962204876, 1); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - // benytter klassiske blandingsregler - - pipe.setInletThermoSystem(testSystem); // setter termodyanmikken for rorsystemet - pipe.setNumberOfLegs(5); // deler inn roret i et gitt antall legger - pipe.setNumberOfNodesInLeg(100); // setter antall nodepunkter (beregningspunkter/grid) pr. - // leg - double[] height = {0, 0, 0, 0, 0, 0}; - double[] length = {0.0, 1.7, 3.5, 5.0, 7.5, 10.4}; - double[] outerTemperature = - {278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 275.0, 275.0, 275.0, 275.0}; - - pipe.setLegHeights(height); // setter inn hoyde for hver leg-ende - pipe.setLegPositions(length); // setter avstand til hver leg-ende - pipe.setLegOuterTemperatures(outerTemperature); - - neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGemometry = - new neqsim.fluidMechanics.geometryDefinitions.reactor.ReactorData[5]; // Deffinerer - // geometrien - // for - // roret - double[] pipeDiameter = {0.02588, 0.02588, 0.02588, 0.02588, 0.02588}; - for (int i = 0; i < pipeDiameter.length; i++) { - pipeGemometry[i] = new neqsim.fluidMechanics.geometryDefinitions.reactor.ReactorData( - pipeDiameter[i], 1); - } - pipe.setEquipmentGeometry(pipeGemometry); // setter inn rorgeometrien for hver leg - // utforer bergninger - pipe.createSystem(); - pipe.init(); - - pipe.solveSteadyState(2); - // pipe.calcFluxes(); - // pipe.getDisplay().displayResult("temperature"); - // pipe.displayResults(); - // testOps.TPflash(); - // testOps.displayResult(); + } + + /** {@inheritDoc} */ + @Override + public void solveSteadyState(int type, UUID id) { + double[] times = {0.0}; + display = new TwoPhasePipeFlowVisualization(this.getTotalNumberOfNodes(), 1); + getTimeSeries().setTimes(times); + neqsim.thermo.system.SystemInterface[] systems = {flowNode[0].getBulkSystem()}; + getTimeSeries().setInletThermoSystems(systems); + getTimeSeries().setNumberOfTimeStepsInInterval(1); + double[] outletFlowRates = {0.0, 0.0}; + getTimeSeries().setOutletMolarFlowRate(outletFlowRates); + + flowSolver = + new neqsim.fluidMechanics.flowSolver.twoPhaseFlowSolver.twoPhasePipeFlowSolver.TwoPhaseFixedStaggeredGridSolver( + this, getSystemLength(), this.getTotalNumberOfNodes(), false); + flowSolver.setSolverType(type); + flowSolver.solveTDMA(); + getTimeSeries().init(this); + display.setNextData(this); + } + + /** {@inheritDoc} */ + @Override + public void solveTransient(int type, UUID id) { + // pipeSolver pipeSolve = new pipeSolver(this, getSystemLength(), + // getTotalNumberOfNodes()); + // pipeSolve.solveTDMA(); + calcIdentifier = id; + } + + /** + *+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + @SuppressWarnings("unused") + public static void main(String[] args) { + // Initierer et nyt rorsystem + neqsim.fluidMechanics.flowSystem.FlowSystemInterface pipe = new TwoPhaseReactorFlowSystem(); + + // Definerer termodyanmikken5 + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos(295.3, 5.0); // initierer + // et + // system + // som + // benytter + // SRK + // tilstandsligning + // med trykk 305.3 K og 125 bar + neqsim.thermodynamicOperations.ThermodynamicOperations testOps = + new neqsim.thermodynamicOperations.ThermodynamicOperations(testSystem); // gjor + // termodyanmiske + // Flash + // rutiner + // tilgjengelige + testSystem.addComponent("methane", 0.11152181, 0); + // testSystem.addComponent("ethane", 0.0011152181, 0); + testSystem.addComponent("water", 0.04962204876, 1); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + // benytter klassiske blandingsregler + + pipe.setInletThermoSystem(testSystem); // setter termodyanmikken for rorsystemet + pipe.setNumberOfLegs(5); // deler inn roret i et gitt antall legger + pipe.setNumberOfNodesInLeg(100); // setter antall nodepunkter (beregningspunkter/grid) pr. + // leg + double[] height = {0, 0, 0, 0, 0, 0}; + double[] length = {0.0, 1.7, 3.5, 5.0, 7.5, 10.4}; + double[] outerTemperature = + {278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 275.0, 275.0, 275.0, 275.0}; + + pipe.setLegHeights(height); // setter inn hoyde for hver leg-ende + pipe.setLegPositions(length); // setter avstand til hver leg-ende + pipe.setLegOuterTemperatures(outerTemperature); + + neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGemometry = + new neqsim.fluidMechanics.geometryDefinitions.reactor.ReactorData[5]; // Deffinerer + // geometrien + // for + // roret + double[] pipeDiameter = {0.02588, 0.02588, 0.02588, 0.02588, 0.02588}; + for (int i = 0; i < pipeDiameter.length; i++) { + pipeGemometry[i] = + new neqsim.fluidMechanics.geometryDefinitions.reactor.ReactorData(pipeDiameter[i], 1); } + pipe.setEquipmentGeometry(pipeGemometry); // setter inn rorgeometrien for hver leg + // utforer bergninger + pipe.createSystem(); + pipe.init(); + + pipe.solveSteadyState(2); + // pipe.calcFluxes(); + // pipe.getDisplay().displayResult("temperature"); + // pipe.displayResults(); + // testOps.TPflash(); + // testOps.displayResult(); + } } diff --git a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/twoPhaseFlowVisualization/twoPhasePipeFlowVisualization/TwoPhasePipeFlowVisualization.java b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/twoPhaseFlowVisualization/twoPhasePipeFlowVisualization/TwoPhasePipeFlowVisualization.java index c3aeeb9529..d6cf0b2ce1 100644 --- a/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/twoPhaseFlowVisualization/twoPhasePipeFlowVisualization/TwoPhasePipeFlowVisualization.java +++ b/src/main/java/neqsim/fluidMechanics/util/fluidMechanicsVisualization/flowSystemVisualization/twoPhaseFlowVisualization/twoPhasePipeFlowVisualization/TwoPhasePipeFlowVisualization.java @@ -157,7 +157,6 @@ public void displayResult(String name) { // file.createFile(); // } - /* * public void createNetCdfFile(String name) { setPoints(); * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file = new diff --git a/src/main/java/neqsim/processSimulation/SimulationBaseClass.java b/src/main/java/neqsim/processSimulation/SimulationBaseClass.java index 2b984bb244..16f11cf8f7 100644 --- a/src/main/java/neqsim/processSimulation/SimulationBaseClass.java +++ b/src/main/java/neqsim/processSimulation/SimulationBaseClass.java @@ -1,24 +1,37 @@ package neqsim.processSimulation; +import java.util.UUID; import neqsim.util.NamedBaseClass; +/** + * Base class for process simulation objects. + */ public abstract class SimulationBaseClass extends NamedBaseClass implements SimulationInterface { private static final long serialVersionUID = 1L; + + /** + * Unique identifier of which solve/run call was last called successfully. + */ + protected UUID calcIdentifier; protected boolean calculateSteadyState = true; + protected double time = 0; public SimulationBaseClass(String name) { super(name); } /** {@inheritDoc} */ - @Override - public void runTransient(double dt) { - if (getCalculateSteadyState()) { - run(); - return; - } + public UUID getCalculationIdentifier() { + return calcIdentifier; + } - throw new UnsupportedOperationException("RunTransient using difference equations is not supported yet."); + /** {@inheritDoc} */ + public void setCalculationIdentifier(UUID value) { + if (this.calcIdentifier == null || this.calcIdentifier != value) { + this.calcIdentifier = value; + } else { + this.calcIdentifier = value; + } } /** {@inheritDoc} */ @@ -32,4 +45,23 @@ public boolean getCalculateSteadyState() { public void setCalculateSteadyState(boolean steady) { this.calculateSteadyState = steady; } + + /** {@inheritDoc} */ + public double getTime() { + return this.time; + } + + /** {@inheritDoc} */ + public void setTime(double value) { + this.time = value; + } + + /** {@inheritDoc} */ + public void increaseTime(double dt) { + if (dt < 0) { + throw new UnsupportedOperationException( + "Input dt is negative - not allowed to go backwards in time."); + } + this.time = this.time + dt; + } } diff --git a/src/main/java/neqsim/processSimulation/SimulationInterface.java b/src/main/java/neqsim/processSimulation/SimulationInterface.java index 46da985592..984245e842 100644 --- a/src/main/java/neqsim/processSimulation/SimulationInterface.java +++ b/src/main/java/neqsim/processSimulation/SimulationInterface.java @@ -1,47 +1,119 @@ package neqsim.processSimulation; +import java.util.UUID; import neqsim.util.NamedInterface; +/** + * Interface for simulation objects. + */ public interface SimulationInterface extends NamedInterface, Runnable { /** - * Get calculateSteadyState - * + * Getter for property calcIdentifier. + * + * @return Value of calcIdentifier. + */ + public UUID getCalculationIdentifier(); + + /** + * Setter for property calcIdentifier. + * + * @param value Value to set. + */ + public void setCalculationIdentifier(UUID value); + + /** + * Getter for property calculateSteadyState. + * * @return Value of property calculateSteadyState */ public boolean getCalculateSteadyState(); /** - * Setter for property calculateSteadyState - * + * Setter for property calculateSteadyState. + * * @param steady Set true to do steady state calculation when calling runTransient. */ public void setCalculateSteadyState(boolean steady); + /** + * Getter for property time. + * + * @return Value of property time. + */ + public double getTime(); + + /** + * Setter for property time. + * + * @param value Value to set. + */ + public void setTime(double value); + + /** + * Method to increase parameter time by a given value. + * + * @param dt Value to increase time by. + */ + public void increaseTime(double dt); + /** ** run *
* In this method all thermodynamic and unit operations will be calculated in a steady state - * calculation. - * - * + * calculation. Sets calc identifier UUID. */ @Override - public void run(); + public default void run() { + run(UUID.randomUUID()); + } + + /** + *+ * run + *
+ * In this method all thermodynamic and unit operations will be calculated in a steady state + * calculation. Sets calc identifier UUID. + * + * @param value Calc identifier UUID to set. + */ + public void run(UUID value); /** ** runTransient *
- * This method calculates thermodynamic and unit operations using - * difference equations if available and calculateSteadyState is true. - * Use setCalculateSteadyState to set the parameter. - * - * @param dt is the delta time step (seconds) + * This method calculates thermodynamic and unit operations using difference equations if + * available and calculateSteadyState is true. Use setCalculateSteadyState to set the parameter. + * Sets calc identifier UUID. * + * @param dt Delta time [s] + */ + public default void runTransient(double dt) { + runTransient(dt, UUID.randomUUID()); + } + + /** + *+ * runTransient + *
+ * This method calculates thermodynamic and unit operations using difference equations if + * available and calculateSteadyState is true. Use setCalculateSteadyState to set the parameter. + * Sets calc identifier UUID. * + * @param dt Delta time [s] + * @param id Calculation identifier */ - public void runTransient(double dt); + public default void runTransient(double dt, UUID id) { + if (getCalculateSteadyState()) { + run(id); + increaseTime(dt); + return; + } + + throw new UnsupportedOperationException( + "RunTransient using difference equations is not supported yet."); + } /** *diff --git a/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceBaseClass.java b/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceBaseClass.java index 9f4d2f3bdb..46483e88f7 100644 --- a/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceBaseClass.java +++ b/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceBaseClass.java @@ -3,8 +3,10 @@ * * Created on 10. oktober 2006, 19:59 */ + package neqsim.processSimulation.controllerDevice; +import java.util.UUID; import neqsim.processSimulation.measurementDevice.MeasurementDeviceInterface; import neqsim.util.NamedBaseClass; @@ -17,163 +19,171 @@ * @version $Id: $Id */ public class ControllerDeviceBaseClass extends NamedBaseClass implements ControllerDeviceInterface { - private static final long serialVersionUID = 1000; - - private String unit = "[?]"; - private MeasurementDeviceInterface transmitter = null; - private double controllerSetPoint = 0.0; - private double oldError = 0.0, oldoldError = 0.0; - private double error = 0.0; - private double response = 30.0; - int propConstant = 1; - private boolean reverseActing = false; - private double Ksp = 1.0; - private double Tint = 300.0, TintValue = 0.0; - private double Tderiv = 300.0; - - public ControllerDeviceBaseClass() { - super("controller"); - } - - /** {@inheritDoc} */ - @Override - public void setTransmitter(MeasurementDeviceInterface device) { - this.transmitter = device; - } - - /** {@inheritDoc} */ - @Override - public double getMeasuredValue() { - return this.transmitter.getMeasuredValue(); - } - - /** {@inheritDoc} */ - @Override - public void runTransient(double percentSignal, double dt) { - if (isReverseActing()) { - propConstant = -1; - } - oldoldError = error; - oldError = error; - error = transmitter.getMeasuredPercentValue() - - (controllerSetPoint - transmitter.getMinimumValue()) - / (transmitter.getMaximumValue() - transmitter.getMinimumValue()) * 100; - - TintValue += Ksp / Tint * error * dt; - double TderivValue = Ksp * Tderiv * (error - oldError) / dt; - response = percentSignal + propConstant * (Ksp * error + TintValue + TderivValue); - //System.out.println("error " + error + " %"); - // error = device.getMeasuredPercentValue()-controlValue; - // double regulatorSignal = error*1.0; - } - - /** {@inheritDoc} */ - @Override - public void setControllerSetPoint(double signal) { - this.controllerSetPoint = signal; - } - - /** {@inheritDoc} */ - @Override - public String getUnit() { - return unit; - } - - /** {@inheritDoc} */ - @Override - public void setUnit(String unit) { - this.unit = unit; - } - - /** {@inheritDoc} */ - @Override - public double getResponse() { - return response; - } - - /** {@inheritDoc} */ - @Override - public boolean isReverseActing() { - return reverseActing; - } - - /** {@inheritDoc} */ - @Override - public void setReverseActing(boolean reverseActing) { - this.reverseActing = reverseActing; - } - - /** - *
- * getKsp. - *
- * - * @return a double - */ - public double getKsp() { - return Ksp; - } - - /** - *- * setKsp. - *
- * - * @param Ksp a double - */ - public void setKsp(double Ksp) { - this.Ksp = Ksp; - } - - /** {@inheritDoc} */ - @Override - public void setControllerParameters(double Ksp, double Ti, double Td) { - this.setKsp(Ksp); - this.setTint(Ti); - this.setTderiv(Td); - } - - /** - *- * getTint. - *
- * - * @return a double - */ - public double getTint() { - return Tint; - } - - /** - *- * setTint. - *
- * - * @param Tint a double - */ - public void setTint(double Tint) { - this.Tint = Tint; - } - - /** - *- * getTderiv. - *
- * - * @return a double - */ - public double getTderiv() { - return Tderiv; - } - - /** - *- * setTderiv. - *
- * - * @param Tderiv a double - */ - public void setTderiv(double Tderiv) { - this.Tderiv = Tderiv; - } + private static final long serialVersionUID = 1000; + + /** + * Unique identifier of which solve/run call was last called successfully. + */ + protected UUID calcIdentifier; + + private String unit = "[?]"; + private MeasurementDeviceInterface transmitter = null; + private double controllerSetPoint = 0.0; + private double oldError = 0.0; + private double oldoldError = 0.0; + private double error = 0.0; + private double response = 30.0; + int propConstant = 1; + private boolean reverseActing = false; + private double Ksp = 1.0; + private double Tint = 300.0; + private double TintValue = 0.0; + private double Tderiv = 300.0; + + public ControllerDeviceBaseClass() { + super("controller"); + } + + /** {@inheritDoc} */ + @Override + public void setTransmitter(MeasurementDeviceInterface device) { + this.transmitter = device; + } + + /** {@inheritDoc} */ + @Override + public double getMeasuredValue() { + return this.transmitter.getMeasuredValue(); + } + + /** {@inheritDoc} */ + @Override + public void runTransient(double initResponse, double dt, UUID id) { + if (isReverseActing()) { + propConstant = -1; + } + oldoldError = error; + oldError = error; + error = + transmitter.getMeasuredPercentValue() - (controllerSetPoint - transmitter.getMinimumValue()) + / (transmitter.getMaximumValue() - transmitter.getMinimumValue()) * 100; + + TintValue += Ksp / Tint * error * dt; + double TderivValue = Ksp * Tderiv * (error - oldError) / dt; + response = initResponse + propConstant * (Ksp * error + TintValue + TderivValue); + // System.out.println("error " + error + " %"); + // error = device.getMeasuredPercentValue()-controlValue; + // double regulatorSignal = error*1.0; + calcIdentifier = id; + } + + /** {@inheritDoc} */ + @Override + public void setControllerSetPoint(double signal) { + this.controllerSetPoint = signal; + } + + /** {@inheritDoc} */ + @Override + public String getUnit() { + return unit; + } + + /** {@inheritDoc} */ + @Override + public void setUnit(String unit) { + this.unit = unit; + } + + /** {@inheritDoc} */ + @Override + public double getResponse() { + return response; + } + + /** {@inheritDoc} */ + @Override + public boolean isReverseActing() { + return reverseActing; + } + + /** {@inheritDoc} */ + @Override + public void setReverseActing(boolean reverseActing) { + this.reverseActing = reverseActing; + } + + /** + *+ * getKsp. + *
+ * + * @return a double + */ + public double getKsp() { + return Ksp; + } + + /** + *+ * setKsp. + *
+ * + * @param Ksp a double + */ + public void setKsp(double Ksp) { + this.Ksp = Ksp; + } + + /** {@inheritDoc} */ + @Override + public void setControllerParameters(double Ksp, double Ti, double Td) { + this.setKsp(Ksp); + this.setTint(Ti); + this.setTderiv(Td); + } + + /** + *+ * getTint. + *
+ * + * @return a double + */ + public double getTint() { + return Tint; + } + + /** + *+ * setTint. + *
+ * + * @param Tint a double + */ + public void setTint(double Tint) { + this.Tint = Tint; + } + + /** + *+ * getTderiv. + *
+ * + * @return a double + */ + public double getTderiv() { + return Tderiv; + } + + /** + *+ * setTderiv. + *
+ * + * @param Tderiv a double + */ + public void setTderiv(double Tderiv) { + this.Tderiv = Tderiv; + } } diff --git a/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceInterface.java b/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceInterface.java index 0598a82353..daee103281 100644 --- a/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceInterface.java +++ b/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceInterface.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.controllerDevice; +import java.util.UUID; import neqsim.processSimulation.measurementDevice.MeasurementDeviceInterface; /** @@ -11,105 +12,120 @@ * @version $Id: $Id */ public interface ControllerDeviceInterface extends java.io.Serializable { - /** - *- * getMeasuredValue. - *
- * - * @return a double - */ - public double getMeasuredValue(); + /** + *+ * getMeasuredValue. + *
+ * + * @return a double + */ + public double getMeasuredValue(); - /** - *- * setControllerSetPoint. - *
- * - * @param signal a double - */ - public void setControllerSetPoint(double signal); + /** + *+ * setControllerSetPoint. + *
+ * + * @param signal a double + */ + public void setControllerSetPoint(double signal); - /** - *- * getUnit. - *
- * - * @return a {@link java.lang.String} object - */ - public String getUnit(); + /** + *+ * getUnit. + *
+ * + * @return a {@link java.lang.String} object + */ + public String getUnit(); - /** - *- * setUnit. - *
- * - * @param unit a {@link java.lang.String} object - */ - public void setUnit(String unit); + /** + *+ * setUnit. + *
+ * + * @param unit a {@link java.lang.String} object + */ + public void setUnit(String unit); - /** - *- * setTransmitter. - *
- * - * @param device a {@link neqsim.processSimulation.measurementDevice.MeasurementDeviceInterface} - * object - */ - public void setTransmitter(MeasurementDeviceInterface device); + /** + *+ * setTransmitter. + *
+ * + * @param device a {@link neqsim.processSimulation.measurementDevice.MeasurementDeviceInterface} + * object + */ + public void setTransmitter(MeasurementDeviceInterface device); - /** - *- * run. - *
- * - * @param signal a double - * @param dt a double - */ - public void runTransient(double signal, double dt); + /** + *+ * runTransient. + *
+ * Calculates controller output. Sets calc identifier UUID. + * + * @param initResponse Init value for response calculation + * @param dt Delta time [s] + */ + public default void runTransient(double initResponse, double dt) { + runTransient(initResponse, dt, UUID.randomUUID()); + } - /** - *- * getResponse. - *
- * - * @return a double - */ - public double getResponse(); + /** + *+ * runTransient. + *
+ * Calculates controller output. Sets calc identifier UUID. + * + * @param initResponse Init value for response calculation + * @param dt Delta time [s] + * @param id Calculation identifier + */ + public void runTransient(double initResponse, double dt, UUID id); - /** - *- * isReverseActing. - *
- * - * @return a boolean - */ - public boolean isReverseActing(); + /** + *+ * getResponse. + *
+ * + * @return a double + */ + public double getResponse(); - /** - *- * setReverseActing. - *
- * - * @param reverseActing a boolean - */ - public void setReverseActing(boolean reverseActing); + /** + *+ * isReverseActing. + *
+ * + * @return a boolean + */ + public boolean isReverseActing(); - /** - *- * setControllerParameters. - *
- * - * @param Ksp a double - * @param Ti a double - * @param Td a double - */ - public void setControllerParameters(double Ksp, double Ti, double Td); + /** + *+ * setReverseActing. + *
+ * + * @param reverseActing a boolean + */ + public void setReverseActing(boolean reverseActing); - /** {@inheritDoc} */ - @Override - public boolean equals(Object o); + /** + *+ * setControllerParameters. + *
+ * + * @param Ksp a double + * @param Ti a double + * @param Td a double + */ + public void setControllerParameters(double Ksp, double Ti, double Td); - /** {@inheritDoc} */ - @Override - public int hashCode(); + /** {@inheritDoc} */ + @Override + public boolean equals(Object o); + + /** {@inheritDoc} */ + @Override + public int hashCode(); } diff --git a/src/main/java/neqsim/processSimulation/measurementDevice/WellAllocator.java b/src/main/java/neqsim/processSimulation/measurementDevice/WellAllocator.java index 622c87e0c2..e669443628 100644 --- a/src/main/java/neqsim/processSimulation/measurementDevice/WellAllocator.java +++ b/src/main/java/neqsim/processSimulation/measurementDevice/WellAllocator.java @@ -17,7 +17,6 @@ public WellAllocator() { name = "Well Allocator"; } - public WellAllocator(StreamInterface stream) { name = "Well Allocator"; this.wellStream = stream; @@ -28,7 +27,6 @@ public WellAllocator(String streamname, StreamInterface stream) { name = streamname; } - public void setExportGasStream(StreamInterface stream) { this.exportGasStream = stream; } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/ProcessEquipmentBaseClass.java b/src/main/java/neqsim/processSimulation/processEquipment/ProcessEquipmentBaseClass.java index 025ec98e16..9ee3fd21e1 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/ProcessEquipmentBaseClass.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/ProcessEquipmentBaseClass.java @@ -167,24 +167,24 @@ public void setEnergyStream(EnergyStream energyStream) { /** *
- * isSetEnergyStream.
+ * Setter for the field energyStream
.
*
- * Setter for the field energyStream
.
+ * isSetEnergyStream.
*
- * Constructor for SimpleAbsorber. - *
- */ - @Deprecated - public SimpleAbsorber() { - this("SimpleAbsorber"); - } - - /** - *- * Constructor for SimpleAbsorber. - *
- * - * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - @Deprecated - public SimpleAbsorber(StreamInterface inStream1) { - this("SimpleAbsorber", inStream1); - } - - /** - * - * @param name name of absorber - */ - public SimpleAbsorber(String name) { - super(name); - } - - /** - *- * Constructor for SimpleAbsorber. - *
- * - * @param name name of absorber - * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public SimpleAbsorber(String name, StreamInterface inStream1) { - super(name); - this.inStream[0] = inStream1; - this.inStream[1] = inStream1; - outStream[0] = inStream1.clone(); - outStream[1] = inStream1.clone(); - setName(name); - - SystemInterface systemOut1 = inStream1.getThermoSystem().clone(); - outStream[0].setThermoSystem(systemOut1); - - double molCO2 = - inStream1.getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfmoles(); - System.out.println("mol CO2 " + molCO2); - SystemInterface systemOut0 = inStream1.getThermoSystem().clone(); - systemOut0.init(0); - systemOut0.addComponent("MDEA", molCO2 * absorptionEfficiency); - systemOut0.addComponent("water", molCO2 * absorptionEfficiency * 10.0); - systemOut0.chemicalReactionInit(); - systemOut0.createDatabase(true); - systemOut0.setMixingRule(4); - outStream[1].setThermoSystem(systemOut0); - outStream[1].run(); - } - - /** {@inheritDoc} */ - public AbsorberMechanicalDesign getMechanicalDesign() { - return new AbsorberMechanicalDesign(this); - } - - /** {@inheritDoc} */ - @Override - public void setName(String name) { - super.setName(name); - // outStream[0].setName(name + "_Sout1"); - // outStream[1].setName(name + "_Sout2"); - } - - /** - *
- * Setter for the field dT
.
- *
- * Getter for the field outStream
.
- *
- * Getter for the field outStream
.
- *
- * getSolventInStream. - *
- * - * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - public StreamInterface getSolventInStream() { - return inStream[0]; - } - - /** - *
- * Getter for the field inStream
.
- *
- * setOutTemperature. - *
- * - * @param temperature a double - */ - public void setOutTemperature(double temperature) { - this.temperatureOut = temperature; - } - - /** - *- * getOutTemperature. - *
- * - * @param i a int - */ - public void getOutTemperature(int i) { - outStream[i].getThermoSystem().getTemperature(); - } - - /** - *- * getInTemperature. - *
- * - * @param i a int - */ - public void getInTemperature(int i) { - inStream[i].getThermoSystem().getTemperature(); - } - - /** {@inheritDoc} */ - @Override - public void run() { - SystemInterface systemOut1 = inStream[1].getThermoSystem().clone(); - outStream[0].setThermoSystem(systemOut1); - outStream[0].run(); - - outStream[1].run(); - - double error = 1e5; - error = absorptionEfficiency - (outStream[1].getThermoSystem().getPhase(1) - .getComponent("CO2").getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("HCO3-") - .getNumberOfMolesInPhase()) - / (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA") - .getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") - .getNumberOfMolesInPhase()); - int iter = 0; - do { - iter++; - double factor = (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA") - .getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") - .getNumberOfMolesInPhase()); - // outStream[1].getThermoSystem().addComponent("CO2",(20.0-outStream[1].getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfMolesInPhase()),0); - outStream[1].getThermoSystem().addComponent("MDEA", -error * factor); - outStream[1].getThermoSystem().addComponent("water", -error * 10.0 * factor); - outStream[1].run(); - error = absorptionEfficiency - ((outStream[1].getThermoSystem().getPhase(1) - .getComponent("CO2").getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("HCO3-") - .getNumberOfMolesInPhase()) - / (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA") - .getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") - .getNumberOfMolesInPhase())); - - System.out.println("error " + error); - } while (Math.abs(error) > 1e-4 && iter < 30 - && outStream[1].getThermoSystem().getPhase(1).getBeta() > 0 - && outStream[0].getThermoSystem().getPhase(1).getBeta() > 0); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - outStream[0].displayResult(); - outStream[1].displayResult(); - } - - /** {@inheritDoc} */ - @Override - public void setAproachToEquilibrium(double eff) { - this.absorptionEfficiency = eff; - } - - /** - *
- * Getter for the field numberOfTheoreticalStages
.
- *
- * Setter for the field numberOfTheoreticalStages
.
- *
- * Getter for the field numberOfStages
.
- *
- * Setter for the field numberOfStages
.
- *
- * Getter for the field stageEfficiency
.
- *
- * Setter for the field stageEfficiency
.
- *
- * getHTU. - *
- * - * @return a double - */ - public double getHTU() { - return HTU; - } - - /** - *- * setHTU. - *
- * - * @param HTU a double - */ - public void setHTU(double HTU) { - this.HTU = HTU; - } - - /** - *- * getNTU. - *
- * - * @return a double - */ - public double getNTU() { - return NTU; - } - - /** - *- * setNTU. - *
- * - * @param NTU a double - */ - public void setNTU(double NTU) { - this.NTU = NTU; - } - - /** - *
- * Getter for the field fsFactor
.
- *
- * getWettingRate. - *
- * - * @return a double - */ - public double getWettingRate() { - double intArea = 3.14 * getInternalDiameter() * getInternalDiameter() / 4.0; - return getLiquidOutStream().getThermoSystem().getFlowRate("m3/hr") / intArea; - } + private static final long serialVersionUID = 1000; + + boolean setTemperature = false; + StreamInterface[] outStream = new Stream[2]; + StreamInterface[] inStream = new Stream[2]; + SystemInterface system; + protected double temperatureOut = 0; + protected double dT = 0.0; + private int numberOfStages = 5; + private double numberOfTheoreticalStages = 3.0; + double absorptionEfficiency = 0.5; + private double HTU = 0.85; + private double NTU = 2.0; + private double stageEfficiency = 0.25; + private double fsFactor = 0.0; + + /** + *+ * Constructor for SimpleAbsorber. + *
+ */ + @Deprecated + public SimpleAbsorber() { + this("SimpleAbsorber"); + } + + /** + *+ * Constructor for SimpleAbsorber. + *
+ * + * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + @Deprecated + public SimpleAbsorber(StreamInterface inStream1) { + this("SimpleAbsorber", inStream1); + } + + /** + *+ * Constructor for SimpleAbsorber. + *
+ * + * @param name name of absorber + */ + public SimpleAbsorber(String name) { + super(name); + } + + /** + *+ * Constructor for SimpleAbsorber. + *
+ * + * @param name name of absorber + * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public SimpleAbsorber(String name, StreamInterface inStream1) { + super(name); + this.inStream[0] = inStream1; + this.inStream[1] = inStream1; + outStream[0] = inStream1.clone(); + outStream[1] = inStream1.clone(); + setName(name); + + SystemInterface systemOut1 = inStream1.getThermoSystem().clone(); + outStream[0].setThermoSystem(systemOut1); + + double molCO2 = inStream1.getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfmoles(); + System.out.println("mol CO2 " + molCO2); + SystemInterface systemOut0 = inStream1.getThermoSystem().clone(); + systemOut0.init(0); + systemOut0.addComponent("MDEA", molCO2 * absorptionEfficiency); + systemOut0.addComponent("water", molCO2 * absorptionEfficiency * 10.0); + systemOut0.chemicalReactionInit(); + systemOut0.createDatabase(true); + systemOut0.setMixingRule(4); + outStream[1].setThermoSystem(systemOut0); + outStream[1].run(); + } + + /** {@inheritDoc} */ + public AbsorberMechanicalDesign getMechanicalDesign() { + return new AbsorberMechanicalDesign(this); + } + + /** {@inheritDoc} */ + @Override + public void setName(String name) { + super.setName(name); + // outStream[0].setName(name + "_Sout1"); + // outStream[1].setName(name + "_Sout2"); + } + + /** + *
+ * Setter for the field dT
.
+ *
+ * Getter for the field outStream
.
+ *
+ * Getter for the field outStream
.
+ *
+ * getSolventInStream. + *
+ * + * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + public StreamInterface getSolventInStream() { + return inStream[0]; + } + + /** + *
+ * Getter for the field inStream
.
+ *
+ * setOutTemperature. + *
+ * + * @param temperature a double + */ + public void setOutTemperature(double temperature) { + this.temperatureOut = temperature; + } + + /** + *+ * getOutTemperature. + *
+ * + * @param i a int + */ + public void getOutTemperature(int i) { + outStream[i].getThermoSystem().getTemperature(); + } + + /** + *+ * getInTemperature. + *
+ * + * @param i a int + */ + public void getInTemperature(int i) { + inStream[i].getThermoSystem().getTemperature(); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + SystemInterface systemOut1 = inStream[1].getThermoSystem().clone(); + outStream[0].setThermoSystem(systemOut1); + outStream[0].run(id); + outStream[1].run(); + + double error = 1e5; + error = absorptionEfficiency - (outStream[1].getThermoSystem().getPhase(1).getComponent("CO2") + .getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("HCO3-") + .getNumberOfMolesInPhase()) + / (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA").getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") + .getNumberOfMolesInPhase()); + int iter = 0; + do { + iter++; + double factor = + (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA").getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") + .getNumberOfMolesInPhase()); + // outStream[1].getThermoSystem().addComponent("CO2",(20.0-outStream[1].getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfMolesInPhase()),0); + outStream[1].getThermoSystem().addComponent("MDEA", -error * factor); + outStream[1].getThermoSystem().addComponent("water", -error * 10.0 * factor); + outStream[1].run(); + error = absorptionEfficiency - ((outStream[1].getThermoSystem().getPhase(1) + .getComponent("CO2").getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("HCO3-") + .getNumberOfMolesInPhase()) + / (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA") + .getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") + .getNumberOfMolesInPhase())); + + System.out.println("error " + error); + } while (Math.abs(error) > 1e-4 && iter < 30 + && outStream[1].getThermoSystem().getPhase(1).getBeta() > 0 + && outStream[0].getThermoSystem().getPhase(1).getBeta() > 0); + outStream[1].setCalculationIdentifier(id); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + outStream[0].displayResult(); + outStream[1].displayResult(); + } + + /** {@inheritDoc} */ + @Override + public void setAproachToEquilibrium(double eff) { + this.absorptionEfficiency = eff; + } + + /** + *
+ * Getter for the field numberOfTheoreticalStages
.
+ *
+ * Setter for the field numberOfTheoreticalStages
.
+ *
+ * Getter for the field numberOfStages
.
+ *
+ * Setter for the field numberOfStages
.
+ *
+ * Getter for the field stageEfficiency
.
+ *
+ * Setter for the field stageEfficiency
.
+ *
+ * getHTU. + *
+ * + * @return a double + */ + public double getHTU() { + return HTU; + } + + /** + *+ * setHTU. + *
+ * + * @param HTU a double + */ + public void setHTU(double HTU) { + this.HTU = HTU; + } + + /** + *+ * getNTU. + *
+ * + * @return a double + */ + public double getNTU() { + return NTU; + } + + /** + *+ * setNTU. + *
+ * + * @param NTU a double + */ + public void setNTU(double NTU) { + this.NTU = NTU; + } + + /** + *
+ * Getter for the field fsFactor
.
+ *
+ * getWettingRate. + *
+ * + * @return a double + */ + public double getWettingRate() { + double intArea = 3.14 * getInternalDiameter() * getInternalDiameter() / 4.0; + return getLiquidOutStream().getThermoSystem().getFlowRate("m3/hr") / intArea; + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/absorber/SimpleTEGAbsorber.java b/src/main/java/neqsim/processSimulation/processEquipment/absorber/SimpleTEGAbsorber.java index 71fd3be756..875dbbc913 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/absorber/SimpleTEGAbsorber.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/absorber/SimpleTEGAbsorber.java @@ -5,6 +5,7 @@ import java.text.DecimalFormat; import java.text.FieldPosition; import java.util.ArrayList; +import java.util.UUID; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JScrollPane; @@ -24,582 +25,579 @@ * @version $Id: $Id */ public class SimpleTEGAbsorber extends SimpleAbsorber { - private static final long serialVersionUID = 1000; - - protected ArrayList- * Constructor for SimpleTEGAbsorber. - *
- */ - @Deprecated - public SimpleTEGAbsorber() { + private static final long serialVersionUID = 1000; + + protected ArrayList+ * Constructor for SimpleTEGAbsorber. + *
+ */ + @Deprecated + public SimpleTEGAbsorber() {} + + /** + *+ * Constructor for SimpleTEGAbsorber. + *
+ * + * @param name a {@link java.lang.String} object + */ + public SimpleTEGAbsorber(String name) { + super(name); + } + + /** {@inheritDoc} */ + @Override + public void addStream(StreamInterface newStream) { + streams.add(newStream); + if (numberOfInputStreams == 0) { + mixedStream = (Stream) streams.get(0).clone(); + mixedStream.getThermoSystem().setNumberOfPhases(2); + mixedStream.getThermoSystem().reInitPhaseType(); + mixedStream.getThermoSystem().init(0); + mixedStream.getThermoSystem().init(3); } - /** - *- * Constructor for SimpleTEGAbsorber. - *
- * - * @param name a {@link java.lang.String} object - */ - public SimpleTEGAbsorber(String name) { - super(name); - } - - /** {@inheritDoc} */ - @Override - public void addStream(StreamInterface newStream) { - streams.add(newStream); - if (numberOfInputStreams == 0) { - mixedStream = (Stream) streams.get(0).clone(); - mixedStream.getThermoSystem().setNumberOfPhases(2); - mixedStream.getThermoSystem().reInitPhaseType(); - mixedStream.getThermoSystem().init(0); - mixedStream.getThermoSystem().init(3); + numberOfInputStreams++; + } + + /** + *+ * addGasInStream. + *
+ * + * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public void addGasInStream(StreamInterface newStream) { + // todo: fail if gasInStream is not null? + gasInStream = (Stream) newStream; + gasOutStream = (Stream) newStream.clone(); + addStream(newStream); + } + + /** + *+ * addSolventInStream. + *
+ * + * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public void addSolventInStream(StreamInterface newStream) { + // todo: fail if solventInStream is not null? + solventInStream = (Stream) newStream; + solventOutStream = (Stream) newStream.clone(); + addStream(newStream); + solventStreamNumber = streams.size() - 1; + } + + /** + *+ * replaceSolventInStream. + *
+ * + * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public void replaceSolventInStream(StreamInterface newStream) { + // todo: fails if solventStreamNumber is 0, i.e. no solventinstream set? + solventInStream = (Stream) newStream; + streams.set(solventStreamNumber, solventInStream); + } + + /** {@inheritDoc} */ + @Override + public void setPressure(double pressure) { + this.pressure = pressure; + } + + /** + *+ * mixStream. + *
+ */ + public void mixStream() { + String compName = new String(); + + for (int k = 1; k < streams.size(); k++) { + for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] + .getNumberOfComponents(); i++) { + boolean gotComponent = false; + String componentName = + streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i].getName(); + // System.out.println("adding: " + componentName); + + double moles = + streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i].getNumberOfmoles(); + // System.out.println("moles: " + moles + " " + + // mixedStream.getThermoSystem().getPhases()[0].getNumberOfComponents()); + for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] + .getNumberOfComponents(); p++) { + if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() + .equals(componentName)) { + gotComponent = true; + compName = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] + .getComponentName(); + } } - numberOfInputStreams++; - } - - /** - *- * addGasInStream. - *
- * - * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public void addGasInStream(StreamInterface newStream) { - gasInStream = (Stream) newStream; - gasOutStream = (Stream) newStream.clone(); - addStream(newStream); - } - - /** - *- * addSolventInStream. - *
- * - * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public void addSolventInStream(StreamInterface newStream) { - solventInStream = (Stream) newStream; - solventOutStream = (Stream) newStream.clone(); - addStream(newStream); - solventStreamNumber = streams.size() - 1; - } - - /** - *- * replaceSolventInStream. - *
- * - * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public void replaceSolventInStream(StreamInterface newStream) { - solventInStream = (Stream) newStream; - streams.set(solventStreamNumber, solventInStream); - } - - /** {@inheritDoc} */ - @Override - public void setPressure(double pressure) { - this.pressure = pressure; - } - - /** - *- * mixStream. - *
- */ - public void mixStream() { - String compName = new String(); - - for (int k = 1; k < streams.size(); k++) { - for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] - .getNumberOfComponents(); i++) { - boolean gotComponent = false; - String componentName = - streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i] - .getName(); - // System.out.println("adding: " + componentName); - - double moles = streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i] - .getNumberOfmoles(); - // System.out.println("moles: " + moles + " " + - // mixedStream.getThermoSystem().getPhases()[0].getNumberOfComponents()); - for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] - .getNumberOfComponents(); p++) { - if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() - .equals(componentName)) { - gotComponent = true; - compName = - streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] - .getComponentName(); - } - } - - if (gotComponent) { - // System.out.println("adding moles starting...."); - mixedStream.getThermoSystem().addComponent(compName, moles); - // mixedStream.getThermoSystem().init_x_y(); - // System.out.println("adding moles finished"); - } else { - // System.out.println("ikke gaa hit"); - mixedStream.getThermoSystem().addComponent(compName, moles); - } - } + if (gotComponent) { + // System.out.println("adding moles starting...."); + mixedStream.getThermoSystem().addComponent(compName, moles); + // mixedStream.getThermoSystem().init_x_y(); + // System.out.println("adding moles finished"); + } else { + // System.out.println("ikke gaa hit"); + mixedStream.getThermoSystem().addComponent(compName, moles); } - mixedStream.getThermoSystem().init_x_y(); - mixedStream.getThermoSystem().initBeta(); - mixedStream.getThermoSystem().init(2); + } } - - /** - *- * guessTemperature. - *
- * - * @return a double - */ - public double guessTemperature() { - double gtemp = 0; - for (int k = 0; k < streams.size(); k++) { - gtemp += streams.get(k).getThermoSystem().getTemperature() - * streams.get(k).getThermoSystem().getNumberOfMoles() - / mixedStream.getThermoSystem().getNumberOfMoles(); - } - return gtemp; + mixedStream.getThermoSystem().init_x_y(); + mixedStream.getThermoSystem().initBeta(); + mixedStream.getThermoSystem().init(2); + } + + /** + *+ * guessTemperature. + *
+ * + * @return a double + */ + public double guessTemperature() { + double gtemp = 0; + for (int k = 0; k < streams.size(); k++) { + gtemp += streams.get(k).getThermoSystem().getTemperature() + * streams.get(k).getThermoSystem().getNumberOfMoles() + / mixedStream.getThermoSystem().getNumberOfMoles(); } - - /** - *- * calcMixStreamEnthalpy. - *
- * - * @return a double - */ - public double calcMixStreamEnthalpy() { - double enthalpy = 0; - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); - // System.out.println("total enthalpy k : " + ( - // ((StreamInterface) streams.get(k)).getThermoSystem()).getEnthalpy()); - } - // System.out.println("total enthalpy of streams: " + enthalpy); - return enthalpy; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getOutStream() { - return mixedStream; + return gtemp; + } + + /** + *+ * calcMixStreamEnthalpy. + *
+ * + * @return a double + */ + public double calcMixStreamEnthalpy() { + double enthalpy = 0; + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); + // System.out.println("total enthalpy k : " + ( + // ((StreamInterface) streams.get(k)).getThermoSystem()).getEnthalpy()); } + // System.out.println("total enthalpy of streams: " + enthalpy); + return enthalpy; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getOutStream() { + return mixedStream; + } + + /** + *+ * getInStream. + *
+ * + * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + public StreamInterface getInStream() { + return gasInStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getGasOutStream() { + return gasOutStream; + } + + /** + *
+ * Getter for the field gasInStream
.
+ *
+ * calcEa. + *
+ * + * @return a double + */ + public double calcEa() { + double A = mixedStream.getThermoSystem().getPhase(1).getNumberOfMolesInPhase() + / mixedStream.getThermoSystem().getPhase(0).getNumberOfMolesInPhase() / kwater; + absorptionEfficiency = (Math.pow(A, getNumberOfTheoreticalStages() + 1) - A) + / (Math.pow(A, getNumberOfTheoreticalStages() + 1) - 1.0); + return absorptionEfficiency; + } + + /** + *+ * calcY0. + *
+ * + * @return a double + */ + public double calcY0() { + // double fugacityWaterLiquid = + // mixedStream.getThermoSystem().getPhase(1).getFugacity("water"); + // double xrel = + // mixedStream.getFluid().getPhase(0).getComponent("water").getx()/solventInStream.getFluid().getPhase(0).getComponent("water").getx(); + // double y0 = + // xrel*fugacityWaterLiquid/(mixedStream.getFluid().getPhase(0).getComponent("water").getFugacityCoefficient()*mixedStream.getFluid().getPressure()); + double fugCoefRef = + mixedStream.getThermoSystem().getPhase(1).getComponent("water").getFugacityCoefficient(); + double y0 = solventInStream.getFluid().getPhase(0).getComponent("water").getx() * fugCoefRef + / (mixedStream.getThermoSystem().getPhase(0).getComponent("water") + .getFugacityCoefficient()); + return y0; + } + + /** + *+ * calcNumberOfTheoreticalStages. + *
+ * + * @return a double + */ + public double calcNumberOfTheoreticalStages() { + setNumberOfTheoreticalStages(getStageEfficiency() * getNumberOfStages()); + return getNumberOfTheoreticalStages(); + } + + /** + *+ * calcNTU. + *
+ * + * @param y0 a double + * @param y1 a double + * @param yb a double + * @param ymix a double + * @return a double + */ + public double calcNTU(double y0, double y1, double yb, double ymix) { + return Math.log((yb - ymix) / (y1 - y0)); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + try { + double y1 = 0.0; + // double yN = gasInStream.getThermoSystem().getPhase(0).getComponent("water").getx(); + mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); + mixedStream.getThermoSystem().setNumberOfPhases(2); + mixedStream.getThermoSystem().reInitPhaseType(); + mixedStream.getThermoSystem().init(0); + mixStream(); + // System.out.println("feed total number of water " + + // mixedStream.getFluid().getPhase(0).getComponent("water").getNumberOfmoles()); + double enthalpy = calcMixStreamEnthalpy(); + //// System.out.println("temp guess " + guessTemperature()); + mixedStream.getThermoSystem().setTemperature(guessTemperature()); + ThermodynamicOperations testOps = new ThermodynamicOperations(mixedStream.getThermoSystem()); + testOps.TPflash(); + testOps.PHflash(enthalpy, 0); + + kwater = mixedStream.getThermoSystem().getPhase(0).getComponent("water").getx() + / mixedStream.getThermoSystem().getPhase(1).getComponent("water").getx(); + + calcNumberOfTheoreticalStages(); + // System.out.println("number of theoretical stages " + + // getNumberOfTheoreticalStages()); + double absorptionEffiency = calcEa(); - /** - *- * getInStream. - *
- * - * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - public StreamInterface getInStream() { - return gasInStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGasOutStream() { - return gasOutStream; - } - - /** - *
- * Getter for the field gasInStream
.
- *
- * calcEa. - *
- * - * @return a double - */ - public double calcEa() { - double A = mixedStream.getThermoSystem().getPhase(1).getNumberOfMolesInPhase() - / mixedStream.getThermoSystem().getPhase(0).getNumberOfMolesInPhase() / kwater; - absorptionEfficiency = (Math.pow(A, getNumberOfTheoreticalStages() + 1) - A) - / (Math.pow(A, getNumberOfTheoreticalStages() + 1) - 1.0); - return absorptionEfficiency; - } - - /** - *- * calcY0. - *
- * - * @return a double - */ - public double calcY0() { - // double fugacityWaterLiquid = - // mixedStream.getThermoSystem().getPhase(1).getFugacity("water"); - // double xrel = - // mixedStream.getFluid().getPhase(0).getComponent("water").getx()/solventInStream.getFluid().getPhase(0).getComponent("water").getx(); - // double y0 = - // xrel*fugacityWaterLiquid/(mixedStream.getFluid().getPhase(0).getComponent("water").getFugacityCoefficient()*mixedStream.getFluid().getPressure()); - double fugCoefRef = mixedStream.getThermoSystem().getPhase(1).getComponent("water") - .getFugacityCoefficient(); - double y0 = solventInStream.getFluid().getPhase(0).getComponent("water").getx() * fugCoefRef - / (mixedStream.getThermoSystem().getPhase(0).getComponent("water") - .getFugacityCoefficient()); - return y0; - } - - /** - *- * calcNumberOfTheoreticalStages. - *
- * - * @return a double - */ - public double calcNumberOfTheoreticalStages() { - setNumberOfTheoreticalStages(getStageEfficiency() * getNumberOfStages()); - return getNumberOfTheoreticalStages(); - } - - /** - *- * calcNTU. - *
- * - * @param y0 a double - * @param y1 a double - * @param yb a double - * @param ymix a double - * @return a double - */ - public double calcNTU(double y0, double y1, double yb, double ymix) { - double NTU = Math.log((yb - ymix) / (y1 - y0)); - return NTU; - } - - /** {@inheritDoc} */ - @Override - public void run() { - try { - double y0 = 0.0, y1 = 0.0; - // double yN = gasInStream.getThermoSystem().getPhase(0).getComponent("water").getx(); - double absorptionEffiency = 0.0; - mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); - mixedStream.getThermoSystem().setNumberOfPhases(2); - mixedStream.getThermoSystem().reInitPhaseType(); - mixedStream.getThermoSystem().init(0); - mixStream(); - // System.out.println("feed total number of water " + - // mixedStream.getFluid().getPhase(0).getComponent("water").getNumberOfmoles()); - double enthalpy = calcMixStreamEnthalpy(); - //// System.out.println("temp guess " + guessTemperature()); - mixedStream.getThermoSystem().setTemperature(guessTemperature()); - ThermodynamicOperations testOps = - new ThermodynamicOperations(mixedStream.getThermoSystem()); - testOps.TPflash(); - testOps.PHflash(enthalpy, 0); - - kwater = mixedStream.getThermoSystem().getPhase(0).getComponent("water").getx() - / mixedStream.getThermoSystem().getPhase(1).getComponent("water").getx(); - - calcNumberOfTheoreticalStages(); - // System.out.println("number of theoretical stages " + - // getNumberOfTheoreticalStages()); - absorptionEffiency = calcEa(); - - y0 = calcY0(); - if (isSetWaterInDryGas) { - y1 = waterInDryGas; - setNumberOfTheoreticalStages(2.0); - } else { - y1 = gasInStream.getThermoSystem().getPhase(0).getComponent("water").getx() - - absorptionEffiency - * (gasInStream.getThermoSystem().getPhase(0).getComponent("water").getx() - - y0); - } - - double yMean = mixedStream.getThermoSystem().getPhase(0).getComponent("water").getx(); - double molesWaterToMove = (yMean - y1) - * mixedStream.getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - // System.out.println("Lean TEG to absorber " - // +solventInStream.getFlowRate("kg/hr")); - - // System.out.println("mole water to move " + molesWaterToMove); - // System.out.println("total moles water in gas " + - // mixedStream.getThermoSystem().getPhase(0).getComponent("water").getNumberOfMolesInPhase()); - // System.out.println("total moles water " + - // mixedStream.getThermoSystem().getPhase(0).getComponent("water").getNumberOfmoles()); - StreamInterface stream = mixedStream.clone(); - stream.setName("test"); - stream.getThermoSystem().addComponent("water", -molesWaterToMove, 0); - stream.getThermoSystem().addComponent("water", molesWaterToMove, 1); - stream.getThermoSystem().initBeta(); - stream.getThermoSystem().init_x_y(); - stream.getThermoSystem().init(2); - mixedStream = stream; - - // stream.getThermoSystem().display(); - - SystemInterface tempSystem = mixedStream.getThermoSystem().clone(); - SystemInterface gasTemp = tempSystem.phaseToSystem(tempSystem.getPhases()[0]); - gasTemp.init(2); - gasOutStream.setThermoSystem(gasTemp); - // System.out.println("gas total number of water " + - // gasOutStream.getFluid().getPhase(0).getComponent("water").getNumberOfmoles()); - - tempSystem = mixedStream.getThermoSystem().clone(); - SystemInterface liqTemp = tempSystem.phaseToSystem(tempSystem.getPhases()[1]); - liqTemp.init(2); - solventOutStream.setThermoSystem(liqTemp); - // System.out.println("solvent total number of water " + - // solventOutStream.getFluid().getPhase(0).getComponent("water").getNumberOfmoles()); - - setNTU(calcNTU(y0, y1, - gasInStream.getThermoSystem().getPhase(0).getComponent("water").getx(), yMean)); - // System.out.println("NTU " + getNTU()); - - // double Ks = 0.055; - getSolventOutStream().getThermoSystem().initPhysicalProperties(); - getGasOutStream().getThermoSystem().initPhysicalProperties(); - - // double vtemp = Ks * Math.sqrt((getSolventOutStream().getThermoSystem().getPhase(0) - // .getPhysicalProperties().getDensity() - - // getGasOutStream().getThermoSystem().getPhase(0).getPhysicalProperties() - // .getDensity()) / - // getSolventOutStream().getThermoSystem().getPhase(0).getPhysicalProperties().getDensity()); - - // double d = Math.sqrt(4.0 * getGasOutStream().getMolarRate() * - // getGasOutStream().getThermoSystem().getPhase(0).getMolarMass() / - // getGasOutStream().getThermoSystem().getPhase(0).getPhysicalProperties() - // .getDensity()/ 3.14 / vtemp); - // System.out.println("diameter " + d); - } catch (Exception e) { - e.printStackTrace(); - } - // System.out.println("rich TEG from absorber " + - // getSolventOutStream().getFlowRate("kg/hr")); - } - - /** - *- * getGasLoadFactor. - *
- * - * @return a double - */ - public double getGasLoadFactor() { - double intArea = 3.14 * getInternalDiameter() * getInternalDiameter() / 4.0; - double vs = getGasOutStream().getThermoSystem().getFlowRate("m3/sec") / intArea; - return vs / Math.sqrt((getSolventOutStream().getThermoSystem().getPhase(0) - .getPhysicalProperties().getDensity() - - getGasOutStream().getThermoSystem().getPhase(0).getPhysicalProperties() - .getDensity()) - / getSolventOutStream().getThermoSystem().getPhase(0).getPhysicalProperties() - .getDensity()); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - SystemInterface thermoSystem = mixedStream.getThermoSystem(); - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(5); - nf.applyPattern("#.#####E0"); - - JDialog dialog = new JDialog(new JFrame(), "Results from TPflash"); - Container dialogContentPane = dialog.getContentPane(); - dialogContentPane.setLayout(new FlowLayout()); - - thermoSystem.initPhysicalProperties(); - String[][] table = new String[50][5]; - String[] names = {"", "Phase 1", "Phase 2", "Phase 3", "Unit"}; - table[0][0] = ""; - table[0][1] = ""; - table[0][2] = ""; - table[0][3] = ""; - StringBuffer buf = new StringBuffer(); - FieldPosition test = new FieldPosition(0); - - for (int i = 0; i < thermoSystem.getNumberOfPhases(); i++) { - for (int j = 0; j < thermoSystem.getPhases()[0].getNumberOfComponents(); j++) { - table[j + 1][0] = thermoSystem.getPhases()[0].getComponents()[j].getName(); - buf = new StringBuffer(); - table[j + 1][i + 1] = - nf.format(thermoSystem.getPhases()[i].getComponents()[j].getx(), buf, test) - .toString(); - table[j + 1][4] = "[-]"; - } - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 2][0] = "Density"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 2][i + 1] = - nf.format(thermoSystem.getPhases()[i].getPhysicalProperties().getDensity(), buf, - test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 2][4] = "[kg/m^3]"; - - // Double.longValue(thermoSystem.getPhases()[i].getBeta()); - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 3][0] = "PhaseFraction"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 3][i + 1] = - nf.format(thermoSystem.getPhases()[i].getBeta(), buf, test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 3][4] = "[-]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 4][0] = "MolarMass"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 4][i + 1] = - nf.format(thermoSystem.getPhases()[i].getMolarMass() * 1000, buf, test) - .toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 4][4] = "[kg/kmol]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 5][0] = "Cp"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 5][i + 1] = nf.format( - (thermoSystem.getPhases()[i].getCp() - / (thermoSystem.getPhases()[i].getNumberOfMolesInPhase() - * thermoSystem.getPhases()[i].getMolarMass() * 1000)), - buf, test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 5][4] = "[kJ/kg*K]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 7][0] = "Viscosity"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 7][i + 1] = - nf.format((thermoSystem.getPhases()[i].getPhysicalProperties().getViscosity()), - buf, test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 7][4] = "[kg/m*sec]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 8][0] = "Conductivity"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 8][i + 1] = - nf.format(thermoSystem.getPhases()[i].getPhysicalProperties().getConductivity(), - buf, test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 8][4] = "[W/m*K]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 10][0] = "Pressure"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 10][i + 1] = - Double.toString(thermoSystem.getPhases()[i].getPressure()); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 10][4] = "[bar]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 11][0] = "Temperature"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 11][i + 1] = - Double.toString(thermoSystem.getPhases()[i].getTemperature()); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 11][4] = "[K]"; - Double.toString(thermoSystem.getPhases()[i].getTemperature()); - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][0] = "Stream"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][i + 1] = getName(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][4] = "-"; - } - - JTable Jtab = new JTable(table, names); - JScrollPane scrollpane = new JScrollPane(Jtab); - dialogContentPane.add(scrollpane); - dialog.pack(); - dialog.setVisible(true); - } - - /** - *
- * Setter for the field gasOutStream
.
- *
- * Getter for the field solventOutStream
.
- *
- * Setter for the field solventOutStream
.
- *
- * Setter for the field waterInDryGas
.
- *
+ * getGasLoadFactor. + *
+ * + * @return a double + */ + public double getGasLoadFactor() { + double intArea = 3.14 * getInternalDiameter() * getInternalDiameter() / 4.0; + double vs = getGasOutStream().getThermoSystem().getFlowRate("m3/sec") / intArea; + return vs / Math.sqrt( + (getSolventOutStream().getThermoSystem().getPhase(0).getPhysicalProperties().getDensity() + - getGasOutStream().getThermoSystem().getPhase(0).getPhysicalProperties().getDensity()) + / getSolventOutStream().getThermoSystem().getPhase(0).getPhysicalProperties() + .getDensity()); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + SystemInterface thermoSystem = mixedStream.getThermoSystem(); + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(5); + nf.applyPattern("#.#####E0"); + + JDialog dialog = new JDialog(new JFrame(), "Results from TPflash"); + Container dialogContentPane = dialog.getContentPane(); + dialogContentPane.setLayout(new FlowLayout()); + + thermoSystem.initPhysicalProperties(); + String[][] table = new String[50][5]; + String[] names = {"", "Phase 1", "Phase 2", "Phase 3", "Unit"}; + table[0][0] = ""; + table[0][1] = ""; + table[0][2] = ""; + table[0][3] = ""; + StringBuffer buf = new StringBuffer(); + FieldPosition test = new FieldPosition(0); + + for (int i = 0; i < thermoSystem.getNumberOfPhases(); i++) { + for (int j = 0; j < thermoSystem.getPhases()[0].getNumberOfComponents(); j++) { + table[j + 1][0] = thermoSystem.getPhases()[0].getComponents()[j].getName(); + buf = new StringBuffer(); + table[j + 1][i + 1] = + nf.format(thermoSystem.getPhases()[i].getComponents()[j].getx(), buf, test).toString(); + table[j + 1][4] = "[-]"; + } + buf = new StringBuffer(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 2][0] = "Density"; + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 2][i + 1] = + nf.format(thermoSystem.getPhases()[i].getPhysicalProperties().getDensity(), buf, test) + .toString(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 2][4] = "[kg/m^3]"; + + // Double.longValue(thermoSystem.getPhases()[i].getBeta()); + + buf = new StringBuffer(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 3][0] = "PhaseFraction"; + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 3][i + 1] = + nf.format(thermoSystem.getPhases()[i].getBeta(), buf, test).toString(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 3][4] = "[-]"; + + buf = new StringBuffer(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 4][0] = "MolarMass"; + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 4][i + 1] = + nf.format(thermoSystem.getPhases()[i].getMolarMass() * 1000, buf, test).toString(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 4][4] = "[kg/kmol]"; + + buf = new StringBuffer(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 5][0] = "Cp"; + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 5][i + 1] = + nf.format((thermoSystem.getPhases()[i].getCp() + / (thermoSystem.getPhases()[i].getNumberOfMolesInPhase() + * thermoSystem.getPhases()[i].getMolarMass() * 1000)), + buf, test).toString(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 5][4] = "[kJ/kg*K]"; + + buf = new StringBuffer(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 7][0] = "Viscosity"; + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 7][i + 1] = + nf.format((thermoSystem.getPhases()[i].getPhysicalProperties().getViscosity()), buf, test) + .toString(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 7][4] = "[kg/m*sec]"; + + buf = new StringBuffer(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 8][0] = "Conductivity"; + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 8][i + 1] = nf + .format(thermoSystem.getPhases()[i].getPhysicalProperties().getConductivity(), buf, test) + .toString(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 8][4] = "[W/m*K]"; + + buf = new StringBuffer(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 10][0] = "Pressure"; + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 10][i + 1] = + Double.toString(thermoSystem.getPhases()[i].getPressure()); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 10][4] = "[bar]"; + + buf = new StringBuffer(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 11][0] = "Temperature"; + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 11][i + 1] = + Double.toString(thermoSystem.getPhases()[i].getTemperature()); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 11][4] = "[K]"; + Double.toString(thermoSystem.getPhases()[i].getTemperature()); + + buf = new StringBuffer(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][0] = "Stream"; + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][i + 1] = getName(); + table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][4] = "-"; } - public void isSetWaterInDryGas(boolean isSetwaterInDryGas) { - this.isSetWaterInDryGas = isSetwaterInDryGas; - } + JTable Jtab = new JTable(table, names); + JScrollPane scrollpane = new JScrollPane(Jtab); + dialogContentPane.add(scrollpane); + dialog.pack(); + dialog.setVisible(true); + } + + /** + *
+ * Setter for the field gasOutStream
.
+ *
+ * Getter for the field solventOutStream
.
+ *
+ * Setter for the field solventOutStream
.
+ *
+ * Setter for the field waterInDryGas
.
+ *
- * Constructor for WaterStripperColumn. - *
- */ - @Deprecated - public WaterStripperColumn() { - } - - /** - *- * Constructor for WaterStripperColumn. - *
- * - * @param name a {@link java.lang.String} object - */ - public WaterStripperColumn(String name) { - super(name); - } - - /** {@inheritDoc} */ - @Override - public void addStream(StreamInterface newStream) { - streams.add(newStream); - if (numberOfInputStreams == 0) { - mixedStream = (Stream) streams.get(0).clone(); - mixedStream.getThermoSystem().setNumberOfPhases(2); - mixedStream.getThermoSystem().reInitPhaseType(); - mixedStream.getThermoSystem().init(0); - mixedStream.getThermoSystem().init(3); - } - - numberOfInputStreams++; - } - - /** - *- * addGasInStream. - *
- * - * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public void addGasInStream(StreamInterface newStream) { - gasInStream = (Stream) newStream; - gasOutStream = (Stream) newStream.clone(); - addStream(newStream); - } - - /** - *- * addSolventInStream. - *
- * - * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public void addSolventInStream(StreamInterface newStream) { - solventInStream = (Stream) newStream; - solventOutStream = (Stream) newStream.clone(); - addStream(newStream); - solventStreamNumber = streams.size() - 1; + private static final long serialVersionUID = 1000; + + protected ArrayList+ * Constructor for WaterStripperColumn. + *
+ */ + @Deprecated + public WaterStripperColumn() {} + + /** + *+ * Constructor for WaterStripperColumn. + *
+ * + * @param name a {@link java.lang.String} object + */ + public WaterStripperColumn(String name) { + super(name); + } + + /** {@inheritDoc} */ + @Override + public void addStream(StreamInterface newStream) { + streams.add(newStream); + if (numberOfInputStreams == 0) { + mixedStream = (Stream) streams.get(0).clone(); + mixedStream.getThermoSystem().setNumberOfPhases(2); + mixedStream.getThermoSystem().reInitPhaseType(); + mixedStream.getThermoSystem().init(0); + mixedStream.getThermoSystem().init(3); } - /** - *- * replaceSolventInStream. - *
- * - * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public void replaceSolventInStream(StreamInterface newStream) { - solventInStream = (Stream) newStream; - streams.set(solventStreamNumber, solventInStream); - } - - /** {@inheritDoc} */ - @Override - public void setPressure(double pressure) { - this.pressure = pressure; - } - - /** - *- * mixStream. - *
- */ - public void mixStream() { - String compName = new String(); - - for (int k = 1; k < streams.size(); k++) { - for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] - .getNumberOfComponents(); i++) { - boolean gotComponent = false; - String componentName = - streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i] - .getName(); - // System.out.println("adding: " + componentName); - - double moles = streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i] - .getNumberOfmoles(); - // System.out.println("moles: " + moles + " " + - // mixedStream.getThermoSystem().getPhases()[0].getNumberOfComponents()); - for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] - .getNumberOfComponents(); p++) { - if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() - .equals(componentName)) { - gotComponent = true; - - compName = - streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] - .getComponentName(); - } - } - - if (gotComponent) { - // System.out.println("adding moles starting...."); - mixedStream.getThermoSystem().addComponent(compName, moles); - // mixedStream.getThermoSystem().init_x_y(); - // System.out.println("adding moles finished"); - } else { - // System.out.println("ikke gaa hit"); - mixedStream.getThermoSystem().addComponent(compName, moles); - } - } - } - mixedStream.getThermoSystem().init_x_y(); - mixedStream.getThermoSystem().initBeta(); - mixedStream.getThermoSystem().init(2); - } - - /** - *- * guessTemperature. - *
- * - * @return a double - */ - public double guessTemperature() { - double gtemp = 0; - for (int k = 0; k < streams.size(); k++) { - gtemp += streams.get(k).getThermoSystem().getTemperature() - * streams.get(k).getThermoSystem().getNumberOfMoles() - / mixedStream.getThermoSystem().getNumberOfMoles(); + numberOfInputStreams++; + } + + /** + *+ * addGasInStream. + *
+ * + * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public void addGasInStream(StreamInterface newStream) { + gasInStream = (Stream) newStream; + gasOutStream = (Stream) newStream.clone(); + addStream(newStream); + } + + /** + *+ * addSolventInStream. + *
+ * + * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public void addSolventInStream(StreamInterface newStream) { + solventInStream = (Stream) newStream; + solventOutStream = (Stream) newStream.clone(); + addStream(newStream); + solventStreamNumber = streams.size() - 1; + } + + /** + *+ * replaceSolventInStream. + *
+ * + * @param newStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public void replaceSolventInStream(StreamInterface newStream) { + solventInStream = (Stream) newStream; + streams.set(solventStreamNumber, solventInStream); + } + + /** {@inheritDoc} */ + @Override + public void setPressure(double pressure) { + this.pressure = pressure; + } + + /** + *+ * mixStream. + *
+ */ + public void mixStream() { + String compName = new String(); + + for (int k = 1; k < streams.size(); k++) { + for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] + .getNumberOfComponents(); i++) { + boolean gotComponent = false; + String componentName = + streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i].getName(); + // System.out.println("adding: " + componentName); + + double moles = + streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i].getNumberOfmoles(); + // System.out.println("moles: " + moles + " " + + // mixedStream.getThermoSystem().getPhases()[0].getNumberOfComponents()); + for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] + .getNumberOfComponents(); p++) { + if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() + .equals(componentName)) { + gotComponent = true; + + compName = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] + .getComponentName(); + } } - return gtemp; - } - /** - *- * calcMixStreamEnthalpy. - *
- * - * @return a double - */ - public double calcMixStreamEnthalpy() { - double enthalpy = 0; - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); - // System.out.println("total enthalpy k : " + ( - // ((StreamInterface) streams.get(k)).getThermoSystem()).getEnthalpy()); + if (gotComponent) { + // System.out.println("adding moles starting...."); + mixedStream.getThermoSystem().addComponent(compName, moles); + // mixedStream.getThermoSystem().init_x_y(); + // System.out.println("adding moles finished"); + } else { + // System.out.println("ikke gaa hit"); + mixedStream.getThermoSystem().addComponent(compName, moles); } - // System.out.println("total enthalpy of streams: " + enthalpy); - return enthalpy; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getOutStream() { - return mixedStream; - } - - /** - *- * getInStream. - *
- * - * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - public StreamInterface getInStream() { - return gasInStream; + } } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGasOutStream() { - return gasOutStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getLiquidOutStream() { - return solventOutStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getSolventInStream() { - return solventInStream; - } - - /** - *- * calcEa. - *
- * - * @return a double - */ - public double calcEa() { - double A = mixedStream.getThermoSystem().getPhase(1).getNumberOfMolesInPhase() - / mixedStream.getThermoSystem().getPhase(0).getNumberOfMolesInPhase() / kwater; - absorptionEfficiency = (Math.pow(A, getNumberOfTheoreticalStages() + 1) - A) - / (Math.pow(A, getNumberOfTheoreticalStages() + 1) - 1.0); - return absorptionEfficiency; - } - - /** - *- * calcX0. - *
- * - * @return a double - */ - public double calcX0() { - return 0.0; + mixedStream.getThermoSystem().init_x_y(); + mixedStream.getThermoSystem().initBeta(); + mixedStream.getThermoSystem().init(2); + } + + /** + *+ * guessTemperature. + *
+ * + * @return a double + */ + public double guessTemperature() { + double gtemp = 0; + for (int k = 0; k < streams.size(); k++) { + gtemp += streams.get(k).getThermoSystem().getTemperature() + * streams.get(k).getThermoSystem().getNumberOfMoles() + / mixedStream.getThermoSystem().getNumberOfMoles(); } - - /** - *- * calcNumberOfTheoreticalStages. - *
- * - * @return a double - */ - public double calcNumberOfTheoreticalStages() { - setNumberOfTheoreticalStages(getStageEfficiency() * getNumberOfStages()); - return getNumberOfTheoreticalStages(); - } - - /** - *- * calcNTU. - *
- * - * @param y0 a double - * @param y1 a double - * @param yb a double - * @param ymix a double - * @return a double - */ - public double calcNTU(double y0, double y1, double yb, double ymix) { - double NTU = Math.log((yb - ymix) / (y1 - y0)); - return NTU; + return gtemp; + } + + /** + *+ * calcMixStreamEnthalpy. + *
+ * + * @return a double + */ + public double calcMixStreamEnthalpy() { + double enthalpy = 0; + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); + // System.out.println("total enthalpy k : " + ( + // ((StreamInterface) streams.get(k)).getThermoSystem()).getEnthalpy()); } - - /** {@inheritDoc} */ - @Override - public void run() { - try { - double x2 = getSolventInStream().getFluid().getPhase(0).getComponent("water").getz(); - double x0 = 0.0; - double absorptionEffiency = 0.0; - mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); - mixedStream.getThermoSystem().setNumberOfPhases(2); - mixedStream.getThermoSystem().reInitPhaseType(); - mixedStream.getThermoSystem().init(0); - mixStream(); - double enthalpy = calcMixStreamEnthalpy(); - //// System.out.println("temp guess " + guessTemperature()); - mixedStream.getThermoSystem().setTemperature(guessTemperature()); - ThermodynamicOperations testOps = - new ThermodynamicOperations(mixedStream.getThermoSystem()); - testOps.TPflash(); - testOps.PHflash(enthalpy, 0); - - if (mixedStream.getThermoSystem().getNumberOfPhases() == 1) { - if (mixedStream.getThermoSystem().getPhase(0).getPhaseTypeName() - .equals("aqueous")) { - SystemInterface tempSystem = mixedStream.getThermoSystem().clone(); - gasOutStream.setEmptyThermoSystem(tempSystem); - gasOutStream.run(); - solventOutStream.setThermoSystem(tempSystem); - solventOutStream.run(); - } - if (mixedStream.getThermoSystem().getPhase(0).getPhaseTypeName().equals("gas")) { - SystemInterface tempSystem = mixedStream.getThermoSystem().clone(); - solventOutStream.setEmptyThermoSystem(tempSystem); - solventOutStream.run(); - gasOutStream.setThermoSystem(tempSystem); - gasOutStream.run(); - } - return; - } - - kwater = mixedStream.getThermoSystem().getPhase(0).getComponent("water").getx() - / mixedStream.getThermoSystem().getPhase(1).getComponent("water").getx(); - - double Ntheoretical = calcNumberOfTheoreticalStages(); - // System.out.println("number of theoretical stages " + - // getNumberOfTheoreticalStages()); - absorptionEffiency = calcEa(); - - x0 = calcX0(); - double revA = 1.0 / absorptionEffiency; - - double x1 = x2 - (Math.pow(revA, Ntheoretical + 1) - revA) - / (Math.pow(revA, Ntheoretical + 1) - 1.0) * (x2 - x0); - - double xMean = mixedStream.getThermoSystem().getPhase(1).getComponent("water").getx(); - double molesWaterToMove = (xMean - x1) - * mixedStream.getThermoSystem().getPhase(1).getNumberOfMolesInPhase(); - // System.out.println("mole water to move " + molesWaterToMove); - - StreamInterface stream = mixedStream.clone(); - stream.setName("test"); - stream.getThermoSystem().addComponent("water", molesWaterToMove, 0); - stream.getThermoSystem().addComponent("water", -molesWaterToMove, 1); - stream.getThermoSystem().initBeta(); - stream.getThermoSystem().init_x_y(); - stream.getThermoSystem().init(2); - mixedStream = stream; - // stream.getThermoSystem().display(); - - SystemInterface tempSystem = mixedStream.getThermoSystem().clone(); - SystemInterface gasTemp = tempSystem.phaseToSystem(tempSystem.getPhases()[0]); - gasTemp.init(2); - gasOutStream.setThermoSystem(gasTemp); - - tempSystem = mixedStream.getThermoSystem().clone(); - SystemInterface liqTemp = tempSystem.phaseToSystem(tempSystem.getPhases()[1]); - liqTemp.init(2); - solventOutStream.setThermoSystem(liqTemp); - solventOutStream.run(); - // System.out.println("Gas from water stripper " + - // gasOutStream.getFlowRate("kg/hr") + " kg/hr"); - - // System.out.println("TEG from water stripper " + - // solventOutStream.getFlowRate("kg/hr") + " kg/hr"); - } catch (Exception e) { - e.printStackTrace(); + // System.out.println("total enthalpy of streams: " + enthalpy); + return enthalpy; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getOutStream() { + return mixedStream; + } + + /** + *+ * getInStream. + *
+ * + * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + public StreamInterface getInStream() { + return gasInStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getGasOutStream() { + return gasOutStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getLiquidOutStream() { + return solventOutStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getSolventInStream() { + return solventInStream; + } + + /** + *+ * calcEa. + *
+ * + * @return a double + */ + public double calcEa() { + double A = mixedStream.getThermoSystem().getPhase(1).getNumberOfMolesInPhase() + / mixedStream.getThermoSystem().getPhase(0).getNumberOfMolesInPhase() / kwater; + absorptionEfficiency = (Math.pow(A, getNumberOfTheoreticalStages() + 1) - A) + / (Math.pow(A, getNumberOfTheoreticalStages() + 1) - 1.0); + return absorptionEfficiency; + } + + /** + *+ * calcX0. + *
+ * + * @return a double + */ + public double calcX0() { + return 0.0; + } + + /** + *+ * calcNumberOfTheoreticalStages. + *
+ * + * @return a double + */ + public double calcNumberOfTheoreticalStages() { + setNumberOfTheoreticalStages(getStageEfficiency() * getNumberOfStages()); + return getNumberOfTheoreticalStages(); + } + + /** + *+ * calcNTU. + *
+ * + * @param y0 a double + * @param y1 a double + * @param yb a double + * @param ymix a double + * @return a double + */ + public double calcNTU(double y0, double y1, double yb, double ymix) { + return Math.log((yb - ymix) / (y1 - y0)); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + try { + double x2 = getSolventInStream().getFluid().getPhase(0).getComponent("water").getz(); + double x0 = 0.0; + double absorptionEffiency = 0.0; + mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); + mixedStream.getThermoSystem().setNumberOfPhases(2); + mixedStream.getThermoSystem().reInitPhaseType(); + mixedStream.getThermoSystem().init(0); + mixStream(); + double enthalpy = calcMixStreamEnthalpy(); + //// System.out.println("temp guess " + guessTemperature()); + mixedStream.getThermoSystem().setTemperature(guessTemperature()); + ThermodynamicOperations testOps = new ThermodynamicOperations(mixedStream.getThermoSystem()); + testOps.TPflash(); + testOps.PHflash(enthalpy, 0); + + if (mixedStream.getThermoSystem().getNumberOfPhases() == 1) { + if (mixedStream.getThermoSystem().getPhase(0).getPhaseTypeName().equals("aqueous")) { + SystemInterface tempSystem = mixedStream.getThermoSystem().clone(); + gasOutStream.setEmptyThermoSystem(tempSystem); + gasOutStream.run(id); + solventOutStream.setThermoSystem(tempSystem); + solventOutStream.run(id); } - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - SystemInterface thermoSystem = mixedStream.getThermoSystem(); - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(5); - nf.applyPattern("#.#####E0"); - - JDialog dialog = new JDialog(new JFrame(), "Results from TPflash"); - Container dialogContentPane = dialog.getContentPane(); - dialogContentPane.setLayout(new FlowLayout()); - - thermoSystem.initPhysicalProperties(); - String[][] table = new String[50][5]; - String[] names = {"", "Phase 1", "Phase 2", "Phase 3", "Unit"}; - table[0][0] = ""; - table[0][1] = ""; - table[0][2] = ""; - table[0][3] = ""; - StringBuffer buf = new StringBuffer(); - FieldPosition test = new FieldPosition(0); - - for (int i = 0; i < thermoSystem.getNumberOfPhases(); i++) { - for (int j = 0; j < thermoSystem.getPhases()[0].getNumberOfComponents(); j++) { - table[j + 1][0] = thermoSystem.getPhases()[0].getComponents()[j].getName(); - buf = new StringBuffer(); - table[j + 1][i + 1] = - nf.format(thermoSystem.getPhases()[i].getComponents()[j].getx(), buf, test) - .toString(); - table[j + 1][4] = "[-]"; - } - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 2][0] = "Density"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 2][i + 1] = - nf.format(thermoSystem.getPhases()[i].getPhysicalProperties().getDensity(), buf, - test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 2][4] = "[kg/m^3]"; - - // Double.longValue(thermoSystem.getPhases()[i].getBeta()); - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 3][0] = "PhaseFraction"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 3][i + 1] = - nf.format(thermoSystem.getPhases()[i].getBeta(), buf, test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 3][4] = "[-]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 4][0] = "MolarMass"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 4][i + 1] = - nf.format(thermoSystem.getPhases()[i].getMolarMass() * 1000, buf, test) - .toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 4][4] = "[kg/kmol]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 5][0] = "Cp"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 5][i + 1] = nf.format( - (thermoSystem.getPhases()[i].getCp() - / (thermoSystem.getPhases()[i].getNumberOfMolesInPhase() - * thermoSystem.getPhases()[i].getMolarMass() * 1000)), - buf, test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 5][4] = "[kJ/kg*K]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 7][0] = "Viscosity"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 7][i + 1] = - nf.format((thermoSystem.getPhases()[i].getPhysicalProperties().getViscosity()), - buf, test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 7][4] = "[kg/m*sec]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 8][0] = "Conductivity"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 8][i + 1] = - nf.format(thermoSystem.getPhases()[i].getPhysicalProperties().getConductivity(), - buf, test).toString(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 8][4] = "[W/m*K]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 10][0] = "Pressure"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 10][i + 1] = - Double.toString(thermoSystem.getPhases()[i].getPressure()); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 10][4] = "[bar]"; - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 11][0] = "Temperature"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 11][i + 1] = - Double.toString(thermoSystem.getPhases()[i].getTemperature()); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 11][4] = "[K]"; - Double.toString(thermoSystem.getPhases()[i].getTemperature()); - - buf = new StringBuffer(); - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][0] = "Stream"; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][i + 1] = name; - table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][4] = "-"; + if (mixedStream.getThermoSystem().getPhase(0).getPhaseTypeName().equals("gas")) { + SystemInterface tempSystem = mixedStream.getThermoSystem().clone(); + solventOutStream.setEmptyThermoSystem(tempSystem); + solventOutStream.run(id); + gasOutStream.setThermoSystem(tempSystem); + gasOutStream.run(id); } - - JTable Jtab = new JTable(table, names); - JScrollPane scrollpane = new JScrollPane(Jtab); - dialogContentPane.add(scrollpane); - dialog.pack(); - dialog.setVisible(true); - } - - /** - *
- * Getter for the field waterDewPointTemperature
.
- *
- * Setter for the field waterDewPointTemperature
.
- *
- * Setter for the field gasOutStream
.
- *
- * Getter for the field solventOutStream
.
- *
- * Setter for the field solventOutStream
.
- *
+ * Getter for the field waterDewPointTemperature
.
+ *
+ * Setter for the field waterDewPointTemperature
.
+ *
+ * Setter for the field gasOutStream
.
+ *
+ * Getter for the field solventOutStream
.
+ *
+ * Setter for the field solventOutStream
.
+ *
- * Constructor for SimpleAdsorber. - *
- */ - @Deprecated - public SimpleAdsorber() { - this("SimpleAdsorber"); - } - - /** - *- * Constructor for SimpleAdsorber. - *
- * - * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public SimpleAdsorber(StreamInterface inStream1) { - this("SimpleAdsorber"); - this.inStream[0] = inStream1; - this.inStream[1] = inStream1; - outStream[0] = (Stream) inStream1.clone(); - outStream[1] = (Stream) inStream1.clone(); - - SystemInterface systemOut1 = inStream1.getThermoSystem().clone(); - outStream[0].setThermoSystem(systemOut1); - - double molCO2 = - inStream1.getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfmoles(); - System.out.println("mol CO2 " + molCO2); - SystemInterface systemOut0 = inStream1.getThermoSystem().clone(); - systemOut0.init(0); - systemOut0.addComponent("MDEA", molCO2 * absorptionEfficiency); - systemOut0.addComponent("water", molCO2 * absorptionEfficiency * 10.0); - systemOut0.chemicalReactionInit(); - systemOut0.createDatabase(true); - systemOut0.setMixingRule(4); - outStream[1].setThermoSystem(systemOut0); - outStream[1].run(); - } - - /** {@inheritDoc} */ - public SimpleAdsorber(String name) { - super(name); - } - - /** - *- * Constructor for SimpleAdsorber. - *
- * - * @param name name of the unit operation - * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public SimpleAdsorber(String name, StreamInterface inStream1) { - this(name); - this.inStream[0] = inStream1; - this.inStream[1] = inStream1; - outStream[0] = (Stream) inStream1.clone(); - outStream[1] = (Stream) inStream1.clone(); - setName(name); - - SystemInterface systemOut1 = inStream1.getThermoSystem().clone(); - outStream[0].setThermoSystem(systemOut1); - - double molCO2 = - inStream1.getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfmoles(); - System.out.println("mol CO2 " + molCO2); - SystemInterface systemOut0 = inStream1.getThermoSystem().clone(); - systemOut0.init(0); - systemOut0.addComponent("MDEA", molCO2 * absorptionEfficiency); - systemOut0.addComponent("water", molCO2 * absorptionEfficiency * 10.0); - systemOut0.chemicalReactionInit(); - systemOut0.createDatabase(true); - systemOut0.setMixingRule(4); - outStream[1].setThermoSystem(systemOut0); - outStream[1].run(); - } - - public AdsorberMechanicalDesign getMechanicalDesign() { - return new AdsorberMechanicalDesign(this); - } - - /** {@inheritDoc} */ - @Override - public void setName(String name) { - super.setName(name); - outStream[0].setName(name + "_Sout1"); - outStream[1].setName(name + "_Sout2"); - } - - /** - *
- * Setter for the field dT
.
- *
- * Getter for the field outStream
.
- *
- * setOutTemperature. - *
- * - * @param temperature a double - */ - public void setOutTemperature(double temperature) { - this.temperatureOut = temperature; - } - - /** - *- * getOutTemperature. - *
- * - * @param i a int - */ - public void getOutTemperature(int i) { - outStream[i].getThermoSystem().getTemperature(); - } - - /** - *- * getInTemperature. - *
- * - * @param i a int - */ - public void getInTemperature(int i) { - inStream[i].getThermoSystem().getTemperature(); - } - - /** {@inheritDoc} */ - @Override - public void run() { - SystemInterface systemOut1 = inStream[1].getThermoSystem().clone(); - outStream[0].setThermoSystem(systemOut1); - outStream[0].run(); - - outStream[1].run(); - - double error = 1e5; - error = absorptionEfficiency - (outStream[1].getThermoSystem().getPhase(1) - .getComponent("CO2").getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("HCO3-") - .getNumberOfMolesInPhase()) - / (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA") - .getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") - .getNumberOfMolesInPhase()); - int iter = 0; - do { - iter++; - double factor = (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA") - .getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") - .getNumberOfMolesInPhase()); - // outStream[1].getThermoSystem().addComponent("CO2",(20.0-outStream[1].getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfMolesInPhase()),0); - outStream[1].getThermoSystem().addComponent("MDEA", -error * factor); - outStream[1].getThermoSystem().addComponent("water", -error * 10.0 * factor); - outStream[1].run(); - error = absorptionEfficiency - ((outStream[1].getThermoSystem().getPhase(1) - .getComponent("CO2").getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("HCO3-") - .getNumberOfMolesInPhase()) - / (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA") - .getNumberOfMolesInPhase() - + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") - .getNumberOfMolesInPhase())); - - System.out.println("error " + error); - } while (Math.abs(error) > 1e-4 && iter < 30 - && outStream[1].getThermoSystem().getPhase(1).getBeta() > 0 - && outStream[0].getThermoSystem().getPhase(1).getBeta() > 0); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - outStream[0].displayResult(); - outStream[1].displayResult(); - } - - /** - *- * setAproachToEquilibrium. - *
- * - * @param eff a double - */ - public void setAproachToEquilibrium(double eff) { - this.absorptionEfficiency = eff; - } - - /** - *
- * Getter for the field numberOfTheoreticalStages
.
- *
- * Setter for the field numberOfTheoreticalStages
.
- *
- * Getter for the field numberOfStages
.
- *
- * Setter for the field numberOfStages
.
- *
- * Getter for the field stageEfficiency
.
- *
- * Setter for the field stageEfficiency
.
- *
- * getHTU. - *
- * - * @return a double - */ - public double getHTU() { - return HTU; - } - - /** - *- * setHTU. - *
- * - * @param HTU a double - */ - public void setHTU(double HTU) { - this.HTU = HTU; - } - - /** - *- * getNTU. - *
- * - * @return a double - */ - public double getNTU() { - return NTU; - } - - /** - *- * setNTU. - *
- * - * @param NTU a double - */ - public void setNTU(double NTU) { - this.NTU = NTU; - } + private static final long serialVersionUID = 1000; + + boolean setTemperature = false; + String name = new String(); + StreamInterface[] outStream = new Stream[2]; + StreamInterface[] inStream = new Stream[2]; + SystemInterface system; + protected double temperatureOut = 0; + + protected double dT = 0.0; + + private int numberOfStages = 5; + private double numberOfTheoreticalStages = 3.0; + double absorptionEfficiency = 0.5; + private double HTU = 0.85; + private double NTU = 2.0; + private double stageEfficiency = 0.25; + + /** + *+ * Constructor for SimpleAdsorber. + *
+ */ + @Deprecated + public SimpleAdsorber() { + this("SimpleAdsorber"); + } + + /** + *+ * Constructor for SimpleAdsorber. + *
+ * + * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public SimpleAdsorber(StreamInterface inStream1) { + this("SimpleAdsorber"); + this.inStream[0] = inStream1; + this.inStream[1] = inStream1; + outStream[0] = (Stream) inStream1.clone(); + outStream[1] = (Stream) inStream1.clone(); + + SystemInterface systemOut1 = inStream1.getThermoSystem().clone(); + outStream[0].setThermoSystem(systemOut1); + + double molCO2 = inStream1.getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfmoles(); + System.out.println("mol CO2 " + molCO2); + SystemInterface systemOut0 = inStream1.getThermoSystem().clone(); + systemOut0.init(0); + systemOut0.addComponent("MDEA", molCO2 * absorptionEfficiency); + systemOut0.addComponent("water", molCO2 * absorptionEfficiency * 10.0); + systemOut0.chemicalReactionInit(); + systemOut0.createDatabase(true); + systemOut0.setMixingRule(4); + outStream[1].setThermoSystem(systemOut0); + outStream[1].run(); + } + + /** {@inheritDoc} */ + public SimpleAdsorber(String name) { + super(name); + } + + /** + *+ * Constructor for SimpleAdsorber. + *
+ * + * @param name name of the unit operation + * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public SimpleAdsorber(String name, StreamInterface inStream1) { + this(name); + this.inStream[0] = inStream1; + this.inStream[1] = inStream1; + outStream[0] = (Stream) inStream1.clone(); + outStream[1] = (Stream) inStream1.clone(); + setName(name); + + SystemInterface systemOut1 = inStream1.getThermoSystem().clone(); + outStream[0].setThermoSystem(systemOut1); + + double molCO2 = inStream1.getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfmoles(); + System.out.println("mol CO2 " + molCO2); + SystemInterface systemOut0 = inStream1.getThermoSystem().clone(); + systemOut0.init(0); + systemOut0.addComponent("MDEA", molCO2 * absorptionEfficiency); + systemOut0.addComponent("water", molCO2 * absorptionEfficiency * 10.0); + systemOut0.chemicalReactionInit(); + systemOut0.createDatabase(true); + systemOut0.setMixingRule(4); + outStream[1].setThermoSystem(systemOut0); + outStream[1].run(); + } + + public AdsorberMechanicalDesign getMechanicalDesign() { + return new AdsorberMechanicalDesign(this); + } + + /** {@inheritDoc} */ + @Override + public void setName(String name) { + super.setName(name); + outStream[0].setName(name + "_Sout1"); + outStream[1].setName(name + "_Sout2"); + } + + /** + *
+ * Setter for the field dT
.
+ *
+ * Getter for the field outStream
.
+ *
+ * setOutTemperature. + *
+ * + * @param temperature a double + */ + public void setOutTemperature(double temperature) { + this.temperatureOut = temperature; + } + + /** + *+ * getOutTemperature. + *
+ * + * @param i a int + */ + public void getOutTemperature(int i) { + outStream[i].getThermoSystem().getTemperature(); + } + + /** + *+ * getInTemperature. + *
+ * + * @param i a int + */ + public void getInTemperature(int i) { + inStream[i].getThermoSystem().getTemperature(); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + SystemInterface systemOut1 = inStream[1].getThermoSystem().clone(); + outStream[0].setThermoSystem(systemOut1); + outStream[0].run(id); + outStream[1].run(); + + double error = 1e5; + error = absorptionEfficiency - (outStream[1].getThermoSystem().getPhase(1).getComponent("CO2") + .getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("HCO3-") + .getNumberOfMolesInPhase()) + / (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA").getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") + .getNumberOfMolesInPhase()); + int iter = 0; + do { + iter++; + double factor = + (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA").getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") + .getNumberOfMolesInPhase()); + // outStream[1].getThermoSystem().addComponent("CO2",(20.0-outStream[1].getThermoSystem().getPhase(0).getComponent("CO2").getNumberOfMolesInPhase()),0); + outStream[1].getThermoSystem().addComponent("MDEA", -error * factor); + outStream[1].getThermoSystem().addComponent("water", -error * 10.0 * factor); + outStream[1].run(); + error = absorptionEfficiency - ((outStream[1].getThermoSystem().getPhase(1) + .getComponent("CO2").getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("HCO3-") + .getNumberOfMolesInPhase()) + / (outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA") + .getNumberOfMolesInPhase() + + outStream[1].getThermoSystem().getPhase(1).getComponent("MDEA+") + .getNumberOfMolesInPhase())); + + System.out.println("error " + error); + } while (Math.abs(error) > 1e-4 && iter < 30 + && outStream[1].getThermoSystem().getPhase(1).getBeta() > 0 + && outStream[0].getThermoSystem().getPhase(1).getBeta() > 0); + outStream[1].setCalculationIdentifier(id); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + outStream[0].displayResult(); + outStream[1].displayResult(); + } + + /** + *+ * setAproachToEquilibrium. + *
+ * + * @param eff a double + */ + public void setAproachToEquilibrium(double eff) { + this.absorptionEfficiency = eff; + } + + /** + *
+ * Getter for the field numberOfTheoreticalStages
.
+ *
+ * Setter for the field numberOfTheoreticalStages
.
+ *
+ * Getter for the field numberOfStages
.
+ *
+ * Setter for the field numberOfStages
.
+ *
+ * Getter for the field stageEfficiency
.
+ *
+ * Setter for the field stageEfficiency
.
+ *
+ * getHTU. + *
+ * + * @return a double + */ + public double getHTU() { + return HTU; + } + + /** + *+ * setHTU. + *
+ * + * @param HTU a double + */ + public void setHTU(double HTU) { + this.HTU = HTU; + } + + /** + *+ * getNTU. + *
+ * + * @return a double + */ + public double getNTU() { + return NTU; + } + + /** + *+ * setNTU. + *
+ * + * @param NTU a double + */ + public void setNTU(double NTU) { + this.NTU = NTU; + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/compressor/Compressor.java b/src/main/java/neqsim/processSimulation/processEquipment/compressor/Compressor.java index 9af7506ac8..5d5686452b 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/compressor/Compressor.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/compressor/Compressor.java @@ -5,15 +5,13 @@ import java.text.DecimalFormat; import java.text.FieldPosition; import java.util.Objects; - +import java.util.UUID; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - import neqsim.processSimulation.mechanicalDesign.compressor.CompressorMechanicalDesign; import neqsim.processSimulation.processEquipment.TwoPortEquipment; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -30,1286 +28,1289 @@ * @version $Id: $Id */ public class Compressor extends TwoPortEquipment implements CompressorInterface { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(Compressor.class); - public SystemInterface thermoSystem; - private double outTemperature = 298.15; - private boolean useOutTemperature = false; - private CompressorPropertyProfile propertyProfile = new CompressorPropertyProfile(); - public double dH = 0.0; - public double inletEnthalpy = 0; - public double pressure = 0.0; - private int speed = 3000; - public double isentropicEfficiency = 1.0, polytropicEfficiency = 1.0; - public boolean usePolytropicCalc = false; - public boolean powerSet = false; - private CompressorChartInterface compressorChart = new CompressorChart(); - private AntiSurge antiSurge = new AntiSurge(); - private double polytropicHead = 0; - private double polytropicFluidHead = 0, polytropicHeadMeter = 0.0; - private double polytropicExponent = 0; - private int numberOfCompressorCalcSteps = 40; - private boolean useRigorousPolytropicMethod = false; - private boolean useGERG2008 = false; - private String pressureUnit = "bara"; - private String polytropicMethod = "detailed"; - - /** - *- * Constructor for Compressor. - *
- */ - @Deprecated - public Compressor() { - this("Compressor"); - } - - /** - *- * Constructor for Compressor. - *
- * - * @param inletStream a - * {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public Compressor(StreamInterface inletStream) { - this(); - setInletStream(inletStream); - } - - /** - *- * Constructor for Compressor. - *
- * - * @param interpolateMapLookup a boolean - */ - @Deprecated - public Compressor(boolean interpolateMapLookup) { - this("Compressor", interpolateMapLookup); - } - - /** - * Constructor for Compressor. - * - * @param name - */ - public Compressor(String name) { - super(name); - } - - /** - *- * Constructor for Compressor. - *
- * - * @param name a {@link java.lang.String} object - * @param inletStream a - * {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public Compressor(String name, StreamInterface inletStream) { - this(name); - setInletStream(inletStream); - } - - /** - *- * Constructor for Compressor. - *
- * - * @param name - * @param interpolateMapLookup a boolean - */ - public Compressor(String name, boolean interpolateMapLookup) { - this(name); - if (interpolateMapLookup) { - compressorChart = new CompressorChartAlternativeMapLookup(); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(Compressor.class); + public SystemInterface thermoSystem; + private double outTemperature = 298.15; + private boolean useOutTemperature = false; + private CompressorPropertyProfile propertyProfile = new CompressorPropertyProfile(); + public double dH = 0.0; + public double inletEnthalpy = 0; + public double pressure = 0.0; + private int speed = 3000; + public double isentropicEfficiency = 1.0; + public double polytropicEfficiency = 1.0; + public boolean usePolytropicCalc = false; + public boolean powerSet = false; + private CompressorChartInterface compressorChart = new CompressorChart(); + private AntiSurge antiSurge = new AntiSurge(); + private double polytropicHead = 0; + private double polytropicFluidHead = 0; + private double polytropicHeadMeter = 0.0; + private double polytropicExponent = 0; + private int numberOfCompressorCalcSteps = 40; + private boolean useRigorousPolytropicMethod = false; + private boolean useGERG2008 = false; + private String pressureUnit = "bara"; + private String polytropicMethod = "detailed"; + + /** + *+ * Constructor for Compressor. + *
+ */ + @Deprecated + public Compressor() { + this("Compressor"); + } + + /** + *+ * Constructor for Compressor. + *
+ * + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public Compressor(StreamInterface inletStream) { + this(); + setInletStream(inletStream); + } + + /** + *+ * Constructor for Compressor. + *
+ * + * @param interpolateMapLookup a boolean + */ + @Deprecated + public Compressor(boolean interpolateMapLookup) { + this("Compressor", interpolateMapLookup); + } + + /** + * Constructor for Compressor. + * + * @param name + */ + public Compressor(String name) { + super(name); + } + + /** + *+ * Constructor for Compressor. + *
+ * + * @param name a {@link java.lang.String} object + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public Compressor(String name, StreamInterface inletStream) { + this(name); + setInletStream(inletStream); + } + + /** + *+ * Constructor for Compressor. + *
+ * + * @param name + * @param interpolateMapLookup a boolean + */ + public Compressor(String name, boolean interpolateMapLookup) { + this(name); + if (interpolateMapLookup) { + compressorChart = new CompressorChartAlternativeMapLookup(); + } + } + + /** + * {@inheritDoc} + */ + public CompressorMechanicalDesign getMechanicalDesign() { + return new CompressorMechanicalDesign(this); + } + + /** + *+ * Create deep copy. + *
+ * + * @return a {@link neqsim.processSimulation.processSystem.ProcessSystem} object + */ + public Compressor copy() { + return (Compressor) super.copy(); + } + + /** + * {@inheritDoc} + */ + @Override + public void setInletStream(StreamInterface inletStream) { + this.inStream = inletStream; + try { + this.outStream = inletStream.clone(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + *+ * solveAntiSurge. + *
+ */ + public void solveAntiSurge() { + if (getAntiSurge().isActive()) { + // .... + } + } + + /** + * {@inheritDoc} + */ + @Override + public void setOutletPressure(double pressure) { + this.pressure = pressure; + } + + /** + *+ * setOutletPressure. + *
+ * + * @param pressure a double + * @param unit a {@link java.lang.String} object + */ + public void setOutletPressure(double pressure, String unit) { + this.pressure = pressure; + this.pressureUnit = unit; + } + + /** + *+ * getOutletPressure. + *
+ * + * @return a double + */ + public double getOutletPressure() { + return pressure; + } + + /** + * {@inheritDoc} + */ + @Override + public double getEnergy() { + return getTotalWork(); + } + + /** + *+ * getPower. + *
+ * + * @return a double + */ + public double getPower() { + return getTotalWork(); + } + + /** + *+ * getPower. + *
+ * + * @param unit a {@link java.lang.String} object + * @return a double + */ + public double getPower(String unit) { + double conversionFactor = 1.0; + if (unit.equals("MW")) { + conversionFactor = 1.0 / 1.0e6; + } else if (unit.equals("kW")) { + conversionFactor = 1.0 / 1.0e3; + } + return conversionFactor * getPower(); + } + + /** + *+ * setPower. + *
+ * + * @param p a double + */ + public void setPower(double p) { + powerSet = true; + dH = p; + } + + /** + * Calculates polytropic or isentropic efficiency + * + * @param outTemperature a double + * @return a double + */ + public double solveEfficiency(double outTemperature) { + double funk = 0.0; + double funkOld = 0.0; + double newPoly; + double dfunkdPoly = 100.0; + double dPoly = 100.0; + double oldPoly = outTemperature; + useOutTemperature = false; + run(); + useOutTemperature = true; + int iter = 0; + boolean useOld = usePolytropicCalc; + // usePolytropicCalc = true; + // System.out.println("use polytropic " + usePolytropicCalc); + do { + iter++; + funk = getThermoSystem().getTemperature() - outTemperature; + dfunkdPoly = (funk - funkOld) / dPoly; + newPoly = polytropicEfficiency - funk / dfunkdPoly; + if (iter <= 1) { + newPoly = polytropicEfficiency + 0.01; + } + oldPoly = polytropicEfficiency; + polytropicEfficiency = newPoly; + isentropicEfficiency = newPoly; + dPoly = polytropicEfficiency - oldPoly; + funkOld = funk; + useOutTemperature = false; + run(); + useOutTemperature = true; + // System.out.println("temperature compressor " + + // getThermoSystem().getTemperature() + " funk " + funk + " polytropic " + + // polytropicEfficiency); + } while ((Math.abs((getThermoSystem().getTemperature() - outTemperature)) > 1e-5 || iter < 3) + && (iter < 50)); + usePolytropicCalc = useOld; + return newPoly; + } + + /** + *+ * findOutPressure. + *
+ * + * @param hinn a double + * @param hout a double + * @param polytropicEfficiency a double + * @return a double + */ + public double findOutPressure(double hinn, double hout, double polytropicEfficiency) { + double entropy = getThermoSystem().getEntropy(); + getThermoSystem().setPressure(getThermoSystem().getPressure() + 1.0, pressureUnit); + + // System.out.println("entropy inn.." + entropy); + ThermodynamicOperations thermoOps = new ThermodynamicOperations(getThermoSystem()); + thermoOps.PSflash(entropy); + + double houtGuess = hinn + dH / polytropicEfficiency; + thermoOps.PHflash(houtGuess, 0); + System.out.println("TEMPERATURE .." + getThermoSystem().getTemperature()); + return getThermoSystem().getPressure(); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + thermoSystem = inStream.getThermoSystem().clone(); + + if (Math.abs(pressure - thermoSystem.getPressure(pressureUnit)) < 1e-6 + && !compressorChart.isUseCompressorChart()) { + thermoSystem.initProperties(); + outStream.setThermoSystem(getThermoSystem()); + outStream.setCalculationIdentifier(id); + dH = 0.0; + polytropicFluidHead = 0.0; + polytropicHeadMeter = 0.0; + return; + } + + ThermodynamicOperations thermoOps = new ThermodynamicOperations(getThermoSystem()); + thermoOps = new ThermodynamicOperations(getThermoSystem()); + getThermoSystem().init(3); + getThermoSystem().initPhysicalProperties("density"); + double presinn = getThermoSystem().getPressure(); + double hinn = getThermoSystem().getEnthalpy(); + double densInn = getThermoSystem().getDensity(); + double entropy = getThermoSystem().getEntropy(); + + if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + double[] gergProps; + gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); + hinn = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); + entropy = gergProps[8] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); + densInn = getThermoSystem().getPhase(0).getDensity_GERG2008(); + } + + inletEnthalpy = hinn; + boolean surgeCheck = false; + double orginalMolarFLow = thermoSystem.getTotalNumberOfMoles(); + double fractionAntiSurge = 0.0; + double kappa = 0.0; + if (useOutTemperature) { + if (useRigorousPolytropicMethod) { + solveEfficiency(outTemperature); + polytropicHead = getPower() / getThermoSystem().getFlowRate("kg/sec") / 1000.0 + * getPolytropicEfficiency(); + polytropicFluidHead = polytropicHead; + polytropicHeadMeter = + polytropicFluidHead * 1000.0 / ThermodynamicConstantsInterface.gravity; + return; + } else { + double MW = thermoSystem.getMolarMass(); + thermoSystem.setPressure(getOutletPressure(), pressureUnit); + thermoOps.PSflash(entropy); + if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + thermoOps.PSflashGERG2008(entropy); } - } - - /** - * {@inheritDoc} - */ - public CompressorMechanicalDesign getMechanicalDesign() { - return new CompressorMechanicalDesign(this); - } - - /** - *- * Create deep copy. - *
- * - * @return a {@link neqsim.processSimulation.processSystem.ProcessSystem} - * object - */ - public Compressor copy() { - return (Compressor) super.copy(); - } - - /** - * {@inheritDoc} - */ - @Override - public void setInletStream(StreamInterface inletStream) { - this.inStream = inletStream; - try { - this.outStream = inletStream.clone(); - } catch (Exception e) { - e.printStackTrace(); + thermoSystem.initPhysicalProperties("density"); + double densOutIsentropic = thermoSystem.getDensity("kg/m3"); + double enthalpyOutIsentropic = thermoSystem.getEnthalpy(); + if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + double[] gergProps; + gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); + densOutIsentropic = getThermoSystem().getPhase(0).getDensity_GERG2008(); + enthalpyOutIsentropic = + gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); + } + thermoSystem.setTemperature(outTemperature); + thermoOps.TPflash(); + thermoSystem.init(2); + thermoSystem.initPhysicalProperties("density"); + double outEnthalpy = thermoSystem.getEnthalpy(); + double densOut = thermoSystem.getDensity("kg/m3"); + if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + double[] gergProps; + gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); + outEnthalpy = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); + densOut = getThermoSystem().getPhase(0).getDensity_GERG2008(); + } + dH = outEnthalpy - inletEnthalpy; + // System.out.println("total power " + + // dH/getThermoSystem().getFlowRate("kg/sec")); + + double n = Math.log(getOutletPressure() / presinn) / Math.log(densOut / densInn); + double CF = (enthalpyOutIsentropic - inletEnthalpy) / thermoSystem.getFlowRate("kg/sec") + / (n / (n - 1.0) + * (getOutletPressure() * 1e5 / densOutIsentropic - presinn * 1e5 / densInn)); + + double F1 = thermoSystem.getTotalNumberOfMoles(); + double polytropicPower = F1 * MW * (n / (n - 1.0)) * CF * presinn * 1e5 / densInn + * (Math.pow((getOutletPressure() / presinn), (n - 1.0) / n) - 1.0); + // System.out.println("polytropic power " + + // polytropicPower/getThermoSystem().getFlowRate("kg/sec")); + polytropicEfficiency = polytropicPower / getThermoSystem().getFlowRate("kg/sec") + / (dH / getThermoSystem().getFlowRate("kg/sec")); + isentropicEfficiency = (enthalpyOutIsentropic - inletEnthalpy) / dH; + + // isentropicEfficiency = (getThermoSystem().getEnthalpy() - hinn) / dH; + double k = Math.log(getOutletPressure() / presinn) / Math.log(densOutIsentropic / densInn); + double term1 = Math.pow(getOutletPressure() / presinn, (n - 1.0) / n) - 1.0; + double term2 = n / (n - 1.0) * (k - 1.0) / k; + double term3 = Math.pow(getOutletPressure() / presinn, (k - 1.0) / k) - 1.0; + double polyPow = term1 * term2 / term3 * isentropicEfficiency; + polytropicEfficiency = polyPow; + polytropicPower = dH * polytropicEfficiency; + // System.out.println("polytropic eff " + polytropicEfficiency); + // System.out.println("isentropic eff " + isentropicEfficiency); + polytropicFluidHead = polytropicPower / getThermoSystem().getFlowRate("kg/sec") / 1000.0; + polytropicHeadMeter = polytropicFluidHead * 1000.0 / 9.81; + polytropicHead = polytropicFluidHead; + if (getCompressorChart().isUseCompressorChart()) { + if (getCompressorChart().getHeadUnit().equals("meter")) { + polytropicHead = polytropicHeadMeter; + } else { + polytropicHead = polytropicFluidHead; + } + } + outStream.setThermoSystem(getThermoSystem()); + outStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); + return; + } + } + if (compressorChart.isUseCompressorChart()) { + do { + double actualFlowRate = thermoSystem.getFlowRate("m3/hr"); + double z_inlet = thermoSystem.getZ(); + double MW = thermoSystem.getMolarMass(); + + if (getCompressorChart().useRealKappa()) { + kappa = thermoSystem.getGamma(); + } else { + kappa = thermoSystem.getGamma2(); + } + if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + double[] gergProps; + gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); + actualFlowRate *= gergProps[1] / z_inlet; + kappa = gergProps[14]; + z_inlet = gergProps[1]; } - } - /** - *- * solveAntiSurge. - *
- */ - public void solveAntiSurge() { + double polytropEff = + getCompressorChart().getPolytropicEfficiency(actualFlowRate, getSpeed()); + setPolytropicEfficiency(polytropEff / 100.0); + polytropicHead = getCompressorChart().getPolytropicHead(actualFlowRate, getSpeed()); + double temperature_inlet = thermoSystem.getTemperature(); + double n = 1.0 / (1.0 - (kappa - 1.0) / kappa * 1.0 / (polytropEff / 100.0)); + polytropicExponent = n; + if (getCompressorChart().getHeadUnit().equals("meter")) { + polytropicFluidHead = polytropicHead / 1000.0 * 9.81; + polytropicHeadMeter = polytropicHead; + } else { + polytropicFluidHead = polytropicHead; + polytropicHeadMeter = polytropicHead * 1000.0 / 9.81; + } + double pressureRatio = Math.pow((polytropicFluidHead * 1000.0 + + (n / (n - 1.0) * z_inlet * 8.314 * (temperature_inlet) / MW)) + / (n / (n - 1.0) * z_inlet * 8.314 * (temperature_inlet) / MW), n / (n - 1.0)); + setOutletPressure(thermoSystem.getPressure() * pressureRatio); if (getAntiSurge().isActive()) { - // .... + logger.info("surge flow " + + getCompressorChart().getSurgeCurve().getSurgeFlow(polytropicHead) + " m3/hr"); + surgeCheck = isSurge(polytropicHead, actualFlowRate); } - } - - /** - * {@inheritDoc} - */ - @Override - public void setOutletPressure(double pressure) { - this.pressure = pressure; - } - - /** - *- * setOutletPressure. - *
- * - * @param pressure a double - * @param unit a {@link java.lang.String} object - */ - public void setOutletPressure(double pressure, String unit) { - this.pressure = pressure; - this.pressureUnit = unit; - } - - /** - *- * getOutletPressure. - *
- * - * @return a double - */ - public double getOutletPressure() { - return pressure; - } - - /** - * {@inheritDoc} - */ - @Override - public double getEnergy() { - return getTotalWork(); - } - - /** - *- * getPower. - *
- * - * @return a double - */ - public double getPower() { - return getTotalWork(); - } - - /** - *- * getPower. - *
- * - * @param unit a {@link java.lang.String} object - * @return a double - */ - public double getPower(String unit) { - double conversionFactor = 1.0; - if (unit.equals("MW")) { - conversionFactor = 1.0 / 1.0e6; - } else if (unit.equals("kW")) { - conversionFactor = 1.0 / 1.0e3; + if (getCompressorChart().getStoneWallCurve().isActive()) { + // logger.info("stone wall? " + isStoneWall(polytropicHead, + // thermoSystem.getFlowRate("m3/hr"))); + } + if (surgeCheck && getAntiSurge().isActive()) { + thermoSystem.setTotalFlowRate( + getAntiSurge().getSurgeControlFactor() + * getCompressorChart().getSurgeCurve().getSurgeFlow(polytropicFluidHead), + "Am3/hr"); + thermoSystem.init(3); + fractionAntiSurge = thermoSystem.getTotalNumberOfMoles() / orginalMolarFLow - 1.0; + getAntiSurge().setCurrentSurgeFraction(fractionAntiSurge); } - return conversionFactor * getPower(); - } - /** - *- * setPower. - *
- * - * @param p a double - */ - public void setPower(double p) { powerSet = true; - dH = p; - } - - /** - * Calculates polytropic or isentropic efficiency - * - * @param outTemperature a double - * @return a double - */ - public double solveEfficiency(double outTemperature) { - double funk = 0.0, funkOld = 0.0; - double newPoly; - double dfunkdPoly = 100.0, dPoly = 100.0, oldPoly = outTemperature; - useOutTemperature = false; - run(); - useOutTemperature = true; - int iter = 0; - boolean useOld = usePolytropicCalc; - // usePolytropicCalc = true; - // System.out.println("use polytropic " + usePolytropicCalc); - do { - iter++; - funk = getThermoSystem().getTemperature() - outTemperature; - dfunkdPoly = (funk - funkOld) / dPoly; - newPoly = polytropicEfficiency - funk / dfunkdPoly; - if (iter <= 1) { - newPoly = polytropicEfficiency + 0.01; - } - oldPoly = polytropicEfficiency; - polytropicEfficiency = newPoly; - isentropicEfficiency = newPoly; - dPoly = polytropicEfficiency - oldPoly; - funkOld = funk; - useOutTemperature = false; - run(); - useOutTemperature = true; - // System.out.println("temperature compressor " + - // getThermoSystem().getTemperature() + " funk " + funk + " polytropic " + - // polytropicEfficiency); - } while ((Math.abs((getThermoSystem().getTemperature() - outTemperature)) > 1e-5 || iter < 3) - && (iter < 50)); - usePolytropicCalc = useOld; - return newPoly; - } - - /** - *- * findOutPressure. - *
- * - * @param hinn a double - * @param hout a double - * @param polytropicEfficiency a double - * @return a double - */ - public double findOutPressure(double hinn, double hout, double polytropicEfficiency) { - double entropy = getThermoSystem().getEntropy(); - getThermoSystem().setPressure(getThermoSystem().getPressure() + 1.0, pressureUnit); - - // System.out.println("entropy inn.." + entropy); - ThermodynamicOperations thermoOps = new ThermodynamicOperations(getThermoSystem()); - thermoOps.PSflash(entropy); - - double houtGuess = hinn + dH / polytropicEfficiency; - thermoOps.PHflash(houtGuess, 0); - System.out.println("TEMPERATURE .." + getThermoSystem().getTemperature()); - return getThermoSystem().getPressure(); + dH = polytropicFluidHead * 1000.0 * thermoSystem.getMolarMass() / getPolytropicEfficiency() + * thermoSystem.getTotalNumberOfMoles(); + } while (surgeCheck && getAntiSurge().isActive()); } - /** - * {@inheritDoc} - */ - @Override - public void run() { - thermoSystem = inStream.getThermoSystem().clone(); - - if (Math.abs(pressure - thermoSystem.getPressure(pressureUnit)) < 1e-6 && !compressorChart.isUseCompressorChart()) { - thermoSystem.initProperties(); - outStream.setThermoSystem(getThermoSystem()); - dH = 0.0; - polytropicFluidHead = 0.0; - polytropicHeadMeter = 0.0; - return; - } - - ThermodynamicOperations thermoOps = new ThermodynamicOperations(getThermoSystem()); + if (usePolytropicCalc) { + if (powerSet) { + double hout = hinn * (1 - 0 + fractionAntiSurge) + dH; + thermoSystem.setPressure(pressure, pressureUnit); thermoOps = new ThermodynamicOperations(getThermoSystem()); - getThermoSystem().init(3); - getThermoSystem().initPhysicalProperties("density"); - double presinn = getThermoSystem().getPressure(); - double hinn = getThermoSystem().getEnthalpy(); - double densInn = getThermoSystem().getDensity(); - double entropy = getThermoSystem().getEntropy(); - + thermoOps.PHflash(hout, 0); if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - double[] gergProps; - gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - hinn = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - entropy = gergProps[8] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - densInn = getThermoSystem().getPhase(0).getDensity_GERG2008(); - } - - inletEnthalpy = hinn; - boolean surgeCheck = false; - double orginalMolarFLow = thermoSystem.getTotalNumberOfMoles(); - double fractionAntiSurge = 0.0; - double kappa = 0.0; - if (useOutTemperature) { - if (useRigorousPolytropicMethod) { - solveEfficiency(outTemperature); - polytropicHead = getPower() / getThermoSystem().getFlowRate("kg/sec") / 1000.0 - * getPolytropicEfficiency(); - polytropicFluidHead = polytropicHead; - polytropicHeadMeter - = polytropicFluidHead * 1000.0 / ThermodynamicConstantsInterface.gravity; - return; - } else { - double MW = thermoSystem.getMolarMass(); - thermoSystem.setPressure(getOutletPressure(), pressureUnit); - thermoOps.PSflash(entropy); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PSflashGERG2008(entropy); - } - thermoSystem.initPhysicalProperties("density"); - double densOutIsentropic = thermoSystem.getDensity("kg/m3"); - double enthalpyOutIsentropic = thermoSystem.getEnthalpy(); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - double[] gergProps; - gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - densOutIsentropic = getThermoSystem().getPhase(0).getDensity_GERG2008(); - enthalpyOutIsentropic - = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - } - thermoSystem.setTemperature(outTemperature); - thermoOps.TPflash(); - thermoSystem.init(2); - thermoSystem.initPhysicalProperties("density"); - double outEnthalpy = thermoSystem.getEnthalpy(); - double densOut = thermoSystem.getDensity("kg/m3"); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - double[] gergProps; - gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - outEnthalpy = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - densOut = getThermoSystem().getPhase(0).getDensity_GERG2008(); - } - dH = outEnthalpy - inletEnthalpy; - // System.out.println("total power " + - // dH/getThermoSystem().getFlowRate("kg/sec")); - - double n = Math.log(getOutletPressure() / presinn) / Math.log(densOut / densInn); - double CF = (enthalpyOutIsentropic - inletEnthalpy) / thermoSystem.getFlowRate("kg/sec") - / (n / (n - 1.0) - * (getOutletPressure() * 1e5 / densOutIsentropic - presinn * 1e5 / densInn)); - - double F1 = thermoSystem.getTotalNumberOfMoles(); - double polytropicPower = F1 * MW * (n / (n - 1.0)) * CF * presinn * 1e5 / densInn - * (Math.pow((getOutletPressure() / presinn), (n - 1.0) / n) - 1.0); - // System.out.println("polytropic power " + - // polytropicPower/getThermoSystem().getFlowRate("kg/sec")); - polytropicEfficiency = polytropicPower / getThermoSystem().getFlowRate("kg/sec") - / (dH / getThermoSystem().getFlowRate("kg/sec")); - isentropicEfficiency = (enthalpyOutIsentropic - inletEnthalpy) / dH; - - // isentropicEfficiency = (getThermoSystem().getEnthalpy() - hinn) / dH; - double k = Math.log(getOutletPressure() / presinn) / Math.log(densOutIsentropic / densInn); - double term1 = Math.pow(getOutletPressure() / presinn, (n - 1.0) / n) - 1.0; - double term2 = n / (n - 1.0) * (k - 1.0) / k; - double term3 = Math.pow(getOutletPressure() / presinn, (k - 1.0) / k) - 1.0; - double polyPow = term1 * term2 / term3 * isentropicEfficiency; - polytropicEfficiency = polyPow; - polytropicPower = dH * polytropicEfficiency; - // System.out.println("polytropic eff " + polytropicEfficiency); - // System.out.println("isentropic eff " + isentropicEfficiency); - polytropicFluidHead = polytropicPower / getThermoSystem().getFlowRate("kg/sec") / 1000.0; - polytropicHeadMeter = polytropicFluidHead * 1000.0 / 9.81; - polytropicHead = polytropicFluidHead; - if (getCompressorChart().isUseCompressorChart()) { - if (getCompressorChart().getHeadUnit().equals("meter")) { - polytropicHead = polytropicHeadMeter; - } else { - polytropicHead = polytropicFluidHead; - } - } - outStream.setThermoSystem(getThermoSystem()); - - return; - } + thermoOps.PHflashGERG2008(hout); } - if (compressorChart.isUseCompressorChart()) { - do { - double actualFlowRate = thermoSystem.getFlowRate("m3/hr"); - double z_inlet = thermoSystem.getZ(); - double MW = thermoSystem.getMolarMass(); - - if (getCompressorChart().useRealKappa()) { - kappa = thermoSystem.getGamma(); - } else { - kappa = thermoSystem.getGamma2(); - } - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - double[] gergProps; - gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - actualFlowRate *= gergProps[1] / z_inlet; - kappa = gergProps[14]; - z_inlet = gergProps[1]; - } - - double polytropEff - = getCompressorChart().getPolytropicEfficiency(actualFlowRate, getSpeed()); - setPolytropicEfficiency(polytropEff / 100.0); - polytropicHead = getCompressorChart().getPolytropicHead(actualFlowRate, getSpeed()); - double temperature_inlet = thermoSystem.getTemperature(); - double n = 1.0 / (1.0 - (kappa - 1.0) / kappa * 1.0 / (polytropEff / 100.0)); - polytropicExponent = n; - if (getCompressorChart().getHeadUnit().equals("meter")) { - polytropicFluidHead = polytropicHead / 1000.0 * 9.81; - polytropicHeadMeter = polytropicHead; - } else { - polytropicFluidHead = polytropicHead; - polytropicHeadMeter = polytropicHead * 1000.0 / 9.81; - } - double pressureRatio = Math.pow((polytropicFluidHead * 1000.0 - + (n / (n - 1.0) * z_inlet * 8.314 * (temperature_inlet) / MW)) - / (n / (n - 1.0) * z_inlet * 8.314 * (temperature_inlet) / MW), n / (n - 1.0)); - setOutletPressure(thermoSystem.getPressure() * pressureRatio); - if (getAntiSurge().isActive()) { - logger.info("surge flow " - + getCompressorChart().getSurgeCurve().getSurgeFlow(polytropicHead) + " m3/hr"); - surgeCheck = isSurge(polytropicHead, actualFlowRate); - } - if (getCompressorChart().getStoneWallCurve().isActive()) { - // logger.info("stone wall? " + isStoneWall(polytropicHead, - // thermoSystem.getFlowRate("m3/hr"))); - } - if (surgeCheck && getAntiSurge().isActive()) { - thermoSystem.setTotalFlowRate( - getAntiSurge().getSurgeControlFactor() - * getCompressorChart().getSurgeCurve().getSurgeFlow(polytropicFluidHead), - "Am3/hr"); - thermoSystem.init(3); - fractionAntiSurge = thermoSystem.getTotalNumberOfMoles() / orginalMolarFLow - 1.0; - getAntiSurge().setCurrentSurgeFraction(fractionAntiSurge); - } - - powerSet = true; - dH = polytropicFluidHead * 1000.0 * thermoSystem.getMolarMass() / getPolytropicEfficiency() - * thermoSystem.getTotalNumberOfMoles(); - } while (surgeCheck && getAntiSurge().isActive()); - } - - if (usePolytropicCalc) { - if (powerSet) { - double hout = hinn * (1 - 0 + fractionAntiSurge) + dH; - thermoSystem.setPressure(pressure, pressureUnit); - thermoOps = new ThermodynamicOperations(getThermoSystem()); - thermoOps.PHflash(hout, 0); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PHflashGERG2008(hout); - } - } else { - if (polytropicMethod.equals("detailed")) { - // todo add detailed output of compressor calculations - int numbersteps = numberOfCompressorCalcSteps; - double dp = (pressure - getThermoSystem().getPressure()) / (1.0 * numbersteps); - for (int i = 0; i < numbersteps; i++) { - entropy = getThermoSystem().getEntropy(); - hinn = getThermoSystem().getEnthalpy(); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - double[] gergProps; - gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - hinn = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - entropy = gergProps[8] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - } - getThermoSystem().setPressure(getThermoSystem().getPressure() + dp, pressureUnit); - thermoOps = new ThermodynamicOperations(getThermoSystem()); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PSflashGERG2008(entropy); - } else { - double oleTemp = getThermoSystem().getTemperature(); - thermoOps.PSflash(entropy); - if (Math.abs(getThermoSystem().getEntropy() - entropy) > 1e-3) { - getThermoSystem().setTemperature(oleTemp); - thermoOps.TPflash(); - getThermoSystem().init(2); - continue; - } - } - double newEnt = getThermoSystem().getEnthalpy(); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - double[] gergProps; - gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - newEnt = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - } - double hout = hinn + (newEnt - hinn) / polytropicEfficiency; - thermoOps.PHflash(hout, 0); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PHflashGERG2008(hout); - } - if (propertyProfile.isActive()) { - propertyProfile.addFluid(thermoSystem.clone()); - } - } - } else if (polytropicMethod.equals("schultz")) { - double schultzX - = thermoSystem.getTemperature() / thermoSystem.getVolume() * thermoSystem.getdVdTpn() - - 1.0; - double schultzY - = -thermoSystem.getPressure() / thermoSystem.getVolume() * thermoSystem.getdVdPtn(); - thermoSystem.setPressure(getOutletPressure(), pressureUnit); - thermoOps.PSflash(entropy); - thermoSystem.initProperties(); - double densOutIsentropic = thermoSystem.getDensity("kg/m3"); - double enthalpyOutIsentropic = thermoSystem.getEnthalpy(); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PSflashGERG2008(entropy); - double[] gergProps; - gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - densOutIsentropic = getThermoSystem().getPhase(0).getDensity_GERG2008(); - enthalpyOutIsentropic - = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - } - double isenthalpicvolumeexponent - = Math.log(getOutletPressure() / presinn) / Math.log(densOutIsentropic / densInn); - double nV = (1.0 + schultzX) - / (1.0 / isenthalpicvolumeexponent * (1.0 / polytropicEfficiency + schultzX) - - schultzY * (1.0 / polytropicEfficiency - 1.0)); - double term = nV / (nV - 1.0); - double term2 = 1e5 * (getOutletPressure() / densOutIsentropic - presinn / densInn); - double term3 = isenthalpicvolumeexponent / (isenthalpicvolumeexponent - 1.0); - double CF = (enthalpyOutIsentropic - inletEnthalpy) / (term2 * term3); - dH = term * CF * 1e5 * presinn / densInn - * (Math.pow(getOutletPressure() / presinn, 1.0 / term) - 1.0) / polytropicEfficiency; - double hout = hinn + dH; - thermoOps = new ThermodynamicOperations(getThermoSystem()); - thermoOps.PHflash(hout, 0); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PHflashGERG2008(hout); - } - } else { - thermoSystem.setPressure(getOutletPressure(), pressureUnit); - thermoOps.PSflash(entropy); - thermoSystem.initProperties(); - double densOutIsentropic = thermoSystem.getDensity("kg/m3"); - double enthalpyOutIsentropic = thermoSystem.getEnthalpy(); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PSflashGERG2008(entropy); - double[] gergProps; - gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - densOutIsentropic = getThermoSystem().getPhase(0).getDensity_GERG2008(); - enthalpyOutIsentropic - = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - } - double isenthalpicvolumeexponent - = Math.log(getOutletPressure() / presinn) / Math.log(densOutIsentropic / densInn); - double term = isenthalpicvolumeexponent / (isenthalpicvolumeexponent - 1.0) - * (polytropicEfficiency); - double term2 = 1e5 * (getOutletPressure() / densOutIsentropic - presinn / densInn); - double CF = (enthalpyOutIsentropic - inletEnthalpy) / (term * term2); - dH = term * CF * 1e5 * presinn / densInn - * (Math.pow(getOutletPressure() / presinn, 1.0 / term) - 1.0); - double hout = hinn + dH; - thermoOps = new ThermodynamicOperations(getThermoSystem()); - thermoOps.PHflash(hout, 0); - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PHflashGERG2008(hout); - } - } + } else { + if (polytropicMethod.equals("detailed")) { + // todo add detailed output of compressor calculations + int numbersteps = numberOfCompressorCalcSteps; + double dp = (pressure - getThermoSystem().getPressure()) / (1.0 * numbersteps); + for (int i = 0; i < numbersteps; i++) { + entropy = getThermoSystem().getEntropy(); + hinn = getThermoSystem().getEnthalpy(); + if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + double[] gergProps; + gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); + hinn = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); + entropy = gergProps[8] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); } - } else { - getThermoSystem().setPressure(pressure, pressureUnit); - // System.out.println("entropy inn.." + entropy); + getThermoSystem().setPressure(getThermoSystem().getPressure() + dp, pressureUnit); thermoOps = new ThermodynamicOperations(getThermoSystem()); - thermoOps.PSflash(entropy); if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PSflashGERG2008(entropy); + thermoOps.PSflashGERG2008(entropy); + } else { + double oleTemp = getThermoSystem().getTemperature(); + thermoOps.PSflash(entropy); + if (Math.abs(getThermoSystem().getEntropy() - entropy) > 1e-3) { + getThermoSystem().setTemperature(oleTemp); + thermoOps.TPflash(); + getThermoSystem().init(2); + continue; + } } - // double densOutIdeal = getThermoSystem().getDensity(); double newEnt = getThermoSystem().getEnthalpy(); - if (!powerSet) { - dH = (getThermoSystem().getEnthalpy() - hinn) / isentropicEfficiency; - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - double[] gergProps; - gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - newEnt = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - dH = (newEnt - hinn) / isentropicEfficiency; - } + if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + double[] gergProps; + gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); + newEnt = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); } - double hout = hinn + dH; - isentropicEfficiency = (newEnt - hinn) / dH; - dH = hout - hinn; - thermoOps = new ThermodynamicOperations(getThermoSystem()); + double hout = hinn + (newEnt - hinn) / polytropicEfficiency; thermoOps.PHflash(hout, 0); if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { - thermoOps.PHflashGERG2008(hout); + thermoOps.PHflashGERG2008(hout); } - } - // thermoSystem.display(); - - if (getCompressorChart().isUseCompressorChart() && getAntiSurge().isActive()) { - thermoSystem.setTotalNumberOfMoles(orginalMolarFLow); - thermoSystem.init(3); - } - thermoSystem.initProperties(); - outStream.setThermoSystem(getThermoSystem()); - - polytropicFluidHead - = getPower() / getThermoSystem().getFlowRate("kg/sec") / 1000.0 * getPolytropicEfficiency(); - polytropicHeadMeter = polytropicFluidHead * 1000.0 / 9.81; - } - - /** - *- * generateCompressorCurves. - *
- */ - public void generateCompressorCurves() { - double flowRef = getThermoSystem().getFlowRate("m3/hr"); - double factor = flowRef / 4000.0; - double[] chartConditions = new double[]{0.3, 1.0, 1.0, 1.0}; - double[] speed = new double[]{12913, 12298, 11683, 11098, 10453, 9224, 8609, 8200}; - double[][] flow = new double[][]{ - {2789.1285, 3174.0375, 3689.2288, 4179.4503, 4570.2768, 4954.7728, 5246.0329, 5661.0331}, - {2571.1753, 2943.7254, 3440.2675, 3837.4448, 4253.0898, 4668.6643, 4997.1926, 5387.4952}, - {2415.3793, 2763.0706, 3141.7095, 3594.7436, 4047.6467, 4494.1889, 4853.7353, 5138.7858}, - {2247.2043, 2799.7342, 3178.3428, 3656.1551, 4102.778, 4394.1591, 4648.3224, 4840.4998}, - {2072.8397, 2463.9483, 2836.4078, 3202.5266, 3599.6333, 3978.0203, 4257.0022, 4517.345}, - {1835.9552, 2208.455, 2618.1322, 2940.8034, 3244.7852, 3530.1279, 3753.3738, 3895.9746}, - {1711.3386, 1965.8848, 2356.9431, 2685.9247, 3008.5154, 3337.2855, 3591.5092}, - {1636.5807, 2002.8708, 2338.0319, 2642.1245, 2896.4894, 3113.6264, 3274.8764, 3411.2977}}; - - for (int i = 0; i < flow.length; i++) { - for (int j = 0; j < flow[i].length; j++) { - flow[i][j] *= factor; + if (propertyProfile.isActive()) { + propertyProfile.addFluid(thermoSystem.clone()); } - } - - double[][] head - = new double[][]{{80.0375, 78.8934, 76.2142, 71.8678, 67.0062, 60.6061, 53.0499, 39.728}, - {72.2122, 71.8369, 68.9009, 65.8341, 60.7167, 54.702, 47.2749, 35.7471}, - {65.1576, 64.5253, 62.6118, 59.1619, 54.0455, 47.0059, 39.195, 31.6387}, - {58.6154, 56.9627, 54.6647, 50.4462, 44.4322, 38.4144, 32.9084, 28.8109}, - {52.3295, 51.0573, 49.5283, 46.3326, 42.3685, 37.2502, 31.4884, 25.598}, - {40.6578, 39.6416, 37.6008, 34.6603, 30.9503, 27.1116, 23.2713, 20.4546}, - {35.2705, 34.6359, 32.7228, 31.0645, 27.0985, 22.7482, 18.0113}, - {32.192, 31.1756, 29.1329, 26.833, 23.8909, 21.3324, 18.7726, 16.3403},}; - - for (int i = 0; i < head.length; i++) { - for (int j = 0; j < head[i].length; j++) { - head[i][j] *= factor / 5.0; - } - } - double[][] polyEff = new double[][]{ - {77.2452238409573, 79.4154186459363, 80.737960012489, 80.5229826589649, 79.2210931638144, - 75.4719133864634, 69.6034181197298, 58.7322388482707}, - {77.0107837113504, 79.3069974136389, 80.8941189021135, 80.7190194665918, 79.5313242980328, - 75.5912622896367, 69.6846136362097, 60.0043057990909}, - {77.0043065299874, 79.1690958847856, 80.8038169975675, 80.6543975614197, 78.8532389102705, - 73.6664774270613, 66.2735600426727, 57.671664571658}, - {77.0716623789093, 80.4629750233093, 81.1390811169072, 79.6374242667478, 75.380928428817, - 69.5332969549779, 63.7997587622339, 58.8120614497758}, - {76.9705872525642, 79.8335492585324, 80.9468133671171, 80.5806471927835, 78.0462158225426, - 73.0403707523258, 66.5572286338589, 59.8624822515064}, - {77.5063036680357, 80.2056198362559, 81.0339108025933, 79.6085962687939, 76.3814534404405, - 70.8027503005902, 64.6437367160571, 60.5299349982342}, - {77.8175271586685, 80.065165942218, 81.0631362122632, 79.8955051771299, 76.1983240929369, - 69.289982774309, 60.8567149372229}, - {78.0924334304045, 80.9353551568667, 80.7904437766234, 78.8639325223295, 75.2170936751143, - 70.3105081673411, 65.5507568533569, 61.0391468300337}}; - - getCompressorChart().setCurves(chartConditions, speed, flow, head, polyEff); - getCompressorChart().setHeadUnit("kJ/kg"); - } - - /** - * {@inheritDoc} - */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(5); - nf.applyPattern("#.#####E0"); - - JDialog dialog = new JDialog(new JFrame(), "Results from TPflash"); - Container dialogContentPane = dialog.getContentPane(); - dialogContentPane.setLayout(new FlowLayout()); - - getThermoSystem().initPhysicalProperties(); - String[][] table = new String[50][5]; - String[] names = {"", "Phase 1", "Phase 2", "Phase 3", "Unit"}; - table[0][0] = ""; - table[0][1] = ""; - table[0][2] = ""; - table[0][3] = ""; - StringBuffer buf = new StringBuffer(); - FieldPosition test = new FieldPosition(0); - - for (int i = 0; i < getThermoSystem().getNumberOfPhases(); i++) { - for (int j = 0; j < getThermoSystem().getPhases()[0].getNumberOfComponents(); j++) { - table[j + 1][0] = getThermoSystem().getPhases()[0].getComponents()[j].getName(); - buf = new StringBuffer(); - table[j + 1][i + 1] - = nf.format(getThermoSystem().getPhases()[i].getComponents()[j].getx(), buf, test) - .toString(); - table[j + 1][4] = "[-]"; - } - buf = new StringBuffer(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 2][0] = "Density"; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 2][i + 1] = nf - .format(getThermoSystem().getPhases()[i].getPhysicalProperties().getDensity(), buf, test) - .toString(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 2][4] = "[kg/m^3]"; - - // Double.longValue(thermoSystem.getPhases()[i].getBeta()); - buf = new StringBuffer(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 3][0] = "PhaseFraction"; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 3][i + 1] - = nf.format(getThermoSystem().getPhases()[i].getBeta(), buf, test).toString(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 3][4] = "[-]"; - - buf = new StringBuffer(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 4][0] = "MolarMass"; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 4][i + 1] - = nf.format(getThermoSystem().getPhases()[i].getMolarMass() * 1000, buf, test).toString(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 4][4] = "[kg/kmol]"; - - buf = new StringBuffer(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 5][0] = "Cp"; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 5][i + 1] - = nf.format((getThermoSystem().getPhases()[i].getCp() - / getThermoSystem().getPhases()[i].getNumberOfMolesInPhase() * 1.0 - / getThermoSystem().getPhases()[i].getMolarMass() * 1000), buf, test).toString(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 5][4] = "[kJ/kg*K]"; - - buf = new StringBuffer(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 7][0] = "Viscosity"; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 7][i + 1] - = nf.format((getThermoSystem().getPhases()[i].getPhysicalProperties().getViscosity()), buf, - test).toString(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 7][4] = "[kg/m*sec]"; - - buf = new StringBuffer(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 8][0] = "Conductivity"; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 8][i + 1] - = nf.format(getThermoSystem().getPhases()[i].getPhysicalProperties().getConductivity(), buf, - test).toString(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 8][4] = "[W/m*K]"; - - buf = new StringBuffer(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 10][0] = "Pressure"; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 10][i + 1] - = Double.toString(getThermoSystem().getPhases()[i].getPressure()); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 10][4] = "[bar]"; - - buf = new StringBuffer(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 11][0] = "Temperature"; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 11][i + 1] - = Double.toString(getThermoSystem().getPhases()[i].getTemperature()); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 11][4] = "[K]"; - Double.toString(getThermoSystem().getPhases()[i].getTemperature()); - - buf = new StringBuffer(); - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 13][0] = "Stream"; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 13][i + 1] = name; - table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 13][4] = "-"; - } - - JTable Jtab = new JTable(table, names); - JScrollPane scrollpane = new JScrollPane(Jtab); - dialogContentPane.add(scrollpane); - dialog.pack(); - dialog.setVisible(true); - } - - /** - * {@inheritDoc} - */ - @Override - public String[][] getResultTable() { - return thermoSystem.getResultTable(); - } - - /** - *- * getTotalWork. - *
- * - * @return a double - */ - public double getTotalWork() { - double multi = 1.0; - if (getAntiSurge().isActive()) { - multi = 1.0 + getAntiSurge().getCurrentSurgeFraction(); - } - if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + } + } else if (polytropicMethod.equals("schultz")) { + double schultzX = + thermoSystem.getTemperature() / thermoSystem.getVolume() * thermoSystem.getdVdTpn() + - 1.0; + double schultzY = + -thermoSystem.getPressure() / thermoSystem.getVolume() * thermoSystem.getdVdPtn(); + thermoSystem.setPressure(getOutletPressure(), pressureUnit); + thermoOps.PSflash(entropy); + thermoSystem.initProperties(); + double densOutIsentropic = thermoSystem.getDensity("kg/m3"); + double enthalpyOutIsentropic = thermoSystem.getEnthalpy(); + if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + thermoOps.PSflashGERG2008(entropy); double[] gergProps; gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); - double enth = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); - return (enth - inletEnthalpy) * multi; - } else { - return multi * (getThermoSystem().getEnthalpy() - inletEnthalpy); - } - } - - /** - * {@inheritDoc} - */ - @Override - public double getIsentropicEfficiency() { - return isentropicEfficiency; - } - - /** - * {@inheritDoc} - */ - @Override - public void setIsentropicEfficiency(double isentropicEfficiency) { - this.isentropicEfficiency = isentropicEfficiency; - } - - /** - *- * usePolytropicCalc. - *
- * - * @return the usePolytropicCalc - */ - public boolean usePolytropicCalc() { - return usePolytropicCalc; - } - - /** - *
- * Setter for the field usePolytropicCalc
.
- *
- * Getter for the field compressorChart
.
- *
- * Setter for the field compressorChart
.
- *
- * isSurge. - *
- * - * @param flow a double - * @param head a double - * @return a boolean - */ - public boolean isSurge(double flow, double head) { - getAntiSurge().setSurge(getCompressorChart().getSurgeCurve().isSurge(flow, head)); - return getAntiSurge().isSurge(); - } - - /** - *- * isStoneWall. - *
- * - * @param flow a double - * @param head a double - * @return a boolean - */ - public boolean isStoneWall(double flow, double head) { - return getCompressorChart().getStoneWallCurve().isStoneWall(flow, head); - } - - /** - *
- * Setter for the field antiSurge
.
- *
- * Getter for the field speed
.
- *
- * Setter for the field speed
.
- *
- * Getter for the field polytropicHead
.
- *
- * Getter for the field polytropicHead
.
- *
- * Getter for the field polytropicFluidHead
.
- *
- * Getter for the field polytropicExponent
.
- *
- * Getter for the field polytropicHeadMeter
.
- *
- * Setter for the field polytropicHeadMeter
.
- *
- * Getter for the field outTemperature
.
- *
- * Setter for the field outTemperature
.
- *
- * useOutTemperature. - *
- * - * @param useOutTemperature a boolean - */ - public void useOutTemperature(boolean useOutTemperature) { - this.useOutTemperature = useOutTemperature; - } - - /** - *
- * Getter for the field numberOfCompressorCalcSteps
.
- *
- * Setter for the field numberOfCompressorCalcSteps
.
- *
- * isUseRigorousPolytropicMethod. - *
- * - * @return a boolean - */ - public boolean isUseRigorousPolytropicMethod() { - return useRigorousPolytropicMethod; - } - - /** - *
- * Setter for the field useRigorousPolytropicMethod
.
- *
- * Setter for the field pressure
.
- *
- * Getter for the field polytropicMethod
.
- *
- * Setter for the field polytropicMethod
.
- *
+ * generateCompressorCurves. + *
+ */ + public void generateCompressorCurves() { + double flowRef = getThermoSystem().getFlowRate("m3/hr"); + double factor = flowRef / 4000.0; + double[] chartConditions = new double[] {0.3, 1.0, 1.0, 1.0}; + double[] speed = new double[] {12913, 12298, 11683, 11098, 10453, 9224, 8609, 8200}; + double[][] flow = new double[][] { + {2789.1285, 3174.0375, 3689.2288, 4179.4503, 4570.2768, 4954.7728, 5246.0329, 5661.0331}, + {2571.1753, 2943.7254, 3440.2675, 3837.4448, 4253.0898, 4668.6643, 4997.1926, 5387.4952}, + {2415.3793, 2763.0706, 3141.7095, 3594.7436, 4047.6467, 4494.1889, 4853.7353, 5138.7858}, + {2247.2043, 2799.7342, 3178.3428, 3656.1551, 4102.778, 4394.1591, 4648.3224, 4840.4998}, + {2072.8397, 2463.9483, 2836.4078, 3202.5266, 3599.6333, 3978.0203, 4257.0022, 4517.345}, + {1835.9552, 2208.455, 2618.1322, 2940.8034, 3244.7852, 3530.1279, 3753.3738, 3895.9746}, + {1711.3386, 1965.8848, 2356.9431, 2685.9247, 3008.5154, 3337.2855, 3591.5092}, + {1636.5807, 2002.8708, 2338.0319, 2642.1245, 2896.4894, 3113.6264, 3274.8764, 3411.2977}}; + + for (int i = 0; i < flow.length; i++) { + for (int j = 0; j < flow[i].length; j++) { + flow[i][j] *= factor; + } + } + + double[][] head = + new double[][] {{80.0375, 78.8934, 76.2142, 71.8678, 67.0062, 60.6061, 53.0499, 39.728}, + {72.2122, 71.8369, 68.9009, 65.8341, 60.7167, 54.702, 47.2749, 35.7471}, + {65.1576, 64.5253, 62.6118, 59.1619, 54.0455, 47.0059, 39.195, 31.6387}, + {58.6154, 56.9627, 54.6647, 50.4462, 44.4322, 38.4144, 32.9084, 28.8109}, + {52.3295, 51.0573, 49.5283, 46.3326, 42.3685, 37.2502, 31.4884, 25.598}, + {40.6578, 39.6416, 37.6008, 34.6603, 30.9503, 27.1116, 23.2713, 20.4546}, + {35.2705, 34.6359, 32.7228, 31.0645, 27.0985, 22.7482, 18.0113}, + {32.192, 31.1756, 29.1329, 26.833, 23.8909, 21.3324, 18.7726, 16.3403},}; + + for (int i = 0; i < head.length; i++) { + for (int j = 0; j < head[i].length; j++) { + head[i][j] *= factor / 5.0; + } + } + double[][] polyEff = new double[][] { + {77.2452238409573, 79.4154186459363, 80.737960012489, 80.5229826589649, 79.2210931638144, + 75.4719133864634, 69.6034181197298, 58.7322388482707}, + {77.0107837113504, 79.3069974136389, 80.8941189021135, 80.7190194665918, 79.5313242980328, + 75.5912622896367, 69.6846136362097, 60.0043057990909}, + {77.0043065299874, 79.1690958847856, 80.8038169975675, 80.6543975614197, 78.8532389102705, + 73.6664774270613, 66.2735600426727, 57.671664571658}, + {77.0716623789093, 80.4629750233093, 81.1390811169072, 79.6374242667478, 75.380928428817, + 69.5332969549779, 63.7997587622339, 58.8120614497758}, + {76.9705872525642, 79.8335492585324, 80.9468133671171, 80.5806471927835, 78.0462158225426, + 73.0403707523258, 66.5572286338589, 59.8624822515064}, + {77.5063036680357, 80.2056198362559, 81.0339108025933, 79.6085962687939, 76.3814534404405, + 70.8027503005902, 64.6437367160571, 60.5299349982342}, + {77.8175271586685, 80.065165942218, 81.0631362122632, 79.8955051771299, 76.1983240929369, + 69.289982774309, 60.8567149372229}, + {78.0924334304045, 80.9353551568667, 80.7904437766234, 78.8639325223295, 75.2170936751143, + 70.3105081673411, 65.5507568533569, 61.0391468300337}}; + + getCompressorChart().setCurves(chartConditions, speed, flow, head, polyEff); + getCompressorChart().setHeadUnit("kJ/kg"); + } + + /** + * {@inheritDoc} + */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(5); + nf.applyPattern("#.#####E0"); + + JDialog dialog = new JDialog(new JFrame(), "Results from TPflash"); + Container dialogContentPane = dialog.getContentPane(); + dialogContentPane.setLayout(new FlowLayout()); + + getThermoSystem().initPhysicalProperties(); + String[][] table = new String[50][5]; + String[] names = {"", "Phase 1", "Phase 2", "Phase 3", "Unit"}; + table[0][0] = ""; + table[0][1] = ""; + table[0][2] = ""; + table[0][3] = ""; + StringBuffer buf = new StringBuffer(); + FieldPosition test = new FieldPosition(0); + + for (int i = 0; i < getThermoSystem().getNumberOfPhases(); i++) { + for (int j = 0; j < getThermoSystem().getPhases()[0].getNumberOfComponents(); j++) { + table[j + 1][0] = getThermoSystem().getPhases()[0].getComponents()[j].getName(); + buf = new StringBuffer(); + table[j + 1][i + 1] = + nf.format(getThermoSystem().getPhases()[i].getComponents()[j].getx(), buf, test) + .toString(); + table[j + 1][4] = "[-]"; + } + buf = new StringBuffer(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 2][0] = "Density"; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 2][i + 1] = nf + .format(getThermoSystem().getPhases()[i].getPhysicalProperties().getDensity(), buf, test) + .toString(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 2][4] = "[kg/m^3]"; + + // Double.longValue(thermoSystem.getPhases()[i].getBeta()); + buf = new StringBuffer(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 3][0] = "PhaseFraction"; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 3][i + 1] = + nf.format(getThermoSystem().getPhases()[i].getBeta(), buf, test).toString(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 3][4] = "[-]"; + + buf = new StringBuffer(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 4][0] = "MolarMass"; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 4][i + 1] = + nf.format(getThermoSystem().getPhases()[i].getMolarMass() * 1000, buf, test).toString(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 4][4] = "[kg/kmol]"; + + buf = new StringBuffer(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 5][0] = "Cp"; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 5][i + 1] = + nf.format((getThermoSystem().getPhases()[i].getCp() + / getThermoSystem().getPhases()[i].getNumberOfMolesInPhase() * 1.0 + / getThermoSystem().getPhases()[i].getMolarMass() * 1000), buf, test).toString(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 5][4] = "[kJ/kg*K]"; + + buf = new StringBuffer(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 7][0] = "Viscosity"; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 7][i + 1] = + nf.format((getThermoSystem().getPhases()[i].getPhysicalProperties().getViscosity()), buf, + test).toString(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 7][4] = "[kg/m*sec]"; + + buf = new StringBuffer(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 8][0] = "Conductivity"; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 8][i + 1] = + nf.format(getThermoSystem().getPhases()[i].getPhysicalProperties().getConductivity(), buf, + test).toString(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 8][4] = "[W/m*K]"; + + buf = new StringBuffer(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 10][0] = "Pressure"; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 10][i + 1] = + Double.toString(getThermoSystem().getPhases()[i].getPressure()); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 10][4] = "[bar]"; + + buf = new StringBuffer(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 11][0] = "Temperature"; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 11][i + 1] = + Double.toString(getThermoSystem().getPhases()[i].getTemperature()); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 11][4] = "[K]"; + Double.toString(getThermoSystem().getPhases()[i].getTemperature()); + + buf = new StringBuffer(); + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 13][0] = "Stream"; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 13][i + 1] = name; + table[getThermoSystem().getPhases()[0].getNumberOfComponents() + 13][4] = "-"; + } + + JTable Jtab = new JTable(table, names); + JScrollPane scrollpane = new JScrollPane(Jtab); + dialogContentPane.add(scrollpane); + dialog.pack(); + dialog.setVisible(true); + } + + /** + * {@inheritDoc} + */ + @Override + public String[][] getResultTable() { + return thermoSystem.getResultTable(); + } + + /** + *+ * getTotalWork. + *
+ * + * @return a double + */ + public double getTotalWork() { + double multi = 1.0; + if (getAntiSurge().isActive()) { + multi = 1.0 + getAntiSurge().getCurrentSurgeFraction(); + } + if (useGERG2008 && thermoSystem.getNumberOfPhases() == 1) { + double[] gergProps; + gergProps = getThermoSystem().getPhase(0).getProperties_GERG2008(); + double enth = gergProps[7] * getThermoSystem().getPhase(0).getNumberOfMolesInPhase(); + return (enth - inletEnthalpy) * multi; + } else { + return multi * (getThermoSystem().getEnthalpy() - inletEnthalpy); + } + } + + /** + * {@inheritDoc} + */ + @Override + public double getIsentropicEfficiency() { + return isentropicEfficiency; + } + + /** + * {@inheritDoc} + */ + @Override + public void setIsentropicEfficiency(double isentropicEfficiency) { + this.isentropicEfficiency = isentropicEfficiency; + } + + /** + *+ * usePolytropicCalc. + *
+ * + * @return the usePolytropicCalc + */ + public boolean usePolytropicCalc() { + return usePolytropicCalc; + } + + /** + *
+ * Setter for the field usePolytropicCalc
.
+ *
+ * Getter for the field compressorChart
.
+ *
+ * Setter for the field compressorChart
.
+ *
+ * isSurge. + *
+ * + * @param flow a double + * @param head a double + * @return a boolean + */ + public boolean isSurge(double flow, double head) { + getAntiSurge().setSurge(getCompressorChart().getSurgeCurve().isSurge(flow, head)); + return getAntiSurge().isSurge(); + } + + /** + *+ * isStoneWall. + *
+ * + * @param flow a double + * @param head a double + * @return a boolean + */ + public boolean isStoneWall(double flow, double head) { + return getCompressorChart().getStoneWallCurve().isStoneWall(flow, head); + } + + /** + *
+ * Setter for the field antiSurge
.
+ *
+ * Getter for the field speed
.
+ *
+ * Setter for the field speed
.
+ *
+ * Getter for the field polytropicHead
.
+ *
+ * Getter for the field polytropicHead
.
+ *
+ * Getter for the field polytropicFluidHead
.
+ *
+ * Getter for the field polytropicExponent
.
+ *
+ * Getter for the field polytropicHeadMeter
.
+ *
+ * Setter for the field polytropicHeadMeter
.
+ *
+ * Getter for the field outTemperature
.
+ *
+ * Setter for the field outTemperature
.
+ *
+ * useOutTemperature. + *
+ * + * @param useOutTemperature a boolean + */ + public void useOutTemperature(boolean useOutTemperature) { + this.useOutTemperature = useOutTemperature; + } + + /** + *
+ * Getter for the field numberOfCompressorCalcSteps
.
+ *
+ * Setter for the field numberOfCompressorCalcSteps
.
+ *
+ * isUseRigorousPolytropicMethod. + *
+ * + * @return a boolean + */ + public boolean isUseRigorousPolytropicMethod() { + return useRigorousPolytropicMethod; + } + + /** + *
+ * Setter for the field useRigorousPolytropicMethod
.
+ *
+ * Setter for the field pressure
.
+ *
+ * Getter for the field polytropicMethod
.
+ *
+ * Setter for the field polytropicMethod
.
+ *
- * Getter for the field refluxRatio
.
- *
+ * Getter for the field refluxRatio
.
+ *
- * Setter for the field refluxRatio
.
- *
+ * Setter for the field refluxRatio
.
+ *
- * Getter for the field duty
.
- *
+ * Getter for the field duty
.
+ *
- * Constructor for DistillationColumn. - *
- * - * @param numberOfTraysLocal a int - * @param hasReboiler a boolean - * @param hasCondenser a boolean - */ - public DistillationColumn(int numberOfTraysLocal, boolean hasReboiler, boolean hasCondenser) { - super("DistillationColumn"); - this.hasReboiler = hasReboiler; - this.hasCondenser = hasCondenser; - distoperations = new neqsim.processSimulation.processSystem.ProcessSystem(); - this.numberOfTrays = numberOfTraysLocal; - if (hasReboiler) { - trays.add(new Reboiler("Reboiler")); - this.numberOfTrays++; - } - for (int i = 0; i < numberOfTraysLocal; i++) { - trays.add(new SimpleTray("SimpleTray" + i + 1)); - } - if (hasCondenser) { - trays.add(new Condenser("Condenser")); - this.numberOfTrays++; - } - for (int i = 0; i < this.numberOfTrays; i++) { - distoperations.add(trays.get(i)); - } + private static final long serialVersionUID = 1000; + private boolean doInitializion = true; + boolean hasReboiler = false; + boolean hasCondenser = false; + protected ArrayList+ * Constructor for DistillationColumn. + *
+ * + * @param numberOfTraysLocal a int + * @param hasReboiler a boolean + * @param hasCondenser a boolean + */ + public DistillationColumn(int numberOfTraysLocal, boolean hasReboiler, boolean hasCondenser) { + super("DistillationColumn"); + this.hasReboiler = hasReboiler; + this.hasCondenser = hasCondenser; + distoperations = new neqsim.processSimulation.processSystem.ProcessSystem(); + this.numberOfTrays = numberOfTraysLocal; + if (hasReboiler) { + trays.add(new Reboiler("Reboiler")); + this.numberOfTrays++; } - - /** - *- * addFeedStream. - *
- * - * @param inputStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - * @param feedTrayNumber a int - */ - public void addFeedStream(StreamInterface inputStream, int feedTrayNumber) { - feedStream = inputStream; - getTray(feedTrayNumber).addStream(inputStream); - setFeedTrayNumber(feedTrayNumber); - double moles = inputStream.getThermoSystem().getTotalNumberOfMoles(); - gasOutStream.setThermoSystem(inputStream.getThermoSystem().clone()); - gasOutStream.getThermoSystem().setTotalNumberOfMoles(moles / 2.0); - liquidOutStream.setThermoSystem(inputStream.getThermoSystem().clone()); - liquidOutStream.getThermoSystem().setTotalNumberOfMoles(moles / 2.0); + for (int i = 0; i < numberOfTraysLocal; i++) { + trays.add(new SimpleTray("SimpleTray" + i + 1)); } - - /** - *- * init. - *
- */ - public void init() { - if (!isDoInitializion()) { - return; - } - setDoInitializion(false); - ((Runnable) trays.get(feedTrayNumber)).run(); - - if (getTray(feedTrayNumber).getStream(0).getFluid().getNumberOfPhases() == 1) { - for (int i = 0; i < numberOfTrays; i++) { - if (getTray(i).getNumberOfInputStreams() > 0 && i != feedTrayNumber) { - getTray(feedTrayNumber).addStream(trays.get(i).getStream(0)); - getTray(feedTrayNumber).run(); - getTray(feedTrayNumber).removeInputStream(getTray(feedTrayNumber).getNumberOfInputStreams()-1); - if (getTray(feedTrayNumber).getThermoSystem().getNumberOfPhases() > 1) - break; - } - else if(i == feedTrayNumber && getTray(i).getNumberOfInputStreams() > 1) { - getTray(feedTrayNumber).addStream(trays.get(i).getStream(1)); - ((Runnable) trays.get(feedTrayNumber)).run(); - getTray(feedTrayNumber).removeInputStream(getTray(feedTrayNumber).getNumberOfInputStreams()-1); - if (getTray(feedTrayNumber).getThermoSystem().getNumberOfPhases() > 1) - break; - } - } - } - ((MixerInterface) trays.get(numberOfTrays - 1)) - .addStream(trays.get(feedTrayNumber).getGasOutStream()); - ((Mixer) trays.get(numberOfTrays - 1)).getStream(0).getThermoSystem() - .setTotalNumberOfMoles(((Mixer) trays.get(numberOfTrays - 1)).getStream(0) - .getThermoSystem().getTotalNumberOfMoles() * (1.0e-6)); - ((MixerInterface) trays.get(0)).addStream(trays.get(feedTrayNumber).getLiquidOutStream()); - int streamNumbReboil = (trays.get(0)).getNumberOfInputStreams() - 1; - ((Mixer) trays.get(0)).getStream(streamNumbReboil).getThermoSystem() - .setTotalNumberOfMoles(((Mixer) trays.get(0)).getStream(streamNumbReboil) - .getThermoSystem().getTotalNumberOfMoles() * (1.0e-6)); - - // ((Runnable) trays.get(numberOfTrays - 1)).run(); - ((Runnable) trays.get(0)).run(); - - condenserTemperature = - ((MixerInterface) trays.get(numberOfTrays - 1)).getThermoSystem().getTemperature(); - reboilerTemperature = ((MixerInterface) trays.get(0)).getThermoSystem().getTemperature(); - - // double deltaTemp = (reboilerTemperature - condenserTemperature) / (numberOfTrays * 1.0); - double feedTrayTemperature = - getTray(getFeedTrayNumber()).getThermoSystem().getTemperature(); - - double deltaTempCondenser = (feedTrayTemperature - condenserTemperature) - / (numberOfTrays * 1.0 - feedTrayNumber - 1); - double deltaTempReboiler = - (reboilerTemperature - feedTrayTemperature) / (feedTrayNumber * 1.0); - - double delta = 0; - for (int i = feedTrayNumber + 1; i < numberOfTrays; i++) { - delta += deltaTempCondenser; - ((Mixer) trays.get(i)).setTemperature( - getTray(getFeedTrayNumber()).getThermoSystem().getTemperature() - delta); - } - delta = 0; - for (int i = feedTrayNumber - 1; i >= 0; i--) { - delta += deltaTempReboiler; - ((Mixer) trays.get(i)).setTemperature( - getTray(getFeedTrayNumber()).getThermoSystem().getTemperature() + delta); - } - - for (int i = 1; i < numberOfTrays - 1; i++) { - ((MixerInterface) trays.get(i)).addStream(trays.get(i - 1).getGasOutStream()); - trays.get(i).init(); - ((Runnable) trays.get(i)).run(); - } - - ((MixerInterface) trays.get(numberOfTrays - 1)).replaceStream(0, - trays.get(numberOfTrays - 2).getGasOutStream()); - trays.get(numberOfTrays - 1).init(); - ((Runnable) trays.get(numberOfTrays - 1)).run(); - - for (int i = numberOfTrays - 2; i >= 1; i--) { - ((MixerInterface) trays.get(i)).addStream(trays.get(i + 1).getLiquidOutStream()); - trays.get(i).init(); - ((Runnable) trays.get(i)).run(); - } - int streamNumb = (trays.get(0)).getNumberOfInputStreams() - 1; - ((MixerInterface) trays.get(0)).replaceStream(streamNumb, - trays.get(1).getLiquidOutStream()); - trays.get(0).init(); - ((Runnable) trays.get(0)).run(); + if (hasCondenser) { + trays.add(new Condenser("Condenser")); + this.numberOfTrays++; } - - /** - *
- * Getter for the field gasOutStream
.
- *
- * Getter for the field liquidOutStream
.
- *
+ * addFeedStream. + *
+ * + * @param inputStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + * @param feedTrayNumber a int + */ + public void addFeedStream(StreamInterface inputStream, int feedTrayNumber) { + feedStream = inputStream; + getTray(feedTrayNumber).addStream(inputStream); + setFeedTrayNumber(feedTrayNumber); + double moles = inputStream.getThermoSystem().getTotalNumberOfMoles(); + gasOutStream.setThermoSystem(inputStream.getThermoSystem().clone()); + gasOutStream.getThermoSystem().setTotalNumberOfMoles(moles / 2.0); + liquidOutStream.setThermoSystem(inputStream.getThermoSystem().clone()); + liquidOutStream.getThermoSystem().setTotalNumberOfMoles(moles / 2.0); + } + + /** + *+ * init. + *
+ */ + public void init() { + if (!isDoInitializion()) { + return; } - - /** - *- * getTray. - *
- * - * @param trayNumber a int - * @return a {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} object - */ - public SimpleTray getTray(int trayNumber) { - return trays.get(trayNumber); - } - - /** {@inheritDoc} */ - @Override - public void setNumberOfTrays(int number) { - int oldNumberOfTrays = numberOfTrays; - - int tempNumberOfTrays = number; - - if (hasReboiler) { - tempNumberOfTrays++; - } - if (hasCondenser) { - tempNumberOfTrays++; + setDoInitializion(false); + ((Runnable) trays.get(feedTrayNumber)).run(); + + if (getTray(feedTrayNumber).getStream(0).getFluid().getNumberOfPhases() == 1) { + for (int i = 0; i < numberOfTrays; i++) { + if (getTray(i).getNumberOfInputStreams() > 0 && i != feedTrayNumber) { + getTray(feedTrayNumber).addStream(trays.get(i).getStream(0)); + getTray(feedTrayNumber).run(); + getTray(feedTrayNumber) + .removeInputStream(getTray(feedTrayNumber).getNumberOfInputStreams() - 1); + if (getTray(feedTrayNumber).getThermoSystem().getNumberOfPhases() > 1) { + break; + } + } else if (i == feedTrayNumber && getTray(i).getNumberOfInputStreams() > 1) { + getTray(feedTrayNumber).addStream(trays.get(i).getStream(1)); + ((Runnable) trays.get(feedTrayNumber)).run(); + getTray(feedTrayNumber) + .removeInputStream(getTray(feedTrayNumber).getNumberOfInputStreams() - 1); + if (getTray(feedTrayNumber).getThermoSystem().getNumberOfPhases() > 1) { + break; + } } - - int change = tempNumberOfTrays - oldNumberOfTrays; - - if (change > 0) { - for (int i = 0; i < change; i++) { - trays.add(1, new SimpleTray("SimpleTray" + oldNumberOfTrays + i + 1)); - } - } else if (change < 0) { - for (int i = 0; i > change; i--) { - trays.remove(1); - } - } - numberOfTrays = tempNumberOfTrays; - - setDoInitializion(true); - init(); + } } - - /** - *- * setTopCondenserDuty. - *
- * - * @param duty a double - */ - public void setTopCondenserDuty(double duty) { - condenserCoolingDuty = duty; + ((MixerInterface) trays.get(numberOfTrays - 1)) + .addStream(trays.get(feedTrayNumber).getGasOutStream()); + ((Mixer) trays.get(numberOfTrays - 1)).getStream(0).getThermoSystem() + .setTotalNumberOfMoles(((Mixer) trays.get(numberOfTrays - 1)).getStream(0).getThermoSystem() + .getTotalNumberOfMoles() * (1.0e-6)); + ((MixerInterface) trays.get(0)).addStream(trays.get(feedTrayNumber).getLiquidOutStream()); + int streamNumbReboil = (trays.get(0)).getNumberOfInputStreams() - 1; + ((Mixer) trays.get(0)).getStream(streamNumbReboil).getThermoSystem().setTotalNumberOfMoles( + ((Mixer) trays.get(0)).getStream(streamNumbReboil).getThermoSystem().getTotalNumberOfMoles() + * (1.0e-6)); + + // ((Runnable) trays.get(numberOfTrays - 1)).run(); + ((Runnable) trays.get(0)).run(); + + condenserTemperature = + ((MixerInterface) trays.get(numberOfTrays - 1)).getThermoSystem().getTemperature(); + reboilerTemperature = ((MixerInterface) trays.get(0)).getThermoSystem().getTemperature(); + + // double deltaTemp = (reboilerTemperature - condenserTemperature) / (numberOfTrays * 1.0); + double feedTrayTemperature = getTray(getFeedTrayNumber()).getThermoSystem().getTemperature(); + + double deltaTempCondenser = + (feedTrayTemperature - condenserTemperature) / (numberOfTrays * 1.0 - feedTrayNumber - 1); + double deltaTempReboiler = (reboilerTemperature - feedTrayTemperature) / (feedTrayNumber * 1.0); + + double delta = 0; + for (int i = feedTrayNumber + 1; i < numberOfTrays; i++) { + delta += deltaTempCondenser; + ((Mixer) trays.get(i)) + .setTemperature(getTray(getFeedTrayNumber()).getThermoSystem().getTemperature() - delta); } - - /** - *- * setTopPressure. - *
- * - * @param topPressure a double - */ - public void setTopPressure(double topPressure) { - topTrayPressure = topPressure; + delta = 0; + for (int i = feedTrayNumber - 1; i >= 0; i--) { + delta += deltaTempReboiler; + ((Mixer) trays.get(i)) + .setTemperature(getTray(getFeedTrayNumber()).getThermoSystem().getTemperature() + delta); } - /** - *- * setBottomPressure. - *
- * - * @param bottomPressure a double - */ - public void setBottomPressure(double bottomPressure) { - bottomTrayPressure = bottomPressure; + for (int i = 1; i < numberOfTrays - 1; i++) { + ((MixerInterface) trays.get(i)).addStream(trays.get(i - 1).getGasOutStream()); + trays.get(i).init(); + ((Runnable) trays.get(i)).run(); } - /** {@inheritDoc} */ - @Override - public void run() { - double dp = 0.0; - if (bottomTrayPressure < 0) { - bottomTrayPressure = getTray(feedTrayNumber).getStream(0).getPressure(); - } - if (topTrayPressure < 0) { - topTrayPressure = getTray(feedTrayNumber).getStream(0).getPressure(); - } - if (numberOfTrays > 1) { - dp = (bottomTrayPressure - topTrayPressure) / (numberOfTrays - 1.0); - } - for (int i = 0; i < numberOfTrays; i++) { - trays.get(i).setPressure(bottomTrayPressure - i * dp); - } - getTray(feedTrayNumber).getStream(0).setThermoSystem(feedStream.getThermoSystem().clone()); - - if (numberOfTrays == 1) { - ((Runnable) trays.get(0)).run(); - gasOutStream.setThermoSystem(trays.get(0).getGasOutStream().getThermoSystem().clone()); - liquidOutStream - .setThermoSystem(trays.get(0).getLiquidOutStream().getThermoSystem().clone()); - return; - } + ((MixerInterface) trays.get(numberOfTrays - 1)).replaceStream(0, + trays.get(numberOfTrays - 2).getGasOutStream()); + trays.get(numberOfTrays - 1).init(); + ((Runnable) trays.get(numberOfTrays - 1)).run(); - if (isDoInitializion()) { - this.init(); - } - double err = 1.0e10, errOld; - int iter = 0; - double[] oldtemps = new double[numberOfTrays]; - ((Runnable) trays.get(feedTrayNumber)).run(); - - do { - iter++; - errOld = err; - err = 0.0; - for (int i = 0; i < numberOfTrays; i++) { - oldtemps[i] = ((MixerInterface) trays.get(i)).getThermoSystem().getTemperature(); - } - - for (int i = feedTrayNumber; i > 1; i--) { - ((Mixer) trays.get(i - 1)).replaceStream(1, trays.get(i).getLiquidOutStream()); - trays.get(i - 1).setPressure(bottomTrayPressure - (i - 1) * dp); - ((Runnable) trays.get(i - 1)).run(); - } - int streamNumb = (trays.get(0)).getNumberOfInputStreams() - 1; - ((Mixer) trays.get(0)).replaceStream(streamNumb, trays.get(1).getLiquidOutStream()); - ((Runnable) trays.get(0)).run(); - - for (int i = 1; i <= numberOfTrays - 1; i++) { - int replaceStream = 0; - if (i == feedTrayNumber) - replaceStream = 1; - ((Mixer) trays.get(i)).replaceStream(replaceStream, - trays.get(i - 1).getGasOutStream()); - ((Runnable) trays.get(i)).run(); - } - - for (int i = numberOfTrays - 2; i == feedTrayNumber; i--) { - int replaceStream = 1; - if (i == feedTrayNumber) - replaceStream = 2; - if (i == feedTrayNumber && i == 0) - replaceStream = 1; - ((Mixer) trays.get(i)).replaceStream(replaceStream, - trays.get(i + 1).getLiquidOutStream()); - ((Runnable) trays.get(i)).run(); - } - for (int i = 0; i < numberOfTrays; i++) { - err += Math.abs(oldtemps[i] - - ((MixerInterface) trays.get(i)).getThermoSystem().getTemperature()); - } - System.out.println("error iter " + err + " iteration " + iter); - // massBalanceCheck(); - } while (err > 1e-4 && err < errOld && iter < 10);// && !massBalanceCheck()); - - // massBalanceCheck(); - gasOutStream.setThermoSystem( - trays.get(numberOfTrays - 1).getGasOutStream().getThermoSystem().clone()); - liquidOutStream - .setThermoSystem(trays.get(0).getLiquidOutStream().getThermoSystem().clone()); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - distoperations.displayResult(); - } - - /** - *- * massBalanceCheck. - *
- * - * @return a boolean - */ - public boolean massBalanceCheck() { - double[] massInput = new double[numberOfTrays]; - double[] massOutput = new double[numberOfTrays]; - double[] massBalance = new double[numberOfTrays]; - System.out.println("water in feed " - + feedStream.getFluid().getPhase(0).getComponent("water").getNumberOfmoles()); - System.out.println("water in strip gas feed " + trays.get(0).getStream(0).getFluid() - .getPhase(0).getComponent("water").getNumberOfmoles()); - - for (int i = 0; i < numberOfTrays; i++) { - int numberOfInputStreams = trays.get(i).getNumberOfInputStreams(); - for (int j = 0; j < numberOfInputStreams; j++) { - massInput[i] += trays.get(i).getStream(j).getFluid().getFlowRate("kg/hr"); - } - massOutput[i] += trays.get(i).getGasOutStream().getFlowRate("kg/hr"); - massOutput[i] += trays.get(i).getLiquidOutStream().getFlowRate("kg/hr"); - massBalance[i] = massInput[i] - massOutput[i]; - System.out.println("tray " + i + " number of input streams " + numberOfInputStreams - + " massinput " + massInput[i] + " massoutput " + massOutput[i] - + " massbalance " + massBalance[i] + " gasout " - + trays.get(i).getGasOutStream().getFlowRate("kg/hr") + " liquidout " - + trays.get(i).getLiquidOutStream().getFlowRate("kg/hr") + " pressure " - + trays.get(i).getGasOutStream().getPressure() + " temperature " - + trays.get(i).getGasOutStream().getTemperature("C")); - - System.out - .println("tray " + i + " number of input streams " + numberOfInputStreams - + " water in gasout " - + trays.get(i).getGasOutStream().getFluid().getPhase(0) - .getComponent("water").getNumberOfmoles() - + " water in liquidout " - + trays.get(i).getLiquidOutStream().getFluid().getPhase(0) - .getComponent("water").getNumberOfmoles() - + " pressure " + trays.get(i).getGasOutStream().getPressure() - + " temperature " + trays.get(i).getGasOutStream().getTemperature("C")); - } - - double massError = 0.0; - for (int i = 0; i < numberOfTrays; i++) { - massError += Math.abs(massBalance[i]); - } - if (massError > 1e-6) - return false; - else - return true; + for (int i = numberOfTrays - 2; i >= 1; i--) { + ((MixerInterface) trays.get(i)).addStream(trays.get(i + 1).getLiquidOutStream()); + trays.get(i).init(); + ((Runnable) trays.get(i)).run(); } - - /** - *- * energyBalanceCheck. - *
- */ - public void energyBalanceCheck() { - double[] energyInput = new double[numberOfTrays]; - double[] energyOutput = new double[numberOfTrays]; - double[] energyBalance = new double[numberOfTrays]; - for (int i = 0; i < numberOfTrays; i++) { - int numberOfInputStreams = trays.get(i).getNumberOfInputStreams(); - for (int j = 0; j < numberOfInputStreams; j++) { - energyInput[i] += trays.get(i).getStream(j).getFluid().getEnthalpy(); - } - energyOutput[i] += trays.get(i).getGasOutStream().getFluid().getEnthalpy(); - energyOutput[i] += trays.get(i).getLiquidOutStream().getFluid().getEnthalpy(); - energyBalance[i] = energyInput[i] - energyOutput[i]; - System.out.println("tray " + i + " number of input streams " + numberOfInputStreams - + " energyinput " + energyInput[i] + " energyoutput " + energyOutput[i] - + " energybalance " + energyBalance[i] + " gasout " - + trays.get(i).getGasOutStream().getFlowRate("kg/hr") + " liquidout " - + trays.get(i).getLiquidOutStream().getFlowRate("kg/hr") + " pressure " - + trays.get(i).getGasOutStream().getPressure() + " temperature " - + trays.get(i).getGasOutStream().getTemperature("C")); - } + int streamNumb = (trays.get(0)).getNumberOfInputStreams() - 1; + ((MixerInterface) trays.get(0)).replaceStream(streamNumb, trays.get(1).getLiquidOutStream()); + trays.get(0).init(); + ((Runnable) trays.get(0)).run(); + } + + /** + *
+ * Getter for the field gasOutStream
.
+ *
+ * Getter for the field liquidOutStream
.
+ *
+ * getTray. + *
+ * + * @param trayNumber a int + * @return a {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} object + */ + public SimpleTray getTray(int trayNumber) { + return trays.get(trayNumber); + } + + /** {@inheritDoc} */ + @Override + public void setNumberOfTrays(int number) { + int oldNumberOfTrays = numberOfTrays; + + int tempNumberOfTrays = number; + + if (hasReboiler) { + tempNumberOfTrays++; } - - /** - *- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos((273.15 - 0.0), 15.000); - // testSystem.addComponent("methane", 10.00); - testSystem.addComponent("ethane", 10.0); - testSystem.addComponent("CO2", 10.0); - testSystem.addComponent("propane", 20.0); - // testSystem.addComponent("i-butane", 5.0); - // testSystem.addComponent("n-hexane", 15.0); - // testSystem.addComponent("n-heptane", 30.0); - // testSystem.addComponent("n-octane", 4.0); - // testSystem.addComponent("n-nonane", 3.0); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - ThermodynamicOperations ops = new ThermodynamicOperations(testSystem); - ops.TPflash(); - testSystem.display(); - Stream stream_1 = new Stream("Stream1", testSystem); - - DistillationColumn column = new DistillationColumn(5, true, true); - column.addFeedStream(stream_1, 3); - // column.getReboiler().setHeatInput(520000.0); - ((Reboiler) column.getReboiler()).setRefluxRatio(0.5); - // column.getCondenser().setHeatInput(-70000.0); - // ((Condenser) column.getCondenser()).setRefluxRatio(0.2); - - neqsim.processSimulation.processSystem.ProcessSystem operations = - new neqsim.processSimulation.processSystem.ProcessSystem(); - operations.add(stream_1); - operations.add(column); - operations.run(); - - column.displayResult(); - System.out.println("reboiler duty" + ((Reboiler) column.getReboiler()).getDuty()); - System.out.println("condenser duty" + ((Condenser) column.getCondenser()).getDuty()); + if (hasCondenser) { + tempNumberOfTrays++; } - /** - *- * getReboiler. - *
- * - * @return a {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} object - */ - public SimpleTray getReboiler() { - return trays.get(0); - } + int change = tempNumberOfTrays - oldNumberOfTrays; - /** - *- * getCondenser. - *
- * - * @return a {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} object - */ - public SimpleTray getCondenser() { - return trays.get(trays.size() - 1); + if (change > 0) { + for (int i = 0; i < change; i++) { + trays.add(1, new SimpleTray("SimpleTray" + oldNumberOfTrays + i + 1)); + } + } else if (change < 0) { + for (int i = 0; i > change; i--) { + trays.remove(1); + } } - - /** - *
- * Getter for the field reboilerTemperature
.
- *
+ * setTopCondenserDuty. + *
+ * + * @param duty a double + */ + public void setTopCondenserDuty(double duty) { + condenserCoolingDuty = duty; + } + + /** + *+ * setTopPressure. + *
+ * + * @param topPressure a double + */ + public void setTopPressure(double topPressure) { + topTrayPressure = topPressure; + } + + /** + *+ * setBottomPressure. + *
+ * + * @param bottomPressure a double + */ + public void setBottomPressure(double bottomPressure) { + bottomTrayPressure = bottomPressure; + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + if (bottomTrayPressure < 0) { + bottomTrayPressure = getTray(feedTrayNumber).getStream(0).getPressure(); } - - /** - *
- * Setter for the field reboilerTemperature
.
- *
- * getCondenserTemperature. - *
- * - * @return the condenserTemperature - */ - public double getCondenserTemperature() { - return condenserTemperature; + double dp = 0.0; + if (numberOfTrays > 1) { + dp = (bottomTrayPressure - topTrayPressure) / (numberOfTrays - 1.0); } - - /** - *- * setCondenserTemperature. - *
- * - * @param condenserTemperature the condenserTemperature to set - */ - public void setCondenserTemperature(double condenserTemperature) { - this.condenserTemperature = condenserTemperature; + for (int i = 0; i < numberOfTrays; i++) { + trays.get(i).setPressure(bottomTrayPressure - i * dp); } + getTray(feedTrayNumber).getStream(0).setThermoSystem(feedStream.getThermoSystem().clone()); + + if (numberOfTrays == 1) { + ((SimpleTray) trays.get(0)).run(id); + gasOutStream.setThermoSystem(trays.get(0).getGasOutStream().getThermoSystem().clone()); + liquidOutStream.setThermoSystem(trays.get(0).getLiquidOutStream().getThermoSystem().clone()); + } else { + if (isDoInitializion()) { + this.init(); + } + double err = 1.0e10; + double errOld; + int iter = 0; + double[] oldtemps = new double[numberOfTrays]; + ((SimpleTray) trays.get(feedTrayNumber)).run(); + + do { + iter++; + errOld = err; + err = 0.0; + for (int i = 0; i < numberOfTrays; i++) { + oldtemps[i] = ((MixerInterface) trays.get(i)).getThermoSystem().getTemperature(); + } - /** - *
- * Getter for the field feedTrayNumber
.
- *
- * Setter for the field feedTrayNumber
.
- *
- * isDoInitializion. - *
- * - * @return a boolean - */ - public boolean isDoInitializion() { - return doInitializion; + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + distoperations.displayResult(); + } + + /** + *+ * massBalanceCheck. + *
+ * + * @return a boolean + */ + public boolean massBalanceCheck() { + double[] massInput = new double[numberOfTrays]; + double[] massOutput = new double[numberOfTrays]; + double[] massBalance = new double[numberOfTrays]; + System.out.println("water in feed " + + feedStream.getFluid().getPhase(0).getComponent("water").getNumberOfmoles()); + System.out.println("water in strip gas feed " + trays.get(0).getStream(0).getFluid().getPhase(0) + .getComponent("water").getNumberOfmoles()); + + for (int i = 0; i < numberOfTrays; i++) { + int numberOfInputStreams = trays.get(i).getNumberOfInputStreams(); + for (int j = 0; j < numberOfInputStreams; j++) { + massInput[i] += trays.get(i).getStream(j).getFluid().getFlowRate("kg/hr"); + } + massOutput[i] += trays.get(i).getGasOutStream().getFlowRate("kg/hr"); + massOutput[i] += trays.get(i).getLiquidOutStream().getFlowRate("kg/hr"); + massBalance[i] = massInput[i] - massOutput[i]; + System.out.println("tray " + i + " number of input streams " + numberOfInputStreams + + " massinput " + massInput[i] + " massoutput " + massOutput[i] + " massbalance " + + massBalance[i] + " gasout " + trays.get(i).getGasOutStream().getFlowRate("kg/hr") + + " liquidout " + trays.get(i).getLiquidOutStream().getFlowRate("kg/hr") + " pressure " + + trays.get(i).getGasOutStream().getPressure() + " temperature " + + trays.get(i).getGasOutStream().getTemperature("C")); + + System.out.println( + "tray " + i + " number of input streams " + numberOfInputStreams + " water in gasout " + + trays.get(i).getGasOutStream().getFluid().getPhase(0).getComponent("water") + .getNumberOfmoles() + + " water in liquidout " + + trays.get(i).getLiquidOutStream().getFluid().getPhase(0).getComponent("water") + .getNumberOfmoles() + + " pressure " + trays.get(i).getGasOutStream().getPressure() + " temperature " + + trays.get(i).getGasOutStream().getTemperature("C")); } - /** - *
- * Setter for the field doInitializion
.
- *
- * getFsFactor. - *
- * - * @return a double - */ - public double getFsFactor() { - double intArea = 3.14 * getInternalDiameter() * getInternalDiameter() / 4.0; - return getGasOutStream().getThermoSystem().getFlowRate("m3/sec") / intArea - * Math.sqrt(getGasOutStream().getThermoSystem().getDensity("kg/m3")); + if (massError > 1e-6) { + return false; + } else { + return true; } - - /** - *
- * Getter for the field internalDiameter
.
- *
+ * energyBalanceCheck. + *
+ */ + public void energyBalanceCheck() { + double[] energyInput = new double[numberOfTrays]; + double[] energyOutput = new double[numberOfTrays]; + double[] energyBalance = new double[numberOfTrays]; + for (int i = 0; i < numberOfTrays; i++) { + int numberOfInputStreams = trays.get(i).getNumberOfInputStreams(); + for (int j = 0; j < numberOfInputStreams; j++) { + energyInput[i] += trays.get(i).getStream(j).getFluid().getEnthalpy(); + } + energyOutput[i] += trays.get(i).getGasOutStream().getFluid().getEnthalpy(); + energyOutput[i] += trays.get(i).getLiquidOutStream().getFluid().getEnthalpy(); + energyBalance[i] = energyInput[i] - energyOutput[i]; + System.out.println( + "tray " + i + " number of input streams " + numberOfInputStreams + " energyinput " + + energyInput[i] + " energyoutput " + energyOutput[i] + " energybalance " + + energyBalance[i] + " gasout " + trays.get(i).getGasOutStream().getFlowRate("kg/hr") + + " liquidout " + trays.get(i).getLiquidOutStream().getFlowRate("kg/hr") + + " pressure " + trays.get(i).getGasOutStream().getPressure() + " temperature " + + trays.get(i).getGasOutStream().getTemperature("C")); } - - /** - *
- * Setter for the field internalDiameter
.
- *
+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 - 0.0), 15.000); + // testSystem.addComponent("methane", 10.00); + testSystem.addComponent("ethane", 10.0); + testSystem.addComponent("CO2", 10.0); + testSystem.addComponent("propane", 20.0); + // testSystem.addComponent("i-butane", 5.0); + // testSystem.addComponent("n-hexane", 15.0); + // testSystem.addComponent("n-heptane", 30.0); + // testSystem.addComponent("n-octane", 4.0); + // testSystem.addComponent("n-nonane", 3.0); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + ThermodynamicOperations ops = new ThermodynamicOperations(testSystem); + ops.TPflash(); + testSystem.display(); + Stream stream_1 = new Stream("Stream1", testSystem); + + DistillationColumn column = new DistillationColumn(5, true, true); + column.addFeedStream(stream_1, 3); + // column.getReboiler().setHeatInput(520000.0); + ((Reboiler) column.getReboiler()).setRefluxRatio(0.5); + // column.getCondenser().setHeatInput(-70000.0); + // ((Condenser) column.getCondenser()).setRefluxRatio(0.2); + + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + operations.add(stream_1); + operations.add(column); + operations.run(); + + column.displayResult(); + System.out.println("reboiler duty" + ((Reboiler) column.getReboiler()).getDuty()); + System.out.println("condenser duty" + ((Condenser) column.getCondenser()).getDuty()); + } + + /** + *+ * getReboiler. + *
+ * + * @return a {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} object + */ + public SimpleTray getReboiler() { + return trays.get(0); + } + + /** + *+ * getCondenser. + *
+ * + * @return a {@link neqsim.processSimulation.processEquipment.distillation.SimpleTray} object + */ + public SimpleTray getCondenser() { + return trays.get(trays.size() - 1); + } + + /** + *
+ * Getter for the field reboilerTemperature
.
+ *
+ * Setter for the field reboilerTemperature
.
+ *
+ * getCondenserTemperature. + *
+ * + * @return the condenserTemperature + */ + public double getCondenserTemperature() { + return condenserTemperature; + } + + /** + *+ * setCondenserTemperature. + *
+ * + * @param condenserTemperature the condenserTemperature to set + */ + public void setCondenserTemperature(double condenserTemperature) { + this.condenserTemperature = condenserTemperature; + } + + /** + *
+ * Getter for the field feedTrayNumber
.
+ *
+ * Setter for the field feedTrayNumber
.
+ *
+ * isDoInitializion. + *
+ * + * @return a boolean + */ + public boolean isDoInitializion() { + return doInitializion; + } + + /** + *
+ * Setter for the field doInitializion
.
+ *
+ * getFsFactor. + *
+ * + * @return a double + */ + public double getFsFactor() { + double intArea = 3.14 * getInternalDiameter() * getInternalDiameter() / 4.0; + return getGasOutStream().getThermoSystem().getFlowRate("m3/sec") / intArea + * Math.sqrt(getGasOutStream().getThermoSystem().getDensity("kg/m3")); + } + + /** + *
+ * Getter for the field internalDiameter
.
+ *
+ * Setter for the field internalDiameter
.
+ *
- * Constructor for Reboiler. - *
- * - * @param name name of unit operation - */ - public Reboiler(String name) { - super(name); - } + /** + *+ * Constructor for Reboiler. + *
+ * + * @param name name of unit operation + */ + public Reboiler(String name) { + super(name); + } - /** - *
- * Getter for the field refluxRatio
.
- *
+ * Getter for the field refluxRatio
.
+ *
- * Setter for the field refluxRatio
.
- *
+ * Setter for the field refluxRatio
.
+ *
- * Getter for the field duty
.
- *
+ * Getter for the field duty
.
+ *
- * Constructor for SimpleTray. - *
- * - * @param name name of tray - */ - public SimpleTray(String name) { - super(name); + implements TrayInterface { + private static final long serialVersionUID = 1000; + + double heatInput = 0.0; + private double temperature = Double.NaN; + + private double trayPressure = -1.0; + + /** + *+ * Constructor for SimpleTray. + *
+ * + * @param name name of tray + */ + public SimpleTray(String name) { + super(name); + } + + /** + *+ * init. + *
+ */ + public void init() { + int pp = 0; + if (streams.size() == 3) { + pp = 1; } - - /** - *- * init. - *
- */ - public void init() { - int pp = 0; - if (streams.size() == 3) { - pp = 1; - } - for (int k = pp; k < streams.size(); k++) { - (streams.get(k).getThermoSystem()).setTemperature(temperature); - } + for (int k = pp; k < streams.size(); k++) { + (streams.get(k).getThermoSystem()).setTemperature(temperature); } - - /** {@inheritDoc} */ - @Override - public void setHeatInput(double heatinp) { - this.heatInput = heatinp; + } + + /** {@inheritDoc} */ + @Override + public void setHeatInput(double heatinp) { + this.heatInput = heatinp; + } + + /** + *+ * calcMixStreamEnthalpy0. + *
+ * + * @return a double + */ + public double calcMixStreamEnthalpy0() { + double enthalpy = 0; + + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); + // System.out.println("total enthalpy k : " + ( ((Stream) + // streams.get(k)).getThermoSystem()).getEnthalpy()); } - - /** - *- * calcMixStreamEnthalpy0. - *
- * - * @return a double - */ - public double calcMixStreamEnthalpy0() { - double enthalpy = 0; - - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); - // System.out.println("total enthalpy k : " + ( ((Stream) - // streams.get(k)).getThermoSystem()).getEnthalpy()); - } - // System.out.println("total enthalpy of streams: " + enthalpy); - return enthalpy; + // System.out.println("total enthalpy of streams: " + enthalpy); + return enthalpy; + } + + /** {@inheritDoc} */ + @Override + public double calcMixStreamEnthalpy() { + double enthalpy = heatInput; + if (isSetEnergyStream()) { + enthalpy -= energyStream.getDuty(); } - /** {@inheritDoc} */ - @Override - public double calcMixStreamEnthalpy() { - double enthalpy = heatInput; - if (isSetEnergyStream()) { - enthalpy -= energyStream.getDuty(); - } - - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); - // System.out.println("total enthalpy k : " + ( ((Stream) - // streams.get(k)).getThermoSystem()).getEnthalpy()); - } - // System.out.println("total enthalpy of streams: " + enthalpy); - return enthalpy; + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); + // System.out.println("total enthalpy k : " + ( ((Stream) + // streams.get(k)).getThermoSystem()).getEnthalpy()); } - - /** - *- * run2. - *
- */ - public void run2() { - super.run(); - temperature = mixedStream.getTemperature(); + // System.out.println("total enthalpy of streams: " + enthalpy); + return enthalpy; + } + + /** + *+ * run2. + *
+ */ + public void run2() { + super.run(); + temperature = mixedStream.getTemperature(); + } + + /** + *+ * TPflash. + *
+ */ + public void TPflash() {} + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + double enthalpy = 0.0; + // double flowRate = ((Stream) + // streams.get(0)).getThermoSystem().getFlowRate("kg/hr"); + // ((Stream) streams.get(0)).getThermoSystem().display(); + SystemInterface thermoSystem2 = streams.get(0).getThermoSystem().clone(); + + // System.out.println("total number of moles " + + // thermoSystem2.getTotalNumberOfMoles()); + if (trayPressure > 0) { + thermoSystem2.setPressure(trayPressure); } - - /** - *- * TPflash. - *
- */ - public void TPflash() {} - - /** {@inheritDoc} */ - @Override - public void run() { - double enthalpy = 0.0; - // double flowRate = ((Stream) - // streams.get(0)).getThermoSystem().getFlowRate("kg/hr"); - // ((Stream) streams.get(0)).getThermoSystem().display(); - SystemInterface thermoSystem2 = streams.get(0).getThermoSystem().clone(); - - // System.out.println("total number of moles " + - // thermoSystem2.getTotalNumberOfMoles()); - if (trayPressure > 0) { - thermoSystem2.setPressure(trayPressure); - } - mixedStream.setThermoSystem(thermoSystem2); - // thermoSystem2.display(); - ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem2); - if (streams.size() > 0) { - mixedStream.getThermoSystem().setNumberOfPhases(2); - mixedStream.getThermoSystem().reInitPhaseType(); - mixedStream.getThermoSystem().init(0); - - mixStream(); - if (trayPressure > 0) - mixedStream.setPressure(trayPressure, "bara"); - enthalpy = calcMixStreamEnthalpy(); - // System.out.println("temp guess " + guessTemperature()); - if (!isSetOutTemperature()) { - // mixedStream.getThermoSystem().setTemperature(guessTemperature()); - } else { - mixedStream.setTemperature(getOutTemperature(), "K"); - } - // System.out.println("filan temp " + mixedStream.getTemperature()); - } - if (isSetOutTemperature()) { - if (!Double.isNaN(getOutTemperature())) - mixedStream.getThermoSystem().setTemperature(getOutTemperature()); - testOps.TPflash(); - mixedStream.getThermoSystem().init(2); - } else { - try { - testOps.PHflash(enthalpy, 0); - } catch (Exception e) { - if (!Double.isNaN(getOutTemperature())) - mixedStream.getThermoSystem().setTemperature(getOutTemperature()); - testOps.TPflash(); - } - } - setTemperature(mixedStream.getTemperature()); - } - - /** - *- * getGasOutStream. - *
- * - * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - public StreamInterface getGasOutStream() { - return new Stream("", mixedStream.getThermoSystem().phaseToSystem(0)); - } - - /** - *- * getLiquidOutStream. - *
- * - * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - public StreamInterface getLiquidOutStream() { - return new Stream("", mixedStream.getThermoSystem().phaseToSystem(1)); - } - - /** - *
- * Getter for the field temperature
.
- *
+ * getGasOutStream. + *
+ * + * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + public StreamInterface getGasOutStream() { + return new Stream("", mixedStream.getThermoSystem().phaseToSystem(0)); + } + + /** + *+ * getLiquidOutStream. + *
+ * + * @return a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + public StreamInterface getLiquidOutStream() { + return new Stream("", mixedStream.getThermoSystem().phaseToSystem(1)); + } + + /** + *
+ * Getter for the field temperature
.
+ *
- * Constructor for VLSolidTray. - *
- * - * @param name name of tray - */ - public VLSolidTray(String name) { - super(name); + private static final long serialVersionUID = 1000; + + double heatInput = 0.0; + private double temperature = 273.15; + + /** + *+ * Constructor for VLSolidTray. + *
+ * + * @param name name of tray + */ + public VLSolidTray(String name) { + super(name); + } + + /** {@inheritDoc} */ + @Override + public void init() { + int pp = 0; + if (streams.size() == 3) { + pp = 1; } - - /** {@inheritDoc} */ - @Override - public void init() { - int pp = 0; - if (streams.size() == 3) { - pp = 1; - } - for (int k = pp; k < streams.size(); k++) { - (streams.get(k).getThermoSystem()).setTemperature(temperature); - } - } - - /** {@inheritDoc} */ - @Override - public void setHeatInput(double heatinp) { - this.heatInput = heatinp; + for (int k = pp; k < streams.size(); k++) { + (streams.get(k).getThermoSystem()).setTemperature(temperature); } - - /** {@inheritDoc} */ - @Override - public double calcMixStreamEnthalpy() { - double enthalpy = heatInput; - - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); - System.out.println( - "total enthalpy k : " + streams.get(k).getThermoSystem().getEnthalpy()); - } - System.out.println("total enthalpy of streams: " + enthalpy); - return enthalpy; + } + + /** {@inheritDoc} */ + @Override + public void setHeatInput(double heatinp) { + this.heatInput = heatinp; + } + + /** {@inheritDoc} */ + @Override + public double calcMixStreamEnthalpy() { + double enthalpy = heatInput; + + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); + System.out.println("total enthalpy k : " + streams.get(k).getThermoSystem().getEnthalpy()); } - - /** {@inheritDoc} */ - @Override - public void run() { - double enthalpy = 0.0; - - // ((Stream) streams.get(0)).getThermoSystem().display(); - - SystemInterface thermoSystem2 = streams.get(0).getThermoSystem().clone(); - // System.out.println("total number of moles " + - // thermoSystem2.getTotalNumberOfMoles()); - mixedStream.setThermoSystem(thermoSystem2); - // thermoSystem2.display(); - ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem2); - if (streams.size() > 0) { - // mixedStream.getThermoSystem().setSolidPhaseCheck("CO2"); - mixedStream.getThermoSystem().setNumberOfPhases(2); - mixedStream.getThermoSystem().reInitPhaseType(); - mixedStream.getThermoSystem().init(0); - - mixStream(); - - enthalpy = calcMixStreamEnthalpy(); - // mixedStream.getThermoSystem().display(); - // System.out.println("temp guess " + guessTemperature()); - mixedStream.getThermoSystem().setSolidPhaseCheck("CO2"); - mixedStream.getThermoSystem().setTemperature(guessTemperature()); - testOps.PHsolidFlash(enthalpy); - mixedStream.getThermoSystem().display(); - // System.out.println("filan temp " + mixedStream.getTemperature()); - } else { - testOps.TPflash(); - } - mixedStream.getThermoSystem().setSolidPhaseCheck(false); - // System.out.println("enthalpy: " + - // mixedStream.getThermoSystem().getEnthalpy()); - // System.out.println("enthalpy: " + enthalpy); - // System.out.println("temperature: " + - // mixedStream.getThermoSystem().getTemperature()); - - // System.out.println("beta " + mixedStream.getThermoSystem().getBeta()); - // outStream.setThermoSystem(mixedStream.getThermoSystem()); - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGasOutStream() { - return new Stream("", mixedStream.getThermoSystem().phaseToSystem(0)); - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getLiquidOutStream() { - return new Stream("", mixedStream.getThermoSystem().phaseToSystem(1)); - } - - /** {@inheritDoc} */ - @Override - public double getTemperature() { - return temperature; - } - - /** {@inheritDoc} */ - @Override - public void setTemperature(double temperature) { - this.temperature = temperature; + System.out.println("total enthalpy of streams: " + enthalpy); + return enthalpy; + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + double enthalpy = 0.0; + + // ((Stream) streams.get(0)).getThermoSystem().display(); + + SystemInterface thermoSystem2 = streams.get(0).getThermoSystem().clone(); + // System.out.println("total number of moles " + + // thermoSystem2.getTotalNumberOfMoles()); + mixedStream.setThermoSystem(thermoSystem2); + // thermoSystem2.display(); + ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem2); + if (streams.size() > 0) { + // mixedStream.getThermoSystem().setSolidPhaseCheck("CO2"); + mixedStream.getThermoSystem().setNumberOfPhases(2); + mixedStream.getThermoSystem().reInitPhaseType(); + mixedStream.getThermoSystem().init(0); + + mixStream(); + + enthalpy = calcMixStreamEnthalpy(); + // mixedStream.getThermoSystem().display(); + // System.out.println("temp guess " + guessTemperature()); + mixedStream.getThermoSystem().setSolidPhaseCheck("CO2"); + mixedStream.getThermoSystem().setTemperature(guessTemperature()); + testOps.PHsolidFlash(enthalpy); + mixedStream.getThermoSystem().display(); + // System.out.println("filan temp " + mixedStream.getTemperature()); + } else { + testOps.TPflash(); } + mixedStream.getThermoSystem().setSolidPhaseCheck(false); + // System.out.println("enthalpy: " + + // mixedStream.getThermoSystem().getEnthalpy()); + // System.out.println("enthalpy: " + enthalpy); + // System.out.println("temperature: " + + // mixedStream.getThermoSystem().getTemperature()); + + // System.out.println("beta " + mixedStream.getThermoSystem().getBeta()); + // outStream.setThermoSystem(mixedStream.getThermoSystem()); + mixedStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getGasOutStream() { + return new Stream("", mixedStream.getThermoSystem().phaseToSystem(0)); + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getLiquidOutStream() { + return new Stream("", mixedStream.getThermoSystem().phaseToSystem(1)); + } + + /** {@inheritDoc} */ + @Override + public double getTemperature() { + return temperature; + } + + /** {@inheritDoc} */ + @Override + public void setTemperature(double temperature) { + this.temperature = temperature; + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/expander/Expander.java b/src/main/java/neqsim/processSimulation/processEquipment/expander/Expander.java index a773929bda..f54973abe9 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/expander/Expander.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/expander/Expander.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.expander; +import java.util.UUID; import neqsim.processSimulation.processEquipment.compressor.Compressor; import neqsim.processSimulation.processEquipment.stream.StreamInterface; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -13,114 +14,113 @@ * @version $Id: $Id */ public class Expander extends Compressor implements ExpanderInterface { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - /** - *- * Constructor for Expander. - *
- */ - @Deprecated - public Expander() { - super(); - } + /** + *+ * Constructor for Expander. + *
+ */ + @Deprecated + public Expander() { + super(); + } - /** - *- * Constructor for Expander. - *
- * - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public Expander(StreamInterface inletStream) { - super(inletStream); - } + /** + *+ * Constructor for Expander. + *
+ * + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public Expander(StreamInterface inletStream) { + super(inletStream); + } - /** - * Constructor for Expander. - * - * @param name name of unit operation - */ - public Expander(String name) { - super(name); - } + /** + * Constructor for Expander. + * + * @param name name of unit operation + */ + public Expander(String name) { + super(name); + } - /** - *- * Constructor for Expander. - *
- * - * @param name a {@link java.lang.String} object - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public Expander(String name, StreamInterface inletStream) { - super(name, inletStream); - } + /** + *+ * Constructor for Expander. + *
+ * + * @param name a {@link java.lang.String} object + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public Expander(String name, StreamInterface inletStream) { + super(name, inletStream); + } - /** {@inheritDoc} */ - @Override - public void run() { - // System.out.println("expander running.."); - thermoSystem = inStream.getThermoSystem().clone(); - ThermodynamicOperations thermoOps = new ThermodynamicOperations(getThermoSystem()); - thermoOps = new ThermodynamicOperations(thermoSystem); - thermoSystem.init(3); - // double presinn = getThermoSystem().getPressure(); - double hinn = getThermoSystem().getEnthalpy(); - // double densInn = getThermoSystem().getDensity(); - double entropy = getThermoSystem().getEntropy(); - inletEnthalpy = hinn; + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + // System.out.println("expander running.."); + thermoSystem = inStream.getThermoSystem().clone(); + ThermodynamicOperations thermoOps = new ThermodynamicOperations(getThermoSystem()); + thermoOps = new ThermodynamicOperations(thermoSystem); + thermoSystem.init(3); + // double presinn = getThermoSystem().getPressure(); + double hinn = getThermoSystem().getEnthalpy(); + // double densInn = getThermoSystem().getDensity(); + double entropy = getThermoSystem().getEntropy(); + inletEnthalpy = hinn; - if (usePolytropicCalc) { - int numbersteps = 40; - double dp = (pressure - getThermoSystem().getPressure()) / (1.0 * numbersteps); - for (int i = 0; i < numbersteps; i++) { - entropy = getThermoSystem().getEntropy(); - hinn = getThermoSystem().getEnthalpy(); - getThermoSystem().setPressure(getThermoSystem().getPressure() + dp); - thermoOps.PSflash(entropy); - double hout = - hinn + (getThermoSystem().getEnthalpy() - hinn) * polytropicEfficiency; - thermoOps.PHflash(hout, 0); - } - /* - * HYSYS method double oldPolyt = 10.5; int iter = 0; do { - * - * - * iter++; double n = Math.log(thermoSystem.getPressure() / presinn) / - * Math.log(thermoSystem.getDensity() / densInn); double k = - * Math.log(thermoSystem.getPressure() / presinn) / Math.log(densOutIdeal / densInn); - * double factor = ((Math.pow(thermoSystem.getPressure() / presinn, (n - 1.0) / n) - - * 1.0) * (n / (n - 1.0)) * (k - 1) / k) / (Math.pow(thermoSystem.getPressure() / - * presinn, (k - 1.0) / k) - 1.0); oldPolyt = polytropicEfficiency; polytropicEfficiency - * = factor * isentropicEfficiency; dH = thermoSystem.getEnthalpy() - hinn; hout = hinn - * + dH / polytropicEfficiency; thermoOps.PHflash(hout, 0); - * System.out.println(" factor " + factor + " n " + n + " k " + k + - * " polytropic effici " + polytropicEfficiency + " iter " + iter); - * - * } while (Math.abs((oldPolyt - polytropicEfficiency) / oldPolyt) > 1e-5 && iter < - * 500); // polytropicEfficiency = isentropicEfficiency * (); - * - */ - } else { - getThermoSystem().setPressure(pressure); + if (usePolytropicCalc) { + int numbersteps = 40; + double dp = (pressure - getThermoSystem().getPressure()) / (1.0 * numbersteps); + for (int i = 0; i < numbersteps; i++) { + entropy = getThermoSystem().getEntropy(); + hinn = getThermoSystem().getEnthalpy(); + getThermoSystem().setPressure(getThermoSystem().getPressure() + dp); + thermoOps.PSflash(entropy); + double hout = hinn + (getThermoSystem().getEnthalpy() - hinn) * polytropicEfficiency; + thermoOps.PHflash(hout, 0); + } + /* + * HYSYS method double oldPolyt = 10.5; int iter = 0; do { + * + * + * iter++; double n = Math.log(thermoSystem.getPressure() / presinn) / + * Math.log(thermoSystem.getDensity() / densInn); double k = + * Math.log(thermoSystem.getPressure() / presinn) / Math.log(densOutIdeal / densInn); double + * factor = ((Math.pow(thermoSystem.getPressure() / presinn, (n - 1.0) / n) - 1.0) * (n / (n - + * 1.0)) * (k - 1) / k) / (Math.pow(thermoSystem.getPressure() / presinn, (k - 1.0) / k) - + * 1.0); oldPolyt = polytropicEfficiency; polytropicEfficiency = factor * + * isentropicEfficiency; dH = thermoSystem.getEnthalpy() - hinn; hout = hinn + dH / + * polytropicEfficiency; thermoOps.PHflash(hout, 0); System.out.println(" factor " + factor + + * " n " + n + " k " + k + " polytropic effici " + polytropicEfficiency + " iter " + iter); + * + * } while (Math.abs((oldPolyt - polytropicEfficiency) / oldPolyt) > 1e-5 && iter < 500); // + * polytropicEfficiency = isentropicEfficiency * (); + * + */ + } else { + getThermoSystem().setPressure(pressure); - // System.out.println("entropy inn.." + entropy); - thermoOps.PSflash(entropy); - // double densOutIdeal = getThermoSystem().getDensity(); - if (!powerSet) { - dH = (getThermoSystem().getEnthalpy() - hinn) * isentropicEfficiency; - } - double hout = hinn + dH; - isentropicEfficiency = dH / (getThermoSystem().getEnthalpy() - hinn); - // System.out.println("isentropicEfficiency.. " + isentropicEfficiency); - dH = hout - hinn; - thermoOps.PHflash(hout, 0); - } - // thermoSystem.display(); - outStream.setThermoSystem(getThermoSystem()); + // System.out.println("entropy inn.." + entropy); + thermoOps.PSflash(entropy); + // double densOutIdeal = getThermoSystem().getDensity(); + if (!powerSet) { + dH = (getThermoSystem().getEnthalpy() - hinn) * isentropicEfficiency; + } + double hout = hinn + dH; + isentropicEfficiency = dH / (getThermoSystem().getEnthalpy() - hinn); + // System.out.println("isentropicEfficiency.. " + isentropicEfficiency); + dH = hout - hinn; + thermoOps.PHflash(hout, 0); } + // thermoSystem.display(); + outStream.setThermoSystem(getThermoSystem()); + setCalculationIdentifier(id); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/expander/ExpanderOld.java b/src/main/java/neqsim/processSimulation/processEquipment/expander/ExpanderOld.java index 53a294893d..b7b7257e2e 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/expander/ExpanderOld.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/expander/ExpanderOld.java @@ -4,6 +4,7 @@ import java.awt.FlowLayout; import java.text.DecimalFormat; import java.text.FieldPosition; +import java.util.UUID; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JScrollPane; @@ -56,7 +57,7 @@ public ExpanderOld(StreamInterface inletStream) { /** * Constructor for ExpanderOld. - * + * * @param name name of expander */ public ExpanderOld(String name) { @@ -68,7 +69,7 @@ public ExpanderOld(String name) { * Constructor for ExpanderOld. * * - * @param name a {@link java.lang.String} object + * @param name name of expander * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} * object */ @@ -100,22 +101,21 @@ public double getEnergy() { /** {@inheritDoc} */ @Override - public void run() { + public void run(UUID id) { System.out.println("expander running.."); thermoSystem = inStream.getThermoSystem().clone(); thermoOps = new ThermodynamicOperations(thermoSystem); thermoSystem.init(3); - double hinn = thermoSystem.getEnthalpy(); double entropy = thermoSystem.getEntropy(); - thermoSystem.setPressure(pressure); System.out.println("entropy inn.." + entropy); + double hinn = thermoSystem.getEnthalpy(); + thermoSystem.setPressure(pressure); thermoOps.PSflash(entropy); dH = thermoSystem.getEnthalpy() - hinn; outStream.setThermoSystem(thermoSystem); + setCalculationIdentifier(id); } - - /** {@inheritDoc} */ @Override public void displayResult() { @@ -129,7 +129,6 @@ public void displayResult() { thermoSystem.initPhysicalProperties(); String[][] table = new String[20][5]; - String[] names = {"", "Phase 1", "Phase 2", "Phase 3", "Unit"}; table[0][0] = ""; table[0][1] = ""; table[0][2] = ""; @@ -206,6 +205,7 @@ public void displayResult() { table[thermoSystem.getPhases()[0].getNumberOfComponents() + 13][4] = "-"; } + String[] names = {"", "Phase 1", "Phase 2", "Phase 3", "Unit"}; JTable Jtab = new JTable(table, names); JScrollPane scrollpane = new JScrollPane(Jtab); dialogContentPane.add(scrollpane); diff --git a/src/main/java/neqsim/processSimulation/processEquipment/filter/Filter.java b/src/main/java/neqsim/processSimulation/processEquipment/filter/Filter.java index 57f11bb14b..e78af11329 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/filter/Filter.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/filter/Filter.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.filter; +import java.util.UUID; import neqsim.processSimulation.processEquipment.ProcessEquipmentInterface; import neqsim.processSimulation.processEquipment.TwoPortEquipment; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -48,7 +49,7 @@ public Filter(String name, StreamInterface inStream) { /** {@inheritDoc} */ @Override - public void run() { + public void run(UUID id) { SystemInterface system = inStream.getThermoSystem().clone(); if (Math.abs(getDeltaP()) > 1e-10) { system.setPressure(inStream.getPressure() - getDeltaP()); @@ -58,6 +59,7 @@ public void run() { system.initProperties(); outStream.setThermoSystem(system); Cv = Math.sqrt(deltaP) / inStream.getFlowRate("kg/hr"); + setCalculationIdentifier(id); } /** diff --git a/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java b/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java index 1b13b9331d..0e19295d06 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java @@ -5,6 +5,7 @@ */ package neqsim.processSimulation.processEquipment.heatExchanger; +import java.util.UUID; import neqsim.processSimulation.conditionMonitor.ConditionMonitorSpecifications; import neqsim.processSimulation.processEquipment.ProcessEquipmentInterface; import neqsim.processSimulation.processEquipment.stream.Stream; @@ -21,589 +22,593 @@ * @version $Id: $Id */ public class HeatExchanger extends Heater implements HeatExchangerInterface { - private static final long serialVersionUID = 1000; - - boolean setTemperature = false; - StreamInterface[] outStream = new Stream[2]; - StreamInterface[] inStream = new Stream[2]; - SystemInterface system; - double NTU; - protected double temperatureOut = 0, dT = 0.0; - double dH = 0.0; - private double UAvalue = 500.0; - double duty = 0.0; - private double hotColdDutyBalance = 1.0; - boolean firstTime = true; - public double guessOutTemperature = 273.15 + 130.0; - int outStreamSpecificationNumber = 0; - public double thermalEffectiveness = 0.0; - private String flowArrangement = "concentric tube counterflow"; - - /** - *- * Constructor for HeatExchanger. - *
- */ - @Deprecated - public HeatExchanger() { - this("HeatExchanger"); - } - - /** - *- * Constructor for HeatExchanger. - *
- * - * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public HeatExchanger(StreamInterface inStream1) { - this("HeatExchanger", inStream1); - } - - /** - *- * Constructor for HeatExchanger. - *
- * - * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - * @param inStream2 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public HeatExchanger(StreamInterface inStream1, StreamInterface inStream2) { - this("HeatExchanger", inStream1, inStream2); - } - - /** - * Constructor for HeatExchanger. - * - * @param name name of heat exchanger - */ - public HeatExchanger(String name) { - super(name); - } - - /** - * Constructor for HeatExchanger. - * - * @param name name of heat exchanger - * @param inStream1 input stream - */ - public HeatExchanger(String name, StreamInterface inStream1) { - this(name); - this.inStream[0] = inStream1; - this.inStream[1] = inStream1; - outStream[0] = inStream1.clone(); - outStream[1] = inStream1.clone(); - } - - /** - * Constructor for HeatExchanger. - * - * @param name name of heat exchanger - * @param inStream1 input stream 1 - * @param inStream2 input stream 2 - */ - public HeatExchanger(String name, StreamInterface inStream1, StreamInterface inStream2) { - this(name); - this.inStream[0] = inStream1; - this.inStream[1] = inStream2; - outStream[0] = inStream1.clone(); - outStream[1] = inStream2.clone(); - } - - /** - *- * addInStream. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public void addInStream(StreamInterface inStream) { - this.inStream[1] = inStream; - } - - /** - *- * setFeedStream. - *
- * - * @param number a int - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public void setFeedStream(int number, StreamInterface inStream) { - this.inStream[number] = inStream; - outStream[number] = inStream.clone(); - } - - /** {@inheritDoc} */ - @Override - public void setName(String name) { - super.setName(name); - outStream[0].setName(name + "_Sout1"); - outStream[1].setName(name + "_Sout2"); - } - - /** {@inheritDoc} */ - @Override - public void setdT(double dT) { - this.dT = dT; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getOutStream(int i) { - return outStream[i]; - } - - /** - *
- * Getter for the field inStream
.
- *
- * getOutTemperature. - *
- * - * @param i a int - */ - public void getOutTemperature(int i) { - outStream[i].getThermoSystem().getTemperature(); - } - - /** - *- * getInTemperature. - *
- * - * @param i a int - */ - public void getInTemperature(int i) { - inStream[i].getThermoSystem().getTemperature(); - } - - /** - *
- * Setter for the field outStream
.
- *
- * runSpecifiedStream. - *
- */ - public void runSpecifiedStream() { - int nonOutStreamSpecifiedStreamNumber = 0; - if (outStreamSpecificationNumber == 0) { - nonOutStreamSpecifiedStreamNumber = 1; - } - - SystemInterface systemOut0 = - inStream[nonOutStreamSpecifiedStreamNumber].getThermoSystem().clone(); - // SystemInterface systemOut1 = - // inStream[outStreamSpecificationNumber].getThermoSystem().clone(); - - if (getSpecification().equals("out stream")) { - outStream[outStreamSpecificationNumber].setFlowRate( - getInStream(outStreamSpecificationNumber).getFlowRate("kg/sec"), "kg/sec"); - outStream[outStreamSpecificationNumber].run(); - temperatureOut = outStream[outStreamSpecificationNumber].getTemperature(); - // system = - // outStream[outStreamSpecificationNumber].getThermoSystem().clone(); - } - - double deltaEnthalpy = outStream[outStreamSpecificationNumber].getFluid().getEnthalpy() - - inStream[outStreamSpecificationNumber].getFluid().getEnthalpy(); - double enthalpyOutRef = inStream[nonOutStreamSpecifiedStreamNumber].getFluid().getEnthalpy() - - deltaEnthalpy; - - ThermodynamicOperations testOps = new ThermodynamicOperations(systemOut0); - testOps.PHflash(enthalpyOutRef); - System.out.println("out temperature " + systemOut0.getTemperature("C")); - outStream[nonOutStreamSpecifiedStreamNumber].setFluid(systemOut0); - } - - /** {@inheritDoc} */ - @Override - public void run() { - if (getSpecification().equals("out stream")) { - runSpecifiedStream(); - return; - } - - // inStream[0].run(); - // inStream[1].displayResult(); - if (firstTime) { - firstTime = false; - SystemInterface systemOut0 = inStream[0].getThermoSystem().clone(); - outStream[0].setThermoSystem(systemOut0); - outStream[0].getThermoSystem().setTemperature(guessOutTemperature); - outStream[0].run(); - run(); - return; - } - - double cP0 = inStream[0].getThermoSystem().getCp(); - double cP1 = inStream[1].getThermoSystem().getCp(); - int streamToCalculate = 0, streamToSet = 1; - - if (cP0 < cP1) { - // streamToCalculate = 1; - // streamToSet = 0; - } - SystemInterface systemOut0 = inStream[streamToSet].getThermoSystem().clone(); - SystemInterface systemOut1 = inStream[streamToCalculate].getThermoSystem().clone(); - - // systemOut1.setTemperature(inTemp1); - outStream[streamToSet].setThermoSystem(systemOut0); - outStream[streamToCalculate].setThermoSystem(systemOut1); - outStream[streamToSet].setTemperature( - inStream[streamToCalculate].getThermoSystem().getTemperature(), "K"); - outStream[streamToSet].getThermoSystem() - .setTemperature(inStream[streamToCalculate].getThermoSystem().getTemperature()); - if (!outStream[streamToSet].getSpecification().equals("TP")) { - outStream[streamToSet].runTPflash(); - } - outStream[streamToSet].run(); - double dEntalphy1 = outStream[streamToSet].getThermoSystem().getEnthalpy() - - inStream[streamToSet].getThermoSystem().getEnthalpy(); - double C1 = Math.abs(dEntalphy1) - / Math.abs((outStream[streamToSet].getThermoSystem().getTemperature() - - inStream[streamToSet].getThermoSystem().getTemperature())); - - outStream[streamToCalculate] - .setTemperature(inStream[streamToSet].getThermoSystem().getTemperature(), "K"); - outStream[streamToCalculate].getThermoSystem() - .setTemperature(inStream[streamToSet].getThermoSystem().getTemperature()); - if (!outStream[streamToCalculate].getSpecification().equals("TP")) { - outStream[streamToCalculate].runTPflash(); - } - outStream[streamToCalculate].run(); - double dEntalphy2 = outStream[streamToCalculate].getThermoSystem().getEnthalpy() - - inStream[streamToCalculate].getThermoSystem().getEnthalpy(); - double C2 = Math.abs(dEntalphy2) - / Math.abs(outStream[streamToCalculate].getThermoSystem().getTemperature() - - inStream[streamToCalculate].getThermoSystem().getTemperature()); - double Cmin = C1; - double Cmax = C2; - if (C2 < C1) { - Cmin = C2; - Cmax = C1; - } - double Cr = Cmin / Cmax; - if (Math.abs(dEntalphy1) > Math.abs(dEntalphy2)) { - int streamCHange = streamToCalculate; - streamToCalculate = streamToSet; - streamToSet = streamCHange; - } - - double dEntalphy = outStream[streamToSet].getThermoSystem().getEnthalpy() - - inStream[streamToSet].getThermoSystem().getEnthalpy(); - NTU = UAvalue / Cmin; - - thermalEffectiveness = calcThermalEffectivenes(NTU, Cr); - // double corrected_Entalphy = dEntalphy;// * - // inStream[1].getThermoSystem().getNumberOfMoles() / - // inStream[0].getThermoSystem().getNumberOfMoles(); - dEntalphy = thermalEffectiveness * dEntalphy; - // System.out.println("dent " + dEntalphy); - ThermodynamicOperations testOps = - new ThermodynamicOperations(outStream[streamToCalculate].getThermoSystem()); - testOps.PHflash(inStream[streamToCalculate].getThermoSystem().getEnthalpy() - dEntalphy, 0); - - if (Math.abs(thermalEffectiveness - 1.0) > 1e-10) { - testOps = new ThermodynamicOperations(outStream[streamToSet].getThermoSystem()); - testOps.PHflash(inStream[streamToSet].getThermoSystem().getEnthalpy() + dEntalphy, 0); - } - duty = dEntalphy; - hotColdDutyBalance = 1.0; - // outStream[0].displayResult(); - // outStream[1].displayResult(); - // System.out.println("temperatur Stream 1 out " + - // outStream[0].getTemperature()); - // System.out.println("temperatur Stream 0 out " + - // outStream[1].getTemperature()); - // outStream[0].setThermoSystem(systemOut0); - // System.out.println("temperature out " + - // outStream[streamToCalculate].getTemperature()); - /* - * if (systemOut0.getTemperature() <= inTemp1 - dT) { systemOut0.setTemperature(inTemp1); - * outStream[0].setThermoSystem(systemOut0); outStream[0].run(); //inStream[0].run(); - * - * dEntalphy = outStream[0].getThermoSystem().getEnthalpy() - - * inStream[0].getThermoSystem().getEnthalpy(); corrected_Entalphy = dEntalphy * - * inStream[0].getThermoSystem().getNumberOfMoles() / - * inStream[1].getThermoSystem().getNumberOfMoles(); - * - * systemOut1 = inStream[1].getThermoSystem().clone(); System.out.println("dent " + - * dEntalphy); testOps = new ThermodynamicOperations(systemOut1); - * testOps.PHflash(systemOut1.getEnthalpy() - corrected_Entalphy, 0); - * outStream[1].setThermoSystem(systemOut1); System.out.println("temperatur out " + - * outStream[1].getTemperature()); } - */ - } - - /** {@inheritDoc} */ - @Override - public double getDuty() { - return duty; - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - outStream[0].displayResult(); - outStream[1].displayResult(); - } - - /** - *- * getUAvalue. - *
- * - * @return the UAvalue - */ - public double getUAvalue() { - return UAvalue; - } - - /** - *- * setUAvalue. - *
- * - * @param UAvalue the UAvalue to set - */ - public void setUAvalue(double UAvalue) { - this.UAvalue = UAvalue; - } - - /** - *
- * Getter for the field guessOutTemperature
.
- *
- * Setter for the field guessOutTemperature
.
- *
- * runConditionAnalysis. - *
- */ - public void runConditionAnalysis() { - runConditionAnalysis(this); - } - - /** - *
- * Getter for the field thermalEffectiveness
.
- *
- * Setter for the field thermalEffectiveness
.
- *
- * calcThermalEffectivenes. - *
- * - * @param NTU a double - * @param Cr a double - * @return a double - */ - public double calcThermalEffectivenes(double NTU, double Cr) { - if (Cr == 0.0) { - return 1.0 - Math.exp(-NTU); - } - if (flowArrangement.equals("concentric tube counterflow")) { - if (Cr == 1.0) - return NTU / (1.0 + NTU); - else - return (1.0 - Math.exp(-NTU * (1 - Cr))) / (1.0 - Cr * Math.exp(-NTU * (1 - Cr))); - } else if (flowArrangement.equals("concentric tube paralellflow")) { - return (1.0 - Math.exp(-NTU * (1 + Cr))) / ((1 + Cr)); - } else if (flowArrangement.equals("shell and tube")) { - return (1.0 - Math.exp(-NTU * (1 - Cr))) / (1.0 - Cr * Math.exp(-NTU * (1 - Cr))); - } else - return (1.0 - Math.exp(-NTU * (1 - Cr))) / (1.0 - Cr * Math.exp(-NTU * (1 - Cr))); - } - - /** - *
- * Getter for the field hotColdDutyBalance
.
- *
- * Setter for the field hotColdDutyBalance
.
- *
+ * Constructor for HeatExchanger. + *
+ */ + @Deprecated + public HeatExchanger() { + this("HeatExchanger"); + } + + /** + *+ * Constructor for HeatExchanger. + *
+ * + * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public HeatExchanger(StreamInterface inStream1) { + this("HeatExchanger", inStream1); + } + + /** + *+ * Constructor for HeatExchanger. + *
+ * + * @param inStream1 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + * @param inStream2 a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public HeatExchanger(StreamInterface inStream1, StreamInterface inStream2) { + this("HeatExchanger", inStream1, inStream2); + } + + /** + * Constructor for HeatExchanger. + * + * @param name name of heat exchanger + */ + public HeatExchanger(String name) { + super(name); + } + + /** + * Constructor for HeatExchanger. + * + * @param name name of heat exchanger + * @param inStream1 input stream + */ + public HeatExchanger(String name, StreamInterface inStream1) { + this(name); + this.inStream[0] = inStream1; + this.inStream[1] = inStream1; + outStream[0] = inStream1.clone(); + outStream[1] = inStream1.clone(); + } + + /** + * Constructor for HeatExchanger. + * + * @param name name of heat exchanger + * @param inStream1 input stream 1 + * @param inStream2 input stream 2 + */ + public HeatExchanger(String name, StreamInterface inStream1, StreamInterface inStream2) { + this(name); + this.inStream[0] = inStream1; + this.inStream[1] = inStream2; + outStream[0] = inStream1.clone(); + outStream[1] = inStream2.clone(); + } + + /** + *+ * addInStream. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public void addInStream(StreamInterface inStream) { + this.inStream[1] = inStream; + } + + /** + *+ * setFeedStream. + *
+ * + * @param number a int + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public void setFeedStream(int number, StreamInterface inStream) { + this.inStream[number] = inStream; + outStream[number] = inStream.clone(); + } + + /** {@inheritDoc} */ + @Override + public void setName(String name) { + super.setName(name); + outStream[0].setName(name + "_Sout1"); + outStream[1].setName(name + "_Sout2"); + } + + /** {@inheritDoc} */ + @Override + public void setdT(double dT) { + this.dT = dT; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getOutStream(int i) { + return outStream[i]; + } + + /** + *
+ * Getter for the field inStream
.
+ *
+ * getOutTemperature. + *
+ * + * @param i a int + */ + public void getOutTemperature(int i) { + outStream[i].getThermoSystem().getTemperature(); + } + + /** + *+ * getInTemperature. + *
+ * + * @param i a int + */ + public void getInTemperature(int i) { + inStream[i].getThermoSystem().getTemperature(); + } + + /** + *
+ * Setter for the field outStream
.
+ *
+ * runSpecifiedStream. + *
+ */ + public void runSpecifiedStream(UUID id) { + int nonOutStreamSpecifiedStreamNumber = 0; + if (outStreamSpecificationNumber == 0) { + nonOutStreamSpecifiedStreamNumber = 1; + } + + SystemInterface systemOut0 = + inStream[nonOutStreamSpecifiedStreamNumber].getThermoSystem().clone(); + // SystemInterface systemOut1 = + // inStream[outStreamSpecificationNumber].getThermoSystem().clone(); + + if (getSpecification().equals("out stream")) { + outStream[outStreamSpecificationNumber] + .setFlowRate(getInStream(outStreamSpecificationNumber).getFlowRate("kg/sec"), "kg/sec"); + outStream[outStreamSpecificationNumber].run(id); + temperatureOut = outStream[outStreamSpecificationNumber].getTemperature(); + // system = + // outStream[outStreamSpecificationNumber].getThermoSystem().clone(); + } + + double deltaEnthalpy = outStream[outStreamSpecificationNumber].getFluid().getEnthalpy() + - inStream[outStreamSpecificationNumber].getFluid().getEnthalpy(); + double enthalpyOutRef = + inStream[nonOutStreamSpecifiedStreamNumber].getFluid().getEnthalpy() - deltaEnthalpy; + + ThermodynamicOperations testOps = new ThermodynamicOperations(systemOut0); + testOps.PHflash(enthalpyOutRef); + System.out.println("out temperature " + systemOut0.getTemperature("C")); + outStream[nonOutStreamSpecifiedStreamNumber].setFluid(systemOut0); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + if (getSpecification().equals("out stream")) { + runSpecifiedStream(id); + } + // inStream[0].run(id); + // inStream[1].displayResult(); + else if (firstTime) { + firstTime = false; + SystemInterface systemOut0 = inStream[0].getThermoSystem().clone(); + outStream[0].setThermoSystem(systemOut0); + outStream[0].getThermoSystem().setTemperature(guessOutTemperature); + outStream[0].run(id); + run(id); + } else { + double cP0 = inStream[0].getThermoSystem().getCp(); + double cP1 = inStream[1].getThermoSystem().getCp(); + int streamToCalculate = 0; + + // if (cP0 < cP1) { + // streamToCalculate = 1; + // streamToSet = 0; + // } + + int streamToSet = 1; + SystemInterface systemOut0 = inStream[streamToSet].getThermoSystem().clone(); + SystemInterface systemOut1 = inStream[streamToCalculate].getThermoSystem().clone(); + + // systemOut1.setTemperature(inTemp1); + outStream[streamToSet].setThermoSystem(systemOut0); + outStream[streamToCalculate].setThermoSystem(systemOut1); + outStream[streamToSet] + .setTemperature(inStream[streamToCalculate].getThermoSystem().getTemperature(), "K"); + outStream[streamToSet].getThermoSystem() + .setTemperature(inStream[streamToCalculate].getThermoSystem().getTemperature()); + if (!outStream[streamToSet].getSpecification().equals("TP")) { + outStream[streamToSet].runTPflash(); + } + outStream[streamToSet].run(id); + double dEntalphy1 = outStream[streamToSet].getThermoSystem().getEnthalpy() + - inStream[streamToSet].getThermoSystem().getEnthalpy(); + double C1 = + Math.abs(dEntalphy1) / Math.abs((outStream[streamToSet].getThermoSystem().getTemperature() + - inStream[streamToSet].getThermoSystem().getTemperature())); + + outStream[streamToCalculate] + .setTemperature(inStream[streamToSet].getThermoSystem().getTemperature(), "K"); + outStream[streamToCalculate].getThermoSystem() + .setTemperature(inStream[streamToSet].getThermoSystem().getTemperature()); + if (!outStream[streamToCalculate].getSpecification().equals("TP")) { + outStream[streamToCalculate].runTPflash(); + } + outStream[streamToCalculate].run(id); + double dEntalphy2 = outStream[streamToCalculate].getThermoSystem().getEnthalpy() + - inStream[streamToCalculate].getThermoSystem().getEnthalpy(); + double C2 = Math.abs(dEntalphy2) + / Math.abs(outStream[streamToCalculate].getThermoSystem().getTemperature() + - inStream[streamToCalculate].getThermoSystem().getTemperature()); + double Cmin = C1; + double Cmax = C2; + if (C2 < C1) { + Cmin = C2; + Cmax = C1; + } + double Cr = Cmin / Cmax; + if (Math.abs(dEntalphy1) > Math.abs(dEntalphy2)) { + int streamCHange = streamToCalculate; + streamToCalculate = streamToSet; + streamToSet = streamCHange; + } + + double dEntalphy = outStream[streamToSet].getThermoSystem().getEnthalpy() + - inStream[streamToSet].getThermoSystem().getEnthalpy(); + NTU = UAvalue / Cmin; + + thermalEffectiveness = calcThermalEffectivenes(NTU, Cr); + // double corrected_Entalphy = dEntalphy;// * + // inStream[1].getThermoSystem().getNumberOfMoles() / + // inStream[0].getThermoSystem().getNumberOfMoles(); + dEntalphy = thermalEffectiveness * dEntalphy; + // System.out.println("dent " + dEntalphy); + ThermodynamicOperations testOps = + new ThermodynamicOperations(outStream[streamToCalculate].getThermoSystem()); + testOps.PHflash(inStream[streamToCalculate].getThermoSystem().getEnthalpy() - dEntalphy, 0); + + if (Math.abs(thermalEffectiveness - 1.0) > 1e-10) { + testOps = new ThermodynamicOperations(outStream[streamToSet].getThermoSystem()); + testOps.PHflash(inStream[streamToSet].getThermoSystem().getEnthalpy() + dEntalphy, 0); + } + duty = dEntalphy; + hotColdDutyBalance = 1.0; + // outStream[0].displayResult(); + // outStream[1].displayResult(); + // System.out.println("temperatur Stream 1 out " + + // outStream[0].getTemperature()); + // System.out.println("temperatur Stream 0 out " + + // outStream[1].getTemperature()); + // outStream[0].setThermoSystem(systemOut0); + // System.out.println("temperature out " + + // outStream[streamToCalculate].getTemperature()); + /* + * if (systemOut0.getTemperature() <= inTemp1 - dT) { systemOut0.setTemperature(inTemp1); + * outStream[0].setThermoSystem(systemOut0); outStream[0].run(); //inStream[0].run(); + * + * dEntalphy = outStream[0].getThermoSystem().getEnthalpy() - + * inStream[0].getThermoSystem().getEnthalpy(); corrected_Entalphy = dEntalphy * + * inStream[0].getThermoSystem().getNumberOfMoles() / + * inStream[1].getThermoSystem().getNumberOfMoles(); + * + * systemOut1 = inStream[1].getThermoSystem().clone(); System.out.println("dent " + + * dEntalphy); testOps = new ThermodynamicOperations(systemOut1); + * testOps.PHflash(systemOut1.getEnthalpy() - corrected_Entalphy, 0); + * outStream[1].setThermoSystem(systemOut1); System.out.println("temperatur out " + + * outStream[1].getTemperature()); } + */ + } + + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public double getDuty() { + return duty; + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + outStream[0].displayResult(); + outStream[1].displayResult(); + } + + /** + *+ * getUAvalue. + *
+ * + * @return the UAvalue + */ + public double getUAvalue() { + return UAvalue; + } + + /** + *+ * setUAvalue. + *
+ * + * @param UAvalue the UAvalue to set + */ + public void setUAvalue(double UAvalue) { + this.UAvalue = UAvalue; + } + + /** + *
+ * Getter for the field guessOutTemperature
.
+ *
+ * Setter for the field guessOutTemperature
.
+ *
+ * runConditionAnalysis. + *
+ */ + public void runConditionAnalysis() { + runConditionAnalysis(this); + } + + /** + *
+ * Getter for the field thermalEffectiveness
.
+ *
+ * Setter for the field thermalEffectiveness
.
+ *
+ * calcThermalEffectivenes. + *
+ * + * @param NTU a double + * @param Cr a double + * @return a double + */ + public double calcThermalEffectivenes(double NTU, double Cr) { + if (Cr == 0.0) { + return 1.0 - Math.exp(-NTU); + } + if (flowArrangement.equals("concentric tube counterflow")) { + if (Cr == 1.0) { + return NTU / (1.0 + NTU); + } else { + return (1.0 - Math.exp(-NTU * (1 - Cr))) / (1.0 - Cr * Math.exp(-NTU * (1 - Cr))); + } + } else if (flowArrangement.equals("concentric tube paralellflow")) { + return (1.0 - Math.exp(-NTU * (1 + Cr))) / ((1 + Cr)); + } else if (flowArrangement.equals("shell and tube")) { + return (1.0 - Math.exp(-NTU * (1 - Cr))) / (1.0 - Cr * Math.exp(-NTU * (1 - Cr))); + } else { + return (1.0 - Math.exp(-NTU * (1 - Cr))) / (1.0 - Cr * Math.exp(-NTU * (1 - Cr))); + } + } + + /** + *
+ * Getter for the field hotColdDutyBalance
.
+ *
+ * Setter for the field hotColdDutyBalance
.
+ *
- * Constructor for NeqHeater. - *
- */ - @Deprecated - public NeqHeater() { - this("NeqHeater"); - } + /** + *+ * Constructor for NeqHeater. + *
+ */ + @Deprecated + public NeqHeater() { + this("NeqHeater"); + } - /** - *- * Constructor for NeqHeater. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public NeqHeater(StreamInterface inStream) { - this("NeqHeater", inStream); - } + /** + *+ * Constructor for NeqHeater. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public NeqHeater(StreamInterface inStream) { + this("NeqHeater", inStream); + } - /** - * Constructor for NeqHeater. - * - * @param name name of heater - */ - public NeqHeater(String name) { - super(name); - } + /** + * Constructor for NeqHeater. + * + * @param name name of heater + */ + public NeqHeater(String name) { + super(name); + } - /** - * Constructor for NeqHeater. - * - * @param name name of heater - * @param inStream input stream - */ - public NeqHeater(String name, StreamInterface inStream) { - super(name, inStream); - } + /** + * Constructor for NeqHeater. + * + * @param name name of heater + * @param inStream input stream + */ + public NeqHeater(String name, StreamInterface inStream) { + super(name, inStream); + } - /** {@inheritDoc} */ - @Override - public void setOutTemperature(double temperature) { - this.setTemperature = true; - this.temperatureOut = temperature; - } + /** {@inheritDoc} */ + @Override + public void setOutTemperature(double temperature) { + this.setTemperature = true; + this.temperatureOut = temperature; + } - /** {@inheritDoc} */ - @Override - public void run() { - system = inStream.getThermoSystem().clone(); - double oldH = system.getEnthalpy(); - if (setTemperature) { - system.setTemperature(temperatureOut); - } else { - system.setTemperature(system.getTemperature() + dT); - } - system.init(3); - double newH = system.getEnthalpy(); - dH = newH - oldH; - // system.setTemperature(temperatureOut); - // testOps.TPflash(); - // system.setTemperature(temperatureOut); - outStream.setThermoSystem(system); + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + system = inStream.getThermoSystem().clone(); + double oldH = system.getEnthalpy(); + if (setTemperature) { + system.setTemperature(temperatureOut); + } else { + system.setTemperature(system.getTemperature() + dT); } + system.init(3); + double newH = system.getEnthalpy(); + dH = newH - oldH; + // system.setTemperature(temperatureOut); + // testOps.TPflash(); + // system.setTemperature(temperatureOut); + outStream.setThermoSystem(system); - /** {@inheritDoc} */ - @Override - public void displayResult() { - System.out.println("heater dH: " + dH); - } + outStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + System.out.println("heater dH: " + dH); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/ReBoiler.java b/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/ReBoiler.java index 7ba44b74d4..e07f86cf22 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/ReBoiler.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/ReBoiler.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.heatExchanger; +import java.util.UUID; import neqsim.processSimulation.processEquipment.TwoPortEquipment; import neqsim.processSimulation.processEquipment.stream.StreamInterface; import neqsim.thermo.system.SystemInterface; @@ -14,97 +15,99 @@ * @version $Id: $Id */ public class ReBoiler extends TwoPortEquipment { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - boolean setTemperature = false; - SystemInterface system; - private double reboilerDuty = 0.0; + boolean setTemperature = false; + SystemInterface system; + private double reboilerDuty = 0.0; - /** - *- * Constructor for ReBoiler. - *
- */ - @Deprecated - public ReBoiler() { - super("ReBoiler"); - } + /** + *+ * Constructor for ReBoiler. + *
+ */ + @Deprecated + public ReBoiler() { + super("ReBoiler"); + } - /** - *- * Constructor for ReBoiler. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public ReBoiler(StreamInterface inStream) { - this("ReBoiler", inStream); - } + /** + *+ * Constructor for ReBoiler. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public ReBoiler(StreamInterface inStream) { + this("ReBoiler", inStream); + } - /** - *- * Constructor for ReBoiler. - *
- * - * @param name name of reboiler - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public ReBoiler(String name, StreamInterface inStream) { - super(name, inStream); - } + /** + *+ * Constructor for ReBoiler. + *
+ * + * @param name name of reboiler + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public ReBoiler(String name, StreamInterface inStream) { + super(name, inStream); + } - /** {@inheritDoc} */ - @Override - public void run() { - system = inStream.getThermoSystem().clone(); - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - double oldH = system.getEnthalpy(); - testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - testOps.PHflash(oldH + reboilerDuty, 0); - outStream.setThermoSystem(system); - // if(setTemperature) system.setTemperature(temperatureOut); - // else system.setTemperature(system.getTemperature()+dT); - // testOps = new ThermodynamicOperations(system); - // system.setTemperat ure(temperatureOut); - // testOps.TPflash(); - // double newH = system.getEnthalpy(); - // dH = newH - oldH; - // // system.setTemperature(temperatureOut); - // // testOps.TPflash(); - // // system.setTemperature(temperatureOut); - // outStream.setThermoSystem(system); - } + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + system = inStream.getThermoSystem().clone(); + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + testOps.TPflash(); + double oldH = system.getEnthalpy(); + testOps = new ThermodynamicOperations(system); + testOps.TPflash(); + testOps.PHflash(oldH + reboilerDuty, 0); + outStream.setThermoSystem(system); + // if(setTemperature) system.setTemperature(temperatureOut); + // else system.setTemperature(system.getTemperature()+dT); + // testOps = new ThermodynamicOperations(system); + // system.setTemperat ure(temperatureOut); + // testOps.TPflash(); + // double newH = system.getEnthalpy(); + // dH = newH - oldH; + // // system.setTemperature(temperatureOut); + // // testOps.TPflash(); + // // system.setTemperature(temperatureOut); + // outStream.setThermoSystem(system); + outStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); + } - /** {@inheritDoc} */ - @Override - public void displayResult() { - System.out.println("out Temperature " + reboilerDuty); - } + /** {@inheritDoc} */ + @Override + public void displayResult() { + System.out.println("out Temperature " + reboilerDuty); + } - /** - *
- * Getter for the field reboilerDuty
.
- *
+ * Getter for the field reboilerDuty
.
+ *
- * Setter for the field reboilerDuty
.
- *
+ * Setter for the field reboilerDuty
.
+ *
- * Constructor for StaticMixer. - *
- */ - @Deprecated - public StaticMixer() {} + /** + *+ * Constructor for StaticMixer. + *
+ */ + @Deprecated + public StaticMixer() {} - /** - *- * Constructor for StaticMixer. - *
- * - * @param name a {@link java.lang.String} object - */ - public StaticMixer(String name) { - super(name); - } + /** + *+ * Constructor for StaticMixer. + *
+ * + * @param name a {@link java.lang.String} object + */ + public StaticMixer(String name) { + super(name); + } - /** {@inheritDoc} */ - @Override - public void mixStream() { - int index = 0; - String compName = new String(); - for (int k = 1; k < streams.size(); k++) { - for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] - .getNumberOfComponents(); i++) { - boolean gotComponent = false; - String componentName = - streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i] - .getName(); - // System.out.println("adding: " + componentName); - double moles = streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i] - .getNumberOfmoles(); - // System.out.println("moles: " + moles + " " + - // mixedStream.getThermoSystem().getPhases()[0].getNumberOfComponents()); - for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] - .getNumberOfComponents(); p++) { - if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() - .equals(componentName)) { - gotComponent = true; - index = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] - .getComponentNumber(); - compName = - streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] - .getComponentName(); - } - } + /** {@inheritDoc} */ + @Override + public void mixStream() { + int index = 0; + String compName = new String(); + for (int k = 1; k < streams.size(); k++) { + for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] + .getNumberOfComponents(); i++) { + boolean gotComponent = false; + String componentName = + streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i].getName(); + // System.out.println("adding: " + componentName); + double moles = + streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i].getNumberOfmoles(); + // System.out.println("moles: " + moles + " " + + // mixedStream.getThermoSystem().getPhases()[0].getNumberOfComponents()); + for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] + .getNumberOfComponents(); p++) { + if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() + .equals(componentName)) { + gotComponent = true; + index = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] + .getComponentNumber(); + compName = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] + .getComponentName(); + } + } - if (gotComponent) { - // System.out.println("adding moles starting...."); - mixedStream.getThermoSystem().addComponent(index, moles, 0); - // mixedStream.getThermoSystem().init_x_y(); - // System.out.println("adding moles finished"); - } else { - // System.out.println("ikke gaa hit"); - mixedStream.getThermoSystem().addComponent(compName, moles, 0); - } - } + if (gotComponent) { + // System.out.println("adding moles starting...."); + mixedStream.getThermoSystem().addComponent(index, moles, 0); + // mixedStream.getThermoSystem().init_x_y(); + // System.out.println("adding moles finished"); + } else { + // System.out.println("ikke gaa hit"); + mixedStream.getThermoSystem().addComponent(compName, moles, 0); } + } } + } - /** {@inheritDoc} */ - @Override - public double guessTemperature() { - double gtemp = 0; - for (int k = 0; k < streams.size(); k++) { - gtemp += streams.get(k).getThermoSystem().getTemperature() - * streams.get(k).getThermoSystem().getNumberOfMoles() - / mixedStream.getThermoSystem().getNumberOfMoles(); - } - return gtemp; + /** {@inheritDoc} */ + @Override + public double guessTemperature() { + double gtemp = 0; + for (int k = 0; k < streams.size(); k++) { + gtemp += streams.get(k).getThermoSystem().getTemperature() + * streams.get(k).getThermoSystem().getNumberOfMoles() + / mixedStream.getThermoSystem().getNumberOfMoles(); } + return gtemp; + } - /** {@inheritDoc} */ - @Override - public double calcMixStreamEnthalpy() { - double enthalpy = 0; - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); - System.out.println( - "total enthalpy k : " + streams.get(k).getThermoSystem().getEnthalpy()); - } - System.out.println("total enthalpy of streams: " + enthalpy); - return enthalpy; + /** {@inheritDoc} */ + @Override + public double calcMixStreamEnthalpy() { + double enthalpy = 0; + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); + System.out.println("total enthalpy k : " + streams.get(k).getThermoSystem().getEnthalpy()); } + System.out.println("total enthalpy of streams: " + enthalpy); + return enthalpy; + } - /** {@inheritDoc} */ - @Override - public void run() { - double enthalpy = 0.0; - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); - } - mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); - mixedStream.getThermoSystem().setNumberOfPhases(2); - mixedStream.getThermoSystem().reInitPhaseType(); - mixStream(); - ThermodynamicOperations testOps = - new ThermodynamicOperations(mixedStream.getThermoSystem()); - testOps.PHflash(enthalpy, 0); - // System.out.println("temp " + mixedStream.getThermoSystem().getTemperature()); - mixedStream.getThermoSystem().init(3); - } + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + double enthalpy = 0.0; + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); + } + mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); + mixedStream.getThermoSystem().setNumberOfPhases(2); + mixedStream.getThermoSystem().reInitPhaseType(); + mixStream(); + ThermodynamicOperations testOps = new ThermodynamicOperations(mixedStream.getThermoSystem()); + testOps.PHflash(enthalpy, 0); + // System.out.println("temp " + mixedStream.getThermoSystem().getTemperature()); + mixedStream.getThermoSystem().init(3); + setCalculationIdentifier(id); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/mixer/StaticNeqMixer.java b/src/main/java/neqsim/processSimulation/processEquipment/mixer/StaticNeqMixer.java index af9c953841..a8c027319e 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/mixer/StaticNeqMixer.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/mixer/StaticNeqMixer.java @@ -5,6 +5,7 @@ */ package neqsim.processSimulation.processEquipment.mixer; +import java.util.UUID; import neqsim.thermo.system.SystemInterface; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -17,113 +18,113 @@ * @version $Id: $Id */ public class StaticNeqMixer extends StaticMixer { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - /** - *- * Constructor for StaticNeqMixer. - *
- */ - @Deprecated - public StaticNeqMixer() {} + /** + *+ * Constructor for StaticNeqMixer. + *
+ */ + @Deprecated + public StaticNeqMixer() {} - /** - *- * Constructor for StaticNeqMixer. - *
- * - * @param name a {@link java.lang.String} object - */ - public StaticNeqMixer(String name) { - super(name); - } + /** + *+ * Constructor for StaticNeqMixer. + *
+ * + * @param name a {@link java.lang.String} object + */ + public StaticNeqMixer(String name) { + super(name); + } - /** {@inheritDoc} */ - @Override - public void mixStream() { - int index = 0; - String compName = new String(); + /** {@inheritDoc} */ + @Override + public void mixStream() { + int index = 0; + String compName = new String(); - for (int k = 1; k < streams.size(); k++) { - for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] - .getNumberOfComponents(); i++) { - boolean gotComponent = false; - String componentName = - streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i] - .getName(); - System.out.println("adding: " + componentName); - int numberOfPhases = streams.get(k).getThermoSystem().getNumberOfPhases(); - double[] moles = new double[numberOfPhases]; - // her maa man egentlig sjekke at phase typen er den samme !!! antar at begge er - // to fase elle gass - tofase - for (int p = 0; p < numberOfPhases; p++) { - moles[p] = streams.get(k).getThermoSystem().getPhases()[p].getComponents()[i] - .getNumberOfMolesInPhase(); - } - for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] - .getNumberOfComponents(); p++) { - if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() - .equals(componentName)) { - gotComponent = true; - index = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] - .getComponentNumber(); - compName = - streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] - .getComponentName(); - } - } + for (int k = 1; k < streams.size(); k++) { + for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] + .getNumberOfComponents(); i++) { + boolean gotComponent = false; + String componentName = + streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i].getName(); + System.out.println("adding: " + componentName); + int numberOfPhases = streams.get(k).getThermoSystem().getNumberOfPhases(); + double[] moles = new double[numberOfPhases]; + // her maa man egentlig sjekke at phase typen er den samme !!! antar at begge er + // to fase elle gass - tofase + for (int p = 0; p < numberOfPhases; p++) { + moles[p] = streams.get(k).getThermoSystem().getPhases()[p].getComponents()[i] + .getNumberOfMolesInPhase(); + } + for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] + .getNumberOfComponents(); p++) { + if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() + .equals(componentName)) { + gotComponent = true; + index = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] + .getComponentNumber(); + compName = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] + .getComponentName(); + } + } - if (gotComponent) { - System.out.println("adding moles starting...."); - for (int p = 0; p < numberOfPhases; p++) { - mixedStream.getThermoSystem().addComponent(index, moles[p], p); - } - System.out.println("adding moles finished"); - } else { - System.out.println("ikke gaa hit"); - for (int p = 0; p < numberOfPhases; p++) { - mixedStream.getThermoSystem().addComponent(compName, moles[p], p); - } - } - } + if (gotComponent) { + System.out.println("adding moles starting...."); + for (int p = 0; p < numberOfPhases; p++) { + mixedStream.getThermoSystem().addComponent(index, moles[p], p); + } + System.out.println("adding moles finished"); + } else { + System.out.println("ikke gaa hit"); + for (int p = 0; p < numberOfPhases; p++) { + mixedStream.getThermoSystem().addComponent(compName, moles[p], p); + } } - mixedStream.getThermoSystem().init_x_y(); - mixedStream.getThermoSystem().initBeta(); - mixedStream.getThermoSystem().init(2); + } } + mixedStream.getThermoSystem().init_x_y(); + mixedStream.getThermoSystem().initBeta(); + mixedStream.getThermoSystem().init(2); + } - /** {@inheritDoc} */ - @Override - public void run() { - double enthalpy = 0.0; - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); - } + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + double enthalpy = 0.0; + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + enthalpy += streams.get(k).getThermoSystem().getEnthalpy(); + } - mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); - mixedStream.getThermoSystem().setNumberOfPhases(2); - mixedStream.getThermoSystem().reInitPhaseType(); - mixStream(); + mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); + mixedStream.getThermoSystem().setNumberOfPhases(2); + mixedStream.getThermoSystem().reInitPhaseType(); + mixStream(); - SystemInterface syst = mixedStream.getThermoSystem().clone(); - syst.setTemperature(streams.get(0).getThermoSystem().getTemperature()); - syst.setPressure(streams.get(0).getThermoSystem().getPressure()); - ThermodynamicOperations testOps = new ThermodynamicOperations(syst); - testOps.PHflash(enthalpy, 0); - System.out.println("temp " + syst.getTemperature()); - mixedStream.getThermoSystem().setTemperature(syst.getTemperature()); - mixedStream.getThermoSystem().init(3); - // double enthalpy = calcMixStreamEnthalpy(); - // System.out.println("temp guess " + guessTemperature()); - // mixedStream.getThermoSystem().setTemperature(guessTemperature()); - // testOps = new ThermodynamicOperations(mixedStream.getThermoSystem()); - // testOps.TPflash(); - // testOps.PHflash(enthalpy, 0); - // System.out.println("enthalpy: " + - // mixedStream.getThermoSystem().getEnthalpy()); - // System.out.println("enthalpy: " + enthalpy); - // System.out.println("temperature: " + - // mixedStream.getThermoSystem().getTemperature()); - } + SystemInterface syst = mixedStream.getThermoSystem().clone(); + syst.setTemperature(streams.get(0).getThermoSystem().getTemperature()); + syst.setPressure(streams.get(0).getThermoSystem().getPressure()); + ThermodynamicOperations testOps = new ThermodynamicOperations(syst); + testOps.PHflash(enthalpy, 0); + System.out.println("temp " + syst.getTemperature()); + mixedStream.getThermoSystem().setTemperature(syst.getTemperature()); + mixedStream.getThermoSystem().init(3); + // double enthalpy = calcMixStreamEnthalpy(); + // System.out.println("temp guess " + guessTemperature()); + // mixedStream.getThermoSystem().setTemperature(guessTemperature()); + // testOps = new ThermodynamicOperations(mixedStream.getThermoSystem()); + // testOps.TPflash(); + // testOps.PHflash(enthalpy, 0); + // System.out.println("enthalpy: " + + // mixedStream.getThermoSystem().getEnthalpy()); + // System.out.println("enthalpy: " + enthalpy); + // System.out.println("temperature: " + + // mixedStream.getThermoSystem().getTemperature()); + mixedStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/mixer/StaticPhaseMixer.java b/src/main/java/neqsim/processSimulation/processEquipment/mixer/StaticPhaseMixer.java index e816cd93b0..0c8700e65d 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/mixer/StaticPhaseMixer.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/mixer/StaticPhaseMixer.java @@ -1,5 +1,7 @@ package neqsim.processSimulation.processEquipment.mixer; +import java.util.UUID; + /** ** StaticPhaseMixer class. @@ -9,113 +11,113 @@ * @version $Id: $Id */ public class StaticPhaseMixer extends StaticMixer { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - /** - *
- * Constructor for StaticPhaseMixer. - *
- */ - @Deprecated - public StaticPhaseMixer() {} + /** + *+ * Constructor for StaticPhaseMixer. + *
+ */ + @Deprecated + public StaticPhaseMixer() {} - /** - *- * Constructor for StaticPhaseMixer. - *
- * - * @param name a {@link java.lang.String} object - */ - public StaticPhaseMixer(String name) { - super(name); - } + /** + *+ * Constructor for StaticPhaseMixer. + *
+ * + * @param name a {@link java.lang.String} object + */ + public StaticPhaseMixer(String name) { + super(name); + } - /** {@inheritDoc} */ - @Override - public void mixStream() { - int index = 0; - String compName = new String(); + /** {@inheritDoc} */ + @Override + public void mixStream() { + int index = 0; + String compName = new String(); - for (int k = 1; k < streams.size(); k++) { - for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] - .getNumberOfComponents(); i++) { - boolean gotComponent = false; - String componentName = - streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i] - .getName(); - System.out.println("adding: " + componentName); - int numberOfPhases = streams.get(k).getThermoSystem().getNumberOfPhases(); - double[] moles = new double[numberOfPhases]; - int[] phaseType = new int[numberOfPhases]; + for (int k = 1; k < streams.size(); k++) { + for (int i = 0; i < streams.get(k).getThermoSystem().getPhases()[0] + .getNumberOfComponents(); i++) { + boolean gotComponent = false; + String componentName = + streams.get(k).getThermoSystem().getPhases()[0].getComponents()[i].getName(); + System.out.println("adding: " + componentName); + int numberOfPhases = streams.get(k).getThermoSystem().getNumberOfPhases(); + double[] moles = new double[numberOfPhases]; + int[] phaseType = new int[numberOfPhases]; - // her maa man egentlig sjekke at phase typen er den samme !!! antar at begge er - // to fase elle gass - tofase - for (int p = 0; p < numberOfPhases; p++) { - moles[p] = streams.get(k).getThermoSystem().getPhase(p).getComponents()[i] - .getNumberOfMolesInPhase(); - phaseType[p] = streams.get(k).getThermoSystem().getPhase(p).getPhaseType(); - } - if (k == 1) { - phaseType[0] = 0; - mixedStream.getThermoSystem().getPhase(1) - .setTemperature(streams.get(k).getThermoSystem().getTemperature()); - } + // her maa man egentlig sjekke at phase typen er den samme !!! antar at begge er + // to fase elle gass - tofase + for (int p = 0; p < numberOfPhases; p++) { + moles[p] = streams.get(k).getThermoSystem().getPhase(p).getComponents()[i] + .getNumberOfMolesInPhase(); + phaseType[p] = streams.get(k).getThermoSystem().getPhase(p).getPhaseType(); + } + if (k == 1) { + phaseType[0] = 0; + mixedStream.getThermoSystem().getPhase(1) + .setTemperature(streams.get(k).getThermoSystem().getTemperature()); + } - for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] - .getNumberOfComponents(); p++) { - if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() - .equals(componentName)) { - gotComponent = true; - index = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] - .getComponentNumber(); - compName = - streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] - .getComponentName(); - } - } + for (int p = 0; p < mixedStream.getThermoSystem().getPhases()[0] + .getNumberOfComponents(); p++) { + if (mixedStream.getThermoSystem().getPhases()[0].getComponents()[p].getName() + .equals(componentName)) { + gotComponent = true; + index = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] + .getComponentNumber(); + compName = streams.get(0).getThermoSystem().getPhases()[0].getComponents()[p] + .getComponentName(); + } + } - if (gotComponent) { - System.out.println("adding moles starting...."); - for (int p = 0; p < numberOfPhases; p++) { - if (phaseType[p] == 0) { - System.out.println("adding liq"); - mixedStream.getThermoSystem().addComponent(index, moles[p], 1); - } else if (phaseType[p] == 1) { - System.out.println("adding gas"); - mixedStream.getThermoSystem().addComponent(index, moles[p], 0); - } else { - System.out.println("not here...."); - } - } - System.out.println("adding moles finished"); - } else { - System.out.println("ikke gaa hit"); - for (int p = 0; p < numberOfPhases; p++) { - mixedStream.getThermoSystem().addComponent(compName, moles[p], p); - } - } + if (gotComponent) { + System.out.println("adding moles starting...."); + for (int p = 0; p < numberOfPhases; p++) { + if (phaseType[p] == 0) { + System.out.println("adding liq"); + mixedStream.getThermoSystem().addComponent(index, moles[p], 1); + } else if (phaseType[p] == 1) { + System.out.println("adding gas"); + mixedStream.getThermoSystem().addComponent(index, moles[p], 0); + } else { + System.out.println("not here...."); } + } + System.out.println("adding moles finished"); + } else { + System.out.println("ikke gaa hit"); + for (int p = 0; p < numberOfPhases; p++) { + mixedStream.getThermoSystem().addComponent(compName, moles[p], p); + } } - mixedStream.getThermoSystem().init_x_y(); - mixedStream.getThermoSystem().initBeta(); - mixedStream.getThermoSystem().init(2); + } } + mixedStream.getThermoSystem().init_x_y(); + mixedStream.getThermoSystem().initBeta(); + mixedStream.getThermoSystem().init(2); + } - /** {@inheritDoc} */ - @Override - public void run() { - for (int k = 0; k < streams.size(); k++) { - streams.get(k).getThermoSystem().init(3); - } + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + for (int k = 0; k < streams.size(); k++) { + streams.get(k).getThermoSystem().init(3); + } - mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); - mixedStream.getThermoSystem().init(0); - mixedStream.getThermoSystem().setBeta(1, 1e-10); - mixedStream.getThermoSystem().init(2); - mixedStream.getThermoSystem().reInitPhaseType(); + mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone())); + mixedStream.getThermoSystem().init(0); + mixedStream.getThermoSystem().setBeta(1, 1e-10); + mixedStream.getThermoSystem().init(2); + mixedStream.getThermoSystem().reInitPhaseType(); - mixStream(); + mixStream(); - mixedStream.getThermoSystem().init(3); - } + mixedStream.getThermoSystem().init(3); + mixedStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/AdiabaticPipe.java b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/AdiabaticPipe.java index 336f463232..8e16bdeeac 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/AdiabaticPipe.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/AdiabaticPipe.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.pipeline; +import java.util.UUID; import neqsim.fluidMechanics.flowSystem.FlowSystemInterface; import neqsim.processSimulation.processEquipment.stream.Stream; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -14,380 +15,385 @@ * @version $Id: $Id */ public class AdiabaticPipe extends Pipeline { - private static final long serialVersionUID = 1000; - - double inletPressure = 0; - boolean setTemperature = false, setPressureOut = false; - protected double temperatureOut = 270, pressureOut = 0.0; - double length = 100.0; - double insideDiameter = 0.1; - double velocity = 1.0; - double pipeWallRoughness = 1e-5; - private double inletElevation = 0; - private double outletElevation = 0; - double dH = 0.0; - String flowPattern = "unknown"; - String pipeSpecification = "AP02"; - - /** - *- * Constructor for AdiabaticPipe. - *
- */ - @Deprecated - public AdiabaticPipe() { - this("AdiabaticPipe"); + private static final long serialVersionUID = 1000; + + double inletPressure = 0; + boolean setTemperature = false; + + boolean setPressureOut = false; + + protected double temperatureOut = 270; + + protected double pressureOut = 0.0; + + double length = 100.0; + double insideDiameter = 0.1; + double velocity = 1.0; + double pipeWallRoughness = 1e-5; + private double inletElevation = 0; + private double outletElevation = 0; + double dH = 0.0; + String flowPattern = "unknown"; + String pipeSpecification = "AP02"; + + /** + *+ * Constructor for AdiabaticPipe. + *
+ */ + @Deprecated + public AdiabaticPipe() { + this("AdiabaticPipe"); + } + + /** + *+ * Constructor for AdiabaticPipe. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public AdiabaticPipe(StreamInterface inStream) { + this("AdiabaticPipe", inStream); + } + + /** + * Constructor for AdiabaticPipe. + * + * @param name name of pipe + */ + public AdiabaticPipe(String name) { + super(name); + } + + /** + * Constructor for AdiabaticPipe. + * + * @param name name of pipe + * @param inStream input stream + */ + public AdiabaticPipe(String name, StreamInterface inStream) { + this(name); + this.inStream = inStream; + outStream = (Stream) inStream.clone(); + } + + /** + *
+ * Setter for the field pipeSpecification
.
+ *
+ * setOutTemperature. + *
+ * + * @param temperature a double + */ + public void setOutTemperature(double temperature) { + setTemperature = true; + this.temperatureOut = temperature; + } + + /** + *+ * setOutPressure. + *
+ * + * @param pressure a double + */ + public void setOutPressure(double pressure) { + setPressureOut = true; + this.pressureOut = pressure; + } + + /** + *+ * calcWallFrictionFactor. + *
+ * + * @param reynoldsNumber a double + * @return a double + */ + public double calcWallFrictionFactor(double reynoldsNumber) { + double relativeRoughnes = getPipeWallRoughness() / insideDiameter; + if (Math.abs(reynoldsNumber) < 2000) { + flowPattern = "laminar"; + return 64.0 / reynoldsNumber; + } else { + flowPattern = "turbulent"; + return Math.pow((1.0 + / (-1.8 * Math.log10(6.9 / reynoldsNumber + Math.pow(relativeRoughnes / 3.7, 1.11)))), + 2.0); } - - /** - *- * Constructor for AdiabaticPipe. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public AdiabaticPipe(StreamInterface inStream) { - this("AdiabaticPipe", inStream); - } - - /** - * Constructor for AdiabaticPipe. - * - * @param name name of pipe - */ - public AdiabaticPipe(String name) { - super(name); - } - - /** - * Constructor for AdiabaticPipe. - * - * @param name name of pipe - * @param inStream input stream - */ - public AdiabaticPipe(String name, StreamInterface inStream) { - this(name); - this.inStream = inStream; - outStream = (Stream) inStream.clone(); - } - - /** - *
- * Setter for the field pipeSpecification
.
- *
- * setOutTemperature. - *
- * - * @param temperature a double - */ - public void setOutTemperature(double temperature) { - setTemperature = true; - this.temperatureOut = temperature; - } - - /** - *- * setOutPressure. - *
- * - * @param pressure a double - */ - public void setOutPressure(double pressure) { - setPressureOut = true; - this.pressureOut = pressure; + } + + /** + *+ * calcPressureOut. + *
+ * + * @return a double + */ + public double calcPressureOut() { + double area = Math.PI / 4.0 * Math.pow(insideDiameter, 2.0); + velocity = system.getPhase(0).getTotalVolume() / area / 1.0e5; + double reynoldsNumber = velocity * insideDiameter + / system.getPhase(0).getPhysicalProperties().getKinematicViscosity(); + double frictionFactor = calcWallFrictionFactor(reynoldsNumber); + double dp = Math + .pow(4.0 * system.getPhase(0).getNumberOfMolesInPhase() * system.getPhase(0).getMolarMass() + / neqsim.thermo.ThermodynamicConstantsInterface.pi, 2.0) + * frictionFactor * length * system.getPhase(0).getZ() + * neqsim.thermo.ThermodynamicConstantsInterface.R / system.getPhase(0).getMolarMass() + * system.getTemperature() / Math.pow(insideDiameter, 5.0); + // \\System.out.println("friction fact" + frictionFactor + " velocity " + + // velocity + " reynolds number " + reynoldsNumber); + System.out.println("dp gravity " + + system.getDensity("kg/m3") * neqsim.thermo.ThermodynamicConstantsInterface.gravity + * (inletElevation - outletElevation) / 1.0e5); + double dp_gravity = + system.getDensity("kg/m3") * neqsim.thermo.ThermodynamicConstantsInterface.gravity + * (inletElevation - outletElevation); + return Math.sqrt(Math.pow(inletPressure * 1e5, 2.0) - dp) / 1.0e5 + dp_gravity / 1.0e5; + } + + /** + *+ * calcFlow. + *
+ * + * @return a double + */ + public double calcFlow() { + double averagePressue = (inletPressure + pressureOut) / 2.0; + system.setPressure(averagePressue); + system.init(1); + system.initPhysicalProperties(); + + double area = Math.PI / 4.0 * Math.pow(insideDiameter, 2.0); + double presdrop2 = Math.pow(inletPressure * 1e2, 2.0) - Math.pow(pressureOut * 1e2, 2.0); + double gasGravity = system.getMolarMass() / 0.028; + double oldReynold = 0; + double reynoldsNumber = -1000.0; + double flow = 0; + do { + oldReynold = reynoldsNumber; + velocity = system.getPhase(0).getTotalVolume() / area / 1.0e5; + reynoldsNumber = velocity * insideDiameter + / system.getPhase(0).getPhysicalProperties().getKinematicViscosity(); + double frictionFactor = calcWallFrictionFactor(reynoldsNumber) * 4.0; + double temp = Math.sqrt(presdrop2 * Math.pow(insideDiameter * 1000.0, 5.0) + / (gasGravity * system.getPhase(0).getZ() * system.getTemperature() * frictionFactor + * length / 1000.0)); + flow = 1.1494e-3 * 288.15 / (system.getPressure() * 100) * temp; + system.setTotalFlowRate(flow / 1e6, "MSm^3/day"); + system.init(1); + // System.out.println("flow " + flow + " velocity " + velocity); + } while (Math.abs(reynoldsNumber - oldReynold) / reynoldsNumber > 1e-3); + return flow; + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + system = inStream.getThermoSystem().clone(); + inletPressure = system.getPressure(); + // system.setMultiPhaseCheck(true); + if (setTemperature) { + system.setTemperature(this.temperatureOut); } - /** - *- * calcWallFrictionFactor. - *
- * - * @param reynoldsNumber a double - * @return a double - */ - public double calcWallFrictionFactor(double reynoldsNumber) { - double relativeRoughnes = getPipeWallRoughness() / insideDiameter; - if (Math.abs(reynoldsNumber) < 2000) { - flowPattern = "laminar"; - return 64.0 / reynoldsNumber; - } else { - flowPattern = "turbulent"; - return Math.pow( - (1.0 / (-1.8 * Math - .log10(6.9 / reynoldsNumber + Math.pow(relativeRoughnes / 3.7, 1.11)))), - 2.0); - } - } - - /** - *- * calcPressureOut. - *
- * - * @return a double - */ - public double calcPressureOut() { - double area = Math.PI / 4.0 * Math.pow(insideDiameter, 2.0); - velocity = system.getPhase(0).getTotalVolume() / area / 1.0e5; - double reynoldsNumber = velocity * insideDiameter - / system.getPhase(0).getPhysicalProperties().getKinematicViscosity(); - double frictionFactor = calcWallFrictionFactor(reynoldsNumber); - double dp = Math - .pow(4.0 * system.getPhase(0).getNumberOfMolesInPhase() - * system.getPhase(0).getMolarMass() - / neqsim.thermo.ThermodynamicConstantsInterface.pi, 2.0) - * frictionFactor * length * system.getPhase(0).getZ() - * neqsim.thermo.ThermodynamicConstantsInterface.R - / system.getPhase(0).getMolarMass() * system.getTemperature() - / Math.pow(insideDiameter, 5.0); - // \\System.out.println("friction fact" + frictionFactor + " velocity " + - // velocity + " reynolds number " + reynoldsNumber); - System.out.println("dp gravity " - + system.getDensity("kg/m3") * neqsim.thermo.ThermodynamicConstantsInterface.gravity - * (inletElevation - outletElevation) / 1.0e5); - double dp_gravity = - system.getDensity("kg/m3") * neqsim.thermo.ThermodynamicConstantsInterface.gravity - * (inletElevation - outletElevation); - return Math.sqrt(Math.pow(inletPressure * 1e5, 2.0) - dp) / 1.0e5 + dp_gravity / 1.0e5; - } - - /** - *- * calcFlow. - *
- * - * @return a double - */ - public double calcFlow() { - double averagePressue = (inletPressure + pressureOut) / 2.0; - system.setPressure(averagePressue); - system.init(1); + double oldPressure = 0.0; + int iter = 0; + if (!setPressureOut) { + do { + iter++; + oldPressure = system.getPressure(); + system.init(3); system.initPhysicalProperties(); - - double area = Math.PI / 4.0 * Math.pow(insideDiameter, 2.0); - double presdrop2 = Math.pow(inletPressure * 1e2, 2.0) - Math.pow(pressureOut * 1e2, 2.0); - double gasGravity = system.getMolarMass() / 0.028; - double oldReynold = 0; - double reynoldsNumber = -1000.0; - double flow = 0; - do { - oldReynold = reynoldsNumber; - velocity = system.getPhase(0).getTotalVolume() / area / 1.0e5; - reynoldsNumber = velocity * insideDiameter - / system.getPhase(0).getPhysicalProperties().getKinematicViscosity(); - double frictionFactor = calcWallFrictionFactor(reynoldsNumber) * 4.0; - double temp = Math.sqrt(presdrop2 * Math.pow(insideDiameter * 1000.0, 5.0) - / (gasGravity * system.getPhase(0).getZ() * system.getTemperature() - * frictionFactor * length / 1000.0)); - flow = 1.1494e-3 * 288.15 / (system.getPressure() * 100) * temp; - system.setTotalFlowRate(flow / 1e6, "MSm^3/day"); - system.init(1); - // System.out.println("flow " + flow + " velocity " + velocity); - } while (Math.abs(reynoldsNumber - oldReynold) / reynoldsNumber > 1e-3); - return flow; - } - - /** {@inheritDoc} */ - @Override - public void run() { - system = inStream.getThermoSystem().clone(); - inletPressure = system.getPressure(); - // system.setMultiPhaseCheck(true); - if (setTemperature) { - system.setTemperature(this.temperatureOut); - } - - double oldPressure = 0.0; - int iter = 0; - if (!setPressureOut) { - do { - iter++; - oldPressure = system.getPressure(); - system.init(3); - system.initPhysicalProperties(); - system.setPressure(calcPressureOut()); - } while (Math.abs(system.getPressure() - oldPressure) > 1e-2 && iter < 25); - } else { - calcFlow(); - system.setPressure(pressureOut); - system.init(3); - } - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - if (setPressureOut) { - inStream.getThermoSystem().setTotalFlowRate(system.getFlowRate("kg/sec"), "kg/sec"); - } - // system.setMultiPhaseCheck(false); - outStream.setThermoSystem(system); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - system.display(); - } - - /** {@inheritDoc} */ - @Override - public FlowSystemInterface getPipe() { - return null; + system.setPressure(calcPressureOut()); + } while (Math.abs(system.getPressure() - oldPressure) > 1e-2 && iter < 25); + } else { + calcFlow(); + system.setPressure(pressureOut); + system.init(3); } - - /** {@inheritDoc} */ - @Override - public void setInitialFlowPattern(String flowPattern) {} - - /** - *
- * Getter for the field length
.
- *
- * Setter for the field length
.
- *
- * getDiameter. - *
- * - * @return the diameter - */ - public double getDiameter() { - return insideDiameter; - } - - /** - *- * setDiameter. - *
- * - * @param diameter the diameter to set - */ - public void setDiameter(double diameter) { - this.insideDiameter = diameter; - } - - /** - *
- * Getter for the field pipeWallRoughness
.
- *
- * Setter for the field pipeWallRoughness
.
- *
- * Getter for the field inletElevation
.
- *
- * Setter for the field inletElevation
.
- *
- * Getter for the field outletElevation
.
- *
- * Setter for the field outletElevation
.
- *
- * main. - *
- * - * @param name an array of {@link java.lang.String} objects - */ - public static void main(String[] name) { - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos((273.15 + 5.0), 220.00); - testSystem.addComponent("methane", 24.0, "MSm^3/day"); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - testSystem.init(0); - - Stream stream_1 = new Stream("Stream1", testSystem); - - AdiabaticPipe pipe = new AdiabaticPipe(stream_1); - pipe.setLength(700000.0); - pipe.setDiameter(0.7112); - pipe.setPipeWallRoughness(5e-6); - pipe.setOutPressure(112.0); - - neqsim.processSimulation.processSystem.ProcessSystem operations = - new neqsim.processSimulation.processSystem.ProcessSystem(); - operations.add(stream_1); - operations.add(pipe); - operations.run(); - pipe.displayResult(); + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + testOps.TPflash(); + if (setPressureOut) { + inStream.getThermoSystem().setTotalFlowRate(system.getFlowRate("kg/sec"), "kg/sec"); } + // system.setMultiPhaseCheck(false); + outStream.setThermoSystem(system); + outStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + system.display(); + } + + /** {@inheritDoc} */ + @Override + public FlowSystemInterface getPipe() { + return null; + } + + /** {@inheritDoc} */ + @Override + public void setInitialFlowPattern(String flowPattern) {} + + /** + *
+ * Getter for the field length
.
+ *
+ * Setter for the field length
.
+ *
+ * getDiameter. + *
+ * + * @return the diameter + */ + public double getDiameter() { + return insideDiameter; + } + + /** + *+ * setDiameter. + *
+ * + * @param diameter the diameter to set + */ + public void setDiameter(double diameter) { + this.insideDiameter = diameter; + } + + /** + *
+ * Getter for the field pipeWallRoughness
.
+ *
+ * Setter for the field pipeWallRoughness
.
+ *
+ * Getter for the field inletElevation
.
+ *
+ * Setter for the field inletElevation
.
+ *
+ * Getter for the field outletElevation
.
+ *
+ * Setter for the field outletElevation
.
+ *
+ * main. + *
+ * + * @param name an array of {@link java.lang.String} objects + */ + public static void main(String[] name) { + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 + 5.0), 220.00); + testSystem.addComponent("methane", 24.0, "MSm^3/day"); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + testSystem.init(0); + + Stream stream_1 = new Stream("Stream1", testSystem); + + AdiabaticPipe pipe = new AdiabaticPipe(stream_1); + pipe.setLength(700000.0); + pipe.setDiameter(0.7112); + pipe.setPipeWallRoughness(5e-6); + pipe.setOutPressure(112.0); + + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + operations.add(stream_1); + operations.add(pipe); + operations.run(); + pipe.displayResult(); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/AdiabaticTwoPhasePipe.java b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/AdiabaticTwoPhasePipe.java index 92353a409a..0a136025ae 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/AdiabaticTwoPhasePipe.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/AdiabaticTwoPhasePipe.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.pipeline; +import java.util.UUID; import neqsim.fluidMechanics.flowSystem.FlowSystemInterface; import neqsim.processSimulation.processEquipment.stream.Stream; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -15,480 +16,488 @@ * @version $Id: $Id */ public class AdiabaticTwoPhasePipe extends Pipeline { - private static final long serialVersionUID = 1000; - - double inletPressure = 0; - boolean setTemperature = false, setPressureOut = false; - protected double temperatureOut = 270, pressureOut = 0.0; - - private double pressureOutLimit = 0.0; - double length = 100.0, flowLimit = 1e20; - String maxflowunit = "kg/hr"; - double insideDiameter = 0.1; - double velocity = 1.0; - double pipeWallRoughness = 1e-5; - private double inletElevation = 0; - private double outletElevation = 0; - double dH = 0.0; - String flowPattern = "unknown"; - String pipeSpecification = "AP02"; - - /** - *- * Constructor for AdiabaticTwoPhasePipe. - *
- */ - @Deprecated - public AdiabaticTwoPhasePipe() { + private static final long serialVersionUID = 1000; + + double inletPressure = 0; + boolean setTemperature = false; + + boolean setPressureOut = false; + + protected double temperatureOut = 270; + + protected double pressureOut = 0.0; + + private double pressureOutLimit = 0.0; + double length = 100.0; + + double flowLimit = 1e20; + + String maxflowunit = "kg/hr"; + double insideDiameter = 0.1; + double velocity = 1.0; + double pipeWallRoughness = 1e-5; + private double inletElevation = 0; + private double outletElevation = 0; + double dH = 0.0; + String flowPattern = "unknown"; + String pipeSpecification = "AP02"; + + /** + *+ * Constructor for AdiabaticTwoPhasePipe. + *
+ */ + @Deprecated + public AdiabaticTwoPhasePipe() {} + + /** + *+ * Constructor for AdiabaticTwoPhasePipe. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public AdiabaticTwoPhasePipe(StreamInterface inStream) { + this("AdiabaticTwoPhasePipe", inStream); + } + + /** + * Constructor for AdiabaticTwoPhasePipe. + * + * @param name name of pipe + */ + public AdiabaticTwoPhasePipe(String name) { + super(name); + } + + /** + * Constructor for AdiabaticTwoPhasePipe. + * + * @param name name of pipe + * @param inStream input stream + */ + public AdiabaticTwoPhasePipe(String name, StreamInterface inStream) { + super(name, inStream); + } + + /** + *
+ * Setter for the field pipeSpecification
.
+ *
+ * setOutTemperature. + *
+ * + * @param temperature a double + */ + public void setOutTemperature(double temperature) { + setTemperature = true; + this.temperatureOut = temperature; + } + + /** + *+ * setOutPressure. + *
+ * + * @param pressure a double + */ + public void setOutPressure(double pressure) { + setPressureOut = true; + this.pressureOut = pressure; + } + + /** + *+ * calcWallFrictionFactor. + *
+ * + * @param reynoldsNumber a double + * @return a double + */ + public double calcWallFrictionFactor(double reynoldsNumber) { + double relativeRoughnes = getPipeWallRoughness() / insideDiameter; + if (Math.abs(reynoldsNumber) < 2000) { + flowPattern = "laminar"; + return 64.0 / reynoldsNumber; + } else { + flowPattern = "turbulent"; + return Math.pow((1.0 + / (-1.8 * Math.log10(6.9 / reynoldsNumber + Math.pow(relativeRoughnes / 3.7, 1.11)))), + 2.0); } - - /** - *- * Constructor for AdiabaticTwoPhasePipe. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public AdiabaticTwoPhasePipe(StreamInterface inStream) { - this("AdiabaticTwoPhasePipe", inStream); - } - - /** - * Constructor for AdiabaticTwoPhasePipe. - * - * @param name name of pipe - */ - public AdiabaticTwoPhasePipe(String name) { - super(name); - } - - /** - * Constructor for AdiabaticTwoPhasePipe. - * - * @param name name of pipe - * @param inStream input stream - */ - public AdiabaticTwoPhasePipe(String name, StreamInterface inStream) { - super(name, inStream); - } - - /** - *
- * Setter for the field pipeSpecification
.
- *
- * setOutTemperature. - *
- * - * @param temperature a double - */ - public void setOutTemperature(double temperature) { - setTemperature = true; - this.temperatureOut = temperature; - } - - /** - *- * setOutPressure. - *
- * - * @param pressure a double - */ - public void setOutPressure(double pressure) { - setPressureOut = true; - this.pressureOut = pressure; - } - - /** - *- * calcWallFrictionFactor. - *
- * - * @param reynoldsNumber a double - * @return a double - */ - public double calcWallFrictionFactor(double reynoldsNumber) { - double relativeRoughnes = getPipeWallRoughness() / insideDiameter; - if (Math.abs(reynoldsNumber) < 2000) { - flowPattern = "laminar"; - return 64.0 / reynoldsNumber; - } else { - flowPattern = "turbulent"; - return Math.pow( - (1.0 / (-1.8 * Math - .log10(6.9 / reynoldsNumber + Math.pow(relativeRoughnes / 3.7, 1.11)))), - 2.0); - } + } + + /** + *+ * calcPressureOut. + *
+ * + * @return a double + */ + public double calcPressureOut() { + double area = Math.PI / 4.0 * Math.pow(insideDiameter, 2.0); + velocity = system.getFlowRate("m3/sec") / area; + double reynoldsNumber = velocity * insideDiameter / system.getKinematicViscosity("m2/sec"); + double frictionFactor = calcWallFrictionFactor(reynoldsNumber); + double dp = 2.0 * frictionFactor * length * Math.pow(system.getFlowRate("kg/sec"), 2.0) + / insideDiameter / system.getDensity("kg/m3");// * () * + // neqsim.thermo.ThermodynamicConstantsInterface.R + // / system.getMolarMass() * system.getTemperature() / Math.pow(insideDiameter, + // 5.0); + // \\System.out.println("friction fact" + frictionFactor + " velocity " + + // velocity + " reynolds number " + reynoldsNumber); + // System.out.println("dp gravity " + + // system.getDensity("kg/m3")*neqsim.thermo.ThermodynamicConstantsInterface.gravity*(inletElevation-outletElevation)/1.0e5); + double dp_gravity = + system.getDensity("kg/m3") * neqsim.thermo.ThermodynamicConstantsInterface.gravity + * (inletElevation - outletElevation); + return (inletPressure * 1e5 - dp) / 1.0e5 + dp_gravity / 1.0e5; + } + + /** + *+ * calcFlow. + *
+ * + * @param pressureOut a double + * @return a double + */ + public double calcFlow(double pressureOut) { + double averagePressue = (pressureOut + pressureOut) / 2.0; + system.setPressure(averagePressue); + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + testOps.TPflash(); + system.initProperties(); + + double area = Math.PI / 4.0 * Math.pow(insideDiameter, 2.0); + double presdrop2 = Math.pow(inletPressure * 1e2, 2.0) - Math.pow(pressureOut * 1e2, 2.0); + double gasGravity = system.getMolarMass() / 0.028; + double oldReynold = 0; + double reynoldsNumber = -1000.0; + double flow = 0; + do { + oldReynold = reynoldsNumber; + velocity = system.getVolume("m3") / area; + reynoldsNumber = velocity * insideDiameter / system.getKinematicViscosity(); + double frictionFactor = calcWallFrictionFactor(reynoldsNumber) * 4.0; + double temp = Math.sqrt(presdrop2 * Math.pow(insideDiameter * 1000.0, 5.0) / (gasGravity + * system.getZ() * system.getTemperature() * frictionFactor * length / 1000.0)); + flow = 1.1494e-3 * 288.15 / (system.getPressure() * 100) * temp; + system.setTotalFlowRate(flow / 1e6, "MSm^3/day"); + testOps.TPflash(); + system.initProperties(); + // System.out.println("flow " + flow + " velocity " + velocity); + } while (Math.abs(reynoldsNumber - oldReynold) / reynoldsNumber > 1e-3); + return flow; + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + system = inStream.getThermoSystem().clone(); + inletPressure = system.getPressure(); + // system.setMultiPhaseCheck(true); + if (setTemperature) { + system.setTemperature(this.temperatureOut); } - /** - *- * calcPressureOut. - *
- * - * @return a double - */ - public double calcPressureOut() { - double area = Math.PI / 4.0 * Math.pow(insideDiameter, 2.0); - velocity = system.getFlowRate("m3/sec") / area; - double reynoldsNumber = velocity * insideDiameter / system.getKinematicViscosity("m2/sec"); - double frictionFactor = calcWallFrictionFactor(reynoldsNumber); - double dp = 2.0 * frictionFactor * length * Math.pow(system.getFlowRate("kg/sec"), 2.0) - / insideDiameter / system.getDensity("kg/m3");// * () * - // neqsim.thermo.ThermodynamicConstantsInterface.R - // / system.getMolarMass() * system.getTemperature() / Math.pow(insideDiameter, - // 5.0); - // \\System.out.println("friction fact" + frictionFactor + " velocity " + - // velocity + " reynolds number " + reynoldsNumber); - // System.out.println("dp gravity " + - // system.getDensity("kg/m3")*neqsim.thermo.ThermodynamicConstantsInterface.gravity*(inletElevation-outletElevation)/1.0e5); - double dp_gravity = - system.getDensity("kg/m3") * neqsim.thermo.ThermodynamicConstantsInterface.gravity - * (inletElevation - outletElevation); - return (inletPressure * 1e5 - dp) / 1.0e5 + dp_gravity / 1.0e5; - } + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + testOps.TPflash(); - /** - *- * calcFlow. - *
- * - * @param pressureOut a double - * @return a double - */ - public double calcFlow(double pressureOut) { - double averagePressue = (pressureOut + pressureOut) / 2.0; - system.setPressure(averagePressue); - ThermodynamicOperations testOps = new ThermodynamicOperations(system); + double oldPressure = 0.0; + int iter = 0; + if (!setPressureOut) { + if (system.getFlowRate(maxflowunit) > flowLimit) { + system.setTotalFlowRate(flowLimit, maxflowunit); + testOps = new ThermodynamicOperations(system); testOps.TPflash(); + } + do { + iter++; + oldPressure = system.getPressure(); system.initProperties(); - - double area = Math.PI / 4.0 * Math.pow(insideDiameter, 2.0); - double presdrop2 = Math.pow(inletPressure * 1e2, 2.0) - Math.pow(pressureOut * 1e2, 2.0); - double gasGravity = system.getMolarMass() / 0.028; - double oldReynold = 0; - double reynoldsNumber = -1000.0; - double flow = 0; - do { - oldReynold = reynoldsNumber; - velocity = system.getVolume("m3") / area; - reynoldsNumber = velocity * insideDiameter / system.getKinematicViscosity(); - double frictionFactor = calcWallFrictionFactor(reynoldsNumber) * 4.0; - double temp = Math.sqrt(presdrop2 * Math.pow(insideDiameter * 1000.0, 5.0) / (gasGravity - * system.getZ() * system.getTemperature() * frictionFactor * length / 1000.0)); - flow = 1.1494e-3 * 288.15 / (system.getPressure() * 100) * temp; - system.setTotalFlowRate(flow / 1e6, "MSm^3/day"); - testOps.TPflash(); - system.initProperties(); - // System.out.println("flow " + flow + " velocity " + velocity); - } while (Math.abs(reynoldsNumber - oldReynold) / reynoldsNumber > 1e-3); - return flow; - } - - /** {@inheritDoc} */ - @Override - public void run() { - system = inStream.getThermoSystem().clone(); - inletPressure = system.getPressure(); - // system.setMultiPhaseCheck(true); - if (setTemperature) { - system.setTemperature(this.temperatureOut); - } - - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - - double oldPressure = 0.0; - int iter = 0; - if (!setPressureOut) { - if (system.getFlowRate(maxflowunit) > flowLimit) { - system.setTotalFlowRate(flowLimit, maxflowunit); - testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - } - do { - iter++; - oldPressure = system.getPressure(); - system.initProperties(); - double outP = calcPressureOut(); - if (outP < 1e-10 || Double.isNaN(outP)) - break; - system.setPressure(outP); - testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - } while (Math.abs(system.getPressure() - oldPressure) > 1e-2 && iter < 25); - if (system.getPressure() < pressureOutLimit) { - iter = 0; - double outP = system.getPressure(); - do { - iter++; - oldPressure = system.getNumberOfMoles(); - system.setTotalNumberOfMoles( - system.getNumberOfMoles() * outP / pressureOutLimit); - - // System.out.println("new moles " + - // system.getNumberOfMoles() + " outP "+ outP); - // outP = calcPressureOut(); - // System.out.println("out P " + outP + " oldP " + oldPressure); - testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - system.initProperties(); - - outP = calcPressureOut(); - system.setPressure(outP); - - if (outP < 1e-10 || Double.isNaN(outP)) - break; - } while (Math.abs(system.getNumberOfMoles() - oldPressure) / oldPressure > 1e-3 - && iter < 3); - // calcFlow(pressureOutLimit); - // System.out.println("new moles " + - // system.getNumberOfMoles()*system.getPressure()/pressureOutLimit); - // System.out.println("flow " + system.getFlowRate(maxflowunit)); - } - if (system.getFlowRate(maxflowunit) > flowLimit) { - system.setTotalFlowRate(flowLimit, maxflowunit); - system.init(1); - } - inStream.getThermoSystem().setTotalFlowRate(system.getFlowRate(maxflowunit), - maxflowunit); - inStream.run(); - } else { - calcFlow(pressureOut); - inStream.getThermoSystem().setTotalFlowRate(system.getFlowRate("kg/sec"), "kg/sec"); - system.setPressure(pressureOut); - system.init(3); - if (system.getFlowRate(maxflowunit) > flowLimit) { - system.setTotalFlowRate(flowLimit, maxflowunit); - inStream.getThermoSystem().setTotalFlowRate(flowLimit, maxflowunit); - iter = 0; - do { - iter++; - oldPressure = system.getPressure(); - system.init(3); - system.initPhysicalProperties(); - system.setPressure(calcPressureOut()); - testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - } while (Math.abs(system.getPressure() - oldPressure) > 1e-2 && iter < 25); - } + double outP = calcPressureOut(); + if (outP < 1e-10 || Double.isNaN(outP)) { + break; } + system.setPressure(outP); testOps = new ThermodynamicOperations(system); testOps.TPflash(); - System.out.println("flow rate " + system.getFlowRate(maxflowunit)); - // system.setMultiPhaseCheck(false); - outStream.setThermoSystem(system); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - system.display(); - } - - /** {@inheritDoc} */ - @Override - public FlowSystemInterface getPipe() { - return null; - } - - /** {@inheritDoc} */ - @Override - public void setInitialFlowPattern(String flowPattern) {} - - /** - *
- * Getter for the field length
.
- *
- * Setter for the field length
.
- *
- * getDiameter. - *
- * - * @return the diameter - */ - public double getDiameter() { - return insideDiameter; - } - - /** - *- * setDiameter. - *
- * - * @param diameter the diameter to set - */ - public void setDiameter(double diameter) { - this.insideDiameter = diameter; - } - - /** - *
- * Getter for the field pipeWallRoughness
.
- *
- * Setter for the field pipeWallRoughness
.
- *
- * Getter for the field inletElevation
.
- *
- * Setter for the field inletElevation
.
- *
- * Getter for the field outletElevation
.
- *
- * Setter for the field outletElevation
.
- *
- * main. - *
- * - * @param name an array of {@link java.lang.String} objects - */ - public static void main(String[] name) { - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos((273.15 + 5.0), 100.00); - testSystem.addComponent("methane", 10.0, "MSm^3/day"); - testSystem.addComponent("n-heptane", 5.0, "MSm^3/day"); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - testSystem.init(0); - - Stream stream_1 = new Stream("Stream1", testSystem); - - AdiabaticTwoPhasePipe pipe = new AdiabaticTwoPhasePipe(stream_1); - pipe.setLength(100000.0); - pipe.setDiameter(0.5017112); - pipe.setPipeWallRoughness(10e-6); - // pipe.setOutPressure(112.0); - - neqsim.processSimulation.processSystem.ProcessSystem operations = - new neqsim.processSimulation.processSystem.ProcessSystem(); - operations.add(stream_1); - operations.add(pipe); - operations.run(); - pipe.displayResult(); - System.out.println("flow " + pipe.getOutletStream().getFluid().getFlowRate("MSm3/day")); - } - - /** - *
- * Getter for the field pressureOutLimit
.
- *
- * Setter for the field pressureOutLimit
.
- *
- * Setter for the field flowLimit
.
- *
+ * Getter for the field length
.
+ *
+ * Setter for the field length
.
+ *
+ * getDiameter. + *
+ * + * @return the diameter + */ + public double getDiameter() { + return insideDiameter; + } + + /** + *+ * setDiameter. + *
+ * + * @param diameter the diameter to set + */ + public void setDiameter(double diameter) { + this.insideDiameter = diameter; + } + + /** + *
+ * Getter for the field pipeWallRoughness
.
+ *
+ * Setter for the field pipeWallRoughness
.
+ *
+ * Getter for the field inletElevation
.
+ *
+ * Setter for the field inletElevation
.
+ *
+ * Getter for the field outletElevation
.
+ *
+ * Setter for the field outletElevation
.
+ *
+ * main. + *
+ * + * @param name an array of {@link java.lang.String} objects + */ + public static void main(String[] name) { + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 + 5.0), 100.00); + testSystem.addComponent("methane", 10.0, "MSm^3/day"); + testSystem.addComponent("n-heptane", 5.0, "MSm^3/day"); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + testSystem.init(0); + + Stream stream_1 = new Stream("Stream1", testSystem); + + AdiabaticTwoPhasePipe pipe = new AdiabaticTwoPhasePipe(stream_1); + pipe.setLength(100000.0); + pipe.setDiameter(0.5017112); + pipe.setPipeWallRoughness(10e-6); + // pipe.setOutPressure(112.0); + + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + operations.add(stream_1); + operations.add(pipe); + operations.run(); + pipe.displayResult(); + System.out.println("flow " + pipe.getOutletStream().getFluid().getFlowRate("MSm3/day")); + } + + /** + *
+ * Getter for the field pressureOutLimit
.
+ *
+ * Setter for the field pressureOutLimit
.
+ *
+ * Setter for the field flowLimit
.
+ *
- * Constructor for IncompressiblePipeFlow. - *
- */ - @Deprecated - public IncompressiblePipeFlow() { - super("IncompressiblePipeFlow"); + private static final long serialVersionUID = 1000; + + Fittings fittings = new Fittings(); + private double totalEqLenth = 0; + double momentum = 0; + + /** + *+ * Constructor for IncompressiblePipeFlow. + *
+ */ + @Deprecated + public IncompressiblePipeFlow() { + super("IncompressiblePipeFlow"); + } + + /** + *+ * Constructor for IncompressiblePipeFlow. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public IncompressiblePipeFlow(StreamInterface inStream) { + this("IncompressiblePipeFlow", inStream); + } + + /** + * Constructor for IncompressiblePipeFlow. + * + * @param name name of pipeline + */ + public IncompressiblePipeFlow(String name) { + super(name); + } + + /** + * * Constructor for IncompressiblePipeFlow. + * + * @param name name of pipe + * @param inStream input stream + */ + public IncompressiblePipeFlow(String name, StreamInterface inStream) { + super(name, inStream); + } + + /** + *+ * addFittingFromDatabase. + *
+ * + * @param name a {@link java.lang.String} object + */ + public void addFittingFromDatabase(String name) { + fittings.add(name); + } + + /** + *+ * addFitting. + *
+ * + * @param name a {@link java.lang.String} object + * @param LdivD a double + */ + public void addFitting(String name, double LdivD) { + fittings.add(name, LdivD); + } + + /** {@inheritDoc} */ + @Override + public double calcPressureOut() { + setTotalEqLenth(length); + + for (int i = 0; i < fittings.fittingList.size(); i++) { + setTotalEqLenth(getTotalEqLenth() + fittings.getFittingsList().get(i).getLtoD()); } - /** - *- * Constructor for IncompressiblePipeFlow. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public IncompressiblePipeFlow(StreamInterface inStream) { - this("IncompressiblePipeFlow", inStream); - } - - /** - * Constructor for IncompressiblePipeFlow. - * - * @param name name of pipeline - */ - public IncompressiblePipeFlow(String name) { - super(name); - } - - /** - * * Constructor for IncompressiblePipeFlow. - * - * @param name name of pipe - * @param inStream input stream - */ - public IncompressiblePipeFlow(String name, StreamInterface inStream) { - super(name, inStream); - } - - /** - *- * addFittingFromDatabase. - *
- * - * @param name a {@link java.lang.String} object - */ - public void addFittingFromDatabase(String name) { - fittings.add(name); - } - - /** - *- * addFitting. - *
- * - * @param name a {@link java.lang.String} object - * @param LdivD a double - */ - public void addFitting(String name, double LdivD) { - fittings.add(name, LdivD); - } - - /** {@inheritDoc} */ - @Override - public double calcPressureOut() { - setTotalEqLenth(length); - - for (int i = 0; i < fittings.fittingList.size(); i++) { - setTotalEqLenth(getTotalEqLenth() + fittings.getFittingsList().get(i).getLtoD()); - } - - double area = 3.14 / 4.0 * Math.pow(insideDiameter, 2.0); - double velocity = 1.0 / system.getPhase(0).getPhysicalProperties().getDensity() - / (system.getPhase(0).getNumberOfMolesInPhase() - * (system.getPhase(0).getMolarVolume() / 1e5)) - / area; - - momentum = system.getPhase(0).getPhysicalProperties().getDensity() * velocity * velocity; - double reynoldsNumber = velocity * insideDiameter - / system.getPhase(0).getPhysicalProperties().getKinematicViscosity(); - double frictionFactor = calcWallFrictionFactor(reynoldsNumber); - - double dp = -momentum * frictionFactor * getTotalEqLenth() / (2.0 * insideDiameter); - dp += (getInletElevation() - getOutletElevation()) - * system.getPhase(0).getPhysicalProperties().getDensity() - * neqsim.thermo.ThermodynamicConstantsInterface.gravity; - - // double dp = Math.pow(4.0 * system.getPhase(0).getNumberOfMolesInPhase() * - // system.getPhase(0).getMolarMass()/thermo.ThermodynamicConstantsInterface.pi, - // 2.0) * frictionFactor * length * system.getPhase(0).getZ() * - // thermo.ThermodynamicConstantsInterface.R/system.getPhase(0).getMolarMass() * - // system.getTemperature() / Math.pow(insideDiameter, 5.0); - System.out.println("outpres " + ((system.getPressure() * 1e5 + dp) / 1.0e5) + " dp " + dp - + " friction fact" + frictionFactor + " velocity " + velocity + " reynolds number " - + reynoldsNumber + " equivalentLength " + getTotalEqLenth()); - - return (system.getPressure() * 1e5 + dp) / 1.0e5; - } - - /** {@inheritDoc} */ - @Override - public void run() { - system = inStream.getThermoSystem().clone(); - // system.setMultiPhaseCheck(true); - if (setTemperature) { - system.setTemperature(this.temperatureOut); - } - system.init(3); - system.initPhysicalProperties(); - calcPressureOut(); - system.setPressure(calcPressureOut()); - - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - // system.setMultiPhaseCheck(false); - outStream.setThermoSystem(system); - } - - /** - *- * main. - *
- * - * @param name an array of {@link java.lang.String} objects - */ - public static void main(String[] name) { - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); - testSystem.addComponent("water", 100.0 * 1e3, "kg/hr"); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - testSystem.initPhysicalProperties(); - Stream stream_1 = new Stream("Stream1", testSystem); - - IncompressiblePipeFlow pipe = new IncompressiblePipeFlow(stream_1); - pipe.setLength(1000.0); - pipe.setDiameter(0.25); - pipe.setPipeWallRoughness(2e-5); - pipe.addFittingFromDatabase("Standard elbow (R=1.5D), 90deg"); - - IncompressiblePipeFlow pipe2 = new IncompressiblePipeFlow(pipe.getOutletStream()); - pipe2.setLength(1000.0); - pipe2.setDiameter(0.25); - pipe2.setPipeWallRoughness(2e-5); - pipe2.setInletElevation(10); - pipe2.setOutletElevation(0); - - neqsim.processSimulation.processSystem.ProcessSystem operations = - new neqsim.processSimulation.processSystem.ProcessSystem(); - operations.add(stream_1); - operations.add(pipe); - operations.add(pipe2); - operations.run(); - pipe.displayResult(); - } - - /** - *
- * Getter for the field totalEqLenth
.
- *
- * Setter for the field totalEqLenth
.
- *
+ * main. + *
+ * + * @param name an array of {@link java.lang.String} objects + */ + public static void main(String[] name) { + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem.addComponent("water", 100.0 * 1e3, "kg/hr"); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + testSystem.initPhysicalProperties(); + Stream stream_1 = new Stream("Stream1", testSystem); + + IncompressiblePipeFlow pipe = new IncompressiblePipeFlow(stream_1); + pipe.setLength(1000.0); + pipe.setDiameter(0.25); + pipe.setPipeWallRoughness(2e-5); + pipe.addFittingFromDatabase("Standard elbow (R=1.5D), 90deg"); + + IncompressiblePipeFlow pipe2 = new IncompressiblePipeFlow(pipe.getOutletStream()); + pipe2.setLength(1000.0); + pipe2.setDiameter(0.25); + pipe2.setPipeWallRoughness(2e-5); + pipe2.setInletElevation(10); + pipe2.setOutletElevation(0); + + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + operations.add(stream_1); + operations.add(pipe); + operations.add(pipe2); + operations.run(); + pipe.displayResult(); + } + + /** + *
+ * Getter for the field totalEqLenth
.
+ *
+ * Setter for the field totalEqLenth
.
+ *
- * Constructor for SimpleTPoutPipeline. - *
- */ - @Deprecated - public SimpleTPoutPipeline() {} + /** + *+ * Constructor for SimpleTPoutPipeline. + *
+ */ + @Deprecated + public SimpleTPoutPipeline() {} - /** - *- * Constructor for SimpleTPoutPipeline. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public SimpleTPoutPipeline(StreamInterface inStream) { - this("SimpleTPoutPipeline", inStream); - } + /** + *+ * Constructor for SimpleTPoutPipeline. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public SimpleTPoutPipeline(StreamInterface inStream) { + this("SimpleTPoutPipeline", inStream); + } - /** - * Constructor for SimpleTPoutPipeline. - * - * @param name name of pipeline - */ - public SimpleTPoutPipeline(String name) { - super(name); - } + /** + * Constructor for SimpleTPoutPipeline. + * + * @param name name of pipeline + */ + public SimpleTPoutPipeline(String name) { + super(name); + } - /** - * Constructor for SimpleTPoutPipeline. - * - * @param name name of pipeline - * @param inStream the inlet stream - */ - public SimpleTPoutPipeline(String name, StreamInterface inStream) { - super(name, inStream); - } + /** + * Constructor for SimpleTPoutPipeline. + * + * @param name name of pipeline + * @param inStream the inlet stream + */ + public SimpleTPoutPipeline(String name, StreamInterface inStream) { + super(name, inStream); + } - /** - *- * setOutTemperature. - *
- * - * @param temperature a double - */ - public void setOutTemperature(double temperature) { - this.temperatureOut = temperature; - } + /** + *+ * setOutTemperature. + *
+ * + * @param temperature a double + */ + public void setOutTemperature(double temperature) { + this.temperatureOut = temperature; + } - /** - *- * setOutPressure. - *
- * - * @param pressure a double - */ - public void setOutPressure(double pressure) { - this.pressureOut = pressure; - } + /** + *+ * setOutPressure. + *
+ * + * @param pressure a double + */ + public void setOutPressure(double pressure) { + this.pressureOut = pressure; + } - /** {@inheritDoc} */ - @Override - public void run() { - system = inStream.getThermoSystem().clone(); - // system.setMultiPhaseCheck(true); - system.setTemperature(this.temperatureOut); - system.setPressure(this.pressureOut); - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - testOps.TPflash(); - // system.setMultiPhaseCheck(false); - outStream.setThermoSystem(system); - } + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + system = inStream.getThermoSystem().clone(); + // system.setMultiPhaseCheck(true); + system.setTemperature(this.temperatureOut); + system.setPressure(this.pressureOut); + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + testOps.TPflash(); + // system.setMultiPhaseCheck(false); + outStream.setThermoSystem(system); + setCalculationIdentifier(id); + } - /** {@inheritDoc} */ - @Override - public void displayResult() { - outStream.getThermoSystem().display(name); - outStream.getThermoSystem().initPhysicalProperties(); - System.out.println("Superficial velocity out gas : " + getSuperficialVelocity(0, 1)); - System.out.println("Superficial velocity out condensate : " + getSuperficialVelocity(1, 1)); - System.out.println("Superficial velocity out MEG/water : " + getSuperficialVelocity(2, 1)); - } + /** {@inheritDoc} */ + @Override + public void displayResult() { + outStream.getThermoSystem().display(name); + outStream.getThermoSystem().initPhysicalProperties(); + System.out.println("Superficial velocity out gas : " + getSuperficialVelocity(0, 1)); + System.out.println("Superficial velocity out condensate : " + getSuperficialVelocity(1, 1)); + System.out.println("Superficial velocity out MEG/water : " + getSuperficialVelocity(2, 1)); + } - /** {@inheritDoc} */ - @Override - public FlowSystemInterface getPipe() { - return null; - } + /** {@inheritDoc} */ + @Override + public FlowSystemInterface getPipe() { + return null; + } - /** {@inheritDoc} */ - @Override - public void setInitialFlowPattern(String flowPattern) {} + /** {@inheritDoc} */ + @Override + public void setInitialFlowPattern(String flowPattern) {} } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/TwoPhasePipeLine.java b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/TwoPhasePipeLine.java index e5baf3cc26..d3653d2356 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/pipeline/TwoPhasePipeLine.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/pipeline/TwoPhasePipeLine.java @@ -5,6 +5,7 @@ */ package neqsim.processSimulation.processEquipment.pipeline; +import java.util.UUID; import neqsim.fluidMechanics.flowSystem.twoPhaseFlowSystem.twoPhasePipeFlowSystem.TwoPhasePipeFlowSystem; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -72,9 +73,12 @@ public void createSystem() {} /** {@inheritDoc} */ @Override - public void run() { - super.run(); - pipe.solveSteadyState(2); + public void run(UUID id) { + UUID oldid = getCalculationIdentifier(); + super.run(id); + setCalculationIdentifier(oldid); + pipe.solveSteadyState(2, id); + setCalculationIdentifier(id); pipe.print(); } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/powerGeneration/GasTurbine.java b/src/main/java/neqsim/processSimulation/processEquipment/powerGeneration/GasTurbine.java index 6990602866..f9fa1ee59f 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/powerGeneration/GasTurbine.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/powerGeneration/GasTurbine.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.powerGeneration; +import java.util.UUID; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import neqsim.processSimulation.mechanicalDesign.compressor.CompressorMechanicalDesign; @@ -128,30 +129,31 @@ public void setInletStream(StreamInterface inletStream) { /** {@inheritDoc} */ @Override - public void run() { - double heatOfCombustion = inStream.LCV() * inStream.getFlowRate("mole/sec"); + public void run(UUID id) { thermoSystem = inStream.getThermoSystem().clone(); airStream.setFlowRate(thermoSystem.getFlowRate("mole/sec") * airGasRatio, "mole/sec"); airStream.setPressure(1.01325); - airStream.run(); + airStream.run(id); airCompressor.setInletStream(airStream); airCompressor.setOutletPressure(combustionpressure); - airCompressor.run(); + airCompressor.run(id); compressorPower = airCompressor.getPower(); StreamInterface outStreamAir = airCompressor.getOutletStream().clone(); outStreamAir.getFluid().addFluid(thermoSystem); // outStreamAir.getFluid().setTemperature(800.0); // outStreamAir.getFluid().createDatabase(true); - double moleMethane = outStreamAir.getFluid().getComponent("methane").getNumberOfmoles(); - // double moleEthane = outStreamAir.getFluid().getComponent("ethane").getNumberOfmoles(); - // double molePropane = outStreamAir.getFluid().getComponent("propane").getNumberOfmoles(); - outStreamAir.run(); + outStreamAir.run(id); + + double heatOfCombustion = inStream.LCV() * inStream.getFlowRate("mole/sec"); Heater locHeater = new Heater("locHeater", outStreamAir); locHeater.setEnergyInput(heatOfCombustion); - locHeater.run(); + locHeater.run(id); + double moleMethane = outStreamAir.getFluid().getComponent("methane").getNumberOfmoles(); + // double moleEthane = outStreamAir.getFluid().getComponent("ethane").getNumberOfmoles(); + // double molePropane = outStreamAir.getFluid().getComponent("propane").getNumberOfmoles(); locHeater.getOutletStream().getFluid().addComponent("CO2", moleMethane); locHeater.getOutletStream().getFluid().addComponent("water", moleMethane * 2.0); locHeater.getOutletStream().getFluid().addComponent("methane", -moleMethane); @@ -159,20 +161,21 @@ public void run() { // todo: Init fails because there is less than moleMethane of oxygen locHeater.getOutletStream().getFluid().init(3); - // locHeater.getOutStream().run(); + // locHeater.getOutStream().run(id); locHeater.displayResult(); Expander expander = new Expander("expander", locHeater.getOutletStream()); expander.setOutletPressure(1.01325); - expander.run(); + expander.run(id); Cooler cooler1 = new Cooler("cooler1", expander.getOutletStream()); cooler1.setOutTemperature(288.15); - cooler1.run(); + cooler1.run(id); expanderPower = expander.getPower(); power = expanderPower - compressorPower; this.heat = cooler1.getDuty(); + setCalculationIdentifier(id); } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/pump/Pump.java b/src/main/java/neqsim/processSimulation/processEquipment/pump/Pump.java index ddf23756ec..75eb44f744 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/pump/Pump.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/pump/Pump.java @@ -4,6 +4,7 @@ import java.awt.FlowLayout; import java.text.DecimalFormat; import java.text.FieldPosition; +import java.util.UUID; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JScrollPane; @@ -153,7 +154,7 @@ public void calculateAsCompressor(boolean setPumpCalcType) { /** {@inheritDoc} */ @Override - public void run() { + public void run(UUID id) { // System.out.println("pump running.."); inStream.getThermoSystem().init(3); double hinn = inStream.getThermoSystem().getEnthalpy(); @@ -217,8 +218,10 @@ public void run() { // thermoOps.PSflash(entropy); dH = thermoSystem.getEnthalpy() - hinn; outStream.setThermoSystem(thermoSystem); + outStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); - // outStream.run(); + // outStream.run(id); } /** {@inheritDoc} */ @@ -376,10 +379,11 @@ public void setIsentropicEfficiency(double isentropicEfficiency) { * @return a double */ public double getOutTemperature() { - if (useOutTemperature) + if (useOutTemperature) { return outTemperature; - else + } else { return getThermoSystem().getTemperature(); + } } /** diff --git a/src/main/java/neqsim/processSimulation/processEquipment/reservoir/SimpleReservoir.java b/src/main/java/neqsim/processSimulation/processEquipment/reservoir/SimpleReservoir.java index 5d3127f2df..f455db05c4 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/reservoir/SimpleReservoir.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/reservoir/SimpleReservoir.java @@ -6,6 +6,7 @@ package neqsim.processSimulation.processEquipment.reservoir; import java.util.ArrayList; +import java.util.UUID; import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass; import neqsim.processSimulation.processEquipment.pipeline.AdiabaticTwoPhasePipe; import neqsim.processSimulation.processEquipment.stream.Stream; @@ -22,746 +23,751 @@ * @version $Id: $Id */ public class SimpleReservoir extends ProcessEquipmentBaseClass { - private static final long serialVersionUID = 1000; - - SystemInterface thermoSystem; - - double oilVolume = 0.0, gasVolume = 0.0, waterVolume = 0.0; - ArrayList- * Constructor for SimpleReservoir. - *
- */ - @Deprecated - public SimpleReservoir() { - this("SimpleReservoir"); + private static final long serialVersionUID = 1000; + + SystemInterface thermoSystem; + + double oilVolume = 0.0; + double gasVolume = 0.0; + double waterVolume = 0.0; + + ArrayList+ * Constructor for SimpleReservoir. + *
+ */ + @Deprecated + public SimpleReservoir() { + this("SimpleReservoir"); + } + + /** + *+ * Constructor for SimpleReservoir. + *
+ * + * @param name a {@link java.lang.String} object + */ + public SimpleReservoir(String name) { + super(name); + } + + /** + *+ * getReservoirFluid. + *
+ * + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface getReservoirFluid() { + return thermoSystem; + } + + /* + * public StreamInterface getGasOutStream() { return gasOutStream; } + * + * + * + * public StreamInterface getOilOutStream() { return oilOutStream; } + */ + + /** + *+ * addGasProducer. + *
+ * + * @param name a {@link java.lang.String} object + * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + public StreamInterface addGasProducer(String name) { + Well newWell = new Well(name); + gasProducer.add(newWell); + StreamInterface gasOutStream = new Stream("gasOutStream"); + gasOutStream.setFluid(thermoSystem.phaseToSystem("gas")); + gasOutStream.getFluid().setTotalFlowRate(1.0e-1, "kg/sec"); + newWell.setStream(gasOutStream); + return newWell.getStream(); + } + + /** + *+ * addOilProducer. + *
+ * + * @param name a {@link java.lang.String} object + * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + public StreamInterface addOilProducer(String name) { + Well newWell = new Well(name); + oilProducer.add(newWell); + StreamInterface oilOutStream = new Stream("oilOutStream"); + oilOutStream.setFluid(thermoSystem.phaseToSystem("oil")); + oilOutStream.getFluid().setTotalFlowRate(1.0e-1, "kg/sec"); + newWell.setStream(oilOutStream); + return newWell.getStream(); + } + + /** + *+ * addWaterInjector. + *
+ * + * @param name a {@link java.lang.String} object + * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + public StreamInterface addWaterInjector(String name) { + Well newWell = new Well(name); + waterInjector.add(newWell); + StreamInterface waterInStream = new Stream("waterInStream"); + waterInStream.setFluid(thermoSystem.phaseToSystem("aqueous")); + // waterInStream.init(0); + waterInStream.getFluid().setTotalFlowRate(1.0e-1, "kg/sec"); + newWell.setStream(waterInStream); + return newWell.getStream(); + } + + /** + *+ * addGasInjector. + *
+ * + * @param name a {@link java.lang.String} object + * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + public StreamInterface addGasInjector(String name) { + Well newWell = new Well(name); + gasInjector.add(newWell); + StreamInterface gasInStream = new Stream("gasInStream"); + gasInStream.setFluid(thermoSystem.phaseToSystem("gas")); + gasInStream.getFluid().setTotalFlowRate(1.0e-1, "kg/sec"); + newWell.setStream(gasInStream); + return newWell.getStream(); + } + + /** + *+ * getGasInPlace. + *
+ * + * @param unit a {@link java.lang.String} object + * @return a double + */ + public double getGasInPlace(String unit) { + SystemInterface locStream = (thermoSystem).clone(); + locStream.setTemperature(288.15); + locStream.setPressure(1.01325); + ThermodynamicOperations ops = new ThermodynamicOperations(locStream); + ops.TPflash(); + locStream.initProperties(); + double volume = Double.NaN; + if (locStream.hasPhaseType("gas")) { + volume = locStream.getPhase("gas").getVolume("m3"); } - - /** - *- * Constructor for SimpleReservoir. - *
- * - * @param name a {@link java.lang.String} object - */ - public SimpleReservoir(String name) { - super(name); + if (unit.equals("GSm3")) { + return volume / 1.0e9; } - - /** - *- * getReservoirFluid. - *
- * - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface getReservoirFluid() { - return thermoSystem; + return volume; + } + + /** + *+ * getOilInPlace. + *
+ * + * @param unit a {@link java.lang.String} object + * @return a double + */ + public double getOilInPlace(String unit) { + SystemInterface locStream = (thermoSystem).clone(); + locStream.setTemperature(288.15); + locStream.setPressure(1.01325); + ThermodynamicOperations ops = new ThermodynamicOperations(locStream); + ops.TPflash(); + locStream.initProperties(); + double volume = Double.NaN; + if (locStream.hasPhaseType("oil")) { + volume = locStream.getPhase("oil").getVolume("m3"); } - - /* - * public StreamInterface getGasOutStream() { return gasOutStream; } - * - * - * - * public StreamInterface getOilOutStream() { return oilOutStream; } - */ - - /** - *- * addGasProducer. - *
- * - * @param name a {@link java.lang.String} object - * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object - */ - public StreamInterface addGasProducer(String name) { - Well newWell = new Well(name); - gasProducer.add(newWell); - StreamInterface gasOutStream = new Stream("gasOutStream"); - gasOutStream.setFluid(thermoSystem.phaseToSystem("gas")); - gasOutStream.getFluid().setTotalFlowRate(1.0e-1, "kg/sec"); - newWell.setStream(gasOutStream); - return newWell.getStream(); - } - - /** - *- * addOilProducer. - *
- * - * @param name a {@link java.lang.String} object - * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object - */ - public StreamInterface addOilProducer(String name) { - Well newWell = new Well(name); - oilProducer.add(newWell); - StreamInterface oilOutStream = new Stream("oilOutStream"); - oilOutStream.setFluid(thermoSystem.phaseToSystem("oil")); - oilOutStream.getFluid().setTotalFlowRate(1.0e-1, "kg/sec"); - newWell.setStream(oilOutStream); - return newWell.getStream(); - } - - /** - *- * addWaterInjector. - *
- * - * @param name a {@link java.lang.String} object - * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object - */ - public StreamInterface addWaterInjector(String name) { - Well newWell = new Well(name); - waterInjector.add(newWell); - StreamInterface waterInStream = new Stream("waterInStream"); - waterInStream.setFluid(thermoSystem.phaseToSystem("aqueous")); - // waterInStream.init(0); - waterInStream.getFluid().setTotalFlowRate(1.0e-1, "kg/sec"); - newWell.setStream(waterInStream); - return newWell.getStream(); - } - - /** - *- * addGasInjector. - *
- * - * @param name a {@link java.lang.String} object - * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object - */ - public StreamInterface addGasInjector(String name) { - Well newWell = new Well(name); - gasInjector.add(newWell); - StreamInterface gasInStream = new Stream("gasInStream"); - gasInStream.setFluid(thermoSystem.phaseToSystem("gas")); - gasInStream.getFluid().setTotalFlowRate(1.0e-1, "kg/sec"); - newWell.setStream(gasInStream); - return newWell.getStream(); - } - - /** - *- * getGasInPlace. - *
- * - * @param unit a {@link java.lang.String} object - * @return a double - */ - public double getGasInPlace(String unit) { - SystemInterface locStream = (thermoSystem).clone(); - locStream.setTemperature(288.15); - locStream.setPressure(1.01325); - ThermodynamicOperations ops = new ThermodynamicOperations(locStream); - ops.TPflash(); - locStream.initProperties(); - double volume = Double.NaN; - if (locStream.hasPhaseType("gas")) { - volume = locStream.getPhase("gas").getVolume("m3"); - } - if (unit.equals("GSm3")) { - return volume / 1.0e9; - } - return volume; + if (unit.equals("MSm3")) { + return volume / 1.0e6; } - - /** - *- * getOilInPlace. - *
- * - * @param unit a {@link java.lang.String} object - * @return a double - */ - public double getOilInPlace(String unit) { - SystemInterface locStream = (thermoSystem).clone(); - locStream.setTemperature(288.15); - locStream.setPressure(1.01325); - ThermodynamicOperations ops = new ThermodynamicOperations(locStream); - ops.TPflash(); - locStream.initProperties(); - double volume = Double.NaN; - if (locStream.hasPhaseType("oil")) { - volume = locStream.getPhase("oil").getVolume("m3"); - } - if (unit.equals("MSm3")) { - return volume / 1.0e6; + return volume; + } + + /** + *
+ * Getter for the field gasProducer
.
+ *
+ * Getter for the field oilProducer
.
+ *
+ * Getter for the field oilProducer
.
+ *
+ * Getter for the field waterInjector
.
+ *
+ * Getter for the field gasInjector
.
+ *
+ * setReservoirFluid. + *
+ * + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + * @param gasVolume a double + * @param oilVolume a double + * @param waterVolume a double + */ + public void setReservoirFluid(SystemInterface thermoSystem, double gasVolume, double oilVolume, + double waterVolume) { + this.thermoSystem = thermoSystem; + this.oilVolume = oilVolume; + this.gasVolume = gasVolume; + this.waterVolume = waterVolume; + ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem); + ops.TPflash(); + + // thermoSystem.display(); + SystemInterface thermoSystem2 = thermoSystem.clone(); + + thermoSystem.setEmptyFluid(); // (1.0e-10); + // thermoSystem.init(1); + // thermoSystem.display(); + // System.out.println("number of phases " + thermoSystem.getNumberOfPhases()); + // double totalliquidVolume = 0.0; + for (int j = 0; j < thermoSystem.getNumberOfPhases(); j++) { + double relFact = gasVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5); + if (j >= 1) { + if (j == 1) { + relFact = oilVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5); + // totalliquidVolume += oilVolume / thermoSystem2.getPhase(j).getMolarVolume(); + } else if (j == 2) { + relFact = waterVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5); + // totalliquidVolume += waterVolume / + // thermoSystem2.getPhase(j).getMolarVolume(); } - return volume; + } + for (int i = 0; i < thermoSystem.getPhase(j).getNumberOfComponents(); i++) { + thermoSystem.addComponent(thermoSystem.getPhase(j).getComponent(i).getComponentNumber(), + relFact * thermoSystem2.getPhase(j).getComponent(i).getNumberOfMolesInPhase(), j); + } } - - /** - *
- * Getter for the field gasProducer
.
- *
- * Getter for the field oilProducer
.
- *
- * Getter for the field waterInjector
.
- *
+ * GORprodution. + *
+ * + * @return a double + */ + public double GORprodution() { + double GOR = 0.0; + double flow = 0.0; + for (int i = 0; i < gasProducer.size(); i++) { + flow += gasProducer.get(i).getStream().getFluid().getNumberOfMoles(); + GOR += gasProducer.get(i).getGOR() + * gasProducer.get(i).getStream().getFluid().getNumberOfMoles(); + } + for (int i = 0; i < oilProducer.size(); i++) { + flow += oilProducer.get(i).getStream().getFluid().getNumberOfMoles(); + GOR += oilProducer.get(i).getGOR() + * oilProducer.get(i).getStream().getFluid().getNumberOfMoles(); + } + return GOR / flow; + } + + /** + *+ * getGasProdution. + *
+ * + * @param unit a {@link java.lang.String} object + * @return a double + */ + public double getGasProdution(String unit) { + double volume = 0.0; + for (int i = 0; i < gasProducer.size(); i++) { + volume += gasProducer.get(i).getStdGasProduction(); + } + for (int i = 0; i < oilProducer.size(); i++) { + volume += oilProducer.get(i).getStdGasProduction(); + } + if (unit.equals("Sm3/sec")) { + } else if (unit.equals("Sm3/day")) { + volume = volume * 60.0 * 60 * 24; + } + return volume; + } + + /** + *+ * getOilProdution. + *
+ * + * @param unit a {@link java.lang.String} object + * @return a double + */ + public double getOilProdution(String unit) { + double volume = 0.0; + for (int i = 0; i < gasProducer.size(); i++) { + volume += gasProducer.get(i).getStdOilProduction(); + } + for (int i = 0; i < oilProducer.size(); i++) { + volume += oilProducer.get(i).getStdOilProduction(); + } + if (unit.equals("Sm3/sec")) { + } else if (unit.equals("Sm3/day")) { + volume = volume * 60.0 * 60 * 24; } + return volume; + } + + /** {@inheritDoc} */ + @Override + public void runTransient(double dt, UUID id) { + increaseTime(dt); + if (thermoSystem.getPressure("bara") < lowPressureLimit) { + System.out.println("low pressure reservoir limit reached"); + setCalculationIdentifier(id); + return; + } + gasProductionTotal += getGasProdution("Sm3/sec") * dt; + oilProductionTotal += getOilProdution("Sm3/sec") * dt; + thermoSystem.init(0); + for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) { + // thermoSystem.addComponent(i, -10000000000.001); + for (int k = 0; k < gasProducer.size(); k++) { + thermoSystem.addComponent(i, + -gasProducer.get(k).getStream().getFluid().getComponent(i).getNumberOfmoles() * dt); + } + + for (int k = 0; k < oilProducer.size(); k++) { + thermoSystem.addComponent(i, + -oilProducer.get(k).getStream().getFluid().getComponent(i).getNumberOfmoles() * dt); + } + + for (int k = 0; k < waterInjector.size(); k++) { + thermoSystem.addComponent(i, + waterInjector.get(k).getStream().getFluid().getComponent(i).getNumberOfmoles() * dt); + } + for (int k = 0; k < gasInjector.size(); k++) { + thermoSystem.addComponent(i, + gasInjector.get(k).getStream().getFluid().getComponent(i).getNumberOfmoles() * dt); + } + } + + ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem); + ops.TVflash(reservoirVolume, "m3"); + thermoSystem.initProperties(); - /** - *
- * Getter for the field gasInjector
.
- *
- * Getter for the field oilProducer
.
- *
- * setReservoirFluid. - *
- * - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - * @param gasVolume a double - * @param oilVolume a double - * @param waterVolume a double + for (int k = 0; k < waterInjector.size(); k++) { + waterInjector.get(k).getStream().run(id); + } + for (int k = 0; k < gasInjector.size(); k++) { + gasInjector.get(k).getStream().run(id); + } + /* + * double totalVolume = 0; for (int i = 0; i < getReservoirFluid().getNumberOfPhases(); i++) { + * totalVolume += getReservoirFluid().getPhase(i).getVolume("m3"); } + * System.out.println("tot volume " + totalVolume/1.0e6 + " gas volume "+ */ - public void setReservoirFluid(SystemInterface thermoSystem, double gasVolume, double oilVolume, - double waterVolume) { - this.thermoSystem = thermoSystem; - this.oilVolume = oilVolume; - this.gasVolume = gasVolume; - this.waterVolume = waterVolume; - ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem); - ops.TPflash(); - - // thermoSystem.display(); - SystemInterface thermoSystem2 = thermoSystem.clone(); - - thermoSystem.setEmptyFluid();// (1.0e-10); - // thermoSystem.init(1); - // thermoSystem.display(); - // System.out.println("number of phases " + thermoSystem.getNumberOfPhases()); - // double totalliquidVolume = 0.0; - for (int j = 0; j < thermoSystem.getNumberOfPhases(); j++) { - double relFact = gasVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5); - if (j >= 1) { - if (j == 1) { - relFact = oilVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5); - // totalliquidVolume += oilVolume / thermoSystem2.getPhase(j).getMolarVolume(); - } else if (j == 2) { - relFact = waterVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5); - // totalliquidVolume += waterVolume / - // thermoSystem2.getPhase(j).getMolarVolume(); - } - } - for (int i = 0; i < thermoSystem.getPhase(j).getNumberOfComponents(); i++) { - thermoSystem.addComponent( - thermoSystem.getPhase(j).getComponent(i).getComponentNumber(), - relFact * thermoSystem2.getPhase(j).getComponent(i) - .getNumberOfMolesInPhase(), - j); - } - } - /* - * if (thermoSystem.hasPhaseType("gas")) { thermoSystem.setBeta(gasVolume / - * thermoSystem2.getPhase(0).getMolarVolume() / (gasVolume / - * thermoSystem2.getPhase(0).getMolarVolume() + oilVolume / - * thermoSystem2.getPhase(1).getMolarVolume())); } - */ - ThermodynamicOperations ops2 = new ThermodynamicOperations(thermoSystem); - ops2.TPflash(); - thermoSystem.initProperties(); - // thermoSystem.display(); - // gasOutStream = new Stream(); - // gasOutStream.setFluid(thermoSystem.phaseToSystem("gas")); - reservoirVolume = gasVolume + oilVolume + waterVolume; - - OOIP = getOilInPlace("Sm3"); - OGIP = getGasInPlace("Sm3"); - // oilOutStream = new Stream(); - // oilOutStream.setFluid(thermoSystem.phaseToSystem("oil")); - - lowPressureLimit = 50.0; - } - - /** {@inheritDoc} */ - @Override - public void run() { - System.out.println("gas volume " + thermoSystem.getPhase("gas").getVolume("m3")); - System.out.println("oil volume " + thermoSystem.getPhase("oil").getVolume("m3")); - System.out.println("water volume " + thermoSystem.getPhase("aqueous").getVolume("m3")); - - for (int i = 0; i < gasProducer.size(); i++) { - gasProducer.get(i).getStream().run(); - } - for (int i = 0; i < oilProducer.size(); i++) { - oilProducer.get(i).getStream().run(); - } - for (int i = 0; i < waterInjector.size(); i++) { - waterInjector.get(i).getStream().run(); - } - for (int i = 0; i < gasInjector.size(); i++) { - gasInjector.get(i).getStream().run(); - } - // gasOutStream.setFluid(thermoSystem.phaseToSystem("gas")); - // gasOutStream.run(); - } + // getReservoirFluid().getPhase("gas").getVolume("m3")/1.0e6 + " oil volume "+ + // getReservoirFluid().getPhase("oil").getVolume("m3")/1.0e6 + " water volume "+ + // getReservoirFluid().getPhase("aqueous").getVolume("m3")/1.0e6); + // oilOutStream.getFluid().setMolarComposition(thermoSystem.getPhase("oil").getMolarComposition()); + // oilOutStream.run(id); - /** - *- * GORprodution. - *
- * - * @return a double - */ - public double GORprodution() { - double GOR = 0.0; - double flow = 0.0; - for (int i = 0; i < gasProducer.size(); i++) { - flow += gasProducer.get(i).getStream().getFluid().getNumberOfMoles(); - GOR += gasProducer.get(i).getGOR() - * gasProducer.get(i).getStream().getFluid().getNumberOfMoles(); - } - for (int i = 0; i < oilProducer.size(); i++) { - flow += oilProducer.get(i).getStream().getFluid().getNumberOfMoles(); - GOR += oilProducer.get(i).getGOR() - * oilProducer.get(i).getStream().getFluid().getNumberOfMoles(); - } - return GOR / flow; + // thermoSystem.display(); + for (int k = 0; k < gasProducer.size(); k++) { + gasProducer.get(k).getStream().getFluid().setPressure(thermoSystem.getPressure()); } - /** - *- * getGasProdution. - *
- * - * @param unit a {@link java.lang.String} object - * @return a double - */ - public double getGasProdution(String unit) { - double volume = 0.0; - for (int i = 0; i < gasProducer.size(); i++) { - volume += gasProducer.get(i).getStdGasProduction(); - } - for (int i = 0; i < oilProducer.size(); i++) { - volume += oilProducer.get(i).getStdGasProduction(); - } - if (unit.equals("Sm3/sec")) { - } else if (unit.equals("Sm3/day")) { - volume = volume * 60.0 * 60 * 24; - } - return volume; + for (int k = 0; k < oilProducer.size(); k++) { + oilProducer.get(k).getStream().getFluid().setPressure(thermoSystem.getPressure()); } - /** - *- * getOilProdution. - *
- * - * @param unit a {@link java.lang.String} object - * @return a double - */ - public double getOilProdution(String unit) { - double volume = 0.0; - for (int i = 0; i < gasProducer.size(); i++) { - volume += gasProducer.get(i).getStdOilProduction(); - } - for (int i = 0; i < oilProducer.size(); i++) { - volume += oilProducer.get(i).getStdOilProduction(); - } - if (unit.equals("Sm3/sec")) { - } else if (unit.equals("Sm3/day")) { - volume = volume * 60.0 * 60 * 24; - } - return volume; + for (int k = 0; k < waterInjector.size(); k++) { + waterInjector.get(k).getStream().setPressure(thermoSystem.getPressure()); + } + for (int k = 0; k < gasInjector.size(); k++) { + gasInjector.get(k).getStream().setPressure(thermoSystem.getPressure()); + } + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + thermoSystem.display(); + } + + /** + *+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 + 100.0), 200.00); + testSystem.addComponent("nitrogen", 0.100); + testSystem.addComponent("methane", 30.00); + testSystem.addComponent("ethane", 1.0); + testSystem.addComponent("propane", 1.0); + testSystem.addComponent("i-butane", 1.0); + testSystem.addComponent("n-butane", 1.0); + testSystem.addComponent("n-hexane", 0.1); + testSystem.addComponent("n-heptane", 0.1); + testSystem.addComponent("n-nonane", 1.0); + testSystem.addComponent("nC10", 1.0); + testSystem.addComponent("nC12", 3.0); + testSystem.addComponent("nC15", 3.0); + testSystem.addComponent("nC20", 3.0); + testSystem.addComponent("water", 11.0); + testSystem.setMixingRule(2); + testSystem.setMultiPhaseCheck(true); + + SimpleReservoir reservoirOps = new SimpleReservoir("Well 1 reservoir"); + reservoirOps.setReservoirFluid(testSystem, 5.0 * 1e7, 552.0 * 1e6, 10.0e6); + + StreamInterface producedOilStream = reservoirOps.addOilProducer("oilproducer_1"); + StreamInterface injectorGasStream = reservoirOps.addGasInjector("gasproducer_1"); + StreamInterface producedGasStream = reservoirOps.addGasProducer("SLP_A32562G"); + StreamInterface waterInjectorStream = reservoirOps.addWaterInjector("SLP_WI32562O"); + + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + operations.add(reservoirOps); + operations.save("c:/temp/resmode1.neqsim"); + + System.out.println("gas in place (GIP) " + reservoirOps.getGasInPlace("GSm3") + " GSm3"); + System.out.println("oil in place (OIP) " + reservoirOps.getOilInPlace("MSm3") + " MSm3"); + + // StreamInterface producedGasStream = + // reservoirOps.addGasProducer("SLP_A32562G"); + producedGasStream.setFlowRate(0.01, "MSm3/day"); + + // StreamInterface injectorGasStream = + // reservoirOps.addGasInjector("SLP_A32562GI"); + injectorGasStream.setFlowRate(0.01, "MSm3/day"); + // injectorGasStream.getFluid().setMolarComposition(.new double[0.1, 0.1]); + + // StreamInterface producedGasStream2 = + // reservoirOps.addGasProducer("SLP_A32562G2"); + // producedGasStream2.setFlowRate(0.011, "MSm3/hr"); + + producedOilStream.setFlowRate(50000000.0, "kg/day"); + + waterInjectorStream.setFlowRate(12100000.0, "kg/day"); + + // StreamInterface producedGasStream = reservoirOps.getGasOutStream(); + // producedGasStream.setFlowRate(1.0e-3, "MSm3/day"); + + // StreamInterface producedOilStream = reservoirOps.getOilOutStream(); + // producedOilStream.setFlowRate(1500000.0, "kg/hr"); + + reservoirOps.run(); + + reservoirOps.runTransient(60 * 60 * 24 * 3); + for (int i = 0; i < 1; i++) { + reservoirOps.runTransient(60 * 60 * 24 * 15); + System.out.println("water volume" + + reservoirOps.getReservoirFluid().getPhase("aqueous").getVolume("m3") / 1.0e6); + System.out + .println("oil production total" + reservoirOps.getOilProductionTotal("Sm3") + " Sm3"); + System.out + .println("total produced " + reservoirOps.getProductionTotal("MSm3 oe") + " MSm3 oe"); + if (reservoirOps.getFluid().getPressure() < 50.0) { + break; + } } + System.out.println("GOR gas " + reservoirOps.getGasProducer(0).getGOR()); + // System.out.println("GOR oil " + reservoirOps.getOilProducer(0).getGOR()); + System.out.println("GOR production " + reservoirOps.GORprodution()); - /** {@inheritDoc} */ - @Override - public void runTransient(double dt) { - time = getTime() + dt; - if (thermoSystem.getPressure("bara") < lowPressureLimit) { - System.out.println("low pressure reservoir limit reached"); - return; - } - gasProductionTotal += getGasProdution("Sm3/sec") * dt; - oilProductionTotal += getOilProdution("Sm3/sec") * dt; - thermoSystem.init(0); - for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) { - // thermoSystem.addComponent(i, -10000000000.001); - for (int k = 0; k < gasProducer.size(); k++) { - thermoSystem.addComponent(i, -gasProducer.get(k).getStream().getFluid() - .getComponent(i).getNumberOfmoles() * dt); - } - - for (int k = 0; k < oilProducer.size(); k++) { - thermoSystem.addComponent(i, -oilProducer.get(k).getStream().getFluid() - .getComponent(i).getNumberOfmoles() * dt); - } - - for (int k = 0; k < waterInjector.size(); k++) { - thermoSystem.addComponent(i, waterInjector.get(k).getStream().getFluid() - .getComponent(i).getNumberOfmoles() * dt); - } - for (int k = 0; k < gasInjector.size(); k++) { - thermoSystem.addComponent(i, - gasInjector.get(k).getStream().getFluid().getComponent(i).getNumberOfmoles() - * dt); - } - } + // System.out.println("GOR oil " + reservoirOps.getOilProducer(0).getGOR()); - ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem); - ops.TVflash(reservoirVolume, "m3"); - thermoSystem.initProperties(); - - /* - * if (thermoSystem.hasPhaseType("gas")) System.out.println("gas volume " + - * thermoSystem.getPhase("gas").getVolume("m3")); if (thermoSystem.hasPhaseType("oil")) - * System.out.println("oil volume " + thermoSystem.getPhase("oil").getVolume("m3")); if - * (thermoSystem.hasPhaseType("aqueous")) System.out.println("water volume " + - * thermoSystem.getPhase("aqueous").getVolume("m3")); - */ - // System.out.println("pressure " + thermoSystem.getPressure("bara")); - - if (thermoSystem.hasPhaseType("gas")) { - for (int k = 0; k < gasProducer.size(); k++) { - gasProducer.get(k).getStream().getFluid() - .setMolarComposition(thermoSystem.getPhase("gas").getMolarComposition()); - gasProducer.get(k).getStream().run(); - } - } - if (thermoSystem.hasPhaseType("oil")) { - for (int k = 0; k < oilProducer.size(); k++) { - oilProducer.get(k).getStream().getFluid() - .setMolarComposition(thermoSystem.getPhase("oil").getMolarComposition()); - oilProducer.get(k).getStream().run(); - } - } - /* - * if(thermoSystem.hasPhaseType("aqueous")) { for (int k = 0; k < waterInjector.size(); k++) - * { waterInjector.get(k).getStream().getFluid() - * .setMolarComposition(thermoSystem.getPhase("aqueous").getMolarComposition()); - * waterInjector.get(k).getStream().run(); } - */ - for (int k = 0; k < waterInjector.size(); k++) { - waterInjector.get(k).getStream().run(); - } - for (int k = 0; k < gasInjector.size(); k++) { - gasInjector.get(k).getStream().run(); - } - /* - * double totalVolume = 0; for (int i = 0; i < getReservoirFluid().getNumberOfPhases(); i++) - * { totalVolume += getReservoirFluid().getPhase(i).getVolume("m3"); } - * System.out.println("tot volume " + totalVolume/1.0e6 + " gas volume "+ - */ - - // getReservoirFluid().getPhase("gas").getVolume("m3")/1.0e6 + " oil volume "+ - // getReservoirFluid().getPhase("oil").getVolume("m3")/1.0e6 + " water volume "+ - // getReservoirFluid().getPhase("aqueous").getVolume("m3")/1.0e6); - // oilOutStream.getFluid().setMolarComposition(thermoSystem.getPhase("oil").getMolarComposition()); - // oilOutStream.run(); - - // thermoSystem.display(); - for (int k = 0; k < gasProducer.size(); k++) { - gasProducer.get(k).getStream().getFluid().setPressure(thermoSystem.getPressure()); - } + System.out.println("gas production " + reservoirOps.getGasProdution("Sm3/day") + " Sm3/day"); + System.out.println("oil production " + reservoirOps.getOilProdution("Sm3/day") + " Sm3/day"); - for (int k = 0; k < oilProducer.size(); k++) { - oilProducer.get(k).getStream().getFluid().setPressure(thermoSystem.getPressure()); - } + System.out + .println("oil production total" + reservoirOps.getOilProductionTotal("Sm3") + " Sm3"); - for (int k = 0; k < waterInjector.size(); k++) { - waterInjector.get(k).getStream().setPressure(thermoSystem.getPressure()); - } - for (int k = 0; k < gasInjector.size(); k++) { - gasInjector.get(k).getStream().setPressure(thermoSystem.getPressure()); - } - } + // reservoirOps.runTransient(60 * 60 * 24 * 365); + // reservoirOps.runTransient(60 * 60 * 24 * 365); + // reservoirOps.runTransient(60 * 60 * 24 * 365); + System.out + .println("gas production total" + reservoirOps.getGasProductionTotal("GSm3") + " GSm3"); - /** {@inheritDoc} */ - @Override - public void displayResult() { - thermoSystem.display(); - } + System.out + .println("oil production total" + reservoirOps.getOilProductionTotal("MSm3") + " MSm3"); + System.out.println("gas in place (GIP) " + reservoirOps.getGasInPlace("GSm3") + " GSm3"); + System.out.println("oil in place (OIP) " + reservoirOps.getOilInPlace("MSm3") + " MSm3"); + System.out.println("original oil in place (OOIP) " + reservoirOps.getOOIP("MSm3") + " MSm3"); + System.out.println("original gas in place (OGIP) " + reservoirOps.getOGIP("GSm3") + " GSm3"); - /** - *- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos((273.15 + 100.0), 200.00); - testSystem.addComponent("nitrogen", 0.100); - testSystem.addComponent("methane", 30.00); - testSystem.addComponent("ethane", 1.0); - testSystem.addComponent("propane", 1.0); - testSystem.addComponent("i-butane", 1.0); - testSystem.addComponent("n-butane", 1.0); - testSystem.addComponent("n-hexane", 0.1); - testSystem.addComponent("n-heptane", 0.1); - testSystem.addComponent("n-nonane", 1.0); - testSystem.addComponent("nC10", 1.0); - testSystem.addComponent("nC12", 3.0); - testSystem.addComponent("nC15", 3.0); - testSystem.addComponent("nC20", 3.0); - testSystem.addComponent("water", 11.0); - testSystem.setMixingRule(2); - testSystem.setMultiPhaseCheck(true); - - SimpleReservoir reservoirOps = new SimpleReservoir("Well 1 reservoir"); - reservoirOps.setReservoirFluid(testSystem, 5.0 * 1e7, 552.0 * 1e6, 10.0e6); - - StreamInterface producedOilStream = reservoirOps.addOilProducer("oilproducer_1"); - StreamInterface injectorGasStream = reservoirOps.addGasInjector("gasproducer_1"); - StreamInterface producedGasStream = reservoirOps.addGasProducer("SLP_A32562G"); - StreamInterface waterInjectorStream = reservoirOps.addWaterInjector("SLP_WI32562O"); - - neqsim.processSimulation.processSystem.ProcessSystem operations = - new neqsim.processSimulation.processSystem.ProcessSystem(); - operations.add(reservoirOps); - operations.save("c:/temp/resmode1.neqsim"); - - System.out.println("gas in place (GIP) " + reservoirOps.getGasInPlace("GSm3") + " GSm3"); - System.out.println("oil in place (OIP) " + reservoirOps.getOilInPlace("MSm3") + " MSm3"); - - // StreamInterface producedGasStream = - // reservoirOps.addGasProducer("SLP_A32562G"); - producedGasStream.setFlowRate(0.01, "MSm3/day"); - - // StreamInterface injectorGasStream = - // reservoirOps.addGasInjector("SLP_A32562GI"); - injectorGasStream.setFlowRate(0.01, "MSm3/day"); - // injectorGasStream.getFluid().setMolarComposition(.new double[0.1, 0.1]); - - // StreamInterface producedGasStream2 = - // reservoirOps.addGasProducer("SLP_A32562G2"); - // producedGasStream2.setFlowRate(0.011, "MSm3/hr"); - - producedOilStream.setFlowRate(50000000.0, "kg/day"); - - waterInjectorStream.setFlowRate(12100000.0, "kg/day"); - - // StreamInterface producedGasStream = reservoirOps.getGasOutStream(); - // producedGasStream.setFlowRate(1.0e-3, "MSm3/day"); - - // StreamInterface producedOilStream = reservoirOps.getOilOutStream(); - // producedOilStream.setFlowRate(1500000.0, "kg/hr"); - - reservoirOps.run(); - - reservoirOps.runTransient(60 * 60 * 24 * 3); - for (int i = 0; i < 1; i++) { - reservoirOps.runTransient(60 * 60 * 24 * 15); - System.out.println("water volume" - + reservoirOps.getReservoirFluid().getPhase("aqueous").getVolume("m3") / 1.0e6); - System.out.println( - "oil production total" + reservoirOps.getOilProductionTotal("Sm3") + " Sm3"); - System.out.println( - "total produced " + reservoirOps.getProductionTotal("MSm3 oe") + " MSm3 oe"); - if (reservoirOps.getFluid().getPressure() < 50.0) - break; - } - System.out.println("GOR gas " + reservoirOps.getGasProducer(0).getGOR()); - // System.out.println("GOR oil " + reservoirOps.getOilProducer(0).getGOR()); - System.out.println("GOR production " + reservoirOps.GORprodution()); - - // System.out.println("GOR oil " + reservoirOps.getOilProducer(0).getGOR()); - - System.out - .println("gas production " + reservoirOps.getGasProdution("Sm3/day") + " Sm3/day"); - System.out - .println("oil production " + reservoirOps.getOilProdution("Sm3/day") + " Sm3/day"); - - System.out.println( - "oil production total" + reservoirOps.getOilProductionTotal("Sm3") + " Sm3"); - - // reservoirOps.runTransient(60 * 60 * 24 * 365); - // reservoirOps.runTransient(60 * 60 * 24 * 365); - // reservoirOps.runTransient(60 * 60 * 24 * 365); - System.out.println( - "gas production total" + reservoirOps.getGasProductionTotal("GSm3") + " GSm3"); - - System.out.println( - "oil production total" + reservoirOps.getOilProductionTotal("MSm3") + " MSm3"); - System.out.println("gas in place (GIP) " + reservoirOps.getGasInPlace("GSm3") + " GSm3"); - System.out.println("oil in place (OIP) " + reservoirOps.getOilInPlace("MSm3") + " MSm3"); - System.out - .println("original oil in place (OOIP) " + reservoirOps.getOOIP("MSm3") + " MSm3"); - System.out - .println("original gas in place (OGIP) " + reservoirOps.getOGIP("GSm3") + " GSm3"); - - // reservoirOps.runTransient(60 * 60 * 24 * 365); - // producedGasStream.setFlowRate(4.0, "MSm3/day"); - // producedOilStream.setFlowRate(1.0, "kg/hr"); - - for (int i = 0; i < 300; i++) { - // reservoirOps.runTransient(60 * 60 * 24 * 365); - } - System.out.println("oil flow " + producedOilStream.getFlowRate("kg/hr")); - - AdiabaticTwoPhasePipe testPipe = new AdiabaticTwoPhasePipe("testPipe", producedOilStream); - testPipe.setLength(3300.0); - testPipe.setInletElevation(0.0); - testPipe.setOutletElevation(2200.0); - testPipe.setDiameter(2.69); - testPipe.setPressureOutLimit(80.0); - testPipe.setFlowLimit(producedOilStream.getFlowRate("kg/hr") * 0.4, "kg/hr"); - testPipe.setOutTemperature(273.15 + 50.0); - testPipe.run(); - System.out.println(" flow limit " + producedOilStream.getFlowRate("kg/hr") * 0.4); - System.out.println("oil flow " + producedOilStream.getFlowRate("kg/hr")); - // testPipe.getOutStream().displayResult(); - - for (int i = 0; i < 60; i++) { - reservoirOps.runTransient(60 * 60 * 24 * 25); - testPipe.run(); - System.out.println("oil flow " + producedOilStream.getFlowRate("kg/hr") + " pressure " - + producedOilStream.getPressure("bara") + " pipe out pres " - + testPipe.getOutletStream().getFluid().getPressure()); - } - } + // reservoirOps.runTransient(60 * 60 * 24 * 365); + // producedGasStream.setFlowRate(4.0, "MSm3/day"); + // producedOilStream.setFlowRate(1.0, "kg/hr"); - /** - *
- * Getter for the field gasProductionTotal
.
- *
- * Getter for the field oilProductionTotal
.
- *
- * getProductionTotal. - *
- * - * @param unit a {@link java.lang.String} object - * @return a double - */ - public double getProductionTotal(String unit) { - double prod = getOilProductionTotal("Sm3") + getGasProductionTotal("Sm3") / 1.0e3; - if (unit.equals("MSm3 oe")) - return prod / 1e6; - return prod; - } - - /** - *- * getOOIP. - *
- * - * @param unit a {@link java.lang.String} object - * @return a double - */ - public double getOOIP(String unit) { - if (unit.equals("MSm3")) - return OOIP / 1.0e6; - return OOIP; - } - - /** - *- * getOGIP. - *
- * - * @param unit a {@link java.lang.String} object - * @return a double - */ - public double getOGIP(String unit) { - if (unit.equals("GSm3")) - return OGIP / 1.0e9; - return OGIP; - } - - /** - *
- * Getter for the field time
.
- *
+ * Getter for the field gasProductionTotal
.
+ *
+ * Getter for the field oilProductionTotal
.
+ *
+ * getProductionTotal. + *
+ * + * @param unit a {@link java.lang.String} object + * @return a double + */ + public double getProductionTotal(String unit) { + double prod = getOilProductionTotal("Sm3") + getGasProductionTotal("Sm3") / 1.0e3; + if (unit.equals("MSm3 oe")) { + return prod / 1e6; + } + return prod; + } + + /** + *+ * getOOIP. + *
+ * + * @param unit a {@link java.lang.String} object + * @return a double + */ + public double getOOIP(String unit) { + if (unit.equals("MSm3")) { + return OOIP / 1.0e6; + } + return OOIP; + } + + /** + *+ * getOGIP. + *
+ * + * @param unit a {@link java.lang.String} object + * @return a double + */ + public double getOGIP(String unit) { + if (unit.equals("GSm3")) { + return OGIP / 1.0e9; } + return OGIP; + } + + /** + *
+ * Getter for the field time
.
+ *
- * Constructor for GasScrubber. - *
- */ - @Deprecated - public GasScrubber() { - this("GasScrubber"); - } - - /** - *- * Constructor for GasScrubber. - *
- * - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - @Deprecated - public GasScrubber(StreamInterface inletStream) { - this("GasScrubber", inletStream); - } - - /** - * Constructor for GasScrubber. - * - * @param name name of gas scrubber - */ - public GasScrubber(String name) { - super(name); - this.setOrientation("vertical"); - } - - /** - *- * Constructor for GasScrubber. - *
- * - * @param name a {@link java.lang.String} object - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - public GasScrubber(String name, StreamInterface inletStream) { - super(name, inletStream); - this.setOrientation("vertical"); - } - - public GasScrubberMechanicalDesign getMechanicalDesign() { - return new GasScrubberMechanicalDesign(this); - } - - /** - *
- * Setter for the field inletStream
.
- *
- * addScrubberSection. - *
- * - * @param type a {@link java.lang.String} object - */ - public void addScrubberSection(String type) { - scrubberSection.add(new SeparatorSection("section" + scrubberSection.size() + 1, type, this)); - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getLiquidOutStream() { - return liquidOutStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGasOutStream() { - return gasOutStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGas() { - return getGasOutStream(); - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getLiquid() { - return getLiquidOutStream(); - } - - /** {@inheritDoc} */ - @Override - public void run() { - thermoSystem = inletStream.getThermoSystem().clone(); - gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]); - gasSystem.setNumberOfPhases(1); - gasOutStream.setThermoSystem(gasSystem); - - thermoSystem = inletStream.getThermoSystem().clone(); - liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]); - liquidSystem.setNumberOfPhases(1); - liquidOutStream.setThermoSystem(liquidSystem); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - } + private static final long serialVersionUID = 1000; + + SystemInterface thermoSystem; + + SystemInterface gasSystem; + + SystemInterface waterSystem; + + SystemInterface liquidSystem; + + SystemInterface thermoSystemCloned; + + ArrayList+ * Constructor for GasScrubber. + *
+ */ + @Deprecated + public GasScrubber() { + this("GasScrubber"); + } + + /** + *+ * Constructor for GasScrubber. + *
+ * + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + @Deprecated + public GasScrubber(StreamInterface inletStream) { + this("GasScrubber", inletStream); + } + + /** + * Constructor for GasScrubber. + * + * @param name name of gas scrubber + */ + public GasScrubber(String name) { + super(name); + this.setOrientation("vertical"); + } + + /** + *+ * Constructor for GasScrubber. + *
+ * + * @param name a {@link java.lang.String} object + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + public GasScrubber(String name, StreamInterface inletStream) { + super(name, inletStream); + this.setOrientation("vertical"); + } + + public GasScrubberMechanicalDesign getMechanicalDesign() { + return new GasScrubberMechanicalDesign(this); + } + + /** + *
+ * Setter for the field inletStream
.
+ *
+ * addScrubberSection. + *
+ * + * @param type a {@link java.lang.String} object + */ + public void addScrubberSection(String type) { + scrubberSection.add(new SeparatorSection("section" + scrubberSection.size() + 1, type, this)); + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getLiquidOutStream() { + return liquidOutStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getGasOutStream() { + return gasOutStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getGas() { + return getGasOutStream(); + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getLiquid() { + return getLiquidOutStream(); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + thermoSystem = inletStream.getThermoSystem().clone(); + gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]); + gasSystem.setNumberOfPhases(1); + gasOutStream.setThermoSystem(gasSystem); + + thermoSystem = inletStream.getThermoSystem().clone(); + liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]); + liquidSystem.setNumberOfPhases(1); + liquidOutStream.setThermoSystem(liquidSystem); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() {} } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/GasScrubberSimple.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/GasScrubberSimple.java index f67e17695b..dfff09ec42 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/GasScrubberSimple.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/GasScrubberSimple.java @@ -5,6 +5,7 @@ */ package neqsim.processSimulation.processEquipment.separator; +import java.util.UUID; import neqsim.processSimulation.mechanicalDesign.separator.GasScrubberMechanicalDesign; import neqsim.processSimulation.processEquipment.stream.Stream; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -20,147 +21,152 @@ * @version $Id: $Id */ public class GasScrubberSimple extends Separator { - private static final long serialVersionUID = 1000; - - SystemInterface gasSystem, waterSystem, liquidSystem, thermoSystemCloned; - StreamInterface inletStream; - StreamInterface gasOutStream; - StreamInterface liquidOutStream; - String name = new String(); - - /** - *- * Constructor for GasScrubberSimple. - *
- */ - @Deprecated - public GasScrubberSimple() { - this("GasScrubberSimple"); + private static final long serialVersionUID = 1000; + + SystemInterface gasSystem; + SystemInterface waterSystem; + SystemInterface liquidSystem; + SystemInterface thermoSystemCloned; + + StreamInterface inletStream; + StreamInterface gasOutStream; + StreamInterface liquidOutStream; + String name = new String(); + + /** + *+ * Constructor for GasScrubberSimple. + *
+ */ + @Deprecated + public GasScrubberSimple() { + this("GasScrubberSimple"); + } + + /** + *+ * Constructor for GasScrubberSimple. + *
+ * + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + @Deprecated + public GasScrubberSimple(StreamInterface inletStream) { + this("GasScrubberSimple", inletStream); + } + + /** + * Constructor for GasScrubberSimple. + * + * @param name name of scrubber + */ + public GasScrubberSimple(String name) { + super(name); + this.setOrientation("vertical"); + } + + /** + *+ * Constructor for GasScrubberSimple. + *
+ * + * @param name a {@link java.lang.String} object + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + */ + public GasScrubberSimple(String name, StreamInterface inletStream) { + super(name, inletStream); + this.setOrientation("vertical"); + } + + public GasScrubberMechanicalDesign getMechanicalDesign() { + return new GasScrubberMechanicalDesign(this); + } + + /** + *
+ * Setter for the field inletStream
.
+ *
- * Constructor for GasScrubberSimple. - *
- * - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - @Deprecated - public GasScrubberSimple(StreamInterface inletStream) { - this("GasScrubberSimple", inletStream); - } - - /** - * Constructor for GasScrubberSimple. - * - * @param name name of scrubber - */ - public GasScrubberSimple(String name) { - super(name); - this.setOrientation("vertical"); - } - - /** - *- * Constructor for GasScrubberSimple. - *
- * - * @param name a {@link java.lang.String} object - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - */ - public GasScrubberSimple(String name, StreamInterface inletStream) { - super(name, inletStream); - this.setOrientation("vertical"); + gasSystem = thermoSystem.phaseToSystem(0); + gasSystem.setNumberOfPhases(1); + gasOutStream.setThermoSystem(gasSystem); + + thermoSystem = inletStream.getThermoSystem().clone(); + if (separatorSection.size() > 0) { + thermoSystem.addGasToLiquid(getGasCarryunderFraction()); + liquidSystem = thermoSystem.phaseToSystem(1); } - - public GasScrubberMechanicalDesign getMechanicalDesign() { - return new GasScrubberMechanicalDesign(this); - } - - /** - *
- * Setter for the field inletStream
.
- *
+ * calcLiquidCarryoverFraction. + *
+ * + * @return a double + */ + public double calcLiquidCarryoverFraction() { + double ktotal = 1.0; + + for (int i = 0; i < separatorSection.size(); i++) { + ktotal *= (1.0 - separatorSection.get(i).getEfficiency()); } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGasOutStream() { - return gasOutStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGas() { - return getGasOutStream(); - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getLiquid() { - return getLiquidOutStream(); - } - - /** {@inheritDoc} */ - @Override - public void run() { - thermoSystem = inletStream.getThermoSystem().clone(); - ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); - thermoOps.TPflash(); - if (separatorSection.size() > 0) { - calcLiquidCarryoverFraction(); - thermoSystem.addLiquidToGas(getLiquidCarryoverFraction()); - } - gasSystem = thermoSystem.phaseToSystem(0); - gasSystem.setNumberOfPhases(1); - gasOutStream.setThermoSystem(gasSystem); - - thermoSystem = inletStream.getThermoSystem().clone(); - if (separatorSection.size() > 0) { - thermoSystem.addGasToLiquid(getGasCarryunderFraction()); - liquidSystem = thermoSystem.phaseToSystem(1); - } - liquidSystem.setNumberOfPhases(1); - liquidOutStream.setThermoSystem(liquidSystem); - } - - /** - *- * calcLiquidCarryoverFraction. - *
- * - * @return a double - */ - public double calcLiquidCarryoverFraction() { - double Ktot = 1.0; - - for (int i = 0; i < separatorSection.size(); i++) { - Ktot *= (1.0 - separatorSection.get(i).getEfficiency()); - } - System.out.println("Ktot " + (1.0 - Ktot)); - double area = getInternalDiameter() * getInternalDiameter() / 4.0 * 3.14; - double gasVel = - thermoSystem.getTotalNumberOfMoles() * thermoSystem.getMolarVolume() / 1e5 / area; - setLiquidCarryoverFraction(Ktot); - return gasVel; - } + System.out.println("Ktot " + (1.0 - ktotal)); + double area = getInternalDiameter() * getInternalDiameter() / 4.0 * 3.14; + double gasVel = + thermoSystem.getTotalNumberOfMoles() * thermoSystem.getMolarVolume() / 1e5 / area; + setLiquidCarryoverFraction(ktotal); + return gasVel; + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/Hydrocyclone.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/Hydrocyclone.java index efa4d92bc9..54fefd2e04 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/Hydrocyclone.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/Hydrocyclone.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.separator; +import java.util.UUID; import neqsim.processSimulation.processEquipment.stream.Stream; import neqsim.processSimulation.processEquipment.stream.StreamInterface; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -38,9 +39,8 @@ public Hydrocyclone() { * Constructor for Hydrocyclone. * * - * @param inletStream a - * {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object */ @Deprecated public Hydrocyclone(StreamInterface inletStream) { @@ -61,10 +61,9 @@ public Hydrocyclone(String name) { * Constructor for Hydrocyclone. * * - * @param name a {@link java.lang.String} object - * @param inletStream a - * {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object + * @param name a {@link java.lang.String} object + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object */ public Hydrocyclone(String name, StreamInterface inletStream) { super(name, inletStream); @@ -85,9 +84,7 @@ public void setInletStream(StreamInterface inletStream) { * Getter for the fieldwaterOutStream
.
*
*
- * @return a
- * {@link neqsim.processSimulation.processEquipment.stream.StreamInterface}
- * object
+ * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object
*/
public StreamInterface getWaterOutStream() {
return waterOutStream;
@@ -98,9 +95,7 @@ public StreamInterface getWaterOutStream() {
* getOilOutStream.
*
*
- * @return a
- * {@link neqsim.processSimulation.processEquipment.stream.StreamInterface}
- * object
+ * @return a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object
*/
public StreamInterface getOilOutStream() {
return liquidOutStream;
@@ -108,8 +103,8 @@ public StreamInterface getOilOutStream() {
/** {@inheritDoc} */
@Override
- public void run() {
- inletStreamMixer.run();
+ public void run(UUID id) {
+ inletStreamMixer.run(id);
thermoSystem = inletStreamMixer.getOutletStream().getThermoSystem().clone();
// double oilInWaterIn = 0.0001; //
@@ -137,7 +132,6 @@ public void run() {
} else {
gasOutStream.setThermoSystem(thermoSystem.getEmptySystemClone());
}
- // //gasOutStream.run();
//// liquidSystem = thermoSystem.phaseToSystem(1);
//// liquidOutStream.setThermoSystem(liquidSystem);
@@ -148,8 +142,9 @@ public void run() {
liquidOutStream.setThermoSystem(thermoSystem.getEmptySystemClone());
}
// sOutStream.setPressure(overflowPressure, "bara");
- gasOutStream.run();
- liquidOutStream.run();
+ gasOutStream.run(id);
+ liquidOutStream.run(id);
+ setCalculationIdentifier(id);
}
/** {@inheritDoc} */
diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/NeqGasScrubber.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/NeqGasScrubber.java
index 6efa19914c..77ecee1357 100644
--- a/src/main/java/neqsim/processSimulation/processEquipment/separator/NeqGasScrubber.java
+++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/NeqGasScrubber.java
@@ -1,6 +1,7 @@
package neqsim.processSimulation.processEquipment.separator;
import java.util.ArrayList;
+import java.util.UUID;
import neqsim.processSimulation.mechanicalDesign.separator.GasScrubberMechanicalDesign;
import neqsim.processSimulation.processEquipment.separator.sectionType.SeparatorSection;
import neqsim.processSimulation.processEquipment.stream.Stream;
@@ -16,137 +17,141 @@
* @version $Id: $Id
*/
public class NeqGasScrubber extends Separator {
- private static final long serialVersionUID = 1000;
-
- SystemInterface thermoSystem, gasSystem, waterSystem, liquidSystem, thermoSystemCloned;
- ArrayList- * Constructor for NeqGasScrubber. - *
- */ - @Deprecated - public NeqGasScrubber() { - this("NeqGasScrubber"); - } - - /** - *- * Constructor for NeqGasScrubber. - *
- * - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public NeqGasScrubber(StreamInterface inletStream) { - this("NeqGasScrubber", inletStream); - } - - /** - * Constructor for NeqGasScrubber. - * - * @param name name of unit operation - */ - public NeqGasScrubber(String name) { - super(name); - this.setOrientation("vertical"); - } - - /** - *- * Constructor for NeqGasScrubber. - *
- * - * @param name a {@link java.lang.String} object - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public NeqGasScrubber(String name, StreamInterface inletStream) { - super(name, inletStream); - this.setOrientation("vertical"); - } - - public GasScrubberMechanicalDesign getMechanicalDesign() { - return new GasScrubberMechanicalDesign(this); - } - - /** - *
- * Setter for the field inletStream
.
- *
- * addScrubberSection. - *
- * - * @param type a {@link java.lang.String} object - */ - public void addScrubberSection(String type) { - scrubberSection.add(new SeparatorSection("section" + scrubberSection.size() + 1, type, this)); - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getLiquidOutStream() { - return liquidOutStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGasOutStream() { - return gasOutStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGas() { - return getGasOutStream(); - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getLiquid() { - return getLiquidOutStream(); - } - - /** {@inheritDoc} */ - @Override - public void run() { - thermoSystem = inletStream.getThermoSystem().clone(); - gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]); - gasSystem.setNumberOfPhases(1); - gasOutStream.setThermoSystem(gasSystem); - - thermoSystem = inletStream.getThermoSystem().clone(); - liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]); - liquidSystem.setNumberOfPhases(1); - liquidOutStream.setThermoSystem(liquidSystem); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - } + private static final long serialVersionUID = 1000; + + SystemInterface thermoSystem; + SystemInterface gasSystem; + SystemInterface waterSystem; + SystemInterface liquidSystem; + SystemInterface thermoSystemCloned; + ArrayList+ * Constructor for NeqGasScrubber. + *
+ */ + @Deprecated + public NeqGasScrubber() { + this("NeqGasScrubber"); + } + + /** + *+ * Constructor for NeqGasScrubber. + *
+ * + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public NeqGasScrubber(StreamInterface inletStream) { + this("NeqGasScrubber", inletStream); + } + + /** + * Constructor for NeqGasScrubber. + * + * @param name name of unit operation + */ + public NeqGasScrubber(String name) { + super(name); + this.setOrientation("vertical"); + } + + /** + *+ * Constructor for NeqGasScrubber. + *
+ * + * @param name a {@link java.lang.String} object + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public NeqGasScrubber(String name, StreamInterface inletStream) { + super(name, inletStream); + this.setOrientation("vertical"); + } + + public GasScrubberMechanicalDesign getMechanicalDesign() { + return new GasScrubberMechanicalDesign(this); + } + + /** + *
+ * Setter for the field inletStream
.
+ *
+ * addScrubberSection. + *
+ * + * @param type a {@link java.lang.String} object + */ + public void addScrubberSection(String type) { + scrubberSection.add(new SeparatorSection("section" + scrubberSection.size() + 1, type, this)); + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getLiquidOutStream() { + return liquidOutStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getGasOutStream() { + return gasOutStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getGas() { + return getGasOutStream(); + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getLiquid() { + return getLiquidOutStream(); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + thermoSystem = inletStream.getThermoSystem().clone(); + gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]); + gasSystem.setNumberOfPhases(1); + gasOutStream.setThermoSystem(gasSystem); + + thermoSystem = inletStream.getThermoSystem().clone(); + liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]); + liquidSystem.setNumberOfPhases(1); + liquidOutStream.setThermoSystem(liquidSystem); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() {} } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java index deddf5ec0a..e500cb95c4 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Objects; +import java.util.UUID; import neqsim.processSimulation.mechanicalDesign.separator.SeparatorMechanicalDesign; import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass; import neqsim.processSimulation.processEquipment.mixer.Mixer; @@ -194,8 +195,8 @@ public SystemInterface getThermoSystem() { /** {@inheritDoc} */ @Override - public void run() { - inletStreamMixer.run(); + public void run(UUID id) { + inletStreamMixer.run(id); thermoSystem2 = inletStreamMixer.getOutletStream().getThermoSystem().clone(); thermoSystem2.setPressure(thermoSystem2.getPressure() - pressureDrop); @@ -212,12 +213,12 @@ public void run() { liquidOutStream.setThermoSystem(thermoSystem2.getEmptySystemClone()); } if (thermoSystem2.hasPhaseType("gas")) { - gasOutStream.run(); + gasOutStream.run(id); } else { gasOutStream.getFluid().init(3); } if (thermoSystem2.hasPhaseType("aqueous") || thermoSystem2.hasPhaseType("oil")) { - liquidOutStream.run(); + liquidOutStream.run(id); } else { liquidOutStream.getFluid().init(3); } @@ -263,6 +264,7 @@ public void run() { e.printStackTrace(); } thermoSystem = thermoSystem2; + setCalculationIdentifier(id); } /** {@inheritDoc} */ @@ -279,13 +281,14 @@ public String[][] getResultTable() { /** {@inheritDoc} */ @Override - public void runTransient(double dt) { + public void runTransient(double dt, UUID id) { if (getCalculateSteadyState()) { - run(); + run(id); + increaseTime(dt); return; } - inletStreamMixer.run(); + inletStreamMixer.run(id); // System.out.println("moles out" + // liquidOutStream.getThermoSystem().getTotalNumberOfMoles()); @@ -325,6 +328,7 @@ public void runTransient(double dt) { * getSeparatorLength(); gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter() * getSeparatorLength(); + setCalculationIdentifier(id); } /** @@ -343,9 +347,11 @@ public void setTempPres(double temp, double pres) { gasOutStream.getThermoSystem().setPressure(pres); liquidOutStream.getThermoSystem().setPressure(pres); - inletStreamMixer.run(); - gasOutStream.run(); - liquidOutStream.run(); + UUID id = UUID.randomUUID(); + + inletStreamMixer.run(id); + gasOutStream.run(id); + liquidOutStream.run(id); } /** diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/ThreePhaseSeparator.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/ThreePhaseSeparator.java index edecc81807..3bde197351 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/ThreePhaseSeparator.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/ThreePhaseSeparator.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.separator; +import java.util.UUID; import neqsim.processSimulation.processEquipment.stream.Stream; import neqsim.processSimulation.processEquipment.stream.StreamInterface; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -155,8 +156,8 @@ public StreamInterface getOilOutStream() { /** {@inheritDoc} */ @Override - public void run() { - inletStreamMixer.run(); + public void run(UUID id) { + inletStreamMixer.run(id); thermoSystem = inletStreamMixer.getOutletStream().getThermoSystem().clone(); thermoSystem.setMultiPhaseCheck(true); @@ -182,32 +183,31 @@ public void run() { // //gasOutStream.setThermoSystem(gasSystem); if (thermoSystem.hasPhaseType("gas")) { gasOutStream.setThermoSystemFromPhase(thermoSystem, "gas"); - gasOutStream.run(); + gasOutStream.run(id); } else { gasOutStream.setThermoSystem(thermoSystem.getEmptySystemClone()); } - // //gasOutStream.run(); //// liquidSystem = thermoSystem.phaseToSystem(1); //// liquidOutStream.setThermoSystem(liquidSystem); if (thermoSystem.hasPhaseType("oil")) { // thermoSystem.display(); liquidOutStream.setThermoSystemFromPhase(thermoSystem, "oil"); - liquidOutStream.run(); + liquidOutStream.run(id); // thermoSystem.display(); } else { liquidOutStream.setThermoSystem(thermoSystem.getEmptySystemClone()); } - // //liquidOutStream.run(); //// waterSystem = thermoSystem.phaseToSystem(2); //// waterOutStream.setThermoSystem(waterSystem); if (thermoSystem.hasPhaseType("aqueous")) { waterOutStream.setThermoSystemFromPhase(thermoSystem, "aqueous"); - waterOutStream.run(); + waterOutStream.run(id); } else { waterOutStream.setThermoSystem(thermoSystem.getEmptySystemClone()); } + setCalculationIdentifier(id); } /** {@inheritDoc} */ diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/TwoPhaseSeparator.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/TwoPhaseSeparator.java index 226595cb01..266ee842a8 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/TwoPhaseSeparator.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/TwoPhaseSeparator.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.separator; +import java.util.UUID; import neqsim.processSimulation.processEquipment.stream.Stream; import neqsim.processSimulation.processEquipment.stream.StreamInterface; import neqsim.thermo.system.SystemInterface; @@ -13,113 +14,122 @@ * @version $Id: $Id */ public class TwoPhaseSeparator extends Separator { - private static final long serialVersionUID = 1000; - - SystemInterface thermoSystem, gasSystem, waterSystem, liquidSystem, thermoSystemCloned; - StreamInterface inletStream; - StreamInterface gasOutStream; - StreamInterface liquidOutStream; - String name = new String(); - - /** - *- * Constructor for TwoPhaseSeparator. - *
- */ - @Deprecated - public TwoPhaseSeparator() { - this("TwoPhaseSeparator"); - } - - /** - *- * Constructor for TwoPhaseSeparator. - *
- * - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public TwoPhaseSeparator(StreamInterface inletStream) { - this("TwoPhaseSeparator", inletStream); - } - - /** - * Constructor for TwoPhaseSeparator. - * - * @param name name of separator - */ - public TwoPhaseSeparator(String name) { - super(name); - } - - /** - *- * Constructor for TwoPhaseSeparator. - *
- * - * @param name a {@link java.lang.String} object - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public TwoPhaseSeparator(String name, StreamInterface inletStream) { - super(name, inletStream); - } - - /** {@inheritDoc} */ - @Override - public void setInletStream(StreamInterface inletStream) { - this.inletStream = inletStream; - - thermoSystem = inletStream.getThermoSystem().clone(); - gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]); - gasOutStream = new Stream("gasOutStream", gasSystem); - - thermoSystem = inletStream.getThermoSystem().clone(); - liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]); - liquidOutStream = new Stream("liquidOutStream", liquidSystem); - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getLiquidOutStream() { - return liquidOutStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGasOutStream() { - return gasOutStream; - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getGas() { - return getGasOutStream(); - } - - /** {@inheritDoc} */ - @Override - public StreamInterface getLiquid() { - return getLiquidOutStream(); - } - - /** {@inheritDoc} */ - @Override - public void run() { - thermoSystem = inletStream.getThermoSystem().clone(); - gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]); - gasSystem.setNumberOfPhases(1); - gasOutStream.setThermoSystem(gasSystem); - - thermoSystem = inletStream.getThermoSystem().clone(); - liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]); - liquidSystem.setNumberOfPhases(1); - liquidOutStream.setThermoSystem(liquidSystem); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - } + private static final long serialVersionUID = 1000; + + SystemInterface thermoSystem; + + SystemInterface gasSystem; + + SystemInterface waterSystem; + + SystemInterface liquidSystem; + + SystemInterface thermoSystemCloned; + + StreamInterface inletStream; + StreamInterface gasOutStream; + StreamInterface liquidOutStream; + String name = new String(); + + /** + *+ * Constructor for TwoPhaseSeparator. + *
+ */ + @Deprecated + public TwoPhaseSeparator() { + this("TwoPhaseSeparator"); + } + + /** + *+ * Constructor for TwoPhaseSeparator. + *
+ * + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public TwoPhaseSeparator(StreamInterface inletStream) { + this("TwoPhaseSeparator", inletStream); + } + + /** + * Constructor for TwoPhaseSeparator. + * + * @param name name of separator + */ + public TwoPhaseSeparator(String name) { + super(name); + } + + /** + *+ * Constructor for TwoPhaseSeparator. + *
+ * + * @param name a {@link java.lang.String} object + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public TwoPhaseSeparator(String name, StreamInterface inletStream) { + super(name, inletStream); + } + + /** {@inheritDoc} */ + @Override + public void setInletStream(StreamInterface inletStream) { + this.inletStream = inletStream; + + thermoSystem = inletStream.getThermoSystem().clone(); + gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]); + gasOutStream = new Stream("gasOutStream", gasSystem); + + thermoSystem = inletStream.getThermoSystem().clone(); + liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]); + liquidOutStream = new Stream("liquidOutStream", liquidSystem); + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getLiquidOutStream() { + return liquidOutStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getGasOutStream() { + return gasOutStream; + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getGas() { + return getGasOutStream(); + } + + /** {@inheritDoc} */ + @Override + public StreamInterface getLiquid() { + return getLiquidOutStream(); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + thermoSystem = inletStream.getThermoSystem().clone(); + gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]); + gasSystem.setNumberOfPhases(1); + gasOutStream.setThermoSystem(gasSystem); + + thermoSystem = inletStream.getThermoSystem().clone(); + liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]); + liquidSystem.setNumberOfPhases(1); + liquidOutStream.setThermoSystem(liquidSystem); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() {} } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/sectionType/MeshSection.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/sectionType/MeshSection.java index c9f6a7273f..c78c5f31e5 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/sectionType/MeshSection.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/sectionType/MeshSection.java @@ -14,7 +14,6 @@ public class MeshSection extends SeparatorSection { private static final long serialVersionUID = 1000; - /** ** Constructor for MeshSection. diff --git a/src/main/java/neqsim/processSimulation/processEquipment/splitter/ComponentSplitter.java b/src/main/java/neqsim/processSimulation/processEquipment/splitter/ComponentSplitter.java index b09b6637e5..8800528881 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/splitter/ComponentSplitter.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/splitter/ComponentSplitter.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.splitter; +import java.util.UUID; import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass; import neqsim.processSimulation.processEquipment.stream.Stream; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -78,7 +79,7 @@ public StreamInterface getSplitStream(int i) { /** {@inheritDoc} */ @Override - public void run() { + public void run(UUID id) { for (int i = 0; i < 2; i++) { thermoSystem = inletStream.getThermoSystem().clone(); thermoSystem.setEmptyFluid(); @@ -101,6 +102,7 @@ public void run() { new ThermodynamicOperations(splitStream[i].getThermoSystem()); thermoOps.TPflash(); } + setCalculationIdentifier(id); } /** {@inheritDoc} */ diff --git a/src/main/java/neqsim/processSimulation/processEquipment/splitter/Splitter.java b/src/main/java/neqsim/processSimulation/processEquipment/splitter/Splitter.java index 2bf790a6d1..51f9822098 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/splitter/Splitter.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/splitter/Splitter.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.splitter; +import java.util.UUID; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass; @@ -138,21 +139,21 @@ public StreamInterface getSplitStream(int i) { /** {@inheritDoc} */ @Override - public void run() { + public void run(UUID id) { double totSplit = 0.0; for (int i = 0; i < splitNumber; i++) { - if(splitFactor[i]<0) { + if (splitFactor[i] < 0) { logger.debug("split factor negative = " + splitFactor[i]); splitFactor[i] = 0.0; } totSplit += splitFactor[i]; } - if(Math.abs(totSplit-1.0)>1e-10) { + if (Math.abs(totSplit - 1.0) > 1e-10) { logger.debug("total split factor different from 0 in splitter - totsplit = " + totSplit); logger.debug("setting first split to = " + (1.0 - totSplit)); splitFactor[0] = 1.0 - totSplit; } - + for (int i = 0; i < splitNumber; i++) { thermoSystem = inletStream.getThermoSystem().clone(); thermoSystem.init(0); @@ -166,6 +167,7 @@ public void run() { new ThermodynamicOperations(splitStream[i].getThermoSystem()); thermoOps.TPflash(); } + setCalculationIdentifier(id); } /** {@inheritDoc} */ diff --git a/src/main/java/neqsim/processSimulation/processEquipment/stream/EquilibriumStream.java b/src/main/java/neqsim/processSimulation/processEquipment/stream/EquilibriumStream.java index ea73e80a5f..c46c1bfeef 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/stream/EquilibriumStream.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/stream/EquilibriumStream.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.stream; +import java.util.UUID; import neqsim.thermo.system.SystemInterface; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -12,84 +13,84 @@ * @version $Id: $Id */ public class EquilibriumStream extends Stream { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - /** - *
- * Constructor for EquilibriumStream. - *
- */ - @Deprecated - public EquilibriumStream() {} + /** + *+ * Constructor for EquilibriumStream. + *
+ */ + @Deprecated + public EquilibriumStream() {} - /** - *- * Constructor for EquilibriumStream. - *
- * - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - @Deprecated - public EquilibriumStream(SystemInterface thermoSystem) { - super(thermoSystem); - } + /** + *+ * Constructor for EquilibriumStream. + *
+ * + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + @Deprecated + public EquilibriumStream(SystemInterface thermoSystem) { + super(thermoSystem); + } - /** - *- * Constructor for EquilibriumStream. - *
- * - * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public EquilibriumStream(StreamInterface stream) { - this("EquilibriumStream", stream.getThermoSystem()); - } + /** + *+ * Constructor for EquilibriumStream. + *
+ * + * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + @Deprecated + public EquilibriumStream(StreamInterface stream) { + this("EquilibriumStream", stream.getThermoSystem()); + } - /** - * Constructor for EquilibriumStream. - * - * @param name name of stream - */ - public EquilibriumStream(String name) { - super(name); - } + /** + * Constructor for EquilibriumStream. + * + * @param name name of stream + */ + public EquilibriumStream(String name) { + super(name); + } - /** - *- * Constructor for EquilibriumStream. - *
- * - * @param name a {@link java.lang.String} object - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - public EquilibriumStream(String name, SystemInterface thermoSystem) { - super(name, thermoSystem); - } + /** + *+ * Constructor for EquilibriumStream. + *
+ * + * @param name a {@link java.lang.String} object + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + public EquilibriumStream(String name, SystemInterface thermoSystem) { + super(name, thermoSystem); + } - /** {@inheritDoc} */ - @Override - public EquilibriumStream clone() { - EquilibriumStream clonedStream = null; + /** {@inheritDoc} */ + @Override + public EquilibriumStream clone() { + EquilibriumStream clonedStream = null; - try { - clonedStream = (EquilibriumStream) super.clone(); - } catch (Exception e) { - e.printStackTrace(System.err); - } - - thermoSystem = thermoSystem.clone(); - return clonedStream; + try { + clonedStream = (EquilibriumStream) super.clone(); + } catch (Exception e) { + e.printStackTrace(System.err); } - /** {@inheritDoc} */ - @Override - public void run() { - System.out.println("start flashing stream... " + streamNumber); - ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); - thermoOps.TPflash(); - System.out.println("number of phases: " + thermoSystem.getNumberOfPhases()); - System.out.println("beta: " + thermoSystem.getBeta()); - } + thermoSystem = thermoSystem.clone(); + return clonedStream; + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + System.out.println("start flashing stream... " + streamNumber); + ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); + thermoOps.TPflash(); + System.out.println("number of phases: " + thermoSystem.getNumberOfPhases()); + System.out.println("beta: " + thermoSystem.getBeta()); + setCalculationIdentifier(id); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/stream/IronIonSaturationStream.java b/src/main/java/neqsim/processSimulation/processEquipment/stream/IronIonSaturationStream.java index 468d250cb8..da6cfdbd76 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/stream/IronIonSaturationStream.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/stream/IronIonSaturationStream.java @@ -3,8 +3,10 @@ * * Created on 12. mars 2001, 13:11 */ + package neqsim.processSimulation.processEquipment.stream; +import java.util.UUID; import neqsim.thermo.system.SystemInterface; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -17,123 +19,122 @@ * @version $Id: $Id */ public class IronIonSaturationStream extends Stream { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - protected SystemInterface reactiveThermoSystem; + protected SystemInterface reactiveThermoSystem; - /** - *- * Constructor for IronIonSaturationStream. - *
- */ - @Deprecated - public IronIonSaturationStream() { - this("IronIonSaturationStream"); - } + /** + *+ * Constructor for IronIonSaturationStream. + *
+ */ + @Deprecated + public IronIonSaturationStream() { + this("IronIonSaturationStream"); + } - /** - *- * Constructor for IronIonSaturationStream. - *
- * - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - @Deprecated - public IronIonSaturationStream(SystemInterface thermoSystem) { - this("IronIonSaturationStream", thermoSystem); - } + /** + *+ * Constructor for IronIonSaturationStream. + *
+ * + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + @Deprecated + public IronIonSaturationStream(SystemInterface thermoSystem) { + this("IronIonSaturationStream", thermoSystem); + } - /** - *- * Constructor for IronIonSaturationStream. - *
- * - * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public IronIonSaturationStream(StreamInterface stream) { - this("IronIonSaturationStream", stream); - } + /** + *+ * Constructor for IronIonSaturationStream. + *
+ * + * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + @Deprecated + public IronIonSaturationStream(StreamInterface stream) { + this("IronIonSaturationStream", stream); + } - /** - * Constructor for IronIonSaturationStream. - * - * @param name name of stream - */ - public IronIonSaturationStream(String name) { - super(name); - } + /** + * Constructor for IronIonSaturationStream. + * + * @param name name of stream + */ + public IronIonSaturationStream(String name) { + super(name); + } - /** - * Constructor for IronIonSaturationStream. - * - * @param name name of stream - * @param stream input stream - */ - public IronIonSaturationStream(String name, StreamInterface stream) { - super(name, stream); - } + /** + * Constructor for IronIonSaturationStream. + * + * @param name name of stream + * @param stream input stream + */ + public IronIonSaturationStream(String name, StreamInterface stream) { + super(name, stream); + } - /** - *- * Constructor for IronIonSaturationStream. - *
- * - * @param name a {@link java.lang.String} object - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - public IronIonSaturationStream(String name, SystemInterface thermoSystem) { - super(name, thermoSystem); - } + /** + *+ * Constructor for IronIonSaturationStream. + *
+ * + * @param name a {@link java.lang.String} object + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + public IronIonSaturationStream(String name, SystemInterface thermoSystem) { + super(name, thermoSystem); + } - /** {@inheritDoc} */ - @Override - public IronIonSaturationStream clone() { - IronIonSaturationStream clonedSystem = null; - try { - clonedSystem = (IronIonSaturationStream) super.clone(); - } catch (Exception e) { - e.printStackTrace(System.err); - } - return clonedSystem; + /** {@inheritDoc} */ + @Override + public IronIonSaturationStream clone() { + IronIonSaturationStream clonedSystem = null; + try { + clonedSystem = (IronIonSaturationStream) super.clone(); + } catch (Exception e) { + e.printStackTrace(System.err); } + return clonedSystem; + } - /** {@inheritDoc} */ - @Override - public void run() { - System.out.println("start flashing stream... " + streamNumber); - if (stream != null) { - thermoSystem = this.stream.getThermoSystem().clone(); - } - if (stream != null) { - reactiveThermoSystem = - this.stream.getThermoSystem().setModel("Electrolyte-CPA-EOS-statoil"); - } - reactiveThermoSystem.addComponent("Fe++", 1e-6); - // reactiveThermoSystem.chemicalReactionInit(); - // reactiveThermoSystem.createDatabase(true); - // reactiveThermoSystem.addComponent("water", - // reactiveThermoSystem.getPhase(0).getComponent("MEG").getNumberOfmoles()); - ThermodynamicOperations thermoOps = new ThermodynamicOperations(reactiveThermoSystem); - thermoOps.TPflash(); - reactiveThermoSystem.display(); - try { - System.out.println("aqueous phase number " - + reactiveThermoSystem.getPhaseNumberOfPhase("aqueous")); - thermoOps.addIonToScaleSaturation(reactiveThermoSystem.getPhaseNumberOfPhase("aqueous"), - "FeCO3", "Fe++"); - } catch (Exception ex) { - ex.printStackTrace(); - } - reactiveThermoSystem.display(); - System.out.println("number of phases: " + reactiveThermoSystem.getNumberOfPhases()); - System.out.println("beta: " + reactiveThermoSystem.getBeta()); + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + System.out.println("start flashing stream... " + streamNumber); + if (stream != null) { + thermoSystem = this.stream.getThermoSystem().clone(); } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - reactiveThermoSystem.display(name); + if (stream != null) { + reactiveThermoSystem = this.stream.getThermoSystem().setModel("Electrolyte-CPA-EOS-statoil"); } + reactiveThermoSystem.addComponent("Fe++", 1e-6); + // reactiveThermoSystem.chemicalReactionInit(); + // reactiveThermoSystem.createDatabase(true); + // reactiveThermoSystem.addComponent("water", + // reactiveThermoSystem.getPhase(0).getComponent("MEG").getNumberOfmoles()); + ThermodynamicOperations thermoOps = new ThermodynamicOperations(reactiveThermoSystem); + thermoOps.TPflash(); + reactiveThermoSystem.display(); + try { + System.out + .println("aqueous phase number " + reactiveThermoSystem.getPhaseNumberOfPhase("aqueous")); + thermoOps.addIonToScaleSaturation(reactiveThermoSystem.getPhaseNumberOfPhase("aqueous"), + "FeCO3", "Fe++"); + } catch (Exception ex) { + ex.printStackTrace(); + } + reactiveThermoSystem.display(); + System.out.println("number of phases: " + reactiveThermoSystem.getNumberOfPhases()); + System.out.println("beta: " + reactiveThermoSystem.getBeta()); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + reactiveThermoSystem.display(name); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/stream/NeqStream.java b/src/main/java/neqsim/processSimulation/processEquipment/stream/NeqStream.java index b4197b1cd8..89697acb75 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/stream/NeqStream.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/stream/NeqStream.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.stream; +import java.util.UUID; import neqsim.thermo.system.SystemInterface; /** @@ -11,103 +12,103 @@ * @version $Id: $Id */ public class NeqStream extends Stream { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - /** - *- * Constructor for NeqStream. - *
- */ - @Deprecated - public NeqStream() { - super("NeqStream"); - } + /** + *+ * Constructor for NeqStream. + *
+ */ + @Deprecated + public NeqStream() { + super("NeqStream"); + } - /** - *- * Constructor for NeqStream. - *
- * - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - @Deprecated - public NeqStream(SystemInterface thermoSystem) { - super(thermoSystem); - } + /** + *+ * Constructor for NeqStream. + *
+ * + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + @Deprecated + public NeqStream(SystemInterface thermoSystem) { + super(thermoSystem); + } - /** - *- * Constructor for NeqStream. - *
- * - * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public NeqStream(StreamInterface stream) { - super(stream); - } + /** + *+ * Constructor for NeqStream. + *
+ * + * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + @Deprecated + public NeqStream(StreamInterface stream) { + super(stream); + } - /** - * Constructor for NeqStream. - * - * @param name name of stream - */ - public NeqStream(String name) { - super(name); - } + /** + * Constructor for NeqStream. + * + * @param name name of stream + */ + public NeqStream(String name) { + super(name); + } - /** - * Constructor for NeqStream. - * - * @param name name of stream - * @param stream input stream - */ - public NeqStream(String name, StreamInterface stream) { - super(name, stream); - } + /** + * Constructor for NeqStream. + * + * @param name name of stream + * @param stream input stream + */ + public NeqStream(String name, StreamInterface stream) { + super(name, stream); + } - /** - *- * Constructor for NeqStream. - *
- * - * @param name a {@link java.lang.String} object - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - public NeqStream(String name, SystemInterface thermoSystem) { - super(name, thermoSystem); - } + /** + *+ * Constructor for NeqStream. + *
+ * + * @param name a {@link java.lang.String} object + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + public NeqStream(String name, SystemInterface thermoSystem) { + super(name, thermoSystem); + } - /** {@inheritDoc} */ - @Override - public NeqStream clone() { - NeqStream clonedStream = null; + /** {@inheritDoc} */ + @Override + public NeqStream clone() { + NeqStream clonedStream = null; - try { - clonedStream = (NeqStream) super.clone(); - } catch (Exception e) { - e.printStackTrace(System.err); - } + try { + clonedStream = (NeqStream) super.clone(); + } catch (Exception e) { + e.printStackTrace(System.err); + } - thermoSystem = thermoSystem.clone(); + thermoSystem = thermoSystem.clone(); - return clonedStream; - } + return clonedStream; + } - /** {@inheritDoc} */ - @Override - public void run() { - System.out.println("start flashing stream... " + streamNumber); - if (stream != null) { - thermoSystem = this.stream.getThermoSystem().clone(); - } - this.thermoSystem.init_x_y(); - this.thermoSystem.initBeta(); - this.thermoSystem.init(3); - // thermoOps = new ThermodynamicOperations(thermoSystem); - // thermoOps.TPflash(); - System.out.println("number of phases: " + thermoSystem.getNumberOfPhases()); - System.out.println("beta: " + thermoSystem.getBeta()); + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + System.out.println("start flashing stream... " + streamNumber); + if (stream != null) { + thermoSystem = this.stream.getThermoSystem().clone(); } + this.thermoSystem.init_x_y(); + this.thermoSystem.initBeta(); + this.thermoSystem.init(3); + // thermoOps = new ThermodynamicOperations(thermoSystem); + // thermoOps.TPflash(); + System.out.println("number of phases: " + thermoSystem.getNumberOfPhases()); + System.out.println("beta: " + thermoSystem.getBeta()); + setCalculationIdentifier(id); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/stream/ScalePotentialCheckStream.java b/src/main/java/neqsim/processSimulation/processEquipment/stream/ScalePotentialCheckStream.java index aa87aac852..bb9d91d137 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/stream/ScalePotentialCheckStream.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/stream/ScalePotentialCheckStream.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.stream; +import java.util.UUID; import neqsim.thermo.system.SystemInterface; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -12,110 +13,109 @@ * @version $Id: $Id */ public class ScalePotentialCheckStream extends Stream { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - protected SystemInterface reactiveThermoSystem; + protected SystemInterface reactiveThermoSystem; - /** - *- * Constructor for ScalePotentialCheckStream. - *
- */ - @Deprecated - public ScalePotentialCheckStream() { - super("ScalePotentialCheckStream"); - } + /** + *+ * Constructor for ScalePotentialCheckStream. + *
+ */ + @Deprecated + public ScalePotentialCheckStream() { + super("ScalePotentialCheckStream"); + } - /** - *- * Constructor for ScalePotentialCheckStream. - *
- * - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - public ScalePotentialCheckStream(SystemInterface thermoSystem) { - super("ScalePotentialCheckStream", thermoSystem); - } + /** + *+ * Constructor for ScalePotentialCheckStream. + *
+ * + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + public ScalePotentialCheckStream(SystemInterface thermoSystem) { + super("ScalePotentialCheckStream", thermoSystem); + } - /** - *- * Constructor for ScalePotentialCheckStream. - *
- * - * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public ScalePotentialCheckStream(StreamInterface stream) { - super("ScalePotentialCheckStream", stream); - } + /** + *+ * Constructor for ScalePotentialCheckStream. + *
+ * + * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + @Deprecated + public ScalePotentialCheckStream(StreamInterface stream) { + super("ScalePotentialCheckStream", stream); + } - /** - * Constructor for ScalePotentialCheckStream. - * - * @param name name of unit operation - */ - public ScalePotentialCheckStream(String name) { - super(name); - } + /** + * Constructor for ScalePotentialCheckStream. + * + * @param name name of unit operation + */ + public ScalePotentialCheckStream(String name) { + super(name); + } - /** - * Constructor for ScalePotentialCheckStream. - * - * @param name name of stream - * @param stream input stream - */ - public ScalePotentialCheckStream(String name, StreamInterface stream) { - super(name, stream); - } + /** + * Constructor for ScalePotentialCheckStream. + * + * @param name name of stream + * @param stream input stream + */ + public ScalePotentialCheckStream(String name, StreamInterface stream) { + super(name, stream); + } - /** - *- * Constructor for ScalePotentialCheckStream. - *
- * - * @param name a {@link java.lang.String} object - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - public ScalePotentialCheckStream(String name, SystemInterface thermoSystem) { - super(name, thermoSystem); + /** + *+ * Constructor for ScalePotentialCheckStream. + *
+ * + * @param name a {@link java.lang.String} object + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + public ScalePotentialCheckStream(String name, SystemInterface thermoSystem) { + super(name, thermoSystem); + } + + /** {@inheritDoc} */ + @Override + public ScalePotentialCheckStream clone() { + ScalePotentialCheckStream clonedSystem = null; + try { + clonedSystem = (ScalePotentialCheckStream) super.clone(); + } catch (Exception e) { + e.printStackTrace(System.err); } + return clonedSystem; + } - /** {@inheritDoc} */ - @Override - public ScalePotentialCheckStream clone() { - ScalePotentialCheckStream clonedSystem = null; - try { - clonedSystem = (ScalePotentialCheckStream) super.clone(); - } catch (Exception e) { - e.printStackTrace(System.err); - } - return clonedSystem; + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + System.out.println("start flashing stream... " + streamNumber); + if (stream != null) { + thermoSystem = this.stream.getThermoSystem().clone(); + } + if (stream != null) { + reactiveThermoSystem = this.stream.getThermoSystem().setModel("Electrolyte-CPA-EOS-statoil"); } - /** {@inheritDoc} */ - @Override - public void run() { - System.out.println("start flashing stream... " + streamNumber); - if (stream != null) { - thermoSystem = this.stream.getThermoSystem().clone(); - } - if (stream != null) { - reactiveThermoSystem = - this.stream.getThermoSystem().setModel("Electrolyte-CPA-EOS-statoil"); - } + ThermodynamicOperations thermoOps = new ThermodynamicOperations(reactiveThermoSystem); + thermoOps.TPflash(); + reactiveThermoSystem.init(3); - ThermodynamicOperations thermoOps = new ThermodynamicOperations(reactiveThermoSystem); - thermoOps.TPflash(); - reactiveThermoSystem.init(3); + System.out.println("number of phases: " + reactiveThermoSystem.getNumberOfPhases()); + System.out.println("beta: " + reactiveThermoSystem.getBeta()); + setCalculationIdentifier(id); + } - System.out.println("number of phases: " + reactiveThermoSystem.getNumberOfPhases()); - System.out.println("beta: " + reactiveThermoSystem.getBeta()); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - reactiveThermoSystem.display(name); - } + /** {@inheritDoc} */ + @Override + public void displayResult() { + reactiveThermoSystem.display(name); + } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/stream/Stream.java b/src/main/java/neqsim/processSimulation/processEquipment/stream/Stream.java index d6a1602a29..3ff8f484d1 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/stream/Stream.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/stream/Stream.java @@ -5,6 +5,7 @@ */ package neqsim.processSimulation.processEquipment.stream; +import java.util.UUID; import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass; import neqsim.standards.gasQuality.Standard_ISO6976; import neqsim.thermo.system.SystemInterface; @@ -19,541 +20,543 @@ * @version $Id: $Id */ public class Stream extends ProcessEquipmentBaseClass implements StreamInterface, Cloneable { - private static final long serialVersionUID = 1000; - - protected SystemInterface thermoSystem; - - protected int streamNumber = 0; - /** ConstantnumberOfStreams=0
*/
- protected static int numberOfStreams = 0;
- private double gasQuality = 0.5;
- protected StreamInterface stream = null;
-
- /**
- * - * Constructor for Stream. - *
- */ - @Deprecated - public Stream() { - super("Stream"); - } - - /** - *- * Constructor for Stream. - *
- * - * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public Stream(StreamInterface stream) { - this("Stream", stream); - } - - /** - *- * Constructor for Stream. - *
- * - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - @Deprecated - public Stream(SystemInterface thermoSystem) { - this("Stream", thermoSystem); - } - - /** - * Constructor for Stream. - * - * @param name name of stream - */ - public Stream(String name) { - super(name); - } - - /** - * Constructor for Stream. - * - * @param name name of stream - * @param stream input stream - */ - public Stream(String name, StreamInterface stream) { - super(name); - this.setStream(stream); - thermoSystem = stream.getThermoSystem(); - numberOfStreams++; - streamNumber = numberOfStreams; - } - - /** - *- * Constructor for Stream. - *
- * - * @param name a {@link java.lang.String} object - * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - */ - public Stream(String name, SystemInterface thermoSystem) { - super(name); - this.thermoSystem = thermoSystem; - numberOfStreams++; - streamNumber = numberOfStreams; - } - - /** - *
- * Getter for the field gasQuality
.
- *
- * Setter for the field gasQuality
.
- *
- * getSolidFormationTemperature. - *
- * - * @param solidName a {@link java.lang.String} object - * @return a double - */ - public double getSolidFormationTemperature(String solidName) { - SystemInterface copySystem = thermoSystem.clone(); - - try { - if (solidName.equals("hydrate")) { - copySystem.setHydrateCheck(true); - ThermodynamicOperations thermoOps = new ThermodynamicOperations(copySystem); - thermoOps.hydrateFormationTemperature(); - } else { - copySystem.setSolidPhaseCheck(false); - copySystem.setSolidPhaseCheck(solidName); - ThermodynamicOperations thermoOps = new ThermodynamicOperations(copySystem); - thermoOps.freezingPointTemperatureFlash(); - } - return copySystem.getTemperature(); - } catch (Exception e) { - e.printStackTrace(); - } - return 0.0; - } - - /** {@inheritDoc} */ - @Override - public Stream clone() { - Stream clonedSystem = null; - try { - clonedSystem = (Stream) super.clone(); - } catch (Exception e) { - e.printStackTrace(System.err); - } - if (stream != null) - clonedSystem.setStream((Stream) stream.clone());; - clonedSystem.thermoSystem = getThermoSystem().clone(); - return clonedSystem; - } - - /** {@inheritDoc} */ - @Override - public double getTemperature() { - return thermoSystem.getTemperature(); - } - - /** {@inheritDoc} */ - @Override - public double getPressure() { - return thermoSystem.getPressure(); - } - - /** {@inheritDoc} */ - @Override - public double getMolarRate() { - return thermoSystem.getTotalNumberOfMoles(); - } - - /** {@inheritDoc} */ - @Override - public void setThermoSystem(SystemInterface thermoSystem) { - this.thermoSystem = thermoSystem; - if (stream != null) { - stream.setThermoSystem(thermoSystem); - } - } - - /** {@inheritDoc} */ - @Override - public void setFluid(SystemInterface fluid) { - this.setThermoSystem(fluid); - } - - /** {@inheritDoc} */ - @Override - public void setThermoSystemFromPhase(SystemInterface thermoSystem, String phaseTypeName) { - if (phaseTypeName.equals("liquid")) { - if (thermoSystem.hasPhaseType("oil") && thermoSystem.hasPhaseType("aqueous")) { - this.thermoSystem = - thermoSystem.phaseToSystem(thermoSystem.getPhaseNumberOfPhase("oil"), - thermoSystem.getPhaseNumberOfPhase("aqueous")); - } else if (thermoSystem.hasPhaseType("oil")) { - this.thermoSystem = - thermoSystem.phaseToSystem(thermoSystem.getPhaseNumberOfPhase("oil")); - } else if (thermoSystem.hasPhaseType("aqueous")) { - this.thermoSystem = - thermoSystem.phaseToSystem(thermoSystem.getPhaseNumberOfPhase("aqueous")); - } else { - System.out.println("no phase of type " + phaseTypeName); - System.out.println("...returning empty system "); - setEmptyThermoSystem(thermoSystem); - } - return; - } - if (thermoSystem.hasPhaseType(phaseTypeName)) { - this.thermoSystem = thermoSystem.phaseToSystem(phaseTypeName); - } else { - System.out.println("no phase of type " + phaseTypeName); - System.out.println("...returning empty system "); - setEmptyThermoSystem(thermoSystem); - } - } - - /** {@inheritDoc} */ - @Override - public void setEmptyThermoSystem(SystemInterface thermoSystem) { - this.thermoSystem = thermoSystem.getEmptySystemClone(); - this.thermoSystem.setNumberOfPhases(0); - } - - /** {@inheritDoc} */ - @Override - public SystemInterface getThermoSystem() { - return this.thermoSystem; - } - - /** {@inheritDoc} */ - @Override - public void setFlowRate(double flowrate, String unit) { - this.getFluid().setTotalFlowRate(flowrate, unit); - } - - /** {@inheritDoc} */ - @Override - public void setPressure(double pressure, String unit) { - getFluid().setPressure(pressure, unit); - } - - /** {@inheritDoc} */ - @Override - public void setTemperature(double temperature, String unit) { - getFluid().setTemperature(temperature, unit); - } - - /** {@inheritDoc} */ - @Override - public double getFlowRate(String unit) { - return this.getFluid().getFlowRate(unit); - } - - /** {@inheritDoc} */ - @Override - public double getPressure(String unit) { - return getFluid().getPressure(unit); - } - - /** {@inheritDoc} */ - @Override - public double getTemperature(String unit) { - return getFluid().getTemperature(unit); - } - - /** {@inheritDoc} */ - @Override - public void runTPflash() { - if (stream != null) { - thermoSystem = this.stream.getThermoSystem().clone(); - } - - ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); + private static final long serialVersionUID = 1000; + + protected SystemInterface thermoSystem; + + protected int streamNumber = 0; + /** ConstantnumberOfStreams=0
*/
+ protected static int numberOfStreams = 0;
+ private double gasQuality = 0.5;
+ protected StreamInterface stream = null;
+
+ /**
+ * + * Constructor for Stream. + *
+ */ + @Deprecated + public Stream() { + super("Stream"); + } + + /** + *+ * Constructor for Stream. + *
+ * + * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + @Deprecated + public Stream(StreamInterface stream) { + this("Stream", stream); + } + + /** + *+ * Constructor for Stream. + *
+ * + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + @Deprecated + public Stream(SystemInterface thermoSystem) { + this("Stream", thermoSystem); + } + + /** + * Constructor for Stream. + * + * @param name name of stream + */ + public Stream(String name) { + super(name); + } + + /** + * Constructor for Stream. + * + * @param name name of stream + * @param stream input stream + */ + public Stream(String name, StreamInterface stream) { + super(name); + this.setStream(stream); + thermoSystem = stream.getThermoSystem(); + numberOfStreams++; + streamNumber = numberOfStreams; + } + + /** + *+ * Constructor for Stream. + *
+ * + * @param name a {@link java.lang.String} object + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + public Stream(String name, SystemInterface thermoSystem) { + super(name); + this.thermoSystem = thermoSystem; + numberOfStreams++; + streamNumber = numberOfStreams; + } + + /** + *
+ * Getter for the field gasQuality
.
+ *
+ * Setter for the field gasQuality
.
+ *
+ * getSolidFormationTemperature. + *
+ * + * @param solidName a {@link java.lang.String} object + * @return a double + */ + public double getSolidFormationTemperature(String solidName) { + SystemInterface copySystem = thermoSystem.clone(); + + try { + if (solidName.equals("hydrate")) { + copySystem.setHydrateCheck(true); + ThermodynamicOperations thermoOps = new ThermodynamicOperations(copySystem); + thermoOps.hydrateFormationTemperature(); + } else { + copySystem.setSolidPhaseCheck(false); + copySystem.setSolidPhaseCheck(solidName); + ThermodynamicOperations thermoOps = new ThermodynamicOperations(copySystem); + thermoOps.freezingPointTemperatureFlash(); + } + return copySystem.getTemperature(); + } catch (Exception e) { + e.printStackTrace(); + } + return 0.0; + } + + /** {@inheritDoc} */ + @Override + public Stream clone() { + Stream clonedSystem = null; + try { + clonedSystem = (Stream) super.clone(); + } catch (Exception e) { + e.printStackTrace(System.err); + } + if (stream != null) { + clonedSystem.setStream((Stream) stream.clone()); + } + clonedSystem.thermoSystem = getThermoSystem().clone(); + return clonedSystem; + } + + /** {@inheritDoc} */ + @Override + public double getTemperature() { + return thermoSystem.getTemperature(); + } + + /** {@inheritDoc} */ + @Override + public double getTemperature(String unit) { + return getFluid().getTemperature(unit); + } + + /** {@inheritDoc} */ + @Override + public double getPressure() { + return thermoSystem.getPressure(); + } + + /** {@inheritDoc} */ + @Override + public double getPressure(String unit) { + return getFluid().getPressure(unit); + } + + /** {@inheritDoc} */ + @Override + public double getMolarRate() { + return thermoSystem.getTotalNumberOfMoles(); + } + + /** {@inheritDoc} */ + @Override + public void setThermoSystem(SystemInterface thermoSystem) { + this.thermoSystem = thermoSystem; + // todo: when is stream not null? + if (stream != null) { + stream.setThermoSystem(thermoSystem); + } + } + + /** {@inheritDoc} */ + @Override + public void setFluid(SystemInterface fluid) { + this.setThermoSystem(fluid); + } + + /** {@inheritDoc} */ + @Override + public void setThermoSystemFromPhase(SystemInterface thermoSystem, String phaseTypeName) { + if (phaseTypeName.equals("liquid")) { + if (thermoSystem.hasPhaseType("oil") && thermoSystem.hasPhaseType("aqueous")) { + this.thermoSystem = thermoSystem.phaseToSystem(thermoSystem.getPhaseNumberOfPhase("oil"), + thermoSystem.getPhaseNumberOfPhase("aqueous")); + } else if (thermoSystem.hasPhaseType("oil")) { + this.thermoSystem = thermoSystem.phaseToSystem(thermoSystem.getPhaseNumberOfPhase("oil")); + } else if (thermoSystem.hasPhaseType("aqueous")) { + this.thermoSystem = + thermoSystem.phaseToSystem(thermoSystem.getPhaseNumberOfPhase("aqueous")); + } else { + System.out.println("no phase of type " + phaseTypeName); + System.out.println("...returning empty system "); + setEmptyThermoSystem(thermoSystem); + } + return; + } + if (thermoSystem.hasPhaseType(phaseTypeName)) { + this.thermoSystem = thermoSystem.phaseToSystem(phaseTypeName); + } else { + System.out.println("no phase of type " + phaseTypeName); + System.out.println("...returning empty system "); + setEmptyThermoSystem(thermoSystem); + } + } + + /** {@inheritDoc} */ + @Override + public void setEmptyThermoSystem(SystemInterface thermoSystem) { + this.thermoSystem = thermoSystem.getEmptySystemClone(); + this.thermoSystem.setNumberOfPhases(0); + } + + /** {@inheritDoc} */ + @Override + public SystemInterface getThermoSystem() { + return this.thermoSystem; + } + + /** {@inheritDoc} */ + @Override + public void setFlowRate(double flowrate, String unit) { + this.getFluid().setTotalFlowRate(flowrate, unit); + } + + /** {@inheritDoc} */ + @Override + public void setPressure(double pressure, String unit) { + getFluid().setPressure(pressure, unit); + } + + /** {@inheritDoc} */ + @Override + public void setTemperature(double temperature, String unit) { + getFluid().setTemperature(temperature, unit); + } + + /** {@inheritDoc} */ + @Override + public double getFlowRate(String unit) { + return this.getFluid().getFlowRate(unit); + } + + /** {@inheritDoc} */ + @Override + public void runTPflash() { + if (stream != null) { + thermoSystem = this.stream.getThermoSystem().clone(); + } + + ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); + thermoOps.TPflash(); + thermoSystem.initProperties(); + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + // System.out.println("start flashing stream... " + streamNumber); + if (stream != null) { + thermoSystem = this.stream.getThermoSystem().clone(); + } + ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); + + if (stream != null && getThermoSystem().getNumberOfComponents() == 1 + && getSpecification().equals("TP")) { + setSpecification("PH"); + } + if (getSpecification().equals("TP")) { + thermoOps.TPflash(); + } else if (getSpecification().equals("dewP")) { + try { + thermoOps.dewPointTemperatureFlash(); + } catch (Exception e) { + e.printStackTrace(); thermoOps.TPflash(); - thermoSystem.initProperties(); - } - - /** {@inheritDoc} */ - @Override - public void run() { - // System.out.println("start flashing stream... " + streamNumber); - if (stream != null) { - thermoSystem = this.stream.getThermoSystem().clone(); - } - ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); - - if (stream != null && getThermoSystem().getNumberOfComponents() == 1 - && getSpecification().equals("TP")) { - setSpecification("PH"); - } - if (getSpecification().equals("TP")) { - thermoOps.TPflash(); - } else if (getSpecification().equals("dewP")) { - try { - thermoOps.dewPointTemperatureFlash(); - } catch (Exception e) { - e.printStackTrace(); - thermoOps.TPflash(); - } - } else if (getSpecification().equals("dewT")) { - try { - thermoOps.dewPointPressureFlash(); - } catch (Exception e) { - e.printStackTrace(); - thermoOps.TPflash(); - } - } else if (getSpecification().equals("gas quality")) { - try { - thermoSystem.init(0); - thermoSystem.init(2); - double gasEnthalpy = thermoSystem.getPhase(0).getEnthalpy(); - double liquidEnthalpy = thermoSystem.getPhase(1).getEnthalpy(); - - double enthalpySpec = - getGasQuality() * gasEnthalpy + (1.0 - getGasQuality()) * liquidEnthalpy; - thermoOps.PHflash(enthalpySpec); - } catch (Exception e) { - e.printStackTrace(); - thermoOps.TPflash(); - } - } else if (getSpecification().equals("bubP")) { - try { - thermoOps.bubblePointTemperatureFlash(); - } catch (Exception e) { - e.printStackTrace(); - thermoOps.TPflash(); - } - } else if (getSpecification().equals("bubT")) { - try { - thermoOps.bubblePointPressureFlash(false); - } catch (Exception e) { - e.printStackTrace(); - thermoOps.TPflash(); - } - } else if (getSpecification().equals("PH")) { - try { - thermoOps.PHflash(getThermoSystem().getEnthalpy(), 0); - } catch (Exception e) { - e.printStackTrace(); - thermoOps.TPflash(); - } - } else { - thermoOps.TPflash(); - } - - thermoSystem.initProperties(); - // System.out.println("number of phases: " + thermoSystem.getNumberOfPhases()); - // System.out.println("beta: " + thermoSystem.getBeta()); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - thermoSystem.display(name); - } - - /** - *- * getResultTable. - *
- * - * @return an array of {@link java.lang.String} objects - */ - public String[][] getResultTable() { - return thermoSystem.getResultTable(); - } - - /** {@inheritDoc} */ - @Override - public void runTransient(double dt) { - if (hasController) { - // This adjusts the flow rate through this stream. - // Typically used to match/manipulate mass balance. - runController(dt); - this.setFlowRate(getController().getResponse(), "kg/hr"); } - - run(); - } - - /** - *- * runController. - *
- * - * @param dt a double - */ - public void runController(double dt) { - if (hasController) { - getController().runTransient(this.getFlowRate("kg/hr"), dt); - } - } - - /** {@inheritDoc} */ - @Override - public void flashStream() { - ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem); - ops.TPflash(); - } - - /** - *- * phaseEnvelope. - *
- */ - public void phaseEnvelope() { - SystemInterface localSyst = thermoSystem.clone(); - ThermodynamicOperations ops = new ThermodynamicOperations(localSyst); - ops.setRunAsThread(true); - ops.calcPTphaseEnvelope(true); - ops.waitAndCheckForFinishedCalculation(10000); - ops.displayResult(); - // ops.getJfreeChart(); - } - - /** {@inheritDoc} */ - @Override - public double CCB(String unit) { - SystemInterface localSyst = thermoSystem.clone(); - ThermodynamicOperations ops = new ThermodynamicOperations(localSyst); - ops.setRunAsThread(true); - ops.calcPTphaseEnvelope(true); - ops.waitAndCheckForFinishedCalculation(10000); - if (unit.equals("bara") || unit.equals("bar")) { - return ops.get("cricondenbar")[1]; - } else { - if (unit.equals("C")) - return ops.get("cricondenbar")[0] - 273.15; - else - return ops.get("cricondenbar")[0]; - } - // return ops.get - // ops.getJfreeChart(); - } - - /** {@inheritDoc} */ - @Override - public double CCT(String unit) { - SystemInterface localSyst = thermoSystem.clone(); - ThermodynamicOperations ops = new ThermodynamicOperations(localSyst); - ops.setRunAsThread(true); - ops.calcPTphaseEnvelope(true); - ops.waitAndCheckForFinishedCalculation(10000); - if (unit.equals("bara") || unit.equals("bar")) { - return ops.get("cricondentherm")[1]; - } else { - if (unit.equals("C")) - return ops.get("cricondentherm")[0] - 273.15; - else - return ops.get("cricondentherm")[0]; - } - // return ops.get - // ops.getJfreeChart(); - } - - /** {@inheritDoc} */ - @Override - public double TVP(double temperature, String unit) { - SystemInterface localSyst = thermoSystem.clone(); - localSyst.setTemperature(temperature, unit); - ThermodynamicOperations ops = new ThermodynamicOperations(localSyst); - try { - ops.bubblePointPressureFlash(false); - } catch (Exception e) { - } - return localSyst.getPressure(unit); - } - - /** {@inheritDoc} */ - @Override - public String[][] reportResults() { - return thermoSystem.getResultTable(); - } - - /** - *- * getProperty. - *
- * - * @param propertyName a {@link java.lang.String} object - * @param unit a {@link java.lang.String} object - * @param phase a {@link java.lang.String} object - * @param component a {@link java.lang.String} object - * @return a {@link java.lang.Object} object - */ - public Object getProperty(String propertyName, String unit, String phase, String component) { - // getFluid().getProperties.containsKey(propertyName)) { - // if(properties.containsKey(propertyName)) { - // } - // else - return null; - } - - /** {@inheritDoc} */ - @Override - public double GCV() { - Standard_ISO6976 standard = new Standard_ISO6976(thermoSystem.clone(), 0, 15.55, "volume"); - standard.setReferenceState("real"); - standard.calculate(); - return standard.getValue("GCV") * 1.0e3; - } - - /** {@inheritDoc} */ - @Override - public double LCV() { - Standard_ISO6976 standard = new Standard_ISO6976(thermoSystem.clone(), 0, 15.55, "volume"); - standard.setReferenceState("real"); - standard.calculate(); - return standard.getValue("InferiorCalorificValue") * 1.0e3; + } else if (getSpecification().equals("dewT")) { + try { + thermoOps.dewPointPressureFlash(); + } catch (Exception e) { + e.printStackTrace(); + thermoOps.TPflash(); + } + } else if (getSpecification().equals("gas quality")) { + try { + thermoSystem.init(0); + thermoSystem.init(2); + double gasEnthalpy = thermoSystem.getPhase(0).getEnthalpy(); + double liquidEnthalpy = thermoSystem.getPhase(1).getEnthalpy(); + + double enthalpySpec = + getGasQuality() * gasEnthalpy + (1.0 - getGasQuality()) * liquidEnthalpy; + thermoOps.PHflash(enthalpySpec); + } catch (Exception e) { + e.printStackTrace(); + thermoOps.TPflash(); + } + } else if (getSpecification().equals("bubP")) { + try { + thermoOps.bubblePointTemperatureFlash(); + } catch (Exception e) { + e.printStackTrace(); + thermoOps.TPflash(); + } + } else if (getSpecification().equals("bubT")) { + try { + thermoOps.bubblePointPressureFlash(false); + } catch (Exception e) { + e.printStackTrace(); + thermoOps.TPflash(); + } + } else if (getSpecification().equals("PH")) { + try { + thermoOps.PHflash(getThermoSystem().getEnthalpy(), 0); + } catch (Exception e) { + e.printStackTrace(); + thermoOps.TPflash(); + } + } else { + thermoOps.TPflash(); + } + + thermoSystem.initProperties(); + // System.out.println("number of phases: " + thermoSystem.getNumberOfPhases()); + // System.out.println("beta: " + thermoSystem.getBeta()); + setCalculationIdentifier(id); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + thermoSystem.display(name); + } + + /** + *+ * getResultTable. + *
+ * + * @return an array of {@link java.lang.String} objects + */ + public String[][] getResultTable() { + return thermoSystem.getResultTable(); + } + + /** {@inheritDoc} */ + @Override + public void runTransient(double dt, UUID id) { + if (hasController) { + // This adjusts the flow rate through this stream. + // Typically used to match/manipulate mass balance. + runController(dt, id); + this.setFlowRate(getController().getResponse(), "kg/hr"); + } + + run(id); + increaseTime(dt); + } + + /** + *+ * runController. + *
+ * + * @param dt a double + */ + public void runController(double dt, UUID id) { + if (hasController) { + getController().runTransient(this.getFlowRate("kg/hr"), dt, id); + } + } + + /** {@inheritDoc} */ + @Override + public void flashStream() { + ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem); + ops.TPflash(); + } + + /** + *+ * phaseEnvelope. + *
+ */ + public void phaseEnvelope() { + SystemInterface localSyst = thermoSystem.clone(); + ThermodynamicOperations ops = new ThermodynamicOperations(localSyst); + ops.setRunAsThread(true); + ops.calcPTphaseEnvelope(true); + ops.waitAndCheckForFinishedCalculation(10000); + ops.displayResult(); + // ops.getJfreeChart(); + } + + /** {@inheritDoc} */ + @Override + public double CCB(String unit) { + SystemInterface localSyst = thermoSystem.clone(); + ThermodynamicOperations ops = new ThermodynamicOperations(localSyst); + ops.setRunAsThread(true); + ops.calcPTphaseEnvelope(true); + ops.waitAndCheckForFinishedCalculation(10000); + if (unit.equals("bara") || unit.equals("bar")) { + return ops.get("cricondenbar")[1]; + } else { + if (unit.equals("C")) { + return ops.get("cricondenbar")[0] - 273.15; + } else { + return ops.get("cricondenbar")[0]; + } } - - /** - *
- * Setter for the field stream
.
- *
+ * getProperty. + *
+ * + * @param propertyName a {@link java.lang.String} object + * @param unit a {@link java.lang.String} object + * @param phase a {@link java.lang.String} object + * @param component a {@link java.lang.String} object + * @return a {@link java.lang.Object} object + */ + public Object getProperty(String propertyName, String unit, String phase, String component) { + // getFluid().getProperties.containsKey(propertyName)) { + // if(properties.containsKey(propertyName)) { + // } + // else + return null; + } + + /** {@inheritDoc} */ + @Override + public double GCV() { + Standard_ISO6976 standard = new Standard_ISO6976(thermoSystem.clone(), 0, 15.55, "volume"); + standard.setReferenceState("real"); + standard.calculate(); + return standard.getValue("GCV") * 1.0e3; + } + + /** {@inheritDoc} */ + @Override + public double LCV() { + Standard_ISO6976 standard = new Standard_ISO6976(thermoSystem.clone(), 0, 15.55, "volume"); + standard.setReferenceState("real"); + standard.calculate(); + return standard.getValue("InferiorCalorificValue") * 1.0e3; + } + + /** + *
+ * Setter for the field stream
.
+ *
* runTPflash. @@ -67,28 +71,28 @@ public interface StreamInterface extends ProcessEquipmentInterface { */ public double getTemperature(String unit); - /** {@inheritDoc} */ - @Override - public void setName(String name); - /** *
- * CCT. + * getTemperature. *
* - * @param unit a {@link java.lang.String} object * @return a double */ - public double CCT(String unit); + public double getTemperature(); + + /** {@inheritDoc} */ + @Override + public void setName(String name); /** *- * getTemperature. + * CCT. *
* + * @param unit a {@link java.lang.String} object * @return a double */ - public double getTemperature(); + public double CCT(String unit); /** *@@ -139,10 +143,6 @@ public interface StreamInterface extends ProcessEquipmentInterface { */ public double getMolarRate(); - /** {@inheritDoc} */ - @Override - public double getPressure(); - /** *
* clone. diff --git a/src/main/java/neqsim/processSimulation/processEquipment/subsea/SimpleFlowLine.java b/src/main/java/neqsim/processSimulation/processEquipment/subsea/SimpleFlowLine.java index b6432f764e..2de19abcd8 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/subsea/SimpleFlowLine.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/subsea/SimpleFlowLine.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.subsea; +import java.util.UUID; import neqsim.processSimulation.processEquipment.TwoPortEquipment; import neqsim.processSimulation.processEquipment.pipeline.AdiabaticTwoPhasePipe; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -14,105 +15,106 @@ * @version $Id: $Id */ public class SimpleFlowLine extends TwoPortEquipment { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - private double height = 100.0; - public double length = 520.0; - double outletTemperature = 313.15; - AdiabaticTwoPhasePipe pipeline; + private double height = 100.0; + public double length = 520.0; + double outletTemperature = 313.15; + AdiabaticTwoPhasePipe pipeline; - /** - *
- * Constructor for SimpleFlowLine. - *
- * - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - @Deprecated - public SimpleFlowLine(StreamInterface inStream) { - this("SimpleFlowLine", inStream); + /** + *+ * Constructor for SimpleFlowLine. + *
+ * + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public SimpleFlowLine(StreamInterface inStream) { + this("SimpleFlowLine", inStream); - } + } - /** - * Constructor for SimpleFlowLine. - * - * @param name Name of SimpleFlowLine object - * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public SimpleFlowLine(String name, StreamInterface inStream) { - super(name); - this.inStream = inStream; - setOutletStream(inStream.clone()); - pipeline = new AdiabaticTwoPhasePipe("pipeline", inStream); - } + /** + * Constructor for SimpleFlowLine. + * + * @param name Name of SimpleFlowLine object + * @param inStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + public SimpleFlowLine(String name, StreamInterface inStream) { + super(name); + this.inStream = inStream; + setOutletStream(inStream.clone()); + pipeline = new AdiabaticTwoPhasePipe("pipeline", inStream); + } - /** - *
- * Getter for the field pipeline
.
- *
+ * Getter for the field pipeline
.
+ *
- * Getter for the field height
.
- *
- * Setter for the field height
.
- *
+ * Getter for the field height
.
+ *
+ * Setter for the field height
.
+ *
- * Constructor for SubseaWell. - *
- * - * @param instream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object + private static final long serialVersionUID = 1000; + + public double height = 1000.0, length = 1200.0; + AdiabaticTwoPhasePipe pipeline; + + /** + *+ * Constructor for SubseaWell. + *
+ * + * @param instream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} + * object + */ + @Deprecated + public SubseaWell(StreamInterface instream) { + super("SubseaWell"); + this.inStream = instream; + setOutletStream(instream.clone()); + pipeline = new AdiabaticTwoPhasePipe("pipeline", instream); + } + + /** + *
+ * Getter for the field pipeline
.
+ *
+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 + 100.0), 250.00); + testSystem.addComponent("nitrogen", 0.100); + testSystem.addComponent("methane", 70.00); + testSystem.addComponent("ethane", 1.0); + testSystem.addComponent("propane", 1.0); + testSystem.addComponent("i-butane", 1.0); + testSystem.addComponent("n-butane", 1.0); + testSystem.addComponent("n-hexane", 0.1); + testSystem.addComponent("n-heptane", 0.1); + testSystem.addComponent("n-nonane", 1.0); + testSystem.addComponent("nC10", 1.0); + testSystem.addComponent("nC12", 3.0); + testSystem.addComponent("nC15", 13.0); + testSystem.addComponent("nC20", 13.0); + testSystem.addComponent("water", 11.0); + testSystem.setMixingRule(2); + testSystem.setMultiPhaseCheck(true); + + SimpleReservoir reservoirOps = new SimpleReservoir("Well 1 reservoir"); + reservoirOps.setReservoirFluid(testSystem, 5.0 * 1e7, 552.0 * 1e6, 10.0e6); + StreamInterface producedOilStream = reservoirOps.addOilProducer("oilproducer_1"); + producedOilStream.setFlowRate(3500.0 * 24.0 * 600.0, "kg/day"); + + reservoirOps.run(); + + System.out.println("water volume" + + reservoirOps.getReservoirFluid().getPhase("aqueous").getVolume("m3") / 1.0e6); + System.out + .println("oil production total" + reservoirOps.getOilProductionTotal("Sm3") + " Sm3"); + System.out + .println("total produced " + reservoirOps.getProductionTotal("MSm3 oe") + " MSm3 oe"); + + SubseaWell well1 = new SubseaWell(reservoirOps.getOilProducer("oilproducer_1").getStream()); + well1.getPipeline().setDiameter(0.3); + well1.getPipeline().setLength(5500.0); + well1.getPipeline().setInletElevation(-1000.0); + well1.getPipeline().setOutletElevation(-100.0); + ThrottlingValve subseaChoke = new ThrottlingValve("subseaChoke", well1.getOutletStream()); + subseaChoke.setOutletPressure(90.0); + subseaChoke.setAcceptNegativeDP(false); + SimpleFlowLine flowLine = new SimpleFlowLine("flowLine", subseaChoke.getOutletStream()); + flowLine.getPipeline().setDiameter(0.4); + flowLine.getPipeline().setLength(2000.0); + flowLine.getPipeline().setInletElevation(-100.0); + // flowLine.set + ThrottlingValve topsideChoke = new ThrottlingValve("topsideChoke", flowLine.getOutletStream()); + topsideChoke.setOutletPressure(50.0, "bara"); + topsideChoke.setAcceptNegativeDP(false); + + Adjuster adjust = new Adjuster("adjust"); + adjust.setActivateWhenLess(true); + adjust.setTargetVariable(flowLine.getOutletStream(), "pressure", 70.0, "bara"); + adjust.setAdjustedVariable(producedOilStream, "flow rate"); + + ProcessSystem ops = new ProcessSystem(); + ops.add(well1); + ops.add(subseaChoke); + ops.add(flowLine); + ops.add(topsideChoke); + ops.add(adjust); + + ArrayList
- * Getter for the field pipeline
.
- *
- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos((273.15 + 100.0), 250.00); - testSystem.addComponent("nitrogen", 0.100); - testSystem.addComponent("methane", 70.00); - testSystem.addComponent("ethane", 1.0); - testSystem.addComponent("propane", 1.0); - testSystem.addComponent("i-butane", 1.0); - testSystem.addComponent("n-butane", 1.0); - testSystem.addComponent("n-hexane", 0.1); - testSystem.addComponent("n-heptane", 0.1); - testSystem.addComponent("n-nonane", 1.0); - testSystem.addComponent("nC10", 1.0); - testSystem.addComponent("nC12", 3.0); - testSystem.addComponent("nC15", 13.0); - testSystem.addComponent("nC20", 13.0); - testSystem.addComponent("water", 11.0); - testSystem.setMixingRule(2); - testSystem.setMultiPhaseCheck(true); - - SimpleReservoir reservoirOps = new SimpleReservoir("Well 1 reservoir"); - reservoirOps.setReservoirFluid(testSystem, 5.0 * 1e7, 552.0 * 1e6, 10.0e6); - StreamInterface producedOilStream = reservoirOps.addOilProducer("oilproducer_1"); - producedOilStream.setFlowRate(3500.0 * 24.0 * 600.0, "kg/day"); - - reservoirOps.run(); - - System.out.println("water volume" - + reservoirOps.getReservoirFluid().getPhase("aqueous").getVolume("m3") / 1.0e6); - System.out.println( - "oil production total" + reservoirOps.getOilProductionTotal("Sm3") + " Sm3"); - System.out.println( - "total produced " + reservoirOps.getProductionTotal("MSm3 oe") + " MSm3 oe"); - - SubseaWell well1 = new SubseaWell(reservoirOps.getOilProducer("oilproducer_1").getStream()); - well1.getPipeline().setDiameter(0.3); - well1.getPipeline().setLength(5500.0); - well1.getPipeline().setInletElevation(-1000.0); - well1.getPipeline().setOutletElevation(-100.0); - ThrottlingValve subseaChoke = new ThrottlingValve("subseaChoke", well1.getOutletStream()); - subseaChoke.setOutletPressure(90.0); - subseaChoke.setAcceptNegativeDP(false); - SimpleFlowLine flowLine = new SimpleFlowLine("flowLine", subseaChoke.getOutletStream()); - flowLine.getPipeline().setDiameter(0.4); - flowLine.getPipeline().setLength(2000.0); - flowLine.getPipeline().setInletElevation(-100.0); - // flowLine.set - ThrottlingValve topsideChoke = - new ThrottlingValve("topsideChoke", flowLine.getOutletStream()); - topsideChoke.setOutletPressure(50.0, "bara"); - topsideChoke.setAcceptNegativeDP(false); - - Adjuster adjust = new Adjuster("adjust"); - adjust.setActivateWhenLess(true); - adjust.setTargetVariable(flowLine.getOutletStream(), "pressure", 70.0, "bara"); - adjust.setAdjustedVariable(producedOilStream, "flow rate"); - - ProcessSystem ops = new ProcessSystem(); - ops.add(well1); - ops.add(subseaChoke); - ops.add(flowLine); - ops.add(topsideChoke); - ops.add(adjust); - - ArrayList- * Constructor for Adjuster. - *
- */ - @Deprecated - public Adjuster() { - this("Adjuster"); - } + private static final long serialVersionUID = 1000; - /** - *- * Constructor for Adjuster. - *
- * - * @param name a {@link java.lang.String} object - */ - public Adjuster(String name) { - super(name); - } + ProcessEquipmentInterface adjustedEquipment = null; + ProcessEquipmentInterface targetEquipment = null; - /** - *- * setAdjustedVariable. - *
- * - * @param adjustedEquipment a - * {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} object - * @param adjstedVariable a {@link java.lang.String} object - */ - public void setAdjustedVariable(ProcessEquipmentInterface adjustedEquipment, - String adjstedVariable) { - this.adjustedEquipment = adjustedEquipment; - this.adjustedVarialble = adjstedVariable; - } + String adjustedVarialble = ""; + String targetVariable = ""; + String targetPhase = ""; + String targetComponent = ""; - /** - *
- * Setter for the field targetVariable
.
- *
- * Setter for the field targetVariable
.
- *
- * Setter for the field targetVariable
.
- *
+ * Constructor for Adjuster. + *
+ */ + @Deprecated + public Adjuster() { + this("Adjuster"); + } - /** {@inheritDoc} */ - @Override - public boolean solved() { - if (Math.abs(error) < tolerance) - return true; - else - return false; - } + /** + *+ * Constructor for Adjuster. + *
+ * + * @param name a {@link java.lang.String} object + */ + public Adjuster(String name) { + super(name); + } - /** {@inheritDoc} */ - @Override - public void displayResult() {} - - /** - *
- * Getter for the field tolerance
.
- *
+ * setAdjustedVariable. + *
+ * + * @param adjustedEquipment a + * {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} object + * @param adjstedVariable a {@link java.lang.String} object + */ + public void setAdjustedVariable(ProcessEquipmentInterface adjustedEquipment, + String adjstedVariable) { + this.adjustedEquipment = adjustedEquipment; + this.adjustedVarialble = adjstedVariable; + } - /** - *
- * Setter for the field tolerance
.
- *
+ * Setter for the field targetVariable
.
+ *
+ * Setter for the field targetVariable
.
+ *
+ * Setter for the field targetVariable
.
+ *
- * Getter for the field error
.
- *
- * Setter for the field error
.
- *
- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - // test code for adjuster... - neqsim.thermo.system.SystemInterface testSystem = - new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 20.00); - testSystem.addComponent("methane", 1000.00); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - - Stream stream_1 = new Stream("Stream1", testSystem); - Adjuster adjuster1 = new Adjuster(); - adjuster1.setAdjustedVariable(stream_1, "molarFlow"); - adjuster1.setTargetVariable(stream_1, "gasVolumeFlow", 10.0, "MSm3/day", ""); - - neqsim.processSimulation.processSystem.ProcessSystem operations = - new neqsim.processSimulation.processSystem.ProcessSystem(); - operations.add(stream_1); - operations.add(adjuster1); - - operations.run(); + if (activateWhenLess && targetValueCurrent > targetValue) { + error = 0.0; + activateWhenLess = true; + setCalculationIdentifier(id); + return; } - /** - *- * isActivateWhenLess. - *
- * - * @return a boolean - */ - public boolean isActivateWhenLess() { - return activateWhenLess; + iterations++; + double deviation = targetValue - targetValueCurrent; + + error = deviation; + logger.info("adjuster deviation " + deviation + " inputValue " + inputValue); + if (iterations < 2) { + if (adjustedVarialble.equals("mass flow")) { + ((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue + deviation, + "kg/hr"); + } else { + ((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue + deviation, + "mol/sec"); + } + } else { + double derivate = (error - oldError) / (inputValue - oldInputValue); + double newVal = error / derivate; + if (adjustedVarialble.equals("mass flow")) { + ((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue - newVal, + "kg/hr"); + } else { + ((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue - newVal, + "mol/sec"); + } } - /** - *
- * Setter for the field activateWhenLess
.
- *
+ * Getter for the field tolerance
.
+ *
+ * Setter for the field tolerance
.
+ *
+ * Getter for the field error
.
+ *
+ * Setter for the field error
.
+ *
+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + // test code for adjuster... + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 20.00); + testSystem.addComponent("methane", 1000.00); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + + Stream stream_1 = new Stream("Stream1", testSystem); + Adjuster adjuster1 = new Adjuster(); + adjuster1.setAdjustedVariable(stream_1, "molarFlow"); + adjuster1.setTargetVariable(stream_1, "gasVolumeFlow", 10.0, "MSm3/day", ""); + + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + operations.add(stream_1); + operations.add(adjuster1); + + operations.run(); + } + + /** + *+ * isActivateWhenLess. + *
+ * + * @return a boolean + */ + public boolean isActivateWhenLess() { + return activateWhenLess; + } + + /** + *
+ * Setter for the field activateWhenLess
.
+ *
- * Constructor for Calculator. - *
- * - * @param name a {@link java.lang.String} object - */ - public Calculator(String name) { - super(name); - } + /** + *+ * Constructor for Calculator. + *
+ * + * @param name a {@link java.lang.String} object + */ + public Calculator(String name) { + super(name); + } - /** - *- * addInputVariable. - *
- * - * @param unit a {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} - * object - */ - public void addInputVariable(ProcessEquipmentInterface unit) { - inputVariable.add(unit); - } + /** + *+ * addInputVariable. + *
+ * + * @param unit a {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} + * object + */ + public void addInputVariable(ProcessEquipmentInterface unit) { + inputVariable.add(unit); + } - /** - *
- * Getter for the field outputVariable
.
- *
+ * Getter for the field outputVariable
.
+ *
- * Setter for the field outputVariable
.
- *
+ * Setter for the field outputVariable
.
+ *
diff --git a/src/main/java/neqsim/processSimulation/processEquipment/util/MoleFractionControllerUtil.java b/src/main/java/neqsim/processSimulation/processEquipment/util/MoleFractionControllerUtil.java index 6994e26d90..8890c03d75 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/util/MoleFractionControllerUtil.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/util/MoleFractionControllerUtil.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.util; +import java.util.UUID; import neqsim.processSimulation.processEquipment.TwoPortEquipment; import neqsim.processSimulation.processEquipment.stream.Stream; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -116,7 +117,7 @@ public void setRelativeMoleFractionReduction(String compName, double moleFracRat /** {@inheritDoc} */ @Override - public void run() { + public void run(UUID id) { // System.out.println("MoleFractionContollerUtil running.."); thermoSystem = inStream.getThermoSystem().clone(); if (thermoSystem.getPhase(0).hasComponent(compName)) { @@ -132,6 +133,7 @@ public void run() { thermoOps.TPflash(); } outStream.setThermoSystem(thermoSystem); + setCalculationIdentifier(id); } /** {@inheritDoc} */ diff --git a/src/main/java/neqsim/processSimulation/processEquipment/util/NeqSimUnit.java b/src/main/java/neqsim/processSimulation/processEquipment/util/NeqSimUnit.java index 8a7bf3fc12..a937c06a3d 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/util/NeqSimUnit.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/util/NeqSimUnit.java @@ -1,5 +1,6 @@ package neqsim.processSimulation.processEquipment.util; +import java.util.UUID; import neqsim.fluidMechanics.flowNode.FlowNodeInterface; import neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.AnnularFlow; import neqsim.fluidMechanics.flowNode.twoPhaseNode.twoPhasePipeFlowNode.DropletFlowNode; @@ -19,337 +20,339 @@ * @version $Id: $Id */ public class NeqSimUnit extends TwoPortEquipment { - private static final long serialVersionUID = 1000; - - SystemInterface thermoSystem; - private String equipment = "pipeline"; - String flowPattern = "stratified"; - private double length = 1.0; - public int numberOfNodes = 100; - private double ID = 0.5; - private double outerTemperature = 283.15; - public double interfacialArea = 0.0; - - /** - *
- * Constructor for NeqSimUnit. - *
- * - * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object - * @param equipment a {@link java.lang.String} object - * @param flowPattern a {@link java.lang.String} object - */ - public NeqSimUnit(StreamInterface inletStream, String equipment, String flowPattern) { - super("NeqSimUnit"); - this.flowPattern = flowPattern; - this.setEquipment(equipment); - setInletStream(inletStream); - } - - /** - *
- * Setter for the field inletStream
.
- *
+ * Constructor for NeqSimUnit. + *
+ * + * @param inletStream a {@link neqsim.processSimulation.processEquipment.stream.Stream} object + * @param equipment a {@link java.lang.String} object + * @param flowPattern a {@link java.lang.String} object + */ + public NeqSimUnit(StreamInterface inletStream, String equipment, String flowPattern) { + super("NeqSimUnit"); + this.flowPattern = flowPattern; + this.setEquipment(equipment); + setInletStream(inletStream); + } + + /** + *
+ * Setter for the field inletStream
.
+ *
- * runDroplet. - *
- */ - public void runDroplet() { - PipeData pipe1 = new PipeData(getID(), 0.00025); - FlowNodeInterface test = new DropletFlowNode(thermoSystem, pipe1); - test.setInterphaseModelType(1); - test.setLengthOfNode(getLength() / (numberOfNodes * 1.0)); - test.getGeometry().getSurroundingEnvironment().setTemperature(getOuterTemperature()); - - test.getFluidBoundary().setHeatTransferCalc(false); - test.getFluidBoundary().setMassTransferCalc(true); - double length = 0; - test.initFlowCalc(); - double[][] temperatures2 = new double[3][1000]; - int k = 0; - interfacialArea = 0.0; - for (int i = 0; i < numberOfNodes; i++) { - interfacialArea = getInterfacialArea() + test.getInterphaseContactArea(); - length += test.getLengthOfNode(); - test.initFlowCalc(); - test.calcFluxes(); - if (i > 1 && (i % 1) == 0) { - k++; - // test.display("length " + length); - // test.getBulkSystem().display("length " + length); - // test.getInterphaseSystem().display("length " + length); - // test.getFluidBounsdary().display("length " + length); - // test.setLengthOfNode(0.000005 + test.getLengthOfNode() / 2.0); - temperatures2[0][k] = length; - temperatures2[1][k] = test.getGeometry().getInnerWallTemperature(); - // test.getFluidBoundary().display("test"); - } - - // test.getBulkSystem().display(); - test.update(); - // test.getFluidBoundary().display("length " + length); - // test.getInterphaseSystem().display("length " + length); - - // test.getFluidBoundary().display("test"); - } - - /* - * for (int i = 0; i < k; i++) { System.out.println("len temp " + temperatures2[0][i] + " " - * + temperatures2[1][i]); } - */ + // outStream.setThermoSystem(thermoSystem); + outStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); + } + + /** + *+ * runDroplet. + *
+ */ + public void runDroplet() { + PipeData pipe1 = new PipeData(getID(), 0.00025); + FlowNodeInterface test = new DropletFlowNode(thermoSystem, pipe1); + test.setInterphaseModelType(1); + test.setLengthOfNode(getLength() / (numberOfNodes * 1.0)); + test.getGeometry().getSurroundingEnvironment().setTemperature(getOuterTemperature()); + + test.getFluidBoundary().setHeatTransferCalc(false); + test.getFluidBoundary().setMassTransferCalc(true); + double length = 0; + test.initFlowCalc(); + double[][] temperatures2 = new double[3][1000]; + int k = 0; + interfacialArea = 0.0; + for (int i = 0; i < numberOfNodes; i++) { + interfacialArea = getInterfacialArea() + test.getInterphaseContactArea(); + length += test.getLengthOfNode(); + test.initFlowCalc(); + test.calcFluxes(); + if (i > 1 && (i % 1) == 0) { + k++; // test.display("length " + length); - outStream.setThermoSystem(test.getBulkSystem()); + // test.getBulkSystem().display("length " + length); + // test.getInterphaseSystem().display("length " + length); + // test.getFluidBounsdary().display("length " + length); + // test.setLengthOfNode(0.000005 + test.getLengthOfNode() / 2.0); + temperatures2[0][k] = length; + temperatures2[1][k] = test.getGeometry().getInnerWallTemperature(); + // test.getFluidBoundary().display("test"); + } + + // test.getBulkSystem().display(); + test.update(); + // test.getFluidBoundary().display("length " + length); + // test.getInterphaseSystem().display("length " + length); + + // test.getFluidBoundary().display("test"); } - /** - *- * runStratified. - *
+ /* + * for (int i = 0; i < k; i++) { System.out.println("len temp " + temperatures2[0][i] + " " + + * temperatures2[1][i]); } */ - public void runStratified() { - PipeData pipe1 = new PipeData(getID(), 0.00025); - FlowNodeInterface test = new StratifiedFlowNode(thermoSystem, pipe1); - test.setInterphaseModelType(1); - test.setLengthOfNode(getLength() / (numberOfNodes * 1.0)); - test.getGeometry().getSurroundingEnvironment().setTemperature(getOuterTemperature()); - - test.getFluidBoundary().setHeatTransferCalc(false); - test.getFluidBoundary().setMassTransferCalc(true); - double length = 0; - test.initFlowCalc(); - double[][] temperatures2 = new double[3][1000]; - int k = 0; - interfacialArea = 0.0; - for (int i = 0; i < numberOfNodes; i++) { - interfacialArea = getInterfacialArea() + test.getInterphaseContactArea(); - length += test.getLengthOfNode(); - test.initFlowCalc(); - test.calcFluxes(); - if (i > 1 && (i % 1) == 0) { - k++; - // test.display("length " + length); - // test.getBulkSystem().display("length " + length); - // test.getInterphaseSystem().display("length " + length); - // test.getFluidBounsdary().display("length " + length); - // test.setLengthOfNode(0.000005 + test.getLengthOfNode() / 2.0); - temperatures2[0][k] = length; - temperatures2[1][k] = test.getGeometry().getInnerWallTemperature(); - // test.getFluidBoundary().display("test"); - } - - // test.getBulkSystem().display(); - test.update(); - // test.getFluidBoundary().display("length " + length); - // test.getInterphaseSystem().display("length " + length); - - // test.getFluidBoundary().display("test"); - } - - /* - * for (int i = 0; i < k; i++) { System.out.println("len temp " + temperatures2[0][i] + " " - * + temperatures2[1][i]); } - */ + // test.display("length " + length); + outStream.setThermoSystem(test.getBulkSystem()); + } + + /** + *+ * runStratified. + *
+ */ + public void runStratified() { + PipeData pipe1 = new PipeData(getID(), 0.00025); + FlowNodeInterface test = new StratifiedFlowNode(thermoSystem, pipe1); + test.setInterphaseModelType(1); + test.setLengthOfNode(getLength() / (numberOfNodes * 1.0)); + test.getGeometry().getSurroundingEnvironment().setTemperature(getOuterTemperature()); + + test.getFluidBoundary().setHeatTransferCalc(false); + test.getFluidBoundary().setMassTransferCalc(true); + double length = 0; + test.initFlowCalc(); + double[][] temperatures2 = new double[3][1000]; + int k = 0; + interfacialArea = 0.0; + for (int i = 0; i < numberOfNodes; i++) { + interfacialArea = getInterfacialArea() + test.getInterphaseContactArea(); + length += test.getLengthOfNode(); + test.initFlowCalc(); + test.calcFluxes(); + if (i > 1 && (i % 1) == 0) { + k++; // test.display("length " + length); - outStream.setThermoSystem(test.getBulkSystem()); + // test.getBulkSystem().display("length " + length); + // test.getInterphaseSystem().display("length " + length); + // test.getFluidBounsdary().display("length " + length); + // test.setLengthOfNode(0.000005 + test.getLengthOfNode() / 2.0); + temperatures2[0][k] = length; + temperatures2[1][k] = test.getGeometry().getInnerWallTemperature(); + // test.getFluidBoundary().display("test"); + } + + // test.getBulkSystem().display(); + test.update(); + // test.getFluidBoundary().display("length " + length); + // test.getInterphaseSystem().display("length " + length); + + // test.getFluidBoundary().display("test"); } - /** - *- * runAnnular. - *
+ /* + * for (int i = 0; i < k; i++) { System.out.println("len temp " + temperatures2[0][i] + " " + + * temperatures2[1][i]); } */ - public void runAnnular() { - PipeData pipe1 = new PipeData(getID(), 0.00025); - FlowNodeInterface test = new AnnularFlow(thermoSystem, pipe1); - test.setInterphaseModelType(1); - test.setLengthOfNode(getLength() / (numberOfNodes * 1.0)); - test.getGeometry().getSurroundingEnvironment().setTemperature(getOuterTemperature()); - - test.getFluidBoundary().setHeatTransferCalc(false); - test.getFluidBoundary().setMassTransferCalc(true); - double length = 0; - test.initFlowCalc(); - double[][] temperatures2 = new double[3][1000]; - int k = 0; - interfacialArea = 0.0; - for (int i = 0; i < numberOfNodes; i++) { - interfacialArea = getInterfacialArea() + test.getInterphaseContactArea(); - length += test.getLengthOfNode(); - test.initFlowCalc(); - test.calcFluxes(); - if (i > 1 && (i % 1) == 0) { - k++; - // test.display("length " + length); - // test.getBulkSystem().display("length " + length); - // test.getInterphaseSystem().display("length " + length); - // test.getFluidBounsdary().display("length " + length); - // test.setLengthOfNode(0.000005 + test.getLengthOfNode() / 2.0); - temperatures2[0][k] = length; - temperatures2[1][k] = test.getGeometry().getInnerWallTemperature(); - // test.getFluidBoundary().display("test"); - } - - // test.getBulkSystem().display(); - test.update(); - // test.getFluidBoundary().display("length " + length); - // test.getInterphaseSystem().display("length " + length); - - // test.getFluidBoundary().display("test"); - } - - /* - * for (int i = 0; i < k; i++) { System.out.println("len temp " + temperatures2[0][i] + " " - * + temperatures2[1][i]); } - */ + // test.display("length " + length); + outStream.setThermoSystem(test.getBulkSystem()); + } + + /** + *+ * runAnnular. + *
+ */ + public void runAnnular() { + PipeData pipe1 = new PipeData(getID(), 0.00025); + FlowNodeInterface test = new AnnularFlow(thermoSystem, pipe1); + test.setInterphaseModelType(1); + test.setLengthOfNode(getLength() / (numberOfNodes * 1.0)); + test.getGeometry().getSurroundingEnvironment().setTemperature(getOuterTemperature()); + + test.getFluidBoundary().setHeatTransferCalc(false); + test.getFluidBoundary().setMassTransferCalc(true); + double length = 0; + test.initFlowCalc(); + double[][] temperatures2 = new double[3][1000]; + int k = 0; + interfacialArea = 0.0; + for (int i = 0; i < numberOfNodes; i++) { + interfacialArea = getInterfacialArea() + test.getInterphaseContactArea(); + length += test.getLengthOfNode(); + test.initFlowCalc(); + test.calcFluxes(); + if (i > 1 && (i % 1) == 0) { + k++; // test.display("length " + length); - outStream.setThermoSystem(test.getBulkSystem()); - } - - /** - *
- * Getter for the field length
.
- *
- * Setter for the field length
.
- *
- * getID. - *
- * - * @return a double - */ - public double getID() { - return ID; - } - - /** - *- * setID. - *
- * - * @param iD a double - */ - public void setID(double iD) { - ID = iD; - } - - /** - *
- * Getter for the field outerTemperature
.
- *
- * Setter for the field outerTemperature
.
- *
- * Getter for the field equipment
.
- *
- * Setter for the field equipment
.
- *
- * Getter for the field interfacialArea
.
- *
- * Getter for the field numberOfNodes
.
- *
- * Setter for the field numberOfNodes
.
- *
+ * Getter for the field length
.
+ *
+ * Setter for the field length
.
+ *
+ * getID. + *
+ * + * @return a double + */ + public double getID() { + return ID; + } + + /** + *+ * setID. + *
+ * + * @param iD a double + */ + public void setID(double iD) { + ID = iD; + } + + /** + *
+ * Getter for the field outerTemperature
.
+ *
+ * Setter for the field outerTemperature
.
+ *
+ * Getter for the field equipment
.
+ *
+ * Setter for the field equipment
.
+ *
+ * Getter for the field interfacialArea
.
+ *
+ * Getter for the field numberOfNodes
.
+ *
+ * Setter for the field numberOfNodes
.
+ *
+ * Setter for the field downstreamProperty
.
+ *
* Setter for the field
- * Setter for the field
* Getter for the field
- * Constructor for SetPoint.
- *
- * Constructor for SetPoint.
- *
- * Constructor for SetPoint.
- *
- * setSourceVariable.
- *
- * setSourceVariable.
- *
- * Setter for the field
- * Setter for the field
- * Setter for the field
- * Setter for the field
- * main.
- *
+ * Constructor for SetPoint.
+ *
+ * Constructor for SetPoint.
+ *
+ * Constructor for SetPoint.
+ *
+ * setSourceVariable.
+ *
+ * setSourceVariable.
+ *
+ * Setter for the field
+ * Setter for the field
+ * Setter for the field
+ * Setter for the field
+ * main.
+ * downstreamProperty
.
@@ -226,7 +238,7 @@ public void setDownstreamProperties() {
/** {@inheritDoc} */
@Override
- public void run() {
+ public void run(UUID id) {
iterations++;
/*
* if(firstTime || iterations>maxIterations) { firstTime=false; return;
@@ -264,10 +276,12 @@ public void run() {
setDownstreamProperties();
testOps.TPflash();
}
+ mixedStream.setCalculationIdentifier(id);
setError(massBalanceCheck());
System.out.println(name + " recycle error: " + getError());
lastIterationStream = (Stream) mixedStream.clone();
outletStream.setThermoSystem(mixedStream.getThermoSystem());
+ outletStream.setCalculationIdentifier(id);
// System.out.println("flow rate new in recycle " +
// outletStream.getFlowRate("kg/hr"));
@@ -279,6 +293,7 @@ public void run() {
// System.out.println("beta " + mixedStream.getThermoSystem().getBeta());
// outStream.setThermoSystem(mixedStream.getThermoSystem());
+ setCalculationIdentifier(id);
}
/**
@@ -425,17 +440,6 @@ public ArrayListdownstreamProperty
.
- * outletStream
.
diff --git a/src/main/java/neqsim/processSimulation/processEquipment/util/SetPoint.java b/src/main/java/neqsim/processSimulation/processEquipment/util/SetPoint.java
index 38af1984a3..e9228a777a 100644
--- a/src/main/java/neqsim/processSimulation/processEquipment/util/SetPoint.java
+++ b/src/main/java/neqsim/processSimulation/processEquipment/util/SetPoint.java
@@ -1,8 +1,8 @@
package neqsim.processSimulation.processEquipment.util;
+import java.util.UUID;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-
import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass;
import neqsim.processSimulation.processEquipment.ProcessEquipmentInterface;
import neqsim.processSimulation.processEquipment.stream.Stream;
@@ -16,211 +16,223 @@
* @version $Id: $Id
*/
public class SetPoint extends ProcessEquipmentBaseClass {
- private static final long serialVersionUID = 1000;
-
- ProcessEquipmentInterface sourceEquipment = null, targetEquipment = null;
- String sourceVarialble = "", targetVariable = "", targetPhase = "", targetComponent = "";
- double targetValue = 0.0;
- String targetUnit = "";
- double inputValue = 0.0, oldInputValue = 0.0;
-
- static Logger logger = LogManager.getLogger(SetPoint.class);
-
- /**
- * targetVariable
.
- * targetVariable
.
- * targetVariable
.
- * targetVariable
.
- * targetVariable
.
+ * targetVariable
.
+ * targetVariable
.
+ * targetVariable
.
+ *
* initializeStreams. diff --git a/src/main/java/neqsim/processSimulation/processSystem/ProcessModuleBaseClass.java b/src/main/java/neqsim/processSimulation/processSystem/ProcessModuleBaseClass.java index ca3360a858..8fd5d4ac22 100644 --- a/src/main/java/neqsim/processSimulation/processSystem/ProcessModuleBaseClass.java +++ b/src/main/java/neqsim/processSimulation/processSystem/ProcessModuleBaseClass.java @@ -5,6 +5,7 @@ */ package neqsim.processSimulation.processSystem; +import java.util.UUID; import neqsim.processSimulation.SimulationBaseClass; import neqsim.processSimulation.controllerDevice.ControllerDeviceInterface; import neqsim.processSimulation.mechanicalDesign.MechanicalDesign; @@ -111,8 +112,8 @@ public neqsim.processSimulation.processSystem.ProcessSystem getOperations() { /** {@inheritDoc} */ @Override - public void runTransient(double dt) { - getOperations().runTransient(dt); + public void runTransient(double dt, UUID id) { + getOperations().runTransient(dt, id); } // TODO: Check if all the equipment is solved correctly @@ -128,6 +129,12 @@ public SystemInterface getThermoSystem() { return null; } + /** {@inheritDoc} */ + @Override + public String getSpecification() { + return null; + } + /** *
* setSpecification.
@@ -138,12 +145,6 @@ public SystemInterface getThermoSystem() {
*/
public void setSpecification(String specificationName, double value) {}
- /** {@inheritDoc} */
- @Override
- public String getSpecification() {
- return null;
- }
-
/** {@inheritDoc} */
@Override
public void setSpecification(String specification) {}
diff --git a/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java b/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java
index bfa98b1a47..ff14811b2c 100644
--- a/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java
+++ b/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java
@@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
+import java.util.UUID;
import org.apache.commons.lang.SerializationUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -30,920 +31,923 @@
* @version $Id: $Id
*/
public class ProcessSystem extends SimulationBaseClass {
- private static final long serialVersionUID = 1000;
-
- transient Thread thisThread;
- String[][] signalDB = new String[1000][100];
- private double time = 0;
- private double surroundingTemperature = 288.15;
- private int timeStepNumber = 0;
- private ArrayList
- * Constructor for ProcessSystem.
- *
- * add.
- *
- * add.
- *
- * add.
- *
- * getUnit.
- *
- * hasUnitName.
- *
- * getMeasurementDevice.
- *
- * getUnitNumber.
- *
+ * Constructor for ProcessSystem.
+ *
+ * add.
+ *
- * replaceObject.
- *
- * getAllUnitNames.
- *
- * Getter for the field
- * removeUnit.
- *
- * clearAll.
- *
- * clear.
- *
- * setFluid.
- *
- * setFluid.
- *
- * runAsThread.
- *
- * runTransient.
- *
- * Getter for the field
- * Getter for the field
+ * add.
+ *
+ * add.
+ *
+ * getUnit.
+ *
- * runTransient.
- *
- * size.
- *
- * view.
- *
- * displayResult.
- *
+ * hasUnitName.
+ *
+ * getMeasurementDevice.
+ *
+ * getUnitNumber.
+ *
+ * replaceObject.
+ *
+ * getAllUnitNames.
+ *
- * reportMeasuredValues.
- *
+ * Getter for the field
+ * removeUnit.
+ *
+ * clearAll.
+ *
+ * clear.
+ *
+ * setFluid.
+ *
+ * setFluid.
+ *
- * save.
- *
+ * runAsThread.
+ *
- * open.
- *
- * reportResults.
- *
- * printLogFile.
- *
- * Getter for the field
- * Setter for the field
- * Getter for the field
- * Setter for the field
- * Get a SystemMechanicalDesign object from processSystem.
- *
- * Get a CostEstimateBaseClass object from processSystem.
- *
- * getEntropyProduction.
- *
- * getExergyChange.
- *
- * getPower.
- *
- * getCoolerDuty.
- *
- * getHeaterDuty.
- *
- * getMechanicalWeight.
- *
- * Getter for the field
- * Setter for the field
- * Create deep copy.
- *
- * getConditionMonitor.
- *
+ * runTransient.
+ *
+ * runTransient.
+ *
+ * Getter for the field
+ * Getter for the field
+ * size.
+ *
+ * view.
+ *
+ * displayResult.
+ *
+ * reportMeasuredValues.
+ *
+ * save.
+ *
+ * open.
+ *
+ * reportResults.
+ *
+ * printLogFile.
+ *
+ * Getter for the field
+ * Setter for the field
+ * Getter for the field
+ * Setter for the field
+ * Get a SystemMechanicalDesign object from processSystem.
+ *
+ * Get a CostEstimateBaseClass object from processSystem.
+ *
+ * getEntropyProduction.
+ *
+ * getExergyChange.
+ *
+ * getPower.
+ *
+ * getCoolerDuty.
+ *
+ * getHeaterDuty.
+ *
+ * getMechanicalWeight.
+ *
+ * Getter for the field
+ * Setter for the field
+ * Create deep copy.
+ *
+ * getConditionMonitor.
+ *
- * main.
- *
+ * main.
+ *
- * main.
- *
+ * main.
+ *
- * solveAbsorptionFactor.
- *
+ * solveAbsorptionFactor.
+ *
- * calcGlycolConcentration.
- *
- * calcKglycol.
- *
- * main.
- *
- * Getter for the field
- * Setter for the field
+ * calcGlycolConcentration.
+ *
+ * calcKglycol.
+ *
+ * main.
+ *
+ * Getter for the field
+ * Setter for the field
- * setOperationPressure.
- *
- * main.
- *
+ * setOperationPressure.
+ *
+ * main.
+ *
- * main.
- *
+ * main.
+ *
+ * Setter for the field
+ * Setter for the field
- * Setter for the field
- * Setter for the field
- * main.
- *
+ * main.
+ * SeparationTrainModule class.
+ * SeparationTrainModule class.
+ * main.
+ * main.
+ * SeparationTrainModuleSimple class.
+ * SeparationTrainModuleSimple class.
+ * main.
+ * main.
+ * WellFluidModule class.
+ * WellFluidModule class.
+ * main.
+ * main.
+ *
* checkFugacityCoefficientsDn2.
diff --git a/src/main/java/neqsim/thermo/atomElement/UNIFACgroup.java b/src/main/java/neqsim/thermo/atomElement/UNIFACgroup.java
index 23cceb4ab6..676c82259e 100644
--- a/src/main/java/neqsim/thermo/atomElement/UNIFACgroup.java
+++ b/src/main/java/neqsim/thermo/atomElement/UNIFACgroup.java
@@ -268,7 +268,6 @@ public boolean equals(Object obj) {
*/
}
-
/**
* Getter for property xComp.
*
diff --git a/src/main/java/neqsim/thermo/component/ComponentPRvolcor.java b/src/main/java/neqsim/thermo/component/ComponentPRvolcor.java
index 634ade1330..78c76de4e4 100644
--- a/src/main/java/neqsim/thermo/component/ComponentPRvolcor.java
+++ b/src/main/java/neqsim/thermo/component/ComponentPRvolcor.java
@@ -41,7 +41,6 @@ public double calccTT() {
return 0.;
}
-
public ComponentPRvolcor(String component_name, double moles, double molesInPhase,
int compnumber) {
super(component_name, moles, molesInPhase, compnumber);
@@ -57,7 +56,6 @@ public void init(double temp, double pres, double totMoles, double beta, int typ
c = calcc();
}
-
/** {@inheritDoc} */
// @Override
public double getc() {
@@ -89,12 +87,10 @@ public void Finit(PhaseInterface phase, double temp, double pres, double totMole
}
}
-
public double getCi() {
return Ci;
}
-
public double getCij(int j) {
return Cij[j];
}
@@ -102,7 +98,6 @@ public double getCij(int j) {
// depending on the type of the volume translation (T-dependent or not) these sould be properly
// modified
-
// second derivative of C with regards to mole fraction and temperature
public double getCiT() {
return 0;
@@ -112,9 +107,7 @@ public double getcTT() {
return 0;
}
-
-
- /// ** {@inheritDoc} */ do I need this inheritDoc thing?
+ /** {@inheritDoc} */
@Override
public double dFdN(PhaseInterface phase, int numberOfComponents, double temperature,
double pressure) {
@@ -127,7 +120,6 @@ public double getFC(PhaseInterface phase, int numberOfComponents, double tempera
return ((PhasePrEosvolcor) phase).FC();
}
-
/** {@inheritDoc} */
@Override
public double dFdNdT(PhaseInterface phase, int numberOfComponents, double temperature,
@@ -173,7 +165,6 @@ public double dFdNdN(int j, PhaseInterface phase, int numberOfComponents, double
+ phase.FD() * getAij(j);
}
-
/** {@inheritDoc} */
@Override
public double dFdNdV(PhaseInterface phase, int numberOfComponents, double temperature,
@@ -182,10 +173,7 @@ public double dFdNdV(PhaseInterface phase, int numberOfComponents, double temper
return phase.FnV() + phase.FBV() * getBi() + phase.FDV() * getAi() + loc_FCV * getCi();
}
-
-
// Remember this trick above that professor showed to you...you can call whichever new F
// expression
// you need by first specifying the type "PhasePrEosvolcor"
-
}
diff --git a/src/main/java/neqsim/thermo/component/ComponentUMRCPA.java b/src/main/java/neqsim/thermo/component/ComponentUMRCPA.java
index 2528010acb..837550442b 100644
--- a/src/main/java/neqsim/thermo/component/ComponentUMRCPA.java
+++ b/src/main/java/neqsim/thermo/component/ComponentUMRCPA.java
@@ -155,7 +155,6 @@ public void createComponent(String component_name, double moles, double molesInP
}
-
/** {@inheritDoc} */
@Override
public void init(double temperature, double pressure, double totalNumberOfMoles, double beta,
diff --git a/src/main/java/neqsim/thermo/component/attractiveEosTerm/AtractiveTermMatCopPRUMRNew.java b/src/main/java/neqsim/thermo/component/attractiveEosTerm/AtractiveTermMatCopPRUMRNew.java
index a2d85c4a08..df593acb50 100644
--- a/src/main/java/neqsim/thermo/component/attractiveEosTerm/AtractiveTermMatCopPRUMRNew.java
+++ b/src/main/java/neqsim/thermo/component/attractiveEosTerm/AtractiveTermMatCopPRUMRNew.java
@@ -164,7 +164,6 @@ public double diffdiffalphaT(double temperature) {
+ 5.0 / 4.0 * parameters[4] * Math.pow(1.0 - Math.sqrt(Tr), 4.0) / Tc2Trpower32);
}
-
@Override
public double diffaT(double temperature) {
if (useStandardAlphaForSupercritical && temperature / getComponent().getTC() > 1.0
diff --git a/src/main/java/neqsim/thermo/phase/PhaseInterface.java b/src/main/java/neqsim/thermo/phase/PhaseInterface.java
index 15a4317548..30165c4f0f 100644
--- a/src/main/java/neqsim/thermo/phase/PhaseInterface.java
+++ b/src/main/java/neqsim/thermo/phase/PhaseInterface.java
@@ -74,6 +74,13 @@ public interface PhaseInterface extends ThermodynamicConstantsInterface, Cloneab
*/
public double getDensity_AGA8();
+ /**
+ * method to get the Joule Thomson Coefficient of a phase note: implemented in phaseEos.
+ *
+ * @return Joule Thomson coefficient in K/bar
+ */
+ public double getJouleThomsonCoefficient();
+
/**
* method to get the Joule Thomson Coefficient of a phase note: implemented in phaseEos.
*
@@ -96,6 +103,13 @@ public interface PhaseInterface extends ThermodynamicConstantsInterface, Cloneab
*/
public void resetPhysicalProperties();
+ /**
+ * method to return phase volume note: without Peneloux volume correction.
+ *
+ * @return volume in unit m3*1e5
+ */
+ public double getVolume();
+
/**
* method to return fluid volume.
*
@@ -140,6 +154,38 @@ public default double getGamma2() {
*/
public double getWtFractionOfWaxFormingComponents();
+ /**
+ *
+ * getdrhodN.
+ *
+ * setInitType.
+ *
+ * init.
+ *
* init.
@@ -149,12 +195,10 @@ public default double getGamma2() {
/**
*
- * getdrhodN.
+ * initPhysicalProperties.
*
@@ -228,36 +272,6 @@ public default double getGamma2() {
*/
public double getMoleFraction();
- /**
- *
- * init.
- *
- * initPhysicalProperties.
- *
- * setInitType.
- *
* getcomponentArray.
@@ -365,6 +379,16 @@ public void removeComponent(String componentName, double moles, double molesInPh
*/
public double getFugacity(int compNumb);
+ /**
+ *
+ * getFugacity.
+ *
* setProperties.
@@ -526,6 +543,16 @@ public void removeComponent(String componentName, double moles, double molesInPh
*/
public void setMixingRuleGEModel(String name);
+ /**
+ *
+ * getComponent.
+ *
* getComponent.
@@ -536,6 +563,16 @@ public void removeComponent(String componentName, double moles, double molesInPh
*/
public ComponentInterface getComponent(int i);
+ /**
+ *
+ * getActivityCoefficient.
+ *
* getActivityCoefficient.
@@ -582,6 +619,16 @@ public void removeComponent(String componentName, double moles, double molesInPh
*/
public double getLogPureComponentFugacity(int k);
+ /**
+ *
+ * getPureComponentFugacity.
+ *
* getPureComponentFugacity.
@@ -593,6 +640,16 @@ public void removeComponent(String componentName, double moles, double molesInPh
*/
public double getPureComponentFugacity(int k, boolean pure);
+ /**
+ *
+ * addMolesChemReac.
+ *
* addMolesChemReac.
@@ -620,13 +677,13 @@ public void removeComponent(String componentName, double moles, double molesInPh
/**
*
- * getComponent.
+ * specify the type model for the physical properties you want to use. Type: 0 Orginal/default 1
+ * Water 2 Glycol 3 Amine
*
@@ -662,16 +719,6 @@ public void removeComponent(String componentName, double moles, double molesInPh
*/
public void setTemperature(double temperature);
- /**
- *
- * addMolesChemReac.
- *
* getPhysicalProperties.
@@ -1038,16 +1085,6 @@ public void removeComponent(String componentName, double moles, double molesInPh
*/
public double getZ();
- /**
- *
- * specify the type model for the physical properties you want to use. Type: 0 Orginal/default 1
- * Water 2 Glycol 3 Amine
- *
* getPseudoCriticalPressure.
@@ -1093,13 +1130,6 @@ public void removeComponent(String componentName, double moles, double molesInPh
*/
public void setNumberOfComponents(int k);
- /**
- * method to get the Joule Thomson Coefficient of a phase note: implemented in phaseEos.
- *
- * @return Joule Thomson coefficient in K/bar
- */
- public double getJouleThomsonCoefficient();
-
/**
*
* setMixingRule.
@@ -1163,15 +1193,6 @@ public void removeComponent(String componentName, double moles, double molesInPh
*/
public void setMolarVolume(double molarVolume);
- /**
- *
- * getPureComponentFugacity.
- *
- * getFugacity.
- *
- * getActivityCoefficient.
- *
* Getter for property mixingRuleNumber.
diff --git a/src/main/java/neqsim/thermo/phase/PhasePrEosvolcor.java b/src/main/java/neqsim/thermo/phase/PhasePrEosvolcor.java
index bdd6f15222..c1b853da90 100644
--- a/src/main/java/neqsim/thermo/phase/PhasePrEosvolcor.java
+++ b/src/main/java/neqsim/thermo/phase/PhasePrEosvolcor.java
@@ -38,12 +38,10 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int type, in
}
-
public double getCT() {
return CT;
}
-
public double getCTT() {
return 0;
}
@@ -69,8 +67,6 @@ public double dFdV() {
// note that in future the next thre lines should be modified to handle various mixing rules for
// the translation
-
-
public double getcij(ComponentEosInterface compArray, ComponentEosInterface compArray2) {
return ((((ComponentPRvolcor) compArray).getc()) + (((ComponentPRvolcor) compArray2).getc()))
* 0.5;
@@ -86,7 +82,6 @@ public double getcijTT(ComponentPRvolcor compi, ComponentPRvolcor compj) {
return 0;
}
-
// @Override
public double calcCi(int compNumb, PhaseInterface phase, double temperature, double pressure,
int numbcomp) {
@@ -102,7 +97,6 @@ public double calcCi(int compNumb, PhaseInterface phase, double temperature, dou
return Ci;
}
-
public double calcCij(int compNumb, int compNumbj, PhaseInterface phase, double temperature,
double pressure, int numbcomp) {
double cij = 0.0;
@@ -113,8 +107,6 @@ public double calcCij(int compNumb, int compNumbj, PhaseInterface phase, double
- ((ComponentPRvolcor) compArray[compNumbj]).getCi()) / phase.getNumberOfMolesInPhase();
}
-
-
public double calcCiT(int compNumb, PhaseInterface phase, double temperature, double pressure,
int numbcomp) {
double CiT = 0.0;
@@ -129,8 +121,6 @@ public double calcCiT(int compNumb, PhaseInterface phase, double temperature, do
return CiT;
}
-
-
public double calcCT(PhaseInterface phase, double temperature, double pressure, int numbcomp) {
return 0.0;
}
@@ -152,8 +142,6 @@ public double calcC(PhaseInterface phase, double temperature, double pressure,
return C;
}
-
-
private double loc_C() {
return calcC(this, temperature, pressure, numberOfComponents) ;
}
@@ -166,8 +154,6 @@ public double getC() {
return loc_C();
}
-
-
@Override
public double gV() {
return (getb() - getc())
@@ -228,8 +214,6 @@ public double fVVV() {
// val2 * val2));
}
-
-
// derivative of small g with regards to b
// problem with the loc_b in gb(),gc()-->it says that it is not visible and I think this is
// because loc_B is marked as private
@@ -317,7 +301,6 @@ public double gCC() {
return -1.0 / (val * val);
}
-
// Below are the partial derivatives of F with regards to model parameters
@Override
@@ -383,7 +366,6 @@ public double dFdTdT() {
+ FCC() * getCT() * getCT() + FC() * getCTT() + 2 * FCD() * getCT() * getAT();
}
-
@Override
public PhasePrEosvolcor clone() {
PhasePrEosvolcor clonedPhase = null;
diff --git a/src/main/java/neqsim/thermo/system/SystemInterface.java b/src/main/java/neqsim/thermo/system/SystemInterface.java
index 866f701dba..bfa0c7fc1d 100644
--- a/src/main/java/neqsim/thermo/system/SystemInterface.java
+++ b/src/main/java/neqsim/thermo/system/SystemInterface.java
@@ -25,6 +25,16 @@ public interface SystemInterface extends Cloneable, java.io.Serializable {
*/
public void saveFluid(int id);
+ /**
+ *
+ * saveFluid.
+ *
* getComponentNameTag.
@@ -101,7 +111,6 @@ public default void addComponents(String[] names) {
}
}
-
/**
* Add named components to a System with a number of moles. If component already exists, the moles
* will be added to the component.
@@ -127,6 +136,15 @@ public default String[][] calcResultTable() {
return createTable("");
}
+ /**
+ *
+ * getKinematicViscosity.
+ *
- * saveFluid.
- *
* getInterfacialTension.
@@ -289,13 +320,6 @@ public static SystemInterface addFluids(SystemInterface addFluid1, SystemInterfa
*/
public double getInterfacialTension(int phase1, int phase2, String unit);
- /**
- * Calculates physical properties of type propertyName.
- *
- * @param propertyName a {@link java.lang.String} object
- */
- public void initPhysicalProperties(String propertyName);
-
/**
* method to return heat capacity ratio calculated as Cp/(Cp-R).
*
@@ -312,6 +336,13 @@ public default double getGamma2() {
*/
public double getGamma();
+ /**
+ * method to return fluid volume.
+ *
+ * @return volume in unit m3*1e5
+ */
+ public double getVolume();
+
/**
* method to return fluid volume.
*
@@ -329,6 +360,13 @@ public default double getGamma2() {
*/
public double getFlowRate(String flowunit);
+ /**
+ * method to set the pressure of a fluid (same pressure for all phases).
+ *
+ * @param pres pressure in unit bara (absolute pressure in bar)
+ */
+ public void setPressure(double pres);
+
/**
* method to set the pressure of a fluid (same pressure for all phases).
*
@@ -337,6 +375,25 @@ public default double getGamma2() {
*/
public void setPressure(double newPressure, String unit);
+ /**
+ *
+ * method to set the temperature of a fluid (same temperature for all phases).
+ *
+ * setTemperature.
+ *
+ * phaseToSystem.
+ *
+ * phaseToSystem.
+ *
+ * phaseToSystem.
+ *
* phaseToSystem.
@@ -520,16 +606,6 @@ public default void removeMoles() {
*/
public neqsim.thermo.characterization.WaxCharacterise getWaxCharacterisation();
- /**
- *
- * phaseToSystem.
- *
@@ -720,15 +802,6 @@ public default void removeMoles() {
*/
public String[] getCompIDs();
- /**
- *
- * isImplementedCompositionDeriativesofFugacity.
- *
* saveObject.
@@ -1071,6 +1144,15 @@ public void addPlusFraction(String componentName, double numberOfMoles, double m
*/
public void addComponent(int index, double moles, int phaseNumber);
+ /**
+ *
+ * getBeta.
+ *
* getBeta.
@@ -1119,6 +1201,26 @@ public void addPlusFraction(String componentName, double numberOfMoles, double m
*/
public void setMixingRule(String typename, String GEmodel);
+ /**
+ * method to set mixing rule used for the fluid.
+ *
+ * @param type The type of mixing rule to be used for the fluid. 1 - classic mixing rule with all
+ * kij set to zero 2 -classic mixing rule with kij from NeqSim database 3- classic mixing
+ * rule with temperature dependent kij 4- Huron Vidal mixing rule with parameters from
+ * NeqSim database 7 -classic mixing rule with kij of CPA from NeqSim Database 9
+ * -classicmixing rule with temperature dependent kij of CPA from NeqSim database
+ * 10-classic mixing rule with temperature and composition dependent kij of CPA from NeqSim
+ * database
+ */
+ public void setMixingRule(int type);
+
+ /**
+ * method to set the mixing rule for the fluid.
+ *
+ * @param typename a {@link java.lang.String} object
+ */
+ public void setMixingRule(String typename);
+
/**
*
* normalizeBeta.
@@ -1150,27 +1252,27 @@ public void addPlusFraction(String componentName, double numberOfMoles, double m
* checkStability.
*
- * hasPlusFraction.
+ * checkStability.
*
- * checkStability.
+ * hasPlusFraction.
*
@@ -1233,13 +1335,6 @@ public void addPlusFraction(String componentName, double numberOfMoles, double m
*/
public void useVolumeCorrection(boolean volcor);
- /**
- * method to set the mixing rule for the fluid.
- *
- * @param typename a {@link java.lang.String} object
- */
- public void setMixingRule(String typename);
-
/**
*
* Getter for property numericDerivatives.
@@ -1327,6 +1422,15 @@ public void addPlusFraction(String componentName, double numberOfMoles, double m
*/
public void setSolidPhaseCheck(boolean test);
+ /**
+ *
+ * setSolidPhaseCheck.
+ *
* doSolidPhaseCheck.
@@ -1387,7 +1491,6 @@ public default void init() {
*/
public void init(int number, int phase);
-
/**
* Calculates thermodynamic properties of a fluid using the init(2) method.
*/
@@ -1409,22 +1512,22 @@ public default void initThermoProperties() {
/**
*
- * addFluid.
+ * display.
*
- * display.
+ * addFluid.
*
@@ -1501,14 +1604,6 @@ public double calcBeta()
*/
public void calc_x_y();
- /**
- * Get phase number i from SystemInterface object.
- *
- * @param i a int
- * @return a {@link neqsim.thermo.phase.PhaseInterface} object
- */
- public PhaseInterface getPhase(int i);
-
/**
*
* reset_x_y.
@@ -1516,15 +1611,6 @@ public double calcBeta()
*/
public void reset_x_y();
- /**
- *
- * isChemicalSystem.
- * unitOperations
.
- * time
.
- * time
.
- * unitOperations
.
+ * timeStep
.
- * timeStep
.
- * name
.
- * name
.
- * surroundingTemperature
.
- * surroundingTemperature
.
- * time
.
+ * time
.
+ * timeStep
.
+ * timeStep
.
+ * name
.
+ * name
.
+ * surroundingTemperature
.
+ * surroundingTemperature
.
+ * flashPressure
.
- * flashPressure
.
- * flashPressure
.
+ * flashPressure
.
+ * condenserTemperature
.
+ * vaporizerTemperature
.
+ * condenserTemperature
.
- * vaporizerTemperature
.
- *
- * removePhase. + * setBeta. *
* - * @param specPhase a int + * @param phase a int + * @param b a double */ - public void removePhase(int specPhase); + public void setBeta(int phase, double b); /** *- * phaseToSystem. + * removePhase. *
* - * @param newPhase a {@link neqsim.thermo.phase.PhaseInterface} object - * @return a {@link neqsim.thermo.system.SystemInterface} object + * @param specPhase a int */ - public SystemInterface phaseToSystem(PhaseInterface newPhase); + public void removePhase(int specPhase); + + // public void setPressure(double newPressure, int phaseNumber); /** - *- * method to set the temperature of a fluid (same temperature for all phases). - *
+ * method to return pressure. * - * @param temp a double + * @return pressure in unit bara */ - public void setTemperature(double temp); + public double getPressure(); /** *- * setTemperature. + * method to return pressure of phase. *
* - * @param newTemperature a double * @param phaseNumber a int + * @return a double */ - public void setTemperature(double newTemperature, int phaseNumber); - // public void setPressure(double newPressure, int phaseNumber); - - /** - * method to set the pressure of a fluid (same pressure for all phases). - * - * @param pres pressure in unit bara (absolute pressure in bar) - */ - public void setPressure(double pres); - - /** - * method to return pressure. - * - * @return pressure in unit bara - */ - public double getPressure(); + public double getPressure(int phaseNumber); /** * method to return pressure in a specified unit. @@ -1632,16 +1702,6 @@ public double calcBeta() */ public void clearAll(); - /** - *- * method to return pressure of phase. - *
- * - * @param phaseNumber a int - * @return a double - */ - public double getPressure(int phaseNumber); - /** * method to get density of a fluid note: without Peneloux volume correction. * @@ -1657,13 +1717,6 @@ public double calcBeta() */ public double getDensity(String unit); - /** - * method to return fluid volume. - * - * @return volume in unit m3*1e5 - */ - public double getVolume(); - /** ** getChemicalReactionOperations. @@ -1682,6 +1735,15 @@ public double calcBeta() */ public boolean isChemicalSystem(); + /** + *
+ * isChemicalSystem. + *
+ * + * @param temp a boolean + */ + public void isChemicalSystem(boolean temp); + /** * method to return molar volume of the fluid note: without Peneloux volume correction. * @@ -1696,6 +1758,14 @@ public double calcBeta() */ public double getMolarMass(); + /** + * method to get molar mass of a fluid phase. + * + * @param unit Supported units are kg/mol, gr/mol + * @return molar mass in specified unit + */ + public double getMolarMass(String unit); + /** * method to get the total enthalpy of a fluid. * @@ -1703,6 +1773,14 @@ public double calcBeta() */ public double getEnthalpy(); + /** + * method to return total enthalpy in a specified unit. + * + * @param unit Supported units are 'J', 'J/mol', 'J/kg' and 'kJ/kg' + * @return enthalpy in specified unit + */ + public double getEnthalpy(String unit); + /** ** calcInterfaceProperties. @@ -1776,15 +1854,6 @@ public double calcBeta() */ public double getTemperature(int phaseNumber); - /** - *
- * getBeta. - *
- * - * @return a double - */ - public double getBeta(); - /** ** chemicalReactionInit. @@ -1792,30 +1861,35 @@ public double calcBeta() */ public void chemicalReactionInit(); - /** - * Init physical properties for all phases and interfaces. - */ - public void initPhysicalProperties(); + // public double getdfugdt(int i, int j); /** *
- * setBeta. + * method to set the phase type of a given phase. *
* - * @param b a double + * @param phaseToChange a int + * @param newPhaseType a int */ - public void setBeta(double b); - // public double getdfugdt(int i, int j); + public void setPhaseType(int phaseToChange, int newPhaseType); /** *- * method to set the phase type of a given phase. + * setPhaseType. *
* - * @param phaseToChange a int + * @param phases a {@link java.lang.String} object * @param newPhaseType a int */ - public void setPhaseType(int phaseToChange, int newPhaseType); + public void setPhaseType(String phases, int newPhaseType); + + /** + * method to set the phase type of a given phase. + * + * @param phaseToChange the phase number of the phase to set phase type + * @param phaseTypeName the phase type name (valid names are gas or liquid) + */ + public void setPhaseType(int phaseToChange, String phaseTypeName); /** *@@ -1889,13 +1963,6 @@ public double calcBeta() */ public double getGibbsEnergy(); - /** - * method to return internal energy (U) in unit J. - * - * @return internal energy in unit Joule (J) - */ - public double getInternalEnergy(); - /** *
* getHelmholtzEnergy. @@ -1943,19 +2010,6 @@ public double calcBeta() */ public SystemInterface clone(); - /** - * method to set mixing rule used for the fluid. - * - * @param type The type of mixing rule to be used for the fluid. 1 - classic mixing rule with all - * kij set to zero 2 -classic mixing rule with kij from NeqSim database 3- classic mixing - * rule with temperature dependent kij 4- Huron Vidal mixing rule with parameters from - * NeqSim database 7 -classic mixing rule with kij of CPA from NeqSim Database 9 - * -classicmixing rule with temperature dependent kij of CPA from NeqSim database - * 10-classic mixing rule with temperature and composition dependent kij of CPA from NeqSim - * database - */ - public void setMixingRule(int type); - /** *
* getComponentNames. @@ -2001,8 +2055,9 @@ public double calcBeta() /** * method to return heat capacity ratio/adiabatic index/Poisson constant. * - * @return kappa */ - + * @return kappa + */ + public double getKappa(); /** @@ -2090,34 +2145,6 @@ public double calcBeta() */ public double getThermalConductivity(String unit); - /** - * method to return interfacial tension between two phases. - * - * @param phase1 phase type of phase1 as string (valid phases are gas, oil, aqueous) - * @param phase2 phase type of phase2 as string (valid phases are gas, oil, aqueous) - * @return interfacial tension with unit N/m. If one or both phases does not exist - the method - * will return NaN - */ - public double getInterfacialTension(String phase1, String phase2); - - /** - * method to return interfacial tension between two phases. - * - * @param phase1 phase number of phase1 - * @param phase2 phase number of phase2 - * @return interfacial tension with unit N/m - */ - public double getInterfacialTension(int phase1, int phase2); - - /** - *
- * getKinematicViscosity. - *
- * - * @return a double - */ - public double getKinematicViscosity(); - /** ** initRefPhases. @@ -2143,15 +2170,6 @@ public double calcBeta() */ public void setFluidName(java.lang.String fluidName); - /** - *
- * setSolidPhaseCheck. - *
- * - * @param solidComponent a {@link java.lang.String} object - */ - public void setSolidPhaseCheck(String solidComponent); - /** ** Getter for property allowPhaseShift. @@ -2179,25 +2197,6 @@ public double calcBeta() */ public double getPhaseFraction(String phaseTypeName, String unit); - /** - *
- * setPhaseType. - *
- * - * @param phases a {@link java.lang.String} object - * @param newPhaseType a int - */ - public void setPhaseType(String phases, int newPhaseType); - - /** - * method to set the phase type of a given phase. - * - * @param phaseToChange the phase number of the phase to set phase type - * @param phaseTypeName the phase type name (valid names are gas or liquid) - */ - public void setPhaseType(int phaseToChange, String phaseTypeName); - - /** ** getProperty. @@ -2339,16 +2338,6 @@ public double calcBeta() */ public void setTotalNumberOfMoles(double totalNumberOfMoles); - /** - *
- * phaseToSystem. - *
- * - * @param phaseNumber a int - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface phaseToSystem(int phaseNumber); - /** ** hasPhaseType. @@ -2435,6 +2424,15 @@ public void setImplementedPressureDeriativesofFugacity( */ public boolean isImplementedCompositionDeriativesofFugacity(); + /** + *
+ * isImplementedCompositionDeriativesofFugacity. + *
+ * + * @param isImpl a boolean + */ + public void isImplementedCompositionDeriativesofFugacity(boolean isImpl); + /** ** setImplementedCompositionDeriativesofFugacity. diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index e83c22c909..511cad5d22 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -14,14 +14,11 @@ import java.sql.ResultSet; import java.text.FieldPosition; import java.util.ArrayList; - import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - import neqsim.chemicalReactions.ChemicalReactionOperations; import neqsim.physicalProperties.interfaceProperties.InterfaceProperties; import neqsim.physicalProperties.interfaceProperties.InterphasePropertiesInterface; @@ -549,28 +546,6 @@ public void replacePhase(int repPhase, PhaseInterface newPhase) { setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); } - /** {@inheritDoc} */ - @Override - public SystemInterface phaseToSystem(PhaseInterface newPhase) { - for (int i = 0; i < newPhase.getNumberOfComponents(); i++) { - newPhase.getComponents()[i] - .setNumberOfmoles(newPhase.getComponents()[i].getNumberOfMolesInPhase()); - } - - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - phaseArray[i] = newPhase.clone(); - } - - setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); - this.init(0); - setNumberOfPhases(1); - setPhaseType(0, newPhase.getPhaseType()); - initBeta(); - init_x_y(); - this.init(1); - return this; - } - /** {@inheritDoc} */ @Override public SystemInterface getEmptySystemClone() { @@ -595,6 +570,28 @@ public SystemInterface getEmptySystemClone() { return newSystem; } + /** {@inheritDoc} */ + @Override + public SystemInterface phaseToSystem(PhaseInterface newPhase) { + for (int i = 0; i < newPhase.getNumberOfComponents(); i++) { + newPhase.getComponents()[i] + .setNumberOfmoles(newPhase.getComponents()[i].getNumberOfMolesInPhase()); + } + + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + phaseArray[i] = newPhase.clone(); + } + + setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); + this.init(0); + setNumberOfPhases(1); + setPhaseType(0, newPhase.getPhaseType()); + initBeta(); + init_x_y(); + this.init(1); + return this; + } + /** {@inheritDoc} */ @Override public SystemInterface phaseToSystem(String phaseName) { @@ -1738,17 +1735,6 @@ public void init(int type) { } } - /** {@inheritDoc} */ - @Override - public void initProperties() { - if (!isInitialized) { - init(0); - setNumberOfPhases(1); - } - initThermoProperties(); - initPhysicalProperties(); - } - /** {@inheritDoc} */ @Override public void init(int type, int phase) { @@ -2148,6 +2134,17 @@ public void initNumeric() { } } + /** {@inheritDoc} */ + @Override + public void initProperties() { + if (!isInitialized) { + init(0); + setNumberOfPhases(1); + } + initThermoProperties(); + initPhysicalProperties(); + } + /** {@inheritDoc} */ @Override public void initPhysicalProperties() { @@ -2229,9 +2226,6 @@ public final PhaseInterface getLiquidPhase() { } /** @{inheritdoc} */ - /** - * @return IsPhase true or false - */ @Override public boolean IsPhase(int i) { if (i > phaseArray.length) { @@ -2252,6 +2246,50 @@ public final PhaseInterface getPhase(int i) { return phaseArray[phaseIndex[i]]; } + /** {@inheritDoc} */ + @Override + public PhaseInterface getPhase(String phaseTypeName) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { + return getPhase(i); + } + } + throw new RuntimeException(); + } + + /** {@inheritDoc} */ + @Override + public int getPhaseNumberOfPhase(String phaseTypeName) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { + return i; + } + } + return 0; + } + + /** {@inheritDoc} */ + @Override + public int getPhaseIndexOfPhase(String phaseTypeName) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { + return phaseIndex[i]; + } + } + return phaseIndex[0]; + } + + /** {@inheritDoc} */ + @Override + public PhaseInterface getPhaseOfType(String phaseName) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseName)) { + return getPhase(i); + } + } + return null; + } + /** {@inheritDoc} */ @Override public final boolean isChemicalSystem() { @@ -2300,6 +2338,21 @@ public final void setPC(double PC) { criticalPressure = PC; } + /** + *
+ * setMixingRuleGEmodel. + *
+ * + * @param name a {@link java.lang.String} object + */ + public void setMixingRuleGEmodel(String name) { + for (PhaseInterface tmpPhase : phaseArray) { + if (tmpPhase != null) { + tmpPhase.setMixingRuleGEModel(name); + } + } + } + /** {@inheritDoc} */ @Override public final void setMixingRule(int type) { @@ -2316,21 +2369,6 @@ public final void setMixingRule(int type) { } } - /** - *- * setMixingRuleGEmodel. - *
- * - * @param name a {@link java.lang.String} object - */ - public void setMixingRuleGEmodel(String name) { - for (PhaseInterface tmpPhase : phaseArray) { - if (tmpPhase != null) { - tmpPhase.setMixingRuleGEModel(name); - } - } - } - /** {@inheritDoc} */ @Override public void setMixingRule(String typename, String GEmodel) { @@ -2765,6 +2803,12 @@ public void setTemperature(double newTemperature) { } } + /** {@inheritDoc} */ + @Override + public final void setTemperature(double newTemperature, int phase) { + getPhase(phaseIndex[phase]).setTemperature(newTemperature); + } + /** {@inheritDoc} */ @Override public void setTemperature(double newTemperature, String unit) { @@ -2887,12 +2931,6 @@ public final void setPressure(double newPressure, String unit) { } } - /** {@inheritDoc} */ - @Override - public final void setTemperature(double newPressure, int phase) { - getPhase(phaseIndex[phase]).setTemperature(newPressure); - } - /** {@inheritDoc} */ @Override public final double getTemperature() { @@ -2902,7 +2940,8 @@ public final double getTemperature() { /** {@inheritDoc} */ @Override public final double getTemperature(String unit) { - neqsim.util.unit.TemperatureUnit tempConversion = new neqsim.util.unit.TemperatureUnit(getTemperature(), "K"); + neqsim.util.unit.TemperatureUnit tempConversion = + new neqsim.util.unit.TemperatureUnit(getTemperature(), "K"); return tempConversion.getValue(unit); } @@ -2921,7 +2960,8 @@ public final double getPressure() { /** {@inheritDoc} */ @Override public final double getPressure(String unit) { - neqsim.util.unit.PressureUnit presConversion = new neqsim.util.unit.PressureUnit(getPressure(), "bara"); + neqsim.util.unit.PressureUnit presConversion = + new neqsim.util.unit.PressureUnit(getPressure(), "bara"); return presConversion.getValue(unit); } @@ -3207,18 +3247,6 @@ public double getInterfacialTension(String phase1, String phase2) { } } - /** - *- * write. - *
- * - * @return a {@link java.lang.String} object - */ - public String write() { - // create a String description of the system - return ""; - } - /** {@inheritDoc} */ @Override public void normalizeBeta() { @@ -3231,12 +3259,6 @@ public void normalizeBeta() { } } - /** {@inheritDoc} */ - @Override - public void display() { - display(this.getFluidName()); - } - /** {@inheritDoc} */ @Override public String[][] createTable(String name) { @@ -3451,6 +3473,12 @@ public String[][] createTable(String name) { return table; } + /** {@inheritDoc} */ + @Override + public void display() { + display(this.getFluidName()); + } + /** {@inheritDoc} */ @Override public void display(String name) { @@ -3475,6 +3503,18 @@ public void display(String name) { dialog.setVisible(true); } + /** + *+ * write. + *
+ * + * @return a {@link java.lang.String} object + */ + public String write() { + // create a String description of the system + return ""; + } + /** {@inheritDoc} */ @Override public void write(String name, String filename, boolean newfile) { @@ -4569,50 +4609,6 @@ public boolean hasPhaseType(String phaseTypeName) { return false; } - /** {@inheritDoc} */ - @Override - public PhaseInterface getPhase(String phaseTypeName) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { - return getPhase(i); - } - } - throw new RuntimeException(); - } - - /** {@inheritDoc} */ - @Override - public int getPhaseNumberOfPhase(String phaseTypeName) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { - return i; - } - } - return 0; - } - - /** {@inheritDoc} */ - @Override - public int getPhaseIndexOfPhase(String phaseTypeName) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { - return phaseIndex[i]; - } - } - return phaseIndex[0]; - } - - /** {@inheritDoc} */ - @Override - public PhaseInterface getPhaseOfType(String phaseName) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseName)) { - return getPhase(i); - } - } - return null; - } - /** {@inheritDoc} */ @Override public double calcHenrysConstant(String component) { @@ -4659,21 +4655,21 @@ public void setBmixType(int bmixType) { /** {@inheritDoc} */ @Override - public boolean isImplementedTemperatureDeriativesofFugacity() { - return implementedTemperatureDeriativesofFugacity; + public boolean isImplementedCompositionDeriativesofFugacity() { + return implementedCompositionDeriativesofFugacity; } /** {@inheritDoc} */ @Override - public void setImplementedTemperatureDeriativesofFugacity( - boolean implementedTemperatureDeriativesofFugacity) { - this.implementedTemperatureDeriativesofFugacity = implementedTemperatureDeriativesofFugacity; + public void isImplementedCompositionDeriativesofFugacity(boolean isImpl) { + this.implementedCompositionDeriativesofFugacity = isImpl; } /** {@inheritDoc} */ @Override - public boolean isImplementedPressureDeriativesofFugacity() { - return implementedPressureDeriativesofFugacity; + public void setImplementedCompositionDeriativesofFugacity( + boolean implementedCompositionDeriativesofFugacity) { + this.implementedCompositionDeriativesofFugacity = implementedCompositionDeriativesofFugacity; } /** {@inheritDoc} */ @@ -4685,15 +4681,21 @@ public void setImplementedPressureDeriativesofFugacity( /** {@inheritDoc} */ @Override - public boolean isImplementedCompositionDeriativesofFugacity() { - return implementedCompositionDeriativesofFugacity; + public boolean isImplementedPressureDeriativesofFugacity() { + return implementedPressureDeriativesofFugacity; } /** {@inheritDoc} */ @Override - public void setImplementedCompositionDeriativesofFugacity( - boolean implementedCompositionDeriativesofFugacity) { - this.implementedCompositionDeriativesofFugacity = implementedCompositionDeriativesofFugacity; + public boolean isImplementedTemperatureDeriativesofFugacity() { + return implementedTemperatureDeriativesofFugacity; + } + + /** {@inheritDoc} */ + @Override + public void setImplementedTemperatureDeriativesofFugacity( + boolean implementedTemperatureDeriativesofFugacity) { + this.implementedTemperatureDeriativesofFugacity = implementedTemperatureDeriativesofFugacity; } /** {@inheritDoc} */ @@ -4720,19 +4722,19 @@ public void setMaxNumberOfPhases(int maxNumberOfPhases) { /** {@inheritDoc} */ @Override public void setMolarComposition(double[] molefractions) { - setMolarComposition(molefractions, ""); + setMolarFractions(molefractions, ""); } /** {@inheritDoc} */ @Override public void setMolarCompositionPlus(double[] molefractions) { - setMolarComposition(molefractions, "Plus"); + setMolarFractions(molefractions, "Plus"); } /** {@inheritDoc} */ @Override public void setMolarCompositionOfPlusFluid(double[] molefractions) { - setMolarComposition(molefractions, "PlusFluid"); + setMolarFractions(molefractions, "PlusFluid"); } /** {@inheritDoc} */ @@ -5001,12 +5003,6 @@ public double getMoleFraction(int phaseNumber) { return getPhase(phaseNumber).getBeta(); } - /** {@inheritDoc} */ - @Override - public void isImplementedCompositionDeriativesofFugacity(boolean isImpl) { - implementedCompositionDeriativesofFugacity = isImpl; - } - /** {@inheritDoc} */ @Override public void addCapeOpenProperty(String propertyName) { @@ -5074,7 +5070,7 @@ public SystemProperties getProperties() { return new SystemProperties(this); } - private void setMolarComposition(double[] molefractions, String type) { + private void setMolarFractions(double[] molefractions, String type) { double totalFlow = getTotalNumberOfMoles(); if (totalFlow < 1e-100) { String msg = "must be larger than 0 (1e-100) when setting molar composition"; diff --git a/src/main/java/neqsim/thermo/system/SystemUMRCPAEoS.java b/src/main/java/neqsim/thermo/system/SystemUMRCPAEoS.java index 6698fdf7da..f61f10ab41 100644 --- a/src/main/java/neqsim/thermo/system/SystemUMRCPAEoS.java +++ b/src/main/java/neqsim/thermo/system/SystemUMRCPAEoS.java @@ -19,7 +19,6 @@ */ public class SystemUMRCPAEoS extends SystemPrEos { - public SystemUMRCPAEoS() { super(); modelName = "UMR-CPA"; diff --git a/src/main/java/neqsim/thermo/system/SystemUMRPRUMCEosNew.java b/src/main/java/neqsim/thermo/system/SystemUMRPRUMCEosNew.java index 837bd691ee..698c9276d7 100644 --- a/src/main/java/neqsim/thermo/system/SystemUMRPRUMCEosNew.java +++ b/src/main/java/neqsim/thermo/system/SystemUMRPRUMCEosNew.java @@ -19,7 +19,6 @@ */ public class SystemUMRPRUMCEosNew extends SystemUMRPRUMCEos { - public SystemUMRPRUMCEosNew() { super(); modelName = "UMR-PRU-MC-EoS-New"; diff --git a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java index 1e734d6db5..0b4c4aaeb6 100644 --- a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java +++ b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java @@ -164,16 +164,6 @@ public void TPflash() { } } - /** - *- * saturateWithWater. - *
- */ - public void saturateWithWater() { - operation = new SaturateWithWater(system); - getOperation().run(); - } - /** ** TPflash. @@ -213,6 +203,16 @@ public void dTPflash(String[] comps) { getOperation().run(); } + /** + *
+ * saturateWithWater. + *
+ */ + public void saturateWithWater() { + operation = new SaturateWithWater(system); + getOperation().run(); + } + /** ** chemicalEquilibrium. @@ -264,6 +264,8 @@ public void PHflash(double Hspec, String enthalpyUnit) { case "kJ/kg": conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; + default: + break; } PHflash(Hspec / conversionFactor); } @@ -338,6 +340,8 @@ public void PUflash(double Uspec, String unitEnergy) { conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; + default: + break; } PUflash(Uspec / conversionFactorEntr); } @@ -377,6 +381,22 @@ public void PHsolidFlash(double Hspec) { getOperation().run(); } + /** + *
+ * PSflash. + *
+ * + * @param Sspec a double + */ + public void PSflash(double Sspec) { + if (system.getPhase(0).getNumberOfComponents() == 1) { + operation = new PSflashSingleComp(system, Sspec, 0); + } else { + operation = new PSFlash(system, Sspec, 0); + } + getOperation().run(); + } + /** * Method to perform a PS flash calculation for a specified entropy and pressure * @@ -387,7 +407,6 @@ public void PSflash(double Sspec, String unit) { double conversionFactor = 1.0; switch (unit) { case "J/K": - conversionFactor = 1.0; break; case "J/molK": conversionFactor = 1.0 / system.getTotalNumberOfMoles(); @@ -398,10 +417,24 @@ public void PSflash(double Sspec, String unit) { case "kJ/kgK": conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; + default: + break; } PSflash(Sspec / conversionFactor); } + /** + *+ * TSflash. + *
+ * + * @param Sspec a double + */ + public void TSflash(double Sspec) { + operation = new TSFlash(system, Sspec); + getOperation().run(); + } + /** * Method to perform a TS flash calculation for a specified entropy and pressure * @@ -423,26 +456,12 @@ public void TSflash(double Sspec, String unit) { case "kJ/kgK": conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; + default: + break; } TSflash(Sspec / conversionFactor); } - /** - *- * PSflash. - *
- * - * @param Sspec a double - */ - public void PSflash(double Sspec) { - if (system.getPhase(0).getNumberOfComponents() == 1) { - operation = new PSflashSingleComp(system, Sspec, 0); - } else { - operation = new PSFlash(system, Sspec, 0); - } - getOperation().run(); - } - /** ** PSflashGERG2008. @@ -456,18 +475,6 @@ public void PSflashGERG2008(double Sspec) { getOperation().run(); } - /** - *
- * TSflash. - *
- * - * @param Sspec a double - */ - public void TSflash(double Sspec) { - operation = new TSFlash(system, Sspec); - getOperation().run(); - } - /** ** PSflash2. @@ -498,6 +505,8 @@ public void VSflash(double volume, double entropy, String unitVol, String unitEn case "m3": conversionFactorV = 1.0e5; break; + default: + break; } switch (unitEntropy) { @@ -514,6 +523,8 @@ public void VSflash(double volume, double entropy, String unitVol, String unitEn conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; + default: + break; } VSflash(volume * conversionFactorV, entropy / conversionFactorEntr); } @@ -545,6 +556,8 @@ public void TVflash(double Vspec, String unit) { case "m3": conversionFactor = 1.0e5; break; + default: + break; } TVflash(Vspec * conversionFactor); } @@ -605,6 +618,8 @@ public void VHflash(double volume, double enthalpy, String unitVol, String unitE case "m3": conversionFactorV = 1.0e5; break; + default: + break; } switch (unitEnthalpy) { @@ -621,6 +636,8 @@ public void VHflash(double volume, double enthalpy, String unitVol, String unitE conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; + default: + break; } VHflash(volume * conversionFactorV, enthalpy / conversionFactorEntr); } @@ -643,6 +660,8 @@ public void VUflash(double volume, double energy, String unitVol, String unitEne case "m3": conversionFactorV = 1.0e5; break; + default: + break; } switch (unitEnergy) { @@ -659,6 +678,8 @@ public void VUflash(double volume, double energy, String unitVol, String unitEne conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; break; + default: + break; } VUflash(volume * conversionFactorV, energy / conversionFactorEntr); } @@ -1126,6 +1147,39 @@ public void hydrateFormationTemperature() throws Exception { // system.getPhase(4).getComponent("water")).getHydrateStructure() + 1)); } + /** + *
+ * hydrateFormationTemperature. + *
+ * + * @param structure a int + * @throws java.lang.Exception if any. + */ + public void hydrateFormationTemperature(int structure) throws Exception { + system.setTemperature(273.0 + 1.0); + if (structure == 0) { + system.setSolidPhaseCheck("water"); + system.setHydrateCheck(true); + operation = new freezingPointTemperatureFlash(system); + } else { + operation = new HydrateFormationTemperatureFlash(system); + } + + for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { + ((ComponentHydrate) system.getPhases()[4].getComponent(i)).setHydrateStructure(structure - 1); + } + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "hydrateFormationTemperature", "Could not find solution - possible no dew point exists"); + } + } + /** ** hydrateEquilibriumLine. @@ -1200,39 +1254,6 @@ public void waterDewPointLine(double minimumPressure, double maximumPressure) th } } - /** - *
- * hydrateFormationTemperature. - *
- * - * @param structure a int - * @throws java.lang.Exception if any. - */ - public void hydrateFormationTemperature(int structure) throws Exception { - system.setTemperature(273.0 + 1.0); - if (structure == 0) { - system.setSolidPhaseCheck("water"); - system.setHydrateCheck(true); - operation = new freezingPointTemperatureFlash(system); - } else { - operation = new HydrateFormationTemperatureFlash(system); - } - - for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { - ((ComponentHydrate) system.getPhases()[4].getComponent(i)).setHydrateStructure(structure - 1); - } - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "hydrateFormationTemperature", "Could not find solution - possible no dew point exists"); - } - } - /** ** calcCricondenBar. @@ -1269,6 +1290,28 @@ public void bubblePointPressureFlash() throws Exception { } } + /** + *
+ * bubblePointPressureFlash. + *
+ * + * @param derivatives a boolean + * @throws java.lang.Exception if any. + */ + public void bubblePointPressureFlash(boolean derivatives) throws Exception { + constantDutyFlashInterface operation = null; + if (derivatives == true) { + operation = new bubblePointPressureFlashDer(system); + } else { + operation = new bubblePointPressureFlash(system); + } + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); + } + } + /** ** constantPhaseFractionPressureFlash. @@ -1323,28 +1366,6 @@ public void constantPhaseFractionTemperatureFlash(double fraction) throws Except } } - /** - *
- * bubblePointPressureFlash. - *
- * - * @param derivatives a boolean - * @throws java.lang.Exception if any. - */ - public void bubblePointPressureFlash(boolean derivatives) throws Exception { - constantDutyFlashInterface operation = null; - if (derivatives == true) { - operation = new bubblePointPressureFlashDer(system); - } else { - operation = new bubblePointPressureFlash(system); - } - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); - } - } - /** ** dewPointMach. @@ -1368,7 +1389,8 @@ public void dewPointMach(String componentName, String specification, double spec throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), "dewPointMach", "Specified component is not present in mixture: " + componentName); } - double newTemperature = system.getTemperature(), oldTemperature = newTemperature; + double newTemperature = system.getTemperature(); + double oldTemperature = newTemperature; int iterations = 0; if (specification.equals("dewPointTemperature")) { // logger.info("new temperature " + newTemperature); @@ -1476,6 +1498,17 @@ public void dewPointPressureFlash() throws Exception { // } } + /** + *
+ * getJfreeChart. + *
+ * + * @return a {@link org.jfree.chart.JFreeChart} object + */ + public org.jfree.chart.JFreeChart getJfreeChart() { + return getOperation().getJFreeChart(""); + } + // public void dewPointPressureFlash(){ // constantDutyFlashInterface operation = new constantDutyPressureFlash(system); // operation.setBeta((1-1e-7)); @@ -1552,13 +1585,18 @@ public void calcPTphaseEnvelope(boolean bubfirst) { /** *- * getJfreeChart. + * calcPTphaseEnvelope. *
* - * @return a {@link org.jfree.chart.JFreeChart} object + * @param lowPres a double + * @param phasefraction a double */ - public org.jfree.chart.JFreeChart getJfreeChart() { - return getOperation().getJFreeChart(""); + public void calcPTphaseEnvelope(double lowPres, double phasefraction) { + operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, true); + + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); } /** @@ -1572,22 +1610,6 @@ public void calcPTphaseEnvelopeNew() { getOperation().run(); } - /** - *- * calcPTphaseEnvelope. - *
- * - * @param lowPres a double - * @param phasefraction a double - */ - public void calcPTphaseEnvelope(double lowPres, double phasefraction) { - operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, true); - - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - /** ** OLGApropTable. diff --git a/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java b/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java index c5750fb974..8cc0da7b39 100644 --- a/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java +++ b/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java @@ -6,7 +6,6 @@ import neqsim.fluidMechanics.flowSystem.FlowSystemInterface; import neqsim.thermo.system.SystemInterface; - public class PipeFlowSystemTest extends neqsim.NeqSimTest { FlowSystemInterface pipe; diff --git a/src/test/java/neqsim/processSimulation/measurementDevice/WellAllocatorTest.java b/src/test/java/neqsim/processSimulation/measurementDevice/WellAllocatorTest.java index 07d3470d6d..cb925ffaaf 100644 --- a/src/test/java/neqsim/processSimulation/measurementDevice/WellAllocatorTest.java +++ b/src/test/java/neqsim/processSimulation/measurementDevice/WellAllocatorTest.java @@ -45,10 +45,8 @@ void testGetMeasuredValueString() { testFluid.setPressure(48.0, "bara"); testFluid.setTotalFlowRate(2500.0, "kg/hr"); - SystemInterface testFluid2 = testFluid.clone(); - testFluid.setTemperature(24.0, "C"); testFluid.setPressure(48.0, "bara"); testFluid.setTotalFlowRate(2500.0, "kg/hr"); diff --git a/src/test/java/neqsim/processSimulation/processSystem/GlycolRigTest.java b/src/test/java/neqsim/processSimulation/processSystem/GlycolRigTest.java index 500cf8ef75..d8ba2ac96b 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/GlycolRigTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/GlycolRigTest.java @@ -1,42 +1,27 @@ package neqsim.processSimulation.processSystem; -import java.util.ArrayList; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import neqsim.processSimulation.measurementDevice.HydrateEquilibriumTemperatureAnalyser; -import neqsim.processSimulation.processEquipment.ProcessEquipmentInterface; -import neqsim.processSimulation.processEquipment.absorber.SimpleTEGAbsorber; import neqsim.processSimulation.processEquipment.absorber.WaterStripperColumn; import neqsim.processSimulation.processEquipment.compressor.Compressor; import neqsim.processSimulation.processEquipment.distillation.DistillationColumn; -import neqsim.processSimulation.processEquipment.filter.Filter; -import neqsim.processSimulation.processEquipment.heatExchanger.HeatExchanger; import neqsim.processSimulation.processEquipment.heatExchanger.Heater; import neqsim.processSimulation.processEquipment.mixer.Mixer; -import neqsim.processSimulation.processEquipment.mixer.StaticMixer; -import neqsim.processSimulation.processEquipment.pump.Pump; import neqsim.processSimulation.processEquipment.separator.Separator; import neqsim.processSimulation.processEquipment.stream.Stream; -import neqsim.processSimulation.processEquipment.util.Calculator; import neqsim.processSimulation.processEquipment.util.Recycle; -import neqsim.processSimulation.processEquipment.util.SetPoint; -import neqsim.processSimulation.processEquipment.util.StreamSaturatorUtil; -import neqsim.processSimulation.processEquipment.valve.ThrottlingValve; -import neqsim.thermodynamicOperations.ThermodynamicOperations; public class GlycolRigTest extends neqsim.NeqSimTest { ProcessSystem p; String _name = "TestProcess"; - @BeforeEach public void setUp() { p = new ProcessSystem(); p.setName(_name); } - @Test public void runTEGProcessTest() { neqsim.thermo.system.SystemInterface feedTEG = diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java index e8d07020b5..2d0e9699ca 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java @@ -1,8 +1,10 @@ package neqsim.processSimulation.processSystem; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import neqsim.processSimulation.SimulationInterface; import neqsim.processSimulation.controllerDevice.ControllerDeviceBaseClass; import neqsim.processSimulation.controllerDevice.ControllerDeviceInterface; import neqsim.processSimulation.measurementDevice.LevelTransmitter; @@ -13,187 +15,203 @@ import neqsim.processSimulation.processEquipment.valve.ThrottlingValve; import neqsim.thermo.system.SystemInterface; -public class ProcessSystemRunTransientTest extends neqsim.NeqSimTest{ - ProcessSystem p; - - @BeforeEach - public void setUp() { - p = new ProcessSystem(); +public class ProcessSystemRunTransientTest extends neqsim.NeqSimTest { + ProcessSystem p; + + @BeforeEach + public void setUp() { + p = new ProcessSystem(); + } + + @Test + public void testGetName() { + String name = "TestProsess"; + p.setName(name); + Assertions.assertEquals(name, p.getName()); + } + + @Test + void testGetTime() { + + } + + @Test + void testGetTimeStep() { + + } + + private SystemInterface getTestSystem() { + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem.addComponent("methane", 0.900); + testSystem.addComponent("ethane", 0.100); + testSystem.addComponent("n-heptane", 1.00); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + return testSystem; + } + + // @Test + public void testDynamicCalculation() { + neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); + + Stream stream1 = new Stream("Stream1", testSystem); + stream1.setFlowRate(50.0, "kg/hr"); + stream1.setPressure(10.0, "bara"); + + ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1); + valve1.setOutletPressure(5.0); + valve1.setPercentValveOpening(50); + + Separator separator1 = new Separator("sep 1"); + separator1.addStream(valve1.getOutletStream()); + + ThrottlingValve valve2 = new ThrottlingValve("valve_2", separator1.getLiquidOutStream()); + valve2.setOutletPressure(1.0); + valve2.setPercentValveOpening(50); + + ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream()); + valve3.setOutletPressure(1.0); + valve3.setPercentValveOpening(50); + + VolumeFlowTransmitter flowTransmitter = new VolumeFlowTransmitter(stream1); + flowTransmitter.setUnit("kg/hr"); + flowTransmitter.setMaximumValue(100.0); + flowTransmitter.setMinimumValue(1.0); + + ControllerDeviceInterface flowController = new ControllerDeviceBaseClass(); + flowController.setTransmitter(flowTransmitter); + flowController.setReverseActing(true); + flowController.setControllerSetPoint(63.5); + flowController.setControllerParameters(0.1, 0.10, 0.0); + + p.add(stream1); + p.add(valve1); + p.add(separator1); + p.add(valve2); + p.add(valve3); + p.add(flowTransmitter); + valve1.setController(flowController); + + p.run(); + + // transient behaviour + p.setTimeStep(1.0); + for (int i = 0; i < 5; i++) { + // System.out.println("volume flow " + flowTransmitter.getMeasuredValue() + // + " valve opening " + valve_1.getPercentValveOpening() + " pressure " + // + separator_1.getGasOutStream().getPressure()); + p.runTransient(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(sim.getCalculationIdentifier(), p.getCalculationIdentifier()); + } } - - @Test - public void testGetName() { - String name = "TestProsess"; - p.setName(name); - Assertions.assertEquals(name, p.getName()); + } + + @Test + public void testDynamicCalculation2() { + neqsim.thermo.system.SystemInterface testSystem2 = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem2.addComponent("methane", 1.1); + testSystem2.addComponent("ethane", 0.10001); + testSystem2.addComponent("n-heptane", 1.001); + testSystem2.setMixingRule(2); + + Stream purgeStream = new Stream("Purge Stream", testSystem2); + ThrottlingValve purgeValve = new ThrottlingValve("purgeValve", purgeStream); + purgeValve.setOutletPressure(7.0); + purgeValve.setPercentValveOpening(50.0); + + neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); + Stream stream1 = new Stream("Stream1", testSystem); + stream1.setCalculateSteadyState(false); + ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1); + valve1.setOutletPressure(7.0); + valve1.setPercentValveOpening(50); + + Separator separator1 = new Separator("separator_1"); + separator1.addStream(valve1.getOutletStream()); + separator1.addStream(purgeValve.getOutletStream()); + separator1.setCalculateSteadyState(true); + + ThrottlingValve valve2 = new ThrottlingValve("valve_2", separator1.getLiquidOutStream()); + valve2.setOutletPressure(5.0); + valve2.setPercentValveOpening(50); + valve2.setCalculateSteadyState(true); + // valve_2.setCv(10.0); + + ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream()); + valve3.setOutletPressure(5.0); + valve3.setPercentValveOpening(50); + valve3.setCalculateSteadyState(true); + // valve_3.setCv(10.0); + + LevelTransmitter separatorLevelTransmitter = new LevelTransmitter(separator1); + separatorLevelTransmitter.setName("separatorLevelTransmitter1"); + separatorLevelTransmitter.setUnit("meter"); + separatorLevelTransmitter.setMaximumValue(1.0); + separatorLevelTransmitter.setMinimumValue(0.0); + + ControllerDeviceInterface separatorLevelController = new ControllerDeviceBaseClass(); + separatorLevelController.setReverseActing(true); + separatorLevelController.setTransmitter(separatorLevelTransmitter); + separatorLevelController.setControllerSetPoint(0.3); + separatorLevelController.setControllerParameters(1, 1000.0, 0.0); + + PressureTransmitter separatorPressureTransmitter = + new PressureTransmitter(separator1.getGasOutStream()); + separatorPressureTransmitter.setUnit("bar"); + separatorPressureTransmitter.setMaximumValue(10.0); + separatorPressureTransmitter.setMinimumValue(1.0); + + ControllerDeviceInterface separatorPressureController = new ControllerDeviceBaseClass(); + separatorPressureController.setTransmitter(separatorPressureTransmitter); + separatorPressureController.setReverseActing(false); + separatorPressureController.setControllerSetPoint(7.0); + separatorPressureController.setControllerParameters(0.5, 10.0, 0.0); + + p.add(stream1); + p.add(valve1); + + p.add(purgeStream); + p.add(purgeValve); + p.add(separator1); + p.add(valve2); + p.add(valve3); + + // add transmitters + p.add(separatorLevelTransmitter); + valve2.setController(separatorLevelController); + + p.add(separatorPressureTransmitter); + valve3.setController(separatorPressureController); + + p.run(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(sim.getCalculationIdentifier(), p.getCalculationIdentifier()); } - @Test - void testGetTime() { - + // p.displayResult(); + p.setTimeStep(0.01); + for (int i = 0; i < 500; i++) { + // System.out.println("pressure "+separator_1.getGasOutStream().getPressure()+ " flow "+ + // separator_1.getGasOutStream().getFlowRate("kg/hr") + " sepr height + // "+separatorLevelTransmitter.getMeasuredValue()); + p.runTransient(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(p.getCalculationIdentifier(), sim.getCalculationIdentifier()); + } } - @Test - void testGetTimeStep() { - - } - - private SystemInterface getTestSystem() { - neqsim.thermo.system.SystemInterface testSystem = new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); - testSystem.addComponent("methane", 0.900); - testSystem.addComponent("ethane", 0.100); - testSystem.addComponent("n-heptane", 1.00); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - return testSystem; - } - - // @Test - public void testDynamicCalculation() { - neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); - - Stream stream_1 = new Stream("Stream1", testSystem); - stream_1.setFlowRate(50.0, "kg/hr"); - stream_1.setPressure(10.0, "bara"); - - ThrottlingValve valve_1 = new ThrottlingValve("valve_1", stream_1); - valve_1.setOutletPressure(5.0); - valve_1.setPercentValveOpening(50); - - Separator separator_1 = new Separator("sep 1"); - separator_1.addStream(valve_1.getOutletStream()); - - ThrottlingValve valve_2 = new ThrottlingValve("valve_2", separator_1.getLiquidOutStream()); - valve_2.setOutletPressure(1.0); - valve_2.setPercentValveOpening(50); - - ThrottlingValve valve_3 = new ThrottlingValve("valve_3", separator_1.getGasOutStream()); - valve_3.setOutletPressure(1.0); - valve_3.setPercentValveOpening(50); - - VolumeFlowTransmitter flowTransmitter = new VolumeFlowTransmitter(stream_1); - flowTransmitter.setUnit("kg/hr"); - flowTransmitter.setMaximumValue(100.0); - flowTransmitter.setMinimumValue(1.0); - - ControllerDeviceInterface flowController = new ControllerDeviceBaseClass(); - flowController.setTransmitter(flowTransmitter); - flowController.setReverseActing(true); - flowController.setControllerSetPoint(63.5); - flowController.setControllerParameters(0.1, 0.10, 0.0); - - p.add(stream_1); - p.add(valve_1); - p.add(separator_1); - p.add(valve_2); - p.add(valve_3); - p.add(flowTransmitter); - valve_1.setController(flowController); - - p.run(); - - // transient behaviour - p.setTimeStep(1.0); - for (int i = 0; i < 5; i++) { - // System.out.println("volume flow " + flowTransmitter.getMeasuredValue() - // + " valve opening " + valve_1.getPercentValveOpening() + " pressure " - // + separator_1.getGasOutStream().getPressure()); - p.runTransient(); - } - } + valve1.setPercentValveOpening(60); - @Test - public void testDynamicCalculation2() { - - neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); - - neqsim.thermo.system.SystemInterface testSystem2 = new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), - 10.00); - testSystem2.addComponent("methane", 1.1); - testSystem2.addComponent("ethane", 0.10001); - testSystem2.addComponent("n-heptane", 1.001); - testSystem2.setMixingRule(2); - - Stream purgeStream = new Stream("Purge Stream", testSystem2); - ThrottlingValve purgeValve = new ThrottlingValve("purgeValve", purgeStream); - purgeValve.setOutletPressure(7.0); - purgeValve.setPercentValveOpening(50.0); - - Stream stream_1 = new Stream("Stream1", testSystem); - stream_1.setCalculateSteadyState(false); - ThrottlingValve valve_1 = new ThrottlingValve("valve_1", stream_1); - valve_1.setOutletPressure(7.0); - valve_1.setPercentValveOpening(50); - - Separator separator_1 = new Separator("separator_1"); - separator_1.addStream(valve_1.getOutletStream()); - separator_1.addStream(purgeValve.getOutletStream()); - separator_1.setCalculateSteadyState(true); - - ThrottlingValve valve_2 = new ThrottlingValve("valve_2", separator_1.getLiquidOutStream()); - valve_2.setOutletPressure(5.0); - valve_2.setPercentValveOpening(50); - valve_2.setCalculateSteadyState(true); - // valve_2.setCv(10.0); - - ThrottlingValve valve_3 = new ThrottlingValve("valve_3", separator_1.getGasOutStream()); - valve_3.setOutletPressure(5.0); - valve_3.setPercentValveOpening(50); - valve_3.setCalculateSteadyState(true); - // valve_3.setCv(10.0); - - LevelTransmitter separatorLevelTransmitter = new LevelTransmitter(separator_1); - separatorLevelTransmitter.setName("separatorLevelTransmitter1"); - separatorLevelTransmitter.setUnit("meter"); - separatorLevelTransmitter.setMaximumValue(1.0); - separatorLevelTransmitter.setMinimumValue(0.0); - - ControllerDeviceInterface separatorLevelController = new ControllerDeviceBaseClass(); - separatorLevelController.setReverseActing(true); - separatorLevelController.setTransmitter(separatorLevelTransmitter); - separatorLevelController.setControllerSetPoint(0.3); - separatorLevelController.setControllerParameters(1, 1000.0, 0.0); - - PressureTransmitter separatorPressureTransmitter = new PressureTransmitter(separator_1.getGasOutStream()); - separatorPressureTransmitter.setUnit("bar"); - separatorPressureTransmitter.setMaximumValue(10.0); - separatorPressureTransmitter.setMinimumValue(1.0); - - ControllerDeviceInterface separatorPressureController = new ControllerDeviceBaseClass(); - separatorPressureController.setTransmitter(separatorPressureTransmitter); - separatorPressureController.setReverseActing(false); - separatorPressureController.setControllerSetPoint(7.0); - separatorPressureController.setControllerParameters(0.5, 10.0, 0.0); - - p.add(stream_1); - p.add(valve_1); - - p.add(purgeStream); - p.add(purgeValve); - p.add(separator_1); - p.add(valve_2); - p.add(valve_3); - - // add transmitters - p.add(separatorLevelTransmitter); - valve_2.setController(separatorLevelController); - - p.add(separatorPressureTransmitter); - valve_3.setController(separatorPressureController); - - p.run(); - // p.displayResult(); - p.setTimeStep(0.01); - for(int i=0;i<500;i++) { - //System.out.println("pressure "+separator_1.getGasOutStream().getPressure()+ " flow "+ separator_1.getGasOutStream().getFlowRate("kg/hr") + " sepr height "+separatorLevelTransmitter.getMeasuredValue()); - p.runTransient(); - } - - valve_1.setPercentValveOpening(60); - - for(int i=0;i<10;i++) { - // System.out.println("pressure "+separator_1.getGasOutStream().getPressure()+ " flow "+ separator_1.getGasOutStream().getFlowRate("kg/hr")); - p.runTransient(); - } + for (int i = 0; i < 10; i++) { + // System.out.println("pressure "+separator_1.getGasOutStream().getPressure()+ " flow "+ + // separator_1.getGasOutStream().getFlowRate("kg/hr")); + p.runTransient(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(p.getCalculationIdentifier(), sim.getCalculationIdentifier()); + } } + } } diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java index ecc312dac3..f2e9d09bb7 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java @@ -26,7 +26,6 @@ public class ProcessSystemTest extends neqsim.NeqSimTest { ProcessSystem p; String _name = "TestProcess"; - @BeforeEach public void setUp() { p = new ProcessSystem(); @@ -111,7 +110,6 @@ public void testRemoveUnit() { Assertions.assertEquals(0, p.size()); } - @Test @SuppressWarnings("deprecation") public void testAddUnitsWithNoName() { @@ -215,8 +213,6 @@ void testGetMechanicalWeight() { } - - @Test void testGetPower() { @@ -237,13 +233,11 @@ void testGetUnit() { } - @Test void testGetUnitOperations() { } - @Test void testOpen() { @@ -254,7 +248,6 @@ void testPrintLogFile() { } - @Test void testReplaceObject() { diff --git a/src/test/java/neqsim/thermo/system/SystemPrEosTest.java b/src/test/java/neqsim/thermo/system/SystemPrEosTest.java index 22e5a818ff..8d30856733 100644 --- a/src/test/java/neqsim/thermo/system/SystemPrEosTest.java +++ b/src/test/java/neqsim/thermo/system/SystemPrEosTest.java @@ -40,8 +40,6 @@ public static void setUp() { @DisplayName("test a TPflash2") public void testTPflash2() { - - assertEquals(2, testSystem.getNumberOfPhases()); } diff --git a/src/test/java/neqsim/thermo/system/SystemThermoAddComponentTest.java b/src/test/java/neqsim/thermo/system/SystemThermoAddComponentTest.java index ae6c459dbe..7f5ffab634 100644 --- a/src/test/java/neqsim/thermo/system/SystemThermoAddComponentTest.java +++ b/src/test/java/neqsim/thermo/system/SystemThermoAddComponentTest.java @@ -20,7 +20,6 @@ void setup() { */ } - @Test void testAddComponent() { // Assure that System contains no components diff --git a/src/test/java/neqsim/thermo/system/SystemUMRCPAEoStest.java b/src/test/java/neqsim/thermo/system/SystemUMRCPAEoStest.java index 4a43afb9ff..920a9bbfbc 100644 --- a/src/test/java/neqsim/thermo/system/SystemUMRCPAEoStest.java +++ b/src/test/java/neqsim/thermo/system/SystemUMRCPAEoStest.java @@ -43,8 +43,6 @@ public static void setUp() { // testSystem.i } - - /** *
* testFugasities. @@ -61,7 +59,6 @@ public void testFugasities() { assertEquals(-0.002884922, fucoef, 1e-6); - ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); testOps.TPflash(); testSystem.initProperties(); @@ -199,7 +196,6 @@ public void checkFugacityCoefficientsDn2() { assertTrue(testModel.checkFugacityCoefficientsDn2()); } - /** *
* checkPhaseEnvelope. diff --git a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java index 07c42ca571..8501bb81bb 100644 --- a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java +++ b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java @@ -41,8 +41,6 @@ public static void setUp() { // testSystem.i } - - /** *
* testFugasities. @@ -59,7 +57,6 @@ public void testFugasities() { assertEquals(-0.002884922, fucoef, 1e-6); - ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); testOps.TPflash(); testSystem.initProperties(); @@ -184,7 +181,6 @@ public void checkFugacityCoefficientsDn2() { assertTrue(testModel.checkFugacityCoefficientsDn2()); } - /** *
* checkPhaseEnvelope. From 45e96af16332bc24e1521378469d27c8d32905f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Fri, 22 Jul 2022 14:17:52 +0200 Subject: [PATCH 5/9] refact: autoformat and autofix (#489) --- .../shipSystem/LNGship.java | 35 +- .../thermo/phase/PhaseElectrolyteCPA.java | 2683 +++++++++-------- .../freezingFit/TestSolidComplexFunction.java | 94 +- ...teractionParameterFittingFunction_CO2.java | 612 ++-- .../flashOps/PSFlash.java | 241 +- .../flashOps/PVrefluxflash.java | 130 +- .../flashOps/TPmultiflash.java | 1856 ++++++------ .../flashOps/TPmultiflash_1.java | 555 ++-- .../flashOps/TSFlash.java | 220 +- .../bubblePointTemperatureNoDer.java | 279 +- .../constantDutyPressureFlash.java | 183 +- .../constantDutyTemperatureFlash.java | 158 +- .../saturationOps/cricondebarFlash.java | 499 +-- .../saturationOps/cricondenBarTemp.java | 272 +- .../dewPointTemperatureFlashDer.java | 288 +- .../flashOps/sysNewtonRhapsonPHflash.java | 466 +-- .../flashOps/sysNewtonRhapsonTPflash.java | 276 +- .../pTphaseEnvelope.java | 1565 +++++----- .../util/database/AspenIP21Database.java | 244 +- 19 files changed, 5327 insertions(+), 5329 deletions(-) diff --git a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/shipSystem/LNGship.java b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/shipSystem/LNGship.java index bd6d4b4336..53e92c37cd 100644 --- a/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/shipSystem/LNGship.java +++ b/src/main/java/neqsim/fluidMechanics/flowSystem/twoPhaseFlowSystem/shipSystem/LNGship.java @@ -24,21 +24,43 @@ public class LNGship private static final long serialVersionUID = 1000; double[] temperature = null; - double dailyBoilOffRatio = 0.005, totalTankVolume = 140000; + double dailyBoilOffRatio = 0.005; + double totalTankVolume = 140000; private double liquidDensity = 0.7; int numberOffTimeSteps = 100; private double initialTemperature = 111.0; private boolean setInitialTemperature = false; private neqsim.thermo.system.SystemInterface thermoSystem = null; double initialNumberOffMoles; - double molarBoilOffRate = 0.0, dailyBoilOffVolume = 0.0; + double molarBoilOffRate = 0.0; + double dailyBoilOffVolume = 0.0; private double endTime = 960;// 24.0 * 10; private Standard_ISO6976 standardISO6976 = null; StandardInterface standardDensity = null; - double[] WI = null, density = null, volume = null, xmethane, xethane, xpropane, xiC4, xnC4, xiC5, - xnC5, xnC6, xnitrogen; - double[] ymethane, yethane, ypropane, yiC4, ynC4, yiC5, ynC5, ynC6, ynitrogen; - double[] GCV, GCVmass, totalEnergy; + double[] WI = null; + double[] density = null; + double[] volume = null; + double[] xmethane; + double[] xethane; + double[] xpropane; + double[] xiC4; + double[] xnC4; + double[] xiC5; + double[] xnC5; + double[] xnC6; + double[] xnitrogen; + double[] ymethane; + double[] yethane; + double[] ypropane; + double[] yiC4; + double[] ynC4; + double[] yiC5; + double[] ynC5; + double[] ynC6; + double[] ynitrogen; + double[] GCV; + double[] GCVmass; + double[] totalEnergy; double[] time; double[] tankTemperature = null; double timeStep = 0; @@ -185,7 +207,6 @@ public void solveTransient(int type, UUID id) { if (backCalculate) { molarBoilOffRate = -molarBoilOffRate; } - // double orginalMolarBoilOff = molarBoilOffRate; logger.info("end Volume " + endVolume); int iterations = 0; double boilOffCorrection = 0.0; diff --git a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java index 3060764b45..48b9a4c21a 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java +++ b/src/main/java/neqsim/thermo/phase/PhaseElectrolyteCPA.java @@ -20,1429 +20,1444 @@ * @version $Id: $Id */ public class PhaseElectrolyteCPA extends PhaseModifiedFurstElectrolyteEos - implements PhaseCPAInterface { - private static final long serialVersionUID = 1000; - - public CPAMixing cpaSelect = new CPAMixing(); - public CPAMixingInterface cpamix; - double gcpavv = 0.0, gcpavvv = 0.0, gcpa = 0.0, hcpatot = 1.0, FCPA = 0.0, dFCPAdTdV, - dFCPAdTdT = 0.0, dFCPAdT = 0, dFCPAdV = 0, dFCPAdVdV = 0.0, dFCPAdVdVdV = 0.0; - private double gcpav = 0.0; - int cpaon = 1, oldTotalNumberOfAccociationSites = 0; - private int totalNumberOfAccociationSites = 0; - int[][][] selfAccociationScheme = null; - int[][][][] crossAccociationScheme = null; - int[] moleculeNumber = null, assSiteNumber = null; - private double[][] gvector = null, delta = null, deltaNog = null, deltadT = null, - deltadTdT = null; - private double[][][] Klkni = null; - private SimpleMatrix KlkTVMatrix = null, KlkTTMatrix = null, KlkTMatrix = null, - udotTimesmMatrix = null, mVector = null, udotMatrix = null, uMatrix = null, - QMatksiksiksi = null, KlkVVVMatrix = null, KlkVVMatrix = null, udotTimesmiMatrix = null, - ksiMatrix = null, KlkMatrix = null, hessianMatrix = null, hessianInvers = null, - KlkVMatrix = null; - DMatrixRMaj corr2Matrix = null, corr3Matrix = null, corr4Matrix = null;// new - // DenseMatrix64F(getTotalNumberOfAccociationSites(), - // 1); - - static Logger logger = LogManager.getLogger(PhaseElectrolyteCPA.class); - - /** - *
- * Constructor for PhaseElectrolyteCPA. - *
- */ - public PhaseElectrolyteCPA() { - super(); + implements PhaseCPAInterface { + private static final long serialVersionUID = 1000; + + public CPAMixing cpaSelect = new CPAMixing(); + public CPAMixingInterface cpamix; + double gcpavv = 0.0; + double gcpavvv = 0.0; + double gcpa = 0.0; + double hcpatot = 1.0; + double FCPA = 0.0; + double dFCPAdTdV; + double dFCPAdTdT = 0.0; + double dFCPAdT = 0; + double dFCPAdV = 0; + double dFCPAdVdV = 0.0; + double dFCPAdVdVdV = 0.0; + private double gcpav = 0.0; + int cpaon = 1; + int oldTotalNumberOfAccociationSites = 0; + private int totalNumberOfAccociationSites = 0; + int[][][] selfAccociationScheme = null; + int[][][][] crossAccociationScheme = null; + int[] moleculeNumber = null; + int[] assSiteNumber = null; + private double[][] gvector = null; + private double[][] delta = null; + private double[][] deltaNog = null; + private double[][] deltadT = null; + private double[][] deltadTdT = null; + private double[][][] Klkni = null; + private SimpleMatrix KlkTVMatrix = null; + private SimpleMatrix KlkTTMatrix = null; + private SimpleMatrix KlkTMatrix = null; + private SimpleMatrix udotTimesmMatrix = null; + private SimpleMatrix mVector = null; + private SimpleMatrix udotMatrix = null; + private SimpleMatrix uMatrix = null; + private SimpleMatrix QMatksiksiksi = null; + private SimpleMatrix KlkVVVMatrix = null; + private SimpleMatrix KlkVVMatrix = null; + private SimpleMatrix udotTimesmiMatrix = null; + private SimpleMatrix ksiMatrix = null; + private SimpleMatrix KlkMatrix = null; + private SimpleMatrix hessianMatrix = null; + private SimpleMatrix hessianInvers = null; + private SimpleMatrix KlkVMatrix = null; + DMatrixRMaj corr2Matrix = null; + DMatrixRMaj corr3Matrix = null; + DMatrixRMaj corr4Matrix = null; + + static Logger logger = LogManager.getLogger(PhaseElectrolyteCPA.class); + + /** + *+ * Constructor for PhaseElectrolyteCPA. + *
+ */ + public PhaseElectrolyteCPA() { + super(); + } + + /** {@inheritDoc} */ + @Override + public PhaseElectrolyteCPA clone() { + PhaseElectrolyteCPA clonedPhase = null; + try { + clonedPhase = (PhaseElectrolyteCPA) super.clone(); + } catch (Exception e) { + logger.error("Cloning failed.", e); } - - /** {@inheritDoc} */ - @Override - public PhaseElectrolyteCPA clone() { - PhaseElectrolyteCPA clonedPhase = null; - try { - clonedPhase = (PhaseElectrolyteCPA) super.clone(); - } catch (Exception e) { - logger.error("Cloning failed.", e); + // clonedPhase.cpaSelect = (CPAMixing) cpaSelect.clone(); + // clonedPhase.cpamix = (CPAMixingInterface) cpamix.clone(); + + return clonedPhase; + } + + /** {@inheritDoc} */ + @Override + public void setMixingRule(int type) { + super.setMixingRule(type); + cpamix = cpaSelect.getMixingRule(1, this); + } + + /** {@inheritDoc} */ + @Override + public void init(double totalNumberOfMoles, int numberOfComponents, int type, int phase, + double beta) { + if (type == 0) { + setTotalNumberOfAccociationSites(0); + selfAccociationScheme = new int[numberOfComponents][0][0]; + crossAccociationScheme = new int[numberOfComponents][numberOfComponents][0][0]; + for (int i = 0; i < numberOfComponents; i++) { + if (getComponent(i).getNumberOfmoles() < 1e-100) { + getComponent(i).setNumberOfAssociationSites(0); + } else { + getComponent(i) + .setNumberOfAssociationSites(getComponent(i).getOrginalNumberOfAssociationSites()); + setTotalNumberOfAccociationSites( + getTotalNumberOfAccociationSites() + getComponent(i).getNumberOfAssociationSites()); + selfAccociationScheme[i] = cpaSelect.setAssociationScheme(i, this); + for (int j = 0; j < numberOfComponents; j++) { + crossAccociationScheme[i][j] = cpaSelect.setCrossAssociationScheme(i, j, this); + } } - // clonedPhase.cpaSelect = (CPAMixing) cpaSelect.clone(); - // clonedPhase.cpamix = (CPAMixingInterface) cpamix.clone(); - - return clonedPhase; + } + + if (getTotalNumberOfAccociationSites() != oldTotalNumberOfAccociationSites) { + mVector = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + KlkMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkVVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkVVVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + hessianMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkTMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkTTMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkTVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + corr2Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); + corr3Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); + corr4Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); + Klkni = + new double[numberOfComponents][getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + ksiMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + uMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + udotMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + moleculeNumber = new int[getTotalNumberOfAccociationSites()]; + assSiteNumber = new int[getTotalNumberOfAccociationSites()]; + gvector = new double[getTotalNumberOfAccociationSites()][1]; + udotTimesmMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + udotTimesmiMatrix = + new SimpleMatrix(getNumberOfComponents(), getTotalNumberOfAccociationSites()); + delta = new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + deltaNog = + new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + deltadT = + new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + deltadTdT = + new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + QMatksiksiksi = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + } + oldTotalNumberOfAccociationSites = getTotalNumberOfAccociationSites(); + + int temp = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { + moleculeNumber[temp + j] = i; + assSiteNumber[temp + j] = j; + } + temp += getComponent(i).getNumberOfAssociationSites(); + } } - /** {@inheritDoc} */ - @Override - public void setMixingRule(int type) { - super.setMixingRule(type); - cpamix = cpaSelect.getMixingRule(1, this); + if (cpamix == null) { + cpamix = cpaSelect.getMixingRule(1, this); } - /** {@inheritDoc} */ - @Override - public void init(double totalNumberOfMoles, int numberOfComponents, int type, int phase, - double beta) { - if (type == 0) { - setTotalNumberOfAccociationSites(0); - selfAccociationScheme = new int[numberOfComponents][0][0]; - crossAccociationScheme = new int[numberOfComponents][numberOfComponents][0][0]; - for (int i = 0; i < numberOfComponents; i++) { - if (getComponent(i).getNumberOfmoles() < 1e-100) { - getComponent(i).setNumberOfAssociationSites(0); - } else { - getComponent(i).setNumberOfAssociationSites( - getComponent(i).getOrginalNumberOfAssociationSites()); - setTotalNumberOfAccociationSites(getTotalNumberOfAccociationSites() - + getComponent(i).getNumberOfAssociationSites()); - selfAccociationScheme[i] = cpaSelect.setAssociationScheme(i, this); - for (int j = 0; j < numberOfComponents; j++) { - crossAccociationScheme[i][j] = - cpaSelect.setCrossAssociationScheme(i, j, this); - } - } - } - - if (getTotalNumberOfAccociationSites() != oldTotalNumberOfAccociationSites) { - mVector = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); - KlkMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), - getTotalNumberOfAccociationSites()); - KlkVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), - getTotalNumberOfAccociationSites()); - KlkVVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), - getTotalNumberOfAccociationSites()); - KlkVVVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), - getTotalNumberOfAccociationSites()); - hessianMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), - getTotalNumberOfAccociationSites()); - KlkTMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), - getTotalNumberOfAccociationSites()); - KlkTTMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), - getTotalNumberOfAccociationSites()); - KlkTVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), - getTotalNumberOfAccociationSites()); - corr2Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); - corr3Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); - corr4Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); - Klkni = new double[numberOfComponents][getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; - ksiMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); - uMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); - udotMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); - moleculeNumber = new int[getTotalNumberOfAccociationSites()]; - assSiteNumber = new int[getTotalNumberOfAccociationSites()]; - gvector = new double[getTotalNumberOfAccociationSites()][1]; - udotTimesmMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); - udotTimesmiMatrix = new SimpleMatrix(getNumberOfComponents(), - getTotalNumberOfAccociationSites()); - delta = new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; - deltaNog = - new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; - deltadT = - new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; - deltadTdT = - new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; - QMatksiksiksi = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); - } - oldTotalNumberOfAccociationSites = getTotalNumberOfAccociationSites(); - - int temp = 0; - for (int i = 0; i < numberOfComponents; i++) { - for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { - moleculeNumber[temp + j] = i; - assSiteNumber[temp + j] = j; - } - temp += getComponent(i).getNumberOfAssociationSites(); - } - } - - if (cpamix == null) { - cpamix = cpaSelect.getMixingRule(1, this); - } - - super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); - if (type > 0 && isConstantPhaseVolume()) { - volInit(); - calcDelta(); - solveX(); - super.init(totalNumberOfMoles, numberOfComponents, 1, phase, beta); - gcpa = calc_g(); - // lngcpa = Math.log(gcpa); - setGcpav(calc_lngV()); - gcpavv = calc_lngVV(); - gcpavvv = calc_lngVVV(); - } - - if (type > 0) { - hcpatot = calc_hCPA(); - } + super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); + if (type > 0 && isConstantPhaseVolume()) { + volInit(); + calcDelta(); + solveX(); + super.init(totalNumberOfMoles, numberOfComponents, 1, phase, beta); + gcpa = calc_g(); + // lngcpa = Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + } - if (type > 1) { - volInit(); - initCPAMatrix(type); - // hcpatotdT = calc_hCPAdT(); - // super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); - } - super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); + if (type > 0) { + hcpatot = calc_hCPA(); } - /** - *- * calcDelta. - *
- */ - public void calcDelta() { - for (int i = 0; i < totalNumberOfAccociationSites; i++) { - for (int j = i; j < totalNumberOfAccociationSites; j++) { - deltaNog[i][j] = cpamix.calcDeltaNog(assSiteNumber[i], assSiteNumber[j], - moleculeNumber[i], moleculeNumber[j], this, getTemperature(), getPressure(), - numberOfComponents); - deltaNog[j][i] = delta[i][j]; - } - } + if (type > 1) { + volInit(); + initCPAMatrix(type); + // hcpatotdT = calc_hCPAdT(); + // super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); + } + super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); + } + + /** + *+ * calcDelta. + *
+ */ + public void calcDelta() { + for (int i = 0; i < totalNumberOfAccociationSites; i++) { + for (int j = i; j < totalNumberOfAccociationSites; j++) { + deltaNog[i][j] = cpamix.calcDeltaNog(assSiteNumber[i], assSiteNumber[j], moleculeNumber[i], + moleculeNumber[j], this, getTemperature(), getPressure(), numberOfComponents); + deltaNog[j][i] = delta[i][j]; + } + } + } + + /** + *+ * initCPAMatrix. + *
+ * + * @param type a int + */ + public void initCPAMatrix(int type) { + if (getTotalNumberOfAccociationSites() == 0) { + FCPA = 0.0; + dFCPAdTdV = 0.0; + dFCPAdTdT = 0.0; + dFCPAdT = 0; + dFCPAdV = 0; + dFCPAdVdV = 0.0; + dFCPAdVdVdV = 0.0; + + return; } - /** - *- * initCPAMatrix. - *
- * - * @param type a int - */ - public void initCPAMatrix(int type) { - if (getTotalNumberOfAccociationSites() == 0) { - FCPA = 0.0; - dFCPAdTdV = 0.0; - dFCPAdTdT = 0.0; - dFCPAdT = 0; - dFCPAdV = 0; - dFCPAdVdV = 0.0; - dFCPAdVdVdV = 0.0; - - return; + int temp = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { + uMatrix.set(temp + j, 0, + Math.log(ksiMatrix.get(temp + j, 0)) - ksiMatrix.get(temp + j, 0) + 1.0); + gvector[temp + j][0] = mVector.get(temp + j, 0) * udotMatrix.get(temp + j, 0); + } + temp += getComponent(i).getNumberOfAssociationSites(); + } + for (int i = 0; i < getNumberOfComponents(); i++) { + for (int j = 0; j < getTotalNumberOfAccociationSites(); j++) { + if (moleculeNumber[j] == i) { + udotTimesmiMatrix.set(i, j, udotMatrix.get(j, 0)); + } else { + udotTimesmiMatrix.set(i, j, 0.0); } + } + } - int temp = 0; - for (int i = 0; i < numberOfComponents; i++) { - for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { - uMatrix.set(temp + j, 0, - Math.log(ksiMatrix.get(temp + j, 0)) - ksiMatrix.get(temp + j, 0) + 1.0); - gvector[temp + j][0] = mVector.get(temp + j, 0) * udotMatrix.get(temp + j, 0); - } - temp += getComponent(i).getNumberOfAssociationSites(); - } - for (int i = 0; i < getNumberOfComponents(); i++) { - for (int j = 0; j < getTotalNumberOfAccociationSites(); j++) { - if (moleculeNumber[j] == i) { - udotTimesmiMatrix.set(i, j, udotMatrix.get(j, 0)); - } else { - udotTimesmiMatrix.set(i, j, 0.0); - } - } + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + delta[i][j] = deltaNog[i][j] * getGcpa(); + delta[j][i] = delta[i][j]; + if (type > 1) { + deltadT[i][j] = cpamix.calcDeltadT(assSiteNumber[i], assSiteNumber[j], moleculeNumber[i], + moleculeNumber[j], this, getTemperature(), getPressure(), numberOfComponents); + deltadT[j][i] = deltadT[i][j]; + + deltadTdT[i][j] = + cpamix.calcDeltadTdT(assSiteNumber[i], assSiteNumber[j], moleculeNumber[i], + moleculeNumber[j], this, getTemperature(), getPressure(), numberOfComponents); + deltadTdT[j][i] = deltadTdT[i][j]; } + } + } - for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { - for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { - delta[i][j] = deltaNog[i][j] * getGcpa(); - delta[j][i] = delta[i][j]; - if (type > 1) { - deltadT[i][j] = cpamix.calcDeltadT(assSiteNumber[i], assSiteNumber[j], - moleculeNumber[i], moleculeNumber[j], this, getTemperature(), - getPressure(), numberOfComponents); - deltadT[j][i] = deltadT[i][j]; - - deltadTdT[i][j] = cpamix.calcDeltadTdT(assSiteNumber[i], assSiteNumber[j], - moleculeNumber[i], moleculeNumber[j], this, getTemperature(), - getPressure(), numberOfComponents); - deltadTdT[j][i] = deltadTdT[i][j]; - } - } - } + double gdv1 = getGcpav() - 1.0 / getTotalVolume(); + double gdv2 = gdv1 * gdv1; + double gdv3 = gdv2 * gdv1; + double totVol = getTotalVolume(); + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + KlkVMatrix.set(i, j, KlkMatrix.get(i, j) * gdv1); + KlkVMatrix.set(j, i, KlkVMatrix.get(i, j)); + + KlkVVMatrix.set(i, j, KlkMatrix.get(i, j) * gdv2 + + KlkMatrix.get(i, j) * (gcpavv + 1.0 / getTotalVolume() / getTotalVolume())); + KlkVVMatrix.set(j, i, KlkVVMatrix.get(i, j)); + + KlkVVVMatrix.set(i, j, + KlkMatrix.get(i, j) * gdv3 + + 3.0 * KlkMatrix.get(i, j) * (getGcpav() - 1.0 / getTotalVolume()) + * (gcpavv + 1.0 / (totVol * totVol)) + + KlkMatrix.get(i, j) * (gcpavvv - 2.0 / (totVol * totVol * totVol))); + KlkVVVMatrix.set(j, i, KlkVVVMatrix.get(i, j)); - double gdv1 = getGcpav() - 1.0 / getTotalVolume(); - double gdv2 = gdv1 * gdv1; - double gdv3 = gdv2 * gdv1; - double totVol = getTotalVolume(); - // double Klk = 0.0; - for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { - for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { - KlkVMatrix.set(i, j, KlkMatrix.get(i, j) * gdv1); - KlkVMatrix.set(j, i, KlkVMatrix.get(i, j)); - - KlkVVMatrix.set(i, j, KlkMatrix.get(i, j) * gdv2 + KlkMatrix.get(i, j) - * (gcpavv + 1.0 / getTotalVolume() / getTotalVolume())); - KlkVVMatrix.set(j, i, KlkVVMatrix.get(i, j)); - - KlkVVVMatrix.set(i, j, KlkMatrix.get(i, j) * gdv3 - + 3.0 * KlkMatrix.get(i, j) * (getGcpav() - 1.0 / getTotalVolume()) - * (gcpavv + 1.0 / (totVol * totVol)) - + KlkMatrix.get(i, j) * (gcpavvv - 2.0 / (totVol * totVol * totVol))); - KlkVVVMatrix.set(j, i, KlkVVVMatrix.get(i, j)); - - if (type > 1) { - double tempVar = deltadT[i][j] / delta[i][j]; - double tempVardT = deltadTdT[i][j] / delta[i][j] - - (deltadT[i][j] * deltadT[i][j]) / (delta[i][j] * delta[i][j]); - - if (!Double.isNaN(tempVar)) { - // KlkdT[i][j] = KlkMatrix.getMatrix().unsafe_get(i, j) * tempVar; - // KlkdT[j][i] = KlkdT[i][j]; - - KlkTMatrix.set(i, j, KlkMatrix.get(i, j) * tempVar); - KlkTMatrix.set(j, i, KlkTMatrix.get(i, j)); - - KlkTVMatrix.set(i, j, - KlkMatrix.get(i, j) * tempVar * (gcpav - 1.0 / getTotalVolume())); - KlkTVMatrix.set(j, i, KlkTVMatrix.get(i, j)); - - KlkTTMatrix.set(i, j, - KlkMatrix.get(i, j) * (tempVar * tempVar + tempVardT)); - KlkTTMatrix.set(j, i, KlkTTMatrix.get(i, j)); - } - - if (type > 2) { - for (int p = 0; p < numberOfComponents; p++) { - double t1 = 0.0, t2 = 0.0; - if (moleculeNumber[i] == p) { - t1 = 1.0 / mVector.get(i, 0); - } - if (moleculeNumber[j] == p) { - t2 = 1.0 / mVector.get(j, 0); - } - Klkni[p][i][j] = KlkMatrix.get(i, j) * (t1 + t2 - + ((ComponentElectrolyteCPA) getComponent(p)).calc_lngi(this)); - Klkni[p][j][i] = Klkni[p][i][j]; - } - } - } + if (type > 1) { + double tempVar = deltadT[i][j] / delta[i][j]; + double tempVardT = deltadTdT[i][j] / delta[i][j] + - (deltadT[i][j] * deltadT[i][j]) / (delta[i][j] * delta[i][j]); + + if (!Double.isNaN(tempVar)) { + // KlkdT[i][j] = KlkMatrix.getMatrix().unsafe_get(i, j) * tempVar; + // KlkdT[j][i] = KlkdT[i][j]; + + KlkTMatrix.set(i, j, KlkMatrix.get(i, j) * tempVar); + KlkTMatrix.set(j, i, KlkTMatrix.get(i, j)); + + KlkTVMatrix.set(i, j, KlkMatrix.get(i, j) * tempVar * (gcpav - 1.0 / getTotalVolume())); + KlkTVMatrix.set(j, i, KlkTVMatrix.get(i, j)); + + KlkTTMatrix.set(i, j, KlkMatrix.get(i, j) * (tempVar * tempVar + tempVardT)); + KlkTTMatrix.set(j, i, KlkTTMatrix.get(i, j)); + } + + if (type > 2) { + for (int p = 0; p < numberOfComponents; p++) { + double t1 = 0.0; + double t2 = 0.0; + if (moleculeNumber[i] == p) { + t1 = 1.0 / mVector.get(i, 0); + } + if (moleculeNumber[j] == p) { + t2 = 1.0 / mVector.get(j, 0); + } + Klkni[p][i][j] = KlkMatrix.get(i, j) + * (t1 + t2 + ((ComponentElectrolyteCPA) getComponent(p)).calc_lngi(this)); + Klkni[p][j][i] = Klkni[p][i][j]; } - QMatksiksiksi.set(i, 0, 2.0 * mVector.get(i, 0) - / (ksiMatrix.get(i, 0) * ksiMatrix.get(i, 0) * ksiMatrix.get(i, 0))); + } } + } + QMatksiksiksi.set(i, 0, 2.0 * mVector.get(i, 0) + / (ksiMatrix.get(i, 0) * ksiMatrix.get(i, 0) * ksiMatrix.get(i, 0))); + } - SimpleMatrix ksiMatrixTranspose = ksiMatrix.transpose(); + SimpleMatrix ksiMatrixTranspose = ksiMatrix.transpose(); - // dXdV - SimpleMatrix KlkVMatrixksi = KlkVMatrix.mult(ksiMatrix); - SimpleMatrix XV = hessianInvers.mult(KlkVMatrixksi); - SimpleMatrix XVtranspose = XV.transpose(); + // dXdV + SimpleMatrix KlkVMatrixksi = KlkVMatrix.mult(ksiMatrix); + SimpleMatrix XV = hessianInvers.mult(KlkVMatrixksi); + SimpleMatrix XVtranspose = XV.transpose(); - SimpleMatrix QCPA = mVector.transpose() - .mult(uMatrix.minus(ksiMatrix.elementMult(udotMatrix).scale(0.5))); - FCPA = QCPA.get(0, 0); + SimpleMatrix QCPA = + mVector.transpose().mult(uMatrix.minus(ksiMatrix.elementMult(udotMatrix).scale(0.5))); + FCPA = QCPA.get(0, 0); - SimpleMatrix tempMatrix = ksiMatrixTranspose.mult(KlkVMatrixksi).scale(-0.5); - dFCPAdV = tempMatrix.get(0, 0); - SimpleMatrix KlkVVMatrixTImesKsi = KlkVVMatrix.mult(ksiMatrix); - SimpleMatrix tempMatrixVV = ksiMatrixTranspose.mult(KlkVVMatrixTImesKsi).scale(-0.5) - .minus(KlkVMatrixksi.transpose().mult(XV)); - dFCPAdVdV = tempMatrixVV.get(0, 0); + SimpleMatrix tempMatrix = ksiMatrixTranspose.mult(KlkVMatrixksi).scale(-0.5); + dFCPAdV = tempMatrix.get(0, 0); + SimpleMatrix KlkVVMatrixTImesKsi = KlkVVMatrix.mult(ksiMatrix); + SimpleMatrix tempMatrixVV = ksiMatrixTranspose.mult(KlkVVMatrixTImesKsi).scale(-0.5) + .minus(KlkVMatrixksi.transpose().mult(XV)); + dFCPAdVdV = tempMatrixVV.get(0, 0); - SimpleMatrix QVVV = ksiMatrixTranspose.mult(KlkVVVMatrix.mult(ksiMatrix)).scale(-0.5); - SimpleMatrix QVVksi = KlkVVMatrixTImesKsi.scale(-1.0); - SimpleMatrix QksiVksi = KlkVMatrix.scale(-1.0); + SimpleMatrix QVVV = ksiMatrixTranspose.mult(KlkVVVMatrix.mult(ksiMatrix)).scale(-0.5); + SimpleMatrix QVVksi = KlkVVMatrixTImesKsi.scale(-1.0); + SimpleMatrix QksiVksi = KlkVMatrix.scale(-1.0); - SimpleMatrix mat1 = QVVksi.transpose().mult(XV).scale(3.0); - SimpleMatrix mat2 = XVtranspose.mult(QksiVksi.mult(XV)).scale(3.0); - SimpleMatrix mat4 = XVtranspose.mult(QMatksiksiksi.mult(XVtranspose)).mult(XV); + SimpleMatrix mat1 = QVVksi.transpose().mult(XV).scale(3.0); + SimpleMatrix mat2 = XVtranspose.mult(QksiVksi.mult(XV)).scale(3.0); + SimpleMatrix mat4 = XVtranspose.mult(QMatksiksiksi.mult(XVtranspose)).mult(XV); - SimpleMatrix dFCPAdVdVdVMatrix = QVVV.plus(mat1).plus(mat2).plus(mat2).plus(mat4); - dFCPAdVdVdV = dFCPAdVdVdVMatrix.get(0, 0); - temp = 0; + SimpleMatrix dFCPAdVdVdVMatrix = QVVV.plus(mat1).plus(mat2).plus(mat2).plus(mat4); + dFCPAdVdVdV = dFCPAdVdVdVMatrix.get(0, 0); + temp = 0; - if (type == 1) { - return; - } - for (int p = 0; p < numberOfComponents; p++) { - for (int kk = 0; kk < getComponent(p).getNumberOfAssociationSites(); kk++) { - ((ComponentCPAInterface) getComponent(p)).setXsitedV(kk, XV.get(temp + kk, 0)); - } - temp += getComponent(p).getNumberOfAssociationSites(); - } - - // KlkTMatrix = new SimpleMatrix(KlkdT); - SimpleMatrix KlkTMatrixTImesKsi = KlkTMatrix.mult(ksiMatrix); - // dQdT - SimpleMatrix tempMatrix2 = ksiMatrixTranspose.mult(KlkTMatrixTImesKsi).scale(-0.5); - dFCPAdT = tempMatrix2.get(0, 0); - - // SimpleMatrix KlkTVMatrix = new SimpleMatrix(KlkdTdV); - // SimpleMatrix tempMatrixTV = - // ksiMatrixTranspose.mult(KlkTVMatrix.mult(ksiMatrix)).scale(-0.5).minus(KlkTMatrixTImesKsi.transpose().mult(XV)); - // dFCPAdTdV = tempMatrixTV.get(0, 0); - // dXdT - SimpleMatrix XT = hessianInvers.mult(KlkTMatrixTImesKsi); - // dQdTdT - SimpleMatrix tempMatrixTT = ksiMatrixTranspose.mult(KlkTTMatrix.mult(ksiMatrix)).scale(-0.5) - .minus(KlkTMatrixTImesKsi.transpose().mult(XT)); - dFCPAdTdT = tempMatrixTT.get(0, 0); - - SimpleMatrix tempMatrixTV = ksiMatrixTranspose.mult(KlkTVMatrix.mult(ksiMatrix)).scale(-0.5) - .minus(KlkTMatrixTImesKsi.transpose().mult(XV)); - dFCPAdTdV = tempMatrixTV.get(0, 0); - - temp = 0; - for (int p = 0; p < numberOfComponents; p++) { - for (int kk = 0; kk < getComponent(p).getNumberOfAssociationSites(); kk++) { - ((ComponentCPAInterface) getComponent(p)).setXsitedT(kk, XT.get(temp + kk, 0)); - } - temp += getComponent(p).getNumberOfAssociationSites(); - } - - if (type == 2) { - return; - } - - // int assSites = 0; - // if(true) return; - for (int p = 0; p < numberOfComponents; p++) { - SimpleMatrix KiMatrix = new SimpleMatrix(Klkni[p]); - // KiMatrix.print(10,10); - // Matrix dQdniMatrix = - // (ksiMatrix.transpose().times(KiMatrix.times(ksiMatrix)).times(-0.5)); // this - // methods misses one part of .... - // dQdniMatrix.print(10,10); - // KiMatrix.print(10, 10); - // miMatrix.getMatrix(assSites, assSites, 0, totalNumberOfAccociationSites - - // 1).print(10, 10); - // Matrix tempMatrix20 = miMatrix.getMatrix(assSites, assSites, 0, - // totalNumberOfAccociationSites - - // 1).times(uMatrix).minus(ksiMatrix.transpose().times(KiMatrix.times(ksiMatrix)).times(-0.5));// - // ksiMatrix.transpose().times(KlkTMatrix.times(ksiMatrix)).times(-0.5); - // System.out.println("dQdn "); - // tempMatrix20.print(10, 10); - SimpleMatrix tempMatrix4 = KiMatrix.mult(ksiMatrix); - // udotTimesmiMatrix.getMatrix(assSites, assSites, 0, - // totalNumberOfAccociationSites - 1).print(10, 10); - SimpleMatrix tempMatrix5 = - udotTimesmiMatrix.extractVector(true, p).transpose().minus(tempMatrix4); - // tempMki[0] = mki[p]; - // Matrix amatrix = new Matrix(croeneckerProduct(tempMki, - // udotMatrix.getArray())); - // System.out.println("aMatrix "); - // amatrix.transpose().print(10, 10); - // System.out.println("temp4 matrix"); - // tempMatrix4.print(10, 10); - // Matrix tempMatrix5 = amatrix.minus(tempMatrix4); - SimpleMatrix tempMatrix6 = hessianInvers.mult(tempMatrix5);// .scale(-1.0); - // System.out.println("dXdni"); - // tempMatrix4.print(10, 10); - // tempMatrix5.print(10, 10); - // System.out.println("dXdn "); - // tempMatrix6.print(10, 10); - int temp2 = 0; - for (int compp = 0; compp < numberOfComponents; compp++) { - for (int kk = 0; kk < getComponent(compp).getNumberOfAssociationSites(); kk++) { - ((ComponentCPAInterface) getComponent(compp)).setXsitedni(kk, p, - -1.0 * tempMatrix6.get(temp2 + kk, 0)); - } - temp2 += getComponent(compp).getNumberOfAssociationSites(); - } - // assSites += getComponent(p).getNumberOfAssociationSites(); - } - } - - /** {@inheritDoc} */ - @Override - public void addcomponent(String componentName, double moles, double molesInPhase, - int compNumber) { - super.addcomponent(componentName, moles, molesInPhase, compNumber); - componentArray[compNumber] = - new ComponentElectrolyteCPA(componentName, moles, molesInPhase, compNumber); - } - - /** {@inheritDoc} */ - @Override - public double getF() { - return super.getF() + cpaon * FCPA(); - } - - /** {@inheritDoc} */ - @Override - public double dFdT() { - return super.dFdT() + cpaon * dFCPAdT(); - } - - /** {@inheritDoc} */ - @Override - public double dFdTdV() { - return super.dFdTdV() + cpaon * dFCPAdTdV(); + if (type == 1) { + return; } - - /** {@inheritDoc} */ - @Override - public double dFdV() { - double dv2 = dFCPAdV(); - return super.dFdV() + cpaon * dv2; + for (int p = 0; p < numberOfComponents; p++) { + for (int kk = 0; kk < getComponent(p).getNumberOfAssociationSites(); kk++) { + ((ComponentCPAInterface) getComponent(p)).setXsitedV(kk, XV.get(temp + kk, 0)); + } + temp += getComponent(p).getNumberOfAssociationSites(); } - /** {@inheritDoc} */ - @Override - public double dFdVdV() { - return super.dFdVdV() + cpaon * dFCPAdVdV(); + // KlkTMatrix = new SimpleMatrix(KlkdT); + SimpleMatrix KlkTMatrixTImesKsi = KlkTMatrix.mult(ksiMatrix); + // dQdT + SimpleMatrix tempMatrix2 = ksiMatrixTranspose.mult(KlkTMatrixTImesKsi).scale(-0.5); + dFCPAdT = tempMatrix2.get(0, 0); + + // SimpleMatrix KlkTVMatrix = new SimpleMatrix(KlkdTdV); + // SimpleMatrix tempMatrixTV = + // ksiMatrixTranspose.mult(KlkTVMatrix.mult(ksiMatrix)).scale(-0.5).minus(KlkTMatrixTImesKsi.transpose().mult(XV)); + // dFCPAdTdV = tempMatrixTV.get(0, 0); + // dXdT + SimpleMatrix XT = hessianInvers.mult(KlkTMatrixTImesKsi); + // dQdTdT + SimpleMatrix tempMatrixTT = ksiMatrixTranspose.mult(KlkTTMatrix.mult(ksiMatrix)).scale(-0.5) + .minus(KlkTMatrixTImesKsi.transpose().mult(XT)); + dFCPAdTdT = tempMatrixTT.get(0, 0); + + SimpleMatrix tempMatrixTV = ksiMatrixTranspose.mult(KlkTVMatrix.mult(ksiMatrix)).scale(-0.5) + .minus(KlkTMatrixTImesKsi.transpose().mult(XV)); + dFCPAdTdV = tempMatrixTV.get(0, 0); + + temp = 0; + for (int p = 0; p < numberOfComponents; p++) { + for (int kk = 0; kk < getComponent(p).getNumberOfAssociationSites(); kk++) { + ((ComponentCPAInterface) getComponent(p)).setXsitedT(kk, XT.get(temp + kk, 0)); + } + temp += getComponent(p).getNumberOfAssociationSites(); } - /** {@inheritDoc} */ - @Override - public double dFdVdVdV() { - return super.dFdVdVdV() + cpaon * dFCPAdVdVdV(); + if (type == 2) { + return; } - /** {@inheritDoc} */ - @Override - public double dFdTdT() { - return super.dFdTdT() + cpaon * dFCPAdTdT(); + // if(true) return; + for (int p = 0; p < numberOfComponents; p++) { + SimpleMatrix KiMatrix = new SimpleMatrix(Klkni[p]); + // KiMatrix.print(10,10); + // Matrix dQdniMatrix = + // (ksiMatrix.transpose().times(KiMatrix.times(ksiMatrix)).times(-0.5)); // this + // methods misses one part of .... + // dQdniMatrix.print(10,10); + // KiMatrix.print(10, 10); + // miMatrix.getMatrix(assSites, assSites, 0, totalNumberOfAccociationSites - + // 1).print(10, 10); + // Matrix tempMatrix20 = miMatrix.getMatrix(assSites, assSites, 0, + // totalNumberOfAccociationSites - + // 1).times(uMatrix).minus(ksiMatrix.transpose().times(KiMatrix.times(ksiMatrix)).times(-0.5));// + // ksiMatrix.transpose().times(KlkTMatrix.times(ksiMatrix)).times(-0.5); + // System.out.println("dQdn "); + // tempMatrix20.print(10, 10); + SimpleMatrix tempMatrix4 = KiMatrix.mult(ksiMatrix); + // udotTimesmiMatrix.getMatrix(assSites, assSites, 0, + // totalNumberOfAccociationSites - 1).print(10, 10); + SimpleMatrix tempMatrix5 = + udotTimesmiMatrix.extractVector(true, p).transpose().minus(tempMatrix4); + // tempMki[0] = mki[p]; + // Matrix amatrix = new Matrix(croeneckerProduct(tempMki, + // udotMatrix.getArray())); + // System.out.println("aMatrix "); + // amatrix.transpose().print(10, 10); + // System.out.println("temp4 matrix"); + // tempMatrix4.print(10, 10); + // Matrix tempMatrix5 = amatrix.minus(tempMatrix4); + SimpleMatrix tempMatrix6 = hessianInvers.mult(tempMatrix5);// .scale(-1.0); + // System.out.println("dXdni"); + // tempMatrix4.print(10, 10); + // tempMatrix5.print(10, 10); + // System.out.println("dXdn "); + // tempMatrix6.print(10, 10); + int temp2 = 0; + for (int compp = 0; compp < numberOfComponents; compp++) { + for (int kk = 0; kk < getComponent(compp).getNumberOfAssociationSites(); kk++) { + ((ComponentCPAInterface) getComponent(compp)).setXsitedni(kk, p, + -1.0 * tempMatrix6.get(temp2 + kk, 0)); + } + temp2 += getComponent(compp).getNumberOfAssociationSites(); + } + // assSites += getComponent(p).getNumberOfAssociationSites(); } - - /** - *- * FCPA. - *
- * - * @return a double + } + + /** {@inheritDoc} */ + @Override + public void addcomponent(String componentName, double moles, double molesInPhase, + int compNumber) { + super.addcomponent(componentName, moles, molesInPhase, compNumber); + componentArray[compNumber] = + new ComponentElectrolyteCPA(componentName, moles, molesInPhase, compNumber); + } + + /** {@inheritDoc} */ + @Override + public double getF() { + return super.getF() + cpaon * FCPA(); + } + + /** {@inheritDoc} */ + @Override + public double dFdT() { + return super.dFdT() + cpaon * dFCPAdT(); + } + + /** {@inheritDoc} */ + @Override + public double dFdTdV() { + return super.dFdTdV() + cpaon * dFCPAdTdV(); + } + + /** {@inheritDoc} */ + @Override + public double dFdV() { + double dv2 = dFCPAdV(); + return super.dFdV() + cpaon * dv2; + } + + /** {@inheritDoc} */ + @Override + public double dFdVdV() { + return super.dFdVdV() + cpaon * dFCPAdVdV(); + } + + /** {@inheritDoc} */ + @Override + public double dFdVdVdV() { + return super.dFdVdVdV() + cpaon * dFCPAdVdVdV(); + } + + /** {@inheritDoc} */ + @Override + public double dFdTdT() { + return super.dFdTdT() + cpaon * dFCPAdTdT(); + } + + /** + *+ * FCPA. + *
+ * + * @return a double + */ + public double FCPA() { + /* + * double tot = 0.0; double ans = 0.0; for (int i = 0; i < numberOfComponents; i++) { tot = 0.0; + * for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { double xai = + * ((ComponentSrkCPA) getComponent(i)).getXsite()[j]; tot += (Math.log(xai) - 1.0 / 2.0 * xai + + * 1.0 / 2.0); } ans += getComponent(i).getNumberOfMolesInPhase() * tot; } return ans; */ - public double FCPA() { - /* - * double tot = 0.0; double ans = 0.0; for (int i = 0; i < numberOfComponents; i++) { tot = - * 0.0; for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { double xai - * = ((ComponentSrkCPA) getComponent(i)).getXsite()[j]; tot += (Math.log(xai) - 1.0 / 2.0 * - * xai + 1.0 / 2.0); } ans += getComponent(i).getNumberOfMolesInPhase() * tot; } return ans; - */ - return FCPA; - } - - /** - *- * dFCPAdV. - *
- * - * @return a double + return FCPA; + } + + /** + *+ * dFCPAdV. + *
+ * + * @return a double + */ + public double dFCPAdV() { + // return 1.0 / (2.0 * getTotalVolume()) * (1.0 - getTotalVolume() * getGcpav()) + // * hcpatot; + return dFCPAdV; + } + + /** + *+ * dFCPAdVdV. + *
+ * + * @return a double + */ + public double dFCPAdVdV() { + // double sum1 = -1.0 / 2.0 * gcpavv * hcpatot; + // return -1.0 / getTotalVolume() * dFCPAdV() + sum1; + return dFCPAdVdV; + } + + /** + *+ * dFCPAdVdVdV. + *
+ * + * @return a double + */ + public double dFCPAdVdVdV() { + return dFCPAdVdVdV; + // return -1.0 / getTotalVolume() * dFCPAdVdV() + 1.0 / + // Math.pow(getTotalVolume(), 2.0) * dFCPAdV() - hcpatot / (2.0 * + // Math.pow(getTotalVolume(), 2.0)) * (-getGcpav() - getTotalVolume() * gcpavv) + // + hcpatot / (2.0 * getTotalVolume()) * (-gcpavv - getTotalVolume() * gcpavvv + // - gcpavv); + } + + /** + *+ * dFCPAdT. + *
+ * + * @return a double + */ + public double dFCPAdT() { + /* + * double tot = 0.0; double ans = 0.0; for (int i = 0; i < numberOfComponents; i++) { tot = 0.0; + * for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { double xai = + * ((ComponentSrkCPA) getComponent(i)).getXsite()[j]; double xaidT = ((ComponentSrkCPA) + * getComponent(i)).getXsitedT()[j]; tot += 1.0 / xai * xaidT - 0.5 * xaidT;// - 1.0 / 2.0 * xai + * + 1.0 / 2.0); } ans += getComponent(i).getNumberOfMolesInPhase() * tot; } + * System.out.println("dFCPAdT1 " + ans + " dfcpa2 " +dFCPAdT); return ans; */ - public double dFCPAdV() { - // return 1.0 / (2.0 * getTotalVolume()) * (1.0 - getTotalVolume() * getGcpav()) - // * hcpatot; - return dFCPAdV; - } - - /** - *- * dFCPAdVdV. - *
- * - * @return a double + return dFCPAdT; + } + + /** + *+ * dFCPAdTdT. + *
+ * + * @return a double + */ + public double dFCPAdTdT() { + return dFCPAdTdT; + } + + /** + *+ * dFCPAdTdV. + *
+ * + * @return a double + */ + public double dFCPAdTdV() { + // System.out.println("dFCPAdTdV1 " + dFCPAdTdV + " dFCPAdTdV " +( 1.0 / (2.0 * + // getTotalVolume()) * (1.0 - getTotalVolume() * getGcpav()) * hcpatotdT)); + return dFCPAdTdV; + /* + * if (totalNumberOfAccociationSites > 0) { return 1.0 / (2.0 * getTotalVolume()) * (1.0 - + * getTotalVolume() * getGcpav()) * hcpatotdT; } else { return 0; } */ - public double dFCPAdVdV() { - // double sum1 = -1.0 / 2.0 * gcpavv * hcpatot; - // return -1.0 / getTotalVolume() * dFCPAdV() + sum1; - return dFCPAdVdV; + } + + /** + *+ * calc_hCPA. + *
+ * + * @return a double + */ + public double calc_hCPA() { + double htot = 0.0; + double tot = 0.0; + for (int i = 0; i < numberOfComponents; i++) { + htot = 0.0; + for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { + htot += (1.0 - ((ComponentCPAInterface) getComponent(i)).getXsite()[j]); + } + tot += getComponent(i).getNumberOfMolesInPhase() * htot; } - - /** - *- * dFCPAdVdVdV. - *
- * - * @return a double - */ - public double dFCPAdVdVdV() { - return dFCPAdVdVdV; - // return -1.0 / getTotalVolume() * dFCPAdVdV() + 1.0 / - // Math.pow(getTotalVolume(), 2.0) * dFCPAdV() - hcpatot / (2.0 * - // Math.pow(getTotalVolume(), 2.0)) * (-getGcpav() - getTotalVolume() * gcpavv) - // + hcpatot / (2.0 * getTotalVolume()) * (-gcpavv - getTotalVolume() * gcpavvv - // - gcpavv); + return tot; + } + + /** + *+ * calcXsitedV. + *
+ */ + public void calcXsitedV() { + if (totalNumberOfAccociationSites > 0) { + initCPAMatrix(1); } - - /** - *- * dFCPAdT. - *
- * - * @return a double - */ - public double dFCPAdT() { - /* - * double tot = 0.0; double ans = 0.0; for (int i = 0; i < numberOfComponents; i++) { tot = - * 0.0; for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { double xai - * = ((ComponentSrkCPA) getComponent(i)).getXsite()[j]; double xaidT = ((ComponentSrkCPA) - * getComponent(i)).getXsitedT()[j]; tot += 1.0 / xai * xaidT - 0.5 * xaidT;// - 1.0 / 2.0 * - * xai + 1.0 / 2.0); } ans += getComponent(i).getNumberOfMolesInPhase() * tot; } - * System.out.println("dFCPAdT1 " + ans + " dfcpa2 " +dFCPAdT); return ans; - */ - return dFCPAdT; + } + + /** + *+ * solveX. + *
+ * + * @return a boolean + */ + public boolean solveX() { + if (getTotalNumberOfAccociationSites() == 0) { + return true; } - /** - *- * dFCPAdTdT. - *
- * - * @return a double - */ - public double dFCPAdTdT() { - return dFCPAdTdT; + boolean solvedX = solveX2(5); + if (solvedX) { + // return true; } - /** - *- * dFCPAdTdV. - *
- * - * @return a double - */ - public double dFCPAdTdV() { - // System.out.println("dFCPAdTdV1 " + dFCPAdTdV + " dFCPAdTdV " +( 1.0 / (2.0 * - // getTotalVolume()) * (1.0 - getTotalVolume() * getGcpav()) * hcpatotdT)); - return dFCPAdTdV; - /* - * if (totalNumberOfAccociationSites > 0) { return 1.0 / (2.0 * getTotalVolume()) * (1.0 - - * getTotalVolume() * getGcpav()) * hcpatotdT; } else { return 0; } - */ + DMatrixRMaj mat1 = KlkMatrix.getMatrix(); + DMatrixRMaj mat2 = ksiMatrix.getMatrix(); + // second order method not working correctly and not used t the moment b ecause of numerical + // stability + int temp = 0; + int iter = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { + mVector.set(temp + j, 0, getComponent(i).getNumberOfMolesInPhase()); + } + temp += getComponent(i).getNumberOfAssociationSites(); } - - /** - *- * calc_hCPA. - *
- * - * @return a double - */ - public double calc_hCPA() { - double htot = 0.0; - double tot = 0.0; - for (int i = 0; i < numberOfComponents; i++) { - htot = 0.0; - for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { - htot += (1.0 - ((ComponentCPAInterface) getComponent(i)).getXsite()[j]); - } - tot += getComponent(i).getNumberOfMolesInPhase() * htot; - } - return tot; + double Klk = 0.0; + double totvolume = getTotalVolume(); + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + Klk = mVector.get(i, 0) * mVector.get(j, 0) / totvolume * delta[i][j]; + KlkMatrix.set(i, j, Klk); + KlkMatrix.set(j, i, Klk); + } } - - /** - *- * calcXsitedV. - *
- */ - public void calcXsitedV() { - if (totalNumberOfAccociationSites > 0) { - initCPAMatrix(1); + boolean solved = true; + // SimpleMatrix corrMatrix = null; + do { + solved = true; + iter++; + temp = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { + ksiMatrix.set(temp + j, 0, ((ComponentCPAInterface) getComponent(i)).getXsite()[j]); + // ksiMatrix.getMatrix().unsafe_set(temp + j, 0, + // ksiMatrix.getMatrix().unsafe_get(temp + j, 0)); + udotMatrix.set(temp + j, 0, 1.0 / ksiMatrix.get(temp + j, 0) - 1.0); + udotTimesmMatrix.set(temp + j, 0, mVector.get(temp + j, 0) * udotMatrix.get(temp + j, 0)); } - } - - /** - *- * solveX. - *
- * - * @return a boolean - */ - public boolean solveX() { - if (getTotalNumberOfAccociationSites() == 0) { - return true; + temp += getComponent(i).getNumberOfAssociationSites(); + } + + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + int krondelt = 0; + if (i == j) { + krondelt = 1; + } + hessianMatrix.set(i, j, + -mVector.get(i, 0) / (ksiMatrix.get(i, 0) * ksiMatrix.get(i, 0)) * krondelt + - KlkMatrix.get(i, j)); + hessianMatrix.set(j, i, hessianMatrix.get(i, j)); } - - boolean solvedX = solveX2(5); - if (solvedX) { - // return true; + } + + // ksiMatrix = new SimpleMatrix(ksi); + // SimpleMatrix hessianMatrix = new SimpleMatrix(hessian); + try { + hessianInvers = hessianMatrix.invert(); + } catch (Exception e) { + logger.error("error", e); + return false; + } + + CommonOps_DDRM.mult(mat1, mat2, corr2Matrix); + CommonOps_DDRM.subtract(udotTimesmMatrix.getDDRM(), corr2Matrix, corr3Matrix); + CommonOps_DDRM.mult(hessianInvers.getDDRM(), corr3Matrix, corr4Matrix); + // SimpleMatrix gMatrix = udotTimesmMatrix.minus(KlkMatrix.mult(ksiMatrix)); + // corrMatrix = + // hessianInvers.mult(udotTimesmMatrix.minus(KlkMatrix.mult(ksiMatrix)));//.scale(-1.0); + temp = 0; + // System.out.println("print SimpleMatrix ..."); + // corrMatrix.print(10, 10); + // SimpleMatrix simp = new SimpleMatrix(corr4Matrix); + // System.out.println("print CommonOps ..."); + // simp.print(10,10); + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { + double newX = ksiMatrix.get(temp + j, 0) - corr4Matrix.unsafe_get((temp + j), 0); + if (newX < 0) { + newX = 1e-10; + solved = false; + } + ((ComponentCPAInterface) getComponent(i)).setXsite(j, newX); } - - DMatrixRMaj mat1 = KlkMatrix.getMatrix(); - DMatrixRMaj mat2 = ksiMatrix.getMatrix(); - // second order method not working correctly and not used t the moment b ecause of numerical - // stability - int temp = 0, iter = 0; - for (int i = 0; i < numberOfComponents; i++) { - for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { - mVector.set(temp + j, 0, getComponent(i).getNumberOfMolesInPhase()); - } - temp += getComponent(i).getNumberOfAssociationSites(); + temp += getComponent(i).getNumberOfAssociationSites(); + } + // System.out.println("corrmatrix error " ); + // System.out.println("error " + corrMatrix.norm1()); + } while ((NormOps_DDRM.normF(corr4Matrix) > 1e-12 || !solved) && iter < 100); + + // System.out.println("iter " + iter + " error " + NormOps.normF(corr4Matrix)); + // // corrMatrix.print(10, 10); + // ksiMatrix.print(10, 10); + return true; + } + + /** + *+ * solveX2. + *
+ * + * @param maxIter a int + * @return a boolean + */ + public boolean solveX2(int maxIter) { + double err = .0; + int iter = 0; + // if (delta == null) { + // initCPAMatrix(1); + double old = 0.0; + double neeval = 0.0; + // } + do { + iter++; + err = 0.0; + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + old = + ((ComponentCPAInterface) getComponent(moleculeNumber[i])).getXsite()[assSiteNumber[i]]; + neeval = 0; + for (int j = 0; j < getTotalNumberOfAccociationSites(); j++) { + neeval += getComponent(moleculeNumber[j]).getNumberOfMolesInPhase() * delta[i][j] + * ((ComponentCPAInterface) getComponent(moleculeNumber[j])) + .getXsite()[assSiteNumber[j]]; } - double Klk = 0.0; - double totvolume = getTotalVolume(); - for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { - for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { - Klk = mVector.get(i, 0) * mVector.get(j, 0) / totvolume * delta[i][j]; - KlkMatrix.set(i, j, Klk); - KlkMatrix.set(j, i, Klk); - } + neeval = 1.0 / (1.0 + 1.0 / getTotalVolume() * neeval); + ((ComponentCPAInterface) getComponent(moleculeNumber[i])).setXsite(assSiteNumber[i], + neeval); + err += Math.abs((old - neeval) / neeval); + } + } while (Math.abs(err) > 1e-10 && iter < maxIter); + // System.out.println("iter " + iter); + // if (Math.abs(err) + // < 1e-12) { + // return true; + // } else { + // System.out.println("did not solve for Xi in iterations: " + iter); + // System.out.println("error: " + err); + return false; + } + + /** {@inheritDoc} */ + @Override + public double getHcpatot() { + return hcpatot; + } + + /** + * Setter for property hcpatot. + * + * @param hcpatot New value of property hcpatot. + */ + public void setHcpatot(double hcpatot) { + this.hcpatot = hcpatot; + } + + /** {@inheritDoc} */ + @Override + public double getGcpa() { + return gcpa; + } + + /** + *+ * calcRootVolFinder. + *
+ * + * @param phase a int + * @return a double + */ + public double calcRootVolFinder(int phase) { + double solvedBonVHigh = 0.0; + double solvedBonVlow = 1.0; + double oldh = 1; + // double[][] matrix = new double[2][2000]; + double BonV = 1.0 - 1e-10; + try { + // molarVolume(pressure, temperature, A, B, phaseType); + } catch (Exception e) { + logger.error("error", e); + } + double BonVold = BonV; + double Btemp = 0; + double h = 1; + Btemp = getB(); + getA(); + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + for (int i = 0; i < 2000; i++) { + BonVold = BonV; + BonV = 1.0 - (i + 1e-6) * 1.0 / 2000.0; + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + Z = pressure * getMolarVolume() / (R * temperature); + gcpa = calc_g(); + // lngcpa = + // Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + volInit(); + do { + } while (!solveX()); + + h = BonV - Btemp / numberOfMolesInPhase * dFdV() + - pressure * Btemp / (numberOfMolesInPhase * R * temperature); + + if (Math.signum(h) * Math.signum(oldh) < 0 && i > 2) { + if (solvedBonVlow < 1e-3) { + solvedBonVlow = (BonV + BonVold) / 2.0; + if (phase == 1) { + break; + } + } else { + solvedBonVHigh = (BonV + BonVold) / 2.0; + if (phase == 0) { + break; + } } - boolean solved = true; - // SimpleMatrix corrMatrix = null; - do { - solved = true; - iter++; - temp = 0; - for (int i = 0; i < numberOfComponents; i++) { - for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { - ksiMatrix.set(temp + j, 0, - ((ComponentCPAInterface) getComponent(i)).getXsite()[j]); - // ksiMatrix.getMatrix().unsafe_set(temp + j, 0, - // ksiMatrix.getMatrix().unsafe_get(temp + j, 0)); - udotMatrix.set(temp + j, 0, 1.0 / ksiMatrix.get(temp + j, 0) - 1.0); - udotTimesmMatrix.set(temp + j, 0, - mVector.get(temp + j, 0) * udotMatrix.get(temp + j, 0)); - } - temp += getComponent(i).getNumberOfAssociationSites(); - } - - for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { - for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { - int krondelt = 0; - if (i == j) { - krondelt = 1; - } - hessianMatrix.set(i, j, - -mVector.get(i, 0) / (ksiMatrix.get(i, 0) * ksiMatrix.get(i, 0)) - * krondelt - KlkMatrix.get(i, j)); - hessianMatrix.set(j, i, hessianMatrix.get(i, j)); - } - } - - // ksiMatrix = new SimpleMatrix(ksi); - // SimpleMatrix hessianMatrix = new SimpleMatrix(hessian); - try { - hessianInvers = hessianMatrix.invert(); - } catch (Exception e) { - logger.error("error", e); - return false; - } - - CommonOps_DDRM.mult(mat1, mat2, corr2Matrix); - CommonOps_DDRM.subtract(udotTimesmMatrix.getDDRM(), corr2Matrix, corr3Matrix); - CommonOps_DDRM.mult(hessianInvers.getDDRM(), corr3Matrix, corr4Matrix); - // SimpleMatrix gMatrix = udotTimesmMatrix.minus(KlkMatrix.mult(ksiMatrix)); - // corrMatrix = - // hessianInvers.mult(udotTimesmMatrix.minus(KlkMatrix.mult(ksiMatrix)));//.scale(-1.0); - temp = 0; - // System.out.println("print SimpleMatrix ..."); - // corrMatrix.print(10, 10); - // SimpleMatrix simp = new SimpleMatrix(corr4Matrix); - // System.out.println("print CommonOps ..."); - // simp.print(10,10); - for (int i = 0; i < numberOfComponents; i++) { - for (int j = 0; j < getComponent(i).getNumberOfAssociationSites(); j++) { - double newX = - ksiMatrix.get(temp + j, 0) - corr4Matrix.unsafe_get((temp + j), 0); - if (newX < 0) { - newX = 1e-10; - solved = false; - } - ((ComponentCPAInterface) getComponent(i)).setXsite(j, newX); - } - temp += getComponent(i).getNumberOfAssociationSites(); - } - // System.out.println("corrmatrix error " ); - // System.out.println("error " + corrMatrix.norm1()); - } while ((NormOps_DDRM.normF(corr4Matrix) > 1e-12 || !solved) && iter < 100); - - // System.out.println("iter " + iter + " error " + NormOps.normF(corr4Matrix)); - // // corrMatrix.print(10, 10); - // ksiMatrix.print(10, 10); - return true; + } + solvedBonVHigh = (BonV + BonVold) / 2.0; + oldh = h; + // matrix[0][i] = BonV; + // matrix[1][i] = h; } - - /** - *- * solveX2. - *
- * - * @param maxIter a int - * @return a boolean - */ - public boolean solveX2(int maxIter) { - double err = .0; - int iter = 0; - // if (delta == null) { - // initCPAMatrix(1); - double old = 0.0, neeval = 0.0; - // } - do { - iter++; - err = 0.0; - for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { - old = ((ComponentCPAInterface) getComponent(moleculeNumber[i])) - .getXsite()[assSiteNumber[i]]; - neeval = 0; - for (int j = 0; j < getTotalNumberOfAccociationSites(); j++) { - neeval += - getComponent(moleculeNumber[j]).getNumberOfMolesInPhase() * delta[i][j] - * ((ComponentCPAInterface) getComponent(moleculeNumber[j])) - .getXsite()[assSiteNumber[j]]; - } - neeval = 1.0 / (1.0 + 1.0 / getTotalVolume() * neeval); - ((ComponentCPAInterface) getComponent(moleculeNumber[i])).setXsite(assSiteNumber[i], - neeval); - err += Math.abs((old - neeval) / neeval); - } - } while (Math.abs(err) > 1e-10 && iter < maxIter); - // System.out.println("iter " + iter); - // if (Math.abs(err) - // < 1e-12) { - // return true; - // } else { - // System.out.println("did not solve for Xi in iterations: " + iter); - // System.out.println("error: " + err); - return false; + if (solvedBonVlow < 1e-3) { + solvedBonVlow = solvedBonVHigh; } - - /** {@inheritDoc} */ - @Override - public double getHcpatot() { - return hcpatot; + // dataPresentation.fileHandeling.createTextFile.TextFile file = new + // dataPresentation.fileHandeling.createTextFile.TextFile(); + // file.setValues(matrix); + // file.setOutputFileName("D:/temp/temp2.txt"); + // file.createFile(); + if (phase == 1) { + return solvedBonVlow; + } else { + return solvedBonVHigh; } - - /** - * Setter for property hcpatot. - * - * @param hcpatot New value of property hcpatot. - */ - public void setHcpatot(double hcpatot) { - this.hcpatot = hcpatot; + } + + /** {@inheritDoc} */ + @Override + public double molarVolume2(double pressure, double temperature, double A, double B, int phasetype) + throws neqsim.util.exception.IsNaNException, + neqsim.util.exception.TooManyIterationsException { + double BonV = phasetype == 0 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + if (BonV < 0) { + BonV = 1.0e-8; } - /** {@inheritDoc} */ - @Override - public double getGcpa() { - return gcpa; + if (BonV > 1.1) { + BonV = 1.1; } - - /** - *- * calcRootVolFinder. - *
- * - * @param phase a int - * @return a double - */ - public double calcRootVolFinder(int phase) { - double solvedBonVHigh = 0.0; - double solvedBonVlow = 1.0; - double oldh = 1; - // double[][] matrix = new double[2][2000]; - double BonV = 1.0 - 1e-10; - try { - // molarVolume(pressure, temperature, A, B, phaseType); - } catch (Exception e) { - logger.error("error", e); - } - double BonVold = BonV; - double Btemp = 0, h = 1; - // double Dtemp = 0, dh = 0, gvvv = 0, fvvv = 0, dhh = 0; - // double d1 = 0, d2 = 0; - Btemp = getB(); - // Dtemp = getA(); - setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); - for (int i = 0; i < 2000; i++) { - BonVold = BonV; - BonV = 1.0 - (i + 1e-6) * 1.0 / 2000.0; - setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); - Z = pressure * getMolarVolume() / (R * temperature); - gcpa = calc_g(); - // lngcpa = - // Math.log(gcpa); - setGcpav(calc_lngV()); - gcpavv = calc_lngVV(); - gcpavvv = calc_lngVVV(); - volInit(); - do { - } while (!solveX()); - - h = BonV - Btemp / numberOfMolesInPhase * dFdV() - - pressure * Btemp / (numberOfMolesInPhase * R * temperature); - - if (Math.signum(h) * Math.signum(oldh) < 0 && i > 2) { - if (solvedBonVlow < 1e-3) { - solvedBonVlow = (BonV + BonVold) / 2.0; - if (phase == 1) { - break; - } - } else { - solvedBonVHigh = (BonV + BonVold) / 2.0; - if (phase == 0) { - break; - } - } - } - solvedBonVHigh = (BonV + BonVold) / 2.0; - oldh = h; - // matrix[0][i] = BonV; - // matrix[1][i] = h; - } - if (solvedBonVlow < 1e-3) { - solvedBonVlow = solvedBonVHigh; - } - // dataPresentation.fileHandeling.createTextFile.TextFile file = new - // dataPresentation.fileHandeling.createTextFile.TextFile(); - // file.setValues(matrix); - // file.setOutputFileName("D:/temp/temp2.txt"); - // file.createFile(); - if (phase == 1) { - return solvedBonVlow; - } else { - return solvedBonVHigh; - } + double BonVold = BonV; + double Btemp = 0; + double h = 0; + double dh = 0; + double dhh = 0; + double d1 = 0; + double d2 = 0; + Btemp = getB(); + if (Btemp < 0) { + logger.info("b negative in volume calc"); } + calcDelta(); - /** {@inheritDoc} */ - @Override - public double molarVolume2(double pressure, double temperature, double A, double B, - int phasetype) throws neqsim.util.exception.IsNaNException, - neqsim.util.exception.TooManyIterationsException { - double BonV = phasetype == 0 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) - : pressure * getB() / (numberOfMolesInPhase * temperature * R); - // double[][] calcRootVolFinder = calcRootVolFinder(); - // double BonVInit = BonV; - if (BonV < 0) { - BonV = 1.0e-8; - } + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + int iterations = 0; - if (BonV > 1.1) { - BonV = 1.1; + do { + volInit(); + iterations++; + gcpa = calc_g(); + if (gcpa < 0) { + setMolarVolume(1.0 / Btemp / numberOfMolesInPhase); + gcpa = calc_g(); + } + + // double lngcpa = Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + + solveX(); + + hcpatot = calc_hCPA(); + + initCPAMatrix(1); + volInit(); + double BonV2 = BonV * BonV; + BonVold = BonV; + h = BonV - Btemp / numberOfMolesInPhase * dFdV() + - pressure * Btemp / (numberOfMolesInPhase * R * temperature); + dh = 1.0 + Btemp / (BonV2) * (Btemp / numberOfMolesInPhase * dFdVdV()); + dhh = -2.0 * Btemp / (BonV2 * BonV) * (Btemp / numberOfMolesInPhase * dFdVdV()) + - (Btemp * Btemp) / (BonV2 * BonV2) * (Btemp / numberOfMolesInPhase * dFdVdVdV()); + + d1 = -h / dh; + d2 = -dh / dhh; + // System.out.println("d1" + d1 + " d2 " + d2 + " d1 / d2 " + (d1 / d2)); + if (Math.abs(d1 / d2) <= 1.0) { + BonV += d1 * (1.0 + 0.5 * d1 / d2); + } else if (d1 / d2 < -1) { + BonV += 0.5 * d1; + } else if (d1 > d2) { + BonV += d2; + double hnew = h + d2 * dh; + if (Math.abs(hnew) > Math.abs(h)) { + BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); } - double BonVold = BonV; - double Btemp = 0, h = 0, dh = 0, dhh = 0; - // double gvvv = 0, fvvv = 0; - double d1 = 0, d2 = 0; - Btemp = getB(); - if (Btemp < 0) { - logger.info("b negative in volume calc"); + } else { + BonV += 0.5 * d1; + } + if (Math.abs((BonV - BonVold) / BonVold) > 0.1) { + BonV = BonVold + 0.1 * (BonV - BonVold); + } + + if (BonV > 1.1) { + if (iterations < 3) { + BonV = (BonVold + BonV) / 2.0; + } else { + BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); } - calcDelta(); - - setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); - int iterations = 0; - - do { - volInit(); - iterations++; - gcpa = calc_g(); - if (gcpa < 0) { - setMolarVolume(1.0 / Btemp / numberOfMolesInPhase); - gcpa = calc_g(); - } - - // double lngcpa = Math.log(gcpa); - setGcpav(calc_lngV()); - gcpavv = calc_lngVV(); - gcpavvv = calc_lngVVV(); - - solveX(); - - hcpatot = calc_hCPA(); - - initCPAMatrix(1); - volInit(); - double BonV2 = BonV * BonV; - BonVold = BonV; - h = BonV - Btemp / numberOfMolesInPhase * dFdV() - - pressure * Btemp / (numberOfMolesInPhase * R * temperature); - dh = 1.0 + Btemp / (BonV2) * (Btemp / numberOfMolesInPhase * dFdVdV()); - dhh = -2.0 * Btemp / (BonV2 * BonV) * (Btemp / numberOfMolesInPhase * dFdVdV()) - - (Btemp * Btemp) / (BonV2 * BonV2) - * (Btemp / numberOfMolesInPhase * dFdVdVdV()); - - d1 = -h / dh; - d2 = -dh / dhh; - // System.out.println("d1" + d1 + " d2 " + d2 + " d1 / d2 " + (d1 / d2)); - if (Math.abs(d1 / d2) <= 1.0) { - BonV += d1 * (1.0 + 0.5 * d1 / d2); - } else if (d1 / d2 < -1) { - BonV += 0.5 * d1; - } else if (d1 > d2) { - BonV += d2; - double hnew = h + d2 * dh; - if (Math.abs(hnew) > Math.abs(h)) { - BonV = phasetype == 1 - ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) - : pressure * getB() / (numberOfMolesInPhase * temperature * R); - } - } else { - BonV += 0.5 * d1; - } - if (Math.abs((BonV - BonVold) / BonVold) > 0.1) { - BonV = BonVold + 0.1 * (BonV - BonVold); - } + } - if (BonV > 1.1) { - if (iterations < 3) { - BonV = (BonVold + BonV) / 2.0; - } else { - BonV = phasetype == 1 - ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) - : pressure * getB() / (numberOfMolesInPhase * temperature * R); - } - } - - if (BonV < 0) { - if (iterations < 3) { - BonV = Math.abs(BonVold + BonV) / 2.0; - } else { - BonV = phasetype == 1 - ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) - : pressure * getB() / (numberOfMolesInPhase * temperature * R); - } - } - - 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 < 100); - // System.out.println("Z" + Z + " iterations " + iterations + " BonV " + BonV); - // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); - // System.out.println("volume " + getTotalVolume() + " molar volume " + - // getMolarVolume()); - // if(iterations>=100) throw new util.exception.TooManyIterationsException(); - // System.out.println("error in volume " + - // (-pressure+R*temperature/getMolarVolume()-R*temperature*dFdV()));// + " - // firstterm " + (R*temperature/molarVolume) + " second " + - // R*temperature*dFdV()); - - if (Double.isNaN(getMolarVolume())) { - // 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(this, "molarVolume2", "Molar volume"); - // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " - // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" - // + fVV()); + if (BonV < 0) { + if (iterations < 3) { + BonV = Math.abs(BonVold + BonV) / 2.0; + } else { + BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); } - - return getMolarVolume(); + } + + 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 < 100); + // System.out.println("Z" + Z + " iterations " + iterations + " BonV " + BonV); + // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); + // System.out.println("volume " + getTotalVolume() + " molar volume " + + // getMolarVolume()); + // if(iterations>=100) throw new util.exception.TooManyIterationsException(); + // System.out.println("error in volume " + + // (-pressure+R*temperature/getMolarVolume()-R*temperature*dFdV()));// + " + // firstterm " + (R*temperature/molarVolume) + " second " + + // R*temperature*dFdV()); + + if (Double.isNaN(getMolarVolume())) { + // 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(this, "molarVolume2", "Molar volume"); + // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " + // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + // + fVV()); } - /** {@inheritDoc} */ - @Override - public double molarVolume(double pressure, double temperature, double A, double B, - int phasetype) throws neqsim.util.exception.IsNaNException, - neqsim.util.exception.TooManyIterationsException { - double BonV = phasetype == 0 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) - : pressure * getB() / (numberOfMolesInPhase * temperature * R); - // if (pressure > 1000) { - // BonV = 0.9999; - // } - - // double calcRooBonVtVolFinder = calcRootVolFinder(phasetype); - // BonV = calcRooBonVtVolFinder; - // double BonVInit = BonV; - if (BonV <= 0) { - BonV = 1.0e-8; - } - else if (BonV >= 1.0) { - BonV = 0.9999; - } - double BonVold; - double h = 0, dh = 0, dhh = 0; - double d1 = 0, d2 = 0; - double Btemp = getB(); - if (Btemp < 0) { - logger.info("b negative in volume calc"); - } - calcDelta(); - - setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); - int iterations = 0; - - do { - iterations++; - volInit(); - gcpa = calc_g(); - if (gcpa < 0) { - setMolarVolume(1.0 / Btemp / numberOfMolesInPhase); - gcpa = calc_g(); - } - - // lngcpa = - // Math.log(gcpa); - setGcpav(calc_lngV()); - gcpavv = calc_lngVV(); - gcpavvv = calc_lngVVV(); - - if (getTotalNumberOfAccociationSites() > 0) { - solveX(); - } + return getMolarVolume(); + } + + /** {@inheritDoc} */ + @Override + public double molarVolume(double pressure, double temperature, double A, double B, int phasetype) + throws neqsim.util.exception.IsNaNException, + neqsim.util.exception.TooManyIterationsException { + double BonV = phasetype == 0 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + // if (pressure > 1000) { + // BonV = 0.9999; + // } + + // double calcRooBonVtVolFinder = calcRootVolFinder(phasetype); + // BonV = calcRooBonVtVolFinder; + // double BonVInit = BonV; + if (BonV <= 0) { + BonV = 1.0e-8; + } else if (BonV >= 1.0) { + BonV = 0.9999; + } + double BonVold; + double h = 0; + double dh = 0; + double dhh = 0; + double d1 = 0; + double d2 = 0; + double Btemp = getB(); + if (Btemp < 0) { + logger.info("b negative in volume calc"); + } + calcDelta(); - initCPAMatrix(1); - double BonV2 = BonV * BonV; - BonVold = BonV; - h = BonV - Btemp / numberOfMolesInPhase * dFdV() - - pressure * Btemp / (numberOfMolesInPhase * R * temperature); - dh = 1.0 + Btemp / (BonV2) * (Btemp / numberOfMolesInPhase * dFdVdV()); - dhh = -2.0 * Btemp / (BonV2 * BonV) * (Btemp / numberOfMolesInPhase * dFdVdV()) - - (Btemp * Btemp) / (BonV2 * BonV2) - * (Btemp / numberOfMolesInPhase * dFdVdVdV()); - - d1 = -h / dh; - d2 = -dh / dhh; - // System.out.println("h " + h + " iter " + iterations + " " + d1 + " d2 " + d2 - // + " d1 / d2 " + (d1 / d2)); - if (Math.abs(d1 / d2) <= 1.0) { - BonV += d1 * (1.0 + 0.5 * d1 / d2); - } else if (d1 / d2 < -1) { - BonV += 0.5 * d1; - } else if (d1 > d2) { - BonV += d2; - double hnew = h + d2 * dh; - if (Math.abs(hnew) > Math.abs(h)) { - BonV = phasetype == 1 - ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) - : pressure * getB() / (numberOfMolesInPhase * temperature * R); - } - } else { - BonV += 0.5 * d1; - } - if (Math.abs((BonV - BonVold) / BonVold) > 0.1) { - BonV = BonVold + 0.1 * (BonV - BonVold); - } + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + int iterations = 0; - if (BonV > 0.9999) { - if (iterations < 3) { - BonV = (BonVold + BonV) / 2.0; - } else { - return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); - // BonV = 0.9999; - // BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / - // getPseudoCriticalTemperature()) : pressure * getB() / (numberOfMolesInPhase * - // temperature * R); - } - } else if (BonV < 0) { - if (iterations < 3) { - BonV = Math.abs(BonVold + BonV) / 2.0; - } else { - return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); - // BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / - // getPseudoCriticalTemperature()) : pressure * getB() / (numberOfMolesInPhase * - // temperature * R); - } - } - setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); - Z = pressure * getMolarVolume() / (R * temperature); - } while ((Math.abs((BonV - BonVold) / BonV) > 1.0e-10 || Math.abs(h) > 1e-9) - && iterations < 100); - - if (Math.abs(h) > 1e-9) { - // System.out.println("h failed " + "Z" + Z + " iterations " + iterations + " - // BonV " + BonV); - return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); - } - // System.out.println("Z" + Z + " iterations " + iterations + " BonV " + BonV); - // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); - // System.out.println("volume " + getTotalVolume() + " molar volume " + - // getMolarVolume()); - // if(iterations>=100) throw new util.exception.TooManyIterationsException(); - // System.out.println("error in volume " + - // (-pressure+R*temperature/getMolarVolume()-R*temperature*dFdV()));// + " - // firstterm " + (R*temperature/molarVolume) + " second " + - // R*temperature*dFdV()); - // 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(this, "molarVolume", "Molar volume"); - // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " - // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" - // + fVV()); - } - return getMolarVolume(); - } + do { + iterations++; + volInit(); + gcpa = calc_g(); + if (gcpa < 0) { + setMolarVolume(1.0 / Btemp / numberOfMolesInPhase); + gcpa = calc_g(); + } - /** - *- * molarVolumeChangePhase. - *
- * - * @param pressure a double - * @param temperature a double - * @param A a double - * @param B a double - * @param phasetype a int - * @return a double - * @throws neqsim.util.exception.IsNaNException if any. - * @throws neqsim.util.exception.TooManyIterationsException if any. - */ - public double molarVolumeChangePhase(double pressure, double temperature, double A, double B, - int phasetype) throws neqsim.util.exception.IsNaNException, - neqsim.util.exception.TooManyIterationsException { - // double BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / - // getPseudoCriticalTemperature()) : pressure * getB() / (numberOfMolesInPhase * - // temperature * R); - double BonV = calcRootVolFinder(phasetype); - // double BonVInit = BonV; - if (BonV < 0) { - BonV = 1.0e-8; - } + // lngcpa = + // Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); - if (BonV >= 1.0) { - BonV = 0.9999; + if (getTotalNumberOfAccociationSites() > 0) { + solveX(); + } + + initCPAMatrix(1); + double BonV2 = BonV * BonV; + BonVold = BonV; + h = BonV - Btemp / numberOfMolesInPhase * dFdV() + - pressure * Btemp / (numberOfMolesInPhase * R * temperature); + dh = 1.0 + Btemp / (BonV2) * (Btemp / numberOfMolesInPhase * dFdVdV()); + dhh = -2.0 * Btemp / (BonV2 * BonV) * (Btemp / numberOfMolesInPhase * dFdVdV()) + - (Btemp * Btemp) / (BonV2 * BonV2) * (Btemp / numberOfMolesInPhase * dFdVdVdV()); + + d1 = -h / dh; + d2 = -dh / dhh; + // System.out.println("h " + h + " iter " + iterations + " " + d1 + " d2 " + d2 + // + " d1 / d2 " + (d1 / d2)); + if (Math.abs(d1 / d2) <= 1.0) { + BonV += d1 * (1.0 + 0.5 * d1 / d2); + } else if (d1 / d2 < -1) { + BonV += 0.5 * d1; + } else if (d1 > d2) { + BonV += d2; + double hnew = h + d2 * dh; + if (Math.abs(hnew) > Math.abs(h)) { + BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); } - double BonVold = BonV; - double Btemp = 0, h = 0, dh = 0, dhh = 0; - // double gvvv = 0, fvvv = 0; - double d1 = 0, d2 = 0; - Btemp = getB(); - if (Btemp < 0) { - logger.info("b negative in volume calc"); + } else { + BonV += 0.5 * d1; + } + if (Math.abs((BonV - BonVold) / BonVold) > 0.1) { + BonV = BonVold + 0.1 * (BonV - BonVold); + } + + if (BonV > 0.9999) { + if (iterations < 3) { + BonV = (BonVold + BonV) / 2.0; + } else { + return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + // BonV = 0.9999; + // BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / + // getPseudoCriticalTemperature()) : pressure * getB() / (numberOfMolesInPhase * + // temperature * R); } - calcDelta(); - - setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); - int iterations = 0; - - do { - volInit(); - iterations++; - gcpa = calc_g(); - if (gcpa < 0) { - setMolarVolume(1.0 / Btemp / numberOfMolesInPhase); - gcpa = calc_g(); - } - - // lngcpa = - // Math.log(gcpa); - setGcpav(calc_lngV()); - gcpavv = calc_lngVV(); - gcpavvv = calc_lngVVV(); - - solveX(); - - initCPAMatrix(1); - double BonV2 = BonV * BonV; - BonVold = BonV; - h = BonV - Btemp / numberOfMolesInPhase * dFdV() - - pressure * Btemp / (numberOfMolesInPhase * R * temperature); - dh = 1.0 + Btemp / (BonV2) * (Btemp / numberOfMolesInPhase * dFdVdV()); - dhh = -2.0 * Btemp / (BonV2 * BonV) * (Btemp / numberOfMolesInPhase * dFdVdV()) - - (Btemp * Btemp) / (BonV2 * BonV2) - * (Btemp / numberOfMolesInPhase * dFdVdVdV()); - - d1 = -h / dh; - d2 = -dh / dhh; - // System.out.println("d1" + d1 + " d2 " + d2 + " d1 / d2 " + (d1 / d2)); - if (Math.abs(d1 / d2) <= 1.0) { - BonV += d1 * (1.0 + 0.5 * d1 / d2); - } else if (d1 / d2 < -1) { - BonV += 0.5 * d1; - } else if (d1 > d2) { - BonV += d2; - double hnew = h + d2 * dh; - if (Math.abs(hnew) > Math.abs(h)) { - BonV = phasetype == 1 - ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) - : pressure * getB() / (numberOfMolesInPhase * temperature * R); - } - } else { - BonV += 0.5 * d1; - } - if (Math.abs((BonV - BonVold) / BonVold) > 0.1) { - BonV = BonVold + 0.1 * (BonV - BonVold); - } - - if (BonV > 1.1) { - if (iterations < 3) { - BonV = (BonVold + BonV) / 2.0; - } else { - BonV = phasetype == 1 - ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) - : pressure * getB() / (numberOfMolesInPhase * temperature * R); - } - } - - if (BonV < 0) { - if (iterations < 3) { - BonV = Math.abs(BonVold + BonV) / 2.0; - } else { - BonV = phasetype == 1 - ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) - : pressure * getB() / (numberOfMolesInPhase * temperature * R); - } - } - - setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); - Z = pressure * getMolarVolume() / (R * temperature); - - // System.out.println("Z " + Z + "h " + h + " BONV " + (Math.abs((BonV - - // BonVold) / BonV))); - } while ((Math.abs((BonV - BonVold) / BonV) > 1.0e-10) && iterations < 100); - - /* - * if (Math.abs(h) > 1e-8) { if (phasetype == 0) { molarVolume(pressure, temperature, A, B, - * 1); } else { molarVolume(pressure, temperature, A, B, 0); } return getMolarVolume(); } - */ - // System.out.println("Z" + Z + " iterations " + iterations + " BonV " + BonV); - // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); - // System.out.println("volume " + getTotalVolume() + " molar volume " + - // getMolarVolume()); - // if(iterations>=100) throw new util.exception.TooManyIterationsException(); - // System.out.println("error in volume " + - // (-pressure+R*temperature/getMolarVolume()-R*temperature*dFdV()));// + " - // firstterm " + (R*temperature/molarVolume) + " second " + - // R*temperature*dFdV()); - // 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(this, "molarVolumeChangePhase", - "Molar volume"); - // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " - // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" - // + fVV()); + } else if (BonV < 0) { + if (iterations < 3) { + BonV = Math.abs(BonVold + BonV) / 2.0; + } else { + return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + // BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / + // getPseudoCriticalTemperature()) : pressure * getB() / (numberOfMolesInPhase * + // temperature * R); } - - return getMolarVolume(); + } + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + Z = pressure * getMolarVolume() / (R * temperature); + } while ((Math.abs((BonV - BonVold) / BonV) > 1.0e-10 || Math.abs(h) > 1e-9) + && iterations < 100); + + if (Math.abs(h) > 1e-9) { + // System.out.println("h failed " + "Z" + Z + " iterations " + iterations + " + // BonV " + BonV); + return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); } - - /** {@inheritDoc} */ - @Override - public double getGcpav() { - return gcpav; + // System.out.println("Z" + Z + " iterations " + iterations + " BonV " + BonV); + // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); + // System.out.println("volume " + getTotalVolume() + " molar volume " + + // getMolarVolume()); + // if(iterations>=100) throw new util.exception.TooManyIterationsException(); + // System.out.println("error in volume " + + // (-pressure+R*temperature/getMolarVolume()-R*temperature*dFdV()));// + " + // firstterm " + (R*temperature/molarVolume) + " second " + + // R*temperature*dFdV()); + // 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(this, "molarVolume", "Molar volume"); + // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " + // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + // + fVV()); } - - /** - *
- * Setter for the field gcpav
.
- *
+ * molarVolumeChangePhase. + *
+ * + * @param pressure a double + * @param temperature a double + * @param A a double + * @param B a double + * @param phasetype a int + * @return a double + * @throws neqsim.util.exception.IsNaNException if any. + * @throws neqsim.util.exception.TooManyIterationsException if any. + */ + public double molarVolumeChangePhase(double pressure, double temperature, double A, double B, + int phasetype) throws neqsim.util.exception.IsNaNException, + neqsim.util.exception.TooManyIterationsException { + // double BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / + // getPseudoCriticalTemperature()) : pressure * getB() / (numberOfMolesInPhase * + // temperature * R); + double BonV = calcRootVolFinder(phasetype); + // double BonVInit = BonV; + if (BonV < 0) { + BonV = 1.0e-8; } - /** {@inheritDoc} */ - @Override - public CPAMixingInterface getCpamix() { - return cpamix; + if (BonV >= 1.0) { + BonV = 0.9999; } - - /** {@inheritDoc} */ - @Override - public double calcPressure() { - gcpa = calc_g(); - // lngcpa = - // Math.log(gcpa); - setGcpav(calc_lngV()); - gcpavv = calc_lngVV(); - gcpavvv = calc_lngVVV(); - solveX(); - hcpatot = calc_hCPA(); - - initCPAMatrix(1); - return super.calcPressure(); + double BonVold = BonV; + double Btemp = 0; + double h = 0; + double dh = 0; + double dhh = 0; + double d1 = 0; + double d2 = 0; + Btemp = getB(); + if (Btemp < 0) { + logger.info("b negative in volume calc"); } + calcDelta(); + + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + int iterations = 0; - /** {@inheritDoc} */ - @Override - public int getCrossAssosiationScheme(int comp1, int comp2, int site1, int site2) { - if (comp1 == comp2) { - return selfAccociationScheme[comp1][site1][site2]; + do { + volInit(); + iterations++; + gcpa = calc_g(); + if (gcpa < 0) { + setMolarVolume(1.0 / Btemp / numberOfMolesInPhase); + gcpa = calc_g(); + } + + // lngcpa = + // Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + + solveX(); + + initCPAMatrix(1); + double BonV2 = BonV * BonV; + BonVold = BonV; + h = BonV - Btemp / numberOfMolesInPhase * dFdV() + - pressure * Btemp / (numberOfMolesInPhase * R * temperature); + dh = 1.0 + Btemp / (BonV2) * (Btemp / numberOfMolesInPhase * dFdVdV()); + dhh = -2.0 * Btemp / (BonV2 * BonV) * (Btemp / numberOfMolesInPhase * dFdVdV()) + - (Btemp * Btemp) / (BonV2 * BonV2) * (Btemp / numberOfMolesInPhase * dFdVdVdV()); + + d1 = -h / dh; + d2 = -dh / dhh; + // System.out.println("d1" + d1 + " d2 " + d2 + " d1 / d2 " + (d1 / d2)); + if (Math.abs(d1 / d2) <= 1.0) { + BonV += d1 * (1.0 + 0.5 * d1 / d2); + } else if (d1 / d2 < -1) { + BonV += 0.5 * d1; + } else if (d1 > d2) { + BonV += d2; + double hnew = h + d2 * dh; + if (Math.abs(hnew) > Math.abs(h)) { + BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + } + } else { + BonV += 0.5 * d1; + } + if (Math.abs((BonV - BonVold) / BonVold) > 0.1) { + BonV = BonVold + 0.1 * (BonV - BonVold); + } + + if (BonV > 1.1) { + if (iterations < 3) { + BonV = (BonVold + BonV) / 2.0; } else { - return crossAccociationScheme[comp1][comp2][site1][site2]; + BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); } - } + } - /** - *- * croeneckerProduct. - *
- * - * @param a an array of {@link double} objects - * @param b an array of {@link double} objects - * @return an array of {@link double} objects - */ - public double[][] croeneckerProduct(double[][] a, double[][] b) { - int aLength = a.length; - int aCols = a[0].length; - int bLength = b.length; - int bCols = b[0].length; - double[][] result = new double[aLength * bLength][(aCols) * (bCols)]; - for (int z = 0; z < aLength; z++) { - for (int i = 0; i < aCols; i++) { - for (int j = 0; j < bLength; j++) { - for (int k = 0; k < bCols; k++) { - result[j + (z * bLength)][k + (i * bCols)] = a[z][i] * b[j][k]; - } - } - } + if (BonV < 0) { + if (iterations < 3) { + BonV = Math.abs(BonVold + BonV) / 2.0; + } else { + BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); } - return result; - } + } - /** {@inheritDoc} */ - @Override - public int getTotalNumberOfAccociationSites() { - return totalNumberOfAccociationSites; - } + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + Z = pressure * getMolarVolume() / (R * temperature); - /** {@inheritDoc} */ - @Override - public void setTotalNumberOfAccociationSites(int totalNumberOfAccociationSites) { - this.totalNumberOfAccociationSites = totalNumberOfAccociationSites; - } + // System.out.println("Z " + Z + "h " + h + " BONV " + (Math.abs((BonV - + // BonVold) / BonV))); + } while ((Math.abs((BonV - BonVold) / BonV) > 1.0e-10) && iterations < 100); - /** - *- * calc_g. - *
- * - * @return a double + /* + * if (Math.abs(h) > 1e-8) { if (phasetype == 0) { molarVolume(pressure, temperature, A, B, 1); + * } else { molarVolume(pressure, temperature, A, B, 0); } return getMolarVolume(); } */ - public double calc_g() { - double x = 1.9 / 4.0 * getB() / getTotalVolume(); - double g = 1.0 / (1.0 - x); - // System.out.println("g " + g); - return g; + // System.out.println("Z" + Z + " iterations " + iterations + " BonV " + BonV); + // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); + // System.out.println("volume " + getTotalVolume() + " molar volume " + + // getMolarVolume()); + // if(iterations>=100) throw new util.exception.TooManyIterationsException(); + // System.out.println("error in volume " + + // (-pressure+R*temperature/getMolarVolume()-R*temperature*dFdV()));// + " + // firstterm " + (R*temperature/molarVolume) + " second " + + // R*temperature*dFdV()); + // 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(this, "molarVolumeChangePhase", + "Molar volume"); + // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " + // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + // + fVV()); } - /** - *- * calc_lngV. - *
- * - * @return a double - */ - public double calc_lngV() { - double x = 1.9 / 4.0 * getB() / getTotalVolume(); - double gv = (x / getTotalVolume()) / (1.0 - x); - return -gv; + return getMolarVolume(); + } + + /** {@inheritDoc} */ + @Override + public double getGcpav() { + return gcpav; + } + + /** + *
+ * Setter for the field gcpav
.
+ *
- * calc_lngVV. - *
- * - * @return a double - */ - public double calc_lngVV() { - double x = 1.9 / 4.0 * getB() / getTotalVolume(); - double xV = -1.9 / 4.0 * getB() / (getTotalVolume() * getTotalVolume()); - double u = 1.0 - x; - - double val = -x / (getTotalVolume() * getTotalVolume() * u) + xV / (getTotalVolume() * u) - - x / (getTotalVolume() * u * u) * (-1.0) * xV; - return -val; - - // double gvv - // =0.225625/Math.pow(1.0-0.475*getB()/getTotalVolume(),2.0)*Math.pow(getB(),2.0)/(Math.pow(getTotalVolume(),4.0))+0.95/(1.0-0.475*getB()/getTotalVolume())*getB()/(Math.pow(getTotalVolume(),3.0)); - // System.out.println("val2 " + gvv); - // return gvv; - } - - /** - *- * calc_lngVVV. - *
- * - * @return a double - */ - public double calc_lngVVV() { - double totVol = getTotalVolume(); - double totVol4 = totVol * totVol * totVol * totVol; - double totVol5 = totVol4 * totVol; - - double temp1 = 1.0 - 0.475 * getB() / getTotalVolume(); - double gvv = -0.21434375 / (temp1 * temp1 * temp1) * getB() * getB() * getB() - / (totVol5 * totVol) - 0.135375E1 / (temp1 * temp1) * getB() * getB() / (totVol5) - - 0.285E1 / (temp1) * getB() / (totVol4); - return gvv; + } + + /** + *+ * croeneckerProduct. + *
+ * + * @param a an array of {@link double} objects + * @param b an array of {@link double} objects + * @return an array of {@link double} objects + */ + public double[][] croeneckerProduct(double[][] a, double[][] b) { + int aLength = a.length; + int aCols = a[0].length; + int bLength = b.length; + int bCols = b[0].length; + double[][] result = new double[aLength * bLength][(aCols) * (bCols)]; + for (int z = 0; z < aLength; z++) { + for (int i = 0; i < aCols; i++) { + for (int j = 0; j < bLength; j++) { + for (int k = 0; k < bCols; k++) { + result[j + (z * bLength)][k + (i * bCols)] = a[z][i] * b[j][k]; + } + } + } } + return result; + } + + /** {@inheritDoc} */ + @Override + public int getTotalNumberOfAccociationSites() { + return totalNumberOfAccociationSites; + } + + /** {@inheritDoc} */ + @Override + public void setTotalNumberOfAccociationSites(int totalNumberOfAccociationSites) { + this.totalNumberOfAccociationSites = totalNumberOfAccociationSites; + } + + /** + *+ * calc_g. + *
+ * + * @return a double + */ + public double calc_g() { + double x = 1.9 / 4.0 * getB() / getTotalVolume(); + double g = 1.0 / (1.0 - x); + // System.out.println("g " + g); + return g; + } + + /** + *+ * calc_lngV. + *
+ * + * @return a double + */ + public double calc_lngV() { + double x = 1.9 / 4.0 * getB() / getTotalVolume(); + double gv = (x / getTotalVolume()) / (1.0 - x); + return -gv; + } + + /** + *+ * calc_lngVV. + *
+ * + * @return a double + */ + public double calc_lngVV() { + double x = 1.9 / 4.0 * getB() / getTotalVolume(); + double xV = -1.9 / 4.0 * getB() / (getTotalVolume() * getTotalVolume()); + double u = 1.0 - x; + + double val = -x / (getTotalVolume() * getTotalVolume() * u) + xV / (getTotalVolume() * u) + - x / (getTotalVolume() * u * u) * (-1.0) * xV; + return -val; + + // double gvv + // =0.225625/Math.pow(1.0-0.475*getB()/getTotalVolume(),2.0)*Math.pow(getB(),2.0)/(Math.pow(getTotalVolume(),4.0))+0.95/(1.0-0.475*getB()/getTotalVolume())*getB()/(Math.pow(getTotalVolume(),3.0)); + // System.out.println("val2 " + gvv); + // return gvv; + } + + /** + *+ * calc_lngVVV. + *
+ * + * @return a double + */ + public double calc_lngVVV() { + double totVol = getTotalVolume(); + double totVol4 = totVol * totVol * totVol * totVol; + double totVol5 = totVol4 * totVol; + + double temp1 = 1.0 - 0.475 * getB() / getTotalVolume(); + double gvv = + -0.21434375 / (temp1 * temp1 * temp1) * getB() * getB() * getB() / (totVol5 * totVol) + - 0.135375E1 / (temp1 * temp1) * getB() * getB() / (totVol5) + - 0.285E1 / (temp1) * getB() / (totVol4); + return gvv; + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/freezingFit/TestSolidComplexFunction.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/freezingFit/TestSolidComplexFunction.java index 3878c7228c..b7e1a820ab 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/freezingFit/TestSolidComplexFunction.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/freezingFit/TestSolidComplexFunction.java @@ -20,58 +20,58 @@ * @version $Id: $Id */ public class TestSolidComplexFunction { - static Logger logger = LogManager.getLogger(TestSolidComplexFunction.class); + static Logger logger = LogManager.getLogger(TestSolidComplexFunction.class); - /** - *- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList- * Constructor for IonicInteractionParameterFittingFunction_CO2. - *
- */ - public IonicInteractionParameterFittingFunction_CO2() {} + /** + *+ * Constructor for IonicInteractionParameterFittingFunction_CO2. + *
+ */ + public IonicInteractionParameterFittingFunction_CO2() {} - /** {@inheritDoc} */ - @Override - public double calcValue(double[] dependentValues) { - try { - thermoOps.bubblePointPressureFlash(false); - } catch (Exception e) { - logger.error(e.toString()); - } - return system.getPressure() * system.getPhases()[0].getComponent(0).getx(); + /** {@inheritDoc} */ + @Override + public double calcValue(double[] dependentValues) { + try { + thermoOps.bubblePointPressureFlash(false); + } catch (Exception e) { + logger.error(e.toString()); } + return system.getPressure() * system.getPhases()[0].getComponent(0).getx(); + } - /** {@inheritDoc} */ - @Override - public double calcTrueValue(double val) { - return val; - } + /** {@inheritDoc} */ + @Override + public double calcTrueValue(double val) { + return val; + } - /** {@inheritDoc} */ - @Override - public void setFittingParams(int i, double value) { - params[i] = value; - int MDEAplusNumb = 0, MDEANumb = 0, CO2Numb = 0, HCO3numb = 0, Waternumb = 0; - int j = 0; - do { - MDEAplusNumb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEA+")); - j = 0; + /** {@inheritDoc} */ + @Override + public void setFittingParams(int i, double value) { + params[i] = value; + int MDEAplusNumb = 0, MDEANumb = 0, CO2Numb = 0, HCO3numb = 0, Waternumb = 0; + int j = 0; + do { + MDEAplusNumb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEA+")); + j = 0; - do { - MDEANumb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEA")); - j = 0; - do { - CO2Numb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("CO2")); - j = 0; + do { + MDEANumb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEA")); + j = 0; + do { + CO2Numb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("CO2")); + j = 0; - do { - HCO3numb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("HCO3-")); - j = 0; - do { - Waternumb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("water")); + do { + HCO3numb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("HCO3-")); + j = 0; + do { + Waternumb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("water")); - if (i == 1) { - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) - .setHVDijParameter(CO2Numb, MDEANumb, value); - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) - .setHVDijParameter(CO2Numb, MDEANumb, value); - } - if (i == 0) { - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) - .setHVDijParameter(MDEANumb, CO2Numb, value); - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) - .setHVDijParameter(MDEANumb, CO2Numb, value); - } - if (i == 2) { - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) - .setHVDijTParameter(CO2Numb, MDEANumb, value); - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) - .setHVDijTParameter(CO2Numb, MDEANumb, value); - } - if (i == 3) { - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) - .setHVDijTParameter(MDEANumb, CO2Numb, value); - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) - .setHVDijTParameter(MDEANumb, CO2Numb, value); - } - if (i == 4) { - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) - .setHValphaParameter(CO2Numb, MDEANumb, value); - ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) - .setHValphaParameter(CO2Numb, MDEANumb, value); - } - if (i == 5) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, CO2Numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, CO2Numb, value); - } - // if(i==2){ - // ((HVmixingRuleInterface) - // ((PhaseEosInterface)system.getPhases()[0]).getMixingRule()).setHVDijTParameter(CO2Numb,MDEANumb, - // value); - // ((HVmixingRuleInterface) - // ((PhaseEosInterface)system.getPhases()[1]).getMixingRule()).setHVDijTParameter(CO2Numb,MDEANumb, - // value); - // } - // if(i==3){ - // ((HVmixingRuleInterface) - // ((PhaseEosInterface)system.getPhases()[0]).getMixingRule()).setHVDijTParameter(MDEANumb, - // CO2Numb, value); - // ((HVmixingRuleInterface) - // ((PhaseEosInterface)system.getPhases()[1]).getMixingRule()).setHVDijTParameter(MDEANumb, - // CO2Numb, value); - // } + if (i == 1) { + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) + .setHVDijParameter(CO2Numb, MDEANumb, value); + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) + .setHVDijParameter(CO2Numb, MDEANumb, value); + } + if (i == 0) { + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) + .setHVDijParameter(MDEANumb, CO2Numb, value); + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) + .setHVDijParameter(MDEANumb, CO2Numb, value); + } + if (i == 2) { + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) + .setHVDijTParameter(CO2Numb, MDEANumb, value); + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) + .setHVDijTParameter(CO2Numb, MDEANumb, value); + } + if (i == 3) { + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) + .setHVDijTParameter(MDEANumb, CO2Numb, value); + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) + .setHVDijTParameter(MDEANumb, CO2Numb, value); + } + if (i == 4) { + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[0]).getMixingRule()) + .setHValphaParameter(CO2Numb, MDEANumb, value); + ((HVmixingRuleInterface) ((PhaseEosInterface) system.getPhases()[1]).getMixingRule()) + .setHValphaParameter(CO2Numb, MDEANumb, value); + } + if (i == 5) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, CO2Numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, CO2Numb, value); + } + // if(i==2){ + // ((HVmixingRuleInterface) + // ((PhaseEosInterface)system.getPhases()[0]).getMixingRule()).setHVDijTParameter(CO2Numb,MDEANumb, + // value); + // ((HVmixingRuleInterface) + // ((PhaseEosInterface)system.getPhases()[1]).getMixingRule()).setHVDijTParameter(CO2Numb,MDEANumb, + // value); + // } + // if(i==3){ + // ((HVmixingRuleInterface) + // ((PhaseEosInterface)system.getPhases()[0]).getMixingRule()).setHVDijTParameter(MDEANumb, + // CO2Numb, value); + // ((HVmixingRuleInterface) + // ((PhaseEosInterface)system.getPhases()[1]).getMixingRule()).setHVDijTParameter(MDEANumb, + // CO2Numb, value); + // } - if (i == 30) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, MDEANumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, MDEANumb, value); - } - if (i == 20) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, CO2Numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, CO2Numb, value); - } - if (i == 66) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, HCO3numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, HCO3numb, value); - } - if (i == 56) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, Waternumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, Waternumb, value); - } + if (i == 30) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, MDEANumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, MDEANumb, value); + } + if (i == 20) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, CO2Numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, CO2Numb, value); + } + if (i == 66) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, HCO3numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, HCO3numb, value); + } + if (i == 56) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, Waternumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, Waternumb, value); + } - // Temp der 1 - if (i == 30) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, MDEANumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, MDEANumb, value); - } - if (i == 20) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, CO2Numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, CO2Numb, value); - } - if (i == 40) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, HCO3numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, HCO3numb, value); - } - if (i == 50) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, Waternumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, Waternumb, value); - } + // Temp der 1 + if (i == 30) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, MDEANumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, MDEANumb, value); + } + if (i == 20) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, CO2Numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, CO2Numb, value); + } + if (i == 40) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, HCO3numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, HCO3numb, value); + } + if (i == 50) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, Waternumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, Waternumb, value); + } - // Temp der 2 - if (i == 60) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, MDEANumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, MDEANumb, value); - } - if (i == 20) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, CO2Numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, CO2Numb, value); - } - if (i == 7) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, HCO3numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, HCO3numb, value); - } - if (i == 8) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, Waternumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, Waternumb, value); - } + // Temp der 2 + if (i == 60) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, MDEANumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, MDEANumb, value); + } + if (i == 20) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, CO2Numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, CO2Numb, value); + } + if (i == 7) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, HCO3numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, HCO3numb, value); + } + if (i == 8) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, Waternumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, Waternumb, value); } + } - /** - *- * setFittingParams5. - *
- * - * @param i a int - * @param value a double - */ - public void setFittingParams5(int i, double value) { - params[i] = value; - int MDEAplusNumb = 0, MDEANumb = 0, CO2Numb = 0, HCO3numb = 0, Waternumb = 0; - int j = 0; - do { - MDEAplusNumb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName() - .equals("MDEAplus")); - j = 0; + /** + *+ * setFittingParams5. + *
+ * + * @param i a int + * @param value a double + */ + public void setFittingParams5(int i, double value) { + params[i] = value; + int MDEAplusNumb = 0, MDEANumb = 0, CO2Numb = 0, HCO3numb = 0, Waternumb = 0; + int j = 0; + do { + MDEAplusNumb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEAplus")); + j = 0; - do { - MDEANumb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEA")); - j = 0; - do { - CO2Numb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("CO2")); - j = 0; + do { + MDEANumb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEA")); + j = 0; + do { + CO2Numb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("CO2")); + j = 0; - do { - HCO3numb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName() - .equals("HCO3minus")); - j = 0; - do { - Waternumb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("water")); + do { + HCO3numb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("HCO3minus")); + j = 0; + do { + Waternumb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("water")); - // Temp der 1 - if (i == 0) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, MDEANumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, MDEANumb, value); - } - if (i == 3) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, CO2Numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, CO2Numb, value); - } - if (i == 1) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, HCO3numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, HCO3numb, value); - } - if (i == 2) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, Waternumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT1Parameter(MDEAplusNumb, Waternumb, value); - } + // Temp der 1 + if (i == 0) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, MDEANumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, MDEANumb, value); + } + if (i == 3) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, CO2Numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, CO2Numb, value); + } + if (i == 1) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, HCO3numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, HCO3numb, value); + } + if (i == 2) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, Waternumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT1Parameter(MDEAplusNumb, Waternumb, value); + } - // Temp der 2 - if (i == 23) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, MDEANumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, MDEANumb, value); - } - if (i == 20) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, CO2Numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, CO2Numb, value); - } - if (i == 4) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, HCO3numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, HCO3numb, value); - } - if (i == 5) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, Waternumb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijT2Parameter(MDEAplusNumb, Waternumb, value); - } + // Temp der 2 + if (i == 23) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, MDEANumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, MDEANumb, value); + } + if (i == 20) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, CO2Numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, CO2Numb, value); + } + if (i == 4) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, HCO3numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, HCO3numb, value); } + if (i == 5) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, Waternumb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijT2Parameter(MDEAplusNumb, Waternumb, value); + } + } - /** - *- * setFittingParams3. - *
- * - * @param i a int - * @param value a double - */ - public void setFittingParams3(int i, double value) { - params[i] = value; - int MDEAplusNumb = 0, CO2Numb = 0; - // double MDEANumb = 0, HCO3numb = 0, Waternumb = 0; - int j = 0; - do { - MDEAplusNumb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName() - .equals("MDEAplus")); - j = 0; + /** + *+ * setFittingParams3. + *
+ * + * @param i a int + * @param value a double + */ + public void setFittingParams3(int i, double value) { + params[i] = value; + int MDEAplusNumb = 0, CO2Numb = 0; + int j = 0; + do { + MDEAplusNumb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEAplus")); + j = 0; - do { - // MDEANumb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEA")); - j = 0; - do { - CO2Numb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("CO2")); - j = 0; + do { + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("MDEA")); + j = 0; + do { + CO2Numb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("CO2")); + j = 0; - do { - // HCO3numb = j; - j++; - } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName() - .equals("HCO3minus")); + do { + // HCO3numb = j; + j++; + } while (!system.getPhases()[0].getComponents()[j - 1].getComponentName().equals("HCO3minus")); - /* - * j = 0; do { Waternumb = j; j++; } while (!system.getPhases()[0].getComponents()[j - - * 1].getComponentName().equals("water")); - */ + /* + * j = 0; do { Waternumb = j; j++; } while (!system.getPhases()[0].getComponents()[j - + * 1].getComponentName().equals("water")); + */ - if (i == 0) { - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, CO2Numb, value); - ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() - .setWijParameter(MDEAplusNumb, CO2Numb, value); - } + if (i == 0) { + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[0]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, CO2Numb, value); + ((PhaseModifiedFurstElectrolyteEos) system.getPhases()[1]).getElectrolyteMixingRule() + .setWijParameter(MDEAplusNumb, CO2Numb, value); } + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/PSFlash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/PSFlash.java index 553835ecb9..106c041b1f 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/PSFlash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/PSFlash.java @@ -11,130 +11,127 @@ * @version $Id: $Id */ public class PSFlash extends QfuncFlash { - private static final long serialVersionUID = 1000; - - double Sspec = 0; - Flash tpFlash; - int type = 0; - - /** - *- * Constructor for PSFlash. - *
- */ - public PSFlash() {} - - /** - *- * Constructor for PSFlash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param Sspec a double - * @param type a int - */ - public PSFlash(SystemInterface system, double Sspec, int type) { - this.system = system; - this.tpFlash = new TPflash(system); - this.Sspec = Sspec; - this.type = type; + private static final long serialVersionUID = 1000; + + double Sspec = 0; + Flash tpFlash; + int type = 0; + + /** + *+ * Constructor for PSFlash. + *
+ */ + public PSFlash() {} + + /** + *+ * Constructor for PSFlash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param Sspec a double + * @param type a int + */ + public PSFlash(SystemInterface system, double Sspec, int type) { + this.system = system; + this.tpFlash = new TPflash(system); + this.Sspec = Sspec; + this.type = type; + } + + /** {@inheritDoc} */ + @Override + public double calcdQdTT() { + if (system.getNumberOfPhases() == 1) { + return -system.getPhase(0).getCp() / system.getTemperature(); } - /** {@inheritDoc} */ - @Override - public double calcdQdTT() { - // double cP1 = 0.0, cP2 = 0.0; - - if (system.getNumberOfPhases() == 1) { - return -system.getPhase(0).getCp() / system.getTemperature(); - } - - double dQdTT = 0.0; - for (int i = 0; i < system.getNumberOfPhases(); i++) { - dQdTT -= system.getPhase(i).getCp() / system.getPhase(i).getTemperature(); - } - return dQdTT; - } - - /** {@inheritDoc} */ - @Override - public double calcdQdT() { - double dQ = -system.getEntropy() + Sspec; - return dQ; + double dQdTT = 0.0; + for (int i = 0; i < system.getNumberOfPhases(); i++) { + dQdTT -= system.getPhase(i).getCp() / system.getPhase(i).getTemperature(); } - - /** {@inheritDoc} */ - @Override - public double solveQ() { - double oldTemp = system.getTemperature(), nyTemp = system.getTemperature(); - int iterations = 1; - double error = 1.0, erorOld = 10.0e10; - double factor = 0.8; - - boolean correctFactor = true; - double newCorr = 1.0; - system.init(2); - - do { - if (error > erorOld && factor > 0.1 && correctFactor) { - factor *= 0.5; - } else if (error < erorOld && correctFactor) { - factor = 1.0; - } - - iterations++; - oldTemp = system.getTemperature(); - - newCorr = factor * calcdQdT() / calcdQdTT(); - nyTemp = oldTemp - newCorr; - if (Math.abs(system.getTemperature() - nyTemp) > 10.0) { - nyTemp = system.getTemperature() - - Math.signum(system.getTemperature() - nyTemp) * 10.0; - correctFactor = false; - } else if (nyTemp < 0) { - nyTemp = Math.abs(system.getTemperature() - 10.0); - correctFactor = false; - } else if (Double.isNaN(nyTemp)) { - nyTemp = oldTemp + 1.0; - correctFactor = false; - } else { - correctFactor = true; - } - - system.setTemperature(nyTemp); - tpFlash.run(); - system.init(2); - erorOld = error; - error = Math.abs(calcdQdT());// Math.abs((nyTemp - oldTemp) / (nyTemp)); - // if(error>erorOld) factor *= -1.0; - // System.out.println("temp " + system.getTemperature() + " iter "+ iterations + - // " error "+ error + " correction " + newCorr + " factor "+ factor); - // newCorr = Math.abs(factor * calcdQdT() / calcdQdTT()); - } while (((error + erorOld) > 1e-8 || iterations < 3) && iterations < 200); - return nyTemp; - } - - /** - *- * onPhaseSolve. - *
- */ - public void onPhaseSolve() {} - - /** {@inheritDoc} */ - @Override - public void run() { - tpFlash.run(); - - if (type == 0) { - solveQ(); - } else { - sysNewtonRhapsonPHflash secondOrderSolver = new sysNewtonRhapsonPHflash(system, 2, - system.getPhases()[0].getNumberOfComponents(), 1); - secondOrderSolver.setSpec(Sspec); - secondOrderSolver.solve(1); - } - // System.out.println("Entropy: " + system.getEntropy()); - // System.out.println("Temperature: " + system.getTemperature()); + return dQdTT; + } + + /** {@inheritDoc} */ + @Override + public double calcdQdT() { + double dQ = -system.getEntropy() + Sspec; + return dQ; + } + + /** {@inheritDoc} */ + @Override + public double solveQ() { + double oldTemp = system.getTemperature(), nyTemp = system.getTemperature(); + int iterations = 1; + double error = 1.0, erorOld = 10.0e10; + double factor = 0.8; + + boolean correctFactor = true; + double newCorr = 1.0; + system.init(2); + + do { + if (error > erorOld && factor > 0.1 && correctFactor) { + factor *= 0.5; + } else if (error < erorOld && correctFactor) { + factor = 1.0; + } + + iterations++; + oldTemp = system.getTemperature(); + + newCorr = factor * calcdQdT() / calcdQdTT(); + nyTemp = oldTemp - newCorr; + if (Math.abs(system.getTemperature() - nyTemp) > 10.0) { + nyTemp = system.getTemperature() - Math.signum(system.getTemperature() - nyTemp) * 10.0; + correctFactor = false; + } else if (nyTemp < 0) { + nyTemp = Math.abs(system.getTemperature() - 10.0); + correctFactor = false; + } else if (Double.isNaN(nyTemp)) { + nyTemp = oldTemp + 1.0; + correctFactor = false; + } else { + correctFactor = true; + } + + system.setTemperature(nyTemp); + tpFlash.run(); + system.init(2); + erorOld = error; + error = Math.abs(calcdQdT());// Math.abs((nyTemp - oldTemp) / (nyTemp)); + // if(error>erorOld) factor *= -1.0; + // System.out.println("temp " + system.getTemperature() + " iter "+ iterations + + // " error "+ error + " correction " + newCorr + " factor "+ factor); + // newCorr = Math.abs(factor * calcdQdT() / calcdQdTT()); + } while (((error + erorOld) > 1e-8 || iterations < 3) && iterations < 200); + return nyTemp; + } + + /** + *+ * onPhaseSolve. + *
+ */ + public void onPhaseSolve() {} + + /** {@inheritDoc} */ + @Override + public void run() { + tpFlash.run(); + + if (type == 0) { + solveQ(); + } else { + sysNewtonRhapsonPHflash secondOrderSolver = + new sysNewtonRhapsonPHflash(system, 2, system.getPhases()[0].getNumberOfComponents(), 1); + secondOrderSolver.setSpec(Sspec); + secondOrderSolver.solve(1); } + // System.out.println("Entropy: " + system.getEntropy()); + // System.out.println("Temperature: " + system.getTemperature()); + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/PVrefluxflash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/PVrefluxflash.java index 6eb1387996..d1ef332044 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/PVrefluxflash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/PVrefluxflash.java @@ -11,81 +11,79 @@ * @version $Id: $Id */ public class PVrefluxflash extends Flash { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - Flash tpFlash; - int refluxPhase = 0; - double refluxSpec = 0.5; + Flash tpFlash; + int refluxPhase = 0; + double refluxSpec = 0.5; - /** - *- * Constructor for PVrefluxflash. - *
- */ - public PVrefluxflash() {} + /** + *+ * Constructor for PVrefluxflash. + *
+ */ + public PVrefluxflash() {} - /** - *- * Constructor for PVrefluxflash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param refluxSpec a double - * @param refluxPhase a int - */ - public PVrefluxflash(SystemInterface system, double refluxSpec, int refluxPhase) { - this.system = system; - this.tpFlash = new TPflash(system); - this.refluxSpec = refluxSpec; - this.refluxPhase = refluxPhase; - } + /** + *+ * Constructor for PVrefluxflash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param refluxSpec a double + * @param refluxPhase a int + */ + public PVrefluxflash(SystemInterface system, double refluxSpec, int refluxPhase) { + this.system = system; + this.tpFlash = new TPflash(system); + this.refluxSpec = refluxSpec; + this.refluxPhase = refluxPhase; + } - /** {@inheritDoc} */ - @Override - public void run() { - // System.out.println("enthalpy: " + system.getEnthalpy()); - // double err = 0; - int iter = 0; - double f_func = 0.0, f_func_old = 0.0, df_func_dt = 0, t_old = 0, t_oldold = 0.0; - tpFlash.run(); - double dt = 1.0; - do { - iter++; + /** {@inheritDoc} */ + @Override + public void run() { + int iter = 0; + double f_func = 0.0, f_func_old = 0.0, df_func_dt = 0, t_old = 0, t_oldold = 0.0; + tpFlash.run(); + double dt = 1.0; + do { + iter++; - f_func_old = f_func; - t_oldold = t_old; - t_old = system.getTemperature(); + f_func_old = f_func; + t_oldold = t_old; + t_old = system.getTemperature(); - f_func = refluxSpec - (1.0 / system.getBeta(refluxPhase) - 1.0);// system.getPhase(refluxPhase).getVolume() - // / system.getVolume(); - df_func_dt = (f_func - f_func_old) / (t_old - t_oldold); + f_func = refluxSpec - (1.0 / system.getBeta(refluxPhase) - 1.0);// system.getPhase(refluxPhase).getVolume() + // / system.getVolume(); + df_func_dt = (f_func - f_func_old) / (t_old - t_oldold); - // err = Math.abs(f_func); + // err = Math.abs(f_func); - if (iter < 4) { - if (f_func > 0) { - system.setTemperature(system.getTemperature() + 0.1); - } else if (f_func < 0) { - system.setTemperature(system.getTemperature() - 0.1); - } - } else { - dt = f_func / df_func_dt; - if (Math.abs(dt) > 2.0) { - dt = Math.signum(dt) * 2.0; - } + if (iter < 4) { + if (f_func > 0) { + system.setTemperature(system.getTemperature() + 0.1); + } else if (f_func < 0) { + system.setTemperature(system.getTemperature() - 0.1); + } + } else { + dt = f_func / df_func_dt; + if (Math.abs(dt) > 2.0) { + dt = Math.signum(dt) * 2.0; + } - system.setTemperature(system.getTemperature() - dt * (1.0 * iter) / (iter + 50.0)); - } - tpFlash.run(); + system.setTemperature(system.getTemperature() - dt * (1.0 * iter) / (iter + 50.0)); + } + tpFlash.run(); - // System.out.println("temp " + system.getTemperature() + " err " + err + " - // volfor " + system.getPhase(refluxPhase).getVolume() / system.getVolume()); - } while (Math.abs(dt) > 1e-8 && Math.abs(f_func) > 1e-6 && iter < 1000); - } + // System.out.println("temp " + system.getTemperature() + " err " + err + " + // volfor " + system.getPhase(refluxPhase).getVolume() / system.getVolume()); + } while (Math.abs(dt) > 1e-8 && Math.abs(f_func) > 1e-6 && iter < 1000); + } - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java index ee93f6edcc..aa1444a405 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/TPmultiflash.java @@ -24,1012 +24,998 @@ * @version $Id: $Id */ public class TPmultiflash extends TPflash { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(TPmultiflash.class); - - // SystemInterface clonedSystem; - boolean multiPhaseTest = false; - double dQdbeta[][]; - double Qmatrix[][]; - double Erow[]; - double Q = 0; - boolean doStabilityAnalysis = true; - boolean removePhase = false, checkOneRemove = false; - boolean secondTime = false; - - double[] multTerm, multTerm2; - - /** - *- * Constructor for TPmultiflash. - *
- */ - public TPmultiflash() {} - - /** - *- * Constructor for TPmultiflash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public TPmultiflash(SystemInterface system) { - super(system); - Erow = new double[system.getPhase(0).getNumberOfComponents()]; - } + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(TPmultiflash.class); + + // SystemInterface clonedSystem; + boolean multiPhaseTest = false; + double dQdbeta[][]; + double Qmatrix[][]; + double[] Erow; + double Q = 0; + boolean doStabilityAnalysis = true; + boolean removePhase = false; + boolean checkOneRemove = false; + boolean secondTime = false; + + double[] multTerm; + double[] multTerm2; + + /** + *+ * Constructor for TPmultiflash. + *
+ */ + public TPmultiflash() {} + + /** + *+ * Constructor for TPmultiflash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public TPmultiflash(SystemInterface system) { + super(system); + Erow = new double[system.getPhase(0).getNumberOfComponents()]; + } + + /** + *+ * Constructor for TPmultiflash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param check a boolean + */ + public TPmultiflash(SystemInterface system, boolean check) { + super(system, check); + Erow = new double[system.getPhase(0).getNumberOfComponents()]; + multTerm = new double[system.getPhase(0).getNumberOfComponents()]; + multTerm2 = new double[system.getPhase(0).getNumberOfComponents()]; + } + + /** + *+ * calcMultiPhaseBeta. + *
+ */ + public void calcMultiPhaseBeta() {} + + /** + *+ * setDoubleArrays. + *
+ */ + public void setDoubleArrays() { + dQdbeta = new double[system.getNumberOfPhases()][1]; + Qmatrix = new double[system.getNumberOfPhases()][system.getNumberOfPhases()]; + } + + /** + *+ * setXY. + *
+ */ + public void setXY() { + for (int k = 0; k < system.getNumberOfPhases(); k++) { + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getz() > 1e-100) { + system.getPhase(k).getComponents()[i].setx(system.getPhase(0).getComponents()[i].getz() + / Erow[i] / system.getPhase(k).getComponent(i).getFugacityCoefficient()); + } + if (system.getPhase(0).getComponent(i).getIonicCharge() != 0 + && !system.getPhase(k).getPhaseTypeName().equals("aqueous")) { + system.getPhase(k).getComponents()[i].setx(1e-50); + } + if (system.getPhase(0).getComponent(i).getIonicCharge() != 0 + && system.getPhase(k).getPhaseTypeName().equals("aqueous")) { + system.getPhase(k).getComponents()[i] + .setx(system.getPhase(k).getComponents()[i].getNumberOfmoles() + / system.getPhase(k).getNumberOfMolesInPhase()); + } + } - /** - *- * Constructor for TPmultiflash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param check a boolean - */ - public TPmultiflash(SystemInterface system, boolean check) { - super(system, check); - Erow = new double[system.getPhase(0).getNumberOfComponents()]; - multTerm = new double[system.getPhase(0).getNumberOfComponents()]; - multTerm2 = new double[system.getPhase(0).getNumberOfComponents()]; + system.getPhase(k).normalize(); } - - /** - *- * calcMultiPhaseBeta. - *
+ } + + /** + *+ * calcE. + *
+ */ + public void calcE() { + // E = new double[system.getPhase(0).getNumberOfComponents()]; + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + Erow[i] = 0.0; + for (int k = 0; k < system.getNumberOfPhases(); k++) { + Erow[i] += system.getPhase(k).getBeta() + / system.getPhase(k).getComponent(i).getFugacityCoefficient(); + } + } + } + + /** + *+ * calcQ. + *
+ * + * @return a double + */ + public double calcQ() { + /* + * double betaTotal = 0; for (int k = 0; k < system.getNumberOfPhases(); k++) { betaTotal += + * system.getPhase(k).getBeta(); } Q = betaTotal; */ - public void calcMultiPhaseBeta() {} - - /** - *- * setDoubleArrays. - *
+ this.calcE(); + /* + * for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { Q -= Math.log(E[i]) * + * system.getPhase(0).getComponent(i).getz(); } */ - public void setDoubleArrays() { - dQdbeta = new double[system.getNumberOfPhases()][1]; - Qmatrix = new double[system.getNumberOfPhases()][system.getNumberOfPhases()]; - } - /** - *- * setXY. - *
- */ - public void setXY() { - for (int k = 0; k < system.getNumberOfPhases(); k++) { - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - if (system.getPhase(0).getComponent(i).getz() > 1e-100) { - system.getPhase(k).getComponents()[i] - .setx(system.getPhase(0).getComponents()[i].getz() / Erow[i] - / system.getPhase(k).getComponent(i).getFugacityCoefficient()); - } - if (system.getPhase(0).getComponent(i).getIonicCharge() != 0 - && !system.getPhase(k).getPhaseTypeName().equals("aqueous")) { - system.getPhase(k).getComponents()[i].setx(1e-50); - } - if (system.getPhase(0).getComponent(i).getIonicCharge() != 0 - && system.getPhase(k).getPhaseTypeName().equals("aqueous")) { - system.getPhase(k).getComponents()[i] - .setx(system.getPhase(k).getComponents()[i].getNumberOfmoles() - / system.getPhase(k).getNumberOfMolesInPhase()); - } - } + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + multTerm[i] = system.getPhase(0).getComponent(i).getz() / Erow[i]; + multTerm2[i] = system.getPhase(0).getComponent(i).getz() / (Erow[i] * Erow[i]); + } - system.getPhase(k).normalize(); - } + for (int k = 0; k < system.getNumberOfPhases(); k++) { + dQdbeta[k][0] = 1.0; + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + dQdbeta[k][0] -= multTerm[i] / system.getPhase(k).getComponent(i).getFugacityCoefficient(); + } } - /** - *- * calcE. - *
- */ - public void calcE() { - // E = new double[system.getPhase(0).getNumberOfComponents()]; - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - Erow[i] = 0.0; - for (int k = 0; k < system.getNumberOfPhases(); k++) { - Erow[i] += system.getPhase(k).getBeta() - / system.getPhase(k).getComponent(i).getFugacityCoefficient(); - } + for (int i = 0; i < system.getNumberOfPhases(); i++) { + for (int j = 0; j < system.getNumberOfPhases(); j++) { + Qmatrix[i][j] = 0.0; + for (int k = 0; k < system.getPhase(0).getNumberOfComponents(); k++) { + Qmatrix[i][j] += + multTerm2[k] / (system.getPhase(j).getComponent(k).getFugacityCoefficient() + * system.getPhase(i).getComponent(k).getFugacityCoefficient()); + } + if (i == j) { + Qmatrix[i][j] += 1.0e-3; } + } } + return Q; + } + + /** + *+ * solveBeta. + *
+ * + * @return a double + */ + public double solveBeta() { + SimpleMatrix betaMatrix = new SimpleMatrix(1, system.getNumberOfPhases()); + SimpleMatrix ans = null; + double err = 1.0; + int iter = 1; + do { + iter++; + for (int k = 0; k < system.getNumberOfPhases(); k++) { + betaMatrix.set(0, k, system.getPhase(k).getBeta()); + } + + calcQ(); + SimpleMatrix dQM = new SimpleMatrix(dQdbeta); + SimpleMatrix dQdBM = new SimpleMatrix(Qmatrix); + try { + ans = dQdBM.solve(dQM).transpose(); + } catch (Exception e) { + } + betaMatrix = betaMatrix.minus(ans.scale(iter / (iter + 3.0))); + removePhase = false; + for (int k = 0; k < system.getNumberOfPhases(); k++) { + system.setBeta(k, betaMatrix.get(0, k)); + if (betaMatrix.get(0, k) < phaseFractionMinimumLimit) { + system.setBeta(k, phaseFractionMinimumLimit); + if (checkOneRemove) { + checkOneRemove = false; + removePhase = true; + } + checkOneRemove = true; + } else if (betaMatrix.get(0, k) > (1.0 - phaseFractionMinimumLimit)) { + system.setBeta(k, 1.0 - phaseFractionMinimumLimit); + } + } + system.normalizeBeta(); + system.init(1); + calcE(); + setXY(); + system.init(1); + err = ans.normF(); + } while ((err > 1e-12 && iter < 50) || iter < 3); + // logger.info("iterations " + iter); + return err; + } + + /** {@inheritDoc} */ + @Override + public void stabilityAnalysis() { + double[] logWi = new double[system.getPhase(0).getNumberOfComponents()]; + double[][] Wi = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) + .getNumberOfComponents()]; + + double[] deltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] sumw = new double[system.getPhase(0).getNumberOfComponents()]; + double err = 0; + double[] oldlogw = new double[system.getPhase(0).getNumberOfComponents()]; + double[] oldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] d = new double[system.getPhase(0).getNumberOfComponents()]; + double[][] x = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) + .getNumberOfComponents()]; + tm = new double[system.getPhase(0).getNumberOfComponents()]; + + double[] alpha = null; + // SystemInterface minimumGibbsEnergySystem; + ArrayList- * calcQ. - *
- * - * @return a double + lowestGibbsEnergyPhase = 0; + /* + * // logger.info("low gibbs phase " + lowestGibbsEnergyPhase); for (int k = 0; k < + * minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); k++) { for (int i = 0; i < + * minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); i++) { if (!(( + * clonedSystem.get(k)) == null)) { sumw[k] += ( + * clonedSystem.get(k)).getPhase(1).getComponents()[i].getx(); } } } + * + * for (int k = 0; k < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); k++) { for + * (int i = 0; i < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); i++) { if (!(( + * clonedSystem.get(k)) == null) && system.getPhase(0).getComponent(k).getx() > 1e-100) { ( + * clonedSystem.get(k)).getPhase(1).getComponents()[i].setx(( + * clonedSystem.get(k)).getPhase(1).getComponents()[i].getx() / sumw[0]); } logger.info("x: " + + * ( clonedSystem.get(k)).getPhase(0).getComponents()[i].getx()); } if + * (system.getPhase(0).getComponent(k).getx() > 1e-100) { d[k] = + * Math.log(system.getPhase(0).getComponents()[k].getx()) + + * system.getPhase(0).getComponents()[k].getLogFugacityCoefficient(); + * if(minimumGibbsEnergySystem.getPhases()[lowestGibbsEnergyPhase].getComponents + * ()[k].getIonicCharge()!=0) d[k]=0; } //logger.info("dk: " + d[k]); } */ - public double calcQ() { - /* - * double betaTotal = 0; for (int k = 0; k < system.getNumberOfPhases(); k++) { betaTotal += - * system.getPhase(k).getBeta(); } Q = betaTotal; - */ - this.calcE(); - /* - * for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { Q -= - * Math.log(E[i]) * system.getPhase(0).getComponent(i).getz(); } - */ + for (int k = 0; k < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); k++) { + if (system.getPhase(0).getComponent(k).getx() > 1e-100) { + d[k] = Math.log(system.getPhase(0).getComponents()[k].getx()) + + system.getPhase(0).getComponents()[k].getLogFugacityCoefficient(); + // if(minimumGibbsEnergySystem.getPhases()[lowestGibbsEnergyPhase].getComponents()[k].getIonicCharge()!=0) + // d[k]=0; + } + } - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - multTerm[i] = system.getPhase(0).getComponent(i).getz() / Erow[i]; - multTerm2[i] = system.getPhase(0).getComponent(i).getz() / (Erow[i] * Erow[i]); - } + for (int j = 0; j < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); j++) { + if (system.getPhase(0).getComponent(j).getz() > 1e-100) { + logWi[j] = 1.0; + } else { + logWi[j] = -10000.0; + } + } - for (int k = 0; k < system.getNumberOfPhases(); k++) { - dQdbeta[k][0] = 1.0; - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - dQdbeta[k][0] -= - multTerm[i] / system.getPhase(k).getComponent(i).getFugacityCoefficient(); - } + int hydrocarbonTestCompNumb = 0; + int lightTestCompNumb = 0; + double Mmax = 0; + double Mmin = 1e10; + for (int i = 0; i < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); i++) { + if (minimumGibbsEnergySystem.getPhase(0).getComponent(i).isHydrocarbon()) { + if ((minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass()) > Mmax) { + Mmax = minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass(); } - - for (int i = 0; i < system.getNumberOfPhases(); i++) { - for (int j = 0; j < system.getNumberOfPhases(); j++) { - Qmatrix[i][j] = 0.0; - for (int k = 0; k < system.getPhase(0).getNumberOfComponents(); k++) { - Qmatrix[i][j] += multTerm2[k] - / (system.getPhase(j).getComponent(k).getFugacityCoefficient() - * system.getPhase(i).getComponent(k).getFugacityCoefficient()); - } - if (i == j) { - Qmatrix[i][j] += 1.0e-3; - } - } + if ((minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass()) < Mmin) { + Mmin = minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass(); } - return Q; + } } - /** - *- * solveBeta. - *
- * - * @return a double - */ - public double solveBeta() { - SimpleMatrix betaMatrix = new SimpleMatrix(1, system.getNumberOfPhases()); - SimpleMatrix ans = null; - double err = 1.0; - int iter = 1; - do { - iter++; - for (int k = 0; k < system.getNumberOfPhases(); k++) { - betaMatrix.set(0, k, system.getPhase(k).getBeta()); - } - - calcQ(); - SimpleMatrix dQM = new SimpleMatrix(dQdbeta); - SimpleMatrix dQdBM = new SimpleMatrix(Qmatrix); - try { - ans = dQdBM.solve(dQM).transpose(); - } catch (Exception e) { - } - betaMatrix = betaMatrix.minus(ans.scale(iter / (iter + 3.0))); - removePhase = false; - for (int k = 0; k < system.getNumberOfPhases(); k++) { - system.setBeta(k, betaMatrix.get(0, k)); - if (betaMatrix.get(0, k) < phaseFractionMinimumLimit) { - system.setBeta(k, phaseFractionMinimumLimit); - if (checkOneRemove) { - checkOneRemove = false; - removePhase = true; - } - checkOneRemove = true; - } else if (betaMatrix.get(0, k) > (1.0 - phaseFractionMinimumLimit)) { - system.setBeta(k, 1.0 - phaseFractionMinimumLimit); - } - } - system.normalizeBeta(); - system.init(1); - calcE(); - setXY(); - system.init(1); - err = ans.normF(); - } while ((err > 1e-12 && iter < 50) || iter < 3); - // logger.info("iterations " + iter); - return err; + for (int i = 0; i < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); i++) { + if (minimumGibbsEnergySystem.getPhase(0).getComponent(i).isHydrocarbon() + && minimumGibbsEnergySystem.getPhase(0).getComponent(i).getz() > 1e-50) { + if (Math.abs( + (minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass()) - Mmax) < 1e-5) { + hydrocarbonTestCompNumb = i; + // logger.info("CHECKING heavy component " + hydrocarbonTestCompNumb); + } + } + + if (minimumGibbsEnergySystem.getPhase(0).getComponent(i).isHydrocarbon() + && minimumGibbsEnergySystem.getPhase(0).getComponent(i).getz() > 1e-50) { + if (Math.abs( + (minimumGibbsEnergySystem.getPhase(0).getComponent(i).getMolarMass()) - Mmin) < 1e-5) { + lightTestCompNumb = i; + // logger.info("CHECKING light component " + lightTestCompNumb); + } + } } - /** {@inheritDoc} */ - @Override - public void stabilityAnalysis() { - double[] logWi = new double[system.getPhase(0).getNumberOfComponents()]; - double[][] Wi = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) - .getNumberOfComponents()]; - - double[] deltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] sumw = new double[system.getPhase(0).getNumberOfComponents()]; - double err = 0; - double[] oldlogw = new double[system.getPhase(0).getNumberOfComponents()]; - double[] oldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] d = new double[system.getPhase(0).getNumberOfComponents()]; - double[][] x = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) - .getNumberOfComponents()]; - tm = new double[system.getPhase(0).getNumberOfComponents()]; - - double[] alpha = null; - // SystemInterface minimumGibbsEnergySystem; - ArrayList- * stabilityAnalysis2. - *
- */ - public void stabilityAnalysis2() { - double[] logWi = new double[system.getPhase(0).getNumberOfComponents()]; - double[][] Wi = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) - .getNumberOfComponents()]; - - double[] deltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] sumw = new double[system.getPhase(0).getNumberOfComponents()]; - double err = 0; - double[] oldlogw = new double[system.getPhase(0).getNumberOfComponents()]; - double[] oldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] d = new double[system.getPhase(0).getNumberOfComponents()]; - double[][] x = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) - .getNumberOfComponents()]; - tm = new double[system.getPhase(0).getNumberOfComponents()]; - - double[] alpha = null; - // SystemInterface minimumGibbsEnergySystem; - ArrayList+ * stabilityAnalysis2. + *
+ */ + public void stabilityAnalysis2() { + double[] logWi = new double[system.getPhase(0).getNumberOfComponents()]; + double[][] Wi = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) + .getNumberOfComponents()]; + + double[] deltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] sumw = new double[system.getPhase(0).getNumberOfComponents()]; + double err = 0; + double[] oldlogw = new double[system.getPhase(0).getNumberOfComponents()]; + double[] oldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] d = new double[system.getPhase(0).getNumberOfComponents()]; + double[][] x = new double[system.getPhase(0).getNumberOfComponents()][system.getPhase(0) + .getNumberOfComponents()]; + tm = new double[system.getPhase(0).getNumberOfComponents()]; + + double[] alpha = null; + // SystemInterface minimumGibbsEnergySystem; + ArrayList- * Constructor for TPmultiflash_1. - *
- */ - public TPmultiflash_1() {} - - /** - *- * Constructor for TPmultiflash_1. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public TPmultiflash_1(SystemInterface system) { - super(system); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(TPmultiflash_1.class); + + // SystemInterface clonedSystem; + boolean multiPhaseTest = false; + double[] dQdbeta; + double Qmatrix[][]; + double[] E; + double Q = 0; + + /** + *+ * Constructor for TPmultiflash_1. + *
+ */ + public TPmultiflash_1() {} + + /** + *+ * Constructor for TPmultiflash_1. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public TPmultiflash_1(SystemInterface system) { + super(system); + } + + /** + *+ * Constructor for TPmultiflash_1. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param check a boolean + */ + public TPmultiflash_1(SystemInterface system, boolean check) { + super(system, check); + } + + /** + *+ * calcMultiPhaseBeta. + *
+ */ + public void calcMultiPhaseBeta() {} + + /** + *+ * setXY. + *
+ */ + public void setXY() { + for (int k = 0; k < system.getNumberOfPhases(); k++) { + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + system.getPhases()[k].getComponents()[i] + .setx(system.getPhases()[k].getComponents()[i].getz() / E[i] + / system.getPhases()[k].getComponents()[i].getFugacityCoefficient()); + } + } + } + + /** + *+ * calcE. + *
+ */ + public void calcE() { + E = new double[system.getPhases()[0].getNumberOfComponents()]; + + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + for (int k = 0; k < system.getNumberOfPhases(); k++) { + E[i] += system.getPhases()[k].getBeta() + / system.getPhases()[k].getComponents()[i].getFugacityCoefficient(); + } + } + } + + /** + *+ * calcQ. + *
+ * + * @return a double + */ + public double calcQ() { + Q = 0; + double betaTotal = 0; + dQdbeta = new double[system.getNumberOfPhases()]; + Qmatrix = new double[system.getNumberOfPhases()][system.getNumberOfPhases()]; + + for (int k = 0; k < system.getNumberOfPhases(); k++) { + betaTotal += system.getPhases()[k].getBeta(); } - /** - *- * Constructor for TPmultiflash_1. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param check a boolean - */ - public TPmultiflash_1(SystemInterface system, boolean check) { - super(system, check); + Q = betaTotal; + this.calcE(); + + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + Q -= Math.log(E[i]) * system.getPhases()[0].getComponents()[i].getz(); } - /** - *- * calcMultiPhaseBeta. - *
- */ - public void calcMultiPhaseBeta() {} - - /** - *- * setXY. - *
- */ - public void setXY() { - for (int k = 0; k < system.getNumberOfPhases(); k++) { - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - system.getPhases()[k].getComponents()[i] - .setx(system.getPhases()[k].getComponents()[i].getz() / E[i] - / system.getPhases()[k].getComponents()[i] - .getFugacityCoefficient()); - } - } + for (int k = 0; k < system.getNumberOfPhases(); k++) { + dQdbeta[k] = 1.0; + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + dQdbeta[k] -= system.getPhases()[0].getComponents()[i].getz() * 1.0 / E[i] + / system.getPhases()[k].getComponents()[i].getFugacityCoefficient(); + } } - /** - *- * calcE. - *
- */ - public void calcE() { - E = new double[system.getPhases()[0].getNumberOfComponents()]; - - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - for (int k = 0; k < system.getNumberOfPhases(); k++) { - E[i] += system.getPhases()[k].getBeta() - / system.getPhases()[k].getComponents()[i].getFugacityCoefficient(); - } + for (int i = 0; i < system.getNumberOfPhases(); i++) { + for (int j = 0; j < system.getNumberOfPhases(); j++) { + Qmatrix[i][j] = 0; + for (int k = 0; k < system.getPhases()[0].getNumberOfComponents(); k++) { + Qmatrix[i][j] += system.getPhases()[0].getComponents()[k].getz() + / (E[k] * E[k] * system.getPhases()[j].getComponents()[k].getFugacityCoefficient() + * system.getPhases()[i].getComponents()[k].getFugacityCoefficient()); } + } } - - /** - *- * calcQ. - *
- * - * @return a double - */ - public double calcQ() { - Q = 0; - double betaTotal = 0; - dQdbeta = new double[system.getNumberOfPhases()]; - Qmatrix = new double[system.getNumberOfPhases()][system.getNumberOfPhases()]; - - for (int k = 0; k < system.getNumberOfPhases(); k++) { - betaTotal += system.getPhases()[k].getBeta(); + return Q; + } + + /** + *+ * solveBeta. + *
+ */ + public void solveBeta() { + double[] oldBeta = new double[system.getNumberOfPhases()]; + // double newBeta[] = new double[system.getNumberOfPhases()]; + + Matrix ans; + int iter = 1; + do { + iter++; + for (int k = 0; k < system.getNumberOfPhases(); k++) { + oldBeta[k] = system.getPhases()[k].getBeta(); + } + + calcQ(); + + Matrix betaMatrix = new Matrix(oldBeta, 1).transpose(); + Matrix dQM = new Matrix(dQdbeta, 1); + Matrix dQdBM = new Matrix(Qmatrix); + + ans = dQdBM.solve(dQM.transpose()); + betaMatrix.minusEquals(ans.times(iter / (iter + 20.0))); + // ans.print(10,2); + betaMatrix.print(10, 2); + + for (int k = 0; k < system.getNumberOfPhases(); k++) { + system.setBeta(k, betaMatrix.get(k, 0)); + if (betaMatrix.get(k, 0) < 0) { + system.setBeta(k, 1.0e-9); } - - Q = betaTotal; - this.calcE(); - - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - Q -= Math.log(E[i]) * system.getPhases()[0].getComponents()[i].getz(); + if (betaMatrix.get(k, 0) > 1) { + system.setBeta(k, 1.0 - 1e-9); } + } + + calcE(); + setXY(); + system.init(1); + } while (ans.norm2() > 1e-6); + } + + /** {@inheritDoc} */ + @Override + public void stabilityAnalysis() { + double[] logWi = new double[system.getPhases()[1].getNumberOfComponents()]; + double[][] Wi = new double[system.getPhases()[1].getNumberOfComponents()][system.getPhases()[0] + .getNumberOfComponents()]; + double[] sumw = new double[system.getPhases()[1].getNumberOfComponents()]; + double err = 0; + double[] oldlogw = new double[system.getPhases()[1].getNumberOfComponents()]; + double[] d = new double[system.getPhases()[1].getNumberOfComponents()]; + double[][] x = new double[system.getPhases()[1].getNumberOfComponents()][system.getPhases()[0] + .getNumberOfComponents()]; + + SystemInterface minimumGibbsEnergySystem; + ArrayList- * solveBeta. - *
- */ - public void solveBeta() { - double oldBeta[] = new double[system.getNumberOfPhases()]; - // double newBeta[] = new double[system.getNumberOfPhases()]; - - Matrix ans; - int iter = 1; - do { - iter++; - for (int k = 0; k < system.getNumberOfPhases(); k++) { - oldBeta[k] = system.getPhases()[k].getBeta(); - } - - calcQ(); - - Matrix betaMatrix = new Matrix(oldBeta, 1).transpose(); - Matrix dQM = new Matrix(dQdbeta, 1); - Matrix dQdBM = new Matrix(Qmatrix); - - ans = dQdBM.solve(dQM.transpose()); - betaMatrix.minusEquals(ans.times(iter / (iter + 20.0))); - // ans.print(10,2); - betaMatrix.print(10, 2); - - for (int k = 0; k < system.getNumberOfPhases(); k++) { - system.setBeta(k, betaMatrix.get(k, 0)); - if (betaMatrix.get(k, 0) < 0) { - system.setBeta(k, 1.0e-9); - } - if (betaMatrix.get(k, 0) > 1) { - system.setBeta(k, 1.0 - 1e-9); - } - } - - calcE(); - setXY(); - system.init(1); - } while (ans.norm2() > 1e-6); + for (int k = 0; k < minimumGibbsEnergySystem.getPhases()[1].getNumberOfComponents(); k++) { + for (int i = 0; i < minimumGibbsEnergySystem.getPhases()[1].getNumberOfComponents(); i++) { + (clonedSystem.get(k)).getPhases()[1].getComponents()[i] + .setx((clonedSystem.get(k)).getPhases()[1].getComponents()[i].getx() / sumw[0]); + // logger.info("x: " + ( + // clonedSystem.get(k)).getPhases()[0].getComponents()[i].getx()); + } + d[k] = Math.log( + minimumGibbsEnergySystem.getPhases()[lowestGibbsEnergyPhase].getComponents()[k].getx()) + + Math.log(minimumGibbsEnergySystem.getPhases()[lowestGibbsEnergyPhase].getComponents()[k] + .getFugacityCoefficient()); + // logger.info("dk: " + d[k]); } - /** {@inheritDoc} */ - @Override - public void stabilityAnalysis() { - double[] logWi = new double[system.getPhases()[1].getNumberOfComponents()]; - double[][] Wi = new double[system.getPhases()[1] - .getNumberOfComponents()][system.getPhases()[0].getNumberOfComponents()]; - double[] sumw = new double[system.getPhases()[1].getNumberOfComponents()]; - // double sumz = 0; - double err = 0; - double[] oldlogw = new double[system.getPhases()[1].getNumberOfComponents()]; - double[] d = new double[system.getPhases()[1].getNumberOfComponents()]; - double[][] x = new double[system.getPhases()[1] - .getNumberOfComponents()][system.getPhases()[0].getNumberOfComponents()]; - - SystemInterface minimumGibbsEnergySystem; - ArrayList- * Constructor for TSFlash. - *
- */ - public TSFlash() {} - - /** - *- * Constructor for TSFlash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param Sspec a double - */ - public TSFlash(SystemInterface system, double Sspec) { - this.system = system; - this.tpFlash = new TPflash(system); - this.Sspec = Sspec; + private static final long serialVersionUID = 1000; + + double Sspec = 0; + Flash tpFlash; + + /** + *+ * Constructor for TSFlash. + *
+ */ + public TSFlash() {} + + /** + *+ * Constructor for TSFlash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param Sspec a double + */ + public TSFlash(SystemInterface system, double Sspec) { + this.system = system; + this.tpFlash = new TPflash(system); + this.Sspec = Sspec; + } + + /** {@inheritDoc} */ + @Override + public double calcdQdTT() { + if (system.getNumberOfPhases() == 1) { + return -system.getPhase(0).getCp() / system.getTemperature(); } - /** {@inheritDoc} */ - @Override - public double calcdQdTT() { - // double cP1 = 0.0, cP2 = 0.0; - - if (system.getNumberOfPhases() == 1) { - return -system.getPhase(0).getCp() / system.getTemperature(); - } - - double dQdTT = 0.0; - for (int i = 0; i < system.getNumberOfPhases(); i++) { - dQdTT -= system.getPhase(i).getCp() / system.getPhase(i).getTemperature(); - } - return dQdTT; + double dQdTT = 0.0; + for (int i = 0; i < system.getNumberOfPhases(); i++) { + dQdTT -= system.getPhase(i).getCp() / system.getPhase(i).getTemperature(); } - - /** {@inheritDoc} */ - @Override - public double calcdQdT() { - double dQ = -system.getEntropy() + Sspec; - return dQ; - } - - /** {@inheritDoc} */ - @Override - public double solveQ() { - // this method is not yet implemented - double oldTemp = system.getPressure(), nyTemp = system.getPressure(); - int iterations = 1; - double error = 1.0, erorOld = 10.0e10; - // double factor = 0.8; - - // boolean correctFactor = true; - // double newCorr = 1.0; - do { - iterations++; - oldTemp = system.getPressure(); - system.init(2); - - nyTemp = oldTemp - calcdQdT() / 10.0; - - system.setPressure(nyTemp); - tpFlash.run(); - erorOld = error; - error = Math.abs(calcdQdT()); - } while (((error + erorOld) > 1e-8 || iterations < 3) && iterations < 200); - return nyTemp; - } - - /** - *- * onPhaseSolve. - *
- */ - public void onPhaseSolve() {} - - /** {@inheritDoc} */ - @Override - public void run() { - tpFlash.run(); - solveQ(); - } - - /** - *- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - SystemInterface testSystem = new SystemSrkEos(373.15, 45.551793); - - ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); - testSystem.addComponent("methane", 9.4935); - testSystem.addComponent("ethane", 5.06499); - testSystem.addComponent("n-heptane", 0.2); - testSystem.init(0); - try { - testOps.TPflash(); - testSystem.display(); - - double Sspec = testSystem.getEntropy("kJ/kgK"); - System.out.println("S spec " + Sspec); - testSystem.setTemperature(293.15); - testOps.TSflash(Sspec, "kJ/kgK"); - testSystem.display(); - } catch (Exception e) { - logger.error(e.toString()); - } + return dQdTT; + } + + /** {@inheritDoc} */ + @Override + public double calcdQdT() { + double dQ = -system.getEntropy() + Sspec; + return dQ; + } + + /** {@inheritDoc} */ + @Override + public double solveQ() { + // this method is not yet implemented + double oldTemp = system.getPressure(), nyTemp = system.getPressure(); + int iterations = 1; + double error = 1.0, erorOld = 10.0e10; + do { + iterations++; + oldTemp = system.getPressure(); + system.init(2); + + nyTemp = oldTemp - calcdQdT() / 10.0; + + system.setPressure(nyTemp); + tpFlash.run(); + erorOld = error; + error = Math.abs(calcdQdT()); + } while (((error + erorOld) > 1e-8 || iterations < 3) && iterations < 200); + return nyTemp; + } + + /** + *+ * onPhaseSolve. + *
+ */ + public void onPhaseSolve() {} + + /** {@inheritDoc} */ + @Override + public void run() { + tpFlash.run(); + solveQ(); + } + + /** + *+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + SystemInterface testSystem = new SystemSrkEos(373.15, 45.551793); + + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testSystem.addComponent("methane", 9.4935); + testSystem.addComponent("ethane", 5.06499); + testSystem.addComponent("n-heptane", 0.2); + testSystem.init(0); + try { + testOps.TPflash(); + testSystem.display(); + + double Sspec = testSystem.getEntropy("kJ/kgK"); + System.out.println("S spec " + Sspec); + testSystem.setTemperature(293.15); + testOps.TSflash(Sspec, "kJ/kgK"); + testSystem.display(); + } catch (Exception e) { + logger.error(e.toString()); } + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/bubblePointTemperatureNoDer.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/bubblePointTemperatureNoDer.java index 10f4ab06aa..444146ce5c 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/bubblePointTemperatureNoDer.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/bubblePointTemperatureNoDer.java @@ -13,158 +13,153 @@ * @version $Id: $Id */ public class bubblePointTemperatureNoDer extends constantDutyTemperatureFlash { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(bubblePointTemperatureNoDer.class); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(bubblePointTemperatureNoDer.class); - /** - *- * Constructor for bubblePointTemperatureNoDer. - *
- */ - public bubblePointTemperatureNoDer() {} + /** + *+ * Constructor for bubblePointTemperatureNoDer. + *
+ */ + public bubblePointTemperatureNoDer() {} - /** - *- * Constructor for bubblePointTemperatureNoDer. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public bubblePointTemperatureNoDer(SystemInterface system) { - super(system); - } - - /** {@inheritDoc} */ - @Override - public void run() { - if (system.getPhase(0).getNumberOfComponents() == 1 - && system.getPressure() > system.getPhase(0).getComponent(0).getPC()) { - setSuperCritical(true); - } + /** + *+ * Constructor for bubblePointTemperatureNoDer. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public bubblePointTemperatureNoDer(SystemInterface system) { + super(system); + } - int iterations = 0, maxNumberOfIterations = 1000; - double yold = 0, ytotal = 1; - // double deriv = 0, funk = 0; - // logger.info("starting"); + /** {@inheritDoc} */ + @Override + public void run() { + if (system.getPhase(0).getNumberOfComponents() == 1 + && system.getPressure() > system.getPhase(0).getComponent(0).getPC()) { + setSuperCritical(true); + } - system.init(0); - system.setNumberOfPhases(2); - system.setBeta(1, 1.0 - 1e-10); - system.setBeta(0, 1e-10); - // need to fix this close to critical point - if (system.getPhase(0).getNumberOfComponents() == 1) { - double oldTemp = system.getTemperature(); - if (system.getPressure() > system.getPhase(0).getComponent(0).getPC()) { - setSuperCritical(true); - return; - } - if (system.getPressure() < system.getPhase(0).getComponent(0).getPC()) { - system.setTemperature(system.getPhase(0).getComponent(0) - .getAntoineVaporTemperature(system.getPressure())); - } - if (system.getTemperature() > system.getPhase(0).getComponent(0).getTC() - || system.getTemperature() < system.getPhase(0).getComponent(0) - .getTriplePointTemperature()) { - system.setTemperature(oldTemp); - } - } + int iterations = 0; + int maxNumberOfIterations = 1000; + double yold = 0; + double ytotal = 1; + system.init(0); + system.setNumberOfPhases(2); + system.setBeta(1, 1.0 - 1e-10); + system.setBeta(0, 1e-10); + // need to fix this close to critical point + if (system.getPhase(0).getNumberOfComponents() == 1) { + double oldTemp = system.getTemperature(); + if (system.getPressure() > system.getPhase(0).getComponent(0).getPC()) { + setSuperCritical(true); + return; + } + if (system.getPressure() < system.getPhase(0).getComponent(0).getPC()) { + system.setTemperature( + system.getPhase(0).getComponent(0).getAntoineVaporTemperature(system.getPressure())); + } + if (system.getTemperature() > system.getPhase(0).getComponent(0).getTC() || system + .getTemperature() < system.getPhase(0).getComponent(0).getTriplePointTemperature()) { + system.setTemperature(oldTemp); + } + } - // double oldPres = 0; - if (system.isChemicalSystem()) { - system.getChemicalReactionOperations().solveChemEq(0); - system.getChemicalReactionOperations().solveChemEq(1); - } + if (system.isChemicalSystem()) { + system.getChemicalReactionOperations().solveChemEq(0); + system.getChemicalReactionOperations().solveChemEq(1); + } - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - system.getPhases()[1].getComponents()[i] - .setx(system.getPhases()[0].getComponents()[i].getz()); - if (system.getPhases()[0].getComponents()[i].getIonicCharge() != 0) { - system.getPhases()[0].getComponents()[i].setx(1e-40); - } else { - system.getPhases()[0].getComponents()[i] - .setx(system.getPhases()[0].getComponents()[i].getK() - * system.getPhases()[1].getComponents()[i].getz()); - } - } - ytotal = 0.0; - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - ytotal += system.getPhases()[0].getComponents()[i].getx(); - } - double oldTemp = 10.0; + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + system.getPhases()[1].getComponents()[i] + .setx(system.getPhases()[0].getComponents()[i].getz()); + if (system.getPhases()[0].getComponents()[i].getIonicCharge() != 0) { + system.getPhases()[0].getComponents()[i].setx(1e-40); + } else { + system.getPhases()[0].getComponents()[i] + .setx(system.getPhases()[0].getComponents()[i].getK() + * system.getPhases()[1].getComponents()[i].getz()); + } + } + ytotal = 0.0; + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + ytotal += system.getPhases()[0].getComponents()[i].getx(); + } + double oldTemp = 10.0; - double ktot = 0.0; + double ktot = 0.0; + do { + iterations++; + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + system.getPhases()[0].getComponents()[i] + .setx(system.getPhases()[0].getComponents()[i].getx() / ytotal); + } + if (system.isChemicalSystem() && (iterations % 2) == 0) { + system.getChemicalReactionOperations().solveChemEq(1); + } + system.init(1); + oldTemp = system.getTemperature(); + ktot = 0.0; + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { do { - iterations++; - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - system.getPhases()[0].getComponents()[i] - .setx(system.getPhases()[0].getComponents()[i].getx() / ytotal); - } - if (system.isChemicalSystem() && (iterations % 2) == 0) { - system.getChemicalReactionOperations().solveChemEq(1); - } - system.init(1); - oldTemp = system.getTemperature(); - ktot = 0.0; - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - do { - yold = system.getPhases()[0].getComponents()[i].getx(); - if (system.getPhase(0).getComponent(i).getIonicCharge() != 0) { - system.getPhases()[0].getComponents()[i].setK(1e-40); - } else { - system.getPhases()[0].getComponents()[i].setK(Math.exp(Math.log( - system.getPhases()[1].getComponents()[i].getFugacityCoefficient()) - - Math.log(system.getPhases()[0].getComponents()[i] - .getFugacityCoefficient()))); - } - system.getPhases()[1].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getK()); - system.getPhases()[0].getComponents()[i] - .setx(system.getPhases()[0].getComponents()[i].getK() - * system.getPhases()[1].getComponents()[i].getz()); - // logger.info("y err " + - // Math.abs(system.getPhases()[0].getComponents()[i].getx()-yold)); - } while (Math.abs(system.getPhases()[0].getComponents()[i].getx() - yold) > 1e-4); + yold = system.getPhases()[0].getComponents()[i].getx(); + if (system.getPhase(0).getComponent(i).getIonicCharge() != 0) { + system.getPhases()[0].getComponents()[i].setK(1e-40); + } else { + system.getPhases()[0].getComponents()[i].setK( + Math.exp(Math.log(system.getPhases()[1].getComponents()[i].getFugacityCoefficient()) + - Math.log(system.getPhases()[0].getComponents()[i].getFugacityCoefficient()))); + } + system.getPhases()[1].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getK()); + system.getPhases()[0].getComponents()[i] + .setx(system.getPhases()[0].getComponents()[i].getK() + * system.getPhases()[1].getComponents()[i].getz()); + // logger.info("y err " + + // Math.abs(system.getPhases()[0].getComponents()[i].getx()-yold)); + } while (Math.abs(system.getPhases()[0].getComponents()[i].getx() - yold) > 1e-4); - ktot += Math.abs(system.getPhases()[1].getComponents()[i].getK() - 1.0); - } - ytotal = 0.0; - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - ytotal += system.getPhases()[0].getComponents()[i].getx(); - } - if (ytotal > 1.2) { - ytotal = 1.2; - } - if (ytotal < 0.8) { - ytotal = 0.8; - } - // logger.info("y tot " + ytotal); + ktot += Math.abs(system.getPhases()[1].getComponents()[i].getK() - 1.0); + } + ytotal = 0.0; + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + ytotal += system.getPhases()[0].getComponents()[i].getx(); + } + if (ytotal > 1.2) { + ytotal = 1.2; + } + if (ytotal < 0.8) { + ytotal = 0.8; + } + // logger.info("y tot " + ytotal); - // system.setTemperature(system.getTemperature() + - // 0.05*(1.0/ytotal*system.getTemperature()-system.getTemperature())); - system.setTemperature( - system.getTemperature() + 0.1 * system.getTemperature() * (1.0 - ytotal)); - // for (int i=0;i- * Constructor for constantDutyPressureFlash. - *
- */ - public constantDutyPressureFlash() {} - - /** - *- * Constructor for constantDutyPressureFlash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public constantDutyPressureFlash(SystemInterface system) { - super(system); + private static final long serialVersionUID = 1000; + + /** + *+ * Constructor for constantDutyPressureFlash. + *
+ */ + public constantDutyPressureFlash() {} + + /** + *+ * Constructor for constantDutyPressureFlash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public constantDutyPressureFlash(SystemInterface system) { + super(system); + } + + /** {@inheritDoc} */ + @Override + public void run() { + // system.calc_x_y(); + // system.init(2); + + if (system.isChemicalSystem()) { + system.getChemicalReactionOperations().solveChemEq(0); } - /** {@inheritDoc} */ - @Override - public void run() { - // system.calc_x_y(); - // system.init(2); - - if (system.isChemicalSystem()) { - system.getChemicalReactionOperations().solveChemEq(0); - } - - int iterations = 0; - // int maxNumberOfIterations = 10000; - // double yold = 0, ytotal = 1; - double deriv = 0, funk = 0, dkidp = 0, dyidp = 0, dxidp = 0, Pold = 0; - - do { - // system.setBeta(beta+0.65); - system.init(2); - iterations++; - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - system.getPhases()[0].getComponents()[i] - .setK(system.getPhases()[1].getComponents()[i].getFugacityCoefficient() - / system.getPhases()[0].getComponents()[i] - .getFugacityCoefficient()); - system.getPhases()[1].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getK()); - } - - system.calc_x_y_nonorm(); - - funk = 0.0; - deriv = 0.0; - - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - dkidp = (system.getPhases()[1].getComponents()[i].getdfugdp() - - system.getPhases()[0].getComponents()[i].getdfugdp()) - * system.getPhases()[1].getComponents()[i].getK(); - dxidp = -system.getPhases()[1].getComponents()[i].getz() * system.getBeta() * dkidp - / Math.pow( - 1.0 - system.getBeta() - + system.getBeta() - * system.getPhases()[1].getComponents()[i].getK(), - 2.0); - dyidp = dkidp * system.getPhases()[1].getComponents()[i].getx() - + system.getPhases()[1].getComponents()[i].getK() * dxidp; - funk += system.getPhases()[0].getComponents()[i].getx() - - system.getPhases()[1].getComponents()[i].getx(); - deriv += dyidp - dxidp; - } - - // System.out.println("Pressure: " + system.getPressure() + " funk " + funk); - - Pold = system.getPressure(); - double pres = Math.abs(Pold - 0.5 * funk / deriv); - system.setPressure(pres); - } while ((Math.abs((system.getPressure() - Pold) / system.getPressure()) > 1e-10 - && iterations < 300) || iterations < 3); - } - - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} - - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } - - /** {@inheritDoc} */ - @Override - public SystemInterface getThermoSystem() { - return system; - } + int iterations = 0; + double deriv = 0; + + double funk = 0; + double dkidp = 0; + double dyidp = 0; + double dxidp = 0; + double Pold = 0; + do { + // system.setBeta(beta+0.65); + system.init(2); + iterations++; + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + system.getPhases()[0].getComponents()[i] + .setK(system.getPhases()[1].getComponents()[i].getFugacityCoefficient() + / system.getPhases()[0].getComponents()[i].getFugacityCoefficient()); + system.getPhases()[1].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getK()); + } + + system.calc_x_y_nonorm(); + + funk = 0.0; + deriv = 0.0; + + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + dkidp = (system.getPhases()[1].getComponents()[i].getdfugdp() + - system.getPhases()[0].getComponents()[i].getdfugdp()) + * system.getPhases()[1].getComponents()[i].getK(); + dxidp = -system.getPhases()[1].getComponents()[i].getz() * system.getBeta() * dkidp + / Math.pow(1.0 - system.getBeta() + + system.getBeta() * system.getPhases()[1].getComponents()[i].getK(), 2.0); + dyidp = dkidp * system.getPhases()[1].getComponents()[i].getx() + + system.getPhases()[1].getComponents()[i].getK() * dxidp; + funk += system.getPhases()[0].getComponents()[i].getx() + - system.getPhases()[1].getComponents()[i].getx(); + deriv += dyidp - dxidp; + } + + // System.out.println("Pressure: " + system.getPressure() + " funk " + funk); + + Pold = system.getPressure(); + double pres = Math.abs(Pold - 0.5 * funk / deriv); + system.setPressure(pres); + } while ((Math.abs((system.getPressure() - Pold) / system.getPressure()) > 1e-10 + && iterations < 300) || iterations < 3); + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } + + /** {@inheritDoc} */ + @Override + public SystemInterface getThermoSystem() { + return system; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/constantDutyTemperatureFlash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/constantDutyTemperatureFlash.java index c62025c4ad..9152a21f86 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/constantDutyTemperatureFlash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/constantDutyTemperatureFlash.java @@ -11,97 +11,95 @@ * @version $Id: $Id */ public class constantDutyTemperatureFlash extends constantDutyFlash { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - /** - *- * Constructor for constantDutyTemperatureFlash. - *
- */ - public constantDutyTemperatureFlash() {} + /** + *+ * Constructor for constantDutyTemperatureFlash. + *
+ */ + public constantDutyTemperatureFlash() {} - /** - *- * Constructor for constantDutyTemperatureFlash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public constantDutyTemperatureFlash(SystemInterface system) { - super(system); - } + /** + *+ * Constructor for constantDutyTemperatureFlash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public constantDutyTemperatureFlash(SystemInterface system) { + super(system); + } - /** {@inheritDoc} */ - @Override - public void run() { - system.init(0); - system.init(2); + /** {@inheritDoc} */ + @Override + public void run() { + system.init(0); + system.init(2); - int iterations = 0; - // int maxNumberOfIterations = 10000; - // double yold = 0, ytotal = 1; - double deriv = 0, funk = 0, dkidt = 0, dyidt = 0, dxidt = 0, Told = 0; + int iterations = 0; + double deriv = 0; - do { - iterations++; - // system.setBeta(beta+0.65); - system.init(2); + double funk = 0; + double dkidt = 0; + double dyidt = 0; + double dxidt = 0; + double Told = 0; + do { + iterations++; + // system.setBeta(beta+0.65); + system.init(2); - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - system.getPhases()[0].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() - / system.getPhases()[1].getComponents()[i] - .getFugacityCoefficient()); - system.getPhases()[1].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() - / system.getPhases()[1].getComponents()[i] - .getFugacityCoefficient()); - } + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + system.getPhases()[0].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() + / system.getPhases()[1].getComponents()[i].getFugacityCoefficient()); + system.getPhases()[1].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() + / system.getPhases()[1].getComponents()[i].getFugacityCoefficient()); + } - system.calc_x_y_nonorm(); + system.calc_x_y_nonorm(); - funk = 0e0; - deriv = 0e0; + funk = 0e0; + deriv = 0e0; - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - dkidt = (system.getPhases()[0].getComponents()[i].getdfugdt() - - system.getPhases()[1].getComponents()[i].getdfugdt()) - * system.getPhases()[0].getComponents()[i].getK(); - // dxidt=-system.getPhases()[0].getComponents()[i].getx() * - // system.getPhases()[0].getComponents()[i].getx()*1.0/system.getPhases()[0].getComponents()[i].getz()*system.getBeta()*dkidt; - dxidt = -system.getPhases()[0].getComponents()[i].getz() * system.getBeta() * dkidt - / Math.pow( - 1.0 - system.getBeta() - + system.getBeta() - * system.getPhases()[0].getComponents()[i].getK(), - 2); - dyidt = dkidt * system.getPhases()[0].getComponents()[i].getx() - + system.getPhases()[0].getComponents()[i].getK() * dxidt; - funk = funk + system.getPhases()[1].getComponents()[i].getx() - - system.getPhases()[0].getComponents()[i].getx(); - deriv = deriv + dyidt - dxidt; - } + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + dkidt = (system.getPhases()[0].getComponents()[i].getdfugdt() + - system.getPhases()[1].getComponents()[i].getdfugdt()) + * system.getPhases()[0].getComponents()[i].getK(); + // dxidt=-system.getPhases()[0].getComponents()[i].getx() * + // system.getPhases()[0].getComponents()[i].getx()*1.0/system.getPhases()[0].getComponents()[i].getz()*system.getBeta()*dkidt; + dxidt = -system.getPhases()[0].getComponents()[i].getz() * system.getBeta() * dkidt + / Math.pow(1.0 - system.getBeta() + + system.getBeta() * system.getPhases()[0].getComponents()[i].getK(), 2); + dyidt = dkidt * system.getPhases()[0].getComponents()[i].getx() + + system.getPhases()[0].getComponents()[i].getK() * dxidt; + funk = funk + system.getPhases()[1].getComponents()[i].getx() + - system.getPhases()[0].getComponents()[i].getx(); + deriv = deriv + dyidt - dxidt; + } - Told = system.getTemperature(); - system.setTemperature((Told - funk / deriv * 0.7)); - // System.out.println("Temp: " + system.getTemperature() + " funk " + funk); - } while ((Math.abs((system.getTemperature() - Told) / system.getTemperature()) > 1e-7 - && iterations < 300) || iterations < 3); - } + Told = system.getTemperature(); + system.setTemperature((Told - funk / deriv * 0.7)); + // System.out.println("Temp: " + system.getTemperature() + " funk " + funk); + } while ((Math.abs((system.getTemperature() - Told) / system.getTemperature()) > 1e-7 + && iterations < 300) || iterations < 3); + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } - /** {@inheritDoc} */ - @Override - public SystemInterface getThermoSystem() { - return system; - } + /** {@inheritDoc} */ + @Override + public SystemInterface getThermoSystem() { + return system; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondebarFlash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondebarFlash.java index f2becd57eb..74464c0564 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondebarFlash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondebarFlash.java @@ -15,288 +15,289 @@ * @version $Id: $Id */ public class cricondebarFlash extends constantDutyPressureFlash { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(constantDutyFlash.class); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(constantDutyFlash.class); - Matrix Jac, fvec; + Matrix Jac; + Matrix fvec; - /** - *- * Constructor for cricondebarFlash. - *
- */ - public cricondebarFlash() {} + /** + *+ * Constructor for cricondebarFlash. + *
+ */ + public cricondebarFlash() {} - /** - *- * Constructor for cricondebarFlash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public cricondebarFlash(SystemInterface system) { - super(system); - Jac = new Matrix(system.getPhase(0).getNumberOfComponents() + 1, - system.getPhase(0).getNumberOfComponents() + 1); - fvec = new Matrix(system.getPhase(0).getNumberOfComponents() + 1, 1); - } + /** + *+ * Constructor for cricondebarFlash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public cricondebarFlash(SystemInterface system) { + super(system); + Jac = new Matrix(system.getPhase(0).getNumberOfComponents() + 1, + system.getPhase(0).getNumberOfComponents() + 1); + fvec = new Matrix(system.getPhase(0).getNumberOfComponents() + 1, 1); + } - /** - *- * calcx. - *
- * - * @return a double - */ - public double calcx() { - // double ktot = 0; - double xtotal = 0; - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - system.getPhases()[0].getComponents()[i].setK( - Math.exp(system.getPhases()[1].getComponents()[i].getLogFugacityCoefficient() - - system.getPhases()[0].getComponents()[i] - .getLogFugacityCoefficient())); + /** + *+ * calcx. + *
+ * + * @return a double + */ + public double calcx() { + double xtotal = 0; + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + system.getPhases()[0].getComponents()[i] + .setK(Math.exp(system.getPhases()[1].getComponents()[i].getLogFugacityCoefficient() + - system.getPhases()[0].getComponents()[i].getLogFugacityCoefficient())); - system.getPhases()[1].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getK()); - system.getPhases()[1].getComponents()[i] - .setx(1.0 / system.getPhases()[0].getComponents()[i].getK() - * system.getPhases()[1].getComponents()[i].getz()); - // ktot += Math.abs(system.getPhases()[1].getComponents()[i].getK() - 1.0); - } - xtotal = 0.0; - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - xtotal += system.getPhases()[1].getComponents()[i].getx(); - } - return xtotal; + system.getPhases()[1].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getK()); + system.getPhases()[1].getComponents()[i] + .setx(1.0 / system.getPhases()[0].getComponents()[i].getK() + * system.getPhases()[1].getComponents()[i].getz()); + // ktot += Math.abs(system.getPhases()[1].getComponents()[i].getK() - 1.0); + } + xtotal = 0.0; + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + xtotal += system.getPhases()[1].getComponents()[i].getx(); + } + return xtotal; + } + + /** + *+ * initMoleFraction. + *
+ * + * @return a double + */ + public double initMoleFraction() { + double[] XI = new double[system.getPhase(0).getNumberOfComponents()]; + // double sumX = 0.0; + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + XI[i] = Math.exp(Math.log(system.getPhase(0).getComponent(i).getz()) + + system.getPhase(0).getComponent(i).getLogFugacityCoefficient() + - system.getPhase(1).getComponent(i).getLogFugacityCoefficient()); + // sumX += XI[i]; + } + double tempSumXI = 1.0;// sumX; + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + system.getPhase(1).getComponent(i).setx(XI[i] / tempSumXI); } + return tempSumXI; + } + + /** + *+ * run2. + *
+ */ + public void run2() { + ThermodynamicOperations localOperation = new ThermodynamicOperations(system); - /** - *- * initMoleFraction. - *
- * - * @return a double - */ - public double initMoleFraction() { - double[] XI = new double[system.getPhase(0).getNumberOfComponents()]; - // double sumX = 0.0; + system.init(0); + system.setTemperature(system.getPhase(0).getPseudoCriticalTemperature() + 20); + system.setPressure(system.getPhase(0).getPseudoCriticalPressure()); + system.init(3); + int iterations = 0; + + int maxNumberOfIterations = 300; + try { + localOperation.dewPointTemperatureFlash(); + } catch (Exception e) { + logger.error("error", e); + } + system.setNumberOfPhases(2); + system.setBeta(0.5); + system.setTemperature(system.getTemperature() - 20); + system.init(3); + system.display(); + double Q1 = 0; + double Qold = 0.0; + double dQ1dT = 0; + double oldTemperature = 0; + double oldIterTemp = 0; + do { + oldIterTemp = system.getTemperature(); + iterations = 0; + do { + iterations++; + initMoleFraction(); + system.init(3); + Qold = Q1; + Q1 = 0.0; for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - XI[i] = Math.exp(Math.log(system.getPhase(0).getComponent(i).getz()) - + system.getPhase(0).getComponent(i).getLogFugacityCoefficient() - - system.getPhase(1).getComponent(i).getLogFugacityCoefficient()); - // sumX += XI[i]; + Q1 -= system.getPhase(1).getComponent(i).getx() + * (system.getPhase(0).getComponent(i).getdfugdt() + - system.getPhase(1).getComponent(i).getdfugdt()); } - double tempSumXI = 1.0;// sumX; - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - system.getPhase(1).getComponent(i).setx(XI[i] / tempSumXI); + if (iterations > 1) { + dQ1dT = (Q1 - Qold) / (system.getTemperature() - oldTemperature); + } else { + dQ1dT = Q1 * 100.0; } - return tempSumXI; - } - /** - *- * run2. - *
- */ - public void run2() { - ThermodynamicOperations localOperation = new ThermodynamicOperations(system); + oldTemperature = system.getTemperature(); + system.setTemperature(system.getTemperature() - 0.5 * Q1 / dQ1dT); - system.init(0); - system.setTemperature(system.getPhase(0).getPseudoCriticalTemperature() + 20); - system.setPressure(system.getPhase(0).getPseudoCriticalPressure()); system.init(3); - int iterations = 0, maxNumberOfIterations = 300; + logger.info( + "temp " + system.getTemperature() + " Q1 " + Q1 + " pressure " + system.getPressure()); + } while (Math.abs(Q1) > 1e-10 && iterations < maxNumberOfIterations); + iterations = 0; + double presOld = system.getPressure(); + do { + logger.info( + "temp " + system.getTemperature() + " Q1 " + Q1 + " pressure " + system.getPressure()); + Matrix dx = null; + + iterations++; try { - localOperation.dewPointTemperatureFlash(); + system.init(3); + setfvec(); + setJac(); + dx = Jac.solve(fvec); } catch (Exception e) { - logger.error("error", e); + logger.error("error", e); } - system.setNumberOfPhases(2); - system.setBeta(0.5); - system.setTemperature(system.getTemperature() - 20); - system.init(3); - system.display(); - double Q1 = 0, Qold = 0.0, dQ1dT = 0, oldTemperature = 0, oldIterTemp = 0; - do { - oldIterTemp = system.getTemperature(); - iterations = 0; - do { - iterations++; - initMoleFraction(); - system.init(3); - Qold = Q1; - Q1 = 0.0; - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - Q1 -= system.getPhase(1).getComponent(i).getx() - * (system.getPhase(0).getComponent(i).getdfugdt() - - system.getPhase(1).getComponent(i).getdfugdt()); - } - if (iterations > 1) { - dQ1dT = (Q1 - Qold) / (system.getTemperature() - oldTemperature); - } else { - dQ1dT = Q1 * 100.0; - } - - oldTemperature = system.getTemperature(); - system.setTemperature(system.getTemperature() - 0.5 * Q1 / dQ1dT); + double damping = iterations * 1.0 / (10.0 + iterations); + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + double xlocal = system.getPhase(1).getComponent(i).getx() - damping * dx.get(i, 0); + if (xlocal < 1e-30) { + xlocal = 1e-30; + } + if (xlocal > 1.0 - 1e-30) { + xlocal = 1.0 - 1e-30; + } + logger.info("x" + (xlocal) + " press " + system.getPressure() + " fvec " + fvec.norm2()); + system.getPhase(1).getComponent(i).setx(xlocal); + } + system.setPressure( + system.getPressure() - damping * dx.get(system.getPhase(0).getNumberOfComponents(), 0)); + } while (Math.abs(fvec.norm2()) > 1.0e-12 && iterations < maxNumberOfIterations + && Math.abs(presOld - system.getPressure()) < 10.0); + } while (Math.abs(oldIterTemp - system.getTemperature()) > 1e-3); + } - system.init(3); - logger.info("temp " + system.getTemperature() + " Q1 " + Q1 + " pressure " - + system.getPressure()); - } while (Math.abs(Q1) > 1e-10 && iterations < maxNumberOfIterations); + /** {@inheritDoc} */ + @Override + public void run() { + ThermodynamicOperations localOperation = new ThermodynamicOperations(system); - iterations = 0; - double presOld = system.getPressure(); - do { - logger.info("temp " + system.getTemperature() + " Q1 " + Q1 + " pressure " - + system.getPressure()); - Matrix dx = null; + system.init(0); + // system.setTemperature(system.getPhase(0).getPseudoCriticalTemperature() + 7); + // system.setPressure(system.getPhase(0).getPseudoCriticalPressure() / 2.0); + system.init(3); - iterations++; - try { - system.init(3); - setfvec(); - setJac(); - dx = Jac.solve(fvec); - } catch (Exception e) { - logger.error("error", e); - } - double damping = iterations * 1.0 / (10.0 + iterations); - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - double xlocal = - system.getPhase(1).getComponent(i).getx() - damping * dx.get(i, 0); - if (xlocal < 1e-30) { - xlocal = 1e-30; - } - if (xlocal > 1.0 - 1e-30) { - xlocal = 1.0 - 1e-30; - } - logger.info("x" + (xlocal) + " press " + system.getPressure() + " fvec " - + fvec.norm2()); - system.getPhase(1).getComponent(i).setx(xlocal); - } - system.setPressure(system.getPressure() - - damping * dx.get(system.getPhase(0).getNumberOfComponents(), 0)); - } while (Math.abs(fvec.norm2()) > 1.0e-12 && iterations < maxNumberOfIterations - && Math.abs(presOld - system.getPressure()) < 10.0); - } while (Math.abs(oldIterTemp - system.getTemperature()) > 1e-3); - } + int iterations = 0; + localOperation.TPflash(); + double Q1 = 0; + double Qold = 0.0; + double dQ1dT = 1.0; + double oldTemperature = 0; + double dewTemp = 0; - /** {@inheritDoc} */ - @Override - public void run() { - ThermodynamicOperations localOperation = new ThermodynamicOperations(system); + for (int ii = 0; ii < 45; ii++) { + system.setPressure(system.getPressure() + 1.0); + try { + // if(ii<2) localOperation.dewPointTemperatureFlash(); + // else localOperation.dewPointPressureFlash(); + dewTemp = system.getTemperature(); + system.getPressure(); + } catch (Exception e) { + logger.error("error", e); + } - system.init(0); - // system.setTemperature(system.getPhase(0).getPseudoCriticalTemperature() + 7); - // system.setPressure(system.getPhase(0).getPseudoCriticalPressure() / 2.0); + iterations = 0; + do { + iterations++; system.init(3); - - int iterations = 0; + // initMoleFraction(); localOperation.TPflash(); - double Q1 = 0, Qold = 0.0, dQ1dT = 1.0, oldTemperature = 0; - double dewTemp = 0; - // double dewPres = 0; - - for (int ii = 0; ii < 45; ii++) { - system.setPressure(system.getPressure() + 1.0); - try { - // if(ii<2) localOperation.dewPointTemperatureFlash(); - // else localOperation.dewPointPressureFlash(); - dewTemp = system.getTemperature(); - // dewPres = system.getPressure(); - // system.display(); - } catch (Exception e) { - logger.error("error", e); - } - - iterations = 0; - do { - iterations++; - system.init(3); - // initMoleFraction(); - localOperation.TPflash(); - system.display(); - Qold = Q1; - Q1 = 0.0; - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - Q1 -= system.getPhase(1).getComponent(i).getx() - * (system.getPhase(0).getComponent(i).getdfugdt() - - system.getPhase(1).getComponent(i).getdfugdt()); - } - if (iterations > 3) { - dQ1dT = (Q1 - Qold) / (system.getTemperature() - oldTemperature); - } else { - dQ1dT = -Q1 * 100.0; - } + system.display(); + Qold = Q1; + Q1 = 0.0; + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + Q1 -= system.getPhase(1).getComponent(i).getx() + * (system.getPhase(0).getComponent(i).getdfugdt() + - system.getPhase(1).getComponent(i).getdfugdt()); + } + if (iterations > 3) { + dQ1dT = (Q1 - Qold) / (system.getTemperature() - oldTemperature); + } else { + dQ1dT = -Q1 * 100.0; + } - oldTemperature = system.getTemperature(); - system.setTemperature(system.getTemperature() - - iterations * 1.0 / (iterations + 10.0) * Q1 / dQ1dT); + oldTemperature = system.getTemperature(); + system.setTemperature( + system.getTemperature() - iterations * 1.0 / (iterations + 10.0) * Q1 / dQ1dT); - logger.info("temp " + system.getTemperature() + "dewTemp " + dewTemp + " Q1 " + Q1 - + " pressure " + system.getPressure()); - } while (Math.abs(Q1) > 1e-10 && iterations < 15);// maxNumberOfIterations); - logger.info("temp " + system.getTemperature() + " Q1 " + Q1); - // if(ii<2) system.setTemperature(dewTemp-); - logger.info("fvec " + fvec.norm2() + " pressure " + system.getPressure()); - } + logger.info("temp " + system.getTemperature() + "dewTemp " + dewTemp + " Q1 " + Q1 + + " pressure " + system.getPressure()); + } while (Math.abs(Q1) > 1e-10 && iterations < 15);// maxNumberOfIterations); + logger.info("temp " + system.getTemperature() + " Q1 " + Q1); + // if(ii<2) system.setTemperature(dewTemp-); + logger.info("fvec " + fvec.norm2() + " pressure " + system.getPressure()); } + } - /** - *
- * Setter for the field fvec
.
- *
+ * Setter for the field fvec
.
+ *
- * setJac. - *
- */ - public void setJac() { - Jac.timesEquals(0.0); - double dij = 0.0; + /** + *+ * setJac. + *
+ */ + public void setJac() { + Jac.timesEquals(0.0); + double dij = 0.0; - double tempJ = 0.0; + double tempJ = 0.0; - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - for (int j = 0; j < system.getPhase(0).getNumberOfComponents(); j++) { - dij = i == j ? 1.0 : 0.0;// Kroneckers delta - tempJ = -dij * 1.0 / system.getPhases()[1].getComponents()[i].getx() - - system.getPhases()[1].getComponents()[i].getdfugdx(j); - Jac.set(i, j, tempJ); - } - } + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + for (int j = 0; j < system.getPhase(0).getNumberOfComponents(); j++) { + dij = i == j ? 1.0 : 0.0;// Kroneckers delta + tempJ = -dij * 1.0 / system.getPhases()[1].getComponents()[i].getx() + - system.getPhases()[1].getComponents()[i].getdfugdx(j); + Jac.set(i, j, tempJ); + } + } - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - Jac.set(system.getPhase(0).getNumberOfComponents(), i, -1.0); - } - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - Jac.set(i, system.getPhase(0).getNumberOfComponents(), - system.getPhases()[0].getComponents()[i].getdfugdp() - - system.getPhases()[1].getComponents()[i].getdfugdp()); - } + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + Jac.set(system.getPhase(0).getNumberOfComponents(), i, -1.0); + } + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + Jac.set(i, system.getPhase(0).getNumberOfComponents(), + system.getPhases()[0].getComponents()[i].getdfugdp() + - system.getPhases()[1].getComponents()[i].getdfugdp()); } + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp.java index 157af018f8..9f74564a56 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp.java @@ -12,150 +12,156 @@ * @version $Id: $Id */ public class cricondenBarTemp implements java.io.Serializable { - private static final long serialVersionUID = 1000; - int neq = 0, iter = 0; - int ic02p = -100, ic03p = -100, testcrit = 0, npCrit = 0; - double beta = 0, ds = 0, dTmax = 1, dPmax = 1, avscp = 0.1, TC1 = 0, TC2 = 0, PC1 = 0, PC2 = 0; - Matrix Jac; - Matrix fvec; - Matrix u; - Matrix uold; - Matrix Xgij; - SystemInterface system; - int numberOfComponents; - int speceq = 0; - Matrix a = new Matrix(4, 4); - Matrix s = new Matrix(1, 4); - Matrix xg; - Matrix dx; - Matrix xcoef; + private static final long serialVersionUID = 1000; + int neq = 0; + int iter = 0; + int ic02p = -100; + int ic03p = -100; + int testcrit = 0; + int npCrit = 0; + double beta = 0; + double ds = 0; + double dTmax = 1; + double dPmax = 1; + double avscp = 0.1; + double TC1 = 0; + double TC2 = 0; + double PC1 = 0; + double PC2 = 0; + Matrix Jac; + Matrix fvec; + Matrix u; + Matrix uold; + Matrix Xgij; + SystemInterface system; + int numberOfComponents; + int speceq = 0; + Matrix a = new Matrix(4, 4); + Matrix s = new Matrix(1, 4); + Matrix xg; + Matrix dx; + Matrix xcoef; - /** - *- * Constructor for cricondenBarTemp. - *
- */ - public cricondenBarTemp() {} + /** + *+ * Constructor for cricondenBarTemp. + *
+ */ + public cricondenBarTemp() {} - /** - *- * Constructor for cricondenBarTemp. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param numberOfPhases a int - * @param numberOfComponents a int - */ - public cricondenBarTemp(SystemInterface system, int numberOfPhases, int numberOfComponents) { - this.system = system; - this.numberOfComponents = numberOfComponents; - neq = numberOfComponents; - Jac = new Matrix(neq, neq); - fvec = new Matrix(neq, 1); - u = new Matrix(neq, 1); - Xgij = new Matrix(neq, 4); - setu(); - uold = u.copy(); - // System.out.println("Spec : " +speceq); - } + /** + *+ * Constructor for cricondenBarTemp. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param numberOfPhases a int + * @param numberOfComponents a int + */ + public cricondenBarTemp(SystemInterface system, int numberOfPhases, int numberOfComponents) { + this.system = system; + this.numberOfComponents = numberOfComponents; + neq = numberOfComponents; + Jac = new Matrix(neq, neq); + fvec = new Matrix(neq, 1); + u = new Matrix(neq, 1); + Xgij = new Matrix(neq, 4); + setu(); + uold = u.copy(); + // System.out.println("Spec : " +speceq); + } - /** - *
- * Setter for the field fvec
.
- *
+ * Setter for the field fvec
.
+ *
- * setJac. - *
- */ - public void setJac() { - Jac.timesEquals(0.0); - double dij = 0.0; - - double tempJ = 0.0; - // double sumdyidbeta = 0, sumdxidbeta = 0; - // int nofc = numberOfComponents; + /** + *+ * setJac. + *
+ */ + public void setJac() { + Jac.timesEquals(0.0); + double dij = 0.0; - for (int i = 0; i < numberOfComponents; i++) { - for (int j = 0; j < numberOfComponents; j++) { - dij = i == j ? 1.0 : 0.0;// Kroneckers delta - tempJ = 1.0 / system.getBeta() - * (dij / system.getPhases()[0].getComponents()[i].getx() - 1.0 - + system.getPhases()[0].getComponents()[i].getdfugdx(j)) - + 1.0 / (1.0 - system.getBeta()) - * (dij / system.getPhases()[1].getComponents()[i].getx() - 1.0 - + system.getPhases()[1].getComponents()[i].getdfugdx(j)); - Jac.set(i, j, tempJ); - } - } + double tempJ = 0.0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < numberOfComponents; j++) { + dij = i == j ? 1.0 : 0.0;// Kroneckers delta + tempJ = 1.0 / system.getBeta() + * (dij / system.getPhases()[0].getComponents()[i].getx() - 1.0 + + system.getPhases()[0].getComponents()[i].getdfugdx(j)) + + 1.0 / (1.0 - system.getBeta()) + * (dij / system.getPhases()[1].getComponents()[i].getx() - 1.0 + + system.getPhases()[1].getComponents()[i].getdfugdx(j)); + Jac.set(i, j, tempJ); + } } + } - /** - *
- * Setter for the field u
.
- *
+ * Setter for the field u
.
+ *
- * init. - *
- */ - public void init() { - double temp = 0; - - for (int i = 0; i < numberOfComponents; i++) { - temp += u.get(i, 0); - } - system.setBeta(temp); - for (int i = 0; i < numberOfComponents; i++) { - system.getPhases()[0].getComponents()[i].setx(u.get(i, 0) / system.getBeta()); - system.getPhases()[1].getComponents()[i] - .setx((system.getPhases()[0].getComponents()[i].getz() - u.get(i, 0)) - / (1.0 - system.getBeta())); - system.getPhases()[0].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getx() - / system.getPhases()[1].getComponents()[i].getx()); - system.getPhases()[1].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getK()); - } + /** + *+ * init. + *
+ */ + public void init() { + double temp = 0; - system.init(3); + for (int i = 0; i < numberOfComponents; i++) { + temp += u.get(i, 0); } - - /** - *- * solve. - *
- * - * @return a double - */ - public double solve() { - iter++; - init(); - setfvec(); - setJac(); - dx = Jac.solve(fvec); - // dx.print(10,10); - u.minusEquals(dx); - return (dx.norm2() / u.norm2()); + system.setBeta(temp); + for (int i = 0; i < numberOfComponents; i++) { + system.getPhases()[0].getComponents()[i].setx(u.get(i, 0) / system.getBeta()); + system.getPhases()[1].getComponents()[i] + .setx((system.getPhases()[0].getComponents()[i].getz() - u.get(i, 0)) + / (1.0 - system.getBeta())); + system.getPhases()[0].getComponents()[i].setK(system.getPhases()[0].getComponents()[i].getx() + / system.getPhases()[1].getComponents()[i].getx()); + system.getPhases()[1].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getK()); } + + system.init(3); + } + + /** + *+ * solve. + *
+ * + * @return a double + */ + public double solve() { + iter++; + init(); + setfvec(); + setJac(); + dx = Jac.solve(fvec); + // dx.print(10,10); + u.minusEquals(dx); + return (dx.norm2() / u.norm2()); + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/dewPointTemperatureFlashDer.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/dewPointTemperatureFlashDer.java index 3c0c5ca149..e0c9e412a3 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/dewPointTemperatureFlashDer.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/dewPointTemperatureFlashDer.java @@ -11,158 +11,156 @@ * @version $Id: $Id */ public class dewPointTemperatureFlashDer extends constantDutyTemperatureFlash { - private static final long serialVersionUID = 1000; - - /** - *- * Constructor for dewPointTemperatureFlashDer. - *
- */ - public dewPointTemperatureFlashDer() {} - - /** - *- * Constructor for dewPointTemperatureFlashDer. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public dewPointTemperatureFlashDer(SystemInterface system) { - super(system); + private static final long serialVersionUID = 1000; + + /** + *+ * Constructor for dewPointTemperatureFlashDer. + *
+ */ + public dewPointTemperatureFlashDer() {} + + /** + *+ * Constructor for dewPointTemperatureFlashDer. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public dewPointTemperatureFlashDer(SystemInterface system) { + super(system); + } + + /** {@inheritDoc} */ + @Override + public void run() { + if (system.getPhase(0).getNumberOfComponents() == 1 + && system.getPressure() > system.getPhase(0).getComponent(0).getPC()) { + setSuperCritical(true); } - /** {@inheritDoc} */ - @Override - public void run() { - if (system.getPhase(0).getNumberOfComponents() == 1 - && system.getPressure() > system.getPhase(0).getComponent(0).getPC()) { - setSuperCritical(true); - } + // System.out.println("starting"); + system.init(0); + system.setBeta(0, 1.0 - 1e-15); + system.setBeta(1, 1e-15); + system.init(1); + system.setNumberOfPhases(2); + + double oldTemp = 0; + if (system.isChemicalSystem()) { + system.getChemicalReactionOperations().solveChemEq(0); + system.getChemicalReactionOperations().solveChemEq(1); + } - int iterations = 0, maxNumberOfIterations = 1000; - double xtotal = 1; - // double deriv = 0, funk = 0; - // System.out.println("starting"); - system.init(0); - system.setBeta(0, 1.0 - 1e-15); - system.setBeta(1, 1e-15); - system.init(1); - system.setNumberOfPhases(2); - - double oldTemp = 0; - if (system.isChemicalSystem()) { - system.getChemicalReactionOperations().solveChemEq(0); - system.getChemicalReactionOperations().solveChemEq(1); + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + system.getPhases()[0].getComponents()[i] + .setx(system.getPhases()[0].getComponents()[i].getz()); + if (system.getPhases()[0].getComponents()[i].getIonicCharge() != 0) { + system.getPhases()[0].getComponents()[i].setx(1e-40); + } else { + if (system.getPhases()[1].getComponents()[i].getName().equals("water")) { + system.getPhases()[1].getComponents()[i].setx(1.0); + } else if (system.getPhases()[1].hasComponent("water")) { + system.getPhases()[1].getComponents()[i].setx(1.0e-10); + } else { + system.getPhases()[1].getComponents()[i] + .setx(1.0 / system.getPhases()[0].getComponents()[i].getK() + * system.getPhases()[1].getComponents()[i].getz()); } + } + } - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - system.getPhases()[0].getComponents()[i] - .setx(system.getPhases()[0].getComponents()[i].getz()); - if (system.getPhases()[0].getComponents()[i].getIonicCharge() != 0) { - system.getPhases()[0].getComponents()[i].setx(1e-40); - } else { - if (system.getPhases()[1].getComponents()[i].getName().equals("water")) { - system.getPhases()[1].getComponents()[i].setx(1.0); - } else if (system.getPhases()[1].hasComponent("water")) { - system.getPhases()[1].getComponents()[i].setx(1.0e-10); - } else { - system.getPhases()[1].getComponents()[i] - .setx(1.0 / system.getPhases()[0].getComponents()[i].getK() - * system.getPhases()[1].getComponents()[i].getz()); - } - } - } - // system.setPressure(system.getPhases()[0].getAntoineVaporPressure(system.getTemperature())); - xtotal = 0.0; - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - xtotal += system.getPhases()[1].getComponents()[i].getx(); - } - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - system.getPhases()[1].getComponents()[i] - .setx(system.getPhases()[1].getComponents()[i].getx() / xtotal); - } + // system.setPressure(system.getPhases()[0].getAntoineVaporPressure(system.getTemperature())); + double xtotal = 0.0; + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + xtotal += system.getPhases()[1].getComponents()[i].getx(); + } + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + system.getPhases()[1].getComponents()[i] + .setx(system.getPhases()[1].getComponents()[i].getx() / xtotal); + } - double ktot = 0.0; - // double = 0.0, fold = 0; - do { - oldTemp = system.getTemperature(); - iterations++; - system.init(2); - - xtotal = 0.0; - double dfdT = 0.0; - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - xtotal += 1.0 / system.getPhases()[0].getComponents()[i].getK() - * system.getPhases()[1].getComponents()[i].getz(); - dfdT -= 1.0 / system.getPhases()[0].getComponents()[i].getK() - * system.getPhases()[1].getComponents()[i].getz() - * (system.getPhases()[1].getComponents()[i].getdfugdt() - - system.getPhases()[0].getComponents()[i].getdfugdt()); - } - double f = xtotal - 1.0; - // fold = f; - - // System.out.println("x" + xtotal); - // oldTemperature = system.getTemperature(); - - if (iterations < 5) { - system.setTemperature(system.getTemperature() + iterations / (iterations + 100.0) - * (xtotal * system.getTemperature() - system.getTemperature())); - } else { - system.setTemperature( - system.getTemperature() - iterations / (10.0 + iterations) * f / dfdT); - } - // System.out.println("temperature " + system.getTemperature()); - - system.init(1); - - ktot = 0.0; - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - if (system.getPhase(0).getComponent(i).getIonicCharge() != 0) { - system.getPhases()[0].getComponents()[i].setK(1e-40); - } else { - system.getPhases()[0].getComponents()[i].setK(Math.exp( - system.getPhases()[1].getComponents()[i].getLogFugacityCoefficient() - - system.getPhases()[0].getComponents()[i] - .getLogFugacityCoefficient())); - } - system.getPhases()[1].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getK()); - system.getPhases()[1].getComponents()[i] - .setx(1.0 / system.getPhases()[0].getComponents()[i].getK() - * system.getPhases()[1].getComponents()[i].getz()); - ktot += Math.abs(system.getPhases()[1].getComponents()[i].getK() - 1.0); - } - // system.init_x_y(); - - xtotal = 0.0; - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - xtotal += system.getPhases()[1].getComponents()[i].getx(); - } - // System.out.println("xtotal " + xtotal); - for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { - system.getPhases()[1].getComponents()[i] - .setx(system.getPhases()[1].getComponents()[i].getx() / xtotal); - } - } while (((Math.abs(xtotal - 1.0) > 1e-6) - || Math.abs(oldTemp - system.getTemperature()) / oldTemp > 1e-4) - || iterations < 3 && (iterations < maxNumberOfIterations)); - if (Math.abs(xtotal - 1.0) > 1e-5 - || ktot < 1.0e-3 && system.getPhase(0).getNumberOfComponents() > 1) { - setSuperCritical(true); - } - if (ktot < 1.0e-3) { - if (system.getTemperature() < 90.0) { - setSuperCritical(true); - } else { - setSuperCritical(false); - // system.setTemperature(system.getTemperature() - 10.0); - // run(); - } + int iterations = 0; + int maxNumberOfIterations = 1000; + double ktot = 0.0; + do { + oldTemp = system.getTemperature(); + iterations++; + system.init(2); + + xtotal = 0.0; + double dfdT = 0.0; + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + xtotal += 1.0 / system.getPhases()[0].getComponents()[i].getK() + * system.getPhases()[1].getComponents()[i].getz(); + dfdT -= 1.0 / system.getPhases()[0].getComponents()[i].getK() + * system.getPhases()[1].getComponents()[i].getz() + * (system.getPhases()[1].getComponents()[i].getdfugdt() + - system.getPhases()[0].getComponents()[i].getdfugdt()); + } + double f = xtotal - 1.0; + // fold = f; + + // System.out.println("x" + xtotal); + // oldTemperature = system.getTemperature(); + + if (iterations < 5) { + system.setTemperature(system.getTemperature() + iterations / (iterations + 100.0) + * (xtotal * system.getTemperature() - system.getTemperature())); + } else { + system + .setTemperature(system.getTemperature() - iterations / (10.0 + iterations) * f / dfdT); + } + // System.out.println("temperature " + system.getTemperature()); + + system.init(1); + + ktot = 0.0; + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getIonicCharge() != 0) { + system.getPhases()[0].getComponents()[i].setK(1e-40); + } else { + system.getPhases()[0].getComponents()[i] + .setK(Math.exp(system.getPhases()[1].getComponents()[i].getLogFugacityCoefficient() + - system.getPhases()[0].getComponents()[i].getLogFugacityCoefficient())); } + system.getPhases()[1].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getK()); + system.getPhases()[1].getComponents()[i] + .setx(1.0 / system.getPhases()[0].getComponents()[i].getK() + * system.getPhases()[1].getComponents()[i].getz()); + ktot += Math.abs(system.getPhases()[1].getComponents()[i].getK() - 1.0); + } + // system.init_x_y(); + + xtotal = 0.0; + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + xtotal += system.getPhases()[1].getComponents()[i].getx(); + } + // System.out.println("xtotal " + xtotal); + for (int i = 0; i < system.getPhases()[1].getNumberOfComponents(); i++) { + system.getPhases()[1].getComponents()[i] + .setx(system.getPhases()[1].getComponents()[i].getx() / xtotal); + } + } while (((Math.abs(xtotal - 1.0) > 1e-6) + || Math.abs(oldTemp - system.getTemperature()) / oldTemp > 1e-4) + || iterations < 3 && (iterations < maxNumberOfIterations)); + if (Math.abs(xtotal - 1.0) > 1e-5 + || ktot < 1.0e-3 && system.getPhase(0).getNumberOfComponents() > 1) { + setSuperCritical(true); + } + if (ktot < 1.0e-3) { + if (system.getTemperature() < 90.0) { + setSuperCritical(true); + } else { + setSuperCritical(false); + // system.setTemperature(system.getTemperature() - 10.0); + // run(); + } } + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/sysNewtonRhapsonPHflash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/sysNewtonRhapsonPHflash.java index c85af0c9de..d5d4a11b8e 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/sysNewtonRhapsonPHflash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/sysNewtonRhapsonPHflash.java @@ -2,7 +2,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - import Jama.Matrix; import neqsim.MathLib.nonLinearSolver.newtonRhapson; import neqsim.thermo.ThermodynamicConstantsInterface; @@ -17,255 +16,262 @@ * @version $Id: $Id */ public class sysNewtonRhapsonPHflash implements ThermodynamicConstantsInterface { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(sysNewtonRhapsonPHflash.class); - int neq = 0, iter = 0; - int ic02p = -100, ic03p = -100, testcrit = 0, npCrit = 0; - double beta = 0, ds = 0, dTmax = 1, dPmax = 1, avscp = 0.1, TC1 = 0, TC2 = 0, PC1 = 0, PC2 = 0; - double specVar = 0; - Matrix Jac; - Matrix fvec; - Matrix gTvec; - Matrix gPvec; - Matrix u; - Matrix uold; - Matrix Xgij; - SystemInterface system; - int numberOfComponents; - int speceq = 0; - Matrix a = new Matrix(4, 4); - Matrix s = new Matrix(1, 4); - Matrix xg; - Matrix xcoef; - newtonRhapson solver; - boolean etterCP = false; - boolean etterCP2 = false; - double dVdT = 0; - int type = 0; - double dPdT = 0; + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(sysNewtonRhapsonPHflash.class); + int neq = 0; + int iter = 0; + int ic02p = -100; + int ic03p = -100; + int testcrit = 0; + int npCrit = 0; + double beta = 0; + double ds = 0; + double dTmax = 1; + double dPmax = 1; + double avscp = 0.1; + double TC1 = 0; + double TC2 = 0; + double PC1 = 0; + double PC2 = 0; + double specVar = 0; + Matrix Jac; + Matrix fvec; + Matrix gTvec; + Matrix gPvec; + Matrix u; + Matrix uold; + Matrix Xgij; + SystemInterface system; + int numberOfComponents; + int speceq = 0; + Matrix a = new Matrix(4, 4); + Matrix s = new Matrix(1, 4); + Matrix xg; + Matrix xcoef; + newtonRhapson solver; + boolean etterCP = false; + boolean etterCP2 = false; + double dVdT = 0; + int type = 0; + double dPdT = 0; - /** - *- * Constructor for sysNewtonRhapsonPHflash. - *
- */ - public sysNewtonRhapsonPHflash() {} + /** + *+ * Constructor for sysNewtonRhapsonPHflash. + *
+ */ + public sysNewtonRhapsonPHflash() {} - /** - *- * Constructor for sysNewtonRhapsonPHflash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param numberOfPhases a int - * @param numberOfComponents a int - */ - public sysNewtonRhapsonPHflash(SystemInterface system, int numberOfPhases, - int numberOfComponents) { - this.system = system; - this.numberOfComponents = numberOfComponents; - neq = numberOfComponents; - Jac = new Matrix(neq + 2, neq + 2); - fvec = new Matrix(neq + 2, 1); - gTvec = new Matrix(neq, 1); - gPvec = new Matrix(neq, 1); - u = new Matrix(neq + 2, 1); - Xgij = new Matrix(neq + 2, 4); - setu(); - uold = u.copy(); - // logger.info("Spec : " +speceq); - solver = new newtonRhapson(); - solver.setOrder(3); - } + /** + *+ * Constructor for sysNewtonRhapsonPHflash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param numberOfPhases a int + * @param numberOfComponents a int + */ + public sysNewtonRhapsonPHflash(SystemInterface system, int numberOfPhases, + int numberOfComponents) { + this.system = system; + this.numberOfComponents = numberOfComponents; + neq = numberOfComponents; + Jac = new Matrix(neq + 2, neq + 2); + fvec = new Matrix(neq + 2, 1); + gTvec = new Matrix(neq, 1); + gPvec = new Matrix(neq, 1); + u = new Matrix(neq + 2, 1); + Xgij = new Matrix(neq + 2, 4); + setu(); + uold = u.copy(); + // logger.info("Spec : " +speceq); + solver = new newtonRhapson(); + solver.setOrder(3); + } - /** - *- * Constructor for sysNewtonRhapsonPHflash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param numberOfPhases a int - * @param numberOfComponents a int - * @param type a int - */ - public sysNewtonRhapsonPHflash(SystemInterface system, int numberOfPhases, - int numberOfComponents, int type) { - this(system, numberOfPhases, numberOfComponents); - this.type = type; - } + /** + *+ * Constructor for sysNewtonRhapsonPHflash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param numberOfPhases a int + * @param numberOfComponents a int + * @param type a int + */ + public sysNewtonRhapsonPHflash(SystemInterface system, int numberOfPhases, int numberOfComponents, + int type) { + this(system, numberOfPhases, numberOfComponents); + this.type = type; + } - /** - *- * setSpec. - *
- * - * @param spec a double - */ - public void setSpec(double spec) { - this.specVar = spec; - } + /** + *+ * setSpec. + *
+ * + * @param spec a double + */ + public void setSpec(double spec) { + this.specVar = spec; + } - /** - *
- * Setter for the field fvec
.
- *
+ * Setter for the field fvec
.
+ *
- * setJac. - *
- */ - public void setJac() { - Jac.timesEquals(0.0); - double dij = 0.0; - - double tempJ = 0.0; - // int nofc = numberOfComponents; + fvec.set(numberOfComponents, 0, rT); + fvec.set(numberOfComponents + 1, 0, rP); + } - for (int i = 0; i < numberOfComponents; i++) { - for (int j = 0; j < numberOfComponents; j++) { - dij = i == j ? 1.0 : 0.0;// Kroneckers delta - tempJ = 1.0 / system.getBeta() - * (dij / system.getPhases()[0].getComponents()[i].getx() - 1.0 - + system.getPhases()[0].getComponents()[i].getdfugdx(j)) - + 1.0 / (1.0 - system.getBeta()) - * (dij / system.getPhases()[1].getComponents()[i].getx() - 1.0 - + system.getPhases()[1].getComponents()[i].getdfugdx(j)); - Jac.set(i, j, tempJ); - } - } + /** + *+ * setJac. + *
+ */ + public void setJac() { + Jac.timesEquals(0.0); + double dij = 0.0; - double[] gT = new double[numberOfComponents]; - double[] gP = new double[numberOfComponents]; + double tempJ = 0.0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < numberOfComponents; j++) { + dij = i == j ? 1.0 : 0.0;// Kroneckers delta + tempJ = 1.0 / system.getBeta() + * (dij / system.getPhases()[0].getComponents()[i].getx() - 1.0 + + system.getPhases()[0].getComponents()[i].getdfugdx(j)) + + 1.0 / (1.0 - system.getBeta()) + * (dij / system.getPhases()[1].getComponents()[i].getx() - 1.0 + + system.getPhases()[1].getComponents()[i].getdfugdx(j)); + Jac.set(i, j, tempJ); + } + } - for (int i = 0; i < numberOfComponents; i++) { - gT[i] = system.getTemperature() * (system.getPhases()[0].getComponents()[i].getdfugdt() - - system.getPhases()[1].getComponents()[i].getdfugdt()); - gP[i] = system.getPressure() * (system.getPhases()[0].getComponents()[i].getdfugdp() - - system.getPhases()[1].getComponents()[i].getdfugdp()); + double[] gT = new double[numberOfComponents]; + double[] gP = new double[numberOfComponents]; - Jac.set(numberOfComponents, i, gT[i]); - Jac.set(i, numberOfComponents, gT[i]); + for (int i = 0; i < numberOfComponents; i++) { + gT[i] = system.getTemperature() * (system.getPhases()[0].getComponents()[i].getdfugdt() + - system.getPhases()[1].getComponents()[i].getdfugdt()); + gP[i] = system.getPressure() * (system.getPhases()[0].getComponents()[i].getdfugdp() + - system.getPhases()[1].getComponents()[i].getdfugdp()); - Jac.set(numberOfComponents + 1, i, gP[i]); - Jac.set(i, numberOfComponents + 1, gP[i]); - } + Jac.set(numberOfComponents, i, gT[i]); + Jac.set(i, numberOfComponents, gT[i]); - double Ett = -system.getCp() / R; - Jac.set(numberOfComponents, numberOfComponents, Ett); - double Etp = system.getPressure() / R * system.getdVdTpn(); - Jac.set(numberOfComponents, numberOfComponents + 1, Etp); - Jac.set(numberOfComponents + 1, numberOfComponents, Etp); - double Epp = Math.pow(system.getPressure(), 2.0) / (R * system.getTemperature()) - * system.getdVdPtn(); - Jac.set(numberOfComponents + 1, numberOfComponents + 1, Epp); + Jac.set(numberOfComponents + 1, i, gP[i]); + Jac.set(i, numberOfComponents + 1, gP[i]); } - /** - *
- * Setter for the field u
.
- *
+ * Setter for the field u
.
+ *
- * init. - *
- */ - public void init() { - double temp = system.getBeta(); + /** + *+ * init. + *
+ */ + public void init() { + double temp = system.getBeta(); - for (int i = 0; i < numberOfComponents; i++) { - temp += u.get(i, 0); - } - system.setBeta(temp); + for (int i = 0; i < numberOfComponents; i++) { + temp += u.get(i, 0); + } + system.setBeta(temp); - for (int i = 0; i < numberOfComponents; i++) { - double v = 0.0, l = 0.0; - v = system.getPhases()[0].getComponents()[i].getx() * system.getBeta() + u.get(i, 0); - l = system.getPhases()[0].getComponents()[i].getz() - v; - system.getPhases()[0].getComponents()[i].setx(v / system.getBeta()); - system.getPhases()[1].getComponents()[i].setx(l / (1.0 - system.getBeta())); - system.getPhases()[1].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getx() - / system.getPhases()[1].getComponents()[i].getx()); - system.getPhases()[0].getComponents()[i] - .setK(system.getPhases()[1].getComponents()[i].getK()); - } + for (int i = 0; i < numberOfComponents; i++) { + double v = 0.0; + double l = 0.0; + v = system.getPhases()[0].getComponents()[i].getx() * system.getBeta() + u.get(i, 0); + l = system.getPhases()[0].getComponents()[i].getz() - v; + system.getPhases()[0].getComponents()[i].setx(v / system.getBeta()); + system.getPhases()[1].getComponents()[i].setx(l / (1.0 - system.getBeta())); + system.getPhases()[1].getComponents()[i].setK(system.getPhases()[0].getComponents()[i].getx() + / system.getPhases()[1].getComponents()[i].getx()); + system.getPhases()[0].getComponents()[i] + .setK(system.getPhases()[1].getComponents()[i].getK()); + } - // dt = Math.exp(u.get(numberOfComponents+1,0)) - system.getTemperature(); - // logger.info("temperature: " + system.getTemperature()); - // logger.info("pressure: " + system.getPressure()); - // system.init(1); - // v1 = system.getVolume(); - // system.setPressure(Math.exp(u.get(numberOfComponents+1,0))); - logger.info("temperature: " + system.getTemperature()); - system.setTemperature( - Math.exp(u.get(numberOfComponents, 0) + Math.log(system.getTemperature()))); - system.setPressure( - Math.exp(u.get(numberOfComponents + 1, 0) + Math.log(system.getPressure()))); - logger.info("etter temperature: " + system.getTemperature()); + // dt = Math.exp(u.get(numberOfComponents+1,0)) - system.getTemperature(); + // logger.info("temperature: " + system.getTemperature()); + // logger.info("pressure: " + system.getPressure()); + // system.init(1); + // v1 = system.getVolume(); + // system.setPressure(Math.exp(u.get(numberOfComponents+1,0))); + logger.info("temperature: " + system.getTemperature()); + system + .setTemperature(Math.exp(u.get(numberOfComponents, 0) + Math.log(system.getTemperature()))); + system.setPressure(Math.exp(u.get(numberOfComponents + 1, 0) + Math.log(system.getPressure()))); + logger.info("etter temperature: " + system.getTemperature()); - system.init(3); - } + system.init(3); + } - /** - *- * solve. - *
- * - * @param np a int - * @return a int - */ - public int solve(int np) { - // Matrix dx; - iter = 1; - do { - iter++; - init(); - setfvec(); - setJac(); - fvec.print(10, 10); - Jac.print(10, 10); - u = Jac.solve(fvec.times(-1.0)); - // u.equals(dx.timesEquals(1.0)); - fvec.print(10, 10); - logger.info("iter: " + iter); - } while (fvec.norm2() > 1.e-10 && iter < 1000);// && Double.isNaN(dx.norm2())); - logger.info("iter: " + iter); - logger.info("temperature: " + system.getTemperature()); - logger.info("pressure: " + system.getPressure()); - init(); - return iter; - } + /** + *+ * solve. + *
+ * + * @param np a int + * @return a int + */ + public int solve(int np) { + iter = 1; + do { + iter++; + init(); + setfvec(); + setJac(); + fvec.print(10, 10); + Jac.print(10, 10); + u = Jac.solve(fvec.times(-1.0)); + // u.equals(dx.timesEquals(1.0)); + fvec.print(10, 10); + logger.info("iter: " + iter); + } while (fvec.norm2() > 1.e-10 && iter < 1000);// && Double.isNaN(dx.norm2())); + logger.info("iter: " + iter); + logger.info("temperature: " + system.getTemperature()); + logger.info("pressure: " + system.getPressure()); + init(); + return iter; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/sysNewtonRhapsonTPflash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/sysNewtonRhapsonTPflash.java index 445fb8ed05..7190082673 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/sysNewtonRhapsonTPflash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/sysNewtonRhapsonTPflash.java @@ -12,154 +12,160 @@ * @version $Id: $Id */ public class sysNewtonRhapsonTPflash implements java.io.Serializable { - private static final long serialVersionUID = 1000; - int neq = 0, iter = 0; - int ic02p = -100, ic03p = -100, testcrit = 0, npCrit = 0; - double beta = 0, ds = 0, dTmax = 1, dPmax = 1, avscp = 0.1, TC1 = 0, TC2 = 0, PC1 = 0, PC2 = 0; - Matrix Jac; - Matrix fvec; - Matrix u; - Matrix uold; - Matrix Xgij; - SystemInterface system; - int numberOfComponents; - int speceq = 0; - Matrix a = new Matrix(4, 4); - Matrix s = new Matrix(1, 4); - Matrix xg; - Matrix dx; - Matrix xcoef; + private static final long serialVersionUID = 1000; + int neq = 0; + int iter = 0; + int ic02p = -100; + int ic03p = -100; + int testcrit = 0; + int npCrit = 0; + double beta = 0; + double ds = 0; + double dTmax = 1; + double dPmax = 1; + double avscp = 0.1; + double TC1 = 0; + double TC2 = 0; + double PC1 = 0; + double PC2 = 0; + Matrix Jac; + Matrix fvec; + Matrix u; + Matrix uold; + Matrix Xgij; + SystemInterface system; + int numberOfComponents; + int speceq = 0; + Matrix a = new Matrix(4, 4); + Matrix s = new Matrix(1, 4); + Matrix xg; + Matrix dx; + Matrix xcoef; - /** - *- * Constructor for sysNewtonRhapsonTPflash. - *
- */ - public sysNewtonRhapsonTPflash() {} + /** + *+ * Constructor for sysNewtonRhapsonTPflash. + *
+ */ + public sysNewtonRhapsonTPflash() {} - /** - *- * Constructor for sysNewtonRhapsonTPflash. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param numberOfPhases a int - * @param numberOfComponents a int - */ - public sysNewtonRhapsonTPflash(SystemInterface system, int numberOfPhases, - int numberOfComponents) { - this.system = system; - this.numberOfComponents = numberOfComponents; - neq = numberOfComponents; - Jac = new Matrix(neq, neq); - fvec = new Matrix(neq, 1); - u = new Matrix(neq, 1); - Xgij = new Matrix(neq, 4); - setu(); - uold = u.copy(); - // System.out.println("Spec : " +speceq); - } + /** + *+ * Constructor for sysNewtonRhapsonTPflash. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param numberOfPhases a int + * @param numberOfComponents a int + */ + public sysNewtonRhapsonTPflash(SystemInterface system, int numberOfPhases, + int numberOfComponents) { + this.system = system; + this.numberOfComponents = numberOfComponents; + neq = numberOfComponents; + Jac = new Matrix(neq, neq); + fvec = new Matrix(neq, 1); + u = new Matrix(neq, 1); + Xgij = new Matrix(neq, 4); + setu(); + uold = u.copy(); + // System.out.println("Spec : " +speceq); + } - /** - *
- * Setter for the field fvec
.
- *
+ * Setter for the field fvec
.
+ *
- * setJac. - *
- */ - public void setJac() { - Jac.timesEquals(0.0); - double dij = 0.0; - - double tempJ = 0.0; - // double sumdyidbeta = 0, sumdxidbeta = 0; - // int nofc = numberOfComponents; + /** + *+ * setJac. + *
+ */ + public void setJac() { + Jac.timesEquals(0.0); + double dij = 0.0; - for (int i = 0; i < numberOfComponents; i++) { - for (int j = 0; j < numberOfComponents; j++) { - dij = i == j ? 1.0 : 0.0;// Kroneckers delta - tempJ = 1.0 / system.getBeta() - * (dij / system.getPhase(0).getComponents()[i].getx() - 1.0 - + system.getPhase(0).getComponents()[i].getdfugdx(j)) - + 1.0 / (1.0 - system.getBeta()) - * (dij / system.getPhase(1).getComponents()[i].getx() - 1.0 - + system.getPhase(1).getComponents()[i].getdfugdx(j)); - Jac.set(i, j, tempJ); - } - } + double tempJ = 0.0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < numberOfComponents; j++) { + dij = i == j ? 1.0 : 0.0;// Kroneckers delta + tempJ = 1.0 / system.getBeta() + * (dij / system.getPhase(0).getComponents()[i].getx() - 1.0 + + system.getPhase(0).getComponents()[i].getdfugdx(j)) + + 1.0 / (1.0 - system.getBeta()) * (dij / system.getPhase(1).getComponents()[i].getx() + - 1.0 + system.getPhase(1).getComponents()[i].getdfugdx(j)); + Jac.set(i, j, tempJ); + } } + } - /** - *
- * Setter for the field u
.
- *
+ * Setter for the field u
.
+ *
- * init. - *
- */ - public void init() { - double temp = 0; - - for (int i = 0; i < numberOfComponents; i++) { - temp += u.get(i, 0); - } + /** + *+ * init. + *
+ */ + public void init() { + double temp = 0; - system.setBeta(temp); - for (int i = 0; i < numberOfComponents; i++) { - system.getPhase(0).getComponents()[i].setx(u.get(i, 0) / system.getBeta()); - system.getPhase(1).getComponents()[i] - .setx((system.getPhase(0).getComponents()[i].getz() - u.get(i, 0)) - / (1.0 - system.getBeta())); - system.getPhase(0).getComponents()[i].setK(system.getPhase(0).getComponents()[i].getx() - / system.getPhase(1).getComponents()[i].getx()); - system.getPhase(1).getComponents()[i] - .setK(system.getPhase(0).getComponents()[i].getK()); - } + for (int i = 0; i < numberOfComponents; i++) { + temp += u.get(i, 0); + } - system.init(3); + system.setBeta(temp); + for (int i = 0; i < numberOfComponents; i++) { + system.getPhase(0).getComponents()[i].setx(u.get(i, 0) / system.getBeta()); + system.getPhase(1).getComponents()[i].setx( + (system.getPhase(0).getComponents()[i].getz() - u.get(i, 0)) / (1.0 - system.getBeta())); + system.getPhase(0).getComponents()[i].setK(system.getPhase(0).getComponents()[i].getx() + / system.getPhase(1).getComponents()[i].getx()); + system.getPhase(1).getComponents()[i].setK(system.getPhase(0).getComponents()[i].getK()); } - /** - *- * solve. - *
- * - * @return a double - * @throws java.lang.Exception if any. - */ - public double solve() throws Exception { - try { - iter++; - init(); - setfvec(); - setJac(); - dx = Jac.solve(fvec); - // dx.print(10,10); - u.minusEquals(dx); - return (dx.norm2() / u.norm2()); - } catch (Exception e) { - throw e; - } + system.init(3); + } + + /** + *+ * solve. + *
+ * + * @return a double + * @throws java.lang.Exception if any. + */ + public double solve() throws Exception { + try { + iter++; + init(); + setfvec(); + setJac(); + dx = Jac.solve(fvec); + // dx.print(10,10); + u.minusEquals(dx); + return (dx.norm2() / u.norm2()); + } catch (Exception e) { + throw e; } + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java index d6a116ea16..f65e1ba130 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java @@ -25,830 +25,825 @@ * @version $Id: $Id */ public class pTphaseEnvelope extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(pTphaseEnvelope.class); - - double maxPressure = 1000.0; - double minPressure = 1.0; - double[][] copiedPoints = null; - graph2b graph2 = null; - SystemInterface system; - boolean bubblePointFirst = true; - boolean hascopiedPoints = false; - double[] cricondenTherm = new double[3]; - double[] cricondenBar = new double[3]; - double[] cricondenThermX = new double[100]; - double[] cricondenThermY = new double[100]; - double[] cricondenBarX = new double[100]; - double[] cricondenBarY = new double[100]; - double phaseFraction = 1e-10; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; - double lnOldOldK[], lnK[]; - boolean outputToFile = false; - double lnOldK[]; - double lnKwil[]; - double oldDeltalnK[], deltalnK[]; - double tm[] = {1, 1}; - double beta = 1e-5; - int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase - JProgressBar monitor; - JFrame mainFrame; - String fileName = "c:/file"; - JPanel mainPanel; - double temp = 0, pres = 0, startPres = 0; - double[][] points = new double[2][]; - double[] pointsH; - double[][] pointsH2 = new double[4][]; - double[] pointsV; - double[][] pointsV2 = new double[4][]; - double[] pointsS; - double[][] pointsS2 = new double[4][]; - public double[][] points2 = new double[4][]; - double[][] points3 = new double[8][]; - boolean moreLines = false; - boolean restart = true; - int np = 0; - // points[2] = new double[1000]; - int speceq = 0; - String[] navn = {"bubble point", "dew point", "bubble point", "dew point", "dew points"}; - int npfirst; - int ncrfirst; - double Tcfirst; - double Pcfirst; - double Tmin = 0.0; - - double[] cricondenThermfirst = new double[3]; - double[] cricondenBarfirst = new double[3]; - double[] cricondenThermXfirst = new double[100]; - double[] cricondenThermYfirst = new double[100]; - double[] cricondenBarXfirst = new double[100]; - double[] cricondenBarYfirst = new double[100]; - - /** - *- * Constructor for pTphaseEnvelope. - *
- */ - public pTphaseEnvelope() {} - - /** - *- * Constructor for pTphaseEnvelope. - *
- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param name a {@link java.lang.String} object - * @param phaseFraction a double - * @param lowPres a double - * @param bubfirst a boolean - */ - public pTphaseEnvelope(SystemInterface system, String name, double phaseFraction, - double lowPres, boolean bubfirst) { - this.bubblePointFirst = bubfirst; - if (name != null) { - outputToFile = true; - fileName = name; - } - this.system = system; - this.phaseFraction = phaseFraction; - lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnK = new double[system.getPhase(0).getNumberOfComponents()]; - this.lowPres = lowPres; - oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; - deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(pTphaseEnvelope.class); + + double maxPressure = 1000.0; + double minPressure = 1.0; + double[][] copiedPoints = null; + graph2b graph2 = null; + SystemInterface system; + boolean bubblePointFirst = true; + boolean hascopiedPoints = false; + double[] cricondenTherm = new double[3]; + double[] cricondenBar = new double[3]; + double[] cricondenThermX = new double[100]; + double[] cricondenThermY = new double[100]; + double[] cricondenBarX = new double[100]; + double[] cricondenBarY = new double[100]; + double phaseFraction = 1e-10; + int i; + int j = 0; + int nummer = 0; + int iterations = 0; + int maxNumberOfIterations = 10000; + double gibbsEnergy = 0; + double gibbsEnergyOld = 0; + double Kold; + double deviation = 0; + double g0 = 0; + double g1 = 0; + double lowPres = 1.0; + double[] lnOldOldK; + double[] lnK; + boolean outputToFile = false; + double[] lnOldK; + double[] lnKwil; + double[] oldDeltalnK; + double[] deltalnK; + double[] tm = {1, 1}; + double beta = 1e-5; + int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase + JProgressBar monitor; + JFrame mainFrame; + String fileName = "c:/file"; + JPanel mainPanel; + double temp = 0; + double pres = 0; + double startPres = 0; + double[][] points = new double[2][]; + double[] pointsH; + double[][] pointsH2 = new double[4][]; + double[] pointsV; + double[][] pointsV2 = new double[4][]; + double[] pointsS; + double[][] pointsS2 = new double[4][]; + public double[][] points2 = new double[4][]; + double[][] points3 = new double[8][]; + boolean moreLines = false; + boolean restart = true; + int np = 0; + // points[2] = new double[1000]; + int speceq = 0; + String[] navn = {"bubble point", "dew point", "bubble point", "dew point", "dew points"}; + int npfirst; + int ncrfirst; + double Tcfirst; + double Pcfirst; + double Tmin = 0.0; + + double[] cricondenThermfirst = new double[3]; + double[] cricondenBarfirst = new double[3]; + double[] cricondenThermXfirst = new double[100]; + double[] cricondenThermYfirst = new double[100]; + double[] cricondenBarXfirst = new double[100]; + double[] cricondenBarYfirst = new double[100]; + + /** + *+ * Constructor for pTphaseEnvelope. + *
+ */ + public pTphaseEnvelope() {} + + /** + *+ * Constructor for pTphaseEnvelope. + *
+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param name a {@link java.lang.String} object + * @param phaseFraction a double + * @param lowPres a double + * @param bubfirst a boolean + */ + public pTphaseEnvelope(SystemInterface system, String name, double phaseFraction, double lowPres, + boolean bubfirst) { + this.bubblePointFirst = bubfirst; + if (name != null) { + outputToFile = true; + fileName = name; } - - /** {@inheritDoc} */ - @Override - public void run() { - speceq = 0; // initialization + this.system = system; + this.phaseFraction = phaseFraction; + lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnK = new double[system.getPhase(0).getNumberOfComponents()]; + this.lowPres = lowPres; + oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + } + + /** {@inheritDoc} */ + @Override + public void run() { + speceq = 0; // initialization + try { + points[0] = new double[10000]; // declarations for points + points[1] = new double[10000]; // declarations for points + + pointsH = new double[10000]; // declarations for points + pointsV = new double[10000]; // declarations for points + pointsS = new double[10000]; // declarations for points + system.init(0); // initialization + + // selects the most volatile and least volatile component based on Tc values + // afterwards it uses them to define the speceq of the first point + // based on the desired first point, dew/bubble + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + if (system.getComponent(i).getz() < 1e-10) { + continue; + } + if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { + if (bubblePointFirst == true && system.getPhase(0).getComponents()[speceq] + .getTC() > system.getPhase(0).getComponents()[i].getTC()) { + speceq = system.getPhase(0).getComponent(i).getComponentNumber(); + } + if (bubblePointFirst == false && system.getPhase(0).getComponents()[speceq] + .getTC() < system.getPhase(0).getComponents()[i].getTC()) { + speceq = system.getPhase(0).getComponent(i).getComponentNumber(); + } + } + } + + // initialized the first step of the phase envelope + // pressure is already defined + // temperature is the antoine vapor pressure of the selected component + // (least or most volatile. + pres = lowPres; + // temp = + // system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); + temp = tempKWilson(phaseFraction, pres); + + if (Double.isNaN(temp)) { + temp = system.getPhase(0).getComponent(speceq).getTC() - 20.0; + } + system.setTemperature(temp); + system.setPressure(pres); + + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + + // this part converges the first phase envelope point. + // if the plasefraction is more than 0.5 it does a dew point initiallization + // else a bubble point initiallization + + for (int i = 0; i < 5; i++) { try { - points[0] = new double[10000]; // declarations for points - points[1] = new double[10000]; // declarations for points - - pointsH = new double[10000]; // declarations for points - pointsV = new double[10000]; // declarations for points - pointsS = new double[10000]; // declarations for points - system.init(0); // initialization - - // selects the most volatile and least volatile component based on Tc values - // afterwards it uses them to define the speceq of the first point - // based on the desired first point, dew/bubble - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - if (system.getComponent(i).getz() < 1e-10) { - continue; - } - if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { - if (bubblePointFirst == true && system.getPhase(0).getComponents()[speceq] - .getTC() > system.getPhase(0).getComponents()[i].getTC()) { - speceq = system.getPhase(0).getComponent(i).getComponentNumber(); - } - if (bubblePointFirst == false && system.getPhase(0).getComponents()[speceq] - .getTC() < system.getPhase(0).getComponents()[i].getTC()) { - speceq = system.getPhase(0).getComponent(i).getComponentNumber(); - } - } - } - - // initialized the first step of the phase envelope - // pressure is already defined - // temperature is the antoine vapor pressure of the selected component - // (least or most volatile. - pres = lowPres; - // temp = - // system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); - temp = tempKWilson(phaseFraction, pres); - - if (Double.isNaN(temp)) { - temp = system.getPhase(0).getComponent(speceq).getTC() - 20.0; - } + if (phaseFraction < 0.5) { + temp += i * 2; system.setTemperature(temp); - system.setPressure(pres); - - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - - // this part converges the first phase envelope point. - // if the plasefraction is more than 0.5 it does a dew point initiallization - // else a bubble point initiallization - - for (int i = 0; i < 5; i++) { - try { - if (phaseFraction < 0.5) { - temp += i * 2; - system.setTemperature(temp); - testOps.bubblePointTemperatureFlash(); - } else { - temp += i * 2; - system.setTemperature(temp); - testOps.dewPointTemperatureFlash(); - } - } catch (Exception e) { - e.toString(); - } - double tempNy = system.getTemperature(); - - if (!Double.isNaN(tempNy)) { - temp = tempNy; - break; - } - } - - // this part sets the first envelope point into the system - system.setBeta(phaseFraction); - system.setPressure(pres); + testOps.bubblePointTemperatureFlash(); + } else { + temp += i * 2; system.setTemperature(temp); + testOps.dewPointTemperatureFlash(); + } + } catch (Exception e) { + // e.toString(); + } + double tempNy = system.getTemperature(); - sysNewtonRhapsonPhaseEnvelope nonLinSolver = new sysNewtonRhapsonPhaseEnvelope(system, - 2, system.getPhase(0).getNumberOfComponents()); - startPres = system.getPressure(); - nonLinSolver.setu(); - for (np = 1; np < 9980; np++) { - try { - // solves the np point of the envelope - nonLinSolver.calcInc(np); - nonLinSolver.solve(np); - - // this catches the exceptions - // double TT = system.getPhase(0).getTemperature(); - // double PP = system.getPhase(0).getPressure(); - } catch (Exception e0) { - // the envelope crushed. - // this part keeps the old values - // restarts the envelope from the other side - // and then stops - - if (restart) { - restart = false; - // keep values - Tmin = points[0][np - 2]; - npfirst = np - 1; - ncrfirst = nonLinSolver.getNpCrit(); - if (ncrfirst == 0) { - ncrfirst = npfirst; - } - Tcfirst = system.getTC(); - Pcfirst = system.getPC(); - - cricondenBarfirst = cricondenBar; - cricondenBarXfirst = cricondenBarX; - cricondenBarYfirst = cricondenBarY; - - cricondenThermfirst = cricondenTherm; - cricondenThermXfirst = cricondenThermX; - cricondenThermYfirst = cricondenThermY; - - hascopiedPoints = true; - copiedPoints = new double[5][np - 1]; - for (int i = 0; i < np - 1; i++) { - copiedPoints[0][i] = points[0][i]; - copiedPoints[1][i] = points[1][i]; - copiedPoints[2][i] = pointsH[i]; - copiedPoints[3][i] = pointsS[i]; - copiedPoints[4][i] = pointsV[i]; - } - - // new settings - phaseFraction = 1.0 - phaseFraction; - if (bubblePointFirst) { - bubblePointFirst = false; - } else { - bubblePointFirst = true; - } - run(); - /**/ - break; - } else { - np = np - 1; - break; - } - } - - // check for critical point - double Kvallc = system.getPhase(0).getComponent(nonLinSolver.lc).getx() - / system.getPhase(1).getComponent(nonLinSolver.lc).getx(); - double Kvalhc = system.getPhase(0).getComponent(nonLinSolver.hc).getx() - / system.getPhase(1).getComponent(nonLinSolver.hc).getx(); - // double densV = system.getPhase(0).getDensity(); - // double densL = system.getPhase(1).getDensity(); - - // System.out.println(np + " " + system.getTemperature() + " " + - // system.getPressure() + " " + densV + " " + densL ); - - if ((nonLinSolver.etterCP == false)) { - if (Kvallc < 1.05 && Kvalhc > 0.95) { - // close to the critical point - // invert phase types and find the CP Temp and Press - - // System.out.println("critical point"); - nonLinSolver.npCrit = np; - system.invertPhaseTypes(); - nonLinSolver.etterCP = true; - // the critical point is found from interpolation plynimials based on K=1 of - // the - // most or least volatile component - nonLinSolver.calcCrit(); - } - } - if (nonLinSolver.calcCP) { - nonLinSolver.calcCP = false; - nonLinSolver.npCrit = np; - nonLinSolver.calcCrit(); - } - - // stores critondenbar and cricondentherm - // HERE the new cricoT and crico P values will be called instead - if (system.getTemperature() > cricondenTherm[0]) { - cricondenTherm[1] = system.getPressure(); - cricondenTherm[0] = system.getTemperature(); - for (int ii = 0; ii < nonLinSolver.numberOfComponents; ii++) { - cricondenThermX[ii] = system.getPhase(1).getComponent(ii).getx(); - cricondenThermY[ii] = system.getPhase(0).getComponent(ii).getx(); - } - } else { - nonLinSolver.ettercricoT = true; - } - if (system.getPressure() > cricondenBar[1]) { - cricondenBar[0] = system.getTemperature(); - cricondenBar[1] = system.getPressure(); - for (int ii = 0; ii < nonLinSolver.numberOfComponents; ii++) { - cricondenBarX[ii] = system.getPhase(1).getComponent(ii).getx(); - cricondenBarY[ii] = system.getPhase(0).getComponent(ii).getx(); - } - } - - // Exit criteria - if ((system.getPressure() < minPressure && nonLinSolver.ettercricoT)) { - break; - } - if (system.getPressure() > maxPressure) { - break; - } - if (system.getTemperature() > Tmin && !restart) { - break; - } - - // Keeps the calculated points - points[0][np - 1] = system.getTemperature(); - points[1][np - 1] = system.getPressure(); - pointsH[np - 1] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV[np - 1] = system.getPhase(1).getDensity(); - pointsS[np - 1] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; + if (!Double.isNaN(tempNy)) { + temp = tempNy; + break; + } + } + + // this part sets the first envelope point into the system + system.setBeta(phaseFraction); + system.setPressure(pres); + system.setTemperature(temp); + + sysNewtonRhapsonPhaseEnvelope nonLinSolver = + new sysNewtonRhapsonPhaseEnvelope(system, 2, system.getPhase(0).getNumberOfComponents()); + startPres = system.getPressure(); + nonLinSolver.setu(); + for (np = 1; np < 9980; np++) { + try { + // solves the np point of the envelope + nonLinSolver.calcInc(np); + nonLinSolver.solve(np); + + // this catches the exceptions + // double TT = system.getPhase(0).getTemperature(); + // double PP = system.getPhase(0).getPressure(); + } catch (Exception e0) { + // the envelope crushed. + // this part keeps the old values + // restarts the envelope from the other side + // and then stops + + if (restart) { + restart = false; + // keep values + Tmin = points[0][np - 2]; + npfirst = np - 1; + ncrfirst = nonLinSolver.getNpCrit(); + if (ncrfirst == 0) { + ncrfirst = npfirst; } - - try { - int ncr = nonLinSolver.getNpCrit(); - if (ncr == 0) { - ncr = np; - } - int ncr2 = np - ncr; - if (hascopiedPoints) { - // if it enters here the envelope crashed and restarted - // reallocate to have all values - points2 = new double[8][]; - pointsH2 = new double[8][]; - pointsS2 = new double[8][]; - pointsV2 = new double[8][]; - } - - // points2 are plotted - points2[0] = new double[ncr + 1]; - points2[1] = new double[ncr + 1]; - pointsH2[0] = new double[ncr + 1]; - pointsH2[1] = new double[ncr + 1]; - pointsS2[0] = new double[ncr + 1]; - pointsS2[1] = new double[ncr + 1]; - pointsV2[0] = new double[ncr + 1]; - pointsV2[1] = new double[ncr + 1]; - - if (ncr2 > 2) { - points2[2] = new double[ncr2 - 2]; - points2[3] = new double[ncr2 - 2]; - pointsH2[2] = new double[ncr2 - 2]; - pointsH2[3] = new double[ncr2 - 2]; - pointsS2[2] = new double[ncr2 - 2]; - pointsS2[3] = new double[ncr2 - 2]; - pointsV2[2] = new double[ncr2 - 2]; - pointsV2[3] = new double[ncr2 - 2]; - } else { - points2[2] = new double[0]; - points2[3] = new double[0]; - pointsH2[2] = new double[0]; - pointsH2[3] = new double[0]; - pointsS2[2] = new double[0]; - pointsS2[3] = new double[0]; - pointsV2[2] = new double[0]; - pointsV2[3] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - // second branch up to critical point - points2[0][i] = points[0][i]; - points2[1][i] = points[1][i]; - pointsH2[1][i] = points[1][i]; - pointsH2[0][i] = pointsH[i]; - pointsS2[1][i] = points[1][i]; - pointsS2[0][i] = pointsS[i]; - pointsV2[1][i] = points[1][i]; - pointsV2[0][i] = pointsV[i]; - } - if (ncr2 > 2) { - for (int i = 1; i < (ncr2 - 2); i++) { - // second branch after the critical point - points2[2][i] = points[0][i + ncr - 1]; - points2[3][i] = points[1][i + ncr - 1]; - pointsH2[3][i] = points[1][i + ncr - 1]; - pointsH2[2][i] = pointsH[i + ncr - 1]; - pointsS2[3][i] = points[1][i + ncr - 1]; - pointsS2[2][i] = pointsS[i + ncr - 1]; - pointsV2[3][i] = points[1][i + ncr - 1]; - pointsV2[2][i] = pointsV[i + ncr - 1]; - } - } - - if (hascopiedPoints) { - if (ncrfirst > npfirst) { - ncr = copiedPoints[0].length - 1; - ncr2 = npfirst - ncr; - npfirst = npfirst - 1; - } else { - ncr = ncrfirst; - ncr2 = npfirst - ncr; - } - - points2[4] = new double[ncr + 1]; - points2[5] = new double[ncr + 1]; - pointsH2[4] = new double[ncr + 1]; - pointsH2[5] = new double[ncr + 1]; - pointsS2[4] = new double[ncr + 1]; - pointsS2[5] = new double[ncr + 1]; - pointsV2[4] = new double[ncr + 1]; - pointsV2[5] = new double[ncr + 1]; - - if (ncr2 > 2) { - points2[6] = new double[ncr2 - 2]; - points2[7] = new double[ncr2 - 2]; - pointsH2[6] = new double[ncr2 - 2]; - pointsH2[7] = new double[ncr2 - 2]; - pointsS2[6] = new double[ncr2 - 2]; - pointsS2[7] = new double[ncr2 - 2]; - pointsV2[6] = new double[ncr2 - 2]; - pointsV2[7] = new double[ncr2 - 2]; - } else { - points2[6] = new double[0]; - points2[7] = new double[0]; - pointsH2[6] = new double[0]; - pointsH2[7] = new double[0]; - pointsS2[6] = new double[0]; - pointsS2[7] = new double[0]; - pointsV2[6] = new double[0]; - pointsV2[7] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - // first branch up to the critical point - points2[4][i] = copiedPoints[0][i]; - points2[5][i] = copiedPoints[1][i]; - pointsH2[5][i] = copiedPoints[1][i]; - pointsH2[4][i] = copiedPoints[2][i]; - pointsS2[5][i] = copiedPoints[1][i]; - pointsS2[4][i] = copiedPoints[3][i]; - pointsV2[5][i] = copiedPoints[1][i]; - pointsV2[4][i] = copiedPoints[4][i]; - } - if (ncr2 > 2) { - for (int i = 1; i < (ncr2 - 2); i++) { - // first branch after the critical point - points2[6][i] = copiedPoints[0][i + ncr - 1]; - points2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsH2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsH2[6][i] = copiedPoints[2][i + ncr - 1]; - pointsS2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsS2[6][i] = copiedPoints[3][i + ncr - 1]; - pointsV2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsV2[6][i] = copiedPoints[4][i + ncr - 1]; - } - } - } - - // critical point - system.setTemperature(system.getTC()); - system.setPressure(system.getPC()); - - points2[0][ncr] = system.getTC(); - points2[1][ncr] = system.getPC(); - if (ncr2 > 2) { - points2[2][0] = system.getTC(); - points2[3][0] = system.getPC(); - } - } catch (Exception e2) { - // double nef = 0.; - // logger.error("error", e2); + Tcfirst = system.getTC(); + Pcfirst = system.getPC(); + + cricondenBarfirst = cricondenBar; + cricondenBarXfirst = cricondenBarX; + cricondenBarYfirst = cricondenBarY; + + cricondenThermfirst = cricondenTherm; + cricondenThermXfirst = cricondenThermX; + cricondenThermYfirst = cricondenThermY; + + hascopiedPoints = true; + copiedPoints = new double[5][np - 1]; + for (int i = 0; i < np - 1; i++) { + copiedPoints[0][i] = points[0][i]; + copiedPoints[1][i] = points[1][i]; + copiedPoints[2][i] = pointsH[i]; + copiedPoints[3][i] = pointsS[i]; + copiedPoints[4][i] = pointsV[i]; } -/* - try { - if (outputToFile) { - // update this - String name1 = new String(); - name1 = fileName + "Dew.nc"; - file1 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file1.setOutputFileName(name1); - file1.setXvalues(points2[2], "temp", "sec"); - file1.setYvalues(points2[3], "pres", "meter"); - file1.createFile(); - - String name2 = new String(); - name2 = fileName + "Bub.nc"; - file2 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file2.setOutputFileName(name2); - file2.setXvalues(points2[0], "temp", "sec"); - file2.setYvalues(points2[1], "pres", "meter"); - file2.createFile(); - } - } catch (Exception e3) { - // double nef = 0.; - logger.error("error", e3); + + // new settings + phaseFraction = 1.0 - phaseFraction; + if (bubblePointFirst) { + bubblePointFirst = false; + } else { + bubblePointFirst = true; } - */ - } catch (Exception e4) { - // double nef = 0.; - logger.error("error", e4); + run(); + /**/ + break; + } else { + np = np - 1; + break; + } } - } - /** - *- * calcHydrateLine. - *
- */ - public void calcHydrateLine() { - ThermodynamicOperations opsHyd = new ThermodynamicOperations(system); - try { - opsHyd.hydrateEquilibriumLine(10.0, 300.0); - } catch (Exception e) { - logger.error("error", e); + // check for critical point + double Kvallc = system.getPhase(0).getComponent(nonLinSolver.lc).getx() + / system.getPhase(1).getComponent(nonLinSolver.lc).getx(); + double Kvalhc = system.getPhase(0).getComponent(nonLinSolver.hc).getx() + / system.getPhase(1).getComponent(nonLinSolver.hc).getx(); + // double densV = system.getPhase(0).getDensity(); + // double densL = system.getPhase(1).getDensity(); + + // System.out.println(np + " " + system.getTemperature() + " " + + // system.getPressure() + " " + densV + " " + densL ); + + if ((nonLinSolver.etterCP == false)) { + if (Kvallc < 1.05 && Kvalhc > 0.95) { + // close to the critical point + // invert phase types and find the CP Temp and Press + + // System.out.println("critical point"); + nonLinSolver.npCrit = np; + system.invertPhaseTypes(); + nonLinSolver.etterCP = true; + // the critical point is found from interpolation plynimials based on K=1 of + // the + // most or least volatile component + nonLinSolver.calcCrit(); + } } - - // double[][] hydData = opsHyd.getData(); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - if (bubblePointFirst) { - // bubble point side - navn[0] = "bubble point 2"; - navn[1] = "dew point 2"; - navn[2] = "dew point 1"; - navn[3] = "bubble point 1"; - } else { - // dew point side and does not crash - navn[0] = "dew point 2"; - navn[1] = "bubble point 2"; - navn[2] = "dew point 1"; - navn[3] = "bubbl point 1"; + if (nonLinSolver.calcCP) { + nonLinSolver.calcCP = false; + nonLinSolver.npCrit = np; + nonLinSolver.calcCrit(); } - double TC = system.getTC(); - double PC = system.getPC(); - - String title = "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title3 = "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title5 = "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - - graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); - graph3.setVisible(true); - // graph3.saveFigure(new String(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig4.png")); - - graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); - graph4.setVisible(true); - // graph4.saveFigure(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig2.png"); - - graph2b graph5 = - new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); - graph5.setVisible(true); - // graph5.saveFigure(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig3.png"); - - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - graph2.setVisible(true); - // graph2.saveFigure(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig1.png"); - - /* - * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); - * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = - * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); - */ - } - - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} - - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - if (bubblePointFirst) { - // bubble point side - navn[0] = "bubble point 2"; - navn[1] = "dew point 2"; - navn[2] = "dew point 1"; - navn[3] = "bubble point 1"; + // stores critondenbar and cricondentherm + // HERE the new cricoT and crico P values will be called instead + if (system.getTemperature() > cricondenTherm[0]) { + cricondenTherm[1] = system.getPressure(); + cricondenTherm[0] = system.getTemperature(); + for (int ii = 0; ii < nonLinSolver.numberOfComponents; ii++) { + cricondenThermX[ii] = system.getPhase(1).getComponent(ii).getx(); + cricondenThermY[ii] = system.getPhase(0).getComponent(ii).getx(); + } } else { - // dew point side and does not crash - navn[0] = "dew point"; - navn[1] = "bubble point"; - navn[2] = "dew point"; - navn[3] = "bubbl point"; - } - - double TC = system.getTC(); - double PC = system.getPC(); - - String title = "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - return graph2.getChart(); - } - - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points2; - } - - /** {@inheritDoc} */ - @Override - public void addData(String name, double[][] data) { - double[][] localPoints = new double[points2.length + data.length][]; - navn[localPoints.length / 2 - 1] = name; - System.arraycopy(points2, 0, localPoints, 0, points2.length); - System.arraycopy(data, 0, localPoints, points2.length, data.length); - points2 = localPoints; - } - - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - if (name.equals("dewT")) { - return points2[0]; - } - if (name.equals("dewP")) { - return points2[1]; - } - if (name.equals("bubT")) { - return points2[2]; - } - if (name.equals("bubP")) { - return points2[3]; - } - // return points2[3]; - if (name.equals("dewT2")) { - return points2[4]; - } - if (name.equals("dewP2")) { - return points2[5]; - } - if (name.equals("bubT2")) { - return points2[6]; - } - if (name.equals("bubP2")) { - return points2[7]; - } - if (name.equals("dewH")) { - return pointsH2[2]; + nonLinSolver.ettercricoT = true; } - if (name.equals("dewDens")) { - return pointsV2[2]; + if (system.getPressure() > cricondenBar[1]) { + cricondenBar[0] = system.getTemperature(); + cricondenBar[1] = system.getPressure(); + for (int ii = 0; ii < nonLinSolver.numberOfComponents; ii++) { + cricondenBarX[ii] = system.getPhase(1).getComponent(ii).getx(); + cricondenBarY[ii] = system.getPhase(0).getComponent(ii).getx(); + } } - if (name.equals("dewS")) { - return pointsS2[2]; - } - if (name.equals("bubH")) { - return pointsH2[0]; - } - if (name.equals("bubDens")) { - return pointsV2[0]; + + // Exit criteria + if ((system.getPressure() < minPressure && nonLinSolver.ettercricoT)) { + break; } - if (name.equals("bubS")) { - return pointsS2[0]; + if (system.getPressure() > maxPressure) { + break; } - if (name.equals("cricondentherm")) { - return cricondenTherm; + if (system.getTemperature() > Tmin && !restart) { + break; } - if (name.equals("cricondenthermX")) { - return cricondenThermX; + + // Keeps the calculated points + points[0][np - 1] = system.getTemperature(); + points[1][np - 1] = system.getPressure(); + pointsH[np - 1] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV[np - 1] = system.getPhase(1).getDensity(); + pointsS[np - 1] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + } + + try { + int ncr = nonLinSolver.getNpCrit(); + if (ncr == 0) { + ncr = np; } - if (name.equals("cricondenthermY")) { - return cricondenThermY; + int ncr2 = np - ncr; + if (hascopiedPoints) { + // if it enters here the envelope crashed and restarted + // reallocate to have all values + points2 = new double[8][]; + pointsH2 = new double[8][]; + pointsS2 = new double[8][]; + pointsV2 = new double[8][]; } - if (name.equals("cricondenbar")) { - return cricondenBar; + + // points2 are plotted + points2[0] = new double[ncr + 1]; + points2[1] = new double[ncr + 1]; + pointsH2[0] = new double[ncr + 1]; + pointsH2[1] = new double[ncr + 1]; + pointsS2[0] = new double[ncr + 1]; + pointsS2[1] = new double[ncr + 1]; + pointsV2[0] = new double[ncr + 1]; + pointsV2[1] = new double[ncr + 1]; + + if (ncr2 > 2) { + points2[2] = new double[ncr2 - 2]; + points2[3] = new double[ncr2 - 2]; + pointsH2[2] = new double[ncr2 - 2]; + pointsH2[3] = new double[ncr2 - 2]; + pointsS2[2] = new double[ncr2 - 2]; + pointsS2[3] = new double[ncr2 - 2]; + pointsV2[2] = new double[ncr2 - 2]; + pointsV2[3] = new double[ncr2 - 2]; + } else { + points2[2] = new double[0]; + points2[3] = new double[0]; + pointsH2[2] = new double[0]; + pointsH2[3] = new double[0]; + pointsS2[2] = new double[0]; + pointsS2[3] = new double[0]; + pointsV2[2] = new double[0]; + pointsV2[3] = new double[0]; } - if (name.equals("cricondenbarX")) { - return cricondenBarX; + + for (int i = 0; i < ncr; i++) { + // second branch up to critical point + points2[0][i] = points[0][i]; + points2[1][i] = points[1][i]; + pointsH2[1][i] = points[1][i]; + pointsH2[0][i] = pointsH[i]; + pointsS2[1][i] = points[1][i]; + pointsS2[0][i] = pointsS[i]; + pointsV2[1][i] = points[1][i]; + pointsV2[0][i] = pointsV[i]; } - if (name.equals("cricondenbarY")) { - return cricondenBarY; + if (ncr2 > 2) { + for (int i = 1; i < (ncr2 - 2); i++) { + // second branch after the critical point + points2[2][i] = points[0][i + ncr - 1]; + points2[3][i] = points[1][i + ncr - 1]; + pointsH2[3][i] = points[1][i + ncr - 1]; + pointsH2[2][i] = pointsH[i + ncr - 1]; + pointsS2[3][i] = points[1][i + ncr - 1]; + pointsS2[2][i] = pointsS[i + ncr - 1]; + pointsV2[3][i] = points[1][i + ncr - 1]; + pointsV2[2][i] = pointsV[i + ncr - 1]; + } } - if (name.equals("criticalPoint1")) { - return new double[] {system.getTC(), system.getPC()}; + + if (hascopiedPoints) { + if (ncrfirst > npfirst) { + ncr = copiedPoints[0].length - 1; + ncr2 = npfirst - ncr; + npfirst = npfirst - 1; + } else { + ncr = ncrfirst; + ncr2 = npfirst - ncr; + } + + points2[4] = new double[ncr + 1]; + points2[5] = new double[ncr + 1]; + pointsH2[4] = new double[ncr + 1]; + pointsH2[5] = new double[ncr + 1]; + pointsS2[4] = new double[ncr + 1]; + pointsS2[5] = new double[ncr + 1]; + pointsV2[4] = new double[ncr + 1]; + pointsV2[5] = new double[ncr + 1]; + + if (ncr2 > 2) { + points2[6] = new double[ncr2 - 2]; + points2[7] = new double[ncr2 - 2]; + pointsH2[6] = new double[ncr2 - 2]; + pointsH2[7] = new double[ncr2 - 2]; + pointsS2[6] = new double[ncr2 - 2]; + pointsS2[7] = new double[ncr2 - 2]; + pointsV2[6] = new double[ncr2 - 2]; + pointsV2[7] = new double[ncr2 - 2]; + } else { + points2[6] = new double[0]; + points2[7] = new double[0]; + pointsH2[6] = new double[0]; + pointsH2[7] = new double[0]; + pointsS2[6] = new double[0]; + pointsS2[7] = new double[0]; + pointsV2[6] = new double[0]; + pointsV2[7] = new double[0]; + } + + for (int i = 0; i < ncr; i++) { + // first branch up to the critical point + points2[4][i] = copiedPoints[0][i]; + points2[5][i] = copiedPoints[1][i]; + pointsH2[5][i] = copiedPoints[1][i]; + pointsH2[4][i] = copiedPoints[2][i]; + pointsS2[5][i] = copiedPoints[1][i]; + pointsS2[4][i] = copiedPoints[3][i]; + pointsV2[5][i] = copiedPoints[1][i]; + pointsV2[4][i] = copiedPoints[4][i]; + } + if (ncr2 > 2) { + for (int i = 1; i < (ncr2 - 2); i++) { + // first branch after the critical point + points2[6][i] = copiedPoints[0][i + ncr - 1]; + points2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsH2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsH2[6][i] = copiedPoints[2][i + ncr - 1]; + pointsS2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsS2[6][i] = copiedPoints[3][i + ncr - 1]; + pointsV2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsV2[6][i] = copiedPoints[4][i + ncr - 1]; + } + } } - if (name.equals("criticalPoint2")) { - return new double[] {0, 0}; - } else { - return null; + + // critical point + system.setTemperature(system.getTC()); + system.setPressure(system.getPC()); + + points2[0][ncr] = system.getTC(); + points2[1][ncr] = system.getPC(); + if (ncr2 > 2) { + points2[2][0] = system.getTC(); + points2[3][0] = system.getPC(); } + } catch (Exception e2) { + } + /* + * try { if (outputToFile) { // update this String name1 = new String(); name1 = fileName + + * "Dew.nc"; file1 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file1.setOutputFileName(name1); file1.setXvalues(points2[2], "temp", "sec"); + * file1.setYvalues(points2[3], "pres", "meter"); file1.createFile(); + * + * String name2 = new String(); name2 = fileName + "Bub.nc"; file2 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file2.setOutputFileName(name2); file2.setXvalues(points2[0], "temp", "sec"); + * file2.setYvalues(points2[1], "pres", "meter"); file2.createFile(); } } catch (Exception e3) + * { logger.error("error", e3); } + */ + } catch (Exception e4) { + logger.error("error", e4); + } + } + + /** + *+ * calcHydrateLine. + *
+ */ + public void calcHydrateLine() { + ThermodynamicOperations opsHyd = new ThermodynamicOperations(system); + try { + opsHyd.hydrateEquilibriumLine(10.0, 300.0); + } catch (Exception e) { + logger.error("error", e); } - /** - * Getter for property bubblePointFirst. - * - * @return Value of property bubblePointFirst. - */ - public boolean isBubblePointFirst() { - return bubblePointFirst; + // double[][] hydData = opsHyd.getData(); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + if (bubblePointFirst) { + // bubble point side + navn[0] = "bubble point 2"; + navn[1] = "dew point 2"; + navn[2] = "dew point 1"; + navn[3] = "bubble point 1"; + } else { + // dew point side and does not crash + navn[0] = "dew point 2"; + navn[1] = "bubble point 2"; + navn[2] = "dew point 1"; + navn[3] = "bubbl point 1"; } - /** - * Setter for property bubblePointFirst. - * - * @param bubblePointFirst New value of property bubblePointFirst. + double TC = system.getTC(); + double PC = system.getPC(); + + String title = + "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title3 = + "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + + String.valueOf(nf.format(PC)); + String title5 = + "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + + graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); + graph3.setVisible(true); + // graph3.saveFigure(new String(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig4.png")); + + graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); + graph4.setVisible(true); + // graph4.saveFigure(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig2.png"); + + graph2b graph5 = new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); + graph5.setVisible(true); + // graph5.saveFigure(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig3.png"); + + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + graph2.setVisible(true); + // graph2.saveFigure(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig1.png"); + + /* + * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); + * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = + * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); */ - public void setBubblePointFirst(boolean bubblePointFirst) { - this.bubblePointFirst = bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + if (bubblePointFirst) { + // bubble point side + navn[0] = "bubble point 2"; + navn[1] = "dew point 2"; + navn[2] = "dew point 1"; + navn[3] = "bubble point 1"; + } else { + // dew point side and does not crash + navn[0] = "dew point"; + navn[1] = "bubble point"; + navn[2] = "dew point"; + navn[3] = "bubbl point"; } - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; + double TC = system.getTC(); + double PC = system.getPC(); + + String title = + "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + return graph2.getChart(); + } + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points2; + } + + /** {@inheritDoc} */ + @Override + public void addData(String name, double[][] data) { + double[][] localPoints = new double[points2.length + data.length][]; + navn[localPoints.length / 2 - 1] = name; + System.arraycopy(points2, 0, localPoints, 0, points2.length); + System.arraycopy(data, 0, localPoints, points2.length, data.length); + points2 = localPoints; + } + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + if (name.equals("dewT")) { + return points2[0]; + } + if (name.equals("dewP")) { + return points2[1]; + } + if (name.equals("bubT")) { + return points2[2]; + } + if (name.equals("bubP")) { + return points2[3]; + } + // return points2[3]; + if (name.equals("dewT2")) { + return points2[4]; + } + if (name.equals("dewP2")) { + return points2[5]; + } + if (name.equals("bubT2")) { + return points2[6]; + } + if (name.equals("bubP2")) { + return points2[7]; + } + if (name.equals("dewH")) { + return pointsH2[2]; + } + if (name.equals("dewDens")) { + return pointsV2[2]; + } + if (name.equals("dewS")) { + return pointsS2[2]; + } + if (name.equals("bubH")) { + return pointsH2[0]; + } + if (name.equals("bubDens")) { + return pointsV2[0]; + } + if (name.equals("bubS")) { + return pointsS2[0]; + } + if (name.equals("cricondentherm")) { + return cricondenTherm; + } + if (name.equals("cricondenthermX")) { + return cricondenThermX; + } + if (name.equals("cricondenthermY")) { + return cricondenThermY; + } + if (name.equals("cricondenbar")) { + return cricondenBar; + } + if (name.equals("cricondenbarX")) { + return cricondenBarX; + } + if (name.equals("cricondenbarY")) { + return cricondenBarY; + } + if (name.equals("criticalPoint1")) { + return new double[] {system.getTC(), system.getPC()}; + } + if (name.equals("criticalPoint2")) { + return new double[] {0, 0}; + } else { + return null; + } + } + + /** + * Getter for property bubblePointFirst. + * + * @return Value of property bubblePointFirst. + */ + public boolean isBubblePointFirst() { + return bubblePointFirst; + } + + /** + * Setter for property bubblePointFirst. + * + * @param bubblePointFirst New value of property bubblePointFirst. + */ + public void setBubblePointFirst(boolean bubblePointFirst) { + this.bubblePointFirst = bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } + + /** + *+ * tempKWilson. + *
+ * + * @param beta a double + * @param P a double + * @return a double + */ + public double tempKWilson(double beta, double P) { + // Initiallizes the temperature of a saturation point for given pressure + // based on K values of Wilson + // see Michelsen book thermodynamics & computational aspects + + double initTc = 0.; + double initPc = 0.; + double initAc = 0.; + double Tstart = 0.; + double Tstartold = 0.; + double initT = 0; + double dinitT = 0; + int numberOfComponents = system.getPhase(0).getNumberOfComponents(); + int lc = 0; + int hc = 0; + + double[] Kwil = new double[numberOfComponents]; + + double min = 100000.; + double max = 0.; + + for (int i = 0; i < numberOfComponents; i++) { + if (system.getPhase(0).getComponents()[i].getTC() > max) { + max = system.getPhase(0).getComponents()[i].getTC(); + hc = i; + } + if (system.getPhase(0).getComponents()[i].getTC() < min) { + min = system.getPhase(0).getComponents()[i].getTC(); + lc = i; + } } - /** - *- * tempKWilson. - *
- * - * @param beta a double - * @param P a double - * @return a double - */ - public double tempKWilson(double beta, double P) { - // Initiallizes the temperature of a saturation point for given pressure - // based on K values of Wilson - // see Michelsen book thermodynamics & computational aspects - - double initTc = 0.; - double initPc = 0.; - double initAc = 0.; - double Tstart = 0.; - double Tstartold = 0.; - double initT = 0; - double dinitT = 0; - int numberOfComponents = system.getPhase(0).getNumberOfComponents(); - int lc = 0; - int hc = 0; - - double[] Kwil = new double[numberOfComponents]; - - double min = 100000.; - double max = 0.; - - for (int i = 0; i < numberOfComponents; i++) { - if (system.getPhase(0).getComponents()[i].getTC() > max) { - max = system.getPhase(0).getComponents()[i].getTC(); - hc = i; - } - if (system.getPhase(0).getComponents()[i].getTC() < min) { - min = system.getPhase(0).getComponents()[i].getTC(); - lc = i; - } + try { + if (beta <= 0.5) { + initTc = system.getPhase(0).getComponents()[lc].getTC(); // closer to bubble point + // get the lightest + // component + initPc = system.getPhase(0).getComponents()[lc].getPC(); + initAc = system.getPhase(0).getComponents()[lc].getAcentricFactor(); + } else if (beta > 0.5) { + initTc = system.getPhase(0).getComponents()[hc].getTC(); // closer to dew point get + // the heaviest + // component + initPc = system.getPhase(0).getComponents()[hc].getPC(); + initAc = system.getPhase(0).getComponents()[hc].getAcentricFactor(); + } + + // initial T based on the lightest/heaviest component + Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); + + // solve for Tstart with Newton + for (int i = 0; i < 1000; i++) { + initT = 0.; + dinitT = 0.; + for (int j = 0; j < numberOfComponents; j++) { + Kwil[j] = system.getPhase(0).getComponents()[j].getPC() / P + * Math.exp(5.373 * (1. + system.getPhase(0).getComponents()[j].getAcentricFactor()) + * (1. - system.getPhase(0).getComponents()[j].getTC() / Tstart)); + // system.getPhases()[0].getComponents()[j].setK(Kwil[j]); } - try { - if (beta <= 0.5) { - initTc = system.getPhase(0).getComponents()[lc].getTC(); // closer to bubble point - // get the lightest - // component - initPc = system.getPhase(0).getComponents()[lc].getPC(); - initAc = system.getPhase(0).getComponents()[lc].getAcentricFactor(); - } else if (beta > 0.5) { - initTc = system.getPhase(0).getComponents()[hc].getTC(); // closer to dew point get - // the heaviest - // component - initPc = system.getPhase(0).getComponents()[hc].getPC(); - initAc = system.getPhase(0).getComponents()[hc].getAcentricFactor(); - } + for (int j = 0; j < numberOfComponents; j++) { + if (beta < 0.5) { + initT = initT + system.getPhase(0).getComponents()[j].getz() * Kwil[j]; + dinitT = dinitT + system.getPhase(0).getComponents()[j].getz() * Kwil[j] * 5.373 + * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) + * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); + } else { + initT = initT + system.getPhase(0).getComponents()[j].getz() / Kwil[j]; + dinitT = dinitT - system.getPhase(0).getComponents()[j].getz() / Kwil[j] * 5.373 + * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) + * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); + } + } - // initial T based on the lightest/heaviest component - Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); - - // solve for Tstart with Newton - for (int i = 0; i < 1000; i++) { - initT = 0.; - dinitT = 0.; - for (int j = 0; j < numberOfComponents; j++) { - Kwil[j] = system.getPhase(0).getComponents()[j].getPC() / P * Math.exp(5.373 - * (1. + system.getPhase(0).getComponents()[j].getAcentricFactor()) - * (1. - system.getPhase(0).getComponents()[j].getTC() / Tstart)); - // system.getPhases()[0].getComponents()[j].setK(Kwil[j]); - } - - for (int j = 0; j < numberOfComponents; j++) { - if (beta < 0.5) { - initT = initT + system.getPhase(0).getComponents()[j].getz() * Kwil[j]; - dinitT = dinitT + system.getPhase(0).getComponents()[j].getz() * Kwil[j] - * 5.373 - * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) - * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); - } else { - initT = initT + system.getPhase(0).getComponents()[j].getz() / Kwil[j]; - dinitT = dinitT - system.getPhase(0).getComponents()[j].getz() / Kwil[j] - * 5.373 - * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) - * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); - } - } - - initT = initT - 1.; - if (Math.abs(initT / dinitT) > 0.1 * Tstart) { - Tstart = Tstart - 0.001 * initT / dinitT; - } else { - Tstart = Tstart - initT / dinitT; - } - if (Math.abs(Tstart - Tstartold) < 1.e-5) { - return Tstart; - } - Tstartold = Tstart; - } - } catch (Exception e) { - Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); + initT = initT - 1.; + if (Math.abs(initT / dinitT) > 0.1 * Tstart) { + Tstart = Tstart - 0.001 * initT / dinitT; + } else { + Tstart = Tstart - initT / dinitT; } - if (Double.isNaN(Tstart) || Double.isInfinite(Tstart)) { - Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); + if (Math.abs(Tstart - Tstartold) < 1.e-5) { + return Tstart; } - return Tstart; + Tstartold = Tstart; + } + } catch (Exception e) { + Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); + } + if (Double.isNaN(Tstart) || Double.isInfinite(Tstart)) { + Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); } + return Tstart; + } } diff --git a/src/main/java/neqsim/util/database/AspenIP21Database.java b/src/main/java/neqsim/util/database/AspenIP21Database.java index cd0e4755cc..906be04a7d 100644 --- a/src/main/java/neqsim/util/database/AspenIP21Database.java +++ b/src/main/java/neqsim/util/database/AspenIP21Database.java @@ -15,142 +15,138 @@ * @version $Id: $Id */ public class AspenIP21Database - implements neqsim.util.util.FileSystemSettings, java.io.Serializable { - private static final long serialVersionUID = 1000; + implements neqsim.util.util.FileSystemSettings, java.io.Serializable { + private static final long serialVersionUID = 1000; - protected Connection databaseConnection = null; - private static String dataBaseType = "Karsto"; - private Statement statement = null; + protected Connection databaseConnection = null; + private static String dataBaseType = "Karsto"; + private Statement statement = null; - /** - *- * Constructor for AspenIP21Database. - *
- */ - public AspenIP21Database() { - try { - if (dataBaseType.equals("Karsto")) { - Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").getDeclaredConstructor() - .newInstance(); - } - } catch (Exception ex) { - System.out.println("error in Online Karsto " + ex.toString()); - System.out.println("The database must be registered on the local DBMS to work."); - } - - try { - databaseConnection = this.openConnection("Karsto"); - setStatement(databaseConnection.createStatement()); - } catch (Exception ex) { - System.out.println("SQLException " + ex.getMessage()); - } + /** + *+ * Constructor for AspenIP21Database. + *
+ */ + public AspenIP21Database() { + try { + if (dataBaseType.equals("Karsto")) { + Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").getDeclaredConstructor().newInstance(); + } + } catch (Exception ex) { + System.out.println("error in Online Karsto " + ex.toString()); + System.out.println("The database must be registered on the local DBMS to work."); } - /** - *- * openConnection. - *
- * - * @param database a {@link java.lang.String} object - * @return a Connection object - * @throws java.sql.SQLException if any. - * @throws java.lang.ClassNotFoundException if any. - */ - public Connection openConnection(String database) throws SQLException, ClassNotFoundException { - javax.naming.InitialContext ctx = null; - // javax.sql.DataSource ds = null; + try { + databaseConnection = this.openConnection("Karsto"); + setStatement(databaseConnection.createStatement()); + } catch (Exception ex) { + System.out.println("SQLException " + ex.getMessage()); + } + } - try { - return DriverManager.getConnection("....."); - } catch (Exception ex) { - System.out.println("SQLException " + ex.getMessage()); - System.out.println("error in Kaarsto DB " + ex.toString()); - System.out - .println("The Kaarsto database must be registered on the local DBMS to work."); - } finally { - try { - if (ctx != null) { - ctx.close(); - } - } catch (Exception e) { - e.printStackTrace(); - } + /** + *+ * openConnection. + *
+ * + * @param database a {@link java.lang.String} object + * @return a Connection object + * @throws java.sql.SQLException if any. + * @throws java.lang.ClassNotFoundException if any. + */ + public Connection openConnection(String database) throws SQLException, ClassNotFoundException { + javax.naming.InitialContext ctx = null; + try { + return DriverManager.getConnection("....."); + } catch (Exception ex) { + System.out.println("SQLException " + ex.getMessage()); + System.out.println("error in Kaarsto DB " + ex.toString()); + System.out.println("The Kaarsto database must be registered on the local DBMS to work."); + } finally { + try { + if (ctx != null) { + ctx.close(); } - return null; + } catch (Exception e) { + e.printStackTrace(); + } } + return null; + } - /** - *
- * Setter for the field statement
.
- *
+ * Setter for the field statement
.
+ *
- * getResultSet. - *
- * - * @param sqlString a {@link java.lang.String} object - * @return a ResultSet object - */ - public ResultSet getResultSet(String sqlString) { - return this.getResultSet("Karsto", sqlString); - } + /** + *+ * getResultSet. + *
+ * + * @param sqlString a {@link java.lang.String} object + * @return a ResultSet object + */ + public ResultSet getResultSet(String sqlString) { + return this.getResultSet("Karsto", sqlString); + } - /** - *- * getResultSet. - *
- * - * @param database a {@link java.lang.String} object - * @param sqlString a {@link java.lang.String} object - * @return a ResultSet object - */ - public ResultSet getResultSet(String database, String sqlString) { - try { - ResultSet result = getStatement().executeQuery(sqlString); - return result; - } catch (Exception e) { - System.out.println("error in DB " + e.toString()); - System.out.println("The database must be rgistered on the local DBMS to work."); - } - return null; + /** + *+ * getResultSet. + *
+ * + * @param database a {@link java.lang.String} object + * @param sqlString a {@link java.lang.String} object + * @return a ResultSet object + */ + public ResultSet getResultSet(String database, String sqlString) { + try { + ResultSet result = getStatement().executeQuery(sqlString); + return result; + } catch (Exception e) { + System.out.println("error in DB " + e.toString()); + System.out.println("The database must be rgistered on the local DBMS to work."); } + return null; + } - /** - *
- * Getter for the field statement
.
- *
+ * Getter for the field statement
.
+ *
- * main. - *
- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - AspenIP21Database database = new AspenIP21Database(); - ResultSet dataSet = database.getResultSet("Karsto", "....'"); - try { - while (dataSet.next()) { - System.out.println("dataset " + dataSet.getString(4)); - System.out.println("dataset value " + dataSet.getDouble("...")); - } - } catch (Exception e) { - System.out.println("failed " + e.toString()); - } - System.out.println("ok"); + /** + *+ * main. + *
+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + AspenIP21Database database = new AspenIP21Database(); + try (ResultSet dataSet = database.getResultSet("Karsto", "....'")) { + while (dataSet.next()) { + System.out.println("dataset " + dataSet.getString(4)); + System.out.println("dataset value " + dataSet.getDouble("...")); + } + } catch (Exception e) { + System.out.println("failed " + e.toString()); } + + System.out.println("ok"); + } } From b7d9b70ea3b059c9f384ab966deab35eae391e0d Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Fri, 22 Jul 2022 15:07:34 +0200 Subject: [PATCH 6/9] NeqSimMSAccessDatabase The NeqSim parameter database in MS Access format. --- docs/wiki/NeqSimDatabase.mdb | Bin 0 -> 4055040 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/wiki/NeqSimDatabase.mdb diff --git a/docs/wiki/NeqSimDatabase.mdb b/docs/wiki/NeqSimDatabase.mdb new file mode 100644 index 0000000000000000000000000000000000000000..f28e10020efbd8af607df2066665600a7599951c GIT binary patch literal 4055040 zcmeEP2S5}@_up&uZWmNQR4gbUA{ykDqEQ4Duwe@#AV?K^iC{@AG0`*<^Eb^H)BH?K zOgDfgG0o)jGp1P*W9%g%#za$;|9dk#dvgbeh(bW;U~k{e?@jy7?Cg}cvyw)Vl4efM zOPgGn<{g_p(>o?g0w?M9JY8yv{mxORUYJ@a8>RJ&o?Kgb*JD8+&U@!v;PxMOKR)HV zqwhaC=*6hYYt=1_~U!`1OYcjk_ zT^)