Skip to content

Commit

Permalink
refactor(diff): move finite difference file out
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Sep 19, 2023
1 parent bd0f9ed commit 9d1c2ab
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
6 changes: 0 additions & 6 deletions docs/differentiation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,3 @@ API Reference
.. autofunction:: pycaputo.diff

.. automodule:: pycaputo.differentiation

Integer-order Approximations
----------------------------

.. automodule:: pycaputo.differentiation.finite_difference

6 changes: 6 additions & 0 deletions docs/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Jacobi Polynomials

.. automodule:: pycaputo.jacobi


Finite Difference Approximations
--------------------------------

.. automodule:: pycaputo.finite_difference

Generating Functions
--------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class Truncation(NamedTuple):
"""A representation of the truncation error of a :class:`Stencil`."""
"""A representation of the truncation error of a :class:`DiffStencil`."""

#: Order of the approximation.
order: int
Expand Down Expand Up @@ -66,7 +66,7 @@ def apply_derivative(s: DiffStencil, f: Array, h: float = 1.0) -> Array:
Note that only interior points are correctly computed. Any boundary
points will contain invalid values.
:returns: the stencil applies to the function *f*.
:returns: the stencil applied to the function *f*.
"""
a = s.padded_coeffs.astype(f.dtype)
return np.convolve(f, a, mode="same") / h**s.derivative
Expand All @@ -86,7 +86,9 @@ def determine_stencil_truncation_error(
= c \frac{\mathrm{d}^p\, f}{\mathrm{d}\, x^p}(x_m),
where :math:`c` is the expected truncation error coefficient and :math:`p`
is the order of the approximation.
is the order of the approximation. Note that we just find the first :math:`c`
that is sufficiently close to zero, but the truncation error also depends on
the function :math:`f`, whose higher order derivatives can cancel.
:arg atol: absolute tolerance to check whether the coefficient :math:`c`
is sufficiently close to zero.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_diff.py → tests/test_finite_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np

from pycaputo.differentiation.finite_difference import (
from pycaputo.finite_difference import (
DiffStencil,
apply_derivative,
determine_stencil_truncation_error,
Expand All @@ -17,7 +17,7 @@
from pycaputo.logging import get_logger
from pycaputo.utils import EOCRecorder, savefig, set_recommended_matplotlib

logger = get_logger("pycaputo.test_diff")
logger = get_logger("pycaputo.test_finite_difference")
set_recommended_matplotlib()

# {{{ test_finite_difference_taylor
Expand Down

0 comments on commit 9d1c2ab

Please sign in to comment.