My Python Library For Finite Difference Method

In summary, the library is designed to help with the solution of finite difference problems, and is designed for use with boundary value problems.
  • #1
person123
328
52
I recently made a Python library for modelling (very basic) finite difference problems. The Github readme goes into details of what it does and how it works, and I put together a Google Colab with some examples (diffusion, advection, water wave refraction) with interactive visuals.

I'd love to hear what people think: general feedback, if they're running into issues, things they would want to see included. It's still in an early phase, and I would like to add to it. If anyone wants to contribute, let me know!
 
  • Like
Likes Wrichik Basu
Technology news on Phys.org
  • #2
Off-topic: You could consider enabling Discussions in your repo.
 
  • Like
Likes person123
  • #3
Wrichik Basu said:
Off-topic: You could consider enabling Discussions in your repo.
I enabled discussions :)
Feel free to post any thoughts, critiques you have with the project idea or issues you have using it, directions you would like to see it go, interest in collaboration etc.
 
  • Like
Likes Wrichik Basu
  • #4
@person123, would your program be able to solve very elementary difference equation problems like this?
Find an equation of the function that contains the points (1, 1), (2, 8), (3, 27), (4, 64).
 
  • #5
Mark44 said:
@person123, would your program be able to solve very elementary difference equation problems like this?
Find an equation of the function that contains the points (1, 1), (2, 8), (3, 27), (4, 64).
The one-word answer: no.

So far, I've just focused on specifying analytical equations as input, but getting numerical solutions as output. The user specifies initial conditions and boundary conditions for fields, and they see how the field evolves with time under differential equations. But the computation is performed numerically, and the solution is values at each point in the domain. Basically, it's been a tool for numerical models, not for analytical solutions. (I go into more details on what it can do in the github readme).

Is it possible we're thinking of two different things? Maybe you're thinking of interpolation using finite differences, like Lagrange interpolation, while I'm thinking of the finite difference method for numerical modeling (in contrast with finite volume and finite element). But I'm also not very familiar with the former, so maybe there's a connection I'm not seeing.
 
  • #7
@Mark44 Looking at that page, it does seem like there's a connection. While my library can't do interpolation, it can approximate derivatives, seen in the "Relation With Derivatives" and "Higher-order differences" sections (this is actually critical for my library doing anything useful at all). Namely, given some arbitrary coordinates, and the derivative order, inputted as the following:

Python:
d2 = fd.Stencil([-1,0,1], der_order = 2)

It creates a "Stencil" object, a numerical approximation for the second derivative, and prints the equation (sadly not displayed in latex):

Finite approximation: f'' = [f(x-h) - 2f(x+0h) + f(x+h)] / [h^2]

This derivative approximation is then used for modeling the partial differential equation.

I think mathematically, this is similar to interpolating points with polynomials, since they both rely on Taylor series. But for numerical modeling, I think what you care about is constructing a numerical approximation from an analytical derivative, instead of constructing an analytical equation from numeric values. Maybe there would be an application for interpolation as well though, I'm not sure.
 
  • #8
Mark44 said:
Could be, although it's been many years since I did anything with finite differences.
I think the confusion arises because of the difference between the terminology in the title, which is correct:
person123 said:
My Python Library For Finite Difference Method
and in the introduction in the first post, which is not
person123 said:
I recently made a Python library for modelling (very basic) finite difference problems.

Finite difference methods are a class of methods for numerically solving systems of (usually partial) differential equations with given boundary conditions: these are often referred to as boundary value problems (BVPs) to distinguish them from initial value problems (IVPs) for which other methods are used. Finite difference problems aren't really a thing, but if they were then they would be what @Mark44 had in mind.

So the introduction would be better phrased as "I recently made a Python library for modelling (very basic) systems of differential equations using finite difference methods" or "I recently made a Python library for numerical solution of (very basic) boundary value problems using finite difference methods".
 
Last edited:
  • Like
Likes person123 and Wrichik Basu
  • #9
@pbuk Thank you, yes, it sounds like that was the source of the confusion. It looks like I made the post too long ago to edit, but that change would be more accurate.
 
  • Like
Likes berkeman

Similar threads

Replies
1
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
Replies
16
Views
2K
  • Differential Equations
Replies
1
Views
2K
Replies
1
Views
116
Replies
1
Views
6K
Replies
1
Views
3K
Back
Top