Пример #1
0
    def _getSuitableVars(self, vars):
        vars = [var for var in AbstractMatplotlibViewer._getSuitableVars(self, vars) if var.mesh.dim == 1]

        if len(vars) > 1:
            vars = [var for var in vars if var.mesh is vars[0].mesh]
        if len(vars) == 0:
            from fipy.viewers import MeshDimensionError
            raise MeshDimensionError("Can only plot 1D data")
        return vars
Пример #2
0
 def _getSuitableVars(self, vars):
     from fipy.variables.cellVariable import CellVariable
     vars = [var for var in _GistViewer._getSuitableVars(self, vars) \
       if (var.mesh.dim == 2 and isinstance(var, CellVariable))]
     if len(vars) == 0:
         from fipy.viewers import MeshDimensionError
         raise MeshDimensionError("Can only plot 2D data")
     # this viewer can only display one variable
     return [vars[0]]
 def _getSuitableVars(self, vars):
     from fipy.variables.cellVariable import CellVariable
     vars = [var for var in _GistViewer._getSuitableVars(self, vars) \
       if (var.mesh.dim == 1 and isinstance(var, CellVariable))]
     if len(vars) > 1:
         vars = [var for var in vars if var.mesh is vars[0].mesh]
     if len(vars) == 0:
         from fipy.viewers import MeshDimensionError
         raise MeshDimensionError("Can only plot 1D data")
     return vars
 def _getSuitableVars(self, vars):
     vars = [var for var in _GistViewer._getSuitableVars(self, vars) \
       if (var.mesh.dim == 2 \
           and (isinstance(var, FaceVariable) \
                or isinstance(var, CellVariable)) and var.rank == 1)]
     if len(vars) == 0:
         from fipy.viewers import MeshDimensionError
         raise MeshDimensionError("Can only plot 2D vector data")
     # this viewer can only display one variable
     return [vars[0]]
Пример #5
0
 def _getSuitableVars(self, vars):
     from fipy.meshes.mesh2D import Mesh2D
     from fipy.variables.cellVariable import CellVariable
     vars = [var for var in AbstractMatplotlib2DViewer._getSuitableVars(self, vars) \
       if ((isinstance(var.mesh, Mesh2D) and isinstance(var, CellVariable))
           and var.rank == 0)]
     if len(vars) == 0:
         from fipy.viewers import MeshDimensionError
         raise MeshDimensionError("Matplotlib2DViewer can only display a rank-0, 2D CellVariable")
     # this viewer can only display one variable
     return [vars[0]]
Пример #6
0
 def _getSuitableVars(self, vars):
     from fipy.meshes.nonUniformGrid2D import NonUniformGrid2D
     from fipy.meshes.uniformGrid2D import UniformGrid2D
     from fipy.variables.cellVariable import CellVariable
     vars = [var for var in AbstractMatplotlib2DViewer._getSuitableVars(self, vars) \
       if ((isinstance(var.mesh, NonUniformGrid2D)
            or isinstance(var.mesh, UniformGrid2D))
           and isinstance(var, CellVariable))]
     if len(vars) == 0:
         from fipy.viewers import MeshDimensionError
         raise MeshDimensionError("The mesh must be a Grid2D instance")
     # this viewer can only display one variable
     return [vars[0]]
Пример #7
0
    def __init__(self,
                 distanceVar,
                 surfactantVar=None,
                 levelSetValue=0.,
                 title=None,
                 smooth=0,
                 zoomFactor=1.,
                 animate=False,
                 limits={},
                 **kwlimits):
        """
        Create a `MayaviSurfactantViewer`.

            >>> from fipy import *
            >>> dx = 1.
            >>> dy = 1.
            >>> nx = 11
            >>> ny = 11
            >>> Lx = ny * dy
            >>> Ly = nx * dx
            >>> mesh = Grid2D(dx = dx, dy = dy, nx = nx, ny = ny)
            >>> # from fipy.models.levelSet.distanceFunction.distanceVariable import DistanceVariable
            >>> var = DistanceVariable(mesh = mesh, value = -1)

            >>> x, y = mesh.cellCenters

            >>> var.setValue(1, where=(x - Lx / 2.)**2 + (y - Ly / 2.)**2 < (Lx / 4.)**2)
            >>> var.calcDistanceFunction()
            >>> viewer = MayaviSurfactantViewer(var, smooth = 2)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

            >>> var = DistanceVariable(mesh = mesh, value = -1)

            >>> var.setValue(1, where=(y > 2. * Ly / 3.) | ((x > Lx / 2.) & (y > Ly / 3.)) | ((y < Ly / 6.) & (x > Lx / 2)))
            >>> var.calcDistanceFunction()
            >>> viewer = MayaviSurfactantViewer(var)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

            >>> viewer = MayaviSurfactantViewer(var, smooth = 2)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

        :Parameters:

          - `distanceVar`: a `DistanceVariable` object.
          - `levelSetValue`: the value of the contour to be displayed
          - `title`: displayed at the top of the `Viewer` window
          - `animate`: whether to show only the initial condition and the
          - `limits`: a dictionary with possible keys `xmin`, `xmax`,
            `ymin`, `ymax`, `zmin`, `zmax`, `datamin`, `datamax`.  A 1D
            `Viewer` will only use `xmin` and `xmax`, a 2D viewer will also
            use `ymin` and `ymax`, and so on.  All viewers will use
            `datamin` and `datamax`.  Any limit set to a (default) value of
            `None` will autoscale.
            moving top boundary or to show all contours (Default)
        """

        kwlimits.update(limits)
        AbstractViewer.__init__(self, vars=[], title=title, **kwlimits)
        import mayavi
        self._viewer = mayavi.mayavi()
        self.distanceVar = distanceVar
        if surfactantVar is None:
            self.surfactantVar = numerix.zeros(len(self.distanceVar), 'd')
        else:
            self.surfactantVar = surfactantVar
        self.smooth = smooth
        self.zoomFactor = zoomFactor

        self.animate = animate
        if animate:
            self._initialCondition = None

        if distanceVar.mesh.dim != 2:
            raise MeshDimensionError(
                'The MayaviIsoViewer only works for 2D meshes.')
