本文整理汇总了Python中fipy.tools.numerix.MA.masked_array方法的典型用法代码示例。如果您正苦于以下问题:Python MA.masked_array方法的具体用法?Python MA.masked_array怎么用?Python MA.masked_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fipy.tools.numerix.MA
的用法示例。
在下文中一共展示了MA.masked_array方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deleteIslands
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import masked_array [as 别名]
def deleteIslands(self):
cellToCellIDs = self.mesh._cellToCellIDs
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 = numerix.array(MA.where(tmp, -1, self.value))
示例2: _getDifferences
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import masked_array [as 别名]
def _getDifferences(self, adjacentValues, cellValues, oldArray, cellToCellIDs, mesh):
dAP = mesh._cellToCellDistances
## adjacentGradient = numerix.take(oldArray.grad, cellToCellIDs)
adjacentGradient = numerix.take(oldArray.grad, mesh._cellToCellIDs, axis=-1)
adjacentNormalGradient = numerix.dot(adjacentGradient, mesh._cellNormals)
adjacentUpValues = cellValues + 2 * dAP * adjacentNormalGradient
cellIDs = numerix.repeat(numerix.arange(mesh.numberOfCells)[numerix.newaxis, ...],
mesh._maxFacesPerCell, axis=0)
cellIDs = MA.masked_array(cellIDs, mask = MA.getmask(mesh._cellToCellIDs))
cellGradient = numerix.take(oldArray.grad, cellIDs, axis=-1)
cellNormalGradient = numerix.dot(cellGradient, mesh._cellNormals)
cellUpValues = adjacentValues - 2 * dAP * cellNormalGradient
cellLaplacian = (cellUpValues + adjacentValues - 2 * cellValues) / dAP**2
adjacentLaplacian = (adjacentUpValues + cellValues - 2 * adjacentValues) / dAP**2
adjacentLaplacian = adjacentLaplacian.filled(0)
cellLaplacian = cellLaplacian.filled(0)
mm = numerix.where(cellLaplacian * adjacentLaplacian < 0.,
0.,
numerix.where(abs(cellLaplacian) > abs(adjacentLaplacian),
adjacentLaplacian,
cellLaplacian))
return FirstOrderAdvectionTerm._getDifferences(self, adjacentValues, cellValues, oldArray, cellToCellIDs, mesh) - mm * dAP / 2.
示例3: _calcDistanceFunction
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import masked_array [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)
#.........这里部分代码省略.........