Search in sources :

Example 1 with FiniteVolumeIndex

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

the class CartesianMeshMapping method fromMesh3DMembrane.

private VisMesh fromMesh3DMembrane(CartesianMesh cartesianMesh, String domainName) {
    ISize size = cartesianMesh.getSize();
    int numX = size.getX();
    int numY = size.getY();
    int dimension = 3;
    Vect3D origin = new Vect3D(cartesianMesh.getOrigin().x, cartesianMesh.getOrigin().y, cartesianMesh.getOrigin().z);
    Vect3D extent = new Vect3D(cartesianMesh.getExtent().x, cartesianMesh.getExtent().y, cartesianMesh.getExtent().z);
    // invoke VisMesh() constructor
    VisMesh visMesh = new VisMesh(dimension, origin, extent);
    int currPointIndex = 0;
    HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
    List<MembraneElement> membraneElements = cartesianMesh.getMembraneElements(domainName);
    for (MembraneElement membraneElement : membraneElements) {
        // inside
        int insideVolumeIndex = membraneElement.getInsideVolumeIndex();
        int insideI = insideVolumeIndex % numX;
        int insideJ = (insideVolumeIndex % (numX * numY)) / numX;
        int insideK = insideVolumeIndex / (numX * numY);
        Box3D insideBox = cartesianMesh.getVolumeElementBox(insideI, insideJ, insideK);
        // outside
        int outsideVolumeIndex = membraneElement.getOutsideVolumeIndex();
        int outsideI = outsideVolumeIndex % numX;
        int outsideJ = (outsideVolumeIndex % (numX * numY)) / numX;
        int outsideK = outsideVolumeIndex / (numX * numY);
        VisPoint p1Coord;
        VisPoint p2Coord;
        VisPoint p3Coord;
        VisPoint p4Coord;
        if (insideI == outsideI + 1) {
            // x-   z cross y
            double x = insideBox.x_lo;
            p1Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_lo);
            p2Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_hi);
            p3Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_hi);
            p4Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_lo);
        } else if (outsideI == insideI + 1) {
            // x+   y cross z
            double x = insideBox.x_hi;
            p1Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_lo);
            p2Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_lo);
            p3Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_hi);
            p4Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_hi);
        } else if (insideJ == outsideJ + 1) {
            // y-   x cross z
            double y = insideBox.y_lo;
            p1Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_lo);
            p2Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_lo);
            p3Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_hi);
            p4Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_hi);
        } else if (outsideJ == insideJ + 1) {
            // y+   z cross x
            double y = insideBox.y_hi;
            p1Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_lo);
            p2Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_hi);
            p3Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_hi);
            p4Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_lo);
        } else if (insideK == outsideK + 1) {
            // z-   y cross x
            double z = insideBox.z_lo;
            p1Coord = new VisPoint(insideBox.x_lo, insideBox.y_lo, z);
            p2Coord = new VisPoint(insideBox.x_lo, insideBox.y_hi, z);
            p3Coord = new VisPoint(insideBox.x_hi, insideBox.y_hi, z);
            p4Coord = new VisPoint(insideBox.x_hi, insideBox.y_lo, z);
        } else if (outsideK == insideK + 1) {
            // z+   x cross y
            double z = insideBox.z_hi;
            p1Coord = new VisPoint(insideBox.x_lo, insideBox.y_lo, z);
            p2Coord = new VisPoint(insideBox.x_hi, insideBox.y_lo, z);
            p3Coord = new VisPoint(insideBox.x_hi, insideBox.y_hi, z);
            p4Coord = new VisPoint(insideBox.x_lo, insideBox.y_hi, z);
        } else {
            throw new RuntimeException("inside/outside volume indices not reconciled in membraneElement " + membraneElement.getMembraneIndex() + " in domain " + domainName);
        }
        // 
        // make sure vertices are added to model without duplicates and get the assigned identifier.
        // 
        String p1Key = toStringKey(p1Coord);
        Integer i1 = pointDict.get(p1Key);
        if (i1 == null) {
            pointDict.put(p1Key, currPointIndex);
            i1 = currPointIndex;
            visMesh.addToPoints(p1Coord);
            currPointIndex++;
        }
        String p2Key = toStringKey(p2Coord);
        Integer i2 = pointDict.get(p2Key);
        if (i2 == null) {
            pointDict.put(p2Key, currPointIndex);
            i2 = currPointIndex;
            visMesh.addToPoints(p2Coord);
            currPointIndex++;
        }
        String p3Key = toStringKey(p3Coord);
        Integer i3 = pointDict.get(p3Key);
        if (i3 == null) {
            pointDict.put(p3Key, currPointIndex);
            i3 = currPointIndex;
            visMesh.addToPoints(p3Coord);
            currPointIndex++;
        }
        String p4Key = toStringKey(p4Coord);
        Integer i4 = pointDict.get(p4Key);
        if (i4 == null) {
            pointDict.put(p4Key, currPointIndex);
            i4 = currPointIndex;
            visMesh.addToPoints(p4Coord);
            currPointIndex++;
        }
        VisPolygon quad = new VisPolygon(Arrays.asList(new Integer[] { i1, i2, i3, i4 }));
        quad.setFiniteVolumeIndex(new FiniteVolumeIndex(membraneElement.getMembraneIndex(), cartesianMesh.getMembraneRegionIndex(membraneElement.getMembraneIndex())));
        // print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
        visMesh.addToPolygons(quad);
    }
    return visMesh;
}
Also used : FiniteVolumeIndex(org.vcell.vis.vismesh.thrift.FiniteVolumeIndex) HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) Box3D(org.vcell.vis.core.Box3D) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) Vect3D(org.vcell.vis.vismesh.thrift.Vect3D) VisMesh(org.vcell.vis.vismesh.thrift.VisMesh) VisPolygon(org.vcell.vis.vismesh.thrift.VisPolygon) MembraneElement(org.vcell.vis.vcell.MembraneElement) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint)

