Skip to content

Commit

Permalink
Added more integrator classes to current _scipy.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaguer committed Dec 22, 2023
1 parent 5e2404c commit b31fde7
Showing 1 changed file with 36 additions and 7 deletions.
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 @@ def solve(self, rhs, x0, tspan, saveat, **kwargs):
"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

0 comments on commit b31fde7

Please sign in to comment.