Search in sources :

Example 1 with FiniteVolumeIndexData

use of org.vcell.vis.vismesh.thrift.FiniteVolumeIndexData in project vcell by virtualcell.

the class CartesianMeshVtkFileWriter method getVtuMeshData.

public double[] getVtuMeshData(VCellSimFiles vcellFiles, OutputContext outputContext, SimDataBlock simDataBlock, File destinationDirectory, VtuVarInfo var, final double time) throws Exception {
    // 
    // read the "empty" vtk mesh from a file (create the files if necessary)
    // read the indicing arrays from this file to know how to reorder the data into the vtk cell data order.
    // return the vtk cell data
    // 
    File finiteVolumeIndexDataFile = getFiniteVolumeIndexDataFileName(vcellFiles, var.domainName);
    if (!finiteVolumeIndexDataFile.exists()) {
        writeEmptyMeshFiles(vcellFiles, destinationDirectory, null);
        if (!finiteVolumeIndexDataFile.exists()) {
            throw new RuntimeException("failed to find finite volume index file " + finiteVolumeIndexDataFile.getAbsolutePath());
        }
    }
    FiniteVolumeIndexData finiteVolumeIndexData = VisMeshUtils.readFiniteVolumeIndexData(finiteVolumeIndexDataFile);
    int maxGlobalIndex = 0;
    int maxRegionIndex = 0;
    for (FiniteVolumeIndex fvIndex : finiteVolumeIndexData.finiteVolumeIndices) {
        maxGlobalIndex = Math.max((int) fvIndex.globalIndex, maxGlobalIndex);
        maxRegionIndex = Math.max((int) fvIndex.regionIndex, maxRegionIndex);
    }
    int numCells = finiteVolumeIndexData.finiteVolumeIndices.size();
    String vcellName = var.name;
    System.out.println("CartesianMeshVtkFileWriter.getVtuMeshData(): reading data for variable " + vcellName + " at time " + time);
    double[] cartesianMeshData = simDataBlock.getData();
    // 
    // have to reorder the cartesian mesh data according to the vtk mesh cell indices (may not even be the same length)
    // 
    double[] vtkData = new double[numCells];
    if (cartesianMeshData.length >= numCells) {
        // data is not from region variable, uses global indices
        for (int vtkCellIndex = 0; vtkCellIndex < numCells; vtkCellIndex++) {
            int cartesianMeshGlobalIndex = (int) finiteVolumeIndexData.finiteVolumeIndices.get(vtkCellIndex).globalIndex;
            vtkData[vtkCellIndex] = cartesianMeshData[cartesianMeshGlobalIndex];
        }
    } else {
        // data is from region variable, uses region indices
        for (int vtkCellIndex = 0; vtkCellIndex < numCells; vtkCellIndex++) {
            int cartesianMeshRegionIndex = (int) finiteVolumeIndexData.finiteVolumeIndices.get(vtkCellIndex).regionIndex;
            vtkData[vtkCellIndex] = cartesianMeshData[cartesianMeshRegionIndex];
        }
    }
    return vtkData;
}
Also used : FiniteVolumeIndex(org.vcell.vis.vismesh.thrift.FiniteVolumeIndex) FiniteVolumeIndexData(org.vcell.vis.vismesh.thrift.FiniteVolumeIndexData) File(java.io.File)

Example 2 with FiniteVolumeIndexData

use of org.vcell.vis.vismesh.thrift.FiniteVolumeIndexData in project vcell by virtualcell.

the class VisMeshUtils method readFiniteVolumeIndexData.

public static FiniteVolumeIndexData readFiniteVolumeIndexData(File finiteVolumeIndexFile) throws IOException {
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    byte[] blob = FileUtils.readFileToByteArray(finiteVolumeIndexFile);
    FiniteVolumeIndexData finiteVolumeIndexData = new FiniteVolumeIndexData();
    try {
        deserializer.deserialize(finiteVolumeIndexData, blob);
    } catch (TException e) {
        e.printStackTrace();
        throw new IOException("error reading FiniteVolumeIndexData from file " + finiteVolumeIndexFile.getPath() + ": " + e.getMessage(), e);
    }
    return finiteVolumeIndexData;
}
Also used : TException(org.apache.thrift.TException) TDeserializer(org.apache.thrift.TDeserializer) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) IOException(java.io.IOException) FiniteVolumeIndexData(org.vcell.vis.vismesh.thrift.FiniteVolumeIndexData)

Aggregations

FiniteVolumeIndexData (org.vcell.vis.vismesh.thrift.FiniteVolumeIndexData)2 File (java.io.File)1 IOException (java.io.IOException)1 TDeserializer (org.apache.thrift.TDeserializer)1 TException (org.apache.thrift.TException)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 FiniteVolumeIndex (org.vcell.vis.vismesh.thrift.FiniteVolumeIndex)1