ls1-MarDyn
ls1-MarDyn molecular dynamics code
MoleculeRMM.h
1#ifndef SRC_MOLECULES_MOLECULERMM_H_
2#define SRC_MOLECULES_MOLECULERMM_H_
3
4#include "MoleculeInterface.h"
6
7#ifdef UNIT_TESTS
8#define DEBUG_FUNCTIONALITY_HACKS
9#endif
10
11class CellDataSoARMM;
12
14public:
15 enum StorageState {
16 STORAGE_SOA = 0,
17 STORAGE_AOS = 1
18 };
19
20public:
21 MoleculeRMM(unsigned long id = 0, Component *component = nullptr,
22 double rx = 0., double ry = 0., double rz = 0.,
23 double vx = 0., double vy = 0., double vz = 0.,
24 double = 0., double = 0., double = 0., double = 0., /*q0, q1, q2, q3*/
25 double = 0., double = 0., double = 0. /*Dx, Dy, Dz*/
26 ) {
27 _state = STORAGE_AOS;
28 _r[0] = rx;
29 _r[1] = ry;
30 _r[2] = rz;
31 _v[0] = vx;
32 _v[1] = vy;
33 _v[2] = vz;
34 _id = id;
35 _soa = nullptr;
36 _soa_index = 0;
37
38 if(component != nullptr) {
39 _component = component;
40 _quaternion = Quaternion(1.0, 0.0, 0.0, 0.0);
41 _initCalled = true;
42 } else if(not _initCalled) {
43 initStaticVars();
44 }
45 }
46
47 // copy constructor should always create an AOS molecule?
48 MoleculeRMM(const MoleculeRMM& other) {
49 _state = STORAGE_AOS;
50 for (int d = 0; d < 3; ++d) {
51 setr(d, other.r(d));
52 setv(d, other.v(d));
53 }
54 _id = other.getID();
55 _soa = nullptr;
56 _soa_index = 0;
57 }
58
59 MoleculeRMM(CellDataSoARMM * soa, size_t index) {
60 _state = STORAGE_SOA;
61 _soa = soa;
62 _soa_index = index;
63
64 if (not _initCalled) {
65 initStaticVars();
66 }
67 }
68
69 ~~MoleculeRMM() override = default;
70
71 unsigned long getID() const override;
72 void setid(unsigned long id) override;
73 void setr(unsigned short d, double r) override;
74 void setv(unsigned short d, double v) override;
75 void setF(unsigned short, double F) override;
76 double r(unsigned short d) const override;
77 double v(unsigned short d) const override;
78
79
80 void setComponent(Component *component) override {
81 _component = component;
82 this->updateMassInertia();
83 }
84
85 Component* component() const override {
86 return _component;
87 }
88
89#ifndef DEBUG_FUNCTIONALITY_HACKS
90 double F(unsigned short /*d*/) const override {
91 mardyn_assert(false);
92 return 0.0;
93 }
94#else
95 double F(unsigned short d) const override { return v(d);}
96#endif
97
98 const Quaternion& q() const override {
99 return _quaternion;
100 }
101
102 void setq(Quaternion q) override {
103 _quaternion = q;
104 }
105
106 double D(unsigned short /*d*/) const override {
107 return 0.0;
108 }
109 double M(unsigned short /*d*/) const override {
110 return 0.0;
111 }
112 double Vi(unsigned short /*d*/) const override {
113 return 0.0;
114 }
115
116 void setD(unsigned short /*d*/, double /*D*/) override {}
117
118 inline void move(int d, double dr) override {
119 setr(d, r(d) + dr);
120 }
121
122 double getI(unsigned short /*d*/) const override {
123 mardyn_assert(false);
124 // TODO: check values for single-centered molecules
125 return 0.0;
126 }
127
128 void updateMassInertia() override {}
129
130
131 double U_rot() override {
132 return 0.;
133 }
134
135 double U_rot_2() override {
136 return 0.;
137 }
138
139 void setupSoACache(CellDataSoABase * const s, unsigned iLJ, unsigned /*iC*/, unsigned /*iD*/, unsigned /*iQ*/) override {
140 mardyn_assert(false);
141 // should this ever be like called?
142 setSoA(s);
143 _soa_index = iLJ;
144 }
145
146 void setSoA(CellDataSoABase * s) override;
147
148 void setStartIndexSoA_LJ(unsigned i) override {
149 _soa_index = i;
150 }
151 void setStartIndexSoA_C(unsigned /*i*/) override {
152 mardyn_assert(false);
153 }
154 void setStartIndexSoA_D(unsigned /*i*/) override {
155 mardyn_assert(false);
156 }
157 void setStartIndexSoA_Q(unsigned /*i*/) override {
158 mardyn_assert(false);
159 }
160
161 unsigned int numSites() const override {
162 return 1;
163 }
164 unsigned int numOrientedSites() const override {
165 return 0;
166 }
167 unsigned int numLJcenters() const override {
168 return 1;
169 }
170 unsigned int numCharges() const override {
171 return 0;
172 }
173 unsigned int numDipoles() const override {
174 return 0;
175 }
176 unsigned int numQuadrupoles() const override {
177 return 0;
178 }
179
180 std::array<double, 3> site_d(unsigned int /*i*/) const override { return emptyArray3(); }
181
182 std::array<double, 3> ljcenter_d(unsigned int i) const override { return emptyArray3(); }
183 std::array<double, 3> charge_d(unsigned int /*i*/) const override { return emptyArray3(); }
184 std::array<double, 3> dipole_d(unsigned int /*i*/) const override { return emptyArray3(); }
185 std::array<double, 3> quadrupole_d(unsigned int /*i*/) const override { return emptyArray3(); }
186
187 std::array<double, 3> site_d_abs(unsigned int i) const override { return ljcenter_d_abs(i); }
188 std::array<double, 3> ljcenter_d_abs(unsigned int i) const override {
189 mardyn_assert(i == 0);
190 return r_arr();
191 }
192 std::array<double, 3> charge_d_abs(unsigned int /*i*/) const override { return emptyArray3(); }
193 std::array<double, 3> dipole_d_abs(unsigned int /*i*/) const override { return emptyArray3(); }
194 std::array<double, 3> quadrupole_d_abs(unsigned int /*i*/) const override { return emptyArray3(); }
195
196 std::array<double, 3> dipole_e(unsigned int /*i*/) const override { return emptyArray3(); }
197 std::array<double, 3> quadrupole_e(unsigned int /*i*/) const override { return emptyArray3(); }
198
199 std::array<double, 3> site_F(unsigned int /*i*/) const override { return emptyArray3(); }
200 std::array<double, 3> ljcenter_F(unsigned int /*i*/) const override { return emptyArray3(); }
201 std::array<double, 3> charge_F(unsigned int /*i*/) const override { return emptyArray3(); }
202 std::array<double, 3> dipole_F(unsigned int /*i*/) const override { return emptyArray3(); }
203 std::array<double, 3> quadrupole_F(unsigned int /*i*/) const override { return emptyArray3(); }
204
205 void normalizeQuaternion() override {}
206 std::array<double, 3> computeLJcenter_d(unsigned int /*i*/) const override { return emptyArray3(); }
207 std::array<double, 3> computeCharge_d(unsigned int /*i*/) const override { return emptyArray3(); }
208 std::array<double, 3> computeDipole_d(unsigned int /*i*/) const override { return emptyArray3(); }
209 std::array<double, 3> computeQuadrupole_d(unsigned int /*i*/) const override { return emptyArray3(); }
210 std::array<double, 3> computeDipole_e(unsigned int /*i*/) const override { return emptyArray3(); }
211 std::array<double, 3> computeQuadrupole_e(unsigned int /*i*/) const override { return emptyArray3(); }
212
213 unsigned long totalMemsize() const override {
214 //todo: check
215 mardyn_assert(false);
216 return sizeof(*this);
217 }
218
219 void setF(double /*F*/ [3]) override {}
220 void setM(double /*M*/[3]) override {}
221 void setVi(double /*Vi*/[3]) override {}
222 void Fadd(const double /*a*/[]) override {}
223 void Madd(const double /*a*/[]) override {}
224 void Viadd(const double /*a*/[]) override {}
225 void vadd(const double ax, const double ay, const double az) override {
226 setv(0, v(0) + ax); setv(1, v(1) + ay); setv(2, v(2) + az);
227 }
228 void vsub(const double ax, const double ay, const double az) override {
229 setv(0, v(0) - ax); setv(1, v(1) - ay); setv(2, v(2) - az);
230 }
231
232#ifndef DEBUG_FUNCTIONALITY_HACKS
233 void Fljcenteradd(unsigned int /*i*/, double /*a*/[]) override {}
234 void Fljcentersub(unsigned int /*i*/, double /*a*/[]) override {}
235#else
236 void Fljcenteradd(unsigned int i, double a[]) override {
237 mardyn_assert(i == 0);
238 for(int d = 0; d < 3; ++d)
239 setv(d, v(d) + a[d]);
240 }
241 void Fljcentersub(unsigned int i, double a[]) override {
242 mardyn_assert(i == 0);
243 for(int d = 0; d < 3; ++d)
244 setv(d, v(d) - a[d]);
245 }
246#endif
247
248 void Fchargeadd(unsigned int /*i*/, double /*a*/[]) override {}
249 void Fchargesub(unsigned int /*i*/, double /*a*/[]) override {}
250 void Fdipoleadd(unsigned int /*i*/, double /*a*/[]) override {}
251 void Fdipolesub(unsigned int /*i*/, double /*a*/[]) override {}
252 void Fquadrupoleadd(unsigned int /*i*/, double /*a*/[]) override {}
253 void Fquadrupolesub(unsigned int /*i*/, double /*a*/[]) override {}
254 void upd_preF(double /*dt*/) override {
255 mardyn_assert(false);
256 }
257 void upd_postF(double /*dt_halve*/, double& /*summv2*/, double& /*sumIw2*/) override {
258 mardyn_assert(false);
259 }
260 void calculate_mv2_Iw2(double& summv2, double& /*sumIw2*/) override {
261 summv2 += _component->m() * v2();
262 }
263 void calculate_mv2_Iw2(double& summv2, double& /*sumIw2*/, double offx, double offy, double offz) override {
264 double vcx = _v[0] - offx;
265 double vcy = _v[1] - offy;
266 double vcz = _v[2] - offz;
267 summv2 += _component->m() * (vcx*vcx + vcy*vcy + vcz*vcz);
268 }
269 static std::string getWriteFormat();
270 void write(std::ostream& /*ostrm*/) const override;
271 void writeBinary(std::ostream& /*ostrm*/) const override {}
272 void clearFM() override {}
273 void calcFM() override {}
274 void check(unsigned long /*id*/) override {}
275
276 static Component * getStaticRMMComponent() {
277 return _component;
278 }
279
280 void setStorageState(StorageState s) {
281 _state = s;
282 }
283
284 StorageState getStorageState() const {
285 return _state;
286 }
287
288
289 void buildOwnSoA() override {
290 mardyn_assert(_state == STORAGE_AOS);
291 }
292 void releaseOwnSoA() override {
293 mardyn_assert(_state == STORAGE_AOS);
294 }
295
296private:
297 static std::array<double, 3> emptyArray3() {
298 //mardyn_assert(false);
299 std::array<double, 3> ret{0., 0., 0.};
300 return ret;
301 }
302
303 static void initStaticVars();
304
305 static Component *_component;
306 static Quaternion _quaternion;
307 static bool _initCalled;
308
309 StorageState _state;
310
311 // if the state is AOS, the following values are read:
312 vcp_real_calc _r[3];
313 vcp_real_accum _v[3];
314 unsigned long _id;
315
316 // if the state is SOA, the values are read from the SoA:
317 CellDataSoARMM * _soa;
318 size_t _soa_index;
319};
320
321std::ostream& operator<<( std::ostream& os, const MoleculeRMM& m );
322
323#endif /* SRC_MOLECULES_MOLECULERMM_H_ */
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
Class implementing molecules as rigid rotators consisting out of different interaction sites (LJcente...
Definition: Component.h:14
double m() const
Definition: Component.h:53
Definition: MoleculeInterface.h:18
Definition: MoleculeRMM.h:13
void releaseOwnSoA() override
Definition: MoleculeRMM.h:292
void buildOwnSoA() override
Definition: MoleculeRMM.h:289
Definition: Quaternion.h:10
std::ostream & operator<<(std::ostream &stream, const Vector3< type > &v)
Definition: Vector3.h:22
::xsd::cxx::tree::id< char, ncname > id
C++ type corresponding to the ID XML Schema built-in type.
Definition: vtk-punstructured.h:322
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-punstructured.h:270