| [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 |  | 
|---|
| [435065] | 32 | #include <iomanip> | 
|---|
|  | 33 |  | 
|---|
| [6b919f8] | 34 | /** Constructor of class AtomInfo. | 
|---|
|  | 35 | */ | 
|---|
| [97b825] | 36 | AtomInfo::AtomInfo() : | 
|---|
| [6625c3] | 37 | AtomicElement(NULL), | 
|---|
|  | 38 | FixedIon(false) | 
|---|
| [54b42e] | 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 | }; | 
|---|
| [d74077] | 47 |  | 
|---|
|  | 48 | /** Copy constructor of class AtomInfo. | 
|---|
|  | 49 | */ | 
|---|
| [97b825] | 50 | AtomInfo::AtomInfo(const AtomInfo &_atom) : | 
|---|
|  | 51 | AtomicPosition(_atom.AtomicPosition), | 
|---|
| [6625c3] | 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 | }; | 
|---|
| [d74077] | 60 |  | 
|---|
| [97b825] | 61 | AtomInfo::AtomInfo(const VectorInterface &_v) : | 
|---|
| [6625c3] | 62 | AtomicElement(NULL), | 
|---|
|  | 63 | FixedIon(false) | 
|---|
| [54b42e] | 64 | { | 
|---|
|  | 65 | AtomicPosition[0] = _v.getPosition(); | 
|---|
| [6625c3] | 66 | AtomicVelocity.reserve(1); | 
|---|
|  | 67 | AtomicVelocity.push_back(zeroVec); | 
|---|
|  | 68 | AtomicForce.reserve(1); | 
|---|
|  | 69 | AtomicForce.push_back(zeroVec); | 
|---|
| [54b42e] | 70 | }; | 
|---|
| [6b919f8] | 71 |  | 
|---|
|  | 72 | /** Destructor of class AtomInfo. | 
|---|
|  | 73 | */ | 
|---|
|  | 74 | AtomInfo::~AtomInfo() | 
|---|
|  | 75 | { | 
|---|
|  | 76 | }; | 
|---|
|  | 77 |  | 
|---|
| [e2373df] | 78 | void AtomInfo::AppendTrajectoryStep() | 
|---|
|  | 79 | { | 
|---|
|  | 80 | AtomicPosition.push_back(zeroVec); | 
|---|
|  | 81 | AtomicVelocity.push_back(zeroVec); | 
|---|
|  | 82 | AtomicForce.push_back(zeroVec); | 
|---|
| [fb9eba] | 83 | LOG(5,"AtomInfo::AppendTrajectoryStep() called, size is (" | 
|---|
|  | 84 | << AtomicPosition.size() << "," | 
|---|
|  | 85 | << AtomicVelocity.size() << "," | 
|---|
|  | 86 | << AtomicForce.size() << ")"); | 
|---|
| [e2373df] | 87 | } | 
|---|
|  | 88 |  | 
|---|
| [d74077] | 89 | const element *AtomInfo::getType() const | 
|---|
|  | 90 | { | 
|---|
|  | 91 | return AtomicElement; | 
|---|
|  | 92 | } | 
|---|
|  | 93 |  | 
|---|
|  | 94 | const double& AtomInfo::operator[](size_t i) const | 
|---|
|  | 95 | { | 
|---|
| [1b558c] | 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]; | 
|---|
| [d74077] | 101 | } | 
|---|
|  | 102 |  | 
|---|
|  | 103 | const double& AtomInfo::at(size_t i) const | 
|---|
|  | 104 | { | 
|---|
| [1b558c] | 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); | 
|---|
| [d74077] | 110 | } | 
|---|
|  | 111 |  | 
|---|
| [6b020f] | 112 | const double& AtomInfo::atStep(size_t i, unsigned int _step) const | 
|---|
| [056e70] | 113 | { | 
|---|
|  | 114 | ASSERT(AtomicPosition.size() > _step, | 
|---|
| [1b558c] | 115 | "AtomInfo::atStep() - Access out of range: " | 
|---|
|  | 116 | +toString(_step) | 
|---|
|  | 117 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [056e70] | 118 | return AtomicPosition[_step].at(i); | 
|---|
|  | 119 | } | 
|---|
|  | 120 |  | 
|---|
| [d74077] | 121 | void AtomInfo::set(size_t i, const double value) | 
|---|
|  | 122 | { | 
|---|
| [7188b1] | 123 | OBSERVE; | 
|---|
|  | 124 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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; | 
|---|
| [d74077] | 130 | } | 
|---|
|  | 131 |  | 
|---|
|  | 132 | const Vector& AtomInfo::getPosition() const | 
|---|
|  | 133 | { | 
|---|
| [1b558c] | 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()]; | 
|---|
| [f16a4b] | 139 | } | 
|---|
|  | 140 |  | 
|---|
| [6b020f] | 141 | const Vector& AtomInfo::getPositionAtStep(const unsigned int _step) const | 
|---|
| [6625c3] | 142 | { | 
|---|
|  | 143 | ASSERT(_step < AtomicPosition.size(), | 
|---|
| [1b558c] | 144 | "AtomInfo::getPositionAtStep() - Access out of range: " | 
|---|
|  | 145 | +toString(_step) | 
|---|
|  | 146 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 147 | return AtomicPosition[_step]; | 
|---|
|  | 148 | } | 
|---|
|  | 149 |  | 
|---|
| [7188b1] | 150 | void AtomInfo::setType(const element* _type) | 
|---|
|  | 151 | { | 
|---|
|  | 152 | OBSERVE; | 
|---|
|  | 153 | NOTIFY(AtomObservable::ElementChanged); | 
|---|
| [d74077] | 154 | AtomicElement = _type; | 
|---|
| [f16a4b] | 155 | } | 
|---|
|  | 156 |  | 
|---|
| [7188b1] | 157 | void AtomInfo::setType(const int Z) | 
|---|
|  | 158 | { | 
|---|
|  | 159 | OBSERVE; | 
|---|
|  | 160 | NOTIFY(AtomObservable::ElementChanged); | 
|---|
| [ead4e6] | 161 | const element *elem = World::getInstance().getPeriode()->FindElement(Z); | 
|---|
| [f16a4b] | 162 | setType(elem); | 
|---|
|  | 163 | } | 
|---|
| [d74077] | 164 |  | 
|---|
| [056e70] | 165 | //Vector& AtomInfo::getAtomicVelocity() | 
|---|
|  | 166 | //{ | 
|---|
|  | 167 | //  return AtomicVelocity[0]; | 
|---|
|  | 168 | //} | 
|---|
| [bce72c] | 169 |  | 
|---|
| [056e70] | 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 | //} | 
|---|
| [6625c3] | 176 |  | 
|---|
| [bce72c] | 177 | const Vector& AtomInfo::getAtomicVelocity() const | 
|---|
|  | 178 | { | 
|---|
| [056e70] | 179 | ASSERT(AtomicVelocity.size() > 0, | 
|---|
| [1b558c] | 180 | "AtomInfo::getAtomicVelocity() - Access out of range: " | 
|---|
|  | 181 | +toString(WorldTime::getTime()) | 
|---|
|  | 182 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
|  | 183 | return AtomicVelocity[WorldTime::getTime()]; | 
|---|
| [bce72c] | 184 | } | 
|---|
|  | 185 |  | 
|---|
| [6b020f] | 186 | const Vector& AtomInfo::getAtomicVelocityAtStep(const unsigned int _step) const | 
|---|
| [6625c3] | 187 | { | 
|---|
|  | 188 | ASSERT(_step < AtomicVelocity.size(), | 
|---|
| [1b558c] | 189 | "AtomInfo::getAtomicVelocity() - Access out of range: " | 
|---|
|  | 190 | +toString(_step) | 
|---|
|  | 191 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 192 | return AtomicVelocity[_step]; | 
|---|
|  | 193 | } | 
|---|
|  | 194 |  | 
|---|
| [bce72c] | 195 | void AtomInfo::setAtomicVelocity(const Vector &_newvelocity) | 
|---|
|  | 196 | { | 
|---|
| [7188b1] | 197 | OBSERVE; | 
|---|
|  | 198 | NOTIFY(AtomObservable::VelocityChanged); | 
|---|
| [1b558c] | 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; | 
|---|
| [bce72c] | 204 | } | 
|---|
|  | 205 |  | 
|---|
| [6b020f] | 206 | void AtomInfo::setAtomicVelocityAtStep(const unsigned int _step, const Vector &_newvelocity) | 
|---|
| [6625c3] | 207 | { | 
|---|
| [7188b1] | 208 | OBSERVE; | 
|---|
|  | 209 | if (WorldTime::getTime() == _step) | 
|---|
|  | 210 | NOTIFY(AtomObservable::VelocityChanged); | 
|---|
| [1b558c] | 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) { | 
|---|
| [6625c3] | 217 | AtomicVelocity[_step] = _newvelocity; | 
|---|
| [1b558c] | 218 | } else if (_step == size) { | 
|---|
| [e2373df] | 219 | UpdateSteps(); | 
|---|
|  | 220 | AtomicVelocity[_step] = _newvelocity; | 
|---|
| [6625c3] | 221 | } | 
|---|
|  | 222 | } | 
|---|
|  | 223 |  | 
|---|
| [bce72c] | 224 | const Vector& AtomInfo::getAtomicForce() const | 
|---|
|  | 225 | { | 
|---|
| [1b558c] | 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()]; | 
|---|
| [bce72c] | 231 | } | 
|---|
|  | 232 |  | 
|---|
| [6b020f] | 233 | const Vector& AtomInfo::getAtomicForceAtStep(const unsigned int _step) const | 
|---|
| [6625c3] | 234 | { | 
|---|
|  | 235 | ASSERT(_step < AtomicForce.size(), | 
|---|
| [1b558c] | 236 | "AtomInfo::getAtomicForce() - Access out of range: " | 
|---|
|  | 237 | +toString(_step) | 
|---|
|  | 238 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 239 | return AtomicForce[_step]; | 
|---|
|  | 240 | } | 
|---|
|  | 241 |  | 
|---|
| [bce72c] | 242 | void AtomInfo::setAtomicForce(const Vector &_newforce) | 
|---|
|  | 243 | { | 
|---|
| [7188b1] | 244 | OBSERVE; | 
|---|
|  | 245 | NOTIFY(AtomObservable::VelocityChanged); | 
|---|
| [1b558c] | 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; | 
|---|
| [bce72c] | 251 | } | 
|---|
|  | 252 |  | 
|---|
| [6b020f] | 253 | void AtomInfo::setAtomicForceAtStep(const unsigned int _step, const Vector &_newforce) | 
|---|
| [6625c3] | 254 | { | 
|---|
| [7188b1] | 255 | OBSERVE; | 
|---|
|  | 256 | if (WorldTime::getTime() == _step) | 
|---|
|  | 257 | NOTIFY(AtomObservable::VelocityChanged); | 
|---|
| [6b020f] | 258 | const unsigned int size = AtomicForce.size(); | 
|---|
| [056e70] | 259 | ASSERT(_step <= size, | 
|---|
| [1b558c] | 260 | "AtomInfo::setAtomicForce() - Access out of range: " | 
|---|
|  | 261 | +toString(_step) | 
|---|
|  | 262 | +" not in [0,"+toString(AtomicPosition.size())+"]."); | 
|---|
| [056e70] | 263 | if(_step < size) { | 
|---|
| [6625c3] | 264 | AtomicForce[_step] = _newforce; | 
|---|
| [056e70] | 265 | } else if (_step == size) { | 
|---|
| [e2373df] | 266 | UpdateSteps(); | 
|---|
|  | 267 | AtomicForce[_step] = _newforce; | 
|---|
| [6625c3] | 268 | } | 
|---|
|  | 269 | } | 
|---|
|  | 270 |  | 
|---|
|  | 271 | bool AtomInfo::getFixedIon() const | 
|---|
|  | 272 | { | 
|---|
|  | 273 | return FixedIon; | 
|---|
|  | 274 | } | 
|---|
|  | 275 |  | 
|---|
|  | 276 | void AtomInfo::setFixedIon(const bool _fixedion) | 
|---|
|  | 277 | { | 
|---|
| [7188b1] | 278 | OBSERVE; | 
|---|
|  | 279 | NOTIFY(AtomObservable::PropertyChanged); | 
|---|
| [6625c3] | 280 | FixedIon = _fixedion; | 
|---|
|  | 281 | } | 
|---|
|  | 282 |  | 
|---|
| [d74077] | 283 | void AtomInfo::setPosition(const Vector& _vector) | 
|---|
|  | 284 | { | 
|---|
| [7188b1] | 285 | OBSERVE; | 
|---|
|  | 286 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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; | 
|---|
| [d74077] | 292 | //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl; | 
|---|
|  | 293 | } | 
|---|
|  | 294 |  | 
|---|
| [6b020f] | 295 | void AtomInfo::setPositionAtStep(unsigned int _step, const Vector& _vector) | 
|---|
| [6625c3] | 296 | { | 
|---|
| [7188b1] | 297 | OBSERVE; | 
|---|
|  | 298 | if (WorldTime::getTime() == _step) | 
|---|
|  | 299 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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) { | 
|---|
| [6625c3] | 306 | AtomicPosition[_step] = _vector; | 
|---|
| [1b558c] | 307 | } else if (_step == size) { | 
|---|
| [e2373df] | 308 | UpdateSteps(); | 
|---|
|  | 309 | AtomicPosition[_step] = _vector; | 
|---|
| [6625c3] | 310 | } | 
|---|
|  | 311 | //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl; | 
|---|
|  | 312 | } | 
|---|
|  | 313 |  | 
|---|
| [d74077] | 314 | const VectorInterface& AtomInfo::operator+=(const Vector& b) | 
|---|
|  | 315 | { | 
|---|
| [7188b1] | 316 | OBSERVE; | 
|---|
|  | 317 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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; | 
|---|
| [d74077] | 323 | return *this; | 
|---|
|  | 324 | } | 
|---|
|  | 325 |  | 
|---|
|  | 326 | const VectorInterface& AtomInfo::operator-=(const Vector& b) | 
|---|
|  | 327 | { | 
|---|
| [7188b1] | 328 | OBSERVE; | 
|---|
|  | 329 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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; | 
|---|
| [d74077] | 335 | return *this; | 
|---|
|  | 336 | } | 
|---|
|  | 337 |  | 
|---|
|  | 338 | Vector const AtomInfo::operator+(const Vector& b) const | 
|---|
|  | 339 | { | 
|---|
| [1b558c] | 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()]); | 
|---|
| [d74077] | 345 | a += b; | 
|---|
|  | 346 | return a; | 
|---|
|  | 347 | } | 
|---|
|  | 348 |  | 
|---|
|  | 349 | Vector const AtomInfo::operator-(const Vector& b) const | 
|---|
|  | 350 | { | 
|---|
| [1b558c] | 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()]); | 
|---|
| [d74077] | 356 | a -= b; | 
|---|
|  | 357 | return a; | 
|---|
|  | 358 | } | 
|---|
|  | 359 |  | 
|---|
|  | 360 | double AtomInfo::distance(const Vector &point) const | 
|---|
|  | 361 | { | 
|---|
| [1b558c] | 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); | 
|---|
| [d74077] | 367 | } | 
|---|
|  | 368 |  | 
|---|
|  | 369 | double AtomInfo::DistanceSquared(const Vector &y) const | 
|---|
|  | 370 | { | 
|---|
| [1b558c] | 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); | 
|---|
| [d74077] | 376 | } | 
|---|
|  | 377 |  | 
|---|
|  | 378 | double AtomInfo::distance(const VectorInterface &_atom) const | 
|---|
|  | 379 | { | 
|---|
| [1b558c] | 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()]); | 
|---|
| [d74077] | 385 | } | 
|---|
|  | 386 |  | 
|---|
|  | 387 | double AtomInfo::DistanceSquared(const VectorInterface &_atom) const | 
|---|
|  | 388 | { | 
|---|
| [1b558c] | 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()]); | 
|---|
| [d74077] | 394 | } | 
|---|
|  | 395 |  | 
|---|
|  | 396 | VectorInterface &AtomInfo::operator=(const Vector& _vector) | 
|---|
|  | 397 | { | 
|---|
| [7188b1] | 398 | OBSERVE; | 
|---|
|  | 399 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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; | 
|---|
| [d74077] | 405 | return *this; | 
|---|
|  | 406 | } | 
|---|
|  | 407 |  | 
|---|
|  | 408 | void AtomInfo::ScaleAll(const double *factor) | 
|---|
|  | 409 | { | 
|---|
| [7188b1] | 410 | OBSERVE; | 
|---|
|  | 411 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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); | 
|---|
| [d74077] | 417 | } | 
|---|
|  | 418 |  | 
|---|
|  | 419 | void AtomInfo::ScaleAll(const Vector &factor) | 
|---|
|  | 420 | { | 
|---|
| [7188b1] | 421 | OBSERVE; | 
|---|
|  | 422 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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); | 
|---|
| [d74077] | 428 | } | 
|---|
|  | 429 |  | 
|---|
|  | 430 | void AtomInfo::Scale(const double factor) | 
|---|
|  | 431 | { | 
|---|
| [7188b1] | 432 | OBSERVE; | 
|---|
|  | 433 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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); | 
|---|
| [d74077] | 439 | } | 
|---|
|  | 440 |  | 
|---|
|  | 441 | void AtomInfo::Zero() | 
|---|
|  | 442 | { | 
|---|
| [7188b1] | 443 | OBSERVE; | 
|---|
|  | 444 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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(); | 
|---|
| [d74077] | 450 | } | 
|---|
|  | 451 |  | 
|---|
|  | 452 | void AtomInfo::One(const double one) | 
|---|
|  | 453 | { | 
|---|
| [7188b1] | 454 | OBSERVE; | 
|---|
|  | 455 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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); | 
|---|
| [d74077] | 461 | } | 
|---|
|  | 462 |  | 
|---|
|  | 463 | void AtomInfo::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors) | 
|---|
|  | 464 | { | 
|---|
| [7188b1] | 465 | OBSERVE; | 
|---|
|  | 466 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| [1b558c] | 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); | 
|---|
| [d74077] | 472 | } | 
|---|
|  | 473 |  | 
|---|
| [6625c3] | 474 | /** | 
|---|
|  | 475 | *  returns the kinetic energy of this atom at a given time step | 
|---|
|  | 476 | */ | 
|---|
| [7188b1] | 477 | double AtomInfo::getKineticEnergy(const unsigned int _step) const | 
|---|
|  | 478 | { | 
|---|
| [056e70] | 479 | ASSERT(_step < AtomicPosition.size(), | 
|---|
| [1b558c] | 480 | "AtomInfo::getKineticEnergy() - Access out of range: " | 
|---|
|  | 481 | +toString(WorldTime::getTime()) | 
|---|
|  | 482 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [056e70] | 483 | return getMass() * AtomicVelocity[_step].NormSquared(); | 
|---|
| [6625c3] | 484 | } | 
|---|
|  | 485 |  | 
|---|
| [7188b1] | 486 | Vector AtomInfo::getMomentum(const unsigned int _step) const | 
|---|
|  | 487 | { | 
|---|
| [056e70] | 488 | ASSERT(_step < AtomicPosition.size(), | 
|---|
| [1b558c] | 489 | "AtomInfo::getMomentum() - Access out of range: " | 
|---|
|  | 490 | +toString(WorldTime::getTime()) | 
|---|
|  | 491 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [056e70] | 492 | return getMass()*AtomicVelocity[_step]; | 
|---|
| [6625c3] | 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 | { | 
|---|
| [e2373df] | 501 | for (;AtomicPosition.size() <= (unsigned int)(MaxSteps);) | 
|---|
|  | 502 | UpdateSteps(); | 
|---|
|  | 503 | } | 
|---|
| [6625c3] | 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 | */ | 
|---|
| [6b020f] | 518 | void AtomInfo::CopyStepOnStep(const unsigned int dest, const unsigned int src) | 
|---|
| [6625c3] | 519 | { | 
|---|
|  | 520 | if (dest == src)  // self assignment check | 
|---|
|  | 521 | return; | 
|---|
|  | 522 |  | 
|---|
| [7188b1] | 523 | if (WorldTime::getTime() == dest){ | 
|---|
|  | 524 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
|  | 525 | NOTIFY(AtomObservable::VelocityChanged); | 
|---|
|  | 526 | NOTIFY(AtomObservable::ForceChanged); | 
|---|
|  | 527 | } | 
|---|
|  | 528 |  | 
|---|
| [6625c3] | 529 | ASSERT(dest < AtomicPosition.size(), | 
|---|
| [1b558c] | 530 | "AtomInfo::CopyStepOnStep() - destination outside of current trajectory array: " | 
|---|
|  | 531 | +toString(dest) | 
|---|
|  | 532 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 533 | ASSERT(src < AtomicPosition.size(), | 
|---|
| [1b558c] | 534 | "AtomInfo::CopyStepOnStep() - source outside of current trajectory array: " | 
|---|
|  | 535 | +toString(src) | 
|---|
|  | 536 | +" not in [0,"+toString(AtomicPosition.size())+")."); | 
|---|
| [6625c3] | 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 | 
|---|
| [435065] | 547 | * \param Deltat time step width | 
|---|
|  | 548 | * \param IsAngstroem whether the force's underlying unit of length is angstroem or bohr radii | 
|---|
| [6625c3] | 549 | * \param *Force matrix with forces | 
|---|
|  | 550 | */ | 
|---|
| [435065] | 551 | void AtomInfo::VelocityVerletUpdate(int nr, const unsigned int NextStep, double Deltat, bool IsAngstroem, ForceMatrix *Force, const size_t offset) | 
|---|
| [6625c3] | 552 | { | 
|---|
| [435065] | 553 | LOG(2, "INFO: Particle that currently " << *this); | 
|---|
|  | 554 | LOG(2, "INFO: Integrating with mass=" << getMass() << " and Deltat=" | 
|---|
|  | 555 | << Deltat << " at NextStep=" << NextStep); | 
|---|
| [056e70] | 556 | // update force | 
|---|
|  | 557 | // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a | 
|---|
|  | 558 | Vector tempVector; | 
|---|
| [435065] | 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); | 
|---|
| [056e70] | 571 | setAtomicForceAtStep(NextStep, tempVector); | 
|---|
|  | 572 |  | 
|---|
|  | 573 | // update position | 
|---|
|  | 574 | tempVector = getPositionAtStep(NextStep-1); | 
|---|
| [435065] | 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); | 
|---|
| [056e70] | 580 | setPositionAtStep(NextStep, tempVector); | 
|---|
| [435065] | 581 | LOG(3, "INFO: Position at step " << NextStep << " set to " << tempVector); | 
|---|
| [056e70] | 582 |  | 
|---|
| [6625c3] | 583 | // Update U | 
|---|
| [056e70] | 584 | tempVector = getAtomicVelocityAtStep(NextStep-1); | 
|---|
| [435065] | 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); | 
|---|
| [056e70] | 589 | setAtomicVelocityAtStep(NextStep, tempVector); | 
|---|
| [435065] | 590 | LOG(3, "INFO: Velocity at step " << NextStep << " set to " << tempVector); | 
|---|
| [6625c3] | 591 | }; | 
|---|
|  | 592 |  | 
|---|
| [fb0b62] | 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 | //} | 
|---|
| [d74077] | 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 | { | 
|---|
| [b1a5d9] | 620 | const size_t terminalstep = a.getTrajectorySize()-1; | 
|---|
| [e34254] | 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 | } | 
|---|
| [d74077] | 630 | return ost; | 
|---|
|  | 631 | } | 
|---|
|  | 632 |  | 
|---|