Skip to content

Basic 1D finite difference code generator #51

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

Merged
merged 14 commits into from
May 21, 2025

Conversation

jrmaddison
Copy link
Owner

@jrmaddison jrmaddison commented May 19, 2025

Arbitrary order centered finite differencing. Currently unrolls the expression. Differencing transitions, becoming increasingly one-sided as boundaries are approached. Now used by Grid in Grid.D_x, Grid.D_y, Grid.D_xx, and Grid.D_yy.

@jrmaddison jrmaddison force-pushed the jrmaddison/finite_difference_codegen branch from a6387ba to 09aad03 Compare May 20, 2025 09:23
@jrmaddison jrmaddison force-pushed the jrmaddison/finite_difference_codegen branch from 3c7fb7f to 7ac5015 Compare May 20, 2025 10:03
@jrmaddison jrmaddison force-pushed the jrmaddison/finite_difference_codegen branch from 9d70387 to 402305d Compare May 20, 2025 14:58
@jrmaddison jrmaddison force-pushed the jrmaddison/finite_difference_codegen branch from 97c2a6e to 1e7f99d Compare May 21, 2025 08:04
@jrmaddison
Copy link
Owner Author

jrmaddison commented May 21, 2025

Note that this uses a very basic linear solve based method to find the coefficients. Results are correct so long as everything is computed symbolically (diff_bounded uses exact rationals when finding the coefficients) but the method in doi:10.1090/S0025-5718-1988-0935077-0 would be much better if inexact arithmetic is needed. SymPy provides an implementation of the latter algorithm in sympy.calculus.finite_diff.finit_diff_weights, but it's unclear from the SymPy documentation whether a specific displacement ordering is needed, so that isn't used in this PR.

@jrmaddison jrmaddison merged commit 066061f into main May 21, 2025
2 checks passed
@jrmaddison jrmaddison deleted the jrmaddison/finite_difference_codegen branch May 21, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant