use of org.vcell.vis.vtk.VtkService in project vcell by virtualcell.
the class ComsolMeshReader method read.
public static void read(VisMesh visMesh, File comsolFile) throws IOException {
ArrayList<Field> fields = new ArrayList<Field>();
try (BufferedReader br = new BufferedReader(new FileReader(comsolFile))) {
//
// read header lines
//
String model = readStringParameter(br.readLine(), "Model");
String version = readStringParameter(br.readLine(), "Version");
String date = readStringParameter(br.readLine(), "Date");
int dimension = readIntegerParameter(br.readLine(), "Dimension");
int numNodes = readIntegerParameter(br.readLine(), "Nodes");
int numElements = readIntegerParameter(br.readLine(), "Elements");
int numExpressions = readIntegerParameter(br.readLine(), "Expressions");
String description = readStringParameter(br.readLine(), "Description");
String lengthUnit = readStringParameter(br.readLine(), "Length unit");
visMesh.setDimension(dimension);
//
// read coordinates (and set points, origin and extent on VisMesh
//
readCoordinates(br, visMesh, numNodes);
List<VisPoint> points = visMesh.getPoints();
double minX = Double.POSITIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY;
double minZ = Double.POSITIVE_INFINITY;
double maxX = Double.NEGATIVE_INFINITY;
double maxY = Double.NEGATIVE_INFINITY;
double maxZ = Double.NEGATIVE_INFINITY;
for (VisPoint p : points) {
minX = Math.min(p.x, minX);
minY = Math.min(p.y, minY);
minZ = Math.min(p.z, minZ);
maxX = Math.max(p.x, maxX);
maxY = Math.max(p.y, maxY);
maxZ = Math.max(p.z, maxZ);
}
visMesh.setExtent(new Vect3D(maxX - minX, maxY - minY, maxZ - minZ));
visMesh.setOrigin(new Vect3D(minX, minY, minZ));
//
// read triangles
//
readElements(br, visMesh, numElements);
//
for (int fieldIndex = 0; fieldIndex < numExpressions; fieldIndex++) {
fields.add(readField(br, numNodes));
}
}
VtkService vtkService = VtkService.getInstance();
String prefix = comsolFile.getName().replace(".comsoldat", "");
File vtuFile = new File(comsolFile.getParentFile(), prefix + ".vtu");
File indexFile = new File(comsolFile.getParentFile(), prefix + ".comsolindex");
vtkService.writeComsolVtkGridAndIndexData(visMesh, "domain", vtuFile, indexFile);
HashSet<Double> times = new HashSet<Double>();
for (Field field : fields) {
times.add(field.time);
int timeIndex = times.size() - 1;
File outputMeshFile = new File(comsolFile.getParentFile(), prefix + "_" + field.name + "_" + timeIndex + ".vtu");
VisMeshUtils.writePointDataToVtu(vtuFile, field.name, field.data, outputMeshFile);
}
}
Aggregations