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