ls1-MarDyn
ls1-MarDyn molecular dynamics code
SingleCellIterator.h
1/*
2 * SingleCellIterator.h
3 *
4 * Created on: 27 Sep 2017
5 * Author: tchipevn
6 */
7
8#ifndef SRC_PARTICLECONTAINER_SINGLECELLITERATOR_H_
9#define SRC_PARTICLECONTAINER_SINGLECELLITERATOR_H_
10
11#include "molecules/Molecule.h"
12
13template<class ParticleCell>
15public:
18 size_t index_arg = 0) : _cell(cell_arg), _mol_index(index_arg), _currentParticleDeleted(false) {
19 }
20 SingleCellIterator& operator=(const SingleCellIterator& other);
22
23 Molecule& operator * () const {
24 // .at method performs automatically an out-of-bounds check
25 Molecule *moleculePtr = nullptr;
26
27 #ifdef ENABLE_REDUCED_MEMORY_MODE
28 moleculePtr = const_cast<Molecule *>(& _AoSMoleculeReservoir);
29 #endif
30
31 _cell->moleculesAtNew(_mol_index, moleculePtr);
32
33 return *moleculePtr;
34 }
35 Molecule* operator -> () const;
36
37 void deleteCurrentParticle() {
38 _cell->deleteMoleculeByIndex(_mol_index);
39 _currentParticleDeleted = true;
40 }
41
42 size_t getIndex() const {
43 return _mol_index;
44 }
45
46 ParticleCell * getCell() const { return _cell; }
47
48 bool isValid() const {
49 return _cell != nullptr and _mol_index < static_cast<size_t>(_cell->getMoleculeCount());
50 }
51
52 void operator ++() {
53 // if the "current" particle was deleted, then there is a new particle at _mol_index
54 // and the _mol_index value should not be incremented.
55 _mol_index += _currentParticleDeleted ? 0 : 1;
56
57 _currentParticleDeleted = false;
58 }
59
60private:
61
62 ParticleCell * _cell;
63 size_t _mol_index;
64 bool _currentParticleDeleted;
65
66 // note: possible to add offset for a threaded entry within cells
67
68#ifdef ENABLE_REDUCED_MEMORY_MODE
69 Molecule _AoSMoleculeReservoir;
70#endif
71
72};
73
74template<class ParticleCell>
75inline SingleCellIterator<ParticleCell>::SingleCellIterator() : _cell(nullptr), _mol_index(0), _currentParticleDeleted(false) {
76}
77
78template<class ParticleCell>
80 _cell = other._cell;
81 _mol_index = other._mol_index;
82 _currentParticleDeleted = other._currentParticleDeleted;
83 // no operator= for Molecule and it should not be needed.
84 return *this;
85}
86
87// no clue why this returns a pointer
88template<class ParticleCell>
90 return &(this->operator*());
91}
92
93#endif /* SRC_PARTICLECONTAINER_SINGLECELLITERATOR_H_ */
FullMolecule modeled as LJ sphere with point polarities.
Definition: FullMolecule.h:18
FullParticleCell data structure. Renamed from ParticleCell.
Definition: FullParticleCell.h:49
int getMoleculeCount() const override
return the number of molecules contained in this cell
Definition: FullParticleCell.cpp:77
Definition: SingleCellIterator.h:14
SolidHarmonicsExpansion operator*(double scalar, SolidHarmonicsExpansion RHS)
Definition: SolidHarmonicsExpansion.cpp:67