当前位置: 首页>>代码示例>>Python>>正文


Python variable.Variable类代码示例

本文整理汇总了Python中fipy.variables.variable.Variable的典型用法代码示例。如果您正苦于以下问题:Python Variable类的具体用法?Python Variable怎么用?Python Variable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Variable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: allclose

    def allclose(self, other, rtol=1.e-5, atol=1.e-8):
         if self.getMesh().communicator.Nproc > 1:
             def allcloseParallel(a, b):
                 return self.getMesh().communicator.allclose(a, b, rtol=rtol, atol=atol)

             operatorClass = Variable._OperatorVariableClass(self, baseClass=Variable)
             return self._BinaryOperatorVariable(allcloseParallel,
                                                 other, 
                                                 operatorClass=operatorClass,
                                                 opShape=(),
                                                 canInline=False)            
         else:
             return Variable.allclose(self, other, rtol=rtol, atol=atol)
开发者ID:calbaker,项目名称:FiPy-2.1.3,代码行数:13,代码来源:meshVariable.py

示例2: allequal

    def allequal(self, other):
         if self.getMesh().communicator.Nproc > 1:
             def allequalParallel(a, b):
                 return self.getMesh().communicator.allequal(a, b)

             operatorClass = Variable._OperatorVariableClass(self, baseClass=Variable)
             return self._BinaryOperatorVariable(allequalParallel,
                                                 other, 
                                                 operatorClass=operatorClass,
                                                 opShape=(),
                                                 canInline=False)            
         else:
             return Variable.allequal(self, other)
开发者ID:calbaker,项目名称:FiPy-2.1.3,代码行数:13,代码来源:meshVariable.py

示例3: allequal

    def allequal(self, other):
         if parallel.Nproc > 1:
             from mpi4py import MPI
             def allequalParallel(a, b):
                 return MPI.COMM_WORLD.allreduce(numerix.allequal(a, b), op=MPI.LAND)

             operatorClass = Variable._OperatorVariableClass(self, baseClass=Variable)
             return self._BinaryOperatorVariable(allequalParallel,
                                                 other, 
                                                 operatorClass=operatorClass,
                                                 opShape=(),
                                                 canInline=False)            
         else:
             return Variable.allequal(self, other)
开发者ID:regmi,项目名称:fipy,代码行数:14,代码来源:meshVariable.py

示例4: shape

    def shape(self):
        """
        >>> from fipy.meshes import Grid2D
        >>> from fipy.variables.cellVariable import CellVariable
        >>> mesh = Grid2D(nx=2, ny=3)
        >>> var = CellVariable(mesh=mesh)
        >>> print numerix.allequal(var.shape, (6,)) # doctest: +PROCESSOR_0
        True
        >>> print numerix.allequal(var.arithmeticFaceValue.shape, (17,)) # doctest: +PROCESSOR_0
        True
        >>> print numerix.allequal(var.grad.shape, (2, 6)) # doctest: +PROCESSOR_0
        True
        >>> print numerix.allequal(var.faceGrad.shape, (2, 17)) # doctest: +PROCESSOR_0
        True

        Have to account for zero length arrays

        >>> from fipy import Grid1D
        >>> m = Grid1D(nx=0)
        >>> v = CellVariable(mesh=m, elementshape=(2,))
        >>> (v * 1).shape
        (2, 0)
        
        """
        return (Variable._getShape(self)
                or (self.elementshape + self._getShapeFromMesh(self.mesh)) 
                or ())
开发者ID:LWhitson2,项目名称:fipy,代码行数:27,代码来源:meshVariable.py

示例5: _OperatorVariableClass

    def _OperatorVariableClass(self, baseClass=None):
        baseClass = Variable._OperatorVariableClass(self, baseClass=baseClass)
                                     
        class _MeshOperatorVariable(baseClass):
            def __init__(self, op, var, opShape=None, canInline=True,
                         *args, **kwargs):
                mesh = reduce(lambda a, b: a or b, 
                              [getattr(v, "mesh", None) for v in var])
                for shape in [opShape] + [getattr(v, "opShape", None) for v in var]:
                    if shape is not None:
                        opShape = shape
                        break
##                 opShape = reduce(lambda a, b: a or b, 
##                                  [opShape] + [getattr(v, "opShape", None) for v in var])
                if opShape is not None:
                    elementshape = opShape[:-1]
                else:
                    elementshape = reduce(lambda a, b: a or b, 
                                          [getattr(v, "elementshape", None) for v in var])

                baseClass.__init__(self, mesh=mesh, op=op, var=var, 
                                   opShape=opShape, canInline=canInline,
                                   elementshape=elementshape,
                                   *args, **kwargs)
                                 
            def getRank(self):
                return len(self.opShape) - 1
                
        return _MeshOperatorVariable
开发者ID:calbaker,项目名称:FiPy-2.1.3,代码行数:29,代码来源:meshVariable.py

