My Python Library For Finite Difference Method

Click For Summary
SUMMARY

The discussion centers on a newly developed Python library for modeling basic finite difference problems, specifically for numerically solving systems of partial differential equations with given boundary conditions. The library allows users to specify initial and boundary conditions, producing numerical solutions that evolve over time. Key features include the creation of "Stencil" objects for derivative approximations, which are essential for modeling partial differential equations. The conversation also highlights a terminology confusion regarding finite difference methods versus finite difference problems.

PREREQUISITES
  • Understanding of finite difference methods for numerical modeling
  • Familiarity with partial differential equations (PDEs)
  • Basic knowledge of Python programming
  • Experience with numerical analysis concepts
NEXT STEPS
  • Explore the GitHub repository for the Python library and its documentation
  • Learn about creating and using Stencil objects for derivative approximations
  • Research boundary value problems (BVPs) and their numerical solutions
  • Investigate the differences between finite difference, finite volume, and finite element methods
USEFUL FOR

Researchers, engineers, and developers interested in numerical modeling, particularly those working with partial differential equations and finite difference methods.

person123
Messages
326
Reaction score
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   Reactions: Wrichik Basu
Technology news on Phys.org
Off-topic: You could consider enabling Discussions in your repo.
 
  • Like
Likes   Reactions: person123
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   Reactions: Wrichik Basu
@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).
 
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.
 
@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.
 
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   Reactions: person123 and Wrichik Basu
@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   Reactions: berkeman

Similar threads

  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 6 ·
Replies
6
Views
7K
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K