pyfod package¶
Submodules¶
pyfod.fod module¶
This module provides support for three common definitions of fractional derivative in the limiting case of . The definitions available include:
Riemann-Liouville -
riemannliouville()
Caputo -
caputo()
Grünwald-Letnikov -
grunwaldletnikov()
For more details regarding this definitions of fractional derivatives please see [Pod98].
Note
In each method you are required to provide a function handle. Depending on the method being used, you may need to define your function using sympy to allow for extended numerical precision.
-
pyfod.fod.
caputo
(f, lower, upper, dt=0.0001, alpha=0.0, df=None, quadrature='GLegRS', **kwargs)[source]¶ Caputo fractional derivative calculator for .
The general definition for Caputo fractional derivative is
where . In the limiting case where this further simplifies to
To evaluate this we simply need to define a finite-difference scheme for approximating .
- Args:
- Kwargs: name (type) - default
- Returns:
dict
fd: Fractional derivative.
i1: Value of integral.
q1: Quadrature object.
-
pyfod.fod.
grunwaldletnikov
(f, lower, upper, n=100, dt=None, alpha=0.0)[source]¶ Grünwald-Letnikov fractional derivative calculator.
We have implemented the reverse Grünwald-Letnikov definition.
Note
The package as a whole was built for problems where ; however, this definition for Grünwald-Letnikov does not necessarily have the same constraints. It has not been tested for values of , but in principle it will work.
- Args:
- Kwargs: name (type) - default
- Returns:
dict
fd: Fractional derivative.
-
pyfod.fod.
riemannliouville
(f, lower, upper, dt=0.0001, alpha=0.0, quadrature='GLegRS', **kwargs)[source]¶ Riemann-Liouville fractional derivative calculator for .
The general definition for Riemann-Liouville fractional derivative is
where . In the limiting case where this further simplifies to
By defining
we can numerically approximate this definition of fractional derivative as
where . For more details regarding this approach please see [AGomezA17] and [MPOS18].
- Args:
- Kwargs: name (type) - default
- Returns:
dict
fd: Fractional derivative
i1: Value of integral .
i2: Value of integral .
q1: Quadrature object for .
q2: Quadrature object for .
pyfod.quadrature module¶
This module contains a variety of classes for performing quadrature. While this
module was developed to support the fractional derivative calculators in
fod
, the quadrature methods themselves are still applicable to a
wide variety of integration problems.
The quadrature methods are defined to approximate integrals of the form
where is typically equal to . The user is only required to provide the function and the limits of integration. We observe that by setting , this integral is transformed to
which is applicable to many problems.
-
class
pyfod.quadrature.
GaussLaguerre
(deg=5, lower=0.0, upper=1.0, alpha=0.0, f=None, extend_precision=True, n_digits=30, singularity=None)[source]¶ Bases:
object
Gauss-Laguerre quadrature.
- Kwargs: name (type) - default
deg (
int
) - 5: Degree of laguerre polynomials.lower (
float
) - 0.0: Lower limit of integration.upper (
float
) - 1.0: Upper limit of integration.alpha (
float
) - 0.0: Exponent of singular kernel.f (def) - None: Function handle.
extend_precision (
bool
) - True: Flag to use sympy extended precision.n_digits (
int
) - 30: Number of digits in extended precision.singularity (
float
) - None: Location of singularity.
-
class
pyfod.quadrature.
GaussLegendre
(ndom=5, deg=5, lower=0.0, upper=1.0, alpha=0.0, f=None, singularity=None)[source]¶ Bases:
object
Gauss-Legendre quadrature.
- Kwargs: name (type) - default
ndom (
int
) - 5: Number of quadrature intervals.deg (
int
) - 5: Degree of legendre polynomials.lower (
float
) - 0.0: Lower limit of integration.upper (
float
) - 1.0: Upper limit of integration.alpha (
float
) - 0.0: Exponent of singular kernel.f (def) - None: Function handle.
singularity (
float
) - None: Location of singularity.
-
class
pyfod.quadrature.
GaussLegendreGaussLaguerre
(ndom=5, gleg_deg=4, glag_deg=20, percent=0.9, ts=None, lower=0.0, upper=1.0, alpha=0.0, f=None, extend_precision=True, n_digits=30)[source]¶ Bases:
object
Gauss-Legendre, Gauss-Laguerre quadrature.
- Kwargs: name (type) - default
ndom (
int
) - 5: Number of Gauss-Legendre quadrature intervals.gleg_deg (
int
) - 4: Degree of legendre polynomials.glag_deg (
int
) - 20: Degree of laguerre polynomials.percent (
float
) - 0.9: Percentage of interval in which to use Gauss-Legendre method.ts (
float
) - None: User-defined time to switch from Gauss-Legendre to Riemann-Sum quadrature.lower (
float
) - 0.0: Lower limit of integration.upper (
float
) - 1.0: Upper limit of integration.alpha (
float
) - 0.0: Exponent of singular kernel.f (def) - None: Function handle.
extend_precision (
bool
) - True: Flag to use sympy extended precision.n_digits (
int
) - 30: Number of digits in extended precision.
-
class
pyfod.quadrature.
GaussLegendreRiemannSum
(ndom=5, deg=4, nrs=20, percent=0.9, ts=None, lower=0.0, upper=1.0, alpha=0.0, f=None)[source]¶ Bases:
object
Gauss-Legendre, Riemann-Sum quadrature.
- Kwargs: name (type) - default
ndom (
int
) - 5: Number of Gauss-Legendre quadrature intervals.deg (
int
) - 4: Degree of legendre polynomials.nrs (
int
) - 20: Number of Riemann-Sum quadrature intervals.percent (
float
) - 0.9: Percentage of interval in which to use Gauss-Legendre method.ts (
float
) - None: User-defined time to switch from Gauss-Legendre to Riemann-Sum quadrature.lower (
float
) - 0.0: Lower limit of integration.upper (
float
) - 1.0: Upper limit of integration.alpha (
float
) - 0.0: Exponent of singular kernel.f (def) - None: Function handle.
-
class
pyfod.quadrature.
RiemannSum
(n=5, lower=0.0, upper=1.0, alpha=0.0, f=None, singularity=None)[source]¶ Bases:
object
Riemann-Sum quadrature.
- Kwargs: name (type) - default
pyfod.utilities module¶
-
pyfod.utilities.
check_alpha
(alpha)[source]¶ Check value of fractional order.
The package is designed to work on problems where the fractional order has a value in in the range [0, 1).
- Args:
alpha (
float
): Order of fractional derivative.
- Raises:
System exit for ZeroDivisionError.
-
pyfod.utilities.
check_input
(value, varname=None)[source]¶ Check value is defined.
This routine checks that value is defined.
- Args:
value (user defined): Value being tested
- Kwargs: name (type) - default
varname (
str
) - None: Name of variable/value being tested. This provides a more descriptive output for debugging.
If not properly defined
- Raises:
System exist for no value defined.
-
pyfod.utilities.
check_node_type
(n)[source]¶ Check that number of nodes is an integer.
- Args:
n (user defined): Number of nodes.
- Returns:
int(n)
-
pyfod.utilities.
check_range
(lower, upper, value)[source]¶ Check that value falls within [lower, upper] range.
- Args:
If value in range,
- Returns:
value (
float
)
else
- Raises:
System exit for value out of domain.
-
pyfod.utilities.
check_singularity
(singularity, upper)[source]¶ Check singularity was defined.
This routine checks if user provided a singularity location. Default behavior is to use the upper limit of integration as the singularity location.
-
pyfod.utilities.
check_value
(value, default_value, varname=None)[source]¶ Check value with respect to default.
This routine checks that value is defined by either a user-defined value or default value. If still None, then something went wrong and this raises an error message.
- Args:
value (user defined): Value being tested
default_value (method defined): Default value
- Kwargs: name (type) - default
varname (
str
) - None: Name of variable/value being tested. This provides a more descriptive output for debugging.
If properly defined
- Returns:
value
else
- Raises:
System exist for no value defined.