Changeset 2498

Show
Ignore:
Timestamp:
04/24/2008 03:20:51 PM (9 months ago)
Author:
wd15
Message:

fixing examples and viewers

Location:
trunk
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/INSTALLATION.txt

    r2344 r2498  
    259259for specific platforms`_ are available |citeMatplotlibDownload|. 
    260260 
     261.. note:: 
     262 
     263   Matplotlib_ is noticeably slower than Pygist_ or Gnuplot.py_, but 
     264   has superior image rendering and plotting functionality. 
     265 
    261266.. _Matplotlib:  http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://matplotlib.sourceforge.net 
    262267.. _Matplotlib installers for specific platforms: http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://sourceforge.net/project/showfiles.php?group_id=80706&package_id=82474 
     
    309314   may crash the |FiPy| run. "``.eps``" and "``.cgm``" export seem to work. 
    310315 
    311 .. attention:: 
    312  
    313    Pygist_ seems to be unable to make contour plots on x86_64 
    314    architectures running Linux. 
    315  
    316316.. note:: 
    317317 
     
    322322.. note:: 
    323323 
    324    Pygist_ can have problems finding color pallets, such as "``heat.gp``" and 
    325    "``work.gs``", when installed locally. You may need to set the 
    326    ``GISTPATH`` environment variable to point to the directory containing 
    327    these files (you may find it as "``g/``" within the directory you 
    328    specified for ``--home``). 
     324   Pygist_ can have problems finding color pallets such as 
     325   "``heat.gp``" and "``work.gs``" when installed locally. To avoid 
     326   this, copy the files in the "``INSTALLPATH/g``" directory into 
     327   "``INSTALLPATH/lib/python/gist/``" after installation. 
    329328 
    330329.. _Pygist: http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://hifweb.lbl.gov/public/software/gist/ 
  • trunk/examples/diffusion/steadyState/mesh1D/tri2Dinput.py

    r2331 r2498  
    9797    viewer = viewers.make(vars = var) 
    9898    viewer.plot() 
    99     x = mesh.getCellCenters()[:,0] 
     99    x = mesh.getCellCenters()[0] 
    100100    Lx = nx * dx 
    101101    analyticalArray = valueLeft + (valueRight - valueLeft) * x / Lx 
  • trunk/examples/diffusion/steadyState/mesh20x20/modifiedMeshInput.py

    r2301 r2498  
    5959    1 
    6060 
     61    >>> max(mesh._getNonOrthogonality()) < 0.51 
     62    True 
     63 
    6164Note that this test case will only work if you run it by running the 
    6265main FiPy test suite. If you run it directly from the directory it is 
     
    100103    errorViewer = viewers.make(vars = errorVar) 
    101104    errorViewer.plot() 
     105 
    102106    NonOrthoVar = CellVariable(name = "non-orthogonality", 
    103107                               mesh = mesh, 
    104108                               value = mesh._getNonOrthogonality()) 
    105     NOViewer = viewers.make(vars = NonOrthoVar)     
     109    NOViewer = viewers.make(vars = NonOrthoVar) 
     110 
     111 
    106112    NOViewer.plot() 
    107113    raw_input("finished") 
  • trunk/fipy/meshes/common/mesh.py

    r2465 r2498  
    313313     
    314314    def _getNumberOfVertices(self): 
    315         return len(self.vertexCoords[:,0]) 
     315        if hasattr(self, 'numberOfVertices'): 
     316            return self.numberOfVertices 
     317        else: 
     318            return len(self.vertexCoords[:,0]) 
    316319         
    317320    def _getAdjacentCellIDs(self): 
  • trunk/fipy/meshes/numMesh/mesh.py

    r2497 r2498  
    407407 
    408408    def getVertexCoords(self): 
    409         return self.vertexCoords 
     409        if hasattr(self, 'vertexCoords'): 
     410            return self.vertexCoords 
     411        else: 
     412            return self._createVertices() 
    410413 
    411414    def getExteriorFaces(self): 
  • trunk/fipy/meshes/numMesh/mesh2D.py

    r2465 r2498  
    118118     
    119119    def _getNonOrthogonality(self): 
    120         exteriorFaceArray = numerix.zeros((self.faceCellIDs.shape[0],)) 
     120         
     121        exteriorFaceArray = numerix.zeros((self.faceCellIDs.shape[1],)) 
    121122        numerix.put(exteriorFaceArray, self.getExteriorFaces(), 1) 
    122123        unmaskedFaceCellIDs = MA.filled(self.faceCellIDs, 0) ## what we put in for the "fill" doesn't matter because only exterior faces have anything masked, and exterior faces have their displacement vectors set to zero. 
    123124        ## if it's an exterior face, make the "displacement vector" equal to zero so the cross product will be zero. 
    124         faceDisplacementVectors = numerix.where(numerix.array(zip(exteriorFaceArray, exteriorFaceArray)), 0.0, numerix.take(self.getCellCenters(), unmaskedFaceCellIDs[:, 1]) - numerix.take(self.getCellCenters(), unmaskedFaceCellIDs[:, 0])) 
    125         faceCrossProducts = (faceDisplacementVectors[:, 0] * self.faceNormals[:, 1]) - (faceDisplacementVectors[:, 1] * self.faceNormals[:, 0]) 
    126         faceDisplacementVectorLengths = numerix.maximum(((faceDisplacementVectors[:, 0] ** 2) + (faceDisplacementVectors[:, 1] ** 2)) ** 0.5, 1.e-100) 
     125     
     126        faceDisplacementVectors = numerix.where(numerix.array(zip(exteriorFaceArray, exteriorFaceArray)), 0.0, numerix.take(self.getCellCenters().swapaxes(0,1), unmaskedFaceCellIDs[1, :]) - numerix.take(self.getCellCenters().swapaxes(0,1), unmaskedFaceCellIDs[0, :])).swapaxes(0,1) 
     127        faceCrossProducts = (faceDisplacementVectors[0, :] * self.faceNormals[1, :]) - (faceDisplacementVectors[1, :] * self.faceNormals[0, :]) 
     128        faceDisplacementVectorLengths = numerix.maximum(((faceDisplacementVectors[0, :] ** 2) + (faceDisplacementVectors[1, :] ** 2)) ** 0.5, 1.e-100) 
    127129        faceWeightedNonOrthogonalities = abs(faceCrossProducts / faceDisplacementVectorLengths) * self.faceAreas 
    128130        cellFaceWeightedNonOrthogonalities = numerix.take(faceWeightedNonOrthogonalities, self.cellFaceIDs) 
    129131        cellFaceAreas = numerix.take(self.faceAreas, self.cellFaceIDs) 
    130         cellTotalWeightedValues = numerix.add.reduce(cellFaceWeightedNonOrthogonalities, axis = 1) 
    131         cellTotalFaceAreas = numerix.add.reduce(cellFaceAreas, axis = 1) 
     132        cellTotalWeightedValues = numerix.add.reduce(cellFaceWeightedNonOrthogonalities, axis = 0)   
     133        cellTotalFaceAreas = numerix.add.reduce(cellFaceAreas, axis = 0) 
     134   
    132135        return (cellTotalWeightedValues / cellTotalFaceAreas) 
    133136 
  • trunk/fipy/meshes/numMesh/skewedGrid2D.py

    r2356 r2498  
    7070        else: 
    7171            self.dy /= scale 
    72          
    73         self.numberOfVertices = (self.nx + 1) * (self.ny + 1) 
    74          
    75         vertices = self._createVertices() 
     72 
     73        from fipy import Grid2D 
     74        self.grid = Grid2D(nx=nx, ny=ny, dx=dx, dy=dy) 
     75 
     76        self.numberOfVertices = self.grid._getNumberOfVertices() 
     77         
     78        vertices = self.grid.getVertexCoords() 
     79 
    7680        changedVertices = numerix.zeros(vertices.shape, 'd') 
    77 ##        changedVertices = changedVertices.astype(numerix.Float) 
    78         for i in range(len(vertices)): 
     81 
     82        for i in range(len(vertices[0])): 
    7983            if((i % (nx+1)) != 0 and (i % (nx+1)) != nx and (i / nx+1) != 0 and (i / nx+1) != ny): 
    80                 changedVertices[i, 0] = vertices[i, 0] + (rand * ((random.random() * 2) - 1)) 
    81                 changedVertices[i, 1] = vertices[i, 1] + (rand * ((random.random() * 2) - 1)) 
     84                changedVertices[0, i] = vertices[0, i] + (rand * ((random.random() * 2) - 1)) 
     85                changedVertices[1, i] = vertices[1, i] + (rand * ((random.random() * 2) - 1)) 
    8286            else: 
    83                 changedVertices[i, 0] = vertices[i, 0] 
    84                 changedVertices[i, 1] = vertices[i, 1] 
    85         faces = self._createFaces() 
    86         cells = self._createCells() 
     87                changedVertices[0, i] = vertices[0, i] 
     88                changedVertices[1, i] = vertices[1, i] 
     89 
     90 
     91        faces = self.grid._getFaceVertexIDs() 
     92         
     93        cells = self.grid._getCellFaceIDs() 
     94 
    8795        Mesh2D.__init__(self, changedVertices, faces, cells) 
    8896         
    8997        self.setScale(value = scale) 
    9098         
    91     def _createVertices(self): 
    92         x = numerix.arange(self.nx + 1) * self.dx 
    93         y = numerix.arange(self.ny + 1) * self.dy 
    94         x = numerix.resize(x, (self.numberOfVertices,)) 
    95         y = numerix.repeat(y, self.nx + 1) 
    96         return numerix.transpose(numerix.array((x, y))) 
    97      
    98     def _createFaces(self): 
    99         """ 
    100         v1, v2 refer to the cells. 
    101         Horizontel faces are first 
    102         """ 
    103         v1 = numerix.arange(self.numberOfVertices) 
    104         v2 = v1 + 1 
    105         horizontalFaces = vector.prune(numerix.transpose(numerix.array((v1, v2))), self.nx + 1, self.nx) 
    106         v1 = numerix.arange(self.numberOfVertices - (self.nx + 1)) 
    107         v2 = v1 + self.nx + 1 
    108         verticalFaces =  numerix.transpose(numerix.array((v1, v2))) 
    109  
    110         ## reverse some of the face orientations to obtain the correct normals 
    111  
    112         tmp = horizontalFaces.copy() 
    113         horizontalFaces[:self.nx, 0] = tmp[:self.nx, 1] 
    114         horizontalFaces[:self.nx, 1] = tmp[:self.nx, 0] 
    115  
    116         tmp = verticalFaces.copy() 
    117         verticalFaces[:, 0] = tmp[:, 1] 
    118         verticalFaces[:, 1] = tmp[:, 0] 
    119         verticalFaces[::(self.nx + 1), 0] = tmp[::(self.nx + 1), 0] 
    120         verticalFaces[::(self.nx + 1), 1] = tmp[::(self.nx + 1), 1] 
    121  
    122         return numerix.concatenate((horizontalFaces, verticalFaces)) 
    123  
    124     def _createCells(self): 
    125         """ 
    126         cells = (f1, f2, f3, f4) going anticlock wise. 
    127         f1 etx refer to the faces 
    128         """ 
    129         self.numberOfHorizontalFaces = self.nx * (self.ny + 1) 
    130         self.numberOfFaces = self.numberOfHorizontalFaces + self.ny * (self.nx + 1) 
    131         f1 = numerix.arange(self.numberOfHorizontalFaces - self.nx) 
    132         f3 = f1 + self.nx 
    133         f2 = vector.prune(numerix.arange(self.numberOfHorizontalFaces,  self.numberOfFaces), self.nx + 1) 
    134         f4 = f2 - 1 
    135         return numerix.transpose(numerix.array((f1, f2, f3, f4))) 
    136  
     99##     def _createVertices(self): 
     100##         x = numerix.arange(self.nx + 1) * self.dx 
     101##         y = numerix.arange(self.ny + 1) * self.dy 
     102##         x = numerix.resize(x, (self.numberOfVertices,)) 
     103##         y = numerix.repeat(y, self.nx + 1) 
     104##         return numerix.array((x, y)) 
     105## ##        raw_input() 
     106## ##        return numerix.transpose(numerix.array((x, y))) 
     107     
     108##     def _createFaces(self): 
     109##         """ 
     110##         v1, v2 refer to the cells. 
     111##         Horizontel faces are first 
     112##         """ 
     113##         v1 = numerix.arange(self.numberOfVertices) 
     114##         v2 = v1 + 1 
     115##         horizontalFaces = vector.prune(numerix.transpose(numerix.array((v1, v2))), self.nx + 1, self.nx) 
     116##         v1 = numerix.arange(self.numberOfVertices - (self.nx + 1)) 
     117##         v2 = v1 + self.nx + 1 
     118##         verticalFaces =  numerix.transpose(numerix.array((v1, v2))) 
     119 
     120##         ## reverse some of the face orientations to obtain the correct normals 
     121 
     122##         tmp = horizontalFaces.copy() 
     123##         horizontalFaces[:self.nx, 0] = tmp[:self.nx, 1] 
     124##         horizontalFaces[:self.nx, 1] = tmp[:self.nx, 0] 
     125 
     126##         tmp = verticalFaces.copy() 
     127##         verticalFaces[:, 0] = tmp[:, 1] 
     128##         verticalFaces[:, 1] = tmp[:, 0] 
     129##         verticalFaces[::(self.nx + 1), 0] = tmp[::(self.nx + 1), 0] 
     130##         verticalFaces[::(self.nx + 1), 1] = tmp[::(self.nx + 1), 1] 
     131 
     132##         return numerix.concatenate((horizontalFaces, verticalFaces)) 
     133 
     134##     def _createCells(self): 
     135##         """ 
     136##         cells = (f1, f2, f3, f4) going anticlock wise. 
     137##         f1 etx refer to the faces 
     138##         """ 
     139##         self.numberOfHorizontalFaces = self.nx * (self.ny + 1) 
     140##         self.numberOfFaces = self.numberOfHorizontalFaces + self.ny * (self.nx + 1) 
     141##         f1 = numerix.arange(self.numberOfHorizontalFaces - self.nx) 
     142##         f3 = f1 + self.nx 
     143##         f2 = vector.prune(numerix.arange(self.numberOfHorizontalFaces,  self.numberOfFaces), self.nx + 1) 
     144##         f4 = f2 - 1 
     145##         return numerix.transpose(numerix.array((f1, f2, f3, f4))) 
     146 
     147 
     148     
    137149    def getFacesLeft(self): 
    138150        """Return list of faces on left boundary of Grid2D. 
    139151        """ 
    140         return FaceIterator(mesh = self, ids = numerix.arange(self.numberOfHorizontalFaces, self.numberOfFaces, self.nx + 1)) 
    141      
     152        return self.grid.getFacesLeft() 
     153 ##        return FaceIterator(mesh = self, ids = numerix.arange(self.numberOfHorizontalFaces, self.numberOfFaces, self.nx + 1)) 
     154   
    142155    def getFacesRight(self): 
    143156        """Return list of faces on right boundary of Grid2D. 
    144157        """ 
    145         return FaceIterator(mesh = self, ids = numerix.arange(self.numberOfHorizontalFaces + self.nx, self.numberOfFaces, self.nx + 1)) 
    146          
     158        return self.grid.getFacesRight() 
     159 ##        return FaceIterator(mesh = self, ids = numerix.arange(self.numberOfHorizontalFaces + self.nx, self.numberOfFaces, self.nx + 1)) 
     160       
    147161    def getFacesTop(self): 
    148162        """Return list of faces on top boundary of Grid2D. 
    149163        """ 
    150         return FaceIterator(mesh = self, ids = numerix.arange(self.numberOfHorizontalFaces - self.nx, self.numberOfHorizontalFaces)) 
     164        return self.grid.getFacesTop() 
     165 ##        return FaceIterator(mesh = self, ids = numerix.arange(self.numberOfHorizontalFaces - self.nx, self.numberOfHorizontalFaces)) 
    151166 
    152167    getFacesUp = getFacesTop 
    153          
     168       
    154169    def getFacesBottom(self): 
    155170        """Return list of faces on bottom boundary of Grid2D. 
    156171        """ 
    157         return FaceIterator(mesh = self, ids = numerix.arange(self.nx)) 
     172        return self.grid.getFacesBottom() 
     173##         return FaceIterator(mesh = self, ids = numerix.arange(self.nx)) 
    158174 
    159175    getFacesDown = getFacesBottom 
  • trunk/fipy/viewers/gnuplotViewer/gnuplot1DViewer.py

    r2286 r2498  
    8989        for var in self.vars: 
    9090            tupleOfGnuplotData += (Gnuplot.Data(numerix.array(var.getMesh().getCellCenters()[0]), 
    91                                                 var.getValue(), 
     91                                                numerix.array(var.getValue()), 
    9292                                                title=var.getName(), 
    9393                                                with='lines'),) 
  • trunk/fipy/viewers/mayaviViewer/mayaviSurfactantViewer.py

    r2297 r2498  
    133133 
    134134        IDs = numerix.nonzero(self.distanceVar._getCellInterfaceFlag()) 
    135         coordinates = numerix.take(numerix.array(self.distanceVar.getMesh().getCellCenters()), IDs) 
    136          
    137         coordinates -= numerix.take(self.distanceVar.getGrad() * self.distanceVar, IDs) 
     135        coordinates = numerix.take(numerix.array(self.distanceVar.getMesh().getCellCenters()).swapaxes(0,1), IDs) 
     136 
     137        coordinates -= numerix.take(numerix.array(self.distanceVar.getGrad() * self.distanceVar).swapaxes(0,1), IDs) 
     138 
    138139        coordinates *= self.zoomFactor 
    139140 
     
    142143        coordinates = numerix.concatenate((coordinates, shiftedCoords)) 
    143144 
    144  
    145145        from lines import _getOrderedLines 
     146 
    146147        lines = _getOrderedLines(range(2 * len(IDs)), coordinates, thresholdDistance = self.distanceVar.getMesh()._getCellDistances().min() * 10) 
    147148 
     
    159160                             val, 
    160161                             data) 
    161  
    162162         
    163163        for line in lines: 
     
    255255        if xmin is None: 
    256256            xmin = self.surfactantVar.min() 
    257              
     257 
    258258        slh.range_var.set((xmin, xmax)) 
    259259        slh.set_range_var() 
    260260         
    261         slh.v_range_var.set((self.surfactantVar.min(), self.surfactantVar.max())) 
     261        slh.v_range_var.set((float(self.surfactantVar.min()), float(self.surfactantVar.max()))) 
    262262        slh.set_v_range_var() 
    263          
     263 
    264264        self._viewer.Render() 
    265265         
  • trunk/fipy/viewers/mayaviViewer/mayaviViewer.py

    r2497 r2498  
    131131             
    132132        for var in self.vars: 
     133            if var.getRank() > 0: 
     134                raise IndexError, "Mayavi can only plot scalar values" 
    133135            self.structures.append(self._getStructure(var.getMesh())) 
     136 
    134137                                        
    135138    def _getStructure(self, mesh):