| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
|  | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [6b919f8] | 8 | /* | 
|---|
|  | 9 | * atom_atominfo.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: Oct 19, 2009 | 
|---|
|  | 12 | *      Author: heber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
| [bf3817] | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| [112b09] | 21 |  | 
|---|
| [6625c3] | 22 | #include "CodePatterns/Log.hpp" | 
|---|
|  | 23 | #include "CodePatterns/Verbose.hpp" | 
|---|
|  | 24 | #include "config.hpp" | 
|---|
|  | 25 | #include "element.hpp" | 
|---|
|  | 26 | #include "parser.hpp" | 
|---|
| [f16a4b] | 27 | #include "periodentafel.hpp" | 
|---|
|  | 28 | #include "World.hpp" | 
|---|
| [1b558c] | 29 | #include "WorldTime.hpp" | 
|---|
| [6b919f8] | 30 | #include "atom_atominfo.hpp" | 
|---|
|  | 31 |  | 
|---|
|  | 32 | /** Constructor of class AtomInfo. | 
|---|
|  | 33 | */ | 
|---|
| [97b825] | 34 | AtomInfo::AtomInfo() : | 
|---|
| [6625c3] | 35 | AtomicElement(NULL), | 
|---|
|  | 36 | FixedIon(false) | 
|---|
| [54b42e] | 37 | { | 
|---|
|  | 38 | AtomicPosition.reserve(1); | 
|---|
|  | 39 | AtomicPosition.push_back(zeroVec); | 
|---|
|  | 40 | AtomicVelocity.reserve(1); | 
|---|
|  | 41 | AtomicVelocity.push_back(zeroVec); | 
|---|
|  | 42 | AtomicForce.reserve(1); | 
|---|
|  | 43 | AtomicForce.push_back(zeroVec); | 
|---|
|  | 44 | }; | 
|---|
| [d74077] | 45 |  | 
|---|
|  | 46 | /** Copy constructor of class AtomInfo. | 
|---|
|  | 47 | */ | 
|---|
| [97b825] | 48 | AtomInfo::AtomInfo(const AtomInfo &_atom) : | 
|---|
|  | 49 | AtomicPosition(_atom.AtomicPosition), | 
|---|
| [6625c3] | 50 | AtomicElement(_atom.AtomicElement), | 
|---|
|  | 51 | FixedIon(false) | 
|---|
|  | 52 | { | 
|---|
|  | 53 | AtomicVelocity.reserve(1); | 
|---|
|  | 54 | AtomicVelocity.push_back(zeroVec); | 
|---|
|  | 55 | AtomicForce.reserve(1); | 
|---|
|  | 56 | AtomicForce.push_back(zeroVec); | 
|---|
|  | 57 | }; | 
|---|
| [d74077] | 58 |  | 
|---|
| [97b825] | 59 | AtomInfo::AtomInfo(const VectorInterface &_v) : | 
|---|
| [6625c3] | 60 | AtomicElement(NULL), | 
|---|
|  | 61 | FixedIon(false) | 
|---|
| [54b42e] | 62 | { | 
|---|
|  | 63 | AtomicPosition[0] = _v.getPosition(); | 
|---|
| [6625c3] | 64 | AtomicVelocity.reserve(1); | 
|---|
|  | 65 | AtomicVelocity.push_back(zeroVec); | 
|---|
|  | 66 | AtomicForce.reserve(1); | 
|---|
|  | 67 | AtomicForce.push_back(zeroVec); | 
|---|
| [54b42e] | 68 | }; | 
|---|
| [6b919f8] | 69 |  | 
|---|
|  | 70 | /** Destructor of class AtomInfo. | 
|---|
|  | 71 | */ | 
|---|
|  | 72 | AtomInfo::~AtomInfo() | 
|---|
|  | 73 | { | 
|---|
|  | 74 | }; | 
|---|
|  | 75 |  | 
|---|
| [e2373df] | 76 | void AtomInfo::AppendTrajectoryStep() | 
|---|
|  | 77 | { | 
|---|
|  | 78 | AtomicPosition.push_back(zeroVec); | 
|---|
|  | 79 | AtomicVelocity.push_back(zeroVec); | 
|---|
|  | 80 | AtomicForce.push_back(zeroVec); | 
|---|
| [fb9eba] | 81 | LOG(5,"AtomInfo::AppendTrajectoryStep() called, size is (" | 
|---|
|  | 82 | << AtomicPosition.size() << "," | 
|---|
|  | 83 | << AtomicVelocity.size() << "," | 
|---|
|  | 84 | << AtomicForce.size() << ")"); | 
|---|
| [e2373df] | 85 | } | 
|---|
|  | 86 |  | 
|---|
| [d74077] | 87 | const element *AtomInfo::getType() const | 
|---|
|  | 88 | { | 
|---|
|  | 89 | return AtomicElement; | 
|---|
|  | 90 | } | 
|---|
|  | 91 |  | 
|---|
|  | 92 | const double& AtomInfo::operator[](size_t i) const | 
|---|
|  | 93 | { | 
|---|
| [1b558c] | 94 | ASSERT(AtomicPosition.size() > WorldTime::getTime(), | 
|---|
|  | 95 | "AtomInfo::operator[]() - Access out of range: " | 
|---|
|  | 96 | +toString(WorldTime::getTime()) | 
|---|
|  | 97 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 98 | return AtomicPosition[WorldTime::getTime()][i]; | 
|---|
| [d74077] | 99 | } | 
|---|
|  | 100 |  | 
|---|
|  | 101 | const double& AtomInfo::at(size_t i) const | 
|---|
|  | 102 | { | 
|---|
| [1b558c] | 103 | ASSERT(AtomicPosition.size() > WorldTime::getTime(), | 
|---|
|  | 104 | "AtomInfo::at() - Access out of range: " | 
|---|
|  | 105 | +toString(WorldTime::getTime()) | 
|---|
|  | 106 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 107 | return AtomicPosition[WorldTime::getTime()].at(i); | 
|---|
| [d74077] | 108 | } | 
|---|
|  | 109 |  | 
|---|
| [6b020f] | 110 | const double& AtomInfo::atStep(size_t i, unsigned int _step) const | 
|---|
| [056e70] | 111 | { | 
|---|
|  | 112 | ASSERT(AtomicPosition.size() > _step, | 
|---|
| [1b558c] | 113 | "AtomInfo::atStep() - Access out of range: " | 
|---|
|  | 114 | +toString(_step) | 
|---|
|  | 115 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [056e70] | 116 | return AtomicPosition[_step].at(i); | 
|---|
|  | 117 | } | 
|---|
|  | 118 |  | 
|---|
| [d74077] | 119 | void AtomInfo::set(size_t i, const double value) | 
|---|
|  | 120 | { | 
|---|
| [1b558c] | 121 | ASSERT(AtomicPosition.size() > WorldTime::getTime(), | 
|---|
|  | 122 | "AtomInfo::set() - Access out of range: " | 
|---|
|  | 123 | +toString(WorldTime::getTime()) | 
|---|
|  | 124 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 125 | AtomicPosition[WorldTime::getTime()].at(i) = value; | 
|---|
| [d74077] | 126 | } | 
|---|
|  | 127 |  | 
|---|
|  | 128 | const Vector& AtomInfo::getPosition() const | 
|---|
|  | 129 | { | 
|---|
| [1b558c] | 130 | ASSERT(AtomicPosition.size() > WorldTime::getTime(), | 
|---|
|  | 131 | "AtomInfo::getPosition() - Access out of range: " | 
|---|
|  | 132 | +toString(WorldTime::getTime()) | 
|---|
|  | 133 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 134 | return AtomicPosition[WorldTime::getTime()]; | 
|---|
| [f16a4b] | 135 | } | 
|---|
|  | 136 |  | 
|---|
| [6b020f] | 137 | const Vector& AtomInfo::getPositionAtStep(const unsigned int _step) const | 
|---|
| [6625c3] | 138 | { | 
|---|
|  | 139 | ASSERT(_step < AtomicPosition.size(), | 
|---|
| [1b558c] | 140 | "AtomInfo::getPositionAtStep() - Access out of range: " | 
|---|
|  | 141 | +toString(_step) | 
|---|
|  | 142 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 143 | return AtomicPosition[_step]; | 
|---|
|  | 144 | } | 
|---|
|  | 145 |  | 
|---|
| [ead4e6] | 146 | void AtomInfo::setType(const element* _type) { | 
|---|
| [d74077] | 147 | AtomicElement = _type; | 
|---|
| [f16a4b] | 148 | } | 
|---|
|  | 149 |  | 
|---|
| [d74077] | 150 | void AtomInfo::setType(const int Z) { | 
|---|
| [ead4e6] | 151 | const element *elem = World::getInstance().getPeriode()->FindElement(Z); | 
|---|
| [f16a4b] | 152 | setType(elem); | 
|---|
|  | 153 | } | 
|---|
| [d74077] | 154 |  | 
|---|
| [056e70] | 155 | //Vector& AtomInfo::getAtomicVelocity() | 
|---|
|  | 156 | //{ | 
|---|
|  | 157 | //  return AtomicVelocity[0]; | 
|---|
|  | 158 | //} | 
|---|
| [bce72c] | 159 |  | 
|---|
| [056e70] | 160 | //Vector& AtomInfo::getAtomicVelocity(const int _step) | 
|---|
|  | 161 | //{ | 
|---|
|  | 162 | //  ASSERT(_step < AtomicVelocity.size(), | 
|---|
|  | 163 | //      "AtomInfo::getAtomicVelocity() - Access out of range."); | 
|---|
|  | 164 | //  return AtomicVelocity[_step]; | 
|---|
|  | 165 | //} | 
|---|
| [6625c3] | 166 |  | 
|---|
| [bce72c] | 167 | const Vector& AtomInfo::getAtomicVelocity() const | 
|---|
|  | 168 | { | 
|---|
| [056e70] | 169 | ASSERT(AtomicVelocity.size() > 0, | 
|---|
| [1b558c] | 170 | "AtomInfo::getAtomicVelocity() - Access out of range: " | 
|---|
|  | 171 | +toString(WorldTime::getTime()) | 
|---|
|  | 172 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 173 | return AtomicVelocity[WorldTime::getTime()]; | 
|---|
| [bce72c] | 174 | } | 
|---|
|  | 175 |  | 
|---|
| [6b020f] | 176 | const Vector& AtomInfo::getAtomicVelocityAtStep(const unsigned int _step) const | 
|---|
| [6625c3] | 177 | { | 
|---|
|  | 178 | ASSERT(_step < AtomicVelocity.size(), | 
|---|
| [1b558c] | 179 | "AtomInfo::getAtomicVelocity() - Access out of range: " | 
|---|
|  | 180 | +toString(_step) | 
|---|
|  | 181 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 182 | return AtomicVelocity[_step]; | 
|---|
|  | 183 | } | 
|---|
|  | 184 |  | 
|---|
| [bce72c] | 185 | void AtomInfo::setAtomicVelocity(const Vector &_newvelocity) | 
|---|
|  | 186 | { | 
|---|
| [1b558c] | 187 | ASSERT(WorldTime::getTime() < AtomicVelocity.size(), | 
|---|
|  | 188 | "AtomInfo::setAtomicVelocity() - Access out of range: " | 
|---|
|  | 189 | +toString(WorldTime::getTime()) | 
|---|
|  | 190 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 191 | AtomicVelocity[WorldTime::getTime()] = _newvelocity; | 
|---|
| [bce72c] | 192 | } | 
|---|
|  | 193 |  | 
|---|
| [6b020f] | 194 | void AtomInfo::setAtomicVelocityAtStep(const unsigned int _step, const Vector &_newvelocity) | 
|---|
| [6625c3] | 195 | { | 
|---|
| [1b558c] | 196 | const unsigned int size = AtomicVelocity.size(); | 
|---|
|  | 197 | ASSERT(_step <= size, | 
|---|
|  | 198 | "AtomInfo::setAtomicVelocityAtStep() - Access out of range: " | 
|---|
|  | 199 | +toString(_step) | 
|---|
|  | 200 | +" not in [0,"+toString(size)+"]."); | 
|---|
|  | 201 | if(_step < size) { | 
|---|
| [6625c3] | 202 | AtomicVelocity[_step] = _newvelocity; | 
|---|
| [1b558c] | 203 | } else if (_step == size) { | 
|---|
| [e2373df] | 204 | UpdateSteps(); | 
|---|
|  | 205 | AtomicVelocity[_step] = _newvelocity; | 
|---|
| [6625c3] | 206 | } | 
|---|
|  | 207 | } | 
|---|
|  | 208 |  | 
|---|
| [bce72c] | 209 | const Vector& AtomInfo::getAtomicForce() const | 
|---|
|  | 210 | { | 
|---|
| [1b558c] | 211 | ASSERT(WorldTime::getTime() < AtomicForce.size(), | 
|---|
|  | 212 | "AtomInfo::getAtomicForce() - Access out of range: " | 
|---|
|  | 213 | +toString(WorldTime::getTime()) | 
|---|
|  | 214 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 215 | return AtomicForce[WorldTime::getTime()]; | 
|---|
| [bce72c] | 216 | } | 
|---|
|  | 217 |  | 
|---|
| [6b020f] | 218 | const Vector& AtomInfo::getAtomicForceAtStep(const unsigned int _step) const | 
|---|
| [6625c3] | 219 | { | 
|---|
|  | 220 | ASSERT(_step < AtomicForce.size(), | 
|---|
| [1b558c] | 221 | "AtomInfo::getAtomicForce() - Access out of range: " | 
|---|
|  | 222 | +toString(_step) | 
|---|
|  | 223 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 224 | return AtomicForce[_step]; | 
|---|
|  | 225 | } | 
|---|
|  | 226 |  | 
|---|
| [bce72c] | 227 | void AtomInfo::setAtomicForce(const Vector &_newforce) | 
|---|
|  | 228 | { | 
|---|
| [1b558c] | 229 | ASSERT(WorldTime::getTime() < AtomicForce.size(), | 
|---|
|  | 230 | "AtomInfo::setAtomicForce() - Access out of range: " | 
|---|
|  | 231 | +toString(WorldTime::getTime()) | 
|---|
|  | 232 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 233 | AtomicForce[WorldTime::getTime()] = _newforce; | 
|---|
| [bce72c] | 234 | } | 
|---|
|  | 235 |  | 
|---|
| [6b020f] | 236 | void AtomInfo::setAtomicForceAtStep(const unsigned int _step, const Vector &_newforce) | 
|---|
| [6625c3] | 237 | { | 
|---|
| [6b020f] | 238 | const unsigned int size = AtomicForce.size(); | 
|---|
| [056e70] | 239 | ASSERT(_step <= size, | 
|---|
| [1b558c] | 240 | "AtomInfo::setAtomicForce() - Access out of range: " | 
|---|
|  | 241 | +toString(_step) | 
|---|
|  | 242 | +" not in [0,"+toString(AtomicPosition.size())+"]."); | 
|---|
| [056e70] | 243 | if(_step < size) { | 
|---|
| [6625c3] | 244 | AtomicForce[_step] = _newforce; | 
|---|
| [056e70] | 245 | } else if (_step == size) { | 
|---|
| [e2373df] | 246 | UpdateSteps(); | 
|---|
|  | 247 | AtomicForce[_step] = _newforce; | 
|---|
| [6625c3] | 248 | } | 
|---|
|  | 249 | } | 
|---|
|  | 250 |  | 
|---|
|  | 251 | bool AtomInfo::getFixedIon() const | 
|---|
|  | 252 | { | 
|---|
|  | 253 | return FixedIon; | 
|---|
|  | 254 | } | 
|---|
|  | 255 |  | 
|---|
|  | 256 | void AtomInfo::setFixedIon(const bool _fixedion) | 
|---|
|  | 257 | { | 
|---|
|  | 258 | FixedIon = _fixedion; | 
|---|
|  | 259 | } | 
|---|
|  | 260 |  | 
|---|
| [d74077] | 261 | void AtomInfo::setPosition(const Vector& _vector) | 
|---|
|  | 262 | { | 
|---|
| [1b558c] | 263 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 264 | "AtomInfo::setPosition() - Access out of range: " | 
|---|
|  | 265 | +toString(WorldTime::getTime()) | 
|---|
|  | 266 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 267 | AtomicPosition[WorldTime::getTime()] = _vector; | 
|---|
| [d74077] | 268 | //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl; | 
|---|
|  | 269 | } | 
|---|
|  | 270 |  | 
|---|
| [6b020f] | 271 | void AtomInfo::setPositionAtStep(unsigned int _step, const Vector& _vector) | 
|---|
| [6625c3] | 272 | { | 
|---|
| [1b558c] | 273 | const unsigned int size = AtomicPosition.size(); | 
|---|
|  | 274 | ASSERT(_step <= size, | 
|---|
|  | 275 | "AtomInfo::setPosition() - Access out of range: " | 
|---|
|  | 276 | +toString(_step) | 
|---|
|  | 277 | +" not in [0,"+toString(size)+"]."); | 
|---|
|  | 278 | if(_step < size) { | 
|---|
| [6625c3] | 279 | AtomicPosition[_step] = _vector; | 
|---|
| [1b558c] | 280 | } else if (_step == size) { | 
|---|
| [e2373df] | 281 | UpdateSteps(); | 
|---|
|  | 282 | AtomicPosition[_step] = _vector; | 
|---|
| [6625c3] | 283 | } | 
|---|
|  | 284 | //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl; | 
|---|
|  | 285 | } | 
|---|
|  | 286 |  | 
|---|
| [d74077] | 287 | const VectorInterface& AtomInfo::operator+=(const Vector& b) | 
|---|
|  | 288 | { | 
|---|
| [1b558c] | 289 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 290 | "AtomInfo::operator+=() - Access out of range: " | 
|---|
|  | 291 | +toString(WorldTime::getTime()) | 
|---|
|  | 292 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 293 | AtomicPosition[WorldTime::getTime()] += b; | 
|---|
| [d74077] | 294 | return *this; | 
|---|
|  | 295 | } | 
|---|
|  | 296 |  | 
|---|
|  | 297 | const VectorInterface& AtomInfo::operator-=(const Vector& b) | 
|---|
|  | 298 | { | 
|---|
| [1b558c] | 299 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 300 | "AtomInfo::operator-=() - Access out of range: " | 
|---|
|  | 301 | +toString(WorldTime::getTime()) | 
|---|
|  | 302 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 303 | AtomicPosition[WorldTime::getTime()] -= b; | 
|---|
| [d74077] | 304 | return *this; | 
|---|
|  | 305 | } | 
|---|
|  | 306 |  | 
|---|
|  | 307 | Vector const AtomInfo::operator+(const Vector& b) const | 
|---|
|  | 308 | { | 
|---|
| [1b558c] | 309 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 310 | "AtomInfo::operator+() - Access out of range: " | 
|---|
|  | 311 | +toString(WorldTime::getTime()) | 
|---|
|  | 312 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 313 | Vector a(AtomicPosition[WorldTime::getTime()]); | 
|---|
| [d74077] | 314 | a += b; | 
|---|
|  | 315 | return a; | 
|---|
|  | 316 | } | 
|---|
|  | 317 |  | 
|---|
|  | 318 | Vector const AtomInfo::operator-(const Vector& b) const | 
|---|
|  | 319 | { | 
|---|
| [1b558c] | 320 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 321 | "AtomInfo::operator-() - Access out of range: " | 
|---|
|  | 322 | +toString(WorldTime::getTime()) | 
|---|
|  | 323 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 324 | Vector a(AtomicPosition[WorldTime::getTime()]); | 
|---|
| [d74077] | 325 | a -= b; | 
|---|
|  | 326 | return a; | 
|---|
|  | 327 | } | 
|---|
|  | 328 |  | 
|---|
|  | 329 | double AtomInfo::distance(const Vector &point) const | 
|---|
|  | 330 | { | 
|---|
| [1b558c] | 331 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 332 | "AtomInfo::distance() - Access out of range: " | 
|---|
|  | 333 | +toString(WorldTime::getTime()) | 
|---|
|  | 334 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 335 | return AtomicPosition[WorldTime::getTime()].distance(point); | 
|---|
| [d74077] | 336 | } | 
|---|
|  | 337 |  | 
|---|
|  | 338 | double AtomInfo::DistanceSquared(const Vector &y) const | 
|---|
|  | 339 | { | 
|---|
| [1b558c] | 340 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 341 | "AtomInfo::DistanceSquared() - Access out of range: " | 
|---|
|  | 342 | +toString(WorldTime::getTime()) | 
|---|
|  | 343 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 344 | return AtomicPosition[WorldTime::getTime()].DistanceSquared(y); | 
|---|
| [d74077] | 345 | } | 
|---|
|  | 346 |  | 
|---|
|  | 347 | double AtomInfo::distance(const VectorInterface &_atom) const | 
|---|
|  | 348 | { | 
|---|
| [1b558c] | 349 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 350 | "AtomInfo::distance() - Access out of range: " | 
|---|
|  | 351 | +toString(WorldTime::getTime()) | 
|---|
|  | 352 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 353 | return _atom.distance(AtomicPosition[WorldTime::getTime()]); | 
|---|
| [d74077] | 354 | } | 
|---|
|  | 355 |  | 
|---|
|  | 356 | double AtomInfo::DistanceSquared(const VectorInterface &_atom) const | 
|---|
|  | 357 | { | 
|---|
| [1b558c] | 358 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 359 | "AtomInfo::DistanceSquared() - Access out of range: " | 
|---|
|  | 360 | +toString(WorldTime::getTime()) | 
|---|
|  | 361 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 362 | return _atom.DistanceSquared(AtomicPosition[WorldTime::getTime()]); | 
|---|
| [d74077] | 363 | } | 
|---|
|  | 364 |  | 
|---|
|  | 365 | VectorInterface &AtomInfo::operator=(const Vector& _vector) | 
|---|
|  | 366 | { | 
|---|
| [1b558c] | 367 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 368 | "AtomInfo::operator=() - Access out of range: " | 
|---|
|  | 369 | +toString(WorldTime::getTime()) | 
|---|
|  | 370 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 371 | AtomicPosition[WorldTime::getTime()] = _vector; | 
|---|
| [d74077] | 372 | return *this; | 
|---|
|  | 373 | } | 
|---|
|  | 374 |  | 
|---|
|  | 375 | void AtomInfo::ScaleAll(const double *factor) | 
|---|
|  | 376 | { | 
|---|
| [1b558c] | 377 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 378 | "AtomInfo::ScaleAll() - Access out of range: " | 
|---|
|  | 379 | +toString(WorldTime::getTime()) | 
|---|
|  | 380 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 381 | AtomicPosition[WorldTime::getTime()].ScaleAll(factor); | 
|---|
| [d74077] | 382 | } | 
|---|
|  | 383 |  | 
|---|
|  | 384 | void AtomInfo::ScaleAll(const Vector &factor) | 
|---|
|  | 385 | { | 
|---|
| [1b558c] | 386 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 387 | "AtomInfo::ScaleAll() - Access out of range: " | 
|---|
|  | 388 | +toString(WorldTime::getTime()) | 
|---|
|  | 389 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 390 | AtomicPosition[WorldTime::getTime()].ScaleAll(factor); | 
|---|
| [d74077] | 391 | } | 
|---|
|  | 392 |  | 
|---|
|  | 393 | void AtomInfo::Scale(const double factor) | 
|---|
|  | 394 | { | 
|---|
| [1b558c] | 395 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 396 | "AtomInfo::Scale() - Access out of range: " | 
|---|
|  | 397 | +toString(WorldTime::getTime()) | 
|---|
|  | 398 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 399 | AtomicPosition[WorldTime::getTime()].Scale(factor); | 
|---|
| [d74077] | 400 | } | 
|---|
|  | 401 |  | 
|---|
|  | 402 | void AtomInfo::Zero() | 
|---|
|  | 403 | { | 
|---|
| [1b558c] | 404 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 405 | "AtomInfo::Zero() - Access out of range: " | 
|---|
|  | 406 | +toString(WorldTime::getTime()) | 
|---|
|  | 407 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 408 | AtomicPosition[WorldTime::getTime()].Zero(); | 
|---|
| [d74077] | 409 | } | 
|---|
|  | 410 |  | 
|---|
|  | 411 | void AtomInfo::One(const double one) | 
|---|
|  | 412 | { | 
|---|
| [1b558c] | 413 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 414 | "AtomInfo::One() - Access out of range: " | 
|---|
|  | 415 | +toString(WorldTime::getTime()) | 
|---|
|  | 416 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 417 | AtomicPosition[WorldTime::getTime()].One(one); | 
|---|
| [d74077] | 418 | } | 
|---|
|  | 419 |  | 
|---|
|  | 420 | void AtomInfo::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors) | 
|---|
|  | 421 | { | 
|---|
| [1b558c] | 422 | ASSERT(WorldTime::getTime() < AtomicPosition.size(), | 
|---|
|  | 423 | "AtomInfo::LinearCombinationOfVectors() - Access out of range: " | 
|---|
|  | 424 | +toString(WorldTime::getTime()) | 
|---|
|  | 425 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 426 | AtomicPosition[WorldTime::getTime()].LinearCombinationOfVectors(x1,x2,x3,factors); | 
|---|
| [d74077] | 427 | } | 
|---|
|  | 428 |  | 
|---|
| [6625c3] | 429 | /** | 
|---|
|  | 430 | *  returns the kinetic energy of this atom at a given time step | 
|---|
|  | 431 | */ | 
|---|
| [6b020f] | 432 | double AtomInfo::getKineticEnergy(const unsigned int _step) const{ | 
|---|
| [056e70] | 433 | ASSERT(_step < AtomicPosition.size(), | 
|---|
| [1b558c] | 434 | "AtomInfo::getKineticEnergy() - Access out of range: " | 
|---|
|  | 435 | +toString(WorldTime::getTime()) | 
|---|
|  | 436 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [056e70] | 437 | return getMass() * AtomicVelocity[_step].NormSquared(); | 
|---|
| [6625c3] | 438 | } | 
|---|
|  | 439 |  | 
|---|
| [6b020f] | 440 | Vector AtomInfo::getMomentum(const unsigned int _step) const{ | 
|---|
| [056e70] | 441 | ASSERT(_step < AtomicPosition.size(), | 
|---|
| [1b558c] | 442 | "AtomInfo::getMomentum() - Access out of range: " | 
|---|
|  | 443 | +toString(WorldTime::getTime()) | 
|---|
|  | 444 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [056e70] | 445 | return getMass()*AtomicVelocity[_step]; | 
|---|
| [6625c3] | 446 | } | 
|---|
|  | 447 |  | 
|---|
|  | 448 | /** Extends the trajectory STL vector to the new size. | 
|---|
|  | 449 | * Does nothing if \a MaxSteps is smaller than current size. | 
|---|
|  | 450 | * \param MaxSteps | 
|---|
|  | 451 | */ | 
|---|
|  | 452 | void AtomInfo::ResizeTrajectory(size_t MaxSteps) | 
|---|
|  | 453 | { | 
|---|
| [e2373df] | 454 | for (;AtomicPosition.size() <= (unsigned int)(MaxSteps);) | 
|---|
|  | 455 | UpdateSteps(); | 
|---|
|  | 456 | } | 
|---|
| [6625c3] | 457 |  | 
|---|
|  | 458 | size_t AtomInfo::getTrajectorySize() const | 
|---|
|  | 459 | { | 
|---|
|  | 460 | return AtomicPosition.size(); | 
|---|
|  | 461 | } | 
|---|
|  | 462 |  | 
|---|
|  | 463 | double AtomInfo::getMass() const{ | 
|---|
|  | 464 | return AtomicElement->getMass(); | 
|---|
|  | 465 | } | 
|---|
|  | 466 |  | 
|---|
|  | 467 | /** Copies a given trajectory step \a src onto another \a dest | 
|---|
|  | 468 | * \param dest index of destination step | 
|---|
|  | 469 | * \param src index of source step | 
|---|
|  | 470 | */ | 
|---|
| [6b020f] | 471 | void AtomInfo::CopyStepOnStep(const unsigned int dest, const unsigned int src) | 
|---|
| [6625c3] | 472 | { | 
|---|
|  | 473 | if (dest == src)  // self assignment check | 
|---|
|  | 474 | return; | 
|---|
|  | 475 |  | 
|---|
|  | 476 | ASSERT(dest < AtomicPosition.size(), | 
|---|
| [1b558c] | 477 | "AtomInfo::CopyStepOnStep() - destination outside of current trajectory array: " | 
|---|
|  | 478 | +toString(dest) | 
|---|
|  | 479 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 480 | ASSERT(src < AtomicPosition.size(), | 
|---|
| [1b558c] | 481 | "AtomInfo::CopyStepOnStep() - source outside of current trajectory array: " | 
|---|
|  | 482 | +toString(src) | 
|---|
|  | 483 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 484 | for (int n=NDIM;n--;) { | 
|---|
|  | 485 | AtomicPosition.at(dest)[n] = AtomicPosition.at(src)[n]; | 
|---|
|  | 486 | AtomicVelocity.at(dest)[n] = AtomicVelocity.at(src)[n]; | 
|---|
|  | 487 | AtomicForce.at(dest)[n] = AtomicForce.at(src)[n]; | 
|---|
|  | 488 | } | 
|---|
|  | 489 | }; | 
|---|
|  | 490 |  | 
|---|
|  | 491 | /** Performs a velocity verlet update of the trajectory. | 
|---|
|  | 492 | * Parameters are according to those in configuration class. | 
|---|
|  | 493 | * \param NextStep index of sequential step to set | 
|---|
|  | 494 | * \param *configuration pointer to configuration with parameters | 
|---|
|  | 495 | * \param *Force matrix with forces | 
|---|
|  | 496 | */ | 
|---|
| [6b020f] | 497 | void AtomInfo::VelocityVerletUpdate(int nr, const unsigned int NextStep, config *configuration, ForceMatrix *Force, const size_t offset) | 
|---|
| [6625c3] | 498 | { | 
|---|
| [056e70] | 499 | // update force | 
|---|
|  | 500 | // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a | 
|---|
|  | 501 | Vector tempVector; | 
|---|
|  | 502 | for (int d=0; d<NDIM; d++) | 
|---|
|  | 503 | tempVector[d] = -Force->Matrix[0][nr][d+offset]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.); | 
|---|
|  | 504 | setAtomicForceAtStep(NextStep, tempVector); | 
|---|
|  | 505 |  | 
|---|
|  | 506 | // update position | 
|---|
|  | 507 | tempVector = getPositionAtStep(NextStep-1); | 
|---|
|  | 508 | tempVector += configuration->Deltat*(getAtomicVelocityAtStep(NextStep-1));     // s(t) = s(0) + v * deltat + 1/2 a * deltat^2 | 
|---|
|  | 509 | tempVector += 0.5*configuration->Deltat*configuration->Deltat*(getAtomicForceAtStep(NextStep))*(1./getMass());     // F = m * a and s = | 
|---|
|  | 510 | setPositionAtStep(NextStep, tempVector); | 
|---|
|  | 511 |  | 
|---|
| [6625c3] | 512 | // Update U | 
|---|
| [056e70] | 513 | tempVector = getAtomicVelocityAtStep(NextStep-1); | 
|---|
|  | 514 | tempVector += configuration->Deltat * (getAtomicForceAtStep(NextStep)+getAtomicForceAtStep(NextStep-1))*(1./getMass()); // v = F/m * t | 
|---|
|  | 515 | setAtomicVelocityAtStep(NextStep, tempVector); | 
|---|
|  | 516 |  | 
|---|
|  | 517 | // some info for debugging | 
|---|
|  | 518 | DoLog(2) && (Log() << Verbose(2) | 
|---|
|  | 519 | << "Integrated position&velocity of step " << (NextStep) << ": (" | 
|---|
|  | 520 | << getPositionAtStep(NextStep) << ")\t(" | 
|---|
|  | 521 | << getAtomicVelocityAtStep(NextStep) << ")" << std::endl); | 
|---|
| [6625c3] | 522 | }; | 
|---|
|  | 523 |  | 
|---|
| [fb0b62] | 524 | //const AtomInfo& operator*=(AtomInfo& a, const double m) | 
|---|
|  | 525 | //{ | 
|---|
|  | 526 | //  a.Scale(m); | 
|---|
|  | 527 | //  return a; | 
|---|
|  | 528 | //} | 
|---|
|  | 529 | // | 
|---|
|  | 530 | //AtomInfo const operator*(const AtomInfo& a, const double m) | 
|---|
|  | 531 | //{ | 
|---|
|  | 532 | //  AtomInfo copy(a); | 
|---|
|  | 533 | //  copy *= m; | 
|---|
|  | 534 | //  return copy; | 
|---|
|  | 535 | //} | 
|---|
|  | 536 | // | 
|---|
|  | 537 | //AtomInfo const operator*(const double m, const AtomInfo& a) | 
|---|
|  | 538 | //{ | 
|---|
|  | 539 | //  AtomInfo copy(a); | 
|---|
|  | 540 | //  copy *= m; | 
|---|
|  | 541 | //  return copy; | 
|---|
|  | 542 | //} | 
|---|
| [d74077] | 543 |  | 
|---|
|  | 544 | std::ostream & AtomInfo::operator << (std::ostream &ost) const | 
|---|
|  | 545 | { | 
|---|
|  | 546 | return (ost << getPosition()); | 
|---|
|  | 547 | } | 
|---|
|  | 548 |  | 
|---|
|  | 549 | std::ostream & operator << (std::ostream &ost, const AtomInfo &a) | 
|---|
|  | 550 | { | 
|---|
| [b1a5d9] | 551 | const size_t terminalstep = a.getTrajectorySize()-1; | 
|---|
| [e34254] | 552 | if (terminalstep) { | 
|---|
|  | 553 | ost << "starts at " | 
|---|
|  | 554 | << a.getPositionAtStep(0) << " and ends at " | 
|---|
|  | 555 | << a.getPositionAtStep(terminalstep) | 
|---|
|  | 556 | << " at time step " << terminalstep; | 
|---|
|  | 557 | } else { | 
|---|
|  | 558 | ost << "is at " | 
|---|
|  | 559 | << a.getPositionAtStep(0) << " with a single time step only"; | 
|---|
|  | 560 | } | 
|---|
| [d74077] | 561 | return ost; | 
|---|
|  | 562 | } | 
|---|
|  | 563 |  | 
|---|