maroba / findiff

Python package for numerical derivatives and partial differential equations in any number of dimensions.
MIT License
438 stars 61 forks source link

integrals in boundary conditions? #75

Closed linjonathan closed 1 year ago

linjonathan commented 1 year ago

Is there a feature to include integrals (not just derivatives)? I'd like to compute the solution for a system where one of the boundary conditions contains an integral over a dimension. Theoretically it is possible, but would require some numerical approximation for the integral.

maroba commented 1 year ago

@linjonathan Can you give a concrete example how this boundary condition looks like? I could imagine very different possibilities and the solution method would look different as well. Suppose you have the differential equation $Lf=0$ for some differential operator $L$ on the domain $V$ with boundary $\partial V$. Do you mean a Dirichlet boundary condition like

$$f(x\in \partial V) = \int g(x') dV$$

for some function $g$? Then you could use scipy.integrate.simpson for 4th order integration of an approach as described in this article for arbitrary order. Or do you mean a more general boundary condition like $$\int_{\partial V} f(x)g(y-x)dA = a(x), \quad x\in \partial V$$ ? Or the same expression as a volume integral (which would imply a self-consistent solution method)?

linjonathan commented 1 year ago

Sorry, I'll be more specific:

$\frac{\partial f(x, y)}{\partial x} + k(x) \int_x \big( \frac{\partial f(x, y)}{\partial y} \big) dx = g(x)$

at some boundary. I was able to solve this by just differentiating with respect to x to get rid of the integral. Thanks!