Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fluid creator #514

Merged
merged 7 commits into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 12 additions & 90 deletions src/main/java/neqsim/thermo/Fluid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -58,10 +41,6 @@ private void setThermoModel() {
}
}

private void setMixingRule() {
fluid.setMixingRule(getThermoMixingRule());
}

/**
* <p>
* create2.
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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"};
Expand All @@ -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"};
Expand All @@ -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"};
Expand All @@ -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",
Expand All @@ -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};
Expand All @@ -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);
}
Expand All @@ -232,66 +211,6 @@ public neqsim.thermo.system.SystemInterface create(String fluidType) {
return fluid;
}

/**
* <p>
* addCharacterized.
* </p>
*
* @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]);
}
}

/**
* <p>
* addOilFractions.
* </p>
*
* @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;
}

/**
* <p>
* createFluid.
Expand All @@ -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...");
}
Expand Down Expand Up @@ -374,7 +294,9 @@ public boolean isHasWater() {
* @param hasWater a boolean
*/
public void setHasWater(boolean hasWater) {
hasWater = hasWater;

this.hasWater = hasWater;

}

/**
Expand All @@ -396,7 +318,7 @@ public boolean isAutoSelectModel() {
* @param autoSelectModel a boolean
*/
public void setAutoSelectModel(boolean autoSelectModel) {
autoSelectModel = autoSelectModel;
this.autoSelectModel = autoSelectModel;
}

/**
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/neqsim/thermo/FluidCreator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package neqsim.thermo;

import neqsim.thermo.system.SystemInterface;

/**
* Used to generate fluids of type SystemInterface
* <p>
* FluidCreator class.
* </p>
*
* @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);
}
}
27 changes: 27 additions & 0 deletions src/main/java/neqsim/thermo/system/SystemInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -2469,4 +2469,31 @@ public void setImplementedCompositionDeriativesofFugacity(

/** {@inheritDoc} */
public void addToComponentNames(java.lang.String name);

/**
* <p>
* addCharacterized.
* </p>
*
* @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);

/**
* <p>
* addCharacterized.
* </p>
*
* @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);
}
58 changes: 58 additions & 0 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5143,4 +5143,62 @@ private void setMolarFractions(double[] molefractions, String type) {
init(0, i);
}
}

/**
* <p>
* addCharacterized.
* </p>
*
* @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]);
}
}

/**
* <p>
* addOilFractions.
* </p>
*
* @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);
}
}
26 changes: 26 additions & 0 deletions src/test/java/neqsim/thermo/FluidCreatorTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}