AutoPas  3.0.0
Loading...
Searching...
No Matches
MoleculeLJ.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <vector>
11
14
15namespace mdLib {
16
21 public:
22 MoleculeLJ() = default;
23
31 MoleculeLJ(const std::array<double, 3> &pos, const std::array<double, 3> &v, unsigned long moleculeId,
32 unsigned long typeId = 0);
33
34 ~MoleculeLJ() override = default;
35
39 enum AttributeNames : int {
40 ptr,
41 id,
42 posX,
43 posY,
44 posZ,
45 velocityX,
46 velocityY,
47 velocityZ,
48 forceX,
49 forceY,
50 forceZ,
51 oldForceX,
52 oldForceY,
53 oldForceZ,
54 typeId,
55 ownershipState
56 };
57
66 typename autopas::utils::SoAType<MoleculeLJ *, size_t /*id*/, double /*x*/, double /*y*/, double /*z*/,
67 double /*vx*/, double /*vy*/, double /*vz*/, double /*fx*/, double /*fy*/,
68 double /*fz*/, double /*oldFx*/, double /*oldFy*/, double /*oldFz*/,
69 size_t /*typeid*/, autopas::OwnershipState /*ownershipState*/>::Type;
70
76 template <AttributeNames attribute, std::enable_if_t<attribute == AttributeNames::ptr, bool> = true>
77 constexpr typename std::tuple_element<attribute, SoAArraysType>::type::value_type get() {
78 return this;
79 }
87 template <AttributeNames attribute, std::enable_if_t<attribute != AttributeNames::ptr, bool> = true>
88 constexpr typename std::tuple_element<attribute, SoAArraysType>::type::value_type get() const {
89 if constexpr (attribute == AttributeNames::id) {
90 return getID();
91 } else if constexpr (attribute == AttributeNames::posX) {
92 return getR()[0];
93 } else if constexpr (attribute == AttributeNames::posY) {
94 return getR()[1];
95 } else if constexpr (attribute == AttributeNames::posZ) {
96 return getR()[2];
97 } else if constexpr (attribute == AttributeNames::velocityX) {
98 return getV()[0];
99 } else if constexpr (attribute == AttributeNames::velocityY) {
100 return getV()[1];
101 } else if constexpr (attribute == AttributeNames::velocityZ) {
102 return getV()[2];
103 } else if constexpr (attribute == AttributeNames::forceX) {
104 return getF()[0];
105 } else if constexpr (attribute == AttributeNames::forceY) {
106 return getF()[1];
107 } else if constexpr (attribute == AttributeNames::forceZ) {
108 return getF()[2];
109 } else if constexpr (attribute == AttributeNames::oldForceX) {
110 return getOldF()[0];
111 } else if constexpr (attribute == AttributeNames::oldForceY) {
112 return getOldF()[1];
113 } else if constexpr (attribute == AttributeNames::oldForceZ) {
114 return getOldF()[2];
115 } else if constexpr (attribute == AttributeNames::typeId) {
116 return getTypeId();
117 } else if constexpr (attribute == AttributeNames::ownershipState) {
118 return this->_ownershipState;
119 } else {
120 autopas::utils::ExceptionHandler::exception("MoleculeLJ::get() unknown attribute {}", attribute);
121 }
122 }
123
131 template <AttributeNames attribute>
132 constexpr void set(typename std::tuple_element<attribute, SoAArraysType>::type::value_type value) {
133 if constexpr (attribute == AttributeNames::id) {
134 setID(value);
135 } else if constexpr (attribute == AttributeNames::posX) {
136 _r[0] = value;
137 } else if constexpr (attribute == AttributeNames::posY) {
138 _r[1] = value;
139 } else if constexpr (attribute == AttributeNames::posZ) {
140 _r[2] = value;
141 } else if constexpr (attribute == AttributeNames::velocityX) {
142 _v[0] = value;
143 } else if constexpr (attribute == AttributeNames::velocityY) {
144 _v[1] = value;
145 } else if constexpr (attribute == AttributeNames::velocityZ) {
146 _v[2] = value;
147 } else if constexpr (attribute == AttributeNames::forceX) {
148 _f[0] = value;
149 } else if constexpr (attribute == AttributeNames::forceY) {
150 _f[1] = value;
151 } else if constexpr (attribute == AttributeNames::forceZ) {
152 _f[2] = value;
153 } else if constexpr (attribute == AttributeNames::oldForceX) {
154 _oldF[0] = value;
155 } else if constexpr (attribute == AttributeNames::oldForceY) {
156 _oldF[1] = value;
157 } else if constexpr (attribute == AttributeNames::oldForceZ) {
158 _oldF[2] = value;
159 } else if constexpr (attribute == AttributeNames::typeId) {
160 setTypeId(value);
161 } else if constexpr (attribute == AttributeNames::ownershipState) {
162 this->_ownershipState = value;
163 } else {
164 autopas::utils::ExceptionHandler::exception("MoleculeLJ::set() unknown attribute {}", attribute);
165 }
166 }
167
172 [[nodiscard]] const std::array<double, 3> &getOldF() const;
173
178 void setOldF(const std::array<double, 3> &oldForce);
179
184 [[nodiscard]] size_t getTypeId() const;
185
190 void setTypeId(size_t typeId);
191
196 [[nodiscard]] std::string toString() const override;
197
198 protected:
206 size_t _typeId = 0;
207
211 std::array<double, 3> _oldF = {0., 0., 0.};
212};
213
214} // namespace mdLib
Minimal definition of a basic particle.
Definition: ParticleBase.h:33
void setID(idType id)
Set the id of the particle.
Definition: ParticleBase.h:171
std::array< floatType, 3 > _r
Particle position as 3D coordinates.
Definition: ParticleBase.h:78
OwnershipState _ownershipState
Defines the state of the ownership of the particle.
Definition: ParticleBase.h:105
std::array< floatType, 3 > _f
Force the particle experiences as 3D vector.
Definition: ParticleBase.h:95
idType getID() const
Get the id of the particle.
Definition: ParticleBase.h:165
const std::array< double, 3 > & getV() const
Get the velocity of the particle.
Definition: ParticleBase.h:265
std::array< floatType, 3 > _v
Particle velocity as 3D vector.
Definition: ParticleBase.h:90
const std::array< double, 3 > & getF() const
get the force acting on the particle
Definition: ParticleBase.h:135
const std::array< double, 3 > & getR() const
Get the position of the particle.
Definition: ParticleBase.h:177
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
Molecule class for the LJFunctor.
Definition: MoleculeLJ.h:20
size_t getTypeId() const
Get TypeId.
Definition: MoleculeLJ.cpp:17
constexpr void set(typename std::tuple_element< attribute, SoAArraysType >::type::value_type value)
Setter, which allows set an attribute using the corresponding attribute name (defined in AttributeNam...
Definition: MoleculeLJ.h:132
constexpr std::tuple_element< attribute, SoAArraysType >::type::value_type get()
Non-const getter for the pointer of this object.
Definition: MoleculeLJ.h:77
std::string toString() const override
Creates a string containing all data of the particle.
Definition: MoleculeLJ.cpp:20
typename autopas::utils::SoAType< MoleculeLJ *, size_t, double, double, double, double, double, double, double, double, double, double, double, double, size_t, autopas::OwnershipState >::Type SoAArraysType
The type for the SoA storage.
Definition: MoleculeLJ.h:69
void setOldF(const std::array< double, 3 > &oldForce)
Set old force.
Definition: MoleculeLJ.cpp:15
AttributeNames
Enums used as ids for accessing and creating a dynamically sized SoA.
Definition: MoleculeLJ.h:39
const std::array< double, 3 > & getOldF() const
Get the old force.
Definition: MoleculeLJ.cpp:14
std::array< double, 3 > _oldF
Old Force of the particle experiences as 3D vector.
Definition: MoleculeLJ.h:211
constexpr std::tuple_element< attribute, SoAArraysType >::type::value_type get() const
Getter, which allows access to an attribute using the corresponding attribute name (defined in Attrib...
Definition: MoleculeLJ.h:88
void setTypeId(size_t typeId)
Set the type id of the Molecule.
Definition: MoleculeLJ.cpp:18
size_t _typeId
Molecule type id.
Definition: MoleculeLJ.h:206
OwnershipState
Enum that specifies the state of ownership.
Definition: OwnershipState.h:19
Helper struct to get a the SoAType.
Definition: SoAType.h:23