Пример #8
0
    def __init__(self,
                 distanceVar,
                 surfactantVar=None,
                 levelSetValue=0.,
                 title=None,
                 smooth=0,
                 zoomFactor=1.,
                 animate=False,
                 limits={},
                 **kwlimits):
        """
        Create a `MatplotlibSurfactantViewer`.

            >>> from fipy import *
            >>> m = Grid2D(nx=100, ny=100)
            >>> x, y = m.cellCenters
            >>> v = CellVariable(mesh=m, value=x**2 + y**2 - 10**2)
            >>> s = CellVariable(mesh=m, value=sin(x / 10) * cos(y / 30))
            >>> viewer = MatplotlibSurfactantViewer(distanceVar=v, surfactantVar=s)
            >>> from builtins import range
            >>> for r in range(1, 200):
            ...     v.setValue(x**2 + y**2 - r**2)
            ...     viewer.plot()

            >>> from fipy import *
            >>> dx = 1.
            >>> dy = 1.
            >>> nx = 11
            >>> ny = 11
            >>> Lx = ny * dy
            >>> Ly = nx * dx
            >>> mesh = Grid2D(dx = dx, dy = dy, nx = nx, ny = ny)
            >>> # from fipy.models.levelSet.distanceFunction.distanceVariable import DistanceVariable
            >>> var = DistanceVariable(mesh = mesh, value = -1)

            >>> x, y = mesh.cellCenters

            >>> var.setValue(1, where=(x - Lx / 2.)**2 + (y - Ly / 2.)**2 < (Lx / 4.)**2)
            >>> var.calcDistanceFunction()
            >>> viewer = MatplotlibSurfactantViewer(var, smooth = 2)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

            >>> var = DistanceVariable(mesh = mesh, value = -1)

            >>> var.setValue(1, where=(y > 2. * Ly / 3.) | ((x > Lx / 2.) & (y > Ly / 3.)) | ((y < Ly / 6.) & (x > Lx / 2)))
            >>> var.calcDistanceFunction()
            >>> viewer = MatplotlibSurfactantViewer(var)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

            >>> viewer = MatplotlibSurfactantViewer(var, smooth = 2)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

        Parameters
        ----------
        distanceVar : ~fipy.variables.distanceVariable.DistanceVariable
        levelSetValue : float
            the value of the contour to be displayed
        title : str
            displayed at the top of the `Viewer` window
        animate : bool
            whether to show only the initial condition and the
            moving top boundary or to show all contours (Default)
        limits : dict, optional
            a (deprecated) alternative to limit keyword arguments
        float xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax : float, optional
            displayed range of data. A 1D `Viewer` will only use `xmin` and
            `xmax`, a 2D viewer will also use `ymin` and `ymax`, and so on. All
            viewers will use `datamin` and `datamax`. Any limit set to a
            (default) value of `None` will autoscale.
        """

        kwlimits.update(limits)
        AbstractMatplotlibViewer.__init__(self,
                                          vars=[],
                                          title=title,
                                          **kwlimits)

        self.distanceVar = distanceVar
        if surfactantVar is None:
            self.surfactantVar = numerix.zeros(len(self.distanceVar), 'd')
        else:
            self.surfactantVar = surfactantVar
        self.smooth = smooth
        self.zoomFactor = zoomFactor

        self.animate = animate
        if animate:
            self._initialCondition = None

        if distanceVar.mesh.dim != 2:
            raise MeshDimensionError(
                'The MatplotlibSurfactantViewer only works for 2D meshes.')