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