示例#1
0
    def divergence(self):
        r"""the divergence of `self`, :math:`\vec{u}`,

        .. math:: \nabla\cdot\vec{u} \approx \frac{\sum_f (\vec{u}\cdot\hat{n})_f A_f}{V_P}

        Returns
        -------
        divergence : CellVariable
            one rank lower than `self`

        Examples
        --------

        >>> from fipy.meshes import Grid2D
        >>> from fipy.variables.cellVariable import CellVariable
        >>> mesh = Grid2D(nx=3, ny=2)
        >>> from builtins import range
        >>> var = CellVariable(mesh=mesh, value=list(range(3*2)))
        >>> print(var.faceGrad.divergence)
        [ 4.  3.  2. -2. -3. -4.]

        """
        if not hasattr(self, '_divergence'):
            from fipy.variables.addOverFacesVariable import _AddOverFacesVariable

            s = (slice(0, None, None), ) + (numerix.newaxis, ) * (
                len(self.shape) - 2) + (slice(0, None, None), )
            self._divergence = _AddOverFacesVariable(
                (self * self.mesh._orientedAreaProjections[s]).sum(0))

        return self._divergence
示例#2
0
    def _calcAnisotropySource(self, coeff, mesh, var):

        if not hasattr(self, 'anisotropySource'):
            if len(coeff) > 1:
                gradients = var.getGrad().getHarmonicFaceValue().dot(self._getRotationTensor(mesh))
                from fipy.variables.addOverFacesVariable import _AddOverFacesVariable
                self.anisotropySource = _AddOverFacesVariable(gradients[1:].dot(coeff[1:])) * mesh.getCellVolumes()
示例#3
0
    def __calcAnisotropySource(self, coeff, mesh, var):

        if not hasattr(self, 'anisotropySource'):
            if len(coeff) > 1:
                unconstrainedVar = var + 0
                gradients = unconstrainedVar.grad.harmonicFaceValue.dot(self.__getRotationTensor(mesh))
                from fipy.variables.addOverFacesVariable import _AddOverFacesVariable
                self.anisotropySource = _AddOverFacesVariable(gradients[1:].dot(coeff[1:])) * mesh.cellVolumes
示例#4
0
    def __calcAnisotropySource(self, coeff, mesh, var):

        if not hasattr(self, 'anisotropySource'):
            if len(coeff) > 1:
                unconstrainedVar = var + 0
                gradients = unconstrainedVar.grad.harmonicFaceValue.dot(
                    self.__getRotationTensor(mesh))
                from fipy.variables.addOverFacesVariable import _AddOverFacesVariable
                self.anisotropySource = _AddOverFacesVariable(
                    gradients[1:].dot(coeff[1:])) * mesh.cellVolumes
示例#5
0
 def getDivergence(self):
     """
         >>> from fipy.meshes.grid2D import Grid2D
         >>> from fipy.variables.cellVariable import CellVariable
         >>> mesh = Grid2D(nx=3, ny=2)
         >>> var = CellVariable(mesh=mesh, value=range(3*2))
         >>> print var.getFaceGrad().getDivergence()
         [ 4.  3.  2. -2. -3. -4.]
         
     """
     if not hasattr(self, 'divergence'):
         from fipy.variables.addOverFacesVariable import _AddOverFacesVariable
         self.divergence = _AddOverFacesVariable(self.dot(self.getMesh()._getOrientedAreaProjections()))
         
     return self.divergence
示例#6
0
    def divergence(self):
        """
            >>> from fipy.meshes import Grid2D
            >>> from fipy.variables.cellVariable import CellVariable
            >>> mesh = Grid2D(nx=3, ny=2)
            >>> var = CellVariable(mesh=mesh, value=range(3*2))
            >>> print var.faceGrad.divergence
            [ 4.  3.  2. -2. -3. -4.]
            
        """
        if not hasattr(self, '_divergence'):
            from fipy.variables.addOverFacesVariable import _AddOverFacesVariable

            s = (slice(0,None,None),) + (numerix.newaxis,) * (len(self.shape) - 2) + (slice(0,None,None),)
            self._divergence = _AddOverFacesVariable((self * self.mesh._orientedAreaProjections[s]).sum(0))

        return self._divergence
    def divergence(self):
        """
            >>> from fipy.meshes import Grid2D
            >>> from fipy.variables.cellVariable import CellVariable
            >>> mesh = Grid2D(nx=3, ny=2)
            >>> var = CellVariable(mesh=mesh, value=range(3*2))
            >>> print var.faceGrad.divergence
            [ 4.  3.  2. -2. -3. -4.]
            
        """
        if not hasattr(self, '_divergence'):
            from fipy.variables.addOverFacesVariable import _AddOverFacesVariable

            s = (slice(0, None, None), ) + (numerix.newaxis, ) * (
                len(self.shape) - 2) + (slice(0, None, None), )
            self._divergence = _AddOverFacesVariable(
                (self * self.mesh._orientedAreaProjections[s]).sum(0))

        return self._divergence