Search in sources :

Example 1 with ChomboBox

use of org.vcell.vis.chombo.ChomboBox in project vcell by virtualcell.

the class ChomboXmlWriter method write.

public static void write(ChomboMeshData chomboMeshData, String filename) throws IOException {
    Element rootNode = new Element("root");
    Element meshNode = new Element("mesh");
    meshNode.setAttribute("dimension", Integer.toString(chomboMeshData.getMesh().getDimension()));
    rootNode.addContent(meshNode);
    Element levelListNode = new Element("levelList");
    meshNode.addContent(levelListNode);
    for (ChomboLevel chomboLevel : chomboMeshData.getMesh().getLevels()) {
        Element levelNode = new Element("level");
        levelNode.setAttribute("info", "level=" + Integer.toString(chomboLevel.getLevel()));
        levelListNode.addContent(levelNode);
        Element boxListNode = new Element("boxList");
        levelNode.addContent(boxListNode);
        for (ChomboBox chomboBox : chomboLevel.getBoxes()) {
            int minZ = 0;
            int maxZ = 0;
            Element boxNode = new Element("box");
            boxNode.setAttribute("info", "(" + chomboBox.getMinX() + "," + chomboBox.getMinY() + "," + minZ + ") (" + chomboBox.getMaxX() + "," + chomboBox.getMaxY() + "," + maxZ + ")");
            boxListNode.addContent(boxNode);
        }
        Element coveringNode = new Element("covering");
        levelNode.addContent(coveringNode);
        Covering covering = chomboLevel.getCovering();
        int[] levelMap = covering.getLevelMap();
        int[] boxNumberMap = covering.getBoxNumberMap();
        int[] boxIndexMap = covering.getBoxIndexMap();
        ISize size = chomboLevel.getSize();
        int numX = size.getX();
        int numY = size.getY();
        {
            Element levelMapNode = new Element("levelMap");
            levelMapNode.setAttribute("info", "level=" + chomboLevel.getLevel());
            StringBuffer levelMapText = new StringBuffer("\n");
            for (int j = 0; j < numY; j++) {
                levelMapText.append("[");
                for (int i = 0; i < numX; i++) {
                    levelMapText.append(levelMap[i + j * numX] + " ");
                }
                levelMapText.append("]\n");
            }
            levelMapNode.setText(levelMapText.toString());
            coveringNode.addContent(levelMapNode);
        }
        {
            Element boxNumberMapNode = new Element("boxNumberMap");
            boxNumberMapNode.setAttribute("info", "level=" + chomboLevel.getLevel());
            StringBuffer boxNumberMapText = new StringBuffer("\n");
            for (int j = 0; j < numY; j++) {
                boxNumberMapText.append("[");
                for (int i = 0; i < numX; i++) {
                    boxNumberMapText.append(boxNumberMap[i + j * numX] + " ");
                }
                boxNumberMapText.append("]\n");
            }
            boxNumberMapNode.setText(boxNumberMapText.toString());
            coveringNode.addContent(boxNumberMapNode);
        }
        {
            Element boxIndexMapNode = new Element("boxIndexMap");
            boxIndexMapNode.setAttribute("info", "level=" + chomboLevel.getLevel());
            StringBuffer boxIndexMapText = new StringBuffer("\n");
            for (int j = 0; j < numY; j++) {
                boxIndexMapText.append("[");
                for (int i = 0; i < numX; i++) {
                    boxIndexMapText.append(boxIndexMap[i + j * numX] + " ");
                }
                boxIndexMapText.append("]\n");
            }
            boxIndexMapNode.setText(boxIndexMapText.toString());
            coveringNode.addContent(boxIndexMapNode);
        }
    }
    String xmlString = XmlUtil.xmlToString(rootNode, true);
    XmlUtil.writeXMLStringToFile(xmlString, filename, true);
}
Also used : ChomboBox(org.vcell.vis.chombo.ChomboBox) ISize(org.vcell.util.ISize) Element(org.jdom.Element) Covering(org.vcell.vis.chombo.ChomboLevel.Covering) ChomboLevel(org.vcell.vis.chombo.ChomboLevel)

Example 2 with ChomboBox

use of org.vcell.vis.chombo.ChomboBox in project vcell by virtualcell.

the class ChomboMeshMapping method fromMeshData2D.