Example 2 with FiniteVolumeIndex

use of org.vcell.vis.vismesh.thrift.FiniteVolumeIndex 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 3 with FiniteVolumeIndex

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

the class CartesianMeshMapping method fromMesh2DVolume.

private VisMesh fromMesh2DVolume(CartesianMesh cartesianMesh, String domainName) {
    ISize size = cartesianMesh.getSize();
    int numX = size.getX();
    int numY = size.getY();
    int numZ = size.getZ();
    int dimension = 2;
    int z = 0;
    Vect3D origin = new Vect3D(cartesianMesh.getOrigin().x, cartesianMesh.getOrigin().y, cartesianMesh.getOrigin().z);
    Vect3D extent = new Vect3D(cartesianMesh.getExtent().x, cartesianMesh.getExtent().y, cartesianMesh.getExtent().z);
    // invoke VisMesh() constructor
    VisMesh visMesh = new VisMesh(dimension, origin, extent);
    int currPointIndex = 0;
    HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
    List<Integer> volumeRegionIDs = cartesianMesh.getVolumeRegionIDs(domainName);
    int volumeIndex = 0;
    for (int k = 0; k < numZ; k++) {
        for (int j = 0; j < numY; j++) {
            for (int i = 0; i < numX; i++) {
                int regionIndex = cartesianMesh.getVolumeRegionIndex(volumeIndex);
                if (volumeRegionIDs.contains(regionIndex)) {
                    Box3D element = cartesianMesh.getVolumeElementBox(i, j, k);
                    double minX = element.x_lo;
                    double maxX = element.x_hi;
                    double minY = element.y_lo;
                    double maxY = element.y_hi;
                    // 
                    // counter clockwise points for a VisPolygon ... initially a quad ... then may be
                    // 
                    // minX,minY
                    // minX,maxY
                    // maxX,maxY
                    // maxX,minY
                    // 
                    VisPoint p1Coord = new VisPoint(minX, minY, z);
                    String p1Key = toStringKey(p1Coord);
                    Integer i1 = pointDict.get(p1Key);
                    if (i1 == null) {
                        pointDict.put(p1Key, currPointIndex);
                        i1 = currPointIndex;
                        visMesh.addToPoints(p1Coord);
                        currPointIndex++;
                    }
                    VisPoint p2Coord = new VisPoint(minX, maxY, z);
                    String p2Key = toStringKey(p2Coord);
                    Integer i2 = pointDict.get(p2Key);
                    if (i2 == null) {
                        pointDict.put(p2Key, currPointIndex);
                        i2 = currPointIndex;
                        visMesh.addToPoints(p2Coord);
                        currPointIndex++;
                    }
                    VisPoint p3Coord = new VisPoint(maxX, maxY, z);
                    String p3Key = toStringKey(p3Coord);
                    Integer i3 = pointDict.get(p3Key);
                    if (i3 == null) {
                        pointDict.put(p3Key, currPointIndex);
                        i3 = currPointIndex;
                        visMesh.addToPoints(p3Coord);
                        currPointIndex++;
                    }
                    VisPoint p4Coord = new VisPoint(maxX, minY, z);
                    String p4Key = toStringKey(p4Coord);
                    Integer i4 = pointDict.get(p4Key);
                    if (i4 == null) {
                        pointDict.put(p4Key, currPointIndex);
                        i4 = currPointIndex;
                        visMesh.addToPoints(p4Coord);
                        currPointIndex++;
                    }
                    VisPolygon quad = new VisPolygon(Arrays.asList(new Integer[] { i1, i2, i3, i4 }));
                    quad.setFiniteVolumeIndex(new FiniteVolumeIndex(volumeIndex, cartesianMesh.getVolumeRegionIndex(volumeIndex)));
                    // print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
                    visMesh.addToPolygons(quad);
                }
                // end if
                volumeIndex++;
            }
        // end i
        }
    // end j
    }
    return visMesh;
}
Also used : FiniteVolumeIndex(org.vcell.vis.vismesh.thrift.FiniteVolumeIndex) HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) Box3D(org.vcell.vis.core.Box3D) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) Vect3D(org.vcell.vis.vismesh.thrift.Vect3D) VisMesh(org.vcell.vis.vismesh.thrift.VisMesh) VisPolygon(org.vcell.vis.vismesh.thrift.VisPolygon) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint)

