-
Notifications
You must be signed in to change notification settings - Fork 74
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
[WIP] Add support for nd vectors on md field #251
base: main
Are you sure you want to change the base?
Conversation
This is a first suggestion of how to implement spatio-temporal vector fields. It is hardly tested and more a foundation for a discussion.
b53635d
to
05b4239
Compare
Hi Lennart, thanks much for your code changes. I will pull this branch and do the obvious tests that (i) the field realizations remain incompressible for the spatial components, (ii) the spatial correlation length is always the one specified at each time-step (iii) the correlation time-scale is the one specified. What corner cases do you have in mind besides unstructured grids (which, for my personal application, I don't need to bother with)? |
Dear Lennart, I cloned the branch a tested it quickly. Some quick tests by eye show that the correlation length in time and in space match the specified ones, and the 3D spatial field realizations are incompressible. This is really great! However, there seems to be one issue:
by
gives the error
This error comes from line 54 of I think it is expecting a mean vector of size 3 here (even though that is not what we want as the spatial vectors are 2D here). Trying instead
gives the error
which comes from line 100 of I think a fix for this is all that is needed to get this working! |
Hi Joshua, that is great to hear, thanks for testing the code! I hope I'll find some time this weekend to fix the problem you found. |
Dear Lennart, After further testing, I believe the incompressibility does not work here :( Attached is a minimal example showing that the divergence of the field is zero (rather, approaches zero for large grid sizes) for 2d and 3d vector fields, but not for a (3 space + 1 time) field with 3d vectors. I wrote two functions to calculate the divergence of a 2d and 3d field, respectively, and one function test_incompressible which tests each of the 3 cases I listed above, calculating and plotting the divergence of the field on a suitable spatial slice. The grid size can easily be increased here, which shows that the divergence approaches zero for the 2d and 3d case, but not for the (3+1)d case. Note that the divergence is always inaccurate at the edges for all cases, but that is expected. Please let me know if my test is faulty, or if there is actually an issue.
|
That's a pity! But thank you so much for your script. Regarding the I'll need some time to see, if I can find a solution. |
Ah, by the way, in case you haven't done this already, you can significantly decrease computational time by using this line before compiling/ installing GSTools: |
I just calculated the divergence of the equation given in the notes field here and the divergence is actually only zero, if the dimension of the cov. model coincides with the dimension of the vectors :-( I guess I should have done that calculation before hacking away ;-) |
The normalisation in the projector has to use the first `vec_dim` elements of the cov_samples, just check div. of equations.
Maybe I just need more sleep or more coffee... |
Dear Lennart, Thank you for your excellent and rapid communication on this issue. Let me pull this again and check that everything works; your fix seems quite logical! As far as the mean velocity, this is not too problematic; previously i have been commenting out line 448 in generator.py:
Since the default is |
Dear Lennart, I confirm that your fix worked: when generating 3D vector fields in (3 space + 1 time) dimension, the field realizations are now (spatially) incompressible (awesome!), although with zero curl in the x-direction. For my application, I desire a fluid of zero mean velocity. The zero velocity is easy to get by commenting out the default mean velocity in the x-direction that your code automatically imposes, but the incompressibility projector also needs to be modified. I plan to make two minor code contributions to treat the zero-velocity case: (i) simply remove the projector for the incompressible vector field generator to get realizations which are not incompressible, but which can be transformed to an incompressible field by then taking the curl (ii) i will try to implement the method suggested by (Kraichnan, 1970) Eq.19, 20 who appears to have treated the zero-velocity case with a more general projector then what you are using. It appears to require more computation though, because each wave coefficient must be drawn for a 2 or 3 dimensional multivariate Gaussian. I suppose your projector is a sort of special case? If you know of any code implementations (available on github) of the zero-velocity case, I am happy to use those as a start point for contributing to your code. |
Dear Lennart, I filed a new pull request (#260) for this issue. |
Dear Joshua, I'm sorry for taking so long to come back the 4d fields. The last 10 days or so I just had too much things to do. Tomorrow I will have time to take a look at the PR (I live in central European time), I'm very much looking forward to it! |
This is a first suggestion of how to implement spatio-temporal vector fields. It is hardly tested and more a foundation for a discussion.
The normalisation in the projector has to use the first `vec_dim` elements of the cov_samples, just check div. of equations.
…nto nd-vector-fields
This is a first suggestion of how to implement spatio-temporal vector fields. It is hardly tested and more a foundation for a discussion.
We want to implement 2d vectors (let's call this
vec_dim=2
) in 2 spatial and 1 temporal dimensions (let's call thisfield_dim=3
)and 3d vectors (vec_dim=3
) in 3 spatial and 1 temporal dimension (field_dim=4
). This means, that the incompressibility of the vector field only has to be ensured in the spatial plane, which isfield_dim - 1
and always equal tovec_dim
. This means that I didn't have to change much in thesummate_incompr
function insummator.pyx
. Thephase
is now computed for all field dimensions, but thesummed_modes
are computed only for thevec_dim
.As I don't have a lot of time at the moment, I haven't thought this completely through and I'm not sure, if this makes 100% sense.
I'm sure there are also many (corner?) cases which we have to check, e.g. I haven't checked unstructured grids at all.
This is the only script I have used to test this PR:
I'm very much looking forward to your thoughts and criticism! @joshua-benabou please join in on this PR and discussion, which arose from discussion #245 .