private VisMesh fromMeshData2D(ChomboMeshData chomboMeshData) {
    ChomboMesh chomboMesh = chomboMeshData.getMesh();
    ChomboLevel finestLevel = chomboMesh.getLevel(chomboMesh.getNumLevels() - 1);
    int finestAbsRefinement = finestLevel.getAbsoluteRefinement();
    ISize size = finestLevel.getSize();
    int numX = size.getX();
    int numY = size.getY();
    int numZ = size.getZ();
    int dimension = chomboMeshData.getMesh().getDimension();
    int z = 0;
    // invoke VisMesh() constructor
    VisMesh visMesh = new VisMesh(chomboMesh.getDimension(), toThrift(chomboMesh.getOrigin()), toThrift(chomboMesh.getExtent()));
    int currPointIndex = 0;
    HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
    double originX = chomboMesh.getOrigin().x;
    double originY = chomboMesh.getOrigin().y;
    double originZ = chomboMesh.getOrigin().z;
    double extentX = chomboMesh.getExtent().x;
    double extentY = chomboMesh.getExtent().y;
    double extentZ = chomboMesh.getExtent().z;
    ChomboBoundaries chomboBoundaries = chomboMesh.getBoundaries();
    for (ChomboBoundaries.Point chomboPoint : chomboBoundaries.getPoints()) {
        double px = chomboPoint.x;
        double py = chomboPoint.y;
        double pz = z;
        px = (px - originX) * (numX) / extentX * 2 - 1;
        py = (py - originY) * (numY) / extentY * 2 - 1;
        pz = (pz - originZ) * (numZ) / extentZ * 2 - 1;
        if (dimension == 2) {
            pz = z;
        }
        VisPoint newVisPoint = new VisPoint(px, py, pz);
        String coordKey = toStringKey(newVisPoint);
        pointDict.put(coordKey, currPointIndex);
        visMesh.addToPoints(newVisPoint);
        visMesh.addToSurfacePoints(newVisPoint);
        currPointIndex += 1;
    }
    for (ChomboBoundaries.Segment segment : chomboBoundaries.getSegments()) {
        VisLine newVisLine = new VisLine(segment.getP1(), segment.getP2());
        newVisLine.setChomboSurfaceIndex(new ChomboSurfaceIndex(segment.getChomboIndex()));
        visMesh.addToVisLines(newVisLine);
    }
    for (int levelIndex = 0; levelIndex < chomboMesh.getNumLevels(); levelIndex++) {
        ChomboLevelData chomboLevelData = chomboMeshData.getLevelData(levelIndex);
        ChomboLevel currLevel = chomboMesh.getLevel(levelIndex);
        int currAbsRefinement = currLevel.getAbsoluteRefinement();
        Covering covering = currLevel.getCovering();
        int[] levelMap = covering.getLevelMap();
        int[] boxNumberMap = covering.getBoxNumberMap();
        int[] boxIndexMap = covering.getBoxIndexMap();
        int levelNumX = currLevel.getSize().getX();
        int levelNumY = currLevel.getSize().getY();
        for (int x = 0; x < levelNumX; x++) {
            for (int y = 0; y < levelNumY; y++) {
                int mapIndex = x + y * levelNumX;
                if (levelMap[mapIndex] == levelIndex) {
                    // 
                    // if fraction (volume fraction of element in box) is 0 ... then skip this element
                    // 
                    int boxNumber = boxNumberMap[mapIndex];
                    int boxIndex = boxIndexMap[mapIndex];
                    double fraction = chomboLevelData.getCellFraction(currLevel, boxNumber, boxIndex);
                    if (fraction > 0) {
                        // 
                        // add cell
                        // 
                        ChomboBox chomboBox = new ChomboBox(currLevel, x, x, y, y, z, z, dimension).getProjectedBox(currAbsRefinement, finestAbsRefinement);
                        double minX = 2 * chomboBox.getMinX() - 1;
                        double maxX = 2 * chomboBox.getMaxX() + 1;
                        double minY = 2 * chomboBox.getMinY() - 1;
                        double maxY = 2 * chomboBox.getMaxY() + 1;
                        // 
                        // 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.setChomboVolumeIndex(new ChomboVolumeIndex(levelIndex, boxNumber, boxIndex, fraction));
                        // print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
                        visMesh.addToPolygons(quad);
                    }
                }
            }
        }
    }
    cropQuads(visMesh);
    return visMesh;
}
Also used : ChomboSurfaceIndex(org.vcell.vis.vismesh.thrift.ChomboSurfaceIndex) HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) VisLine(org.vcell.vis.vismesh.thrift.VisLine) Covering(org.vcell.vis.chombo.ChomboLevel.Covering) ChomboBoundaries(org.vcell.vis.chombo.ChomboBoundaries) ChomboVolumeIndex(org.vcell.vis.vismesh.thrift.ChomboVolumeIndex) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) ChomboLevelData(org.vcell.vis.chombo.ChomboLevelData) VisMesh(org.vcell.vis.vismesh.thrift.VisMesh) VisPolygon(org.vcell.vis.vismesh.thrift.VisPolygon) ChomboBox(org.vcell.vis.chombo.ChomboBox) ChomboMesh(org.vcell.vis.chombo.ChomboMesh) ChomboLevel(org.vcell.vis.chombo.ChomboLevel) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint)

