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

fix read kij from eclipse #892

Merged
merged 2 commits into from
Dec 24, 2023
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
9 changes: 9 additions & 0 deletions src/main/java/neqsim/thermo/mixingRule/EosMixingRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ public double getBinaryInteractionParameter(int i, int j) {
return intparam[i][j];
}

@Override
public double[][] getBinaryInteractionParameters() {
return intparam;
}

public void prettyPrintKij(){

}

@Override
public double getBinaryInteractionParameterT1(int i, int j) {
if (i == j) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public double calcAiT(int compNumb, PhaseInterface phase, double temperature, do
*/
public PhaseInterface getGEPhase();

public double[][] getBinaryInteractionParameters();
// double calcA2(PhaseInterface phase, double temperature, double pressure, int
// numbcomp);
// double calcB2(PhaseInterface phase, double temperature, double pressure, int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.thermo.ThermodynamicConstantsInterface;
Expand Down Expand Up @@ -250,44 +252,30 @@ public static SystemInterface read(String inputFile) {
}
}
if (st.equals("BIC")) {
int numb = 0;
// kij = new double[ZI.size()][ZI.size()];
int addedComps = 0;
kij = new double[names.size()][names.size()];
int lengthLastLine = 0;
List<String> list = new ArrayList<String>();
while ((st = br.readLine().replace("/", "")) != null) {
numb++;
if (st.startsWith("--") || st.isEmpty()) {
break;
}

// String[] arr = st.replace(" ","").split(" ");
String[] arr = st.split(" ");
if (arr.length == 1) {
break;
List<String> templist = new ArrayList<String>(Arrays.asList(arr));
list.addAll(templist);
list.removeAll(Arrays.asList("", null));
if (lengthLastLine >= list.size()) {
continue;
}

// List<String> list = Arrays.asList(arr);
for (int i = 0; i < arr.length - 1; i++) {
BIC.add(Double.parseDouble(arr[i + 1]));
kij[numb][i] = Double.parseDouble(arr[i + 1]);
kij[i][numb] = kij[numb][i];
// kij[numb-1][i] = Double.parseDouble(arr[i+1]);
// kij[i][numb-1] = kij[numb-1][i] ;
lengthLastLine = list.size();
for (int i = 0; i < list.size(); i++) {
BIC.add(Double.parseDouble(list.get(i)));
kij[i][addedComps + 1] = Double.parseDouble(list.get(i));
kij[addedComps + 1][i] = kij[i][addedComps + 1];
}
// numb++;
Double.parseDouble(arr[1]);
// System.out.println(list.size());
// System.out.println(st);
// BIC.add(Double.parseDouble(st));
addedComps++;
list.clear();
}

/*
* numb =0;
*
* for (int i = 0; i < names.size(); i++) { for (int j = i; j < names.size(); j++) {
* if(i==j) continue; //System.out.println("ij " + i + " " + j+ " " + BIC.get(numb));
* System.out.println("ij " + i + " " + j+ " " + kij[i][j] ); //kij[i][j] = BIC.get(numb);
* //kij[j][i] = kij[i][j]; numb++; } }
*/
}
}
for (int counter = 0; counter < names.size(); counter++) {
Expand Down
36 changes: 34 additions & 2 deletions src/main/java/neqsim/thermo/util/readwrite/TablePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* A utility class for pretty printing a 2D string table.
*/
public class TablePrinter implements Serializable {

/**
* Prints a 2D string table in a formatted and visually appealing way.
*
Expand Down Expand Up @@ -68,7 +69,7 @@ private static void printHorizontalLine(int[] columnWidths) {
/**
* Prints a row of the table with appropriate padding based on column widths.
*
* @param row The row of data to be printed.
* @param row The row of data to be printed.
* @param columnWidths An array containing the maximum width of each column.
*/
private static void printRow(String[] row, int[] columnWidths) {
Expand All @@ -84,4 +85,35 @@ private static void printRow(String[] row, int[] columnWidths) {
}
System.out.println();
}
}

/**
* Prints a 2D string table in a formatted and visually appealing way.
*
* @param table The 2D double table to be printed.
*/
public static void printTable(double[][] table) {
printTable(convertDoubleToString(table));
}

/**
* Returns a 2D string table in a formatted and visually appealing way.
*
* @param doubleArray The 2D double table to be printed.
*/
public static String[][] convertDoubleToString(double[][] doubleArray) {
// Initialize the 2D String array with the same dimensions as the double array
String[][] stringArray = new String[doubleArray.length][];

for (int i = 0; i < doubleArray.length; i++) {
// Initialize the inner array with the same length as the corresponding double array
stringArray[i] = new String[doubleArray[i].length];

for (int j = 0; j < doubleArray[i].length; j++) {
// Convert each double value to string and store it
stringArray[i][j] = String.valueOf(doubleArray[i][j]);
}
}

return stringArray;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ void testReadAndAddFluids2() throws IOException {
testSystem.setPressure(100.0, "bara");
testSystem.setTemperature(25.0, "C");
testOps.TPflash();

// neqsim.thermo.util.readwrite.TablePrinter.printTable((((PhaseEos
// )testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameters()));


}

@Test
Expand Down
Loading