# <img src="docs/frontpage/findiff_logo.png" width="100px"> findiff
[](https://img.shields.io/pypi/v/findiff.png?style=flat-square&color=brightgreen)


[](https://findiff.readthedocs.io/en/latest/index.html)
[]()
[](https://pepy.tech/project/findiff)
A Python package for finite difference numerical derivatives and partial differential equations in
any number of dimensions.
## Main Features
* Differentiate arrays of any number of dimensions along any axis with any desired accuracy order
* Accurate treatment of grid boundary
* Can handle arbitrary linear combinations of derivatives with constant and variable coefficients
* Fully vectorized for speed
* Matrix representations of arbitrary linear differential operators
* Solve partial differential equations with Dirichlet or Neumann boundary conditions
* Symbolic representation of finite difference schemes
* **New in version 0.11**: More comfortable API (keeping the old API available)
* **New in version 0.12**: Periodic boundary conditions for differential operators and PDEs.
## Installation
```
pip install --upgrade findiff
```
## Documentation and Examples
You can find the documentation of the code including examples of application at https://findiff.readthedocs.io/en/stable/.
## Taking Derivatives
*findiff* allows to easily define derivative operators that you can apply to *numpy* arrays of
any dimension.
Consider the simple 1D case of a equidistant grid
with a first derivative $\displaystyle \frac{\partial}{\partial x}$ along the only axis (0):
```python
import numpy as np
from findiff import Diff
# define the grid:
x = np.linspace(0, 1, 100)
# the array to differentiate:
f = np.sin(x) # as an example
# Define the derivative:
d_dx = Diff(0, x[1] - x[0])
# Apply it:
df_dx = d_dx(f)
```
Similarly, you can define partial derivatives along other axes, for example, if $z$ is the 2-axis, we can write
$\frac{\partial}{\partial z}$ as:
```python
Diff(2, dz)
```
`Diff` always creates a first derivative. For higher derivatives, you simply exponentiate them, for example for $\frac{\partial^2}{\partial_x^2}$
```
d2_dx2 = Diff(0, dx)**2
```
and apply it as before.
You can also define more general differential operators intuitively, like
$$
2x \frac{\partial^3}{\partial x^2 \partial z} + 3 \sin(y)z^2 \frac{\partial^3}{\partial x \partial y^2}
$$
which can be written as
```python
# define the operator
diff_op = 2 * X * Diff(0)**2 * Diff(2) + 3 * sin(Y) * Z**2 * Diff(0) * Diff(1)**2
# set the grid you use (equidistant here)
diff_op.set_grid({0: dx, 1: dy, 2: dz})
# apply the operator
result = diff_op(f)
```
where `X, Y, Z` are *numpy* arrays with meshed grid points. Here you see that you can also define your grid
lazily.
Of course, standard operators from vector calculus like gradient, divergence and curl are also available
as shortcuts.
If one or more axis of your grid are periodic, you can specify that when defining the derivative or later
when setting the grid. For example:
```python
d_dx = Diff(0, dx, periodic=True)
# or later
d_dx = Diff(0)
d_dx.set_grid({0: {"h": dx, "periodic": True}})
```
More examples can be found [here](https://findiff.readthedocs.io/en/latest/source/examples.html) and in [this blog](https://medium.com/p/7e54132a73a3).
### Accuracy Control
When constructing an instance of `Diff`, you can request the desired accuracy
order by setting the keyword argument `acc`. For example:
```python
d_dx = Diff(0, dy, acc=4)
df_dx = d2_dx2(f)
```
Alternatively, you can also split operator definition and configuration:
```python
d_dx = Diff(0, dx)
d_dx.set_accuracy(2)
df_dx = d2_dx2(f)
```
which comes in handy if you have a complicated expression of differential operators, because then you
can specify it on the whole expression and it will be passed down to all basic operators.
If not specified, second order accuracy will be taken by default.
## Finite Difference Coefficients
Sometimes you may want to have the raw finite difference coefficients.
These can be obtained for __any__ derivative and accuracy order
using `findiff.coefficients(deriv, acc)`. For instance,
```python
import findiff
coefs = findiff.coefficients(deriv=3, acc=4, symbolic=True)
```
gives
```
{'backward': {'coefficients': [15/8, -13, 307/8, -62, 461/8, -29, 49/8],
'offsets': [-6, -5, -4, -3, -2, -1, 0]},
'center': {'coefficients': [1/8, -1, 13/8, 0, -13/8, 1, -1/8],
'offsets': [-3, -2, -1, 0, 1, 2, 3]},
'forward': {'coefficients': [-49/8, 29, -461/8, 62, -307/8, 13, -15/8],
'offsets': [0, 1, 2, 3, 4, 5, 6]}}
```
If you want to specify the detailed offsets instead of the
accuracy order, you can do this by setting the offset keyword
argument:
```python
import findiff
coefs = findiff.coefficients(deriv=2, offsets=[-2, 1, 0, 2, 3, 4, 7], symbolic=True)
```
The resulting accuracy order is computed and part of the output:
```
{'coefficients': [187/1620, -122/27, 9/7, 103/20, -13/5, 31/54, -19/2835],
'offsets': [-2, 1, 0, 2, 3, 4, 7],
'accuracy': 5}
```
## Matrix Representation
For a given differential operator, you can get the matrix representation
using the `matrix(shape)` method, e.g. for a small 1D grid of 10 points:
```python
d2_dx2 = Diff(0, dx)**2
mat = d2_dx2.matrix((10,)) # this method returns a scipy sparse matrix
print(mat.toarray())
```
has the output
```
[[ 2. -5. 4. -1. 0. 0. 0.]
[ 1. -2. 1. 0. 0. 0. 0.]
[ 0. 1. -2. 1. 0. 0. 0.]
[ 0. 0. 1. -2. 1. 0. 0.]
[ 0. 0. 0. 1. -2. 1. 0.]
[ 0. 0. 0. 0. 1. -2. 1.]
[ 0. 0. 0. -1. 4. -5. 2.]]
```
If you have periodic boundary conditions, the matrix looks like that:
```python
d2_dx2 = Diff(0, dx, periodic=True)**2
mat = d2_dx2.matrix((10,)) # this method returns a scipy sparse matrix
print(mat.toarray())
```
```
[[-2. 1. 0. 0. 0. 0. 1.]
[ 1. -2. 1. 0. 0. 0. 0.]
[ 0. 1. -2. 1. 0. 0. 0.]
[ 0. 0. 1. -2. 1. 0. 0.]
[ 0. 0. 0. 1. -2. 1. 0.]
[ 0. 0. 0. 0. 1. -2. 1.]
[ 1. 0. 0. 0. 0. 1. -2.]]
```
## Stencils
*findiff* uses standard stencils (patterns of grid points) to evaluate the derivative.
However, you can design your own stencil. A picture says more than a thousand words, so
look at the following example for a standard second order accurate stencil for the
2D Laplacian $\displaystyle \frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2}$:
<img src="docs/frontpage/laplace2d.png" width="400">
This can be reproduced by *findiff* writing
```python
offsets = [(0, 0), (1, 0), (-1, 0), (0, 1), (0, -1)]
stencil = Stencil(offsets, partials={(2, 0): 1, (0, 2): 1}, spacings=(1, 1))
```
The attribute `stencil.values` contains the coefficients
```
{(0, 0): -4.0, (1, 0): 1.0, (-1, 0): 1.0, (0, 1): 1.0, (0, -1): 1.0}
```
Now for a some more exotic stencil. Consider this one:
<img src="docs/frontpage/laplace2d-x.png" width="400">
With *findiff* you can get it easily:
```python
offsets = [(0, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
stencil = Stencil(offsets, partials={(2, 0): 1, (0, 2): 1}, spacings=(1, 1))
stencil.values
```
which returns
```
{(0, 0): -2.0, (1, 1): 0.5, (-1, -1): 0.5, (1, -1): 0.5, (-1, 1): 0.5}
```
## Symbolic Representations
As of version 0.10, findiff can also provide a symbolic representation of finite difference schemes suitable for using in conjunction with sympy. The main use case is to facilitate deriving your own iteration schemes.
```python
from findiff import SymbolicMesh, SymbolicDiff
mesh = SymbolicMesh("x, y")
u = mesh.create_symbol("u")
d2_dx2, d2_dy2 = [SymbolicDiff(mesh, axis=k, degree=2) for k in range(2)]
(
d2_dx2(u, at=(m, n), offsets=(-1, 0, 1)) +
d2_dy2(u, at=(m, n), offsets=(-1, 0, 1))
)
```
Outputs:
$$
\frac{u_{m,n + 1} + u_{m,n - 1} - 2 u_{m,n}}{\Delta y^2} + \frac{u_{m + 1,n} + u_{m - 1,n} - 2 u_{m,n}}{\Delta x^2}
$$
Also see the [example notebook](examples/symbolic.ipynb).
## Partial Differential Equations
_findiff_ can be used to easily formulate and solve partial differential equation problems
$$
\mathcal{L}u(\vec{x}) = f(\vec{x})
$$
where $\mathcal{L}$ is a general linear differential operator.
In order to obtain a unique solution, Dirichlet, Neumann or more general boundary conditions
can be applied.
### Boundary Value Problems
#### Example 1: 1D forced harmonic oscillator with friction
Find the solution of
$$
\left( \frac{d^2}{dt^2} - \alpha \frac{d}{dt} + \omega^2 \right)u(t) = \sin{(2t)}
$$
subject to the (Dirichlet) boundary conditions
$$
u(0) = 0, \hspace{1em} u(10) = 1
$$
```python
from findiff import Diff, Id, PDE
shape = (300, )
t = numpy.linspace(0, 10, shape[0])
dt = t[1]-t[0]
L = Diff(0, dt)**2 - Diff(0, dt) + 5 * Id()
f = numpy.cos(2*t)
bc = BoundaryConditions(shape)
bc[0] = 0
bc[-1] = 1
pde = PDE(L, f, bc)
u = pde.solve()
```
Result:
<p align="center">
<img src="docs/frontpage/ho_bvp.jpg" alt="ResultHOBVP" height="300"/>
</p>
#### Example 2: 2D heat conduction
A plate with temperature profile given on one edge and zero heat flux across the other
edges, i.e.
$$
\left( \frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2} \right) u(x,y) = f(x,y)
$$
with Dirichlet boundary condition
$$
\begin{align*}
u(x,0) &= 300 \\
u(1,y) &= 300 - 200y
\end{align*}
$$
and Neumann boundary conditions
$$
\begin{align*}
\frac{\partial u}{\partial x} &= 0, & \text{ for } x = 0 \\
\frac{\partial u}{\partial y} &= 0, & \text{ for } y = 0
\end{align*}
$$
```python
shape = (100, 100)
x, y = np.linspace(0, 1, shape[0]), np.linspace(0, 1, shape[1])
dx, dy = x[1]-x[0], y[1]-y[0]
X, Y = np.meshgrid(x, y, indexing='ij')
L = FinDiff(0, dx, 2) + FinDiff(1, dy, 2)
f = np.zeros(shape)
bc = BoundaryConditions(shape)
bc[1,:] = FinDiff(0, dx, 1), 0 # Neumann BC
bc[-1,:] = 300. - 200*Y # Dirichlet BC
bc[:, 0] = 300. # Dirichlet BC
bc[1:-1, -1] = FinDiff(1, dy, 1), 0 # Neumann BC
pde = PDE(L, f, bc)
u = pde.solve()
```
Result:
<p align="center">
<img src="docs/frontpage/heat.png"/>
</p>
## Citations
You have used *findiff* in a publication? Here is how you can cite it:
> M. Baer. *findiff* software package. URL: https://github.com/maroba/findiff. 2018
BibTeX entry:
```
@misc{findiff,
title = {{findiff} Software Package},
author = {M. Baer},
url = {https://github.com/maroba/findiff},
key = {findiff},
note = {\url{https://github.com/maroba/findiff}},
year = {2018}
}
```
## Development
### Set up development environment
- Fork the repository
- Clone your fork to your machine
- Install in development mode:
```
pip install -e .
```
### Running tests
From the console:
```
pip install pytest
pytest tests
```
Raw data
{
"_id": null,
"home_page": null,
"name": "findiff",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "Matthias Baer <matthias.r.baer@googlemail.com>",
"keywords": "finite-differences, numerical-derivatives, scientific-computing",
"author": "Matthias Baer",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/4c/fe/a4f06eca32442d6193aeeea2397a64a65204840f4e96ad0242638cdb1b79/findiff-0.12.0.tar.gz",
"platform": null,
"description": "# <img src=\"docs/frontpage/findiff_logo.png\" width=\"100px\"> findiff\n\n[](https://img.shields.io/pypi/v/findiff.png?style=flat-square&color=brightgreen)\n\n\n[](https://findiff.readthedocs.io/en/latest/index.html)\n[]()\n[](https://pepy.tech/project/findiff)\n\nA Python package for finite difference numerical derivatives and partial differential equations in\nany number of dimensions.\n\n## Main Features\n\n* Differentiate arrays of any number of dimensions along any axis with any desired accuracy order\n* Accurate treatment of grid boundary\n* Can handle arbitrary linear combinations of derivatives with constant and variable coefficients\n* Fully vectorized for speed\n* Matrix representations of arbitrary linear differential operators\n* Solve partial differential equations with Dirichlet or Neumann boundary conditions\n* Symbolic representation of finite difference schemes\n* **New in version 0.11**: More comfortable API (keeping the old API available)\n* **New in version 0.12**: Periodic boundary conditions for differential operators and PDEs.\n\n## Installation\n\n```\npip install --upgrade findiff\n```\n\n## Documentation and Examples\n\nYou can find the documentation of the code including examples of application at https://findiff.readthedocs.io/en/stable/.\n\n## Taking Derivatives\n\n*findiff* allows to easily define derivative operators that you can apply to *numpy* arrays of \nany dimension. \n\nConsider the simple 1D case of a equidistant grid\nwith a first derivative $\\displaystyle \\frac{\\partial}{\\partial x}$ along the only axis (0):\n\n```python\nimport numpy as np\nfrom findiff import Diff\n\n# define the grid:\nx = np.linspace(0, 1, 100)\n\n# the array to differentiate:\nf = np.sin(x) # as an example\n\n# Define the derivative:\nd_dx = Diff(0, x[1] - x[0])\n\n# Apply it:\ndf_dx = d_dx(f) \n```\n\nSimilarly, you can define partial derivatives along other axes, for example, if $z$ is the 2-axis, we can write\n$\\frac{\\partial}{\\partial z}$ as:\n\n```python\nDiff(2, dz)\n```\n\n`Diff` always creates a first derivative. For higher derivatives, you simply exponentiate them, for example for $\\frac{\\partial^2}{\\partial_x^2}$\n\n```\nd2_dx2 = Diff(0, dx)**2\n```\n\nand apply it as before.\n\nYou can also define more general differential operators intuitively, like\n\n$$\n2x \\frac{\\partial^3}{\\partial x^2 \\partial z} + 3 \\sin(y)z^2 \\frac{\\partial^3}{\\partial x \\partial y^2}\n$$\n\n\nwhich can be written as\n\n```python\n# define the operator\ndiff_op = 2 * X * Diff(0)**2 * Diff(2) + 3 * sin(Y) * Z**2 * Diff(0) * Diff(1)**2\n\n# set the grid you use (equidistant here)\ndiff_op.set_grid({0: dx, 1: dy, 2: dz})\n\n# apply the operator\nresult = diff_op(f)\n```\n\nwhere `X, Y, Z` are *numpy* arrays with meshed grid points. Here you see that you can also define your grid\nlazily.\n\nOf course, standard operators from vector calculus like gradient, divergence and curl are also available\nas shortcuts.\n\nIf one or more axis of your grid are periodic, you can specify that when defining the derivative or later\nwhen setting the grid. For example:\n\n```python\nd_dx = Diff(0, dx, periodic=True)\n\n# or later\nd_dx = Diff(0)\nd_dx.set_grid({0: {\"h\": dx, \"periodic\": True}})\n```\n\nMore examples can be found [here](https://findiff.readthedocs.io/en/latest/source/examples.html) and in [this blog](https://medium.com/p/7e54132a73a3).\n\n### Accuracy Control\n\nWhen constructing an instance of `Diff`, you can request the desired accuracy\norder by setting the keyword argument `acc`. For example:\n\n```python\nd_dx = Diff(0, dy, acc=4)\ndf_dx = d2_dx2(f)\n```\n\nAlternatively, you can also split operator definition and configuration:\n\n```python\nd_dx = Diff(0, dx)\nd_dx.set_accuracy(2)\ndf_dx = d2_dx2(f)\n```\n\nwhich comes in handy if you have a complicated expression of differential operators, because then you\ncan specify it on the whole expression and it will be passed down to all basic operators.\n\nIf not specified, second order accuracy will be taken by default.\n\n## Finite Difference Coefficients\n\nSometimes you may want to have the raw finite difference coefficients.\nThese can be obtained for __any__ derivative and accuracy order\nusing `findiff.coefficients(deriv, acc)`. For instance,\n\n```python\nimport findiff\ncoefs = findiff.coefficients(deriv=3, acc=4, symbolic=True)\n```\n\ngives\n\n```\n{'backward': {'coefficients': [15/8, -13, 307/8, -62, 461/8, -29, 49/8],\n 'offsets': [-6, -5, -4, -3, -2, -1, 0]},\n 'center': {'coefficients': [1/8, -1, 13/8, 0, -13/8, 1, -1/8],\n 'offsets': [-3, -2, -1, 0, 1, 2, 3]},\n 'forward': {'coefficients': [-49/8, 29, -461/8, 62, -307/8, 13, -15/8],\n 'offsets': [0, 1, 2, 3, 4, 5, 6]}}\n```\n\nIf you want to specify the detailed offsets instead of the\naccuracy order, you can do this by setting the offset keyword\nargument:\n\n```python\nimport findiff\ncoefs = findiff.coefficients(deriv=2, offsets=[-2, 1, 0, 2, 3, 4, 7], symbolic=True)\n```\n\nThe resulting accuracy order is computed and part of the output:\n\n```\n{'coefficients': [187/1620, -122/27, 9/7, 103/20, -13/5, 31/54, -19/2835], \n 'offsets': [-2, 1, 0, 2, 3, 4, 7], \n 'accuracy': 5}\n```\n\n## Matrix Representation\n\nFor a given differential operator, you can get the matrix representation\nusing the `matrix(shape)` method, e.g. for a small 1D grid of 10 points:\n\n```python\nd2_dx2 = Diff(0, dx)**2\nmat = d2_dx2.matrix((10,)) # this method returns a scipy sparse matrix\nprint(mat.toarray())\n```\n\nhas the output\n\n```\n[[ 2. -5. 4. -1. 0. 0. 0.]\n [ 1. -2. 1. 0. 0. 0. 0.]\n [ 0. 1. -2. 1. 0. 0. 0.]\n [ 0. 0. 1. -2. 1. 0. 0.]\n [ 0. 0. 0. 1. -2. 1. 0.]\n [ 0. 0. 0. 0. 1. -2. 1.]\n [ 0. 0. 0. -1. 4. -5. 2.]]\n```\n\nIf you have periodic boundary conditions, the matrix looks like that:\n\n```python\nd2_dx2 = Diff(0, dx, periodic=True)**2\nmat = d2_dx2.matrix((10,)) # this method returns a scipy sparse matrix\nprint(mat.toarray())\n```\n\n```\n[[-2. 1. 0. 0. 0. 0. 1.]\n [ 1. -2. 1. 0. 0. 0. 0.]\n [ 0. 1. -2. 1. 0. 0. 0.]\n [ 0. 0. 1. -2. 1. 0. 0.]\n [ 0. 0. 0. 1. -2. 1. 0.]\n [ 0. 0. 0. 0. 1. -2. 1.]\n [ 1. 0. 0. 0. 0. 1. -2.]]\n```\n\n## Stencils\n\n*findiff* uses standard stencils (patterns of grid points) to evaluate the derivative.\nHowever, you can design your own stencil. A picture says more than a thousand words, so\nlook at the following example for a standard second order accurate stencil for the\n2D Laplacian $\\displaystyle \\frac{\\partial^2}{\\partial x^2} + \\frac{\\partial^2}{\\partial y^2}$:\n\n<img src=\"docs/frontpage/laplace2d.png\" width=\"400\">\n\nThis can be reproduced by *findiff* writing\n\n```python\noffsets = [(0, 0), (1, 0), (-1, 0), (0, 1), (0, -1)]\nstencil = Stencil(offsets, partials={(2, 0): 1, (0, 2): 1}, spacings=(1, 1))\n```\n\nThe attribute `stencil.values` contains the coefficients\n\n```\n{(0, 0): -4.0, (1, 0): 1.0, (-1, 0): 1.0, (0, 1): 1.0, (0, -1): 1.0}\n```\n\nNow for a some more exotic stencil. Consider this one:\n\n<img src=\"docs/frontpage/laplace2d-x.png\" width=\"400\">\n\nWith *findiff* you can get it easily:\n\n```python\noffsets = [(0, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]\nstencil = Stencil(offsets, partials={(2, 0): 1, (0, 2): 1}, spacings=(1, 1))\nstencil.values\n```\n\nwhich returns\n\n```\n{(0, 0): -2.0, (1, 1): 0.5, (-1, -1): 0.5, (1, -1): 0.5, (-1, 1): 0.5}\n```\n\n## Symbolic Representations\n\nAs of version 0.10, findiff can also provide a symbolic representation of finite difference schemes suitable for using in conjunction with sympy. The main use case is to facilitate deriving your own iteration schemes.\n\n```python\nfrom findiff import SymbolicMesh, SymbolicDiff\n\nmesh = SymbolicMesh(\"x, y\")\nu = mesh.create_symbol(\"u\")\nd2_dx2, d2_dy2 = [SymbolicDiff(mesh, axis=k, degree=2) for k in range(2)]\n\n(\n d2_dx2(u, at=(m, n), offsets=(-1, 0, 1)) + \n d2_dy2(u, at=(m, n), offsets=(-1, 0, 1))\n)\n```\n\nOutputs:\n\n$$\n\\frac{u_{m,n + 1} + u_{m,n - 1} - 2 u_{m,n}}{\\Delta y^2} + \\frac{u_{m + 1,n} + u_{m - 1,n} - 2 u_{m,n}}{\\Delta x^2}\n$$\n\nAlso see the [example notebook](examples/symbolic.ipynb).\n\n## Partial Differential Equations\n\n_findiff_ can be used to easily formulate and solve partial differential equation problems\n\n$$\n\\mathcal{L}u(\\vec{x}) = f(\\vec{x})\n$$\n\nwhere $\\mathcal{L}$ is a general linear differential operator.\n\nIn order to obtain a unique solution, Dirichlet, Neumann or more general boundary conditions\ncan be applied.\n\n### Boundary Value Problems\n\n#### Example 1: 1D forced harmonic oscillator with friction\n\nFind the solution of\n\n$$\n\\left( \\frac{d^2}{dt^2} - \\alpha \\frac{d}{dt} + \\omega^2 \\right)u(t) = \\sin{(2t)}\n$$\n\nsubject to the (Dirichlet) boundary conditions\n\n$$\nu(0) = 0, \\hspace{1em} u(10) = 1\n$$\n\n```python\nfrom findiff import Diff, Id, PDE\n\nshape = (300, )\nt = numpy.linspace(0, 10, shape[0])\ndt = t[1]-t[0]\n\nL = Diff(0, dt)**2 - Diff(0, dt) + 5 * Id()\nf = numpy.cos(2*t)\n\nbc = BoundaryConditions(shape)\nbc[0] = 0\nbc[-1] = 1\n\npde = PDE(L, f, bc)\nu = pde.solve()\n```\n\nResult:\n\n<p align=\"center\">\n<img src=\"docs/frontpage/ho_bvp.jpg\" alt=\"ResultHOBVP\" height=\"300\"/>\n</p>\n\n#### Example 2: 2D heat conduction\n\nA plate with temperature profile given on one edge and zero heat flux across the other\nedges, i.e.\n\n$$\n\\left( \\frac{\\partial^2}{\\partial x^2} + \\frac{\\partial^2}{\\partial y^2} \\right) u(x,y) = f(x,y)\n$$\n\nwith Dirichlet boundary condition\n\n$$\n\\begin{align*}\nu(x,0) &= 300 \\\\\nu(1,y) &= 300 - 200y\n\\end{align*}\n$$\n\nand Neumann boundary conditions\n\n$$\n\\begin{align*}\n\\frac{\\partial u}{\\partial x} &= 0, & \\text{ for } x = 0 \\\\\n\\frac{\\partial u}{\\partial y} &= 0, & \\text{ for } y = 0\n\\end{align*}\n$$\n\n```python\nshape = (100, 100)\nx, y = np.linspace(0, 1, shape[0]), np.linspace(0, 1, shape[1])\ndx, dy = x[1]-x[0], y[1]-y[0]\nX, Y = np.meshgrid(x, y, indexing='ij')\n\nL = FinDiff(0, dx, 2) + FinDiff(1, dy, 2)\nf = np.zeros(shape)\n\nbc = BoundaryConditions(shape)\nbc[1,:] = FinDiff(0, dx, 1), 0 # Neumann BC\nbc[-1,:] = 300. - 200*Y # Dirichlet BC\nbc[:, 0] = 300. # Dirichlet BC\nbc[1:-1, -1] = FinDiff(1, dy, 1), 0 # Neumann BC\n\npde = PDE(L, f, bc)\nu = pde.solve()\n```\n\nResult:\n\n<p align=\"center\">\n<img src=\"docs/frontpage/heat.png\"/>\n</p>\n\n## Citations\n\nYou have used *findiff* in a publication? Here is how you can cite it:\n\n> M. Baer. *findiff* software package. URL: https://github.com/maroba/findiff. 2018\n\nBibTeX entry:\n\n```\n@misc{findiff,\n title = {{findiff} Software Package},\n author = {M. Baer},\n url = {https://github.com/maroba/findiff},\n key = {findiff},\n note = {\\url{https://github.com/maroba/findiff}},\n year = {2018}\n}\n```\n\n## Development\n\n### Set up development environment\n\n- Fork the repository\n- Clone your fork to your machine\n- Install in development mode:\n\n```\npip install -e .\n```\n\n### Running tests\n\nFrom the console:\n\n```\npip install pytest\npytest tests\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python package for finite difference derivatives in any number of dimensions.",
"version": "0.12.0",
"project_urls": {
"Homepage": "https://github.com/maroba/findiff",
"Issues": "https://github.com/maroba/findiff/issues",
"source": "https://github.com/maroba/findiff",
"tracker": "https://github.com/maroba/findiff/issues"
},
"split_keywords": [
"finite-differences",
" numerical-derivatives",
" scientific-computing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9c0882cf59d7e7680fe4f67c19f26c7a3f5413d9c696ee75757ed9b46223268c",
"md5": "00caa590524fbab87f2a281ec2d3c925",
"sha256": "bd30aa7b0e26f190a4f2c69ff1b5dd2b2b8cb9996d642844806d0b243b155526"
},
"downloads": -1,
"filename": "findiff-0.12.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "00caa590524fbab87f2a281ec2d3c925",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 25730,
"upload_time": "2024-12-16T15:08:07",
"upload_time_iso_8601": "2024-12-16T15:08:07.796849Z",
"url": "https://files.pythonhosted.org/packages/9c/08/82cf59d7e7680fe4f67c19f26c7a3f5413d9c696ee75757ed9b46223268c/findiff-0.12.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4cfea4f06eca32442d6193aeeea2397a64a65204840f4e96ad0242638cdb1b79",
"md5": "63357d7fb0c67fc63e211ee81536a8b6",
"sha256": "3f59fd6d7d3b3a90f818299f9c10827a184fdc666818bf5d1facaf702f333cf6"
},
"downloads": -1,
"filename": "findiff-0.12.0.tar.gz",
"has_sig": false,
"md5_digest": "63357d7fb0c67fc63e211ee81536a8b6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 1628831,
"upload_time": "2024-12-16T15:08:10",
"upload_time_iso_8601": "2024-12-16T15:08:10.140862Z",
"url": "https://files.pythonhosted.org/packages/4c/fe/a4f06eca32442d6193aeeea2397a64a65204840f4e96ad0242638cdb1b79/findiff-0.12.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-16 15:08:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "maroba",
"github_project": "findiff",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "findiff"
}