Example 3 with ChomboBox

use of org.vcell.vis.chombo.ChomboBox in project vcell by virtualcell.

the class ChomboMeshMapping method fromMeshData3D.

private VisMesh fromMeshData3D(ChomboMeshData chomboMeshData, ChomboCombinedVolumeMembraneDomain chomboCombinedVolumeMembraneDomain) {
    int dimension = chomboMeshData.getMesh().getDimension();
    if (dimension != 3) {
        throw new RuntimeException("expecting a 3D mesh");
    }
    ChomboMesh chomboMesh = chomboMeshData.getMesh();
    ChomboLevel finestLevel = chomboMesh.getLevel(chomboMesh.getNumLevels() - 1);
    int finestAbsRefinement = finestLevel.getAbsoluteRefinement();
    ISize size = finestLevel.getSize();
    int numX = size.getX();
    int numY = size.getY();
    int numZ = size.getZ();
    Vect3D origin = new Vect3D(chomboMesh.getOrigin().x, chomboMesh.getOrigin().y, chomboMesh.getOrigin().z);
    Vect3D extent = new Vect3D(chomboMesh.getExtent().x, chomboMesh.getExtent().y, chomboMesh.getExtent().z);
    // invoke VisMesh() constructor
    VisMesh visMesh = new VisMesh(chomboMesh.getDimension(), origin, extent);
    int currPointIndex = 0;
    HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
    double originX = chomboMesh.getOrigin().x;
    double originY = chomboMesh.getOrigin().y;
    double originZ = chomboMesh.getOrigin().z;
    double extentX = chomboMesh.getExtent().x;
    double extentY = chomboMesh.getExtent().y;
    double extentZ = chomboMesh.getExtent().z;
    ChomboBoundaries chomboBoundaries = chomboMesh.getBoundaries();
    for (ChomboBoundaries.Point chomboPoint : chomboBoundaries.getPoints()) {
        double px = chomboPoint.x;
        double py = chomboPoint.y;
        double pz = chomboPoint.z;
        px = (px - originX) * (numX) / extentX * 2 - 1;
        py = (py - originY) * (numY) / extentY * 2 - 1;
        pz = (pz - originZ) * (numZ) / extentZ * 2 - 1;
        VisPoint newVisPoint = new VisPoint(px, py, pz);
        String coordKey = toStringKey(newVisPoint);
        pointDict.put(coordKey, currPointIndex);
        visMesh.addToPoints(newVisPoint);
        visMesh.addToSurfacePoints(newVisPoint);
        currPointIndex += 1;
    }
    for (ChomboBoundaries.SurfaceTriangle surfaceTriangle : chomboBoundaries.getSurfaceTriangles()) {
        List<Integer> vertices = Arrays.asList(new Integer[] { surfaceTriangle.getP1(), surfaceTriangle.getP2(), surfaceTriangle.getP3() });
        org.vcell.vis.vismesh.thrift.Face face = org.vcell.vis.vismesh.thrift.Face.valueOf(surfaceTriangle.getFace().name());
        VisSurfaceTriangle newVisSurfaceTriangle = new VisSurfaceTriangle(vertices, face);
        newVisSurfaceTriangle.setChomboSurfaceIndex(new ChomboSurfaceIndex(surfaceTriangle.getChomboIndex()));
        visMesh.addToSurfaceTriangles(newVisSurfaceTriangle);
    }
    for (int levelIndex = 0; levelIndex < chomboMesh.getNumLevels(); levelIndex++) {
        ChomboLevelData chomboLevelData = chomboMeshData.getLevelData(levelIndex);
        ChomboLevel currLevel = chomboMesh.getLevel(levelIndex);
        int currAbsRefinement = currLevel.getAbsoluteRefinement();
        Covering covering = currLevel.getCovering();
        int[] levelMap = covering.getLevelMap();
        int[] boxNumberMap = covering.getBoxNumberMap();
        int[] boxIndexMap = covering.getBoxIndexMap();
        int levelNumX = currLevel.getSize().getX();
        int levelNumY = currLevel.getSize().getY();
        int levelNumZ = currLevel.getSize().getZ();
        for (int x = 0; x < levelNumX; x++) {
            for (int y = 0; y < levelNumY; y++) {
                for (int z = 0; z < levelNumZ; z++) {
                    int mapIndex = x + y * levelNumX + z * levelNumX * levelNumY;
                    if (levelMap[mapIndex] == levelIndex) {
                        // 
                        // if fraction (volume fraction of element in box) is 0 ... then skip this element
                        // 
                        int boxNumber = boxNumberMap[mapIndex];
                        int boxIndex = boxIndexMap[mapIndex];
                        double fraction = chomboLevelData.getCellFraction(currLevel, boxNumber, boxIndex);
                        if (fraction > 0) {
                            // 
                            // add cell
                            // 
                            ChomboBox chomboBox = new ChomboBox(currLevel, x, x, y, y, z, z, dimension).getProjectedBox(currAbsRefinement, finestAbsRefinement);
                            double minX = 2 * chomboBox.getMinX() - 1;
                            double maxX = 2 * chomboBox.getMaxX() + 1;
                            double minY = 2 * chomboBox.getMinY() - 1;
                            double maxY = 2 * chomboBox.getMaxY() + 1;
                            double minZ = 2 * chomboBox.getMinZ() - 1;
                            double maxZ = 2 * chomboBox.getMaxZ() + 1;
                            // 
                            // 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 i = pointDict.get(key);
                                if (i == null) {
                                    pointDict.put(key, currPointIndex);
                                    i = currPointIndex;
                                    visMesh.addToPoints(visPoint);
                                    currPointIndex++;
                                }
                                indices[v] = i;
                            }
                            VisVoxel voxel = new VisVoxel(Arrays.asList(indices));
                            voxel.setChomboVolumeIndex(new ChomboVolumeIndex(levelIndex, boxNumber, boxIndex, fraction));
                            // print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
                            visMesh.addToVisVoxels(voxel);
                        }
                    }
                }
            }
        }
    }
    cropVoxels(visMesh, chomboBoundaries, chomboCombinedVolumeMembraneDomain);
    return visMesh;
}
Also used : HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) Covering(org.vcell.vis.chombo.ChomboLevel.Covering) ChomboBoundaries(org.vcell.vis.chombo.ChomboBoundaries) ChomboVolumeIndex(org.vcell.vis.vismesh.thrift.ChomboVolumeIndex) Vect3D(org.vcell.vis.vismesh.thrift.Vect3D) ChomboMesh(org.vcell.vis.chombo.ChomboMesh) ChomboLevel(org.vcell.vis.chombo.ChomboLevel) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) ChomboSurfaceIndex(org.vcell.vis.vismesh.thrift.ChomboSurfaceIndex) VisVoxel(org.vcell.vis.vismesh.thrift.VisVoxel) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) ChomboLevelData(org.vcell.vis.chombo.ChomboLevelData) VisMesh(org.vcell.vis.vismesh.thrift.VisMesh) VisSurfaceTriangle(org.vcell.vis.vismesh.thrift.VisSurfaceTriangle) ChomboBox(org.vcell.vis.chombo.ChomboBox) Face(org.vcell.vis.vismesh.thrift.Face)

