ls1-MarDyn
ls1-MarDyn molecular dynamics code
AutoPasSimpleMolecule.h
1
7#pragma once
8
9#include <autopas/molecularDynamics/MoleculeLJ.h>
10#include <autopas/utils/SoAType.h>
11#include <autopas/utils/inBox.h>
12
13#include "FullMolecule.h"
14
18class AutoPasSimpleMolecule final : public MoleculeInterface, public autopas::ParticleFP64 {
19public:
20 explicit AutoPasSimpleMolecule(unsigned long id = 0, Component* component = nullptr, double rx = 0., double ry = 0.,
21 double rz = 0., double vx = 0., double vy = 0., double vz = 0., double q0 = 1.,
22 double q1 = 1., double q2 = 0., double q3 = 0., double Dx = 0., double Dy = 0.,
23 double Dz = 0.);
24
26
27 ~~AutoPasSimpleMolecule() override = default;
28
32 enum AttributeNames : int { ptr, id, posX, posY, posZ, forceX, forceY, forceZ, typeId, ownershipState };
33
42 typename autopas::utils::SoAType<AutoPasSimpleMolecule *, size_t /*id*/, double /*x*/, double /*y*/,
43 double /*z*/, double /*fx*/, double /*fy*/, double /*fz*/,
44 size_t /*typeid*/, autopas::OwnershipState /*ownershipState*/>::Type;
45
52 template <AttributeNames attribute>
53 constexpr typename std::tuple_element<static_cast<size_t>(attribute), SoAArraysType>::type::value_type get() {
54 if constexpr (attribute == AttributeNames::ptr) {
55 return this;
56 } else if constexpr (attribute == AttributeNames::id) {
57 return getID();
58 } else if constexpr (attribute == AttributeNames::posX) {
59 return getR()[0];
60 } else if constexpr (attribute == AttributeNames::posY) {
61 return getR()[1];
62 } else if constexpr (attribute == AttributeNames::posZ) {
63 return getR()[2];
64 } else if constexpr (attribute == AttributeNames::forceX) {
65 return getF()[0];
66 } else if constexpr (attribute == AttributeNames::forceY) {
67 return getF()[1];
68 } else if constexpr (attribute == AttributeNames::forceZ) {
69 return getF()[2];
70 } else if constexpr (attribute == AttributeNames::typeId) {
71 return getTypeId();
72 } else if constexpr (attribute == AttributeNames::ownershipState) {
73 return this->_ownershipState;
74 } else {
75 throw std::runtime_error("AutoPasSimpleMolecule::get() unknown attribute");
76 }
77 }
78
85 template <AttributeNames attribute>
86 constexpr void set(
87 typename std::tuple_element<static_cast<size_t>(attribute), SoAArraysType>::type::value_type value) {
88 if constexpr (attribute == AttributeNames::id) {
89 setID(value);
90 } else if constexpr (attribute == AttributeNames::posX) {
91 _r[0] = value;
92 } else if constexpr (attribute == AttributeNames::posY) {
93 _r[1] = value;
94 } else if constexpr (attribute == AttributeNames::posZ) {
95 _r[2] = value;
96 } else if constexpr (attribute == AttributeNames::forceX) {
97 _f[0] = value;
98 } else if constexpr (attribute == AttributeNames::forceY) {
99 _f[1] = value;
100 } else if constexpr (attribute == AttributeNames::forceZ) {
101 _f[2] = value;
102 } else if constexpr (attribute == AttributeNames::typeId) {
103 setTypeId(value);
104 } else if constexpr (attribute == AttributeNames::ownershipState) {
105 this->_ownershipState = value;
106 } else {
107 throw std::runtime_error("AutoPasSimpleMolecule::set() unknown attribute");
108 }
109 }
110
111 unsigned long getID() const override { return _id; }
112
113 void setid(unsigned long id) override { setID(id); }
114
115 void setComponent(Component* component) override { _component = component; }
116
117 void setr(unsigned short d, double r) override { _r[d] = r; }
118
119 void setv(unsigned short d, double v) override { _v[d] = v; }
120
121 void setF(unsigned short d, double F) override { _f[d] = F; }
122
123 Component* component() const override { return _component; }
124
125 double r(unsigned short d) const override { return getR()[d]; }
126
127 double v(unsigned short d) const override { return getV()[d]; }
128
129 double F(unsigned short d) const override { return getF()[d]; }
130
131 const Quaternion& q() const override { return _quaternion; }
132
133 void setq(Quaternion q) override { _quaternion = q; }
134
135 double D(unsigned short d) const override { return 0.; }
136
137 double M(unsigned short d) const override { return 0.; }
138
139 double Vi(unsigned short d) const override { return 0.; }
140
141 void setD(unsigned short d, double D) override {}
142
143 inline void move(int d, double dr) override { setr(d, r(d) + dr); }
144
145 // by Stefan Becker
146 double getI(unsigned short d) const override { return 1.; }
147
148 double U_rot() override { return 0.; }
149
150 double U_rot_2() override { return 0.; }
151
152 void updateMassInertia() override {}
153
154 void setupSoACache(CellDataSoABase* const s, unsigned iLJ, unsigned iC, unsigned iD, unsigned iQ) override {}
155
156 void setSoA(CellDataSoABase* const s) override{};
157
158 void setStartIndexSoA_LJ(unsigned i) override{};
159
160 void setStartIndexSoA_C(unsigned i) override{};
161
162 void setStartIndexSoA_D(unsigned i) override{};
163
164 void setStartIndexSoA_Q(unsigned i) override{};
165
166 unsigned int numSites() const override { return 1; };
167
168 unsigned int numOrientedSites() const override { return 0; }
169
170 unsigned int numLJcenters() const override { return 1; }
171
172 unsigned int numCharges() const override { return 0; }
173
174 unsigned int numDipoles() const override { return 0; }
175
176 unsigned int numQuadrupoles() const override { return 0; }
177
178 std::array<double, 3> site_d(unsigned int i) const override { return emptyArray3(); }
179
180 std::array<double, 3> ljcenter_d(unsigned int i) const override { return emptyArray3(); }
181
182 std::array<double, 3> charge_d(unsigned int i) const override { return emptyArray3(); }
183
184 std::array<double, 3> dipole_d(unsigned int i) const override { return emptyArray3(); }
185
186 std::array<double, 3> quadrupole_d(unsigned int i) const override { return emptyArray3(); }
187
188 std::array<double, 3> site_d_abs(unsigned int i) const override { return getR(); }
189
190 std::array<double, 3> ljcenter_d_abs(unsigned int i) const override { return getR(); }
191
192 std::array<double, 3> charge_d_abs(unsigned int i) const override { return emptyArray3(); }
193
194 std::array<double, 3> dipole_d_abs(unsigned int i) const override { return emptyArray3(); }
195
196 std::array<double, 3> quadrupole_d_abs(unsigned int i) const override { return emptyArray3(); }
197
198 std::array<double, 3> dipole_e(unsigned int i) const override { return emptyArray3(); }
199
200 std::array<double, 3> quadrupole_e(unsigned int i) const override { return emptyArray3(); }
201
202 std::array<double, 3> site_F(unsigned int i) const override { return getF(); }
203
204 std::array<double, 3> ljcenter_F(unsigned int i) const override { return emptyArray3(); }
205
206 std::array<double, 3> charge_F(unsigned int i) const override { return emptyArray3(); }
207
208 std::array<double, 3> dipole_F(unsigned int i) const override { return emptyArray3(); }
209
210 std::array<double, 3> quadrupole_F(unsigned int i) const override { return emptyArray3(); }
211
212 void normalizeQuaternion() override {}
213
214 std::array<double, 3> computeLJcenter_d(unsigned int i) const override { return emptyArray3(); }
215
216 std::array<double, 3> computeCharge_d(unsigned int i) const override { return emptyArray3(); }
217
218 std::array<double, 3> computeDipole_d(unsigned int i) const override { return emptyArray3(); }
219
220 std::array<double, 3> computeQuadrupole_d(unsigned int i) const override { return emptyArray3(); }
221
222 std::array<double, 3> computeDipole_e(unsigned int i) const override { return emptyArray3(); }
223
224 std::array<double, 3> computeQuadrupole_e(unsigned int i) const override { return emptyArray3(); }
225
226 unsigned long totalMemsize() const override { return sizeof(*this); }
227
228 void setF(double F[3]) override {
229 for (unsigned short i = 0; i < 3; i++) _f[i] = F[i];
230 }
231
232 void setF(const std::array<double, 3>& f) { autopas::Particle::setF(f); }
233
234 void setM(double M[3]) override {}
235
236 void setVi(double Vi[3]) override {}
237
238 void Fadd(const double F[]) override {
239 for (unsigned short i = 0; i < 3; i++) _f[i] += F[i];
240 }
241
242 void Madd(const double a[]) override {}
243
244 void Viadd(const double a[]) override {}
245
246 void vadd(const double ax, const double ay, const double az) override {
247 std::array<double, 3> addV_arr{ax, ay, az};
248 addV(addV_arr);
249 }
250
251 void vsub(const double ax, const double ay, const double az) override {
252 std::array<double, 3> addV_arr{-ax, -ay, -az};
253 addV(addV_arr);
254 }
255
256 void Fljcenteradd(unsigned int i, double a[]) override { vadd(a[0], a[1], a[2]); }
257
258 void Fljcentersub(unsigned int i, double a[]) override { vsub(a[0], a[1], a[2]); }
259
260 void Fchargeadd(unsigned int i, double a[]) override {}
261
262 void Fchargesub(unsigned int i, double a[]) override {}
263
264 void Fdipoleadd(unsigned int i, double a[]) override {}
265
266 void Fdipolesub(unsigned int i, double a[]) override {}
267
268 void Fquadrupoleadd(unsigned int i, double a[]) override {}
269
270 void Fquadrupolesub(unsigned int i, double a[]) override {}
271
272 // Leapfrog integration:
273 void upd_preF(double dt) override;
274
275 void upd_postF(double dt_halve, double& summv2, double& sumIw2) override;
276
277 void calculate_mv2_Iw2(double& summv2, double& sumIw2) override { summv2 += _component->m() * v2(); }
278
279 void calculate_mv2_Iw2(double& summv2, double& sumIw2, double offx, double offy, double offz) override {
280 double vcx = _v[0] - offx;
281 double vcy = _v[1] - offy;
282 double vcz = _v[2] - offz;
283 summv2 += _component->m() * (vcx * vcx + vcy * vcy + vcz * vcz);
284 }
285
286 static std::string getWriteFormat() { return "IRV"; }
287
288 void write(std::ostream& ostrm) const override {
289 ostrm << getID() << "\t" << r(0) << " " << r(1) << " " << r(2) << "\t" << v(0) << " " << v(1) << " " << v(2)
290 << "\t" << std::endl;
291 }
292
293 void writeBinary(std::ostream& ostrm) const override {
294 ostrm.write(reinterpret_cast<const char*>(&_id), 8);
295 ostrm.write(reinterpret_cast<const char*>(&(_r[0])), 8);
296 ostrm.write(reinterpret_cast<const char*>(&(_r[1])), 8);
297 ostrm.write(reinterpret_cast<const char*>(&(_r[2])), 8);
298 ostrm.write(reinterpret_cast<const char*>(&(_v[0])), 8);
299 ostrm.write(reinterpret_cast<const char*>(&(_v[1])), 8);
300 ostrm.write(reinterpret_cast<const char*>(&(_v[2])), 8);
301 }
302
303 void clearFM() override {
304 for (unsigned short d = 0; d < 3; ++d) {
305 setF(d, 0.);
306 }
307 }
308 void calcFM() override {}
309 void check(unsigned long id) override {}
310
311 void buildOwnSoA() override {}
312
313 void releaseOwnSoA() override {}
314
315 bool inBox(const double rmin[3], const double rmax[3]) const override {
316 return MoleculeInterface::inBox(rmin, rmax);
317 }
318
319 bool inBox(const std::array<double, 3>& rmin, const std::array<double, 3>& rmax) const {
320 return autopas::utils::inBox(this->getR(), rmin, rmax);
321 }
322
323 size_t getTypeId() const {
324 mardyn_assert(_component != nullptr);
325 return _component->ID();
326 }
327
328private:
329 static std::array<double, 3> emptyArray3() {
330 // mardyn_assert(false);
331 std::array<double, 3> ret{0., 0., 0.};
332 return ret;
333 }
334
335 static Component* _component;
336 static Quaternion _quaternion;
337};
338
339std::ostream& operator<<( std::ostream& os, const AutoPasSimpleMolecule& m );
Definition: AutoPasSimpleMolecule.h:18
bool inBox(const double rmin[3], const double rmax[3]) const override
test whether molecule is inside a cuboid region
Definition: AutoPasSimpleMolecule.h:315
typename autopas::utils::SoAType< AutoPasSimpleMolecule *, size_t, double, double, double, double, double, double, size_t, autopas::OwnershipState >::Type SoAArraysType
Definition: AutoPasSimpleMolecule.h:44
void buildOwnSoA() override
Definition: AutoPasSimpleMolecule.h:311
constexpr std::tuple_element< static_cast< size_t >(attribute), SoAArraysType >::type::value_type get()
Definition: AutoPasSimpleMolecule.h:53
AttributeNames
Definition: AutoPasSimpleMolecule.h:32
void releaseOwnSoA() override
Definition: AutoPasSimpleMolecule.h:313
constexpr void set(typename std::tuple_element< static_cast< size_t >(attribute), SoAArraysType >::type::value_type value)
Definition: AutoPasSimpleMolecule.h:86
Definition: CellDataSoABase.h:13
Class implementing molecules as rigid rotators consisting out of different interaction sites (LJcente...
Definition: Component.h:14
double m() const
Definition: Component.h:53
unsigned int ID() const
Definition: Component.h:33
Definition: MoleculeInterface.h:18
virtual bool inBox(const double l[3], const double u[3]) const
test whether molecule is inside a cuboid region
Definition: MoleculeInterface.h:300
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