-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
converted gradient function to standard forward difference #68
Conversation
Thanks again for the contribution, @tomflint22. This is much more clear. The Numerical Recipes chapter on Partial Differential Equations covers this in some detail. The bottom line is, neither the current implementation (FTCS) nor your proposed finite difference are numerically stable. Instead, the "correct" implementation would use the Lax method, which replaces the center point of the previous timestep with its average. The following consider the conservative flux equation
FTCSThe current
NR shows, through a von Neumann or linear stability analysis, that this discretization is unstable for all Forward-time One-sided-spaceYour proposed gradient function implements a one-sided difference. This is sometimes appropriate, especially near boundaries, but offers no benefit over FTCS in terms of accuracy or stability.
Lax methodNR reports
Then,
This discretization is conditionally stable, so long as ResolutionIf you update this PR to implement the Lax method, then I will be happy to merge it. Otherwise, let me know, and I will implement it myself. I should also note that the centered-space discretization is appropriate (with second-order spatial truncation error) for computing time-independent quantities, such as the current free energy of a system. In solving things like the heat equation, |
I see, thankyou for clarifying. The current gradient implementation was falling over for me in the heterogeneous heat conduction example. At the interface of a region of higher thermal diffusivity. I used the product rule to break the div(alpha*grad(T)) term up into d(alpha)/dx dT/dx (in one dimension), so taking the gradient of essentially a step function was generating artifacts over two grid points. When I get some time next week though I'll have a go at implementing the LAX method you have suggested. Once again thankyou for all your hard work with mmsp. I'd love to contribute. All the best, Tom |
Sorry I wrote that equation out wrong for heterogeneous conduction: d(alpha)/dxdT/dx + alpha(d2T/dx2) |
OK. The typical approach for implementing
where
For variable α,
Hopefully, implementing this discretization will stabilize your code. |
Ace, thankyou. That's really useful. I'll keep trying to contribute, I love using your code it's great. All the best, Tom |
The proposed changes are intended to {improve the numerics of the gradient function. Currently the gradient is kind of a sum of forward and backwards fifferences: a(x+1)-a(x-1)/2dx. I think this doubles the error}.
This is achieved by {I have converted the gradients to a standard forward difference}.
Fixes #, Addresses #
The modified code may have unintended consequences in {I dont forsee any unintended consequences. The old method may have performed some unintended averaging where used so we should look out for this}.
This change is