Example 4 with ChomboBox

use of org.vcell.vis.chombo.ChomboBox in project vcell by virtualcell.

the class ChomboFileReader method readMesh.

private static ChomboMeshData readMesh(String meshFileName, String vol0FileName) throws Exception {
    ChomboMesh chomboMesh = new ChomboMesh();
    if (H5.H5open() < 0) {
        throw new Exception("H5.H5open() failed");
    }
    FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
    if (fileFormat == null) {
        throw new Exception("FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5) failed, returned null.");
    }
    FileFormat meshFile = fileFormat.createInstance(new File(meshFileName).getAbsolutePath(), FileFormat.READ);
    try {
        meshFile.open();
        DefaultMutableTreeNode meshRootNode = (DefaultMutableTreeNode) meshFile.getRootNode();
        Group meshRootGroup = (Group) meshRootNode.getUserObject();
        Group meshGroup = Hdf5Reader.getChildGroup(meshRootGroup, "mesh");
        chomboMesh.setDimension(Hdf5Reader.getIntAttribute(meshGroup, MESH_ATTR_DIMENSION));
        chomboMesh.setExtent(Hdf5Reader.getVect3DAttribute(meshGroup, MESH_ATTR_EXTENT, 1.0));
        chomboMesh.setOrigin(Hdf5Reader.getVect3DAttribute(meshGroup, MESH_ATTR_ORIGIN, 0.0));
        // it's very wasteful here, but what can I do?
        CartesianMeshChombo cartesianMeshChombo = CartesianMeshChombo.readMeshFile(new File(meshFileName));
        for (FeaturePhaseVol fpv : cartesianMeshChombo.getFeaturePhaseVols()) {
            chomboMesh.addFeaturePhase(fpv.feature, fpv.iphase);
        }
        // Hdf5Reader.DataColumn[] metricsColumns = Hdf5Reader.getDataTable(meshGroup,METRICS_DATASET);
        if (chomboMesh.getDimension() == 2) {
            Hdf5Reader.DataColumn[] segmentColumns = Hdf5Reader.getDataTable(meshGroup, "segments");
            Hdf5Reader.DataColumn[] verticesColumns = Hdf5Reader.getDataTable(meshGroup, "vertices");
            ChomboBoundaries boundaries = chomboMesh.getBoundaries();
            int numVertices = verticesColumns[0].getNumRows();
            int numSegments = segmentColumns[0].getNumRows();
            for (int i = 0; i < numVertices; i++) {
                double x = verticesColumns[0].getValue(i);
                double y = verticesColumns[1].getValue(i);
                double z = 0.0;
                boundaries.addPoint(new ChomboBoundaries.Point(x, y, z));
            }
            for (int i = 0; i < numSegments; i++) {
                int v1 = (int) segmentColumns[1].getValue(i);
                int v2 = (int) segmentColumns[2].getValue(i);
                // THIS COULD BE WRONG - is the chomboIndex one-to-one with the line segments? ... if not should be in the HDF5 file.
                int chomboIndex = i;
                boundaries.addSegment(new ChomboBoundaries.Segment(chomboIndex, v1, v2));
            }
        } else if (chomboMesh.getDimension() == 3) {
            Hdf5Reader.DataColumn[] surfaceTriangleColumns = Hdf5Reader.getDataTable(meshGroup, "surface triangles");
            ChomboBoundaries boundaries = chomboMesh.getBoundaries();
            int numTriangles = surfaceTriangleColumns[0].getNumRows();
            for (int row = 0; row < numTriangles; row++) {
                int index = (int) surfaceTriangleColumns[0].getValue(row);
                int faceNumber = (int) surfaceTriangleColumns[1].getValue(row);
                // not used currently
                int neighborIndex = (int) surfaceTriangleColumns[2].getValue(row);
                double x0 = surfaceTriangleColumns[3].getValue(row);
                double y0 = surfaceTriangleColumns[4].getValue(row);
                double z0 = surfaceTriangleColumns[5].getValue(row);
                int p0_index = boundaries.getOrCreatePoint(x0, y0, z0);
                double x1 = surfaceTriangleColumns[6].getValue(row);
                double y1 = surfaceTriangleColumns[7].getValue(row);
                double z1 = surfaceTriangleColumns[8].getValue(row);
                int p1_index = boundaries.getOrCreatePoint(x1, y1, z1);
                double x2 = surfaceTriangleColumns[9].getValue(row);
                double y2 = surfaceTriangleColumns[10].getValue(row);
                double z2 = surfaceTriangleColumns[11].getValue(row);
                int p2_index = boundaries.getOrCreatePoint(x2, y2, z2);
                Face face = Face.fromInteger(faceNumber);
                SurfaceTriangle surfaceTriangle = new SurfaceTriangle(index, face, p0_index, p1_index, p2_index);
                boundaries.addSurfaceTriangle(surfaceTriangle);
            }
            Hdf5Reader.DataColumn[] metricsColumns = Hdf5Reader.getDataTable(meshGroup, "membrane elements");
            MeshMetrics meshMetrics = boundaries.getMeshMetrics();
            int numMeshMetrics = metricsColumns[0].getNumRows();
            for (int row = 0; row < numMeshMetrics; row++) {
                int index = (int) metricsColumns[0].getValue(row);
                int level = (int) metricsColumns[1].getValue(row);
                // not used currently
                int i = (int) metricsColumns[2].getValue(row);
                // not used currently
                int j = (int) metricsColumns[3].getValue(row);
                // not used currently
                int k = (int) metricsColumns[4].getValue(row);
                double x = metricsColumns[5].getValue(row);
                double y = metricsColumns[6].getValue(row);
                double z = metricsColumns[7].getValue(row);
                Vect3D center = new Vect3D(x, y, z);
                double normalX = metricsColumns[8].getValue(row);
                double normalY = metricsColumns[9].getValue(row);
                double normalZ = metricsColumns[10].getValue(row);
                Vect3D normal = new Vect3D(normalX, normalY, normalZ);
                double volumeFraction = metricsColumns[11].getValue(row);
                double areaFraction = metricsColumns[12].getValue(row);
                int membraneId = (int) metricsColumns[13].getValue(row);
                int cornerPhaseMask = (int) metricsColumns[14].getValue(row);
                BorderCellInfo borderCellInfo = new BorderCellInfo(index, level, i, j, k, center, normal, volumeFraction, areaFraction, membraneId, cornerPhaseMask);
                meshMetrics.addBorderCellInfo(borderCellInfo);
            }
        } else {
            throw new Exception("failed to read chombo file, unexpected mesh dimension " + chomboMesh.getDimension());
        }
    } finally {
        meshFile.close();
    }
    FileFormat vol0File = fileFormat.createInstance(new File(vol0FileName).getAbsolutePath(), FileFormat.READ);
    try {
        vol0File.open();
        DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) vol0File.getRootNode();
        Group rootGroup = (Group) rootNode.getUserObject();
        Group level0Group = Hdf5Reader.getChildGroup(rootGroup, "level_0");
        double time = Hdf5Reader.getDoubleAttribute(level0Group, "time");
        ChomboMeshData chomboMeshData = new ChomboMeshData(chomboMesh, time);
        int numComponents = Hdf5Reader.getIntAttribute(rootGroup, "num_components");
        int numLevels = Hdf5Reader.getIntAttribute(rootGroup, "num_levels");
        int fractionComponentIndex = -1;
        for (int i = 0; i < numComponents; i++) {
            String compName = Hdf5Reader.getStringAttribute(rootGroup, "component_" + i);
            chomboMeshData.addComponentName(compName);
            if (compName.equals("fraction-0")) {
                fractionComponentIndex = i;
                chomboMeshData.setFraction0ComponentIndex(fractionComponentIndex);
            }
        }
        for (int i = 0; i < numLevels; i++) {
            Group levelGroup = Hdf5Reader.getChildGroup(rootGroup, "level_" + i);
            int refinement = 2;
            if (i == 0) {
                refinement = 1;
            }
            ChomboLevel chomboLevel = new ChomboLevel(chomboMesh, i, refinement);
            Hdf5Reader.DataColumn[] boxColumns = Hdf5Reader.getDataTable(levelGroup, "boxes");
            int[] lo_i, lo_j, lo_k, hi_i, hi_j, hi_k;
            if (chomboMesh.getDimension() == 2) {
                lo_i = ((Hdf5Reader.IntColumn) boxColumns[0]).data;
                lo_j = ((Hdf5Reader.IntColumn) boxColumns[1]).data;
                hi_i = ((Hdf5Reader.IntColumn) boxColumns[2]).data;
                hi_j = ((Hdf5Reader.IntColumn) boxColumns[3]).data;
                lo_k = new int[boxColumns[0].getNumRows()];
                hi_k = new int[boxColumns[0].getNumRows()];
            } else {
                lo_i = ((Hdf5Reader.IntColumn) boxColumns[0]).data;
                lo_j = ((Hdf5Reader.IntColumn) boxColumns[1]).data;
                lo_k = ((Hdf5Reader.IntColumn) boxColumns[2]).data;
                hi_i = ((Hdf5Reader.IntColumn) boxColumns[3]).data;
                hi_j = ((Hdf5Reader.IntColumn) boxColumns[4]).data;
                hi_k = ((Hdf5Reader.IntColumn) boxColumns[5]).data;
            }
            for (int b = 0; b < boxColumns[0].getNumRows(); b++) {
                ChomboBox chomboBox = new ChomboBox(chomboLevel, lo_i[b], hi_i[b], lo_j[b], hi_j[b], lo_k[b], hi_k[b], chomboMesh.getDimension());
                chomboLevel.addBox(chomboBox);
            }
            chomboMesh.addLevel(chomboLevel);
            // 
            // read the variables
            // 
            Hdf5Reader.DataColumn[] data = Hdf5Reader.getDataTable(levelGroup, "data:datatype=0");
            Hdf5Reader.DataColumn[] offsets = Hdf5Reader.getDataTable(levelGroup, "data:offsets=0");
            ChomboLevelData chomboLevelData = new ChomboLevelData(i, fractionComponentIndex, ((Hdf5Reader.DoubleColumn) data[0]).data, ((Hdf5Reader.LongColumn) offsets[0]).data);
            chomboMeshData.addLevelData(chomboLevelData);
        }
        readMembraneVarData(chomboMeshData, rootGroup);
        return chomboMeshData;
    } finally {
        vol0File.close();
    }
}
Also used : Group(ncsa.hdf.object.Group) FeaturePhaseVol(cbit.vcell.solvers.CartesianMeshChombo.FeaturePhaseVol) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ChomboBoundaries(org.vcell.vis.chombo.ChomboBoundaries) FileFormat(ncsa.hdf.object.FileFormat) CartesianMeshChombo(cbit.vcell.solvers.CartesianMeshChombo) Vect3D(org.vcell.vis.core.Vect3D) ChomboMesh(org.vcell.vis.chombo.ChomboMesh) MeshMetrics(org.vcell.vis.chombo.ChomboBoundaries.MeshMetrics) BorderCellInfo(org.vcell.vis.chombo.ChomboBoundaries.BorderCellInfo) ChomboMeshData(org.vcell.vis.chombo.ChomboMeshData) Face(org.vcell.vis.core.Face) ChomboLevel(org.vcell.vis.chombo.ChomboLevel) SurfaceTriangle(org.vcell.vis.chombo.ChomboBoundaries.SurfaceTriangle) ChomboLevelData(org.vcell.vis.chombo.ChomboLevelData) ChomboBox(org.vcell.vis.chombo.ChomboBox) File(java.io.File)

