| 1 | /*
 | 
|---|
| 2 |  * atom_atominfo.hpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Oct 19, 2009
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #ifndef ATOM_ATOMINFO_HPP_
 | 
|---|
| 9 | #define ATOM_ATOMINFO_HPP_
 | 
|---|
| 10 | 
 | 
|---|
| 11 | 
 | 
|---|
| 12 | using namespace std;
 | 
|---|
| 13 | 
 | 
|---|
| 14 | /*********************************************** includes ***********************************/
 | 
|---|
| 15 | 
 | 
|---|
| 16 | // include config.h
 | 
|---|
| 17 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 18 | #include <config.h>
 | 
|---|
| 19 | #endif
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include <vector>
 | 
|---|
| 22 | 
 | 
|---|
| 23 | #include "atom_observable.hpp"
 | 
|---|
| 24 | 
 | 
|---|
| 25 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| 26 | #include "LinearAlgebra/VectorInterface.hpp"
 | 
|---|
| 27 | 
 | 
|---|
| 28 | /****************************************** forward declarations *****************************/
 | 
|---|
| 29 | 
 | 
|---|
| 30 | class AtomInfo;
 | 
|---|
| 31 | class element;
 | 
|---|
| 32 | class ForceMatrix;
 | 
|---|
| 33 | class RealSpaceMatrix;
 | 
|---|
| 34 | 
 | 
|---|
| 35 | /********************************************** declarations *******************************/
 | 
|---|
| 36 | 
 | 
