Skip to content

Commit

Permalink
feat(fode): more robust time span handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Oct 2, 2023
1 parent 7c2e85c commit ced7271
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 152 deletions.
2 changes: 0 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Features
^^^^^^^^

* Added an example with the fractional Lorenz system (:ghpr:`13`).
* Support setting a constant for
:meth:`~pycaputo.fode.FractionalDifferentialEquationMethod.predict_time_step`.
* Add a guess for the number of corrector iterations
for :class:`~pycaputo.fode.CaputoPECEMethod` from [Garrappa2010]_.
* Implement :class:`~pycaputo.quadrature.RiemannLiouvilleSimpsonMethod`, a
Expand Down
21 changes: 16 additions & 5 deletions docs/fode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,34 @@ History Handling
.. autoclass:: FixedState
.. autoclass:: FixedSizeHistory

Interface
---------
Time Interval Handling
----------------------

.. exception:: StepEstimateError

.. autoclass:: TimeSpan
.. autoclass:: FixedTimeSpan
.. autoclass:: GradedTimeSpan
.. autoclass:: FixedLipschitzTimeSpan
.. autoclass:: LipschitzTimeSpan

Time Stepping Events
--------------------

.. autoclass:: Event
.. autoclass:: StepFailed
.. autoclass:: StepCompleted

Time Stepping Interface
-----------------------

.. autoclass:: FractionalDifferentialEquationMethod
.. autoclass:: ProductIntegrationMethod

.. autofunction:: evolve
.. autofunction:: advance
.. autofunction:: make_initial_condition

.. autofunction:: make_predict_time_step_fixed
.. autofunction:: make_predict_time_step_graded

Caputo Derivative FODEs
=======================

Expand Down
4 changes: 4 additions & 0 deletions docs/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ References
International Journal of Computer Mathematics, Vol. 87, pp. 2281--2290, 2010,
`DOI <https://doi.org/10.1080/00207160802624331>`__.
.. [Baleanu2012] D. Baleanu, K. Diethelm, E. Scalas, J. J. Trujillo,
*Fractional Calculus - Models and Numerical Methods*,
World Scientific, 2012.
.. [Garrappa2015] R. Garrappa,
*Numerical Evaluation of Two and Three Parameter Mittag-Leffler Functions*,
SIAM Journal on Numerical Analysis, Vol. 53, pp. 1350--1369, 2015,
Expand Down
5 changes: 2 additions & 3 deletions examples/brusselator-predictor-corrector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def brusselator(t: float, y: Array, *, a: float, mu: float) -> Array:

# {{{ solve

from pycaputo.fode import CaputoPECEMethod
from pycaputo.fode import CaputoPECEMethod, FixedTimeSpan

alpha = 0.8
a = 1.0
Expand All @@ -33,9 +33,8 @@ def brusselator(t: float, y: Array, *, a: float, mu: float) -> Array:

stepper = CaputoPECEMethod(
derivative_order=(alpha,),
predict_time_step=1.0e-2,
tspan=FixedTimeSpan.from_data(1.0e-2, tstart=0.0, tfinal=50.0),
source=partial(brusselator, a=a, mu=mu),
tspan=(0, 50),
y0=(y0,),
corrector_iterations=1,
)
Expand Down
5 changes: 2 additions & 3 deletions examples/fractional-lorenz.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def lorenz_jac(t: float, y: Array, *, sigma: float, rho: float, beta: float) ->

# {{{ solve

from pycaputo.fode import CaputoWeightedEulerMethod
from pycaputo.fode import CaputoWeightedEulerMethod, FixedTimeSpan

# NOTE: order example taken from https://doi.org/10.1016/j.chaos.2009.03.016
alpha = (0.985, 0.99, 0.99)
Expand All @@ -49,10 +49,9 @@ def lorenz_jac(t: float, y: Array, *, sigma: float, rho: float, beta: float) ->

stepper = CaputoWeightedEulerMethod(
derivative_order=alpha,
predict_time_step=1.0e-2,
tspan=FixedTimeSpan.from_data(1.0e-2, tstart=0.0, tfinal=75.0),
source=partial(lorenz, sigma=sigma, rho=rho, beta=beta),
source_jac=partial(lorenz_jac, sigma=sigma, rho=rho, beta=beta),
tspan=(0, 75),
y0=(y0,),
theta=1.0,
)
Expand Down
16 changes: 12 additions & 4 deletions pycaputo/fode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@

from pycaputo.fode.base import (
Event,
FixedLipschitzTimeSpan,
FixedTimeSpan,
FractionalDifferentialEquationMethod,
GradedTimeSpan,
LipschitzTimeSpan,
StepCompleted,
StepEstimateError,
StepFailed,
TimeSpan,
advance,
evolve,
make_initial_condition,
make_predict_time_step_fixed,
make_predict_time_step_graded,
)
from pycaputo.fode.caputo import (
CaputoForwardEulerMethod,
Expand Down Expand Up @@ -47,6 +51,12 @@
"FixedState",
"FractionalDifferentialEquationMethod",
"History",
"StepEstimateError",
"TimeSpan",
"FixedTimeSpan",
"FixedLipschitzTimeSpan",
"GradedTimeSpan",
"LipschitzTimeSpan",
"ProductIntegrationMethod",
"ProductIntegrationState",
"State",
Expand All @@ -56,6 +66,4 @@
"advance",
"evolve",
"make_initial_condition",
"make_predict_time_step_fixed",
"make_predict_time_step_graded",
)
Loading

0 comments on commit ced7271

Please sign in to comment.