Aggregations

ChomboBox (org.vcell.vis.chombo.ChomboBox)4 ChomboLevel (org.vcell.vis.chombo.ChomboLevel)4 ISize (org.vcell.util.ISize)3 ChomboBoundaries (org.vcell.vis.chombo.ChomboBoundaries)3 Covering (org.vcell.vis.chombo.ChomboLevel.Covering)3 ChomboLevelData (org.vcell.vis.chombo.ChomboLevelData)3 ChomboMesh (org.vcell.vis.chombo.ChomboMesh)3 HashMap (java.util.HashMap)2 ChomboSurfaceIndex (org.vcell.vis.vismesh.thrift.ChomboSurfaceIndex)2 ChomboVolumeIndex (org.vcell.vis.vismesh.thrift.ChomboVolumeIndex)2 VisMesh (org.vcell.vis.vismesh.thrift.VisMesh)2 VisPoint (org.vcell.vis.vismesh.thrift.VisPoint)2 CartesianMeshChombo (cbit.vcell.solvers.CartesianMeshChombo)1 FeaturePhaseVol (cbit.vcell.solvers.CartesianMeshChombo.FeaturePhaseVol)1 File (java.io.File)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 FileFormat (ncsa.hdf.object.FileFormat)1 Group (ncsa.hdf.object.Group)1 Element (org.jdom.Element)1 BorderCellInfo (org.vcell.vis.chombo.ChomboBoundaries.BorderCellInfo)1