-
Notifications
You must be signed in to change notification settings - Fork 293
AMR: Expand particle deposition onto the grid to vector fields. #5227
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
base: main
Are you sure you want to change the base?
AMR: Expand particle deposition onto the grid to vector fields. #5227
Conversation
Just to add, I am currently only considering |
@cphyc some octree enhancements/changes here that you might be interested in checking out when you're back from holiday :) |
@AnatoleStorck would be happy to look more at this after the test failures are addressed. |
I'd love to see this functionality in yt. Let me know if there are ways I can assist in testing this or debugging. |
@@ -130,7 +131,7 @@ def select_tcoords(self, dobj): | |||
def domain_ind(self): | |||
return self.oct_handler.domain_ind(self.selector) | |||
|
|||
def deposit(self, positions, fields=None, method=None, kernel_name="cubic"): | |||
def deposit(self, positions, fields=None, method=None, kernel_name="cubic", vector_field=False): |
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.
You're missing the corresponding item in the docstring to explain what vector_field
means.
if cls is None: | ||
raise YTParticleDepositionNotImplemented(method) | ||
nz = self.nz | ||
nvals = (nz, nz, nz, (self.domain_ind >= 0).sum()) | ||
if np.max(self.domain_ind) >= nvals[-1]: | ||
if vector_field: | ||
vec_size = fields[0].shape[-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.
This won't work if fields = []
(the default is it is left empty, which can happen).
|
||
source = source.reshape(np.shape(source) + (dims,)) | ||
# If source is a vector field, we need to handle it differently. | ||
is_vector_field = len(np.shape(source)) > 5 |
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.
Maybe use source.ndim == 5
instead?
source = source.reshape((source.shape[0], source.shape[1], | ||
source.shape[2], source.shape[3], dims)) | ||
if is_vector_field: | ||
dest = np.zeros((len(dest), np.shape(source)[-2], dims), |
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 am not sure this is correct - if dest is not None, we should modify it in place instead of creating a new array. It is possible that the upstream code relies on dest
being modified (if passed).
In addition, np.shape(source)[-2]
is cryptic and requires knowing about https://github.com/yt-project/yt/pull/5227/files#diff-3cef3e330a489f3d2975d39b0f17b55a03f3134b27492604af30bc23f1bf7fa7R179. What about something like:
*_, ncells, ndim = source.shape
# assert ndim == dims?
dest = np.zeros((len(dest), ncells, dims), dtype=source.dtype, order='C')
#print("IN COPY2DARRAYF64") | ||
#print(self.dest.shape, self.source.shape) |
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.
#print("IN COPY2DARRAYF64") | |
#print(self.dest.shape, self.source.shape) |
# even though in other instances it varies the fastest. To see this in | ||
# action, try looking at the results of an n_ref=256 particle CIC plot, | ||
# which shows it the most clearly. | ||
return ((i*dims[1])+j)*dims[2]+k |
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.
Shouldn't this be (i*dims[0] + j) * dims[1] + k
?
arr2.shape = arr2.shape + (1,) * (naxes - arr2.ndim) | ||
return arr2 | ||
|
||
cdef class ParticleDepositOperation: |
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.
Could it superclass the one defined in particle_deposit.pyx
to minimize code duplication?
PR Summary
Currently, only scalar quantites of particles can be deposited to the grid (such as mass), with final shape (Ncells,) I want to be able to deposit a vector quantity (stellar spectra of each star particle) onto the grid with shape (Ncells, spectra_length), with the main goal to build spectra for each cell (nebular continuum + emission lines, and stellar spectra.) I have not been able to make the deposition of the vector fields work yet, so any help is greatly appreciated.
PR Checklist