示例6: __init__

    def __init__(self,
                 surfactantVar = None,
                 distanceVar = None,
                 bulkVar = None,
                 rateConstant = None,
                 otherVar = None,
                 otherBulkVar = None,
                 otherRateConstant = None,
                 consumptionCoeff = None):
        """
        Create a `AdsorbingSurfactantEquation` object.

        :Parameters:
          - `surfactantVar`: The `SurfactantVariable` to be solved for.
          - `distanceVar`: The `DistanceVariable` that marks the interface.
          - `bulkVar`: The value of the `surfactantVar` in the bulk.
          - `rateConstant`: The adsorption rate of the `surfactantVar`.
          - `otherVar`: Another `SurfactantVariable` with more surface affinity.
          - `otherBulkVar`: The value of the `otherVar` in the bulk.
          - `otherRateConstant`: The adsorption rate of the `otherVar`.
          - `consumptionCoeff`: The rate that the `surfactantVar` is consumed during deposition.
                             
        """

        self.eq = TransientTerm(coeff = 1) - ExplicitUpwindConvectionTerm(SurfactantConvectionVariable(distanceVar))

        self.dt = Variable(0.)
        mesh = distanceVar.mesh
        adsorptionCoeff = self.dt * bulkVar * rateConstant
        spCoeff = adsorptionCoeff * distanceVar._cellInterfaceFlag
        scCoeff = adsorptionCoeff * distanceVar.cellInterfaceAreas / mesh.cellVolumes

        self.eq += ImplicitSourceTerm(spCoeff) - scCoeff

        if otherVar is not None:
            otherSpCoeff = self.dt * otherBulkVar * otherRateConstant * distanceVar._cellInterfaceFlag
            otherScCoeff = -otherVar.interfaceVar * scCoeff

            self.eq += ImplicitSourceTerm(otherSpCoeff) - otherScCoeff

            vars = (surfactantVar, otherVar)
        else:
            vars = (surfactantVar,)

        total = 0
        for var in vars:
            total += var.interfaceVar
        maxVar = (total > 1) * distanceVar._cellInterfaceFlag

        val = distanceVar.cellInterfaceAreas / mesh.cellVolumes
        for var in vars[1:]:
            val -= distanceVar._cellInterfaceFlag * var
        
        spMaxCoeff = 1e20 * maxVar
        scMaxCoeff = spMaxCoeff * val * (val > 0)
            
        self.eq += ImplicitSourceTerm(spMaxCoeff) - scMaxCoeff - 1e-40

        if consumptionCoeff is not None:
            self.eq += ImplicitSourceTerm(consumptionCoeff)
开发者ID:LWhitson2,项目名称:fipy,代码行数:60,代码来源:adsorbingSurfactantEquation.py

示例7: __init__

    def __init__(self, coeff = (1.,)):
        """
        Create a `DiffusionTerm`.

        :Parameters:
          - `coeff`: `Tuple` or `list` of `FaceVariables` or numbers.
          
        """
        if type(coeff) not in (type(()), type([])):
            coeff = (coeff,)

        self.order = len(coeff) * 2


        if len(coeff) > 0:
            self.nthCoeff = coeff[0]

            from fipy.variables.variable import Variable
            if not isinstance(self.nthCoeff, Variable):
                self.nthCoeff = Variable(value = self.nthCoeff)

            from fipy.variables.cellVariable import CellVariable
            if isinstance(self.nthCoeff, CellVariable):
                self.nthCoeff = self.nthCoeff.getArithmeticFaceValue()

        else:
            self.nthCoeff = None

        Term.__init__(self, coeff = coeff)
        
        if self.order > 0:
            self.lowerOrderDiffusionTerm = DiffusionTerm(coeff = coeff[1:])
开发者ID:calbaker,项目名称:FiPy-2.1.3,代码行数:32,代码来源:diffusionTerm.py

示例8: setValue

 def setValue(self, value, unit = None, where = None):
     if where is not None:
         shape = numerix.getShape(where)
         if shape != self.shape \
           and shape == self._getShapeFromMesh(mesh=self.getMesh()):
             for dim in self.elementshape:
                 where = numerix.repeat(where[numerix.newaxis, ...], repeats=dim, axis=0)
     
     return Variable.setValue(self, value=value, unit=unit, where=where)
开发者ID:calbaker,项目名称:FiPy-2.1.3,代码行数:9,代码来源:meshVariable.py

