From 682828494cd81000500add862f8c6004c725de8c Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:25:08 +0100 Subject: [PATCH] added test for flow setter for simple process (#841) --- .../processEquipment/util/FlowSetter.java | 6 +- .../neqsim/thermo/system/SystemThermo.java | 278 +++++++++--------- .../processEquipment/util/FlowSetterTest.java | 53 ++++ 3 files changed, 200 insertions(+), 137 deletions(-) diff --git a/src/main/java/neqsim/processSimulation/processEquipment/util/FlowSetter.java b/src/main/java/neqsim/processSimulation/processEquipment/util/FlowSetter.java index 166a5c1e81..835c6b27de 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/util/FlowSetter.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/util/FlowSetter.java @@ -152,6 +152,9 @@ public void setGasFlowRate(double flowRate, String flowUnit) { case "Sm3/day": conversionFactor = 1.0 / 3600.0 / 24.0; break; + case "MSm3/day": + conversionFactor = 1.0 / 3600.0 / 24.0 * 1e6; + break; default: throw new RuntimeException("unit not supported " + flowUnit); } @@ -297,9 +300,8 @@ public double getWaterFlowRate(String flowUnit) { @Override public void run(UUID id) { SystemInterface tempFluid = inStream.getThermoSystem().clone(); - double flow = tempFluid.getFlowRate("kg/sec"); - if (flow < 1e-6) { + if (tempFluid.getFlowRate("kg/sec") < 1e-6) { outStream.setThermoSystem(tempFluid); return; } diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index 145a8036ac..987d89675c 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -1,22 +1,12 @@ package neqsim.thermo.system; -import java.awt.BorderLayout; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Toolkit; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -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; @@ -86,7 +76,7 @@ public abstract class SystemThermo implements SystemInterface { protected int numberOfComponents = 0; // protected ArrayList resultArray1 = new ArrayList(); - protected String[] CapeOpenProperties11 = { "molecularWeight", "speedOfSound", + protected String[] CapeOpenProperties11 = {"molecularWeight", "speedOfSound", "jouleThomsonCoefficient", "internalEnergy", "internalEnergy.Dtemperature", "gibbsEnergy", "helmholtzEnergy", "fugacityCoefficient", "logFugacityCoefficient", "logFugacityCoefficient.Dtemperature", "logFugacityCoefficient.Dpressure", @@ -95,8 +85,8 @@ public abstract class SystemThermo implements SystemInterface { "entropy.Dmoles", "heatCapacityCp", "heatCapacityCv", "density", "density.Dtemperature", "density.Dpressure", "density.Dmoles", "volume", "volume.Dpressure", "volume.Dtemperature", "molecularWeight.Dtemperature", "molecularWeight.Dpressure", "molecularWeight.Dmoles", - "compressibilityFactor" }; - protected String[] CapeOpenProperties10 = { "molecularWeight", "speedOfSound", + "compressibilityFactor"}; + protected String[] CapeOpenProperties10 = {"molecularWeight", "speedOfSound", "jouleThomsonCoefficient", "energy", "energy.Dtemperature", "gibbsFreeEnergy", "helmholtzFreeEnergy", "fugacityCoefficient", "logFugacityCoefficient", "logFugacityCoefficient.Dtemperature", "logFugacityCoefficient.Dpressure", @@ -105,7 +95,7 @@ public abstract class SystemThermo implements SystemInterface { "entropy.Dmoles", "heatCapacity", "heatCapacityCv", "density", "density.Dtemperature", "density.Dpressure", "density.Dmoles", "volume", "volume.Dpressure", "volume.Dtemperature", "molecularWeight.Dtemperature", "molecularWeight.Dpressure", "molecularWeight.Dmoles", - "compressibilityFactor" }; + "compressibilityFactor"}; protected int attractiveTermNumber = 0; /** Number of phases in use/existing. */ @@ -113,14 +103,12 @@ public abstract class SystemThermo implements SystemInterface { /** Maximum allowed number of phases . */ public int maxNumberOfPhases = 2; /** - * Array of indexes to phaseArray keeping track of the creation order of the - * phases where 0 is the + * Array of indexes to phaseArray keeping track of the creation order of the phases where 0 is the * first created phase and the lowest number is the phase created last. */ protected int[] phaseIndex; /** - * Array containing all phases of System. NB! Phases are reorered according to - * density, use + * Array containing all phases of System. NB! Phases are reorered according to density, use * phaseIndex to keep track of the creation order. */ protected PhaseInterface[] phaseArray = new PhaseInterface[MAX_PHASES]; @@ -167,16 +155,16 @@ public SystemThermo() { public SystemThermo(double T, double P) { this(); if (T < 0.0) { - neqsim.util.exception.InvalidInputException ex = new neqsim.util.exception.InvalidInputException( - this.getClass().getSimpleName(), - "SystemThermo", "T", "is negative"); + neqsim.util.exception.InvalidInputException ex = + new neqsim.util.exception.InvalidInputException(this.getClass().getSimpleName(), + "SystemThermo", "T", "is negative"); throw new RuntimeException(ex); } if (P < 0.0) { - neqsim.util.exception.InvalidInputException ex = new neqsim.util.exception.InvalidInputException( - this.getClass().getSimpleName(), - "SystemThermo", "P", "is negative"); + neqsim.util.exception.InvalidInputException ex = + new neqsim.util.exception.InvalidInputException(this.getClass().getSimpleName(), + "SystemThermo", "P", "is negative"); throw new RuntimeException(ex); } } @@ -281,24 +269,19 @@ public SystemInterface addFluid(SystemInterface addSystem, int phase) { @Override public void addPhase() { /* - * if (maxNumberOfPhases < 6 && !hydrateCheck) { ArrayList phaseList = new - * ArrayList(0); for - * (int i = 0; i < numberOfPhases; i++) { phaseList.add(phaseArray[i]); } // add - * the new phase - * phaseList.add(phaseArray[0].clone()); beta[phaseList.size() - 1] = 1.0e-8; // - * beta[1] -= + * if (maxNumberOfPhases < 6 && !hydrateCheck) { ArrayList phaseList = new ArrayList(0); for + * (int i = 0; i < numberOfPhases; i++) { phaseList.add(phaseArray[i]); } // add the new phase + * phaseList.add(phaseArray[0].clone()); beta[phaseList.size() - 1] = 1.0e-8; // beta[1] -= * beta[1]/1.0e5; * * PhaseInterface[] phaseArray2 = new PhaseInterface[numberOfPhases + 1]; * - * for (int i = 0; i < numberOfPhases + 1; i++) { phaseArray2[i] = - * (PhaseInterface) + * for (int i = 0; i < numberOfPhases + 1; i++) { phaseArray2[i] = (PhaseInterface) * phaseList.get(i); } * * phaseArray = phaseArray2; * - * System.out.println("number of phases " + numberOfPhases); if - * (maxNumberOfPhases < + * System.out.println("number of phases " + numberOfPhases); if (maxNumberOfPhases < * numberOfPhases) { maxNumberOfPhases = numberOfPhases; } } */ numberOfPhases++; @@ -700,7 +683,8 @@ public void setTotalFlowRate(double flowRate, String flowunit) { if (flowunit.equals("idSm3/hr")) { density = getIdealLiquidDensity("kg/m3"); } - neqsim.util.unit.Unit unit = new neqsim.util.unit.RateUnit(flowRate, flowunit, getMolarMass(), density, 0); + neqsim.util.unit.Unit unit = + new neqsim.util.unit.RateUnit(flowRate, flowunit, getMolarMass(), density, 0); double SIval = unit.getSIvalue(); double totalNumberOfMolesLocal = totalNumberOfMoles; for (int i = 0; i < numberOfComponents; i++) { @@ -708,8 +692,9 @@ public void setTotalFlowRate(double flowRate, String flowunit) { setEmptyFluid(); } else if (totalNumberOfMolesLocal > 1e-100) { // (SIval / totalNumberOfMolesLocal - 1) * ... - double change = SIval / totalNumberOfMolesLocal * getPhase(0).getComponent(i).getNumberOfmoles() - - getPhase(0).getComponent(i).getNumberOfmoles(); + double change = + SIval / totalNumberOfMolesLocal * getPhase(0).getComponent(i).getNumberOfmoles() + - getPhase(0).getComponent(i).getNumberOfmoles(); if (Math.abs(change) > 1e-12) { addComponent(i, change); } @@ -1204,7 +1189,8 @@ public void addComponent(String componentName, double value, String unitName) { double stddens = 0.0; double boilp = 0.0; try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); - java.sql.ResultSet dataSet = database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'"))) { + java.sql.ResultSet dataSet = + database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'"))) { dataSet.next(); molarmass = Double.parseDouble(dataSet.getString("molarmass")) / 1000.0; stddens = Double.parseDouble(dataSet.getString("stddens")); @@ -1212,7 +1198,8 @@ public void addComponent(String componentName, double value, String unitName) { } catch (Exception ex) { logger.error("failed ", ex); } - neqsim.util.unit.Unit unit = new neqsim.util.unit.RateUnit(value, unitName, molarmass, stddens, boilp); + neqsim.util.unit.Unit unit = + new neqsim.util.unit.RateUnit(value, unitName, molarmass, stddens, boilp); double SIval = unit.getSIvalue(); // System.out.println("number of moles " + SIval); this.addComponent(componentName, SIval); @@ -1262,8 +1249,8 @@ public void addComponent(String componentName, double moles, int phaseNumber) { // Add new component if (moles < 0.0) { String msg = "Negative input number of moles."; - neqsim.util.exception.InvalidInputException ex = new neqsim.util.exception.InvalidInputException(this, - "addComponent", "moles", msg); + neqsim.util.exception.InvalidInputException ex = + new neqsim.util.exception.InvalidInputException(this, "addComponent", "moles", msg); throw new RuntimeException(ex); } @@ -1296,7 +1283,8 @@ public void addComponent(String componentName, double value, String name, int ph double stddens = 0.0; double boilp = 0.0; try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); - java.sql.ResultSet dataSet = database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'"))) { + java.sql.ResultSet dataSet = + database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'"))) { dataSet.next(); molarmass = Double.parseDouble(dataSet.getString("molarmass")) / 1000.0; stddens = Double.parseDouble(dataSet.getString("stddens")); @@ -1305,7 +1293,8 @@ public void addComponent(String componentName, double value, String name, int ph logger.error("failed ", ex); throw new RuntimeException(ex); } - neqsim.util.unit.Unit unit = new neqsim.util.unit.RateUnit(value, name, molarmass, stddens, boilp); + neqsim.util.unit.Unit unit = + new neqsim.util.unit.RateUnit(value, name, molarmass, stddens, boilp); double SIval = unit.getSIvalue(); // System.out.println("number of moles " + SIval); this.addComponent(componentName, SIval, phase); @@ -1571,8 +1560,7 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, } /* - * if ((nybeta > maxBeta) || (nybeta < minBeta)) { // nybeta = 0.5 * (maxBeta + - * minBeta); + * if ((nybeta > maxBeta) || (nybeta < minBeta)) { // nybeta = 0.5 * (maxBeta + minBeta); * gbeta = 1.0; } */ } else { @@ -1603,8 +1591,7 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, } /* - * if ((betal > maxBeta) || (betal < minBeta)) { gbeta = 1.0; { betal = 0.5 * - * (maxBeta + + * if ((betal > maxBeta) || (betal < minBeta)) { gbeta = 1.0; { betal = 0.5 * (maxBeta + * minBeta); } } */ nybeta = 1.0 - betal; @@ -1634,8 +1621,7 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, } if (Double.isNaN(beta[1])) { /* - * for (i = 0; i < numberOfComponents; i++) { System.out.println("K " + - * compArray[i].getK()); + * for (i = 0; i < numberOfComponents; i++) { System.out.println("K " + compArray[i].getK()); * System.out.println("z " + compArray[i].getz()); } */ throw new neqsim.util.exception.IsNaNException(this, "calcBeta", "beta"); @@ -1834,10 +1820,8 @@ public void init(int type, int phase) { * initAnalytic. *

* - * @param type a int. 0 to initialize and 1 to reset, 2 to calculate T and P - * derivatives, 3 to - * calculate all derivatives and 4 to calculate all derivatives - * numerically + * @param type a int. 0 to initialize and 1 to reset, 2 to calculate T and P derivatives, 3 to + * calculate all derivatives and 4 to calculate all derivatives numerically */ public void initAnalytic(int type) { @@ -1936,7 +1920,7 @@ public void initAnalytic(int type) { * initAnalytic. *

* - * @param type a int + * @param type a int * @param phase a int */ public void initAnalytic(int type, int phase) { @@ -2002,7 +1986,7 @@ public void initNumeric(int type) { * initNumeric. *

* - * @param type a int + * @param type a int * @param phasen a int */ public void initNumeric(int type, int phasen) { @@ -2072,7 +2056,8 @@ public void initNumeric(int type, int phasen) { init(1); for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - liqfug[0][i] = Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); + liqfug[0][i] = + Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); } addComponent(k, -2.0 * dn, phase); @@ -2083,7 +2068,8 @@ public void initNumeric(int type, int phasen) { for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { // gasfug[1][i] = // Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[1][i] = Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); + liqfug[1][i] = + Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); } addComponent(k, dn, phase); init_x_y(); @@ -2858,7 +2844,8 @@ public double getMolarVolume() { public double getDensity() { double density = 0; for (int i = 0; i < numberOfPhases; i++) { - density += 1.0e5 * (getPhase(i).getMolarMass() * beta[phaseIndex[i]] / getPhase(i).getMolarVolume()); + density += + 1.0e5 * (getPhase(i).getMolarMass() * beta[phaseIndex[i]] / getPhase(i).getMolarVolume()); } return density; } @@ -2868,7 +2855,8 @@ public double getDensity() { public double getDensity(String unit) { double density = 0; for (int i = 0; i < getNumberOfPhases(); i++) { - density += getPhase(i).getVolume() / getVolume() * getPhase(i).getPhysicalProperties().getDensity(); + density += + getPhase(i).getVolume() / getVolume() * getPhase(i).getPhysicalProperties().getDensity(); } double refDensity = density; // density in kg/m3 double conversionFactor = 1.0; @@ -2916,7 +2904,8 @@ public double getMoleFractionsSum() { public double getMolarMass() { double tempVar = 0; for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { - tempVar += phaseArray[0].getComponents()[i].getz() * phaseArray[0].getComponents()[i].getMolarMass(); + tempVar += + phaseArray[0].getComponents()[i].getz() * phaseArray[0].getComponents()[i].getMolarMass(); } return tempVar; } @@ -3044,8 +3033,7 @@ public void reInitPhaseType() { } /** - * Re-initialize phasetype, beta and phaseindex arrays, same initialization - * which is used in + * Re-initialize phasetype, beta and phaseindex arrays, same initialization which is used in * constructor. */ public void reInitPhaseInformation() { @@ -3057,7 +3045,7 @@ public void reInitPhaseInformation() { beta[i] = 1.0; } - phaseIndex = new int[] { 0, 1, 2, 3, 4, 5 }; + phaseIndex = new int[] {0, 1, 2, 3, 4, 5}; } /** {@inheritDoc} */ @@ -3077,7 +3065,8 @@ public final void setPressure(double newPressure) { /** {@inheritDoc} */ @Override public final void setPressure(double newPressure, String unit) { - neqsim.util.unit.PressureUnit presConversion = new neqsim.util.unit.PressureUnit(newPressure, unit); + neqsim.util.unit.PressureUnit presConversion = + new neqsim.util.unit.PressureUnit(newPressure, unit); setPressure(presConversion.getValue("bara")); } @@ -3090,7 +3079,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); } @@ -3109,7 +3099,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); } @@ -3451,51 +3442,55 @@ public String[][] createTable(String name) { } StringBuffer buf = new StringBuffer(); - FieldPosition test = new FieldPosition(0); + java.text.FieldPosition test = new java.text.FieldPosition(0); for (int j = 0; j < getPhases()[0].getNumberOfComponents(); j++) { buf = new StringBuffer(); table[j + 1][1] = nf.format(getPhase(0).getComponents()[j].getz(), buf, test).toString(); } buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 4][1] = nf.format(getMolarMass() * 1000, buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 4][1] = + nf.format(getMolarMass() * 1000, buf, test).toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 9][1] = nf - .format(getEnthalpy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) - .toString(); + table[getPhases()[0].getNumberOfComponents() + 9][1] = + nf.format(getEnthalpy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) + .toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 10][1] = nf - .format(getEntropy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) - .toString(); + table[getPhases()[0].getNumberOfComponents() + 10][1] = + nf.format(getEntropy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) + .toString(); for (int i = 0; i < numberOfPhases; i++) { for (int j = 0; j < getPhases()[0].getNumberOfComponents(); j++) { table[j + 1][0] = getPhases()[0].getComponents()[j].getName(); buf = new StringBuffer(); - table[j + 1][i + 2] = nf.format(getPhase(i).getComponents()[j].getx(), buf, test).toString(); + table[j + 1][i + 2] = + nf.format(getPhase(i).getComponents()[j].getx(), buf, test).toString(); table[j + 1][6] = "[mole fraction]"; } buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 2][0] = "Density"; - table[getPhases()[0].getNumberOfComponents() + 2][i + 2] = nf - .format(getPhase(i).getPhysicalProperties().getDensity(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 2][i + 2] = + nf.format(getPhase(i).getPhysicalProperties().getDensity(), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 2][6] = "[kg/m^3]"; // Double.longValue(system.getPhase(i).getBeta()); buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 3][0] = "PhaseFraction"; - table[getPhases()[0].getNumberOfComponents() + 3][i + 2] = nf.format(getPhase(i).getBeta(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 3][i + 2] = + nf.format(getPhase(i).getBeta(), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 3][6] = "[mole fraction]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 4][0] = "MolarMass"; - table[getPhases()[0].getNumberOfComponents() + 4][i + 2] = nf.format(getPhase(i).getMolarMass() * 1000, buf, test) - .toString(); + table[getPhases()[0].getNumberOfComponents() + 4][i + 2] = + nf.format(getPhase(i).getMolarMass() * 1000, buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 4][6] = "[kg/kmol]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 5][0] = "Z factor"; - table[getPhases()[0].getNumberOfComponents() + 5][i + 2] = nf.format(getPhase(i).getZ(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 5][i + 2] = + nf.format(getPhase(i).getZ(), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 5][6] = "[-]"; buf = new StringBuffer(); @@ -3516,8 +3511,8 @@ public String[][] createTable(String name) { buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 8][0] = "Speed of Sound"; - table[getPhases()[0].getNumberOfComponents() + 8][i + 2] = nf.format((getPhase(i).getSoundSpeed()), buf, test) - .toString(); + table[getPhases()[0].getNumberOfComponents() + 8][i + 2] = + nf.format((getPhase(i).getSoundSpeed()), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 8][6] = "[m/sec]"; buf = new StringBuffer(); @@ -3538,47 +3533,47 @@ public String[][] createTable(String name) { buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 11][0] = "JT coefficient"; - table[getPhases()[0].getNumberOfComponents() + 11][i + 2] = nf - .format((getPhase(i).getJouleThomsonCoefficient()), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 11][i + 2] = + nf.format((getPhase(i).getJouleThomsonCoefficient()), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 11][6] = "[K/bar]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 13][0] = "Viscosity"; - table[getPhases()[0].getNumberOfComponents() + 13][i + 2] = nf - .format((getPhase(i).getPhysicalProperties().getViscosity()), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 13][i + 2] = + nf.format((getPhase(i).getPhysicalProperties().getViscosity()), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 13][6] = "[kg/m*sec]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 14][0] = "Conductivity"; - table[getPhases()[0].getNumberOfComponents() + 14][i + 2] = nf - .format(getPhase(i).getPhysicalProperties().getConductivity(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 14][i + 2] = + nf.format(getPhase(i).getPhysicalProperties().getConductivity(), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 14][6] = "[W/m*K]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 15][0] = "SurfaceTension"; try { if (i < numberOfPhases - 1) { - table[getPhases()[0].getNumberOfComponents() + 15][2] = nf - .format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 15][2] = + nf.format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 15][3] = nf - .format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 15][3] = + nf.format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); buf = new StringBuffer(); if (i == 1) { - table[getPhases()[0].getNumberOfComponents() + 17][2] = nf - .format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 17][2] = + nf.format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 17][4] = nf - .format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 17][4] = + nf.format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 17][6] = "[N/m]"; } if (i == 1) { buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 16][3] = nf - .format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 16][3] = + nf.format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 16][4] = nf - .format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 16][4] = + nf.format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 16][6] = "[N/m]"; } } @@ -3589,12 +3584,14 @@ public String[][] createTable(String name) { buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 19][0] = "Pressure"; - table[getPhases()[0].getNumberOfComponents() + 19][i + 2] = Double.toString(getPhase(i).getPressure()); + table[getPhases()[0].getNumberOfComponents() + 19][i + 2] = + Double.toString(getPhase(i).getPressure()); table[getPhases()[0].getNumberOfComponents() + 19][6] = "[bar]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 20][0] = "Temperature"; - table[getPhases()[0].getNumberOfComponents() + 20][i + 2] = Double.toString(getPhase(i).getTemperature()); + table[getPhases()[0].getNumberOfComponents() + 20][i + 2] = + Double.toString(getPhase(i).getTemperature()); table[getPhases()[0].getNumberOfComponents() + 20][6] = "[K]"; Double.toString(getPhase(i).getTemperature()); @@ -3606,8 +3603,8 @@ public String[][] createTable(String name) { buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 23][0] = "Mixing Rule"; try { - table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = ((PhaseEosInterface) getPhase(i)) - .getMixingRuleName(); + table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = + ((PhaseEosInterface) getPhase(i)).getMixingRuleName(); } catch (Exception ex) { table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = "?"; // logger.error(ex.getMessage(),e); @@ -3633,21 +3630,22 @@ public void display() { /** {@inheritDoc} */ @Override public void display(String name) { - JFrame dialog = new JFrame("System-Report"); - Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); - Container dialogContentPane = dialog.getContentPane(); - dialogContentPane.setLayout(new BorderLayout()); - String[] names = { "", "Feed", "Phase 1", "Phase 2", "Phase 3", "Phase 4", "Unit" }; + javax.swing.JFrame dialog = new javax.swing.JFrame("System-Report"); + java.awt.Dimension screenDimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); + java.awt.Container dialogContentPane = dialog.getContentPane(); + dialogContentPane.setLayout(new java.awt.BorderLayout()); + + String[] names = {"", "Feed", "Phase 1", "Phase 2", "Phase 3", "Phase 4", "Unit"}; String[][] table = createTable(name); - JTable Jtab = new JTable(table, names); - JScrollPane scrollpane = new JScrollPane(Jtab); + javax.swing.JTable Jtab = new javax.swing.JTable(table, names); + javax.swing.JScrollPane scrollpane = new javax.swing.JScrollPane(Jtab); dialogContentPane.add(scrollpane); // setting the size of the frame and text size dialog.setSize(screenDimension.width / 2, screenDimension.height / 2); // pack(); Jtab.setRowHeight(dialog.getHeight() / table.length); - Jtab.setFont(new Font("Serif", Font.PLAIN, + Jtab.setFont(new java.awt.Font("Serif", java.awt.Font.PLAIN, dialog.getHeight() / table.length - dialog.getHeight() / table.length / 10)); // dialog.pack(); @@ -3670,7 +3668,8 @@ public String write() { @Override public void write(String name, String filename, boolean newfile) { String[][] table = createTable(name); - neqsim.dataPresentation.fileHandeling.createTextFile.TextFile file = new neqsim.dataPresentation.fileHandeling.createTextFile.TextFile(); + neqsim.dataPresentation.fileHandeling.createTextFile.TextFile file = + new neqsim.dataPresentation.fileHandeling.createTextFile.TextFile(); if (newfile) { file.newFile(filename); } @@ -3869,9 +3868,10 @@ public void save(String name) { /** {@inheritDoc} */ @Override public SystemInterface readObject(int ID) { - ResultSet rs = null; + java.sql.ResultSet rs = null; SystemThermo tempSystem = null; - neqsim.util.database.NeqSimBlobDatabase database = new neqsim.util.database.NeqSimBlobDatabase(); + neqsim.util.database.NeqSimBlobDatabase database = + new neqsim.util.database.NeqSimBlobDatabase(); try { java.sql.Connection con = database.openConnection(); String sqlStr = "SELECT FLUID FROM fluid_blobdb WHERE ID=" + Integer.toString(ID); @@ -3879,7 +3879,8 @@ public SystemInterface readObject(int ID) { rs = ps.executeQuery(); if (rs.next()) { - try (ObjectInputStream ins = new ObjectInputStream(new ByteArrayInputStream(rs.getBytes("FLUID")))) { + try (ObjectInputStream ins = + new ObjectInputStream(new ByteArrayInputStream(rs.getBytes("FLUID")))) { tempSystem = (SystemThermo) ins.readObject(); } } @@ -3925,20 +3926,21 @@ public void saveObject(int ID, String text) { byte[] byteObject = fout.toByteArray(); ByteArrayInputStream inpStream = new ByteArrayInputStream(byteObject); - neqsim.util.database.NeqSimBlobDatabase database = new neqsim.util.database.NeqSimBlobDatabase(); + neqsim.util.database.NeqSimBlobDatabase database = + new neqsim.util.database.NeqSimBlobDatabase(); try { java.sql.Connection con = database.openConnection(); - java.sql.PreparedStatement ps = con.prepareStatement("REPLACE INTO fluid_blobdb (ID, FLUID) VALUES (?,?)"); + java.sql.PreparedStatement ps = + con.prepareStatement("REPLACE INTO fluid_blobdb (ID, FLUID) VALUES (?,?)"); ps.setInt(1, ID); ps.setBlob(2, inpStream); ps.executeUpdate(); /* * if (!text.isEmpty()) { ps = con.prepareStatement( - * "REPLACE INTO fluidinfo (ID, TEXT) VALUES (?,?)"); ps.setInt(1, ID); - * ps.setString(2, text); + * "REPLACE INTO fluidinfo (ID, TEXT) VALUES (?,?)"); ps.setInt(1, ID); ps.setString(2, text); * } * * ps.executeUpdate(); @@ -3975,7 +3977,8 @@ public void saveObjectToFile(String filePath, String fluidName) { @Override public SystemInterface readObjectFromFile(String filePath, String fluidName) { SystemThermo tempSystem = null; - try (ObjectInputStream objectinputstream = new ObjectInputStream(new FileInputStream(filePath))) { + try (ObjectInputStream objectinputstream = + new ObjectInputStream(new FileInputStream(filePath))) { tempSystem = (SystemThermo) objectinputstream.readObject(); } catch (Exception ex) { logger.error(ex.getMessage(), ex); @@ -4021,7 +4024,8 @@ public void setFluidName(String fluidName) { * @return a boolean */ public boolean setLastTBPasPlus() { - neqsim.thermo.characterization.PlusCharacterize temp = new neqsim.thermo.characterization.PlusCharacterize(this); + neqsim.thermo.characterization.PlusCharacterize temp = + new neqsim.thermo.characterization.PlusCharacterize(this); if (temp.hasPlusFraction()) { return false; } else { @@ -4145,8 +4149,9 @@ public void saveToDataBase() { database.execute("delete FROM systemreport"); int i = 0; for (; i < numberOfComponents; i++) { - String sqlString = "'" + Integer.toString(i + 1) + "', '" + getPhase(0).getComponent(i).getName() + "', " - + "'molfrac[-] ', '" + Double.toString(getPhase(0).getComponent(i).getz()) + "'"; + String sqlString = + "'" + Integer.toString(i + 1) + "', '" + getPhase(0).getComponent(i).getName() + "', " + + "'molfrac[-] ', '" + Double.toString(getPhase(0).getComponent(i).getz()) + "'"; int j = 0; for (; j < numberOfPhases; j++) { @@ -4295,7 +4300,8 @@ public double getHeatOfVaporization() { public void readFluid(String fluidName) { this.fluidName = fluidName; try { - neqsim.util.database.NeqSimFluidDataBase database = new neqsim.util.database.NeqSimFluidDataBase(); + neqsim.util.database.NeqSimFluidDataBase database = + new neqsim.util.database.NeqSimFluidDataBase(); java.sql.ResultSet dataSet = null; dataSet = database.getResultSet("SELECT * FROM " + fluidName); @@ -4358,13 +4364,15 @@ public SystemInterface setModel(String model) { tempModel = new SystemSrkSchwartzentruberEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("Electrolyte-ScRK-EOS")) { - tempModel = new SystemFurstElectrolyteEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + tempModel = + new SystemFurstElectrolyteEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("GERG-water-EOS")) { tempModel = new SystemGERGwaterEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("CPAs-SRK-EOS")) { tempModel = new SystemSrkCPAs(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("CPAs-SRK-EOS-statoil")) { - tempModel = new SystemSrkCPAstatoil(getPhase(0).getTemperature(), getPhase(0).getPressure()); + tempModel = + new SystemSrkCPAstatoil(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("Electrolyte-CPA-EOS-statoil") || model.equals("Electrolyte-CPA-EOS")) { tempModel = new SystemElectrolyteCPAstatoil(getPhase(0).getTemperature(), @@ -4376,9 +4384,11 @@ public SystemInterface setModel(String model) { } else if (model.equals("GERG-2008-EoS")) { tempModel = new SystemGERG2004Eos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("SRK-TwuCoon-Statoil-EOS") || model.equals("SRK-TwuCoon-EOS")) { - tempModel = new SystemSrkTwuCoonStatoilEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + tempModel = + new SystemSrkTwuCoonStatoilEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("SRK-TwuCoon-Param-EOS")) { - tempModel = new SystemSrkTwuCoonParamEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + tempModel = + new SystemSrkTwuCoonParamEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("Duan-Sun")) { tempModel = new SystemDuanSun(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else { @@ -4627,8 +4637,7 @@ public double getTotalNumberOfMoles() { public void setTotalNumberOfMoles(double totalNumberOfMoles) { if (totalNumberOfMoles < 0) { /* - * throw new RuntimeException(new - * neqsim.util.exception.InvalidInputException(this, + * throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, * "setTotalNumberOfMoles", "totalNumberOfMoles", "can not be less than 0.")); */ totalNumberOfMoles = 0; @@ -5092,11 +5101,10 @@ public SystemProperties getProperties() { } /** - * Wrapper function for addComponent to set fluid type and specify mole - * fractions. + * Wrapper function for addComponent to set fluid type and specify mole fractions. * * @param molefractions Component mole fraction of each component. - * @param type Type of fluid. Supports "PlusFluid", "Plus" and default. + * @param type Type of fluid. Supports "PlusFluid", "Plus" and default. */ private void setMolarFractions(double[] molefractions, String type) { double totalFlow = getTotalNumberOfMoles(); diff --git a/src/test/java/neqsim/processSimulation/processEquipment/util/FlowSetterTest.java b/src/test/java/neqsim/processSimulation/processEquipment/util/FlowSetterTest.java index 0f71fec185..3c07b50124 100644 --- a/src/test/java/neqsim/processSimulation/processEquipment/util/FlowSetterTest.java +++ b/src/test/java/neqsim/processSimulation/processEquipment/util/FlowSetterTest.java @@ -3,7 +3,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; import neqsim.processSimulation.measurementDevice.MultiPhaseMeter; +import neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator; import neqsim.processSimulation.processEquipment.stream.Stream; +import neqsim.processSimulation.processEquipment.stream.StreamInterface; import neqsim.thermo.system.SystemInterface; import neqsim.thermo.system.SystemSrkEos; @@ -50,4 +52,55 @@ void testMain() { flowset.getOutletStream().getFluid().prettyPrint(); } + + @Test + void testProcessWithFlowSetter() { + + double gasFlow = 10.0; // MSm3/day + double oilFlow = 2000.0; // m3/hr + double waterFLow = 1000.0; // m3/hr + SystemInterface testFluid = new SystemSrkEos(338.15, 50.0); + testFluid.addComponent("nitrogen", 1.205); + testFluid.addComponent("CO2", 1.340); + testFluid.addComponent("methane", 87.974); + testFluid.addComponent("ethane", 5.258); + testFluid.addComponent("propane", 3.283); + testFluid.addComponent("i-butane", 0.082); + testFluid.addComponent("n-butane", 0.487); + testFluid.addComponent("i-pentane", 0.056); + testFluid.addComponent("n-pentane", 1.053); + testFluid.addComponent("nC10", 4.053); + testFluid.addComponent("water", 10.00); + testFluid.setMixingRule(2); + testFluid.setMultiPhaseCheck(true); + + Stream stream_1 = new Stream("Stream1", testFluid); + stream_1.run(); + stream_1.setPressure(10.0, "bara"); + stream_1.setTemperature(80.0, "C"); + + FlowSetter flowset = new FlowSetter("flowset", stream_1); + flowset.setTemperature(15.0, "C"); + flowset.setPressure(1.01325, "bara"); + flowset.setGasFlowRate(gasFlow, "MSm3/day"); + flowset.setOilFlowRate(oilFlow, "m3/hr"); + flowset.setWaterFlowRate(waterFLow, "m3/hr"); + + StreamInterface feedStream = flowset.getOutletStream(); + + ThreePhaseSeparator separator = new ThreePhaseSeparator(feedStream); + + StreamInterface gasFromSepStream = separator.getGasOutStream(); + + + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + operations.add(stream_1); + operations.add(flowset); + operations.add(separator); + operations.run(); + + feedStream.getThermoSystem().prettyPrint(); + assertEquals(gasFlow, gasFromSepStream.getFlowRate("MSm3/day"), 1.0); + } }