-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Illustrate broadcasting over wavenumber grids (or wavenumber PencilArray) in gradient.jl
?
#42
Comments
@johnryantaylor @simone-silvestri might be interested too |
Right, so
Maybe I'm misunderstanding the question, but this is precisely what "Method 4" illustrates. Perhaps it should appear first, as it's by far the simplest implementation. It's just that this wasn't possible until quite recently... This is also illustrated in the PencilArrays docs (but maybe this is not that easy to find?).
Yeah, that's precisely the way one should think about
The problem is that one cannot construct a 1D Alternatively, one could create a full 3D array of wavenumbers (with e.g. |
Bah! I missed that!
Ah I see the issue. I think what I'm proposing is to partition three 3D PencilArray that have singleton dimensions, but maybe this doesn't make sense. (I guess this requires behavior where singleton dimensions are "extruded" to anticipate their use in broadcasting...)
Ah, indeed! However, that example doesn't use "provided" coordinates but rather generates |
I see, that should be possible, and could be added if there's an interest (but I guess
The coordinates are provided further above :) It's the same as in the gradient example really, only that here we're using the |
Wow, you're right, I missed it again... |
I think part of it is that the name "grid" carries some baggage / meaning; when I see that I immediately assume that we're talking about a physical grid (until I read further and realized it could be a wavenumber grid in Fourier space). But now I understand that it doesn't have to be a "coordinate" at all --- the restriction I guess is that the three component of the triplet have to vary only with But I'm not sure this means that we need a different name... just musing... |
Anyways since broadcasting is actually in the |
In the
gradient.jl
example, a gradient is computed via FFTs by multiplying a transformed field by a wavenumber vector and then transforming back to physical space.The multiplication between the wavenumbers and the transformed field is by looping over indices
PencilFFTs.jl/docs/examples/gradient.jl
Lines 140 to 154 in 4e0cdfe
I'm wondering if it might make sense to illustrate how this computation might be done with broadcasting syntax? Broadcasting might preferred in some applications: it's more compact, and generalizes (in principle...) to GPU.
Partly I'm motivated to propose this modification because I'd like to use this syntax but don't understand quite how to achieve it! I see that
PencilFFTs.jl/examples/gradient.jl
Line 258 in 4e0cdfe
is used in
PencilFFTs.jl/examples/gradient.jl
Lines 133 to 138 in 4e0cdfe
and might illustrate how
localgrid
abstracts the notion of three "coordinates" (basically, three arrays with size(Nx, 1, 1)
,(1, Ny, 1)
, and(1, 1, Nz)
... ?)An alternative might use broadcasting with wavenumbers wrapped in a PencilArray. Not sure which is preferred (is
localgrid
just a wrapper for 3 "special" PencilArray with dimensions as above?)Thanks for the super useful package btw!
The text was updated successfully, but these errors were encountered: