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

Added more Scipy integrators to handle stiff problems #2880

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 36 additions & 7 deletions openpnm/integrators/_scipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
from openpnm.algorithms._solution import TransientSolution
from openpnm.integrators import Integrator

__all__ = ['ScipyRK45']
__all__ = ['ScipyIntegrator',
'ScipyRK45',
'ScipyBDF',
'ScipyLSODA']


class ScipyRK45(Integrator):
"""Integrator class based on SciPy's implementation of RK45"""
class ScipyIntegrator(Integrator):
"""Integrator class based on SciPy's ODE solvers"""

def __init__(self, atol=1e-6, rtol=1e-6, verbose=False, linsolver=None):
def __init__(self,
method="RK45",
atol=1e-6,
rtol=1e-6,
verbose=False,
linsolver=None):
self.method = method
self.atol = atol
self.rtol = rtol
self.verbose = verbose
Expand Down Expand Up @@ -47,10 +56,30 @@
"atol": self.atol,
"rtol": self.rtol,
"t_eval": saveat,
# FIXME: uncomment next line when/if scipy#11815 is merged
# "verbose": self.verbose,
# "verbose": self.verbose, # Uncomment if supported in scipy
}
sol = solve_ivp(rhs, tspan, x0, method="RK45", **options)
sol = solve_ivp(rhs, tspan, x0, method=self.method, **options)
if sol.success:
return TransientSolution(sol.t, sol.y)
raise Exception(sol.message)


class ScipyRK45(ScipyIntegrator):
"""Integrator class using SciPy's RK45 method"""

def __init__(self, method="RK45", **kwargs):
super().__init__(method=method, **kwargs)


class ScipyBDF(ScipyIntegrator):
"""Integrator class using SciPy's BDF method"""

def __init__(self, method="BDF", **kwargs):
super().__init__(method=method, **kwargs)

Check warning on line 78 in openpnm/integrators/_scipy.py

View check run for this annotation

Codecov / codecov/patch

openpnm/integrators/_scipy.py#L78

Added line #L78 was not covered by tests


class ScipyLSODA(ScipyIntegrator):
"""Integrator class using SciPy's LSODA method"""

def __init__(self, method="LSODA", **kwargs):
super().__init__(method=method, **kwargs)

Check warning on line 85 in openpnm/integrators/_scipy.py

View check run for this annotation

Codecov / codecov/patch

openpnm/integrators/_scipy.py#L85

Added line #L85 was not covered by tests