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