Emdee
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
atom.h
Go to the documentation of this file.
1 #ifndef ATOM_H
2 #define ATOM_H
3 
4 // Local includes
5 #include <atomtype.h>
6 #include <math/vector3.h>
7 
8 // System includes
9 //#include <armadillo>
10 #include <vector>
11 #include <forward_list>
12 #ifdef USE_MPI
13 #include <boost/serialization/serialization.hpp>
14 #endif
15 
16 //using namespace arma;
17 using namespace std;
18 
19 class TwoParticleForce;
20 class Atom
21 {
22  friend class TwoParticleForce;
23 public:
24  inline Atom();
25  inline Atom(const AtomType &atomType);
26 
27  inline void clearForcePotentialPressure();
28 
29  inline void clearDisplacement();
30 
31  inline const Vector3 &position() const;
32  inline const Vector3 &velocity() const;
33  inline const Vector3 &force() const;
34  inline const Vector3& displacement() const;
35  inline const AtomType &type() const;
36 // inline const int atomTypeId() const;
37  inline double potential() const;
38  inline double localPressure() const;
39  inline int cellID() const;
40  inline int id() const;
41  inline double mass() const;
42  inline void addLocalPressure(double pressure);
43  inline void addForce(int component, double force);
44 
45 // inline void setAtomTypeId(int atomTypeId);
46  inline void setPosition(const Vector3 &position);
47  inline void setVelocity(const Vector3 &velocity);
48  inline void addForce(const Vector3 &force);
49  inline void addPotential(double potential);
50  inline void setCellID(int cellID);
51  inline void addDisplacement(const Vector3& displacement);
52  inline void addDisplacement(double displacement, uint component);
53 
54  inline void setForce(const Vector3 &force);
55 
56  void clone(const Atom &other);
57  inline void communicationClone(const Atom &other, const vector<AtomType>& moleculeSystem);
58 
59  inline bool isPositionFixed();
60  inline void setPositionFixed(bool fixed);
61 
62  inline void setID(int id);
63 
64  const std::vector<std::pair<Atom *, Vector3 *> > &neighborAtoms();
65  void clearNeighborAtoms();
66  void addNeighborAtom(Atom *neighborAtom, Vector3 *offsetVector);
67 
68  void setAtomType(const AtomType& atomType);
69 protected:
74  double m_potential;
76 
77  int m_cellID;
79 
81  int m_id;
83 
84  std::vector<std::pair<Atom *, Vector3 *> > m_neighborAtoms;
85 
86 private:
87 #ifdef USE_MPI
88  friend class boost::serialization::access;
89  template<class Archive>
90  void serialize(Archive & ar, const unsigned int );
91 #endif
92 };
93 
94 #ifdef USE_MPI
95 BOOST_CLASS_IMPLEMENTATION(Atom,object_serializable)
96 BOOST_IS_BITWISE_SERIALIZABLE(Atom)
97 BOOST_IS_MPI_DATATYPE(Atom)
98 BOOST_CLASS_TRACKING(Atom,track_never)
99 #endif
100 
101 // Inlined constructors
102 inline Atom::Atom() :
103  m_position(Vector3::createZeros()),
104  m_force(Vector3::createZeros()),
105  m_velocity(Vector3::createZeros()),
106  m_displacement(Vector3::createZeros()),
107  m_potential(0.0),
108  m_localPressure(0.0),
109  m_cellID(-999),
110 // m_type(AtomType::argon()),
111  m_isPositionFixed(false),
112  m_id(-1),
113  m_atomTypeIndex(-1)
114 {
115 }
116 
117 inline Atom::Atom(const AtomType &atomType) :
118  m_position(Vector3::createZeros()),
119  m_force(Vector3::createZeros()),
120  m_velocity(Vector3::createZeros()),
121  m_displacement(Vector3::createZeros()),
122  m_potential(0.0),
123  m_localPressure(0.0),
124  m_cellID(-999),
125  m_atomType(atomType),
126  m_isPositionFixed(false),
127  m_id(-1),
128  m_atomTypeIndex(atomType.index())
129 {
130 }
131 
132 #ifdef USE_MPI
133 template<class Archive>
134 inline void Atom::serialize(Archive & ar, const unsigned int)
135 {
136  ar & m_position;
137  ar & m_velocity;
138  ar & m_id;
139  ar & m_atomTypeIndex;
140  // ar & m_force;
141 // ar & m_displacement;
142  // ar & m_mass;
143  // ar & m_potential;
144  // ar & m_localPressure;
145  // ar & m_cellID;
146  // ar & m_type;
147 }
148 #endif
149 // Inlined functions
150 inline void Atom::addForce(int component, double force)
151 {
152  m_force(component) += force;
153 }
154 
155 //inline void Atom::setAtomTypeId(int atomTypeId)
156 //{
157 // m_atomTypeId = atomTypeId;
158 //}
159 
160 inline void Atom::addDisplacement(double displacement, uint component) {
161  m_displacement(component) += displacement;
162 }
163 
164 inline void Atom::addDisplacement(const Vector3& displacement) {
166 }
167 
168 inline void Atom::setCellID(int cellID)
169 {
170  m_cellID = cellID;
171 }
172 inline void Atom::addPotential(double potential) {
174 }
175 inline void Atom::addForce(const Vector3 &force)
176 {
177  m_force += force;
178 }
179 
180 inline void Atom::setForce(const Vector3 &force) {
181  m_force = force;
182 }
183 
184 inline void Atom::setID(int id) {
185  m_id = id;
186 }
187 
188 inline int Atom::id() const {
189  return m_id;
190 }
191 
192 inline void Atom::setVelocity(const Vector3 &velocity)
193 {
195 }
196 
197 inline void Atom::setPosition(const Vector3 &position)
198 {
199  m_displacement += (position - m_position);
201 }
202 
203 inline void Atom::addLocalPressure(double pressure) {
204  m_localPressure += pressure;
205 }
206 
207 inline double Atom::mass() const
208 {
209  return type().mass();
210 }
211 
212 inline int Atom::cellID() const
213 {
214  return m_cellID;
215 }
216 inline double Atom::localPressure() const
217 {
218  return m_localPressure;
219 }
220 inline double Atom::potential() const
221 {
222  return m_potential;
223 }
224 
225 inline const Vector3 &Atom::position() const
226 {
227  return m_position;
228 }
229 inline const Vector3 &Atom::velocity() const
230 {
231  return m_velocity;
232 }
233 inline const Vector3 &Atom::force() const
234 {
235  return m_force;
236 }
237 inline const Vector3& Atom::displacement() const
238 {
239  return m_displacement;
240 }
241 inline const AtomType& Atom::type() const
242 {
243  return m_atomType;
244 }
245 
246 inline void Atom::communicationClone(const Atom &other, const vector<AtomType>& particleTypes)
247 {
248  this->m_id = other.m_id;
249  this->m_position = other.m_position;
250  this->m_velocity = other.m_velocity;
251  this->m_atomTypeIndex = other.m_atomTypeIndex;
252  this->m_atomType = particleTypes[other.m_atomTypeIndex];
253 }
254 
255 inline bool Atom::isPositionFixed() {
256  return m_isPositionFixed;
257 }
258 
259 inline void Atom::setPositionFixed(bool fixed)
260 {
261  m_isPositionFixed = fixed;
262 }
263 
265 {
266  m_force.zeros();
267  m_potential = 0;
268  m_localPressure = 0;
269 }
270 
271 inline void Atom::clearDisplacement() {
273 }
274 
275 #endif // ATOM_H