ls1-MarDyn
ls1-MarDyn molecular dynamics code
CuboidPyramidalMatrix.h
1/*
2 * CuboidPyramidalMatrix.h
3 *
4 * Created on: Dec 11, 2014
5 * Author: uwe
6 */
7
8#ifndef CUBOIDPYRAMIDALMATRIX_H_
9#define CUBOIDPYRAMIDALMATRIX_H_
10
11#include "utils/mardyn_assert.h"
12#include <cstdlib>
13
14namespace bhfmm {
15
17
18public:
19 CuboidPyramidalMatrix() : _totalNumEntries(0), _numSlices(0), _entries(NULL) {}
20
21 CuboidPyramidalMatrix(unsigned N, bool clean = false) :
22 _totalNumEntries(N*(N+1)*(4*N-1)/6), _numSlices(N) {
23 if (N != 0) {
24 _entries = new double[_totalNumEntries];
25 } else {
26 _entries = NULL;
27 }
28 if (clean) clear();
29 }
30
32 _totalNumEntries(c._totalNumEntries), _numSlices(c._numSlices) {
33
34 _entries = new double[_totalNumEntries];
35 std::copy(c._entries, c._entries + c._totalNumEntries, _entries);
36 }
37
38 /* Assignment using copy-and-swap idiom */
40 std::swap(_totalNumEntries, rhs._totalNumEntries);
41 std::swap(_numSlices, rhs._numSlices);
42 std::swap(_entries, rhs._entries);
43 return *this;
44 }
45
46 ~~CuboidPyramidalMatrix() {if (_entries != NULL) delete[] _entries;}
47
48 void clear() { for (unsigned i = 0; i < _totalNumEntries; ++i) _entries[i] = 0.0; }
49
50 unsigned get_num_entries() const {return _totalNumEntries;}
51
52 inline double & access(unsigned i, unsigned j, int k) {return _entries[index(i,j,k)];}
53 inline const double& access_const(unsigned i, unsigned j, int k) const {return _entries[index(i,j,k)];}
54 inline double & access_seq(unsigned i) {return _entries[i];}
55 inline double access_seq_const(unsigned i) const {return _entries[i];}
56
57 inline unsigned index(unsigned i, unsigned j, int k) const {
58 mardyn_assert(i <= _numSlices);
59 mardyn_assert(j <= i);
60 mardyn_assert(static_cast<unsigned>(abs(k))<= i);
61 return i*(i+1)*(4*i-1)/6 + (2*i + 1)*j + i + k; // valid for i < 1024
62
63 /* i*(i+1)*(4*i-1)/6 : select slice.
64 * + (2*i + 1)*j : select row
65 * + i + k : select column. k is signed -> start at the middle column i */
66 }
67
68private:
69
70 unsigned _totalNumEntries;
71 unsigned _numSlices;
72
73 double* _entries;
74};
75
76} /* namespace bhfmm */
77
78
79
80
81#endif /* CUBOIDPYRAMIDALMATRIX_H_ */
Definition: CuboidPyramidalMatrix.h:16
Definition: L2PCellProcessor.cpp:15