def _checkCoeff(self, var): if isinstance(self.coeff, CellVariable): shape = self.coeff.shape[:-1] else: shape = self.coeff.shape if var.rank == 1 and (shape == () or len(shape) == 1): if len(self.coeff.shape) == 2 and isinstance(self.coeff, CellVariable): self.coeff *= numerix.identity(var.shape[0])[..., numerix.newaxis] else: self.coeff *= numerix.identity(var.shape[0]) if isinstance(self.coeff, CellVariable): shape = self.coeff.shape[:-1] else: shape = self.coeff.shape if var.rank == 0: if shape != (): raise TypeError("The coefficient must be rank 0 for a rank 0 solution variable.") if shape != () and len(shape) != 2 and shape[0] != shape[1]: raise TypeError("The coefficient must be a rank-0 or rank-2 vector or a scalar value.") if var.rank == 1: if shape == (): pass elif len(shape) != 2: raise TypeError("The coefficient must be rank 2 or rank 0 for a rank 1 solution variable.") elif var.shape[0] != shape[0]: raise TypeError("The coefficient (N , N) shape must match the the solution variable (N,) shape.")
def _checkCoeff(self, var): if isinstance(self.coeff, CellVariable): shape = self.coeff.shape[:-1] else: shape = self.coeff.shape if var.rank == 1 and (shape == () or len(shape) == 1): if len(self.coeff.shape) == 2 and isinstance(self.coeff, CellVariable): self.coeff *= numerix.identity(var.shape[0])[...,numerix.newaxis] else: self.coeff *= numerix.identity(var.shape[0]) if isinstance(self.coeff, CellVariable): shape = self.coeff.shape[:-1] else: shape = self.coeff.shape if var.rank == 0: if shape != (): raise TypeError, "The coefficient must be rank 0 for a rank 0 solution variable." if shape != () and len(shape) != 2 and shape[0] != shape[1]: raise TypeError, "The coefficient must be a rank-0 or rank-2 vector or a scalar value." if var.rank == 1: if shape == (): pass elif len(shape) != 2: raise TypeError, "The coefficient must be rank 2 or rank 0 for a rank 1 solution variable." elif var.shape[0] != shape[0]: raise TypeError, "The coefficient (N , N) shape must match the the solution variable (N,) shape."
def _calcGeomCoeff(self, var): mesh = var.mesh if self.nthCoeff is not None: coeff = self.nthCoeff shape = numerix.getShape(coeff) if isinstance(coeff, FaceVariable): rank = coeff.rank else: rank = len(shape) if var.rank == 0: anisotropicRank = rank elif var.rank == 1: anisotropicRank = rank - 2 else: raise IndexError('the solution variable has the wrong rank') if anisotropicRank == 0 and self._treatMeshAsOrthogonal(mesh): if coeff.shape != () and not isinstance(coeff, FaceVariable): coeff = coeff[..., numerix.newaxis] tmpBop = (coeff * FaceVariable(mesh=mesh, value=mesh._faceAreas) / mesh._cellDistances)[numerix.newaxis, :] else: if anisotropicRank == 1 or anisotropicRank == 0: coeff = coeff * numerix.identity(mesh.dim) if anisotropicRank > 0: shape = numerix.getShape(coeff) if mesh.dim != shape[0] or mesh.dim != shape[1]: raise IndexError( 'diffusion coefficient tensor is not an appropriate shape for this mesh' ) faceNormals = FaceVariable(mesh=mesh, rank=1, value=mesh.faceNormals) rotationTensor = self.__getRotationTensor(mesh) rotationTensor[:, 0] = rotationTensor[:, 0] / mesh._cellDistances tmpBop = faceNormals.dot(coeff).dot( rotationTensor) * mesh._faceAreas return tmpBop else: return None
def _calcGeomCoeff(self, var): mesh = var.mesh if self.nthCoeff is not None: coeff = self.nthCoeff shape = numerix.getShape(coeff) if isinstance(coeff, FaceVariable): rank = coeff.rank else: rank = len(shape) if var.rank == 0: anisotropicRank = rank elif var.rank == 1: anisotropicRank = rank - 2 else: raise IndexError, 'the solution variable has the wrong rank' if anisotropicRank == 0 and self._treatMeshAsOrthogonal(mesh): if coeff.shape != () and not isinstance(coeff, FaceVariable): coeff = coeff[...,numerix.newaxis] tmpBop = (coeff * FaceVariable(mesh=mesh, value=mesh._faceAreas) / mesh._cellDistances)[numerix.newaxis, :] else: if anisotropicRank == 1 or anisotropicRank == 0: coeff = coeff * numerix.identity(mesh.dim) if anisotropicRank > 0: shape = numerix.getShape(coeff) if mesh.dim != shape[0] or mesh.dim != shape[1]: raise IndexError, 'diffusion coefficent tensor is not an appropriate shape for this mesh' faceNormals = FaceVariable(mesh=mesh, rank=1, value=mesh.faceNormals) rotationTensor = self.__getRotationTensor(mesh) rotationTensor[:,0] = rotationTensor[:,0] / mesh._cellDistances tmpBop = faceNormals.dot(coeff).dot(rotationTensor) * mesh._faceAreas return tmpBop else: return None
def _calcGeomCoeff(self, mesh): if self.nthCoeff is not None: coeff = self.nthCoeff shape = numerix.getShape(coeff) from fipy.variables.faceVariable import FaceVariable if isinstance(coeff, FaceVariable): rank = coeff.getRank() else: rank = len(shape) if rank == 0 and self._treatMeshAsOrthogonal(mesh): tmpBop = (coeff * mesh._getFaceAreas() / mesh._getCellDistances())[numerix.newaxis, :] else: if rank == 1 or rank == 0: coeff = coeff * numerix.identity(mesh.getDim()) if rank > 0: shape = numerix.getShape(coeff) if mesh.getDim() != shape[0] or mesh.getDim() != shape[1]: raise IndexError, 'diffusion coefficent tensor is not an appropriate shape for this mesh' faceNormals = FaceVariable(mesh=mesh, rank=1, value=mesh._getFaceNormals()) rotationTensor = self._getRotationTensor(mesh) rotationTensor[:,0] = rotationTensor[:,0] / mesh._getCellDistances() tmpBop = faceNormals.dot(coeff).dot(rotationTensor) * mesh._getFaceAreas() return tmpBop else: return None