Skip to content

Commit

Permalink
refactor(diff): rename Stencil to DiffStencil
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Sep 19, 2023
1 parent 1fbe547 commit bd0f9ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions pycaputo/differentiation/finite_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Truncation(NamedTuple):


@dataclass(frozen=True)
class Stencil:
class DiffStencil:
r"""Approximation of a derivative by finite difference on a uniform grid.
.. math::
Expand Down Expand Up @@ -60,7 +60,7 @@ def trunc(self) -> Truncation:
return determine_stencil_truncation_error(self)


def apply_derivative(s: Stencil, f: Array, h: float = 1.0) -> Array:
def apply_derivative(s: DiffStencil, f: Array, h: float = 1.0) -> Array:
"""Apply the stencil to a function *f* and a step size *h*.
Note that only interior points are correctly computed. Any boundary
Expand All @@ -73,7 +73,7 @@ def apply_derivative(s: Stencil, f: Array, h: float = 1.0) -> Array:


def determine_stencil_truncation_error(
s: Stencil,
s: DiffStencil,
*,
atol: float | None = None,
) -> Truncation:
Expand Down Expand Up @@ -104,7 +104,7 @@ def determine_stencil_truncation_error(
return Truncation(i - s.derivative, c)


def modified_wavenumber(s: Stencil, k: Array) -> Array:
def modified_wavenumber(s: DiffStencil, k: Array) -> Array:
"""Compute the modified wavenumber of the stencil *s* at each number *k*.
:arg k: wavenumber at which to compute the derivative.
Expand All @@ -123,7 +123,7 @@ def make_taylor_approximation(
bounds: tuple[int, int],
*,
dtype: np.dtype[Any] | None = None,
) -> Stencil:
) -> DiffStencil:
r"""Determine a finite difference stencil by solving a linear system from the
Taylor expansion.
Expand All @@ -143,8 +143,8 @@ def make_taylor_approximation(
if bounds[0] > bounds[1]:
bounds = (bounds[1], bounds[0])

if bounds[0] >= 0 or bounds[1] <= 0:
raise ValueError(f"Bounds must be (smaller, bigger): {bounds}")
if bounds[0] > 0 or bounds[1] < 0:
raise ValueError(f"Bounds must be (smaller <= 0, bigger >= 0): {bounds}")

if dtype is None:
dtype = np.dtype(np.float64)
Expand All @@ -162,7 +162,7 @@ def make_taylor_approximation(
x = np.linalg.solve(A, b)
assert np.allclose(np.sum(x), 0.0)

return Stencil(
return DiffStencil(
derivative=derivative,
coeffs=x,
offsets=offsets,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np

from pycaputo.differentiation.finite_difference import (
Stencil,
DiffStencil,
apply_derivative,
determine_stencil_truncation_error,
make_taylor_approximation,
Expand All @@ -23,7 +23,7 @@
# {{{ test_finite_difference_taylor


def finite_difference_convergence(d: Stencil) -> EOCRecorder:
def finite_difference_convergence(d: DiffStencil) -> EOCRecorder:
eoc = EOCRecorder()

s = np.s_[abs(d.offsets[0]) + 1 : -abs(d.offsets[-1]) - 1]
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_finite_difference_taylor_stencil(*, visualize: bool = False) -> None:
[-0.02651995, 0.18941314, -0.79926643, 0.0, 0.79926643, -0.18941314, 0.02651995]
)
offsets = np.arange(-3, 4)
s = Stencil(derivative=1, coeffs=a, offsets=offsets)
s = DiffStencil(derivative=1, coeffs=a, offsets=offsets)

order, c = determine_stencil_truncation_error(s, atol=1.0e-6)
assert order == 4
Expand Down

0 comments on commit bd0f9ed

Please sign in to comment.