Skip to content

Commit

Permalink
reverse wrongly delete functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangyu-Hu committed Oct 12, 2024
1 parent 23b312f commit a2f6b80
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/shared/particle_dynamics/particle_iterators.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,49 @@ inline ReturnType particle_reduce(const ParallelPolicy &par, const IndexVector &
return operation(x, y);
});
};

/**
* BodypartByCell-wise reduce iterators (for sequential and parallel computing).
*/
template <class ReturnType, typename Operation, class LocalDynamicsFunction>
inline ReturnType particle_reduce(const SequencedPolicy &seq, const ConcurrentCellLists &body_part_cells,
ReturnType temp, Operation &&operation,
const LocalDynamicsFunction &local_dynamics_function)
{
for (size_t i = 0; i != body_part_cells.size(); ++i)
{
ConcurrentIndexVector &particle_indexes = *body_part_cells[i];
for (size_t num = 0; num < particle_indexes.size(); ++num)
{
temp = operation(temp, local_dynamics_function(particle_indexes[num]));
}
}

return temp;
}

template <class ReturnType, typename Operation, class LocalDynamicsFunction>
inline ReturnType particle_reduce(const ParallelPolicy &par, const ConcurrentCellLists &body_part_cells,
ReturnType temp, Operation &&operation,
const LocalDynamicsFunction &local_dynamics_function)
{
return parallel_reduce(
IndexRange(0, body_part_cells.size()),
temp,
[&](const IndexRange &r, ReturnType temp0) -> ReturnType
{
for (size_t i = r.begin(); i != r.end(); ++i)
{
ConcurrentIndexVector &particle_indexes = *body_part_cells[i];
for (size_t num = 0; num < particle_indexes.size(); ++num)
{
temp0 = operation(temp0, local_dynamics_function(particle_indexes[num]));
}
}
return temp0;
},
[&](const ReturnType &x, const ReturnType &y) -> ReturnType
{ return operation(x, y); });
}
} // namespace SPH
#endif // PARTICLE_ITERATORS_H

0 comments on commit a2f6b80

Please sign in to comment.