My Python Library For Finite Difference Method

Click For Summary

Discussion Overview

The discussion revolves around a Python library designed for modeling finite difference problems, focusing on numerical solutions to differential equations. Participants explore its capabilities, limitations, and potential improvements, as well as clarify terminology related to finite difference methods.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Meta-discussion

Main Points Raised

  • One participant shares their experience creating a Python library for basic finite difference problems and invites feedback and contributions.
  • Another participant suggests enabling Discussions in the repository, which is later implemented.
  • Questions arise about the library's ability to solve elementary difference equation problems, with one participant asserting that the library focuses on numerical solutions rather than analytical ones.
  • There is a discussion about the potential confusion between finite difference methods and interpolation, with participants exploring the mathematical connections between them.
  • A participant clarifies that their library approximates derivatives using stencils and highlights the importance of this for numerical modeling.
  • Terminology is debated, with one participant suggesting that the introduction of the library could be more accurately phrased to reflect its focus on boundary value problems rather than finite difference problems.
  • Another participant acknowledges the source of confusion regarding terminology and expresses a desire to correct the initial post.

Areas of Agreement / Disagreement

Participants express differing views on the terminology used to describe the library's purpose, with some agreeing that the introduction could be clearer while others maintain their original interpretations. The discussion remains unresolved regarding the precise definitions and applications of finite difference methods versus interpolation.

Contextual Notes

There are limitations in the discussion regarding the definitions of finite difference problems and the distinction between boundary value problems and initial value problems. The mathematical connections between different methods are not fully explored, leaving some assumptions unaddressed.

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