Skip to content

Commit

Permalink
Add method to zero matrix entries
Browse files Browse the repository at this point in the history
  • Loading branch information
guyer committed Dec 24, 2023
1 parent ecf1f67 commit 36bff38
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fipy/matrices/pysparseMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ def T(self):

return _PysparseMatrix(matrix=A_T)

def zeroEntries(self):
_, irow, jcol = self.matrix.find()
self.put(0, irow, jcol)

class _PysparseMatrixFromShape(_PysparseMatrix):

def __init__(self, rows, cols,
Expand Down
4 changes: 4 additions & 0 deletions fipy/matrices/scipyMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ def T(self):
"""
return _ScipyMatrix(matrix=self.matrix.transpose(copy=True))

def zeroEntries(self):
id1, id2 = self.matrix.nonzero()
self.matrix[id1, id2] = 0

class _ScipyMatrixFromShape(_ScipyMatrix):

def __init__(self, rows, cols,
Expand Down
5 changes: 5 additions & 0 deletions fipy/matrices/sparseMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ def LIL(self):
def T(self):
raise NotImplementedError

def zeroEntries(self):
"""Insert zeros into nonzero matrix entries.
"""
raise NotImplementedError

def _matrix2mesh(self, ids):
"""Convert matrix row indices to mesh cell indices
"""
Expand Down
3 changes: 3 additions & 0 deletions fipy/matrices/trilinosMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ def T(self):

return _TrilinosMatrix(matrix=A_T_bis)

def zeroEntries(self):
self.matrix.PutScalar(0)

class _TrilinosMatrixFromShape(_TrilinosMatrix):
def __init__(self, rows, cols,
nonZerosPerRow=1, exactNonZeros=False, matrix=None):
Expand Down

0 comments on commit 36bff38

Please sign in to comment.