ls1-MarDyn
ls1-MarDyn molecular dynamics code
CellDataSoARMM.h
1#ifndef CELLDATASOARMM_H_
2#define CELLDATASOARMM_H_
3
4#include "utils/ConcatenatedAlignedArrayRMM.h"
6#include "molecules/Molecule.h"
7#include "molecules/MoleculeRMM.h"
8#include "CellDataSoABase.h"
9#include <cstdint>
10
17 typedef ConcatenatedAlignedArrayRMM<vcp_real_calc, vcp_real_accum, uint64_t>::Quantity_t Quantity_t;
18public:
19 CellDataSoARMM(size_t mol_arg) {
20 resize(mol_arg);
21 }
22
23 vcp_inline vcp_real_calc* r_xBegin() { return _data.begin_calc(Quantity_t::RX);}
24 vcp_inline vcp_real_calc* r_yBegin() { return _data.begin_calc(Quantity_t::RY);}
25 vcp_inline vcp_real_calc* r_zBegin() { return _data.begin_calc(Quantity_t::RZ);}
26 vcp_inline vcp_real_accum* v_xBegin() { return _data.begin_accum(Quantity_t::VX);}
27 vcp_inline vcp_real_accum* v_yBegin() { return _data.begin_accum(Quantity_t::VY);}
28 vcp_inline vcp_real_accum* v_zBegin() { return _data.begin_accum(Quantity_t::VZ);}
29
30 const vcp_inline vcp_real_calc* r_xBegin() const { return _data.begin_calc(Quantity_t::RX);}
31 const vcp_inline vcp_real_calc* r_yBegin() const { return _data.begin_calc(Quantity_t::RY);}
32 const vcp_inline vcp_real_calc* r_zBegin() const { return _data.begin_calc(Quantity_t::RZ);}
33 const vcp_inline vcp_real_accum* v_xBegin() const { return _data.begin_accum(Quantity_t::VX);}
34 const vcp_inline vcp_real_accum* v_yBegin() const { return _data.begin_accum(Quantity_t::VY);}
35 const vcp_inline vcp_real_accum* v_zBegin() const { return _data.begin_accum(Quantity_t::VZ);}
36
37 void resize(size_t molecules_arg) {
38 const bool allow_shrink = false; // TODO shrink at some point in the future
39
40 setMolNum(molecules_arg);
41
42 // entries per molecule
43 _data.resize(getMolNum());
44 }
45
46 size_t getDynamicSize() const {
47 return _data.get_dynamic_memory();
48 }
49
50 void appendMolecule(MoleculeInterface& m) {
51 MoleculeRMM& m_RMM = downcastMoleculeReferenceRMM(m);
52 std::array<vcp_real_calc, 3> calcs = {
53 static_cast<vcp_real_calc>(m_RMM.r(0)),
54 static_cast<vcp_real_calc>(m_RMM.r(1)),
55 static_cast<vcp_real_calc>(m_RMM.r(2))
56 };
57 std::array<vcp_real_accum, 3> accums = {
58 static_cast<vcp_real_accum>(m_RMM.v(0)),
59 static_cast<vcp_real_accum>(m_RMM.v(1)),
60 static_cast<vcp_real_accum>(m_RMM.v(2))
61 };
62
63 _data.appendValues(calcs, accums, m_RMM.getID(), getMolNum());
64 incrementMolNum();
65 }
66
67 void increaseStorage(size_t additionalMolecules) {
68 _data.increaseStorage(getMolNum(), additionalMolecules);
69 }
70
71 Molecule buildAoSMolecule(size_t index) const {
72 return Molecule (
73 getMolUid(index), nullptr,
74 getMolR(0,index), getMolR(1,index), getMolR(2,index),
75 getMolV(0,index), getMolV(1,index), getMolV(2,index));
76 }
77
78 void readImmutableMolecule(size_t index, MoleculeInterface& m) const {
79 MoleculeRMM& m_RMM = downcastMoleculeReferenceRMM(m);
80
81 // changes in AOS storage will not be saved
82 m_RMM.setStorageState(MoleculeRMM::STORAGE_AOS);
83 m_RMM.setr(0, getMolR(0,index));
84 m_RMM.setr(1, getMolR(1,index));
85 m_RMM.setr(2, getMolR(2,index));
86 m_RMM.setv(0, getMolV(0,index));
87 m_RMM.setv(1, getMolV(1,index));
88 m_RMM.setv(2, getMolV(2,index));
89 m_RMM.setid(getMolUid(index));
90 }
91
92 void readMutableMolecule(size_t index, MoleculeInterface& m) {
93 MoleculeRMM& m_RMM = downcastMoleculeReferenceRMM(m);
94
95 // changes in SOA storage will be saved
96 m_RMM.setStorageState(MoleculeRMM::STORAGE_SOA);
97 m_RMM.setSoA(this);
98 m_RMM.setStartIndexSoA_LJ(index);
99 }
100
101 void writeMolecule(size_t i, const MoleculeInterface& m) {
102 setMolR(0, i, static_cast<vcp_real_calc>(m.r(0)));
103 setMolR(1, i, static_cast<vcp_real_calc>(m.r(1)));
104 setMolR(2, i, static_cast<vcp_real_calc>(m.r(2)));
105 setMolV(0, i, static_cast<vcp_real_calc>(m.v(0)));
106 setMolV(1, i, static_cast<vcp_real_calc>(m.v(1)));
107 setMolV(2, i, static_cast<vcp_real_calc>(m.v(2)));
108 setMolUid(i, m.getID());
109 }
110
111 void deleteMolecule(size_t index) {
112 mardyn_assert(index < getMolNum());
113 if(getMolNum() > 1 and index < getMolNum() - 1) {
114 setMolR(0, index, getMolR(0,getMolNum()-1));
115 setMolR(1, index, getMolR(1,getMolNum()-1));
116 setMolR(2, index, getMolR(2,getMolNum()-1));
117 setMolV(0, index, getMolV(0,getMolNum()-1));
118 setMolV(1, index, getMolV(1,getMolNum()-1));
119 setMolV(2, index, getMolV(2,getMolNum()-1));
120 setMolUid(index, getMolUid(getMolNum()-1));
121 }
122 decrementMolNum();
123 }
124
125 void prefetchForForce() const {
126 _data.prefetchForForce();
127 }
128
129 vcp_real_calc getMolR(unsigned short d, size_t index) const {
130 mardyn_assert(d < 3);
131 Quantity_t q = static_cast<Quantity_t>(d);
132 return _data.get_calc(q,index);
133 }
134
135 void setMolR(unsigned short d, size_t index, vcp_real_calc molR) {
136 mardyn_assert(d < 3);
137 Quantity_t q = static_cast<Quantity_t>(d);
138 _data.get_calc(q,index) = molR;
139 }
140
141 vcp_real_accum getMolV(unsigned short d, size_t index) const {
142 mardyn_assert(d < 3);
143 Quantity_t q = static_cast<Quantity_t>(d + 3); // +3 to convert to VX, VY, VZ
144 return _data.get_accum(q,index);
145 }
146
147 void setMolV(unsigned short d, size_t index, vcp_real_accum molV) {
148 mardyn_assert(d < 3);
149 Quantity_t q = static_cast<Quantity_t>(d + 3); // +3 to convert to VX, VY, VZ
150 _data.get_accum(q,index) = molV;
151 }
152
153 uint64_t getMolUid(size_t index) const {
154 Quantity_t q = Quantity_t::UID;
155 return _data.get_uid(q, index);
156 }
157
158 void setMolUid(size_t index, unsigned long molUid) {
159 Quantity_t q = Quantity_t::UID;
160 _data.get_uid(q, index) = molUid;
161 }
162
163private:
164 // entries per molecule
166};
167
168#endif /* CELLDATASOARMM_H_ */
169
Defines the length of the vectors and the corresponding functions.
Definition: CellDataSoABase.h:13
Structure of Arrays for single-center lennard-Jones molecules for the RMM run.
Definition: CellDataSoARMM.h:16
Definition: ConcatenatedAlignedArrayRMM.h:16
FullMolecule modeled as LJ sphere with point polarities.
Definition: FullMolecule.h:18
Definition: MoleculeInterface.h:18
Definition: MoleculeRMM.h:13