本文整理汇总了Python中fipy.tools.numerix.MA.take方法的典型用法代码示例。如果您正苦于以下问题:Python MA.take方法的具体用法?Python MA.take怎么用?Python MA.take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fipy.tools.numerix.MA
的用法示例。
在下文中一共展示了MA.take方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _connectFaces
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import take [as 别名]
def _connectFaces(self, faces0, faces1):
"""
Merge faces on the same mesh. This is used to create periodic
meshes. The first list of faces, `faces1`, will be the faces
that are used to add to the matrix diagonals. The faces in
`faces2` will not be used. They aren't deleted but their
adjacent cells are made to point at `faces1`. The list
`faces2` are not altered, they still remain as members of
exterior faces.
>>> from fipy.meshes.numMesh.grid2D import Grid2D
>>> mesh = Grid2D(nx = 2, ny = 2, dx = 1., dy = 1.)
>>> from fipy.tools import parallel
>>> print parallel.procID != 0 or (mesh._getCellFaceIDs() == [[0, 1, 2, 3],
... [7, 8, 10, 11],
... [2, 3, 4, 5],
... [6, 7, 9, 10]]).flatten().all()
True
>>> mesh._connectFaces(numerix.nonzero(mesh.getFacesLeft()), numerix.nonzero(mesh.getFacesRight()))
>>> print parallel.procID != 0 or (mesh._getCellFaceIDs() == [[0, 1, 2, 3],
... [7, 6, 10, 9],
... [2, 3, 4, 5],
... [6, 7, 9, 10]]).flatten().all()
True
"""
## check for errors
## check that faces are members of exterior faces
from fipy.variables.faceVariable import FaceVariable
faces = FaceVariable(mesh=self, value=False)
faces[faces0] = True
faces[faces1] = True
assert (faces | self.getExteriorFaces() == self.getExteriorFaces()).all()
## following assert checks number of faces are equal, normals are opposite and areas are the same
assert numerix.alltrue(numerix.take(self.areaProjections, faces0, axis=1)
== numerix.take(-self.areaProjections, faces1, axis=1))
## extract the adjacent cells for both sets of faces
faceCellIDs0 = self.faceCellIDs[0]
faceCellIDs1 = self.faceCellIDs[1]
## set the new adjacent cells for `faces0`
MA.put(faceCellIDs1, faces0, MA.take(faceCellIDs0, faces0))
MA.put(faceCellIDs0, faces0, MA.take(faceCellIDs0, faces1))
self.faceCellIDs[0] = faceCellIDs0
self.faceCellIDs[1] = faceCellIDs1
## extract the face to cell distances for both sets of faces
faceToCellDistances0 = self.faceToCellDistances[0]
faceToCellDistances1 = self.faceToCellDistances[1]
## set the new faceToCellDistances for `faces0`
MA.put(faceToCellDistances1, faces0, MA.take(faceToCellDistances0, faces0))
MA.put(faceToCellDistances0, faces0, MA.take(faceToCellDistances0, faces1))
self.faceToCellDistances[0] = faceToCellDistances0
self.faceToCellDistances[1] = faceToCellDistances1
## calculate new cell distances and add them to faces0
numerix.put(self.cellDistances, faces0, MA.take(faceToCellDistances0 + faceToCellDistances1, faces0))
## change the direction of the face normals for faces0
for dim in range(self.getDim()):
faceNormals = self.faceNormals[dim].copy()
numerix.put(faceNormals, faces0, MA.take(faceNormals, faces1))
self.faceNormals[dim] = faceNormals
## Cells that are adjacent to faces1 are changed to point at faces0
## get the cells adjacent to faces1
faceCellIDs = MA.take(self.faceCellIDs[0], faces1)
## get all the adjacent faces for those particular cells
cellFaceIDs = numerix.take(self.cellFaceIDs, faceCellIDs, axis=1)
for i in range(cellFaceIDs.shape[0]):
## if the faces is a member of faces1 then change the face to point at
## faces0
cellFaceIDs[i] = MA.where(cellFaceIDs[i] == faces1,
faces0,
cellFaceIDs[i])
## add those faces back to the main self.cellFaceIDs
tmp = self.cellFaceIDs[i]
numerix.put(tmp, faceCellIDs, cellFaceIDs[i])
self.cellFaceIDs[i] = tmp
## calculate new topology
_CommonMesh._calcTopology(self)
## calculate new geometry
self._calcFaceToCellDistanceRatio()
self._calcCellToCellDistances()
self._calcScaledGeometry()
self._calcFaceAspectRatios()
示例2: _connectFaces
# 需要导入模块: from fipy.tools.numerix import MA [as 别名]
# 或者: from fipy.tools.numerix.MA import take [as 别名]
def _connectFaces(self, faces0, faces1):
"""
Merge faces on the same mesh. This is used to create periodic
meshes. The first list of faces, `faces1`, will be the faces
that are used to add to the matrix diagonals. The faces in
`faces2` will not be used. They aren't deleted but their
adjacent cells are made to point at `faces1`. The list
`faces2` are not altered, they still remain as members of
exterior faces.
>>> from fipy.meshes.nonUniformGrid2D import NonUniformGrid2D
>>> mesh = NonUniformGrid2D(nx = 2, ny = 2, dx = 1., dy = 1.)
>>> print((mesh.cellFaceIDs == [[0, 1, 2, 3],
... [7, 8, 10, 11],
... [2, 3, 4, 5],
... [6, 7, 9, 10]]).flatten().all()) # doctest: +PROCESSOR_0
True
>>> mesh._connectFaces(numerix.nonzero(mesh.facesLeft), numerix.nonzero(mesh.facesRight))
>>> print((mesh.cellFaceIDs == [[0, 1, 2, 3],
... [7, 6, 10, 9],
... [2, 3, 4, 5],
... [6, 7, 9, 10]]).flatten().all()) # doctest: +PROCESSOR_0
True
"""
## check for errors
## check that faces are members of exterior faces
from fipy.variables.faceVariable import FaceVariable
faces = FaceVariable(mesh=self, value=False)
faces[faces0] = True
faces[faces1] = True
assert (faces | self.exteriorFaces == self.exteriorFaces).all()
## following assert checks number of faces are equal, normals are opposite and areas are the same
assert numerix.allclose(numerix.take(self._areaProjections, faces0, axis=1),
numerix.take(-self._areaProjections, faces1, axis=1))
## extract the adjacent cells for both sets of faces
faceCellIDs0 = self.faceCellIDs[0]
faceCellIDs1 = self.faceCellIDs[1]
## set the new adjacent cells for `faces0`
MA.put(faceCellIDs1, faces0, MA.take(faceCellIDs0, faces0))
MA.put(faceCellIDs0, faces0, MA.take(faceCellIDs0, faces1))
self.faceCellIDs[0] = faceCellIDs0
self.faceCellIDs[1] = faceCellIDs1
## extract the face to cell distances for both sets of faces
faceToCellDistances0 = self._faceToCellDistances[0]
faceToCellDistances1 = self._faceToCellDistances[1]
## set the new faceToCellDistances for `faces0`
MA.put(faceToCellDistances1, faces0, MA.take(faceToCellDistances0, faces0))
MA.put(faceToCellDistances0, faces0, MA.take(faceToCellDistances0, faces1))
self._faceToCellDistances[0] = faceToCellDistances0
self._faceToCellDistances[1] = faceToCellDistances1
## calculate new cell distances and add them to faces0
numerix.put(self._cellDistances, faces0, MA.take(faceToCellDistances0 + faceToCellDistances1, faces0))
## change the direction of the face normals for faces0
for dim in range(self.dim):
faceNormals = self.faceNormals[dim].copy()
numerix.put(faceNormals, faces0, MA.take(faceNormals, faces1))
self.faceNormals[dim] = faceNormals
## Cells that are adjacent to faces1 are changed to point at faces0
## get the cells adjacent to faces1
faceCellIDs = MA.take(self.faceCellIDs[0], faces1)
## get all the adjacent faces for those particular cells
cellFaceIDs = numerix.take(self.cellFaceIDs, faceCellIDs, axis=1)
for i in range(cellFaceIDs.shape[0]):
## if the faces is a member of faces1 then change the face to point at
## faces0
cellFaceIDs[i] = MA.where(cellFaceIDs[i] == faces1,
faces0,
cellFaceIDs[i])
## add those faces back to the main self.cellFaceIDs
numerix.put(self.cellFaceIDs[i], faceCellIDs, cellFaceIDs[i])
## calculate new topology
self._setTopology()
## calculate new geometry
self._handleFaceConnection()
self.scale = self.scale['length']