-
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
Add feature for zero mean velocity incompressible field #260
base: nd-vector-fields
Are you sure you want to change the base?
Add feature for zero mean velocity incompressible field #260
Conversation
…or field (Kraichnan 1970 method)
…plemented only for generator IncomprRandZeroVelMeth
A quick update: I added a feature for periodic boundary conditions in the spatial dimension (first N coordinates where N=vec_dim), but only for the generator dealing with zero-velocity incompressible random fields. However one could trivially copy paste my code for periodic b.c here to use for scalar and generic incompressible random fields. All it does is, for a given dimension, only use Fourier modes which are multiples of I explicitly checked the periodic b.c setup works, can share code for this check later. |
|
||
self._z_1 = self._rng.random.multivariate_normal(mean, cov, size=self._mode_no) # shape (_mode_no, self.vec_dim) | ||
self._z_2 = self._rng.random.multivariate_normal(mean, cov, size=self._mode_no) | ||
print("shape of z_1: ",np.shape(self._z_1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete this line :-)
Hi Joshua, I think you forked off the main branch or already merged/ rebased changes from there to your local main-branch, which are not on the |
Are you sure that the seed does not work? - You are using the |
print("\nimposing periodic boundary conditions on spatial coordinates!") | ||
print("\nrounding first 'vec_dim' vector components in cov_sample to multiples of 2pi/box_length") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are nice debug prints, but for production code, they should be removed or at least you should use the verbose
keyword, as is done in elsewhere in this file.
Using numpy-functions in Cython code is very very slow. I don't think that you ran into numerical problems, you just didn't wait long enough ;-) |
Could you add your checks of the divergence and so on to the |
I'm sorry, I'm running out of time. I will continue with the review tomorrow. I hope that with my few hints and suggestions, you can continue to improve your code! |
Dear Lennart, Sorry for the long delay in my reply. I finally had time to come back to this and aim to make these changes shortly. However, in the process of testing things I encountered an issue relating to the OpenMP functionality. I've thus far used
The issue is nothing actually changed because, I tried instead just
and no longer works correctly. So how can I install my edited version of the package with OpenMP support? |
Hi Joshua, it's great to hear from you again! I think |
The IncomprRandMeth cannot deal with zero mean velocity fluids, since the projector used to ensure incompressibility has a preferential direction along the x-axis, which ensures the generated vector field has curl with zero x-component. For a zero-mean velocity fluid, there is no preferential direction, so we can instead use the general method introduced by Kraichnan (1970).
The main changes here are the addition of
summate_incompr_zero_vel
and the corresponding classIncomprRandZeroVelMeth
. the coefficients of the cosine and sine Fourier-space basis functions are given by the cross-product of a given wave vector of dimensionvec_dim
and a vector drawn from a multivariate normal distribution of dimensionvec_dim
.Please use my script included in Issue #258 to check that field realizations indeed have zero-divergence on average, in the limit of large grid-sizes. I explicitly verified that the curl of the generated field is non-zero in the x-direction (can attach test script if desired).
My changes here are just to show what should be done and probably don't respect the spirit of your code. For example there are clearly a few issues I did not have time to work out: since the super method of
generator.py
only drawsz_1
andz_2
for a univariate Gaussian, I overwrite them insideIncomprRandZeroVelMeth
, which doesn't respect theseed
business you guys have set up to ensure reproducibility.Further, I attempted to use a
np.cross
to perform the cross product in thesummate_incompr_zero_vel
lines 112,113, but this led to the method running indefinitely when called. I am guessing this is due to type instability or something C-related, but since I'm not used to Cython, I'm not sure. In the meantime I commented out those lines and hard-coded the cross-product for the casevec_dim = 3
only.Further, I paid no attention to the possible normalization of the field (if any), i.e some constant prefactor to ensure the inputted mean velocity of
IncomprRandZeroVelMeth
is correct. For my personal application, I just rescale the velocity anyway, but I can do this properly once I have a bit more time.I also added the function
summate_generic_vector_field
and correspondinglyGenericRandVectorFieldMeth
. These are supposed to be for generating vector fields which are not necessarily incompressible. The point is that, one may then take the curl to get a field with zero divergence. These functions are not correct yet, so please ignore them for the moment.Please excuse my surely incomplete pull request, it's my first time contributing to open source code, but I'm happy to learn from mistakes here.