def _explicitBuildMatrixPy(self, oldArray, id1, id2, b, coeffMatrix, mesh, interiorFaces, dt, weight): oldArrayId1, oldArrayId2 = self._getOldAdjacentValues(oldArray, id1, id2, dt=dt) cell1diag = numerix.take(coeffMatrix['cell 1 diag'], interiorFaces) cell1offdiag = numerix.take(coeffMatrix['cell 1 offdiag'], interiorFaces) cell2diag = numerix.take(coeffMatrix['cell 2 diag'], interiorFaces) cell2offdiag = numerix.take(coeffMatrix['cell 2 offdiag'], interiorFaces) vector.putAdd(b, id1, -(cell1diag * oldArrayId1 + cell1offdiag * oldArrayId2)) vector.putAdd(b, id2, -(cell2diag * oldArrayId2 + cell2offdiag * oldArrayId1))
def _explicitBuildMatrixInline_(self, oldArray, id1, id2, b, coeffMatrix, mesh, interiorFaces, dt, weight): oldArrayId1, oldArrayId2 = self._getOldAdjacentValues(oldArray, id1, id2, dt=dt) cell1diag = numerix.take(coeffMatrix['cell 1 diag'], interiorFaces) cell1offdiag = numerix.take(coeffMatrix['cell 1 offdiag'], interiorFaces) cell2diag = numerix.take(coeffMatrix['cell 2 diag'], interiorFaces) cell2offdiag = numerix.take(coeffMatrix['cell 2 offdiag'], interiorFaces) vector.putAdd(b, id1, -(cell1diag * oldArrayId1 + cell1offdiag * oldArrayId2)) vector.putAdd(b, id2, -(cell2diag * oldArrayId2 + cell2offdiag * oldArrayId1))
def _buildMatrix(self, SparseMatrix, Ncells, MaxFaces, coeff): """Leave **L** unchanged and add gradient to **b** :Parameters: - `SparseMatrix`: *unused* (empty matrix) - `Ncells`: Size of **b**-vector - `MaxFaces`: *unused* - `coeff`: *unused* """ bb = numerix.zeros((Ncells,), 'd') if not self.boundaryConditionApplied: vector.putAdd(bb, self.adjacentCellIDs, -self.contribution) self.boundaryConditionApplied = True return (0, bb)
def _buildMatrix(self, SparseMatrix, Ncells, MaxFaces, coeff): """Leave **L** unchanged and add gradient to **b** :Parameters: - `SparseMatrix`: *unused* (empty matrix) - `Ncells`: Size of **b**-vector - `MaxFaces`: *unused* - `coeff`: *unused* """ bb = numerix.zeros((Ncells, ), 'd') if not self.boundaryConditionApplied: vector.putAdd(bb, self.adjacentCellIDs, -self.contribution) self.boundaryConditionApplied = True return (0, bb)
def _buildMatrix(self, SparseMatrix, Ncells, MaxFaces, coeff): """Set boundary equal to value. A `tuple` of (`LL`, `bb`) is calculated, to be added to the Term's (:math:`\mathsf{L}`, :math:`\mathsf{b}`) matrices. Parameters ---------- SparseMatrix : ~fipy.matrices.sparseMatrix._SparseMatrix Ncells : int Size of matrices MaxFaces : int Maximum number of faces per cell (determines bandwidth of :math:`\mathsf{L}`) coeff : list Contribution to adjacent cell diagonal and :math:`\mathsf{b}` vector by this exterior face """ faces = self.faces.value LL = SparseMatrix(mesh=self.faces.mesh, sizeHint=len(self.faces), bandwidth=1) LL.addAt(coeff['cell 1 diag'][faces], self.adjacentCellIDs, self.adjacentCellIDs) ## The following has been commented out because ## FixedValue's _buildMatrix() method is called for ## each term in the equation. Thus minusCoeff can be different for each term. ## ## if not hasattr(self, 'minusCoeff'): ## self.minusCoeff = -coeff['cell 1 offdiag'] ## self.minusCoeff.dontCacheMe() bb = numerix.zeros((Ncells, ), 'd') value = self.value if isinstance(value, Variable): value = value.value if value.shape == faces.shape: value = value[faces] vector.putAdd(bb, self.adjacentCellIDs, -coeff['cell 1 offdiag'].value[faces] * value) return (LL, bb)
def _buildMatrix(self, SparseMatrix, Ncells, MaxFaces, coeff): """Leave **L** unchanged and add gradient to **b** Parameters ---------- SparseMatrix : ~fipy.matrices.sparseMatrix._SparseMatrix *unused* (empty matrix) Ncells : int Size of **b** vector MaxFaces *unused* coeff : list *unused* """ bb = numerix.zeros((Ncells,), 'd') if not self.boundaryConditionApplied: vector.putAdd(bb, self.adjacentCellIDs, -self.contribution) self.boundaryConditionApplied = True return (0, bb)
def _buildMatrix(self, SparseMatrix, Ncells, MaxFaces, coeff): """Set boundary equal to value. A `tuple` of (`LL`, `bb`) is calculated, to be added to the Term's (:math:`\mathsf{L}`, :math:`\mathsf{b}`) matrices. :Parameters: - `SparseMatrix`: Sparse matrix class to use - `Ncells`: Size of matrices - `MaxFaces`: bandwidth of :math:`\mathsf{L}` - `coeff`: contribution to adjacent cell diagonal and :math:`\mathsf{b}`-vector by this exterior face """ faces = self.faces.value LL = SparseMatrix(mesh=self.faces.mesh, sizeHint=len(self.faces), bandwidth=1) LL.addAt(coeff['cell 1 diag'][faces], self.adjacentCellIDs, self.adjacentCellIDs) ## The following has been commented out because ## FixedValue's _buildMatrix() method is called for ## each term in the equation. Thus minusCoeff can be different for each term. ## ## if not hasattr(self, 'minusCoeff'): ## self.minusCoeff = -coeff['cell 1 offdiag'] ## self.minusCoeff.dontCacheMe() bb = numerix.zeros((Ncells,), 'd') value = self.value if isinstance(value, Variable): value = value.value if value.shape == faces.shape: value = value[faces] vector.putAdd(bb, self.adjacentCellIDs, -coeff['cell 1 offdiag'].value[faces] * value) return (LL, bb)