8#ifndef SRC_PARTICLECONTAINER_LINKEDCELLTRAVERSALS_ORIGINALCELLPAIRTRAVERSAL_H_
9#define SRC_PARTICLECONTAINER_LINKEDCELLTRAVERSALS_ORIGINALCELLPAIRTRAVERSAL_H_
11#include "CellPairTraversals.h"
12#include "utils/Logger.h"
13#include "utils/mardyn_assert.h"
14#include "utils/threeDimensionalMapping.h"
15#include "particleContainer/adapter/CellProcessor.h"
20template <
class CellTemplate>
25 computeNeighbourOffsets();
30 virtual void rebuild(std::vector<CellTemplate>& cells,
31 const std::array<unsigned long, 3>& dims,
double cellLength[3],
double cutoff,
36 void traverseCellPairsInner(
CellProcessor& cellProcessor,
unsigned stage,
unsigned stageCount);
38 virtual void processBaseCell(
CellProcessor& cellProcessor,
unsigned long cellIndex)
const;
48 void computeNeighbourOffsets();
49 void traverseCellPairsBackend(
CellProcessor& cellProcessor,
unsigned loIndex,
unsigned hiIndex, TraverseType
type)
const;
57template<
class CellTemplate>
59 const std::array<unsigned long, 3> &dims,
double cellLength[3],
double cutoff,
63 computeNeighbourOffsets();
65 _innerMostCellIndices.clear();
71 for (
auto i = 0; i < maxIndex; ++i) {
72 if (this->_cells->at(i).isInnerMostCell()){
73 _innerMostCellIndices.push_back(i);
77 global_log->error() <<
"OriginalCellPairTraversalDat::rebuild was called with incompatible Traversal data!" << endl;
82template<
class CellTemplate>
84 Log::global_log->debug() <<
"Setting up cell neighbour index lists." << std::endl;
86 std::fill(_forwardNeighbourOffsets.begin(), _forwardNeighbourOffsets.end(), 0);
87 std::fill(_backwardNeighbourOffsets.begin(), _backwardNeighbourOffsets.end(), 0);
88 int forwardNeighbourIndex = 0, backwardNeighbourIndex = 0;
90 long maxNeighbourOffset = 0;
91 long minNeighbourOffset = 0;
93 std::array<long, 3> dims;
94 for (
int d = 0; d < 3; ++d) {
95 dims[d] =
static_cast<long>(this->_dims[d]);
98 std::array<long, 3> r;
99 for (r[2] = -1; r[2] <= 1; r[2]++) {
100 for (r[1] = -1; r[1] <= 1; r[1]++) {
101 for (r[0] = -1; r[0] <= 1; r[0]++) {
103 long offset = threeDimensionalMapping::threeToOneD(r, dims);
106 _forwardNeighbourOffsets[forwardNeighbourIndex] = offset;
107 ++forwardNeighbourIndex;
108 if (offset > maxNeighbourOffset) {
109 maxNeighbourOffset = offset;
113 _backwardNeighbourOffsets[backwardNeighbourIndex] = abs(offset);
114 ++backwardNeighbourIndex;
115 if (abs(offset) > minNeighbourOffset) {
116 minNeighbourOffset = abs(offset);
123 mardyn_assert(forwardNeighbourIndex == 13);
124 mardyn_assert(backwardNeighbourIndex == 13);
126 Log::global_log->info() <<
"Neighbour offsets are bounded by "
127 << minNeighbourOffset <<
", " << maxNeighbourOffset << std::endl;
131template<
class CellTemplate>
133 CellProcessor& cellProcessor,
unsigned loIndex,
unsigned hiIndex,
134 TraverseType
type)
const {
137 for (
unsigned i = loIndex; i < hiIndex; ++i) {
138 processBaseCell(cellProcessor, i);
142 for (
unsigned i = loIndex; i < hiIndex; ++i) {
143 processBaseCell(cellProcessor, _innerMostCellIndices.at(i));
147 for (
unsigned i = loIndex; i < hiIndex; ++i) {
148 CellTemplate& baseCell = this->_cells->at(i);
149 if (!baseCell.isInnerMostCell()) {
150 processBaseCell(cellProcessor, i);
157template<
class CellTemplate>
159 unsigned long start = 0ul;
160 unsigned long end = this->_cells->size();
161 traverseCellPairsBackend(cellProcessor, start, end, ALL_CELLS);
164template<
class CellTemplate>
166 unsigned long start = 0ul;
167 unsigned long end = this->_cells->size();
168 traverseCellPairsBackend(cellProcessor, start, end, OUTER_CELLS);
171template<
class CellTemplate>
174 unsigned stageCount) {
175 unsigned long start = _innerMostCellIndices.size() * stage / stageCount;
176 unsigned long end = _innerMostCellIndices.size() * (stage+1) / stageCount;
177 traverseCellPairsBackend(cellProcessor, start, end, INNER_CELLS);
180template<
class CellTemplate>
182 unsigned long cellIndex)
const {
184 CellTemplate& currentCell = this->_cells->at(cellIndex);
186 if (currentCell.isInnerCell()) {
189 for (
auto& neighbourOffset : this->_forwardNeighbourOffsets) {
190 CellTemplate& neighbourCell = this->_cells->at(cellIndex + neighbourOffset);
195 if (currentCell.isBoundaryCell()) {
198 for (
auto& neighbourOffset : this->_forwardNeighbourOffsets) {
199 CellTemplate& neighbourCell = this->_cells->at(cellIndex + neighbourOffset);
204 for (
auto& neighbourOffset : this->_backwardNeighbourOffsets) {
205 CellTemplate& neighbourCell = this->_cells->at(cellIndex - neighbourOffset);
206 if (neighbourCell.isHaloCell()) {
Definition: CellPairTraversals.h:21
virtual void rebuild(std::vector< CellTemplate > &cells, const std::array< unsigned long, 3 > &dims, double cellLength[3], double cutoff, CellPairTraversalData *data)
Definition: CellPairTraversals.h:32
Definition: CellProcessor.h:29
virtual void processCell(ParticleCell &cell)=0
virtual void processCellPair(ParticleCell &cell1, ParticleCell &cell2, bool sumAll=false)=0
Definition: OriginalCellPairTraversal.h:21
virtual void rebuild(std::vector< CellTemplate > &cells, const std::array< unsigned long, 3 > &dims, double cellLength[3], double cutoff, struct CellPairTraversalData *data)
Definition: OriginalCellPairTraversal.h:58
std::array< long, 13 > _backwardNeighbourOffsets
Neighbours that come in the total ordering before a cell.
Definition: OriginalCellPairTraversal.h:53
std::array< long, 13 > _forwardNeighbourOffsets
Neighbours that come in the total ordering after a cell.
Definition: OriginalCellPairTraversal.h:52
std::vector< unsigned long > _innerMostCellIndices
Vector containing the indices (for the cells vector) of all inner cells (without boundary)
Definition: OriginalCellPairTraversal.h:54
static void exit(int exitcode)
Terminate simulation with given exit code.
Definition: Simulation.cpp:155
Enumeration class corresponding to the type schema type.
Definition: vtk-unstructured.h:1746
Definition: CellPairTraversals.h:16
Definition: OriginalCellPairTraversal.h:17