Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop divide by zero warning in LU solvers #790

Merged
merged 3 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions fipy/solvers/petsc/linearLUSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class LinearLUSolver(PETScSolver):
A direct solve is performed.

"""

def __init__(self, tolerance=1e-10, iterations=10, precon="lu"):
"""
:Parameters:
- `tolerance`: The required error tolerance.
- `iterations`: The maximum number of iterative steps to perform.
- `precon`: *Ignored*.
- `precon`: *Ignored*.

"""
PETScSolver.__init__(self, tolerance=tolerance,
Expand All @@ -38,26 +38,26 @@ def _solve_(self, L, x, b):
# TODO: SuperLU invoked with PCFactorSetMatSolverType(pc, MATSOLVERSUPERLU)
# see: http://www.mcs.anl.gov/petsc/petsc-dev/src/ksp/ksp/examples/tutorials/ex52.c.html
# PETSc.PC().setFactorSolverType("superlu")

L.assemble()
ksp.setOperators(L)
ksp.setFromOptions()

for iteration in range(self.iterations):
errorVector = L * x - b
tol = errorVector.norm()

if iteration == 0:
tol0 = tol
if (tol / tol0) <= self.tolerance:

if tol <= self.tolerance * tol0:
break

xError = x.copy()

ksp.solve(errorVector, xError)
x -= xError

if 'FIPY_VERBOSE_SOLVER' in os.environ:
from fipy.tools.debug import PRINT
# L.view()
Expand Down
2 changes: 1 addition & 1 deletion fipy/solvers/pysparse/linearLUSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _solve_(self, L, x, b):
for iteration in range(self.iterations):
errorVector = L * x - b

if (numerix.sqrt(numerix.sum(errorVector**2)) / error0) <= self.tolerance:
if numerix.sqrt(numerix.sum(errorVector**2)) <= self.tolerance * error0:
break

xError = numerix.zeros(len(b), 'd')
Expand Down
2 changes: 1 addition & 1 deletion fipy/solvers/scipy/linearLUSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _solve_(self, L, x, b):
for iteration in range(min(self.iterations, 10)):
errorVector = L * x - b

if (numerix.sqrt(numerix.sum(errorVector**2)) / error0) <= self.tolerance:
if numerix.sqrt(numerix.sum(errorVector**2)) <= self.tolerance * error0:
break

xError = LU.solve(errorVector)
Expand Down