|---|
| 37 | class AtomInfo : public VectorInterface, public virtual AtomObservable  {
 | 
|---|
| 38 | 
 | 
|---|
| 39 | public:
 | 
|---|
| 40 |   AtomInfo();
 | 
|---|
| 41 |   AtomInfo(const AtomInfo &_atom);
 | 
|---|
| 42 |   AtomInfo(const VectorInterface &_v);
 | 
|---|
| 43 |   virtual ~AtomInfo();
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   /** Pushes back another step in all trajectory vectors.
 | 
|---|
| 46 |    *
 | 
|---|
| 47 |    * This allows to extend all trajectories contained in different classes
 | 
|---|
| 48 |    * consistently. This is implemented by the topmost class which calls the
 | 
|---|
| 49 |    * real functions, \sa AppendTrajectoryStep(), by all necessary subclasses.
 | 
|---|
| 50 |    */
 | 
|---|
| 51 |   virtual void UpdateSteps()=0;
 | 
|---|
| 52 | 
 | 
|---|
| 53 |   /** Getter for AtomicElement.
 | 
|---|
| 54 |    *
 | 
|---|
| 55 |    * @return constant reference to AtomicElement
 | 
|---|
| 56 |    */
 | 
|---|
| 57 |   const element *getType() const;
 | 
|---|
| 58 |   /** Setter for AtomicElement.
 | 
|---|
| 59 |    *
 | 
|---|
| 60 |    * @param _type new element by pointer to set
 | 
|---|
| 61 |    */
 | 
|---|
| 62 |   void setType(const element *_type);
 | 
|---|
| 63 |   /** Setter for AtomicElement.
 | 
|---|
| 64 |    *
 | 
|---|
| 65 |    * @param _typenr new element by index to set
 | 
|---|
| 66 |    */
 | 
|---|
| 67 |   void setType(const int _typenr);
 | 
|---|
| 68 | 
 | 
|---|
| 69 |   /** Getter for AtomicVelocity.
 | 
|---|
| 70 |    *
 | 
|---|
| 71 |    * Current time step is used.
 | 
|---|
| 72 |    *
 | 
|---|
| 73 |    * @return constant reference to AtomicVelocity
 | 
|---|
| 74 |    */
 | 
|---|
| 75 | //  Vector& getAtomicVelocity();
 | 
|---|
| 76 |   /** Getter for AtomicVelocity.
 | 
|---|
| 77 |    *
 | 
|---|
| 78 |    * @param _step time step to return
 | 
|---|
| 79 |    * @return constant reference to AtomicVelocity
 | 
|---|
| 80 |    */
 | 
|---|
| 81 | //  Vector& getAtomicVelocity(const int _step);
 | 
|---|
| 82 |   /** Getter for AtomicVelocity.
 | 
|---|
| 83 |    *
 | 
|---|
| 84 |    * Current time step is used.
 | 
|---|
| 85 |    *
 | 
|---|
| 86 |    * @return constant reference to AtomicVelocity
 | 
|---|
| 87 |    */
 | 
|---|
| 88 |   const Vector& getAtomicVelocity() const;
 | 
|---|
| 89 |   /** Getter for AtomicVelocity.
 | 
|---|
| 90 |    *
 | 
|---|
| 91 |    * @param _step time step to return
 | 
|---|
| 92 |    * @return constant reference to AtomicVelocity
 | 
|---|
| 93 |    */
 | 
|---|
| 94 |   const Vector& getAtomicVelocityAtStep(const unsigned int _step) const;
 | 
|---|
| 95 |   /** Setter for AtomicVelocity.
 | 
|---|
| 96 |    *
 | 
|---|
| 97 |    * Current time step is used.
 | 
|---|
| 98 |    *
 | 
|---|
| 99 |    * @param _newvelocity new velocity to set
 | 
|---|
| 100 |    */
 | 
|---|
| 101 |   void setAtomicVelocity(const Vector &_newvelocity);
 | 
|---|
| 102 |   /** Setter for AtomicVelocity.
 | 
|---|
| 103 |    *
 | 
|---|
| 104 |    * @param _step time step to set
 | 
|---|
| 105 |    * @param _newvelocity new velocity to set
 | 
|---|
| 106 |    */
 | 
|---|
| 107 |   void setAtomicVelocityAtStep(const unsigned int _step, const Vector &_newvelocity);
 | 
|---|
| 108 | 
 | 
|---|
| 109 |   /** Getter for AtomicForce.
 | 
|---|
| 110 |    *
 | 
|---|
| 111 |    * Current time step is used.
 | 
|---|
| 112 |    *
 | 
|---|
| 113 |    * @return constant reference to AtomicForce
 | 
|---|
| 114 |    */
 | 
|---|
| 115 |   const Vector& getAtomicForce() const;
 | 
|---|
| 116 |   /** Getter for AtomicForce.
 | 
|---|
| 117 |    *
 | 
|---|
| 118 |    * @param _step time step to return
 | 
|---|
| 119 |    * @return constant reference to AtomicForce
 | 
|---|
| 120 |    */
 | 
|---|
| 121 |   const Vector& getAtomicForceAtStep(const unsigned int _step) const;
 | 
|---|
| 122 |   /** Setter for AtomicForce.
 | 
|---|
| 123 |    *
 | 
|---|
| 124 |    * Current time step is used.
 | 
|---|
| 125 |    *
 | 
|---|
| 126 |    * @param _newvelocity new force vector to set
 | 
|---|
| 127 |    */
 | 
|---|
| 128 |   void setAtomicForce(const Vector &_newforce);
 | 
|---|
| 129 |   /** Setter for AtomicForce.
 | 
|---|
| 130 |    *
 | 
|---|
| 131 |    * @param _step time step to set
 | 
|---|
| 132 |    * @param _newvelocity new force vector to set
 | 
|---|
| 133 |    */
 | 
|---|
| 134 |   void setAtomicForceAtStep(const unsigned int _step, const Vector &_newforce);
 | 
|---|
| 135 | 
 | 
|---|
| 136 |   /** Getter for FixedIon.
 | 
|---|
| 137 |    *
 | 
|---|
| 138 |    * @return constant reference to FixedIon
 | 
|---|
| 139 |    */
 | 
|---|
| 140 |   bool getFixedIon() const;
 | 
|---|
| 141 |   /** Setter for FixedIon.
 | 
|---|
| 142 |    *
 | 
|---|
| 143 |    * @param _fixedion new state of FixedIon
 | 
|---|
| 144 |    */
 | 
|---|
| 145 |   void setFixedIon(const bool _fixedion);
 | 
|---|
| 146 | 
 | 
|---|
| 147 |   ///// manipulation of the atomic position
 | 
|---|
| 148 | 
 | 
|---|
| 149 |   // Accessors ussually come in pairs... and sometimes even more than that
 | 
|---|
| 150 |   /** Getter for AtomicPosition.
 | 
|---|
| 151 |    *
 | 
|---|
| 152 |    * Current time step is used.
 | 
|---|
| 153 |    *
 | 
|---|
| 154 |    * @param i component of vector
 | 
|---|
| 155 |    * @return i-th component of atomic position
 | 
|---|
| 156 |    */
 | 
|---|
| 157 |   const double& operator[](size_t i) const;
 | 
|---|
| 158 |   /** Getter for AtomicPosition.
 | 
|---|
| 159 |    *
 | 
|---|
| 160 |    * Current time step is used.
 | 
|---|
| 161 |    *
 | 
|---|
| 162 |    * \sa operator[], this is if instance is a reference.
 | 
|---|
| 163 |    *
 | 
|---|
| 164 |    * @param i component of vector
 | 
|---|
| 165 |    * @return i-th component of atomic position
 | 
|---|
| 166 |    */
 | 
|---|
| 167 |   const double& at(size_t i) const;
 | 
|---|
| 168 |   /** Getter for AtomicPosition.
 | 
|---|
| 169 |    *
 | 
|---|
| 170 |    * \sa operator[], this is if instance is a reference.
 | 
|---|
| 171 |    *
 | 
|---|
| 172 |    * @param i index of component of AtomicPosition
 | 
|---|
| 173 |    * @param _step time step to return
 | 
|---|
| 174 |    * @return atomic position at time step _step
 | 
|---|
| 175 |    */
 | 
|---|
| 176 |   const double& atStep(size_t i, unsigned int _step) const;
 | 
|---|
| 177 |   /** Setter for AtomicPosition.
 | 
|---|
| 178 |    *
 | 
|---|
| 179 |    * Current time step is used.
 | 
|---|
| 180 |    *
 | 
|---|
| 181 |    * @param i component to set
 | 
|---|
| 182 |    * @param value value to set to
 | 
|---|
| 183 |    */
 | 
|---|
| 184 |   void set(size_t i, const double value);
 | 
|---|
| 185 |   /** Setter for AtomicPosition.
 | 
|---|
| 186 |    *
 | 
|---|
| 187 |    * @param i component to set
 | 
|---|
| 188 |    * @param _step time step to set
 | 
|---|
| 189 |    * @param value value to set to
 | 
|---|
| 190 |    */
 | 
|---|
| 191 |   void setAtStep(size_t i, unsigned int _step, const double value);
 | 
|---|
| 192 |   /** Getter for AtomicPosition.
 | 
|---|
| 193 |    *
 | 
|---|
| 194 |    * Current time step is used.
 | 
|---|
| 195 |    *
 | 
|---|
| 196 |    * @return atomic position
 | 
|---|
| 197 |    */
 | 
|---|
| 198 |   const Vector& getPosition() const;
 | 
|---|
| 199 |   /** Getter for AtomicPosition.
 | 
|---|
| 200 |    *
 | 
|---|
| 201 |    * @param _step time step to return
 | 
|---|
| 202 |    * @return atomic position at time step _step
 | 
|---|
| 203 |    */
 | 
|---|
| 204 |   const Vector& getPositionAtStep(unsigned int _step) const;
 | 
|---|
| 205 | 
 | 
|---|
| 206 |   // Assignment operator
 | 
|---|
| 207 |   /** Setter for AtomicPosition.
 | 
|---|
| 208 |    *
 | 
|---|
| 209 |    * Current time step is used.
 | 
|---|
| 210 |    *
 | 
|---|
| 211 |    * @param _vector new position to set
 | 
|---|
| 212 |    */
 | 
|---|
| 213 |   void setPosition(const Vector& _vector);
 | 
|---|
| 214 |   /** Setter for AtomicPosition.
 | 
|---|
| 215 |    *
 | 
|---|
| 216 |    * @param _step time step to set
 | 
|---|
| 217 |    * @param _vector new position to set for time step _step
 | 
|---|
| 218 |    */
 | 
|---|
| 219 |   void setPositionAtStep(const unsigned int _step, const Vector& _vector);
 | 
|---|
| 220 |   class VectorInterface &operator=(const Vector& _vector);
 | 
|---|
| 221 | 
 | 
|---|
| 222 |   // operators for mathematical operations
 | 
|---|
| 223 |   const VectorInterface& operator+=(const Vector& b);
 | 
|---|
| 224 |   const VectorInterface& operator-=(const Vector& b);
 | 
|---|
| 225 |   Vector const operator+(const Vector& b) const;
 | 
|---|
| 226 |   Vector const operator-(const Vector& b) const;
 | 
|---|
| 227 | 
 | 
|---|
| 228 |   void Zero();
 | 
|---|
| 229 |   void One(const double one);
 | 
|---|
| 230 |   void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors);
 | 
