usnistgov / fipy

FiPy is a Finite Volume PDE solver written in Python
http://pages.nist.gov/fipy/en/latest
Other
489 stars 148 forks source link

`underRelaxation` doesn't work on coupled equations #971

Open guyer opened 9 months ago

guyer commented 9 months ago

As observed in #970, when using PETSc, Trilinos, or PySparse solvers,

>>> m = Grid1D(nx=3)
>>> v0 = CellVariable(mesh=m, value=0.)
>>> v1 = CellVariable(mesh=m, value=1.)
>>> eq0 = TransientTerm(var=v0) - DiffusionTerm(coeff=1., var=v0) - DiffusionTerm(coeff=2., var=v1)
>>> eq1 = TransientTerm(var=v1) - DiffusionTerm(coeff=3., var=v0) - DiffusionTerm(coeff=4., var=v1)
>>> eq = eq0 & eq1
>>> eq.sweep(dt=1., underRelaxation=0.5)

raises

Traceback (most recent call last):
  Cell In[4], line 7
    eq.sweep(dt=1., underRelaxation=0.5)
  File ~/Documents/research/FiPy/fipy/fipy/terms/term.py:220 in sweep
    solver._applyUnderRelaxation(underRelaxation=underRelaxation)
  File ~/Documents/research/FiPy/fipy/fipy/solvers/solver.py:112 in _applyUnderRelaxation
    self.matrix.putDiagonal(numerix.asarray(self.matrix.takeDiagonal()) / underRelaxation)
  File ~/Documents/research/FiPy/fipy/fipy/matrices/petscMatrix.py:264 in putDiagonal
    self.put(vector, ids, ids)
  File ~/Documents/research/FiPy/fipy/fipy/matrices/offsetSparseMatrix.py:23 in put
    SparseMatrix.put(self, vector, id1 + self.mesh.numberOfCells * self.equationIndex, id2 + self.mesh.numberOfCells * self.varIndex)
  File ~/Documents/research/FiPy/fipy/fipy/matrices/petscMatrix.py:708 in put
    vector, id1, id2 = self._m2m.globalVectorAndIDs(vector, id1, id2, overlapping)
  File ~/Documents/research/FiPy/fipy/fipy/matrices/sparseMatrix.py:271 in globalVectorAndIDs
    id1, id2, mask = self._getStencil(id1, id2, overlapping)
  File ~/Documents/research/FiPy/fipy/fipy/matrices/sparseMatrix.py:309 in _getStencil
    id2 = self.globalOverlappingColIDs[id2]
IndexError: index 6 is out of bounds for axis 0 with size 6

[!NOTE] It works with SciPy.