本文整理汇总了Python中fipy.tools.numerix.MA.zeros方法的典型用法代码示例。如果您正苦于以下问题:Python MA.zeros方法的具体用法?Python MA.zeros怎么用?Python MA.zeros使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fipy.tools.numerix.MA
的用法示例。
在下文中一共展示了MA.zeros方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: faceCellIDs
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import zeros [as 别名]
def faceCellIDs(self):
XYids = MA.zeros((2, self.nx, self.ny, self.nz + 1), 'l')
indices = numerix.indices((self.nx, self.ny, self.nz + 1))
XYids[1] = indices[0] + (indices[1] + indices[2] * self.ny) * self.nx
XYids[0] = XYids[1] - self.nx * self.ny
XYids[0, ..., 0] = XYids[1, ..., 0]
XYids[1, ..., 0] = MA.masked
XYids[1, ..., -1] = MA.masked
XZids = MA.zeros((2, self.nx, self.ny + 1, self.nz), 'l')
indices = numerix.indices((self.nx, self.ny + 1, self.nz))
XZids[1] = indices[0] + (indices[1] + indices[2] * self.ny) * self.nx
XZids[0] = XZids[1] - self.nx
XZids[0,:, 0,:] = XZids[1,:, 0,:]
XZids[1,:, 0,:] = MA.masked
XZids[1,:, -1,:] = MA.masked
YZids = MA.zeros((2, self.nx + 1, self.ny, self.nz), 'l')
indices = numerix.indices((self.nx + 1, self.ny, self.nz))
YZids[1] = indices[0] + (indices[1] + indices[2] * self.ny) * self.nx
YZids[0] = YZids[1] - 1
YZids[0, 0] = YZids[1, 0]
YZids[1, 0] = MA.masked
YZids[1, -1] = MA.masked
return MA.concatenate((XYids.swapaxes(1, 3).reshape((2, self.numberOfXYFaces)),
XZids.swapaxes(1, 3).reshape((2, self.numberOfXZFaces)),
YZids.swapaxes(1, 3).reshape((2, self.numberOfYZFaces))), axis=1)
示例2: _getCellToCellDistances
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import zeros [as 别名]
def _getCellToCellDistances(self):
distances = MA.zeros((2, self.numberOfCells), "d")
distances[:] = self.dx
if self.numberOfCells > 0:
distances[0, 0] = self.dx / 2.0
distances[1, -1] = self.dx / 2.0
return distances
示例3: _cellToCellDistances
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import zeros [as 别名]
def _cellToCellDistances(self):
distances = MA.zeros((2, self.numberOfCells), 'd')
distances[:] = self.dx
if self.numberOfCells > 0:
distances[0, 0] = self.dx / 2.
distances[1, -1] = self.dx / 2.
return distances
示例4: _cellToCellIDs
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import zeros [as 别名]
def _cellToCellIDs(self):
ids = MA.zeros((4, self.nx, self.ny), 'l')
indices = numerix.indices((self.nx, self.ny))
ids[0] = indices[0] + (indices[1] - 1) * self.nx
ids[1] = (indices[0] + 1) + indices[1] * self.nx
ids[2] = indices[0] + (indices[1] + 1) * self.nx
ids[3] = (indices[0] - 1) + indices[1] * self.nx
if self.ny > 0:
ids[0, ..., 0] = MA.masked
ids[2, ..., -1] = MA.masked
if self.nx > 0:
ids[1, -1, ...] = MA.masked
ids[3, 0, ...] = MA.masked
return MA.reshape(ids.swapaxes(1, 2), (4, self.numberOfCells))
示例5: _cellToCellIDs
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import zeros [as 别名]
def _cellToCellIDs(self):
ids = MA.zeros((6, self.nx, self.ny, self.nz), 'l')
indices = numerix.indices((self.nx, self.ny, self.nz))
ids[0] = indices[0] + (indices[1] + indices[2] * self.ny) * self.nx - 1
ids[1] = indices[0] + (indices[1] + indices[2] * self.ny) * self.nx + 1
ids[2] = indices[0] + (indices[1] + indices[2] * self.ny - self.nz) * self.nx
ids[3] = indices[0] + (indices[1] + indices[2] * self.ny + self.nz) * self.nx
ids[4] = indices[0] + (indices[1] + (indices[2] - 1) * self.ny) * self.nx
ids[5] = indices[0] + (indices[1] + (indices[2] + 1) * self.ny) * self.nx
ids[0, 0, ...] = MA.masked
ids[1,-1, ...] = MA.masked
ids[2,..., 0,...] = MA.masked
ids[3,...,-1,...] = MA.masked
ids[4,..., 0] = MA.masked
ids[5,..., -1] = MA.masked
return MA.reshape(ids.swapaxes(1,3), (6, self.numberOfCells))
示例6: _calcFaceCellIDs
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import zeros [as 别名]
def _calcFaceCellIDs(self):
array = MA.array(MA.indices(self.cellFaceIDs.shape, 'l')[1],
mask=MA.getmask(self.cellFaceIDs))
self.faceCellIDs = MA.zeros((2, self.numberOfFaces), 'l')
## Nasty bug: MA.put(arr, ids, values) fills its ids and
## values arguments when masked! This was not the behavior
## that was assumed when used below. It was only working
## because the old fill value was 0 and the first element of
## the array needed to be 0 since the cell's face was
## 0. numerix.put() has been changed to deal with this
## properly.
## MA.put(firstRow, cellFaceIDsFlat[::-1], array[::-1])
## MA.put(secondRow, cellFaceIDsFlat, array)
firstRow = self.faceCellIDs[0]
secondRow = self.faceCellIDs[1]
numerix.put(firstRow, self.cellFaceIDs[::-1,::-1], array[::-1,::-1])
numerix.put(secondRow, self.cellFaceIDs, array)
mask = ((False,) * self.numberOfFaces, (firstRow == secondRow))
self.faceCellIDs = MA.sort(MA.array(self.faceCellIDs, mask = mask),
axis=0)
示例7: _cellToCellIDs
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import zeros [as 别名]
def _cellToCellIDs(self):
ids = MA.zeros((6, self.nx, self.ny, self.nz), 'l')
indices = numerix.indices((self.nx, self.ny, self.nz))
nxy = self.nx * self.ny
same = indices[0] + indices[1] * self.nx + indices[2] * nxy
ids[0] = same - 1
ids[1] = same + 1
ids[2] = same - self.nx
ids[3] = same + self.nx
ids[4] = same - nxy
ids[5] = same + nxy
if self.nx > 0:
ids[0, 0, ...] = MA.masked
ids[1, -1, ...] = MA.masked
if self.ny > 0:
ids[2,:, 0,:] = MA.masked
ids[3,:, -1,:] = MA.masked
if self.nz > 0:
ids[4, ..., 0] = MA.masked
ids[5, ..., -1] = MA.masked
return MA.reshape(ids.swapaxes(1, 3), (6, self.numberOfCells))
示例8: _calcDistanceFunction
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import zeros [as 别名]
def _calcDistanceFunction(self, extensionVariable = None, narrowBandWidth = None, deleteIslands = False):
if narrowBandWidth == None:
narrowBandWidth = self.narrowBandWidth
## calculate interface values
cellToCellIDs = self.mesh._getCellToCellIDs()
if deleteIslands:
adjVals = numerix.take(self.value, cellToCellIDs)
adjInterfaceValues = MA.masked_array(adjVals, mask = (adjVals * self.value) > 0)
masksum = numerix.sum(numerix.logical_not(MA.getmask(adjInterfaceValues)), 0)
tmp = MA.logical_and(masksum == 4, self.value > 0)
self.value = MA.where(tmp, -1, self.value)
adjVals = numerix.take(self.value, cellToCellIDs)
adjInterfaceValues = MA.masked_array(adjVals, mask = (adjVals * self.value) > 0)
dAP = self.mesh._getCellToCellDistances()
distances = abs(self.value * dAP / (self.value - adjInterfaceValues))
indices = MA.argsort(distances, 0)
sign = (self.value > 0) * 2 - 1
s = distances[indices[0], numerix.arange(indices.shape[1])]
if self.mesh.getDim() == 2:
t = distances[indices[1], numerix.arange(indices.shape[1])]
u = distances[indices[2], numerix.arange(indices.shape[1])]
if indices.shape[1] > 0:
ns = self.cellNormals[..., indices[0], numerix.arange(indices.shape[1])]
nt = self.cellNormals[..., indices[1], numerix.arange(indices.shape[1])]
else:
ns = MA.zeros(self.cellNormals.shape[:-1] + (0,))
nt = MA.zeros(self.cellNormals.shape[:-1] + (0,))
signedDistance = MA.where(MA.getmask(s),
self.value,
MA.where(MA.getmask(t),
sign * s,
MA.where(abs(numerix.dot(ns,nt)) < 0.9,
sign * s * t / MA.sqrt(s**2 + t**2),
MA.where(MA.getmask(u),
sign * s,
sign * s * u / MA.sqrt(s**2 + u**2)
)
)
)
)
else:
signedDistance = MA.where(MA.getmask(s),
self.value,
sign * s)
self.value = signedDistance
## calculate interface flag
masksum = numerix.sum(numerix.logical_not(MA.getmask(distances)), 0)
interfaceFlag = (masksum > 0).astype('l')
## spread the extensionVariable to the whole interface
flag = True
if extensionVariable is None:
extensionVariable = numerix.zeros(self.mesh.getNumberOfCells(), 'd')
flag = False
ext = numerix.zeros(self.mesh.getNumberOfCells(), 'd')
positiveInterfaceFlag = numerix.where(self.value > 0, interfaceFlag, 0)
negativeInterfaceIDs = numerix.nonzero(numerix.where(self.value < 0, interfaceFlag, 0))[0]
for id in negativeInterfaceIDs:
tmp, extensionVariable[...,id] = self._calcTrialValue(id, positiveInterfaceFlag, extensionVariable)
if flag:
self.value = self.tmpValue.copy()
## evaluate the trialIDs
adjInterfaceFlag = numerix.take(interfaceFlag, cellToCellIDs)
hasAdjInterface = (numerix.sum(MA.filled(adjInterfaceFlag, 0), 0) > 0).astype('l')
trialFlag = numerix.logical_and(numerix.logical_not(interfaceFlag), hasAdjInterface).astype('l')
trialIDs = list(numerix.nonzero(trialFlag)[0])
evaluatedFlag = interfaceFlag
for id in trialIDs:
self.value[...,id], extensionVariable[id] = self._calcTrialValue(id, evaluatedFlag, extensionVariable)
while len(trialIDs):
id = trialIDs[numerix.argmin(abs(numerix.take(self.value, trialIDs)))]
if abs(self.value[...,id]) > narrowBandWidth / 2:
break
trialIDs.remove(id)
#.........这里部分代码省略.........