本文整理汇总了Python中fipy.variables.variable.Variable.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Variable.__init__方法的具体用法?Python Variable.__init__怎么用?Python Variable.__init__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fipy.variables.variable.Variable
的用法示例。
在下文中一共展示了Variable.__init__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from fipy.variables.variable import Variable [as 别名]
# 或者: from fipy.variables.variable.Variable import __init__ [as 别名]
def __init__(self, mesh, name='', value=0., rank=None, elementshape=None,
unit=None, cached=1):
"""
:Parameters:
- `mesh`: the mesh that defines the geometry of this `Variable`
- `name`: the user-readable name of the `Variable`
- `value`: the initial value
- `rank`: the rank (number of dimensions) of each element of this
`Variable`. Default: 0
- `elementshape`: the shape of each element of this variable
Default: `rank * (mesh.getDim(),)`
- `unit`: the physical units of the `Variable`
"""
from fipy.tools import debug
if isinstance(value, (list, tuple)):
value = numerix.array(value)
if isinstance(value, _MeshVariable):
if mesh is None:
mesh = value.mesh
elif mesh != value.mesh:
raise ValueError, "The new 'Variable' must use the same mesh as the supplied value"
self.mesh = mesh
value = self._globalToLocalValue(value)
if value is None:
array = None
elif not isinstance(value, _Constant) and isinstance(value, Variable):
name = name or value.name
unit = None
if isinstance(value, _MeshVariable):
if not isinstance(value, self._getVariableClass()):
raise TypeError, "A '%s' cannot be cast to a '%s'" % (value._getVariableClass().__name__,
self._getVariableClass().__name__)
if elementshape is not None and elementshape != value.shape[:-1]:
raise ValueError, "'elementshape' != shape of elements of 'value'"
if rank is not None and rank != value.getRank():
raise ValueError, "'rank' != rank of 'value'"
elementshape = value.shape[:-1]
array = None
# value = value._copyValue()
if elementshape is None:
valueShape = numerix.getShape(value)
if valueShape != () and valueShape[-1] == self._getShapeFromMesh(mesh)[-1]:
if elementshape is not None and elementshape != valueShape[:-1]:
raise ValueError, "'elementshape' != shape of elements of 'value'"
if rank is not None and rank != len(valueShape[:-1]):
raise ValueError, "'rank' != rank of 'value'"
elementshape = valueShape[:-1]
elif rank is None and elementshape is None:
elementshape = valueShape
if rank is None:
if elementshape is None:
elementshape = ()
elif elementshape is None:
elementshape = rank * (mesh.getDim(),)
elif len(elementshape) != rank:
raise ValueError, 'len(elementshape) != rank'
self.elementshape = elementshape
if not locals().has_key("array"):
if numerix._isPhysical(value):
dtype = numerix.obj2sctype(value.value)
else:
dtype = numerix.obj2sctype(value)
array = numerix.zeros(self.elementshape
+ self._getShapeFromMesh(mesh),
dtype)
if numerix._broadcastShape(array.shape, numerix.shape(value)) is None:
if not isinstance(value, Variable):
value = _Constant(value)
value = value[..., numerix.newaxis]
Variable.__init__(self, name=name, value=value, unit=unit,
array=array, cached=cached)
示例2: __init__
# 需要导入模块: from fipy.variables.variable import Variable [as 别名]
# 或者: from fipy.variables.variable.Variable import __init__ [as 别名]
def __init__(self, var):
Variable.__init__(self, unit = var.unit)
self.var = self._requires(var)