Example 4 with FiniteVolumeIndex

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

the class CartesianMeshMapping method fromMesh3DVolume.

private VisMesh fromMesh3DVolume(CartesianMesh cartesianMesh, String domainName) {
    ISize size = cartesianMesh.getSize();
    int numX = size.getX();
    int numY = size.getY();
    int numZ = size.getZ();
    int dimension = 3;
    Vect3D origin = new Vect3D(cartesianMesh.getOrigin().x, cartesianMesh.getOrigin().y, cartesianMesh.getOrigin().z);
    Vect3D extent = new Vect3D(cartesianMesh.getExtent().x, cartesianMesh.getExtent().y, cartesianMesh.getExtent().z);
    // invoke VisMesh() constructor
    VisMesh visMesh = new VisMesh(dimension, origin, extent);
    int currPointIndex = 0;
    HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
    List<Integer> volumeRegionIDs = cartesianMesh.getVolumeRegionIDs(domainName);
    int volumeIndex = 0;
    for (int k = 0; k < numZ; k++) {
        for (int j = 0; j < numY; j++) {
            for (int i = 0; i < numX; i++) {
                int regionIndex = cartesianMesh.getVolumeRegionIndex(volumeIndex);
                if (volumeRegionIDs.contains(regionIndex)) {
                    Box3D element = cartesianMesh.getVolumeElementBox(i, j, k);
                    double minX = element.x_lo;
                    double maxX = element.x_hi;
                    double minY = element.y_lo;
                    double maxY = element.y_hi;
                    double minZ = element.z_lo;
                    double maxZ = element.z_hi;
                    // 
                    // points for a VisPolyhedra ... initially a hex ... then may be clipped
                    // 
                    // p6-------------------p7
                    // /|                   /|
                    // / |                  / |
                    // p4-------------------p5  |
                    // |  |                 |  |
                    // |  |                 |  |
                    // |  |                 |  |         z   y
                    // |  p2................|..p3        |  /
                    // | /                  | /          | /
                    // |/                   |/           |/
                    // p0-------------------p1            O----- x
                    // 
                    // p0 = (X-,Y-,Z-)
                    // p1 = (X+,Y-,Z-)
                    // p2 = (X-,Y+,Z-)
                    // p3 = (X+,Y+,Z-)
                    // p4 = (X-,Y-,Z+)
                    // p5 = (X+,Y-,Z+)
                    // p6 = (X-,Y+,Z+)
                    // p7 = (X+,Y+,Z+)
                    // 
                    VisPoint[] visPoints = { // p0
                    new VisPoint(minX, minY, minZ), // p1
                    new VisPoint(maxX, minY, minZ), // p2
                    new VisPoint(minX, maxY, minZ), // p3
                    new VisPoint(maxX, maxY, minZ), // p4
                    new VisPoint(minX, minY, maxZ), // p5
                    new VisPoint(maxX, minY, maxZ), // p6
                    new VisPoint(minX, maxY, maxZ), // p7
                    new VisPoint(maxX, maxY, maxZ) };
                    Integer[] indices = new Integer[8];
                    for (int v = 0; v < 8; v++) {
                        VisPoint visPoint = visPoints[v];
                        String key = toStringKey(visPoint);
                        Integer p = pointDict.get(key);
                        if (p == null) {
                            pointDict.put(key, currPointIndex);
                            p = currPointIndex;
                            visMesh.addToPoints(visPoint);
                            currPointIndex++;
                        }
                        indices[v] = p;
                    }
                    VisVoxel voxel = new VisVoxel(Arrays.asList(indices));
                    voxel.setFiniteVolumeIndex(new FiniteVolumeIndex(volumeIndex, cartesianMesh.getVolumeRegionIndex(volumeIndex)));
                    // print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
                    visMesh.addToVisVoxels(voxel);
                }
                // end if
                volumeIndex++;
            }
        // end for i
        }
    // end for j
    }
    // end for k
    return visMesh;
}
Also used : FiniteVolumeIndex(org.vcell.vis.vismesh.thrift.FiniteVolumeIndex) HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) VisVoxel(org.vcell.vis.vismesh.thrift.VisVoxel) Box3D(org.vcell.vis.core.Box3D) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) Vect3D(org.vcell.vis.vismesh.thrift.Vect3D) VisMesh(org.vcell.vis.vismesh.thrift.VisMesh) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint)

Aggregations

FiniteVolumeIndex (org.vcell.vis.vismesh.thrift.FiniteVolumeIndex)4 HashMap (java.util.HashMap)3 ISize (org.vcell.util.ISize)3 Box3D (org.vcell.vis.core.Box3D)3 Vect3D (org.vcell.vis.vismesh.thrift.Vect3D)3 VisMesh (org.vcell.vis.vismesh.thrift.VisMesh)3 VisPoint (org.vcell.vis.vismesh.thrift.VisPoint)3 VisPolygon (org.vcell.vis.vismesh.thrift.VisPolygon)2 File (java.io.File)1 MembraneElement (org.vcell.vis.vcell.MembraneElement)1 FiniteVolumeIndexData (org.vcell.vis.vismesh.thrift.FiniteVolumeIndexData)1 VisVoxel (org.vcell.vis.vismesh.thrift.VisVoxel)1