Skip to content

Commit

Permalink
removed static variables from gerg (#512)
Browse files Browse the repository at this point in the history
* removed static variables from gerg

* removed more static variables in fluid creator
  • Loading branch information
EvenSol committed Aug 27, 2022
1 parent 8ee9edd commit ffe027c
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"java.configuration.updateBuildConfiguration": "interactive",
"[java]": {
"editor.defaultFormatter": "redhat.java",
"editor.defaultFormatter": "serikb.google-java-format",
"editor.formatOnSave": true,
},
"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public GasTurbine() {
public GasTurbine(String name) {
super(name);
// needs to be changed to gas tubing mechanical design
SystemInterface airThermoSystem = neqsim.thermo.Fluid.create("combustion air");
SystemInterface airThermoSystem = new neqsim.thermo.Fluid().create("combustion air");
airThermoSystem.createDatabase(true);
// airThermoSystem.display();
airStream = new Stream("airStream", airThermoSystem);
Expand Down
96 changes: 63 additions & 33 deletions src/main/java/neqsim/thermo/Fluid.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,40 @@
*/
public class Fluid {
static Logger logger = LogManager.getLogger(Fluid.class);
static neqsim.thermo.system.SystemInterface fluid = null;
private static boolean hasWater = false;
private static boolean autoSelectModel = false;
private static String thermoModel = "srk";
private static String thermoMixingRule = "classic";
neqsim.thermo.system.SystemInterface fluid = null;
private boolean hasWater = false;
private boolean autoSelectModel = false;
private String thermoModel = "srk";
private String thermoMixingRule = "classic";

private static void setThermoModel() {
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;
}

/**
*
*/
private void setThermoModel() {
if (thermoModel.equals("srk")) {
fluid = new neqsim.thermo.system.SystemSrkEos();
} else if (thermoModel.equals("pr")) {
Expand All @@ -31,7 +58,7 @@ private static void setThermoModel() {
}
}

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

Expand All @@ -43,7 +70,7 @@ private static void setMixingRule() {
* @param componentNames an array of {@link java.lang.String} objects
* @return a {@link neqsim.thermo.system.SystemInterface} object
*/
public static neqsim.thermo.system.SystemInterface create2(String[] componentNames) {
public neqsim.thermo.system.SystemInterface create2(String[] componentNames) {
double[] comp = new double[componentNames.length];
for (int i = 0; i < componentNames.length; i++) {
comp[i] = 1.0;
Expand All @@ -61,12 +88,13 @@ public static neqsim.thermo.system.SystemInterface create2(String[] componentNam
* @param unit a {@link java.lang.String} object
* @return a {@link neqsim.thermo.system.SystemInterface} object
*/
public static neqsim.thermo.system.SystemInterface create2(String[] componentNames,
public neqsim.thermo.system.SystemInterface create2(String[] componentNames,
double[] flowrate, String unit) {
setThermoModel();
createFluid(componentNames, flowrate, unit);
if (isHasWater() == true)
if (isHasWater() == true) {
fluid.addComponent("water", 0.1);
}
fluid.createDatabase(true);
setMixingRule();
if (isHasWater()) {
Expand All @@ -87,10 +115,10 @@ public static neqsim.thermo.system.SystemInterface create2(String[] componentNam
* @param fluidType a {@link java.lang.String} object
* @return a {@link neqsim.thermo.system.SystemInterface} object
*/
public static neqsim.thermo.system.SystemInterface create(String fluidType) {
public neqsim.thermo.system.SystemInterface create(String fluidType) {
String[] compNames = null;
double[] flowrate = null;
setThermoModel();
this.setThermoModel();
if (fluidType.equals("water")) {
compNames = new String[] {"water"};
flowrate = new double[] {1.0};
Expand Down Expand Up @@ -189,8 +217,9 @@ public static neqsim.thermo.system.SystemInterface create(String fluidType) {
return null;
}

if (isHasWater() == true)
if (isHasWater() == true) {
fluid.addComponent("water", 0.1);
}
fluid.createDatabase(true);
setMixingRule();
if (isHasWater()) {
Expand All @@ -213,7 +242,7 @@ public static neqsim.thermo.system.SystemInterface create(String fluidType) {
* @param molarMass an array of {@link double} objects
* @param relativedensity an array of {@link double} objects
*/
public static void addCharacterized(String[] charNames, double[] charFlowrate, double[] molarMass,
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...");
Expand All @@ -235,7 +264,7 @@ public static void addCharacterized(String[] charNames, double[] charFlowrate, d
* @param lastIsPlusFraction a boolean
* @return a {@link neqsim.thermo.system.SystemInterface} object
*/
public static neqsim.thermo.system.SystemInterface addOilFractions(String[] charNames,
public neqsim.thermo.system.SystemInterface addOilFractions(String[] charNames,
double[] charFlowrate, double[] molarMass, double[] relativedensity,
boolean lastIsPlusFraction) {
if (charNames.length != charFlowrate.length) {
Expand Down Expand Up @@ -273,7 +302,7 @@ public static neqsim.thermo.system.SystemInterface addOilFractions(String[] char
* @param unit a {@link java.lang.String} object
* @return a {@link neqsim.thermo.system.SystemInterface} object
*/
public static neqsim.thermo.system.SystemInterface createFluid(String[] componentNames,
public neqsim.thermo.system.SystemInterface createFluid(String[] componentNames,
double[] flowrate, String unit) {
if (componentNames.length != flowrate.length) {
logger.error("component names and mole fractions need to be same length...");
Expand All @@ -293,7 +322,7 @@ public static neqsim.thermo.system.SystemInterface createFluid(String[] componen
*
* @param name a {@link java.lang.String} object
*/
public static void addComponment(String name) {
public void addComponment(String name) {
fluid.addComponent(name, 1.0);
fluid.createDatabase(true);
fluid.setMixingRule(2);
Expand All @@ -311,16 +340,17 @@ public static void addComponment(String name) {
* @param args an array of {@link java.lang.String} objects
*/
public static void main(String[] args) {
neqsim.thermo.Fluid.setHasWater(true);
neqsim.thermo.system.SystemInterface fluid = neqsim.thermo.Fluid.create("petrol");
neqsim.thermo.Fluid fluidCreator = new neqsim.thermo.Fluid();

neqsim.thermo.system.SystemInterface fluid = fluidCreator.create("petrol");
fluid.display();

neqsim.thermo.system.SystemInterface fluid2 = neqsim.thermo.Fluid.create("dry gas");
neqsim.thermo.system.SystemInterface fluid2 = fluidCreator.create("dry gas");
fluid2.display();
fluid2.getNumberOfComponents();

neqsim.thermo.system.SystemInterface fluid3 =
neqsim.thermo.Fluid.create("black oil with water");
fluidCreator.create("black oil with water");
fluid3.display();
fluid3.getNumberOfComponents();
}
Expand All @@ -332,7 +362,7 @@ public static void main(String[] args) {
*
* @return a boolean
*/
public static boolean isHasWater() {
public boolean isHasWater() {
return hasWater;
}

Expand All @@ -343,8 +373,8 @@ public static boolean isHasWater() {
*
* @param hasWater a boolean
*/
public static void setHasWater(boolean hasWater) {
Fluid.hasWater = hasWater;
public void setHasWater(boolean hasWater) {
hasWater = hasWater;
}

/**
Expand All @@ -354,7 +384,7 @@ public static void setHasWater(boolean hasWater) {
*
* @return a boolean
*/
public static boolean isAutoSelectModel() {
public boolean isAutoSelectModel() {
return autoSelectModel;
}

Expand All @@ -365,8 +395,8 @@ public static boolean isAutoSelectModel() {
*
* @param autoSelectModel a boolean
*/
public static void setAutoSelectModel(boolean autoSelectModel) {
Fluid.autoSelectModel = autoSelectModel;
public void setAutoSelectModel(boolean autoSelectModel) {
autoSelectModel = autoSelectModel;
}

/**
Expand All @@ -376,7 +406,7 @@ public static void setAutoSelectModel(boolean autoSelectModel) {
*
* @return a {@link java.lang.String} object
*/
public static String getThermoModel() {
public String getThermoModel() {
return thermoModel;
}

Expand All @@ -387,8 +417,8 @@ public static String getThermoModel() {
*
* @param thermoModel a {@link java.lang.String} object
*/
public static void setThermoModel(String thermoModel) {
Fluid.thermoModel = thermoModel;
public void setThermoModel(String thermoModel) {
this.thermoModel = thermoModel;
}

/**
Expand All @@ -398,7 +428,7 @@ public static void setThermoModel(String thermoModel) {
*
* @return a {@link java.lang.String} object
*/
public static String getThermoMixingRule() {
public String getThermoMixingRule() {
return thermoMixingRule;
}

Expand All @@ -409,7 +439,7 @@ public static String getThermoMixingRule() {
*
* @param thermoMixingRule a {@link java.lang.String} object
*/
public static void setThermoMixingRule(String thermoMixingRule) {
Fluid.thermoMixingRule = thermoMixingRule;
public void setThermoMixingRule(String thermoMixingRule) {
this.thermoMixingRule = thermoMixingRule;
}
}
Loading

0 comments on commit ffe027c

Please sign in to comment.