|---|
| 231 | 
 | 
|---|
| 232 |   double distance(const Vector &point) const;
 | 
|---|
| 233 |   double DistanceSquared(const Vector &y) const;
 | 
|---|
| 234 |   double distance(const VectorInterface &_atom) const;
 | 
|---|
| 235 |   double DistanceSquared(const VectorInterface &_atom) const;
 | 
|---|
| 236 | 
 | 
|---|
| 237 |   void ScaleAll(const double *factor);
 | 
|---|
| 238 |   void ScaleAll(const Vector &factor);
 | 
|---|
| 239 |   void Scale(const double factor);
 | 
|---|
| 240 | 
 | 
|---|
| 241 |   // operations for trajectories
 | 
|---|
| 242 |   void ResizeTrajectory(size_t MaxSteps);
 | 
|---|
| 243 |   size_t getTrajectorySize() const;
 | 
|---|
| 244 |   void CopyStepOnStep(const unsigned int dest, const unsigned int src);
 | 
|---|
| 245 |   void VelocityVerletUpdate(int nr, const unsigned int NextStep, double Deltat, bool IsAngstroem, ForceMatrix *Force, const size_t offset);
 | 
|---|
| 246 |   double getKineticEnergy(const unsigned int step) const;
 | 
|---|
| 247 |   Vector getMomentum(const unsigned int step) const;
 | 
|---|
| 248 |   double getMass() const;
 | 
|---|
| 249 | 
 | 
|---|
| 250 |   std::ostream & operator << (std::ostream &ost) const;
 | 
|---|
| 251 | 
 | 
|---|
| 252 | protected:
 | 
|---|
| 253 |   /** Function used by this and inheriting classes to extend the trajectory
 | 
|---|
| 254 |    * vectors.
 | 
|---|
| 255 |    */
 | 
|---|
| 256 |   void AppendTrajectoryStep();
 | 
|---|
| 257 | 
 | 
|---|
| 258 |   // make these protected only such that deriving atom class still has full
 | 
|---|
| 259 |   // access needed for clone and alike
 | 
|---|
| 260 |   std::vector<Vector> AtomicPosition;       //!< coordinate vector of atom, giving last position within cell
 | 
|---|
| 261 |   std::vector<Vector> AtomicVelocity;       //!< velocity vector of atom, giving last velocity within cell
 | 
|---|
| 262 |   std::vector<Vector> AtomicForce;       //!< Force vector of atom, giving last force within cell
 | 
|---|
| 263 | 
 | 
|---|
| 264 | private:
 | 
|---|
| 265 |   const element *AtomicElement;  //!< pointing to element
 | 
|---|
| 266 |   bool FixedIon;
 | 
|---|
| 267 | };
 | 
|---|
| 268 | 
 | 
|---|
| 269 | std::ostream & operator << (std::ostream &ost, const AtomInfo &a);
 | 
|---|
| 270 | 
 | 
|---|
| 271 | //const AtomInfo& operator*=(AtomInfo& a, const double m);
 | 
|---|
| 272 | //AtomInfo const operator*(const AtomInfo& a, const double m);
 | 
|---|
| 273 | //AtomInfo const operator*(const double m, const AtomInfo& a);
 | 
|---|
| 274 | 
 | 
|---|
| 275 | #endif /* ATOM_ATOMINFO_HPP_ */
 | 
|---|