示例9: _shapeClassAndOther

    def _shapeClassAndOther(self, opShape, operatorClass, other):
        """
        Determine the shape of the result, the base class of the result, and (if
        necessary) a modified form of `other` that is suitable for the
        operation.
        
        By default, returns the result of the generic
        `Variable._shapeClassAndOther()`, but if that fails, and if each
        dimension of `other` is exactly the `Mesh` dimension, do what the user
        probably "meant" and project `other` onto the `Mesh`.
        
        >>> from fipy import *
        >>> mesh = Grid1D(nx=5)
        >>> A = numerix.arange(5)
        >>> B = Variable(1.)
        >>> import warnings
        >>> savedFilters = list(warnings.filters)
        >>> warnings.resetwarnings()
        >>> warnings.simplefilter("error", UserWarning, append=True)
        >>> C = CellVariable(mesh=mesh) * (A * B)
        Traceback (most recent call last):
          ...
        UserWarning: The expression `(multiply([0 1 2 3 4], Variable(value=array(1.0))))` has been cast to a constant `CellVariable`
        >>> warnings.filters = savedFilters
        """
        otherShape = numerix.getShape(other)
        if (not isinstance(other, _MeshVariable) 
            and otherShape is not () 
            and otherShape[-1] == self._globalNumberOfElements):
            if (isinstance(other, Variable) and len(other.requiredVariables) > 0):
                import warnings
                warnings.warn("The expression `%s` has been cast to a constant `%s`" 
                              % (repr(other), self._variableClass.__name__), 
                              UserWarning, stacklevel=4)
            other = self._variableClass(value=other, mesh=self.mesh)

        newOpShape, baseClass, newOther = Variable._shapeClassAndOther(self, opShape, operatorClass, other)
        
        if ((newOpShape is None or baseClass is None)
            and numerix.alltrue(numerix.array(numerix.getShape(other)) == self.mesh.dim)):
                newOpShape, baseClass, newOther = Variable._shapeClassAndOther(self, opShape, operatorClass, other[..., numerix.newaxis])

        return (newOpShape, baseClass, newOther)
开发者ID:LWhitson2,项目名称:fipy,代码行数:43,代码来源:meshVariable.py

示例10: _axisClass

 def _axisClass(self, axis):
     """
     if we operate along the mesh elements, then this is no longer a
     `_MeshVariable`, otherwise we get back a `_MeshVariable` of the same
     class, but lower rank.
     """
     if axis is None or axis == len(self.shape) - 1 or axis == -1:
         return Variable._OperatorVariableClass(self, baseClass=Variable)
     else:
         return self._OperatorVariableClass()
开发者ID:calbaker,项目名称:FiPy-2.1.3,代码行数:10,代码来源:meshVariable.py

示例11: sum

 def sum(self, axis=None):
     if self.getMesh().communicator.Nproc > 1 and (axis is None or axis == len(self.getShape()) - 1):
         def sumParallel(a):
             a = a[self._getLocalNonOverlappingIDs()]
             return self.getMesh().communicator.sum(a, axis=axis)
             
         return self._axisOperator(opname="sumVar", 
                                   op=sumParallel, 
                                   axis=axis)
     else:
         return Variable.sum(self, axis=axis)
开发者ID:calbaker,项目名称:FiPy-2.1.3,代码行数:11,代码来源:meshVariable.py

示例12: max

 def max(self, axis=None):
     if self.mesh.communicator.Nproc > 1 and (axis is None or axis == len(self.shape) - 1):
         def maxParallel(a):
             return self._maxminparallel_(a=a, axis=axis, default=-numerix.inf, 
                                          fn=a.max, fnParallel=self.mesh.communicator.MaxAll)
             
         return self._axisOperator(opname="maxVar", 
                                   op=maxParallel, 
                                   axis=axis)
     else:
         return Variable.max(self, axis=axis)
开发者ID:LWhitson2,项目名称:fipy,代码行数:11,代码来源:meshVariable.py

示例13: min

 def min(self, axis=None):
     if self.getMesh().communicator.Nproc > 1 and (axis is None or axis == len(self.getShape()) - 1):
         def minParallel(a):
             return self._maxminparallel_(a=a, axis=axis, default=numerix.inf, 
                                          fn=a.min, fnParallel=self.getMesh().communicator.epetra_comm.MinAll)
             
         return self._axisOperator(opname="minVar", 
                                   op=minParallel, 
                                   axis=axis)
     else:
         return Variable.min(self, axis=axis)
开发者ID:calbaker,项目名称:FiPy-2.1.3,代码行数:11,代码来源:meshVariable.py

示例14: sum

 def sum(self, axis=None):
     if self.mesh.communicator.Nproc > 1 and (axis is None or axis == len(self.shape) - 1):
         def sumParallel(a):
             a = a[..., self._localNonOverlappingIDs]
             return self.mesh.communicator.sum(a, axis=axis)
             
         return self._axisOperator(opname="sumVar", 
                                   op=sumParallel, 
                                   axis=axis)
     else:
         return Variable.sum(self, axis=axis)
开发者ID:LWhitson2,项目名称:fipy,代码行数:11,代码来源:meshVariable.py

示例15: min

 def min(self, axis=None):
     if parallel.Nproc > 1 and (axis is None or axis == len(self.getShape()) - 1):
         from PyTrilinos import Epetra
         def minParallel(a):
             return self._maxminparallel_(a=a, axis=axis, default=numerix.inf, 
                                          fn=a.min, fnParallel=Epetra.PyComm().MinAll)
             
         return self._axisOperator(opname="minVar", 
                                   op=minParallel, 
                                   axis=axis)
     else:
         return Variable.min(self, axis=axis)
开发者ID:regmi,项目名称:fipy,代码行数:12,代码来源:meshVariable.py


注:本文中的fipy.variables.variable.Variable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。