18#include "molecules/AutoPasSimpleMolecule.h"
19#include <autopas/iterators/ParticleIteratorWrapper.h>
24class ParticleIterator :
public autopas::IteratorTraits<AutoPasSimpleMolecule>::iterator_t {
29 ONLY_INNER_AND_BOUNDARY=1,
34 ParticleIterator(
const autopas::IteratorTraits<AutoPasSimpleMolecule>::iterator_t& parent)
37 size_t getCellIndex() {
45#include "utils/mardyn_assert.h"
46#include "SingleCellIterator.h"
47#include "ParticleCell.h"
48#include "WrapOpenMP.h"
54 ONLY_INNER_AND_BOUNDARY=1,
57 typedef std::vector<ParticleCell> CellContainer_T;
58 typedef CellContainer_T* CellContainer_T_ptr;
59 typedef size_t CellIndex_T;
60 typedef size_t MolIndex_T;
63 ParticleIterator (Type t_arg, CellContainer_T_ptr cells_arg,
const CellIndex_T offset_arg,
const CellIndex_T stride_arg,
const bool initialize=
true);
71 void deleteCurrentParticle();
73 CellIndex_T getCellIndex(){
return _cell_index;}
75 bool isValid()
const {
76 return _cells !=
nullptr and _cell_index < _cells->size() and _cell_iterator.isValid();
79 virtual void operator ++ ();
86 CellContainer_T_ptr _cells;
88 CellIndex_T _cell_index;
90 const CellIndex_T _stride;
92 virtual void next_non_empty_cell();
93 virtual void updateCellIteratorCell();
97inline ParticleIterator :: ParticleIterator () : _cell_iterator(), _type(ALL_CELLS), _cells (nullptr), _cell_index (0), _stride (1) {
100inline ParticleIterator :: ParticleIterator (Type t_arg, CellContainer_T_ptr cells_arg,
const CellIndex_T offset_arg,
const CellIndex_T stride_arg,
const bool initialize) :
101 _cell_iterator(&(cells_arg->front())), _type(t_arg), _cells (cells_arg), _cell_index (offset_arg), _stride (stride_arg) {
106#ifdef ENABLE_REDUCED_MEMORY_MODE
107 const unsigned long my_start = _cells->size() * mardyn_get_thread_num() / mardyn_get_num_threads();
108 _cell_index =
static_cast<CellIndex_T
>(my_start);
110 updateCellIteratorCell();
112 mardyn_assert(_cells !=
nullptr);
114 const CellContainer_T& cells = *_cells;
116 if(_cell_index < cells.size()) {
117 if(cells.at(_cell_index).isEmpty() or (_type == ONLY_INNER_AND_BOUNDARY and cells.at(_cell_index).isHaloCell())) {
118 next_non_empty_cell();
129 mardyn_assert(_stride == other._stride);
130 _cell_iterator = other._cell_iterator;
132 _cells = other._cells;
133 _cell_index = other._cell_index;
137inline void ParticleIterator :: next_non_empty_cell() {
138 mardyn_assert(_cells !=
nullptr);
140 const CellContainer_T& cells = *_cells;
141 const CellIndex_T numCells = cells.size();
144#ifndef ENABLE_REDUCED_MEMORY_MODE
145 for (_cell_index += _stride; _cell_index < numCells; _cell_index += _stride) {
147 const unsigned long my_end = _cells->size() * (mardyn_get_thread_num() + 1) / mardyn_get_num_threads();
148 for (_cell_index++; _cell_index < my_end; ++_cell_index) {
154 if(_type == ONLY_INNER_AND_BOUNDARY and c.isHaloCell()){
160 updateCellIteratorCell();
166inline void ParticleIterator :: operator ++ () {
168 if (_cell_iterator.isValid()) {
174 if (not _cell_iterator.isValid()) {
175 next_non_empty_cell();
179inline Molecule& ParticleIterator :: operator * ()
const {
181 mardyn_assert(&_cells->at(_cell_index) ==
dynamic_cast<const ParticleCell*
>(_cell_iterator.getCell()));
182 return _cell_iterator.operator *();
186inline Molecule* ParticleIterator:: operator -> ()
const {
187 return &(this->operator*());
190inline void ParticleIterator :: deleteCurrentParticle () {
191 _cell_iterator.deleteCurrentParticle();
194inline void ParticleIterator :: updateCellIteratorCell() {
195 if(_cell_index < _cells->size()) {
Definition: AutoPasSimpleMolecule.h:18
FullMolecule modeled as LJ sphere with point polarities.
Definition: FullMolecule.h:18
FullParticleCell data structure. Renamed from ParticleCell.
Definition: FullParticleCell.h:49
ParticleCellBase defines the interface for cells used by the LinkedCells data structure to store mole...
Definition: ParticleCellBase.h:23
bool isNotEmpty() const
Check if current cell contains molecules.
Definition: ParticleCellBase.h:44
Definition: ParticleIterator.h:50
Definition: SingleCellIterator.h:14