Skip to content

Commit

Permalink
Add custom DivergenceWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
guyer committed Nov 11, 2023
1 parent dd914bc commit 78493e3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fipy/solvers/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def __init__(cls, name, bases, dct):
if hasattr(cls, "status_name") and hasattr(cls, "suite"):
cls.name_registry[(cls.suite, cls.status_name)] = cls

class DivergenceWarning(UserWarning):
def __init__(self, divergence):
msg = "msg={status_name}, code={status_code}, residual={residual}".format(**divergence.info)
super(DivergenceWarning, self).__init__(msg)

class ConvergenceBase(with_metaclass(_ConvergenceMeta, object)):
"""Information about whether and why a solver converged.
Expand Down Expand Up @@ -153,7 +158,7 @@ class Divergence(ConvergenceBase):
"""

def warn(self):
warnings.warn("({status_code}, {status_name}): {residual}".format(**self.info), stacklevel=5)
warnings.warn(DivergenceWarning(self), stacklevel=5)

class IterationDivergence(Divergence):
"""Exceeded maximum iterations.
Expand Down

0 comments on commit 78493e3

Please sign in to comment.