Skip to content
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

Accuracy not affecting stencil generation #31

Closed
orebas opened this issue Dec 21, 2020 · 5 comments
Closed

Accuracy not affecting stencil generation #31

orebas opened this issue Dec 21, 2020 · 5 comments

Comments

@orebas
Copy link

orebas commented Dec 21, 2020

It seems like when I generate a Stencil, the accuracy is being ignored.
Repro:
x = np.linspace(0, 10, 11)
y = np.linspace(0, 10, 11)
X, Y = np.meshgrid(x, y, indexing='ij')
u = X+Y
d1x = FinDiff(0, x[1] - x[0],1,acc=10)
stencil1 = d1x.stencil(u.shape)
print(stencil1)

Output (this is the same no matter when I change accuracy too):
('L', 'L'): {(0, 0): -1.5, (1, 0): 2.0, (2, 0): -0.5}
('L', 'C'): {(0, 0): -1.5, (1, 0): 2.0, (2, 0): -0.5}
('L', 'H'): {(0, 0): -1.5, (1, 0): 2.0, (2, 0): -0.5}
('C', 'L'): {(-1, 0): -0.5, (0, 0): 0.0, (1, 0): 0.5}
('C', 'C'): {(-1, 0): -0.5, (0, 0): 0.0, (1, 0): 0.5}
('C', 'H'): {(-1, 0): -0.5, (0, 0): 0.0, (1, 0): 0.5}
('H', 'L'): {(-2, 0): 0.5, (-1, 0): -2.0, (0, 0): 1.5}
('H', 'C'): {(-2, 0): 0.5, (-1, 0): -2.0, (0, 0): 1.5}
('H', 'H'): {(-2, 0): 0.5, (-1, 0): -2.0, (0, 0): 1.5}

@orebas
Copy link
Author

orebas commented Dec 21, 2020

As a comment, I wanted to let you know that I am finding this package otherwise quite useful, indeed I have not found anything as user-friendly. Thank you.

@maroba
Copy link
Owner

maroba commented Dec 21, 2020

Thanks for compliment!

Regarding your issue, the acc property doesn't seem to be passed down correctly to the stencil generator. However, until I fix this, you can alternatively attach the acc argument to the stencil call (instead of the FinDiff constructor) and write:

d1x = FinDiff(0, x[1] - x[0], 1)
stencil1 = d1x.stencil(u.shape, acc=4)
print(stencil1)

Output:

('L', 'L'):	{(0, 0): -2.083333333333331, (1, 0): 3.9999999999999916, (2, 0): -2.999999999999989, (3, 0): 1.3333333333333268, (4, 0): -0.24999999999999858}
('L', 'C'):	{(0, 0): -2.083333333333331, (1, 0): 3.9999999999999916, (2, 0): -2.999999999999989, (3, 0): 1.3333333333333268, (4, 0): -0.24999999999999858}
('L', 'H'):	{(0, 0): -2.083333333333331, (1, 0): 3.9999999999999916, (2, 0): -2.999999999999989, (3, 0): 1.3333333333333268, (4, 0): -0.24999999999999858}
('C', 'L'):	{(-2, 0): 0.08333333333333333, (-1, 0): -0.6666666666666666, (0, 0): 0.0, (1, 0): 0.6666666666666666, (2, 0): -0.08333333333333333}
('C', 'C'):	{(-2, 0): 0.08333333333333333, (-1, 0): -0.6666666666666666, (0, 0): 0.0, (1, 0): 0.6666666666666666, (2, 0): -0.08333333333333333}
('C', 'H'):	{(-2, 0): 0.08333333333333333, (-1, 0): -0.6666666666666666, (0, 0): 0.0, (1, 0): 0.6666666666666666, (2, 0): -0.08333333333333333}
('H', 'L'):	{(-4, 0): 0.24999999999999958, (-3, 0): -1.3333333333333313, (-2, 0): 2.9999999999999956, (-1, 0): -3.999999999999996, (0, 0): 2.0833333333333317}
('H', 'C'):	{(-4, 0): 0.24999999999999958, (-3, 0): -1.3333333333333313, (-2, 0): 2.9999999999999956, (-1, 0): -3.999999999999996, (0, 0): 2.0833333333333317}
('H', 'H'):	{(-4, 0): 0.24999999999999958, (-3, 0): -1.3333333333333313, (-2, 0): 2.9999999999999956, (-1, 0): -3.999999999999996, (0, 0): 2.0833333333333317}

@orebas
Copy link
Author

orebas commented Dec 21, 2020 via email

maroba pushed a commit that referenced this issue Dec 21, 2020
@maroba
Copy link
Owner

maroba commented Dec 22, 2020

Yes, you are right. Stencils for mixed partial derivatives were not yet supported.

In the meantime I have fixed the issue that you reported and also implemented the stencils for mixed partial derivatives. Both is uploaded on github and pypi as version v0.8.6.

By the way, do you explicitly need the stencils or do you just want to apply the derivatives?

@orebas
Copy link
Author

orebas commented Dec 22, 2020 via email

@maroba maroba closed this as completed Dec 29, 2020
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

No branches or pull requests

2 participants