SCOREC / pumi-pic

support libraries for unstructured mesh particle in cell simulations on GPUs and CPUs
BSD 3-Clause "New" or "Revised" License
36 stars 15 forks source link

Question regarding getPIDs function #116

Closed zhangchonglin closed 9 months ago

zhangchonglin commented 9 months ago

If I understand correctly, the two returned values from the getPIDs function listed below should have the following sizes:

Are the above statements correct? If yes, then I found the pids.size() is not equal to particle structure capacity by adding a check below: https://github.com/SCOREC/pumi-pic/blob/c26aef985b95e9cb432f424a6a3bb6089e1ad1d7/particle_structs/test/test_structure.cpp#L359-L360 @Angelyr: could you take a look at this? Thanks!

Angelyr commented 9 months ago

@zhangchonglin You are right about offsets.size(). However, pids.size() should be equal to the number of active particles. The particles in pids will be sorted by element, so you can use offsets(n) to get start index of element n and offsets(n+1) will be the start index of element n+1, with no invalid particles.

zhangchonglin commented 9 months ago

@Angelyr: thanks for the explanation Angel. I will keep this open for now until I have successfully used your function in my code.

zhangchonglin commented 9 months ago

@Angelyr: I have a confusion here:

Cell index 0 1 2 3
number of particles 2 0 1 2
What would be the content of offset look like? I am trying to calculate the number of particles in each cell usingoffset, something below? index of offset 0 1 2 3 4
offset[i] 0 1 2 3 4

Based on the definition, I see there could be an ambiguity on what index to use for cell with 0 particles.

Here for cell index = 1, there is no particle, what would be its starting index and end index? Thanks!

Angelyr commented 9 months ago

@zhangchonglin The offset array is calculated using an exclusive scan of the number of particles.

In this situation the offset array would look like this:

index of offset 0 1 2 3 4
offset[i] 0 2 2 3 5

so when number of particles(n) = 0 then that means that offset(n) == offset(n+1) If you want to get the number of particles using the offset you need: number of particles(n) = offset(n+1) - offset(n)

zhangchonglin commented 9 months ago

@Angelyr: thanks Angel! This makes sense now. So the previous statement offsets(n) will give you the start index of element n, offsets(n+1) will be the end index of element n is not an accurate description of the content of offset array. Could you update the function comment for future reference.

Angelyr commented 9 months ago

I updated the comment. What do think now?

zhangchonglin commented 9 months ago

@Angelyr: thank you Angel! This looks good. The getPIDs function is working well in my code.