Skip to content

Commit

Permalink
Update classes
Browse files Browse the repository at this point in the history
  • Loading branch information
niccolotubini committed Oct 3, 2021
1 parent 764bed8 commit d53178d
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public class Mesh2DMain {
public void process() throws IOException {

if (step == 0) {

long startTime = System.nanoTime();

elementsCentroidsCoordinates = new ArrayList<Double[]>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ReadCSVStructured2D {
public String fileName = null;

@In
public String splitter = " ";
public String splitter = ",";

@In
public boolean printFile = false;
Expand Down Expand Up @@ -69,114 +69,116 @@ public class ReadCSVStructured2D {
private int nElements = -999;
private int nBorderEdges = -999;

// private int step = 0;
private int step = 0;

/**
* @param args
* @throws IOException
*/
@Initialize
@Execute
public void process() throws IOException {

if(step==0) {

verticesCoordinates.add(0, new Double[] {-9999.0,-9999.0});
elementsVertices.add(0, new Integer[] {-9999,-9999,-9999});
elementsLabel.add(0, -9999);
borderEdgesVertices.add(0, new Integer[] {-9999,-9999});
borderEdgesLabel.add(0, -9999);

File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);

String line;
System.out.println("Opened the file: " + fileName + "\n\n");

if(printFile == true) {
while((line = br.readLine()) != null){
System.out.println(line);
}
}

verticesCoordinates.add(0, new Double[] {-9999.0,-9999.0});
elementsVertices.add(0, new Integer[] {-9999,-9999,-9999});
elementsLabel.add(0, -9999);
borderEdgesVertices.add(0, new Integer[] {-9999,-9999});
borderEdgesLabel.add(0, -9999);
int iLine = 0;
while((line = br.readLine()) != null){

File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
String[] lineContent = line.split(splitter);

String line;
System.out.println("Opened the file: " + fileName + "\n\n");

if(printFile == true) {
while((line = br.readLine()) != null){
System.out.println(line);
}
}

int iLine = 0;
while((line = br.readLine()) != null){

String[] lineContent = line.split(splitter);

if(iLine==0) {

nVertices = Integer.valueOf(lineContent[0]);
nElements = Integer.valueOf(lineContent[1]);
nBorderEdges = Integer.valueOf(lineContent[2]);

} else if(iLine>0 && iLine<=nVertices) {

verticesCoordinates.add(iLine, new Double[] { Double.valueOf(lineContent[0]),Double.valueOf(lineContent[1]) } );

} else if(iLine>nVertices && iLine<=nVertices+nElements) {

elementsVertices.add(iLine-nVertices, new Integer[] { Integer.valueOf(lineContent[0]),Integer.valueOf(lineContent[1]),
Integer.valueOf(lineContent[2]),Integer.valueOf(lineContent[3]) } );
elementsLabel.add(iLine-nVertices, Integer.valueOf(lineContent[4]));

} else {

borderEdgesVertices.add(iLine-(nVertices+nElements), new Integer[] {-9999, -9999} );
borderEdgesLabel.add(iLine-(nVertices+nElements), -9999);

if (Integer.valueOf(lineContent[2]) == -1) {
// this is an internal boundary
} else {

borderEdgesVertices.set(iLine-(nVertices+nElements), new Integer[] { Integer.valueOf(lineContent[0]),Integer.valueOf(lineContent[1]) } );
borderEdgesLabel.set(iLine-(nVertices+nElements), Integer.valueOf(lineContent[2]));

if(iLine==0) {

nVertices = Integer.valueOf(lineContent[0]);
nElements = Integer.valueOf(lineContent[1]);
nBorderEdges = Integer.valueOf(lineContent[2]);

} else if(iLine>0 && iLine<=nVertices) {

verticesCoordinates.add(iLine, new Double[] { Double.valueOf(lineContent[0]),Double.valueOf(lineContent[1]) } );

} else if(iLine>nVertices && iLine<=nVertices+nElements) {

elementsVertices.add(iLine-nVertices, new Integer[] { Integer.valueOf(lineContent[0]),Integer.valueOf(lineContent[1]),
Integer.valueOf(lineContent[2]),Integer.valueOf(lineContent[3]) } );
elementsLabel.add(iLine-nVertices, Integer.valueOf(lineContent[4]));

} else {

borderEdgesVertices.add(iLine-(nVertices+nElements), new Integer[] {-9999, -9999} );
borderEdgesLabel.add(iLine-(nVertices+nElements), -9999);

if (Integer.valueOf(lineContent[2]) == -1) {
// this is an internal boundary
} else {

borderEdgesVertices.set(iLine-(nVertices+nElements), new Integer[] { Integer.valueOf(lineContent[0]),Integer.valueOf(lineContent[1]) } );
borderEdgesLabel.set(iLine-(nVertices+nElements), Integer.valueOf(lineContent[2]));

}
}

iLine ++;

}

iLine ++;
br.close();
System.out.println("Reading mesh file completed.");

}

br.close();
System.out.println("Reading mesh file completed.");

/*
* Check informations are correctly stored
*/
if(checkData == true) {

System.out.println("\n\t nVertices : " +nVertices);
System.out.println("\t nElements : " +nElements);
System.out.println("\t nBorderEdges : " +nBorderEdges);

/*
* Check informations are correctly stored
*/
if(checkData == true) {

System.out.println("\n\t nVertices : " +nVertices);
System.out.println("\t nElements : " +nElements);
System.out.println("\t nBorderEdges : " +nBorderEdges);
System.out.println("\n Vertices set :");
for(int vertex=1; vertex<verticesCoordinates.size(); vertex++) {
System.out.println(" " + vertex + " : "+ verticesCoordinates.get(vertex)[0] + "," +verticesCoordinates.get(vertex)[1]);
}

System.out.println("\n Vertices set :");
for(int vertex=1; vertex<verticesCoordinates.size(); vertex++) {
System.out.println(" " + vertex + " : "+ verticesCoordinates.get(vertex)[0] + "," +verticesCoordinates.get(vertex)[1]);
}
System.out.println("\n Elements' vertices :");
for(int element=1; element<elementsVertices.size(); element++) {
System.out.println(" " + element + " : "+ elementsVertices.get(element)[0] + "," +elementsVertices.get(element)[1]
+ "," +elementsVertices.get(element)[2] + "," +elementsVertices.get(element)[3] + " ; " + elementsLabel.get(element));
}

System.out.println("\n Elements' vertices :");
for(int element=1; element<elementsVertices.size(); element++) {
System.out.println(" " + element + " : "+ elementsVertices.get(element)[0] + "," +elementsVertices.get(element)[1]
+ "," +elementsVertices.get(element)[2] + "," +elementsVertices.get(element)[3] + " ; " + elementsLabel.get(element));
}
System.out.println("\n Border edges :");
for(int edge=1; edge<borderEdgesVertices.size(); edge++) {
System.out.println(" " + edge + " : "+ borderEdgesVertices.get(edge)[0] + "," +borderEdgesVertices.get(edge)[1]
+ " ; " + borderEdgesLabel.get(edge));
}

System.out.println("\n Border edges :");
for(int edge=1; edge<borderEdgesVertices.size(); edge++) {
System.out.println(" " + edge + " : "+ borderEdgesVertices.get(edge)[0] + "," +borderEdgesVertices.get(edge)[1]
+ " ; " + borderEdgesLabel.get(edge));
}

}

System.out.println("\nExit ReadCSVStructured\n\n\n");
System.out.println("\nExit ReadCSVStructured\n\n\n");

// }
}

// step++;
step++;

}// close @Execute

public static void main(String[] args) throws IOException {
Expand Down
Loading

0 comments on commit d53178d

Please sign in to comment.