本文整理汇总了Python中fipy.tools.numerix.MA.sqrt方法的典型用法代码示例。如果您正苦于以下问题:Python MA.sqrt方法的具体用法?Python MA.sqrt怎么用?Python MA.sqrt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fipy.tools.numerix.MA
的用法示例。
在下文中一共展示了MA.sqrt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _calcFaceToCellDistances
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import sqrt [as 别名]
def _calcFaceToCellDistances(self):
tmp = MA.repeat(self.faceCenters[...,numerix.NewAxis,:], 2, 1)
# array -= masked_array screws up masking for on numpy 1.1
tmp = tmp - numerix.take(self.cellCenters, self.faceCellIDs, axis=1)
self.cellToFaceDistanceVectors = tmp
self.faceToCellDistances = MA.sqrt(MA.sum(tmp * tmp,0))
示例2: _calcCellDistAndVec
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import sqrt [as 别名]
def _calcCellDistAndVec(self):
tmp = numerix.take(self._cellCenters, self.faceCellIDs, axis=1)
tmp = tmp[...,1,:] - tmp[...,0,:]
tmp = MA.filled(MA.where(MA.getmaskarray(tmp), self._cellToFaceDistanceVectors[:,0], tmp))
cellDistanceVectors = tmp
cellDistances = MA.filled(MA.sqrt(MA.sum(tmp * tmp, 0)))
return cellDistances, cellDistanceVectors
示例3: _calcDistanceFunction
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import sqrt [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)
#.........这里部分代码省略.........