MaMiCo 1.2
Loading...
Searching...
No Matches
CouplingCellWithLinkedCells.h
1#ifndef _MOLECULARDYNAMICS_COUPLING_DATASTRUCTURES_COUPLINGCELLWITHLINKEDCELLS_H_
2#define _MOLECULARDYNAMICS_COUPLING_DATASTRUCTURES_COUPLINGCELLWITHLINKEDCELLS_H_
3
4#include "CouplingCell.h"
5
6namespace coupling {
7namespace datastructures {
8template <class LinkedCell, unsigned int dim> class CouplingCellWithLinkedCells;
9} // namespace datastructures
10} // namespace coupling
11
26template <class LinkedCell, unsigned int dim> class coupling::datastructures::CouplingCellWithLinkedCells : public coupling::datastructures::CouplingCell<dim> {
27public:
34 : coupling::datastructures::CouplingCell<dim>(), _numberCells(getNumberCells(blockSize)), _linkedCells(NULL) {
35
36 _linkedCells = new LinkedCell*[_numberCells];
37 if (_linkedCells == NULL) {
38 std::cout << "ERROR coupling::datastructures::CouplingCellWithLinkedCells: "
39 "_linkedCells == NULL"
40 << std::endl;
41 exit(EXIT_FAILURE);
42 }
43 // set each pointer to a NULL pointer
44 for (unsigned int i = 0; i < _numberCells; i++) {
45 _linkedCells[i] = NULL;
46 }
47 }
48
50 if (_linkedCells != NULL) {
51 for (unsigned int i = 0; i < _numberCells; i++) {
52 _linkedCells[i] = NULL;
53 }
54 delete[] _linkedCells;
55 _linkedCells = NULL;
56 }
57 }
58
65 void addLinkedCell(LinkedCell& cell, const unsigned int& index) { _linkedCells[index] = &cell; }
66
74 template <class A> void iterateCells(A& a) {
75 a.beginCellIteration();
76 for (unsigned int i = 0; i < _numberCells; i++) {
77 a.handleCell(*(_linkedCells[i]));
78 }
79 a.endCellIteration();
80 }
81
90 template <class A> void iterateConstCells(A& a) const {
91 a.beginCellIteration();
92 for (unsigned int i = 0; i < _numberCells; i++) {
93 a.handleCell(*(_linkedCells[i]));
94 }
95 a.endCellIteration();
96 }
97
98private:
105 unsigned int num = 1;
106 for (unsigned int d = 0; d < dim; d++) {
107 num = num * blockSize[d];
108 }
109 return num;
110 }
111
113 const unsigned int _numberCells;
114
117 LinkedCell** _linkedCells;
118};
119
120#endif // _MOLECULARDYNAMICS_COUPLING_DATASTRUCTURES_COUPLINGCELLWITHLINKEDCELLS_H_
defines the cell type with cell-averaged quantities. Derived from the class coupling::datastructures:...
Definition CouplingCellWithLinkedCells.h:26
virtual ~CouplingCellWithLinkedCells()
Definition CouplingCellWithLinkedCells.h:49
unsigned int getNumberCells(tarch::la::Vector< dim, unsigned int > blockSize) const
Definition CouplingCellWithLinkedCells.h:104
void addLinkedCell(LinkedCell &cell, const unsigned int &index)
Definition CouplingCellWithLinkedCells.h:65
LinkedCell ** _linkedCells
Definition CouplingCellWithLinkedCells.h:117
CouplingCellWithLinkedCells(tarch::la::Vector< dim, unsigned int > blockSize)
Definition CouplingCellWithLinkedCells.h:33
void iterateConstCells(A &a) const
Definition CouplingCellWithLinkedCells.h:90
const unsigned int _numberCells
Definition CouplingCellWithLinkedCells.h:113
void iterateCells(A &a)
Definition CouplingCellWithLinkedCells.h:74
defines the cell type with cell-averaged quantities only (no linked cells).
Definition CouplingCell.h:29
CouplingCell()
Definition CouplingCell.h:33
Definition Vector.h:24
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15