Closed zhangchonglin closed 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.
@Angelyr: thanks for the explanation Angel. I will keep this open for now until I have successfully used your function in my code.
@Angelyr: I have a confusion here:
0, 1, 2, 3
;2, 0, 1, 2
particles, respectively;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!
@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)
@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.
I updated the comment. What do think now?
@Angelyr: thank you Angel! This looks good. The getPIDs
function is working well in my code.
If I understand correctly, the two returned values from the
getPIDs
function listed below should have the following sizes:pids
: size is equal toparticle structure capacity
, i.e. the number of particles in the particle structure.offsets
: size is equal to thenumber of mesh elements + 1
. https://github.com/SCOREC/pumi-pic/blob/7b55b1b09ec6a30695d45889fd12acf109cdb6be/particle_structs/src/ps_for.hpp#L57-L85Are the above statements correct? If yes, then I found the
pids.size()
is not equal toparticle 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!