diff --git a/src/main/java/neqsim/thermo/Fluid.java b/src/main/java/neqsim/thermo/Fluid.java index 5449b1871..fca50d101 100644 --- a/src/main/java/neqsim/thermo/Fluid.java +++ b/src/main/java/neqsim/thermo/Fluid.java @@ -22,23 +22,6 @@ public class Fluid { public Fluid() { } - public Fluid(String[] componentNames) { - create2(componentNames); - } - - /** - * @param componentNames - * @param flowrate - * @param unit - */ - public Fluid(String[] componentNames, double[] flowrate, String unit) { - create2(componentNames, flowrate, unit); - } - - public Fluid(String fluidType) { - create(fluidType); - } - public neqsim.thermo.system.SystemInterface getFluid() { return fluid; } @@ -58,10 +41,6 @@ private void setThermoModel() { } } - private void setMixingRule() { - fluid.setMixingRule(getThermoMixingRule()); - } - /** *

* create2. @@ -96,7 +75,7 @@ public neqsim.thermo.system.SystemInterface create2(String[] componentNames, fluid.addComponent("water", 0.1); } fluid.createDatabase(true); - setMixingRule(); + fluid.setMixingRule(fluid.getMixingRule()); if (isHasWater()) { fluid.setMultiPhaseCheck(true); } @@ -155,7 +134,7 @@ public neqsim.thermo.system.SystemInterface create(String fluidType) { double[] charFlowrate = new double[] {0.1, 0.08, 0.05, 0.01}; double[] molarMass = new double[] {0.20, 0.3, 0.36, 0.4}; double[] density = new double[] {700.0e-3, 810.0e-3, 880.0e-3, 920.0e-3}; - addCharacterized(charNames, charFlowrate, molarMass, density); + getFluid().addCharacterized(charNames, charFlowrate, molarMass, density); } else if (fluidType.equals("petrol")) { compNames = new String[] {"n-pentane", "n-hexane", "n-heptane", "n-octane", "n-nonane", "nC10", "nC11", "nC12"}; @@ -177,7 +156,7 @@ public neqsim.thermo.system.SystemInterface create(String fluidType) { double[] charFlowrate = new double[] {0.2, 0.1, 0.05, 0.01}; double[] molarMass = new double[] {0.20, 0.3, 0.36, 0.4}; double[] density = new double[] {700.0e-3, 810.0e-3, 880.0e-3, 920.0e-3}; - addCharacterized(charNames, charFlowrate, molarMass, density); + getFluid().addCharacterized(charNames, charFlowrate, molarMass, density); } else if (fluidType.equals("black oil")) { compNames = new String[] {"nitrogen", "CO2", "methane", "ethane", "propane", "i-butane", "n-butane", "i-pentane", "n-pentane", "n-hexane"}; @@ -187,7 +166,7 @@ public neqsim.thermo.system.SystemInterface create(String fluidType) { double[] charFlowrate = new double[] {0.2, 0.1, 0.1, 0.05, 0.01}; double[] molarMass = new double[] {0.20, 0.25, 0.3, 0.36, 0.4}; double[] density = new double[] {700.0e-3, 750.0e-3, 810.0e-3, 880.0e-3, 920.0e-3}; - addCharacterized(charNames, charFlowrate, molarMass, density); + getFluid().addCharacterized(charNames, charFlowrate, molarMass, density); } else if (fluidType.equals("black oil with water")) { compNames = new String[] {"nitrogen", "CO2", "methane", "ethane", "propane", "i-butane", "n-butane", "i-pentane", "n-pentane", "n-hexane"}; @@ -197,7 +176,7 @@ public neqsim.thermo.system.SystemInterface create(String fluidType) { double[] charFlowrate = new double[] {0.2, 0.1, 0.1, 0.05, 0.01}; double[] molarMass = new double[] {0.20, 0.25, 0.3, 0.36, 0.4}; double[] density = new double[] {700.0e-3, 750.0e-3, 810.0e-3, 880.0e-3, 920.0e-3}; - addCharacterized(charNames, charFlowrate, molarMass, density); + getFluid().addCharacterized(charNames, charFlowrate, molarMass, density); setHasWater(true); } else if (fluidType.equals("heavy oil")) { compNames = new String[] {"nitrogen", "CO2", "methane", "ethane", "propane", "i-butane", @@ -208,7 +187,7 @@ public neqsim.thermo.system.SystemInterface create(String fluidType) { double[] charFlowrate = new double[] {0.2, 0.2, 0.2, 0.1, 0.1}; double[] molarMass = new double[] {0.20, 0.25, 0.3, 0.36, 0.4}; double[] density = new double[] {700.0e-3, 750.0e-3, 810.0e-3, 880.0e-3, 920.0e-3}; - addCharacterized(charNames, charFlowrate, molarMass, density); + getFluid().addCharacterized(charNames, charFlowrate, molarMass, density); } else if (neqsim.util.database.NeqSimDataBase.hasComponent(fluidType)) { compNames = new String[] {fluidType}; flowrate = new double[] {1.0}; @@ -221,7 +200,7 @@ public neqsim.thermo.system.SystemInterface create(String fluidType) { fluid.addComponent("water", 0.1); } fluid.createDatabase(true); - setMixingRule(); + fluid.setMixingRule(fluid.getMixingRule()); if (isHasWater()) { fluid.setMultiPhaseCheck(true); } @@ -232,66 +211,6 @@ public neqsim.thermo.system.SystemInterface create(String fluidType) { return fluid; } - /** - *

- * addCharacterized. - *

- * - * @param charNames an array of {@link java.lang.String} objects - * @param charFlowrate an array of {@link double} objects - * @param molarMass an array of {@link double} objects - * @param relativedensity an array of {@link double} objects - */ - public void addCharacterized(String[] charNames, double[] charFlowrate, double[] molarMass, - double[] relativedensity) { - if (charNames.length != charFlowrate.length) { - logger.error("component names and mole fractions need to be same length..."); - } - for (int i = 0; i < charNames.length; i++) { - fluid.addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); - } - } - - /** - *

- * addOilFractions. - *

- * - * @param charNames an array of {@link java.lang.String} objects - * @param charFlowrate an array of {@link double} objects - * @param molarMass an array of {@link double} objects - * @param relativedensity an array of {@link double} objects - * @param lastIsPlusFraction a boolean - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public neqsim.thermo.system.SystemInterface addOilFractions(String[] charNames, - double[] charFlowrate, double[] molarMass, double[] relativedensity, - boolean lastIsPlusFraction) { - if (charNames.length != charFlowrate.length) { - logger.error("component names and mole fractions need to be same length..."); - } - - for (int i = 0; i < charNames.length - 1; i++) { - fluid.addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); - } - int i = charNames.length - 1; - if (lastIsPlusFraction) { - fluid.addPlusFraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); - } else { - fluid.addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); - } - fluid.createDatabase(true); - if (lastIsPlusFraction) { - fluid.getCharacterization().getLumpingModel().setNumberOfPseudoComponents(12); - fluid.getCharacterization().setLumpingModel("PVTlumpingModel"); - fluid.getCharacterization().characterisePlusFraction(); - } - setMixingRule(); - fluid.setMultiPhaseCheck(true); - fluid.init(0); - return fluid; - } - /** *

* createFluid. @@ -304,6 +223,7 @@ public neqsim.thermo.system.SystemInterface addOilFractions(String[] charNames, */ public neqsim.thermo.system.SystemInterface createFluid(String[] componentNames, double[] flowrate, String unit) { + setThermoModel(); if (componentNames.length != flowrate.length) { logger.error("component names and mole fractions need to be same length..."); } @@ -374,7 +294,9 @@ public boolean isHasWater() { * @param hasWater a boolean */ public void setHasWater(boolean hasWater) { - hasWater = hasWater; + + this.hasWater = hasWater; + } /** @@ -396,7 +318,7 @@ public boolean isAutoSelectModel() { * @param autoSelectModel a boolean */ public void setAutoSelectModel(boolean autoSelectModel) { - autoSelectModel = autoSelectModel; + this.autoSelectModel = autoSelectModel; } /** diff --git a/src/main/java/neqsim/thermo/FluidCreator.java b/src/main/java/neqsim/thermo/FluidCreator.java new file mode 100644 index 000000000..d74b8dea6 --- /dev/null +++ b/src/main/java/neqsim/thermo/FluidCreator.java @@ -0,0 +1,61 @@ +package neqsim.thermo; + +import neqsim.thermo.system.SystemInterface; + +/** + * Used to generate fluids of type SystemInterface + *

+ * FluidCreator class. + *

+ * + * @author esol + * @version $Id: $Id + */ +public class FluidCreator { + + public static boolean hasWater = false; + public static boolean autoSelectModel = false; + public static String thermoModel = "srk"; + public static String thermoMixingRule = "classic"; + + /** + * @param componentNames name of components to be added to a fluid + * @return a fluid object (SystemInterface) + */ + public static SystemInterface create(String[] componentNames) { + Fluid fluid = new Fluid(); + fluid.setHasWater(hasWater); + fluid.setAutoSelectModel(autoSelectModel); + fluid.setThermoModel(thermoModel); + fluid.setThermoModel(thermoModel); + return fluid.create2(componentNames); + } + + /** + * @param componentNames name of components to be added to a fluid + * @param flowrate flow rate + * @param unit unit of flow rate + * @return a fluid object (SystemInterface) + */ + public static SystemInterface create(String[] componentNames, double[] flowrate, String unit) { + Fluid fluid = new Fluid(); + fluid.setHasWater(hasWater); + fluid.setAutoSelectModel(autoSelectModel); + fluid.setThermoModel(thermoModel); + fluid.setThermoModel(thermoModel); + return fluid.createFluid(componentNames, flowrate, unit); + } + + /**" + * @param fluidType fluid type can be "dry gas", "water", "air", "gas condensate", "combustion air"... + * @return + */ + public static SystemInterface create(String fluidType) { + Fluid fluid = new Fluid(); + fluid.setHasWater(hasWater); + fluid.setAutoSelectModel(autoSelectModel); + fluid.setThermoModel(thermoModel); + fluid.setThermoModel(thermoModel); + return fluid.create(fluidType); + } +} diff --git a/src/main/java/neqsim/thermo/system/SystemInterface.java b/src/main/java/neqsim/thermo/system/SystemInterface.java index bfa0c7fc1..562e50db0 100644 --- a/src/main/java/neqsim/thermo/system/SystemInterface.java +++ b/src/main/java/neqsim/thermo/system/SystemInterface.java @@ -2469,4 +2469,31 @@ public void setImplementedCompositionDeriativesofFugacity( /** {@inheritDoc} */ public void addToComponentNames(java.lang.String name); + + /** + *

+ * addCharacterized. + *

+ * + * @param charNames an array of {@link java.lang.String} objects + * @param charFlowrate an array of {@link double} objects + * @param molarMass an array of {@link double} objects + * @param relativedensity an array of {@link double} objects + */ + public void addOilFractions(String[] charNames, + double[] charFlowrate, double[] molarMass, double[] relativedensity, + boolean lastIsPlusFraction); + + /** + *

+ * addCharacterized. + *

+ * + * @param charNames an array of {@link java.lang.String} objects + * @param charFlowrate an array of {@link double} objects + * @param molarMass an array of {@link double} objects + * @param relativedensity an array of {@link double} objects + */ + public void addCharacterized(String[] charNames, double[] charFlowrate, double[] molarMass, + double[] relativedensity); } diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index 7f6707ad5..393af7c2e 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -5143,4 +5143,62 @@ private void setMolarFractions(double[] molefractions, String type) { init(0, i); } } + + /** + *

+ * addCharacterized. + *

+ * + * @param charNames an array of {@link java.lang.String} objects + * @param charFlowrate an array of {@link double} objects + * @param molarMass an array of {@link double} objects + * @param relativedensity an array of {@link double} objects + */ + public void addCharacterized(String[] charNames, double[] charFlowrate, double[] molarMass, + double[] relativedensity) { + if (charNames.length != charFlowrate.length) { + logger.error("component names and mole fractions need to be same length..."); + } + for (int i = 0; i < charNames.length; i++) { + addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); + } + } + + /** + *

+ * addOilFractions. + *

+ * + * @param charNames an array of {@link java.lang.String} objects + * @param charFlowrate an array of {@link double} objects + * @param molarMass an array of {@link double} objects + * @param relativedensity an array of {@link double} objects + * @param lastIsPlusFraction a boolean + */ + public void addOilFractions(String[] charNames, + double[] charFlowrate, double[] molarMass, double[] relativedensity, + boolean lastIsPlusFraction) { + if (charNames.length != charFlowrate.length) { + logger.error("component names and mole fractions need to be same length..."); + } + + for (int i = 0; i < charNames.length - 1; i++) { + addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); + } + int i = charNames.length - 1; + if (lastIsPlusFraction) { + addPlusFraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); + } else { + addTBPfraction(charNames[i], charFlowrate[i], molarMass[i], relativedensity[i]); + } + createDatabase(true); + if (lastIsPlusFraction) { + getCharacterization().getLumpingModel().setNumberOfPseudoComponents(12); + getCharacterization().setLumpingModel("PVTlumpingModel"); + getCharacterization().characterisePlusFraction(); + } + setMixingRule(getMixingRule()); + setMultiPhaseCheck(true); + init(0); + } } diff --git a/src/test/java/neqsim/thermo/FluidCreatorTest.java b/src/test/java/neqsim/thermo/FluidCreatorTest.java new file mode 100644 index 000000000..535296fd7 --- /dev/null +++ b/src/test/java/neqsim/thermo/FluidCreatorTest.java @@ -0,0 +1,26 @@ +package neqsim.thermo; + +import org.junit.jupiter.api.Test; +import neqsim.thermo.system.SystemInterface; + +public class FluidCreatorTest { + @Test + void testCreate() { + String[] componentNames = new String[]{"methane", "ethane"}; + SystemInterface fluid = FluidCreator.create(componentNames); + } + + @Test + void testCreate2() { + String fluidType = "air"; + SystemInterface fluid = FluidCreator.create(fluidType); + } + + @Test + void testCreate3() { + String[] componentNames = new String[] {"methane", "ethane"}; + double[] rate = new double[] {1.0, 1.0}; + String unit = "kg/sec"; + SystemInterface fluid = FluidCreator.create(componentNames, rate, unit); + } +}