Search in sources :

Example 1 with VtkService

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);
    }
}
Also used : VtkService(org.vcell.vis.vtk.VtkService) ArrayList(java.util.ArrayList) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) Vect3D(org.vcell.vis.vismesh.thrift.Vect3D) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Vect3D (org.vcell.vis.vismesh.thrift.Vect3D)1 VisPoint (org.vcell.vis.vismesh.thrift.VisPoint)1 VtkService (org.vcell.vis.vtk.VtkService)1