Skip to content
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

particle property iterators #4696

Closed
RudolfWeeber opened this issue Mar 25, 2023 · 1 comment · Fixed by #4737
Closed

particle property iterators #4696

RudolfWeeber opened this issue Mar 25, 2023 · 1 comment · Fixed by #4737
Assignees

Comments

@RudolfWeeber
Copy link
Contributor

Create iterators over single particle propreties and common groups of particle properties

auto positions = PositionIterator(cellstrucutre.local_particles());
for (std::vector3d& pos: positions) {
};

This can, to my understanding, be implemented by a boost transform iterator.

For combinations such as
PositionChargeIterator,

a design choice needs to be made:
Either one uses a boost zip iterator, then the individual properties (position, velocities) are numbered. (zip itertaor returns tuples)
Or we create proxy classes which forward the poiters and references as named members

class PositionChargeRefProxy() {
   PositionVelcoityProxy(Vector3d& pos_ref, Vector3d charge_ref) {
   m_pos_ref = pos_ref;
   m_charge_ref = charge_ref;
   };
   Vector3d& m_pos_ref;
   Vector3d& charge_ref;
   Vector3d& pos() { return pos_ref; };
   doube& charge() { return m_charge_ref; };
};
@RudolfWeeber
Copy link
Contributor Author

Here's a sketch generated using ChatGTP. May or may not work, but looks OK

#include <boost/iterator/transform_iterator.hpp>

class Particle {
public:
  const Vector3d& pos() const {
    return position_;
  }

private:
  Vector3d position_;
};

// Define a function object to extract the pos() member from a Particle object
struct ExtractPos {
  const Vector3d& operator()(const Particle& particle) const {
    return particle.pos();
  }
};

int main() {
  std::vector<Particle> particles = /* ... */;

  // Create a transform iterator that extracts the pos() member from each Particle object
  auto pos_iterator = boost::make_transform_iterator(particles.begin(), ExtractPos{});

  // Iterate over the pos() members of the particles
  for (auto pos : pos_iterator) {
    // Do something with pos, which is a reference to a Vector3d object
  }

  return 0;
}

@jngrad jngrad added the Core label May 15, 2023
@kodiakhq kodiakhq bot closed this as completed in #4737 Oct 25, 2023
kodiakhq bot added a commit that referenced this issue Oct 25, 2023
Partial fix for #4721, closes #4696

Description of changes:
- Implements the `ParticlePropertyRange` struct containing static methods to transform a `ParticleRange` to a `boost::iterator_range` of properties of the particles, such as `ForceRange` or `ParticleRange`, which can then be used in range-based for-loops.

The refactoring of the P3M part is not finished yet, but I think this PR could also be extended to remove the ParticleRanges from the remaining Coulomb interactions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants