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