Comments (4)
Hi,
I'm not sure if you mean stencil or matrix representation. Anyways, let's look at both.
First of all, yes it is
x, y = np.linspace(0, 1, 100), np.linspace(0, 1, 100)
or simply
x = y = np.linspace(0, 1, 100)
For the stencil, consider the simplified version with only a 5x5 grid of grid spacing 1:
laplace_2d = FinDiff(0, 1, 2) + FinDiff(1, 1, 2)
stencil = laplace_2d.stencil((5, 5))
print(stencil) # as of version v0.9.1 (just released) it is just stencil an no longer stencil.data
which yields
{('L', 'L'): {(0, 0): 4.0, (0, 1): -5.0, (0, 2): 4.0, (0, 3): -1.0, (1, 0): -5.0, (2, 0): 4.0, (3, 0): -1.0},
('L', 'C'): {(0, -1): 1.0, (0, 1): 1.0, (1, 0): -5.0, (2, 0): 4.0, (3, 0): -1.0},
('L', 'H'): {(0, -3): -1.0, (0, -2): 4.0, (0, -1): -5.0, (0, 0): 4.0, (1, 0): -5.0,
(2, 0): 4.0, (3, 0): -1.0},
('C', 'L'): {(-1, 0): 1.0, (0, 1): -5.0, (0, 2): 4.0, (0, 3): -1.0, (1, 0): 1.0},
('C', 'C'): {(-1, 0): 1.0, (0, -1): 1.0, (0, 0): -4.0, (0, 1): 1.0, (1, 0): 1.0},
('C', 'H'): {(-1, 0): 1.0, (0, -3): -1.0, (0, -2): 4.0, (0, -1): -5.0, (0, 0): 8.881784197001252e-16,
(1, 0): 1.0},
('H', 'L'): {(-3, 0): -1.0, (-2, 0): 4.0, (-1, 0): -5.0, (0, 0): 4.0, (0, 1): -5.0,
(0, 2): 4.0, (0, 3): -1.0},
('H', 'C'): {(-3, 0): -1.0, (-2, 0): 4.0, (-1, 0): -5.0, (0, -1): 1.0, (0, 0): 8.881784197001252e-16,
(0, 1): 1.0},
('H', 'H'): {(-3, 0): -1.0, (-2, 0): 4.0, (-1, 0): -5.0, (0, -3): -1.0, (0, -2): 4.0,
(0, -1): -5.0, (0, 0): 4.0}}
which looks ok. In the interior of the grid, the (C,C) stencil applies, near the boundary one of the others. L means low index boundary region, H means high index boundary region. The stencil in your case looks strange because it contains 1 / grid_spacing **2 terms, which is just 1 in my example.
If you mean matrix, then this is how you can get it:
laplace_2d = FinDiff(0, dx, 2) + FinDiff(1, dy, 2)
mat = laplace_2d.matrix(u.shape) # returns a scipy sparse matrix
# apply matrix representation to u:
mat.dot(u.reshape(-1)).reshape(u.shape)
Regarding the Helmholtz operator in 1D, the following works:
from findiff import *
dx = 1
H = Identity() - FinDiff(0, dx, 2)
print(H.matrix((10,)).toarray())
which gives
[[-1. 5. -4. 1. 0. 0. 0. 0. 0. 0.]
[-1. 3. -1. 0. 0. 0. 0. 0. 0. 0.]
[ 0. -1. 3. -1. 0. 0. 0. 0. 0. 0.]
[ 0. 0. -1. 3. -1. 0. 0. 0. 0. 0.]
[ 0. 0. 0. -1. 3. -1. 0. 0. 0. 0.]
[ 0. 0. 0. 0. -1. 3. -1. 0. 0. 0.]
[ 0. 0. 0. 0. 0. -1. 3. -1. 0. 0.]
[ 0. 0. 0. 0. 0. 0. -1. 3. -1. 0.]
[ 0. 0. 0. 0. 0. 0. 0. -1. 3. -1.]
[ 0. 0. 0. 0. 0. 0. 1. -4. 5. -1.]]
which looks correct. For actual computation you need a reasonable grid spacing, of course.
The stencil
method for Helmholtz example really gives an error. I will fix it in the next days
as version 0.9.2.
Edit: What part is a feature request?
from findiff.
Ok, I just released v0.9.2 with the necessary fix.
from findiff.
Thank you very much! I just checked that I can create the stencil for the Helmholtz operator with v0.9.2.
Have a nice day.
from findiff.
Thanks for checking. Have a nice day, too!
from findiff.
Related Issues (20)
- multi dimensional coordinates HOT 1
- Derivatives for a single point in a vector space HOT 1
- PDEs HOT 1
- Using findiff to solve the stationary Schrödinger equation HOT 2
- Allow the user to specify difference method HOT 2
- Time-dependency HOT 2
- First Order Schemes HOT 1
- Replace math images by latex expressions HOT 2
- Analytic inversion of Vandermonde matrix HOT 5
- Outdated conda-forge builds HOT 2
- Higher accuracy derivatives in 3D HOT 3
- Accuracy HOT 2
- How are the higher order derivatives computed in your code? HOT 1
- integrals in boundary conditions? HOT 2
- DOC: Equations seem broken on documentation site HOT 1
- Input for non-uniform spacing HOT 2
- Single point derivative
- possible typo in theory section
- Numerical derivative?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from findiff.