| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| 5 | * Copyright (C)  2014 Frederik Heber. All rights reserved. | 
|---|
| 6 | * | 
|---|
| 7 | * | 
|---|
| 8 | *   This file is part of MoleCuilder. | 
|---|
| 9 | * | 
|---|
| 10 | *    MoleCuilder is free software: you can redistribute it and/or modify | 
|---|
| 11 | *    it under the terms of the GNU General Public License as published by | 
|---|
| 12 | *    the Free Software Foundation, either version 2 of the License, or | 
|---|
| 13 | *    (at your option) any later version. | 
|---|
| 14 | * | 
|---|
| 15 | *    MoleCuilder is distributed in the hope that it will be useful, | 
|---|
| 16 | *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 17 | *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 18 | *    GNU General Public License for more details. | 
|---|
| 19 | * | 
|---|
| 20 | *    You should have received a copy of the GNU General Public License | 
|---|
| 21 | *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| 22 | */ | 
|---|
| 23 |  | 
|---|
| 24 | /* | 
|---|
| 25 | * atom_atominfo.cpp | 
|---|
| 26 | * | 
|---|
| 27 | *  Created on: Oct 19, 2009 | 
|---|
| 28 | *      Author: heber | 
|---|
| 29 | */ | 
|---|
| 30 |  | 
|---|
| 31 | // include config.h | 
|---|
| 32 | #ifdef HAVE_CONFIG_H | 
|---|
| 33 | #include <config.h> | 
|---|
| 34 | #endif | 
|---|
| 35 |  | 
|---|
| 36 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| 37 |  | 
|---|
| 38 | #include "CodePatterns/Verbose.hpp" | 
|---|
| 39 |  | 
|---|
| 40 | #include "atom_atominfo.hpp" | 
|---|
| 41 | #include "CodePatterns/Log.hpp" | 
|---|
| 42 | #include "config.hpp" | 
|---|
| 43 | #include "Element/element.hpp" | 
|---|
| 44 | #include "Element/periodentafel.hpp" | 
|---|
| 45 | #include "Fragmentation/ForceMatrix.hpp" | 
|---|
| 46 | #include "World.hpp" | 
|---|
| 47 | #include "WorldTime.hpp" | 
|---|
| 48 |  | 
|---|
| 49 | #include <iomanip> | 
|---|
| 50 |  | 
|---|
| 51 | /** Constructor of class AtomInfo. | 
|---|
| 52 | */ | 
|---|
| 53 | AtomInfo::AtomInfo() : | 
|---|
| 54 | AtomicElement(1), | 
|---|
| 55 | FixedIon(false), | 
|---|
| 56 | charge(0.) | 
|---|
| 57 | { | 
|---|
| 58 | AtomicPosition.insert( std::make_pair(0, zeroVec) ); | 
|---|
| 59 | AtomicVelocity.insert( std::make_pair(0, zeroVec) ); | 
|---|
| 60 | AtomicForce.insert( std::make_pair(0, zeroVec) ); | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | /** Copy constructor of class AtomInfo. | 
|---|
| 64 | */ | 
|---|
| 65 | AtomInfo::AtomInfo(const AtomInfo &_atom) : | 
|---|
| 66 | AtomicPosition(_atom.AtomicPosition), | 
|---|
| 67 | AtomicVelocity(_atom.AtomicVelocity), | 
|---|
| 68 | AtomicForce(_atom.AtomicForce), | 
|---|
| 69 | AtomicElement(_atom.AtomicElement), | 
|---|
| 70 | FixedIon(_atom.FixedIon), | 
|---|
| 71 | charge(_atom.charge) | 
|---|
| 72 | { | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | AtomInfo::AtomInfo(const VectorInterface &_v) : | 
|---|
| 76 | AtomicElement(1), | 
|---|
| 77 | FixedIon(false), | 
|---|
| 78 | charge(0.) | 
|---|
| 79 | { | 
|---|
| 80 | AtomicPosition.insert( std::make_pair(0, _v.getPosition()) ); | 
|---|
| 81 | AtomicVelocity.insert( std::make_pair(0, zeroVec) ); | 
|---|
| 82 | AtomicForce.insert( std::make_pair(0, zeroVec) ); | 
|---|
| 83 | }; | 
|---|
| 84 |  | 
|---|
| 85 | /** Destructor of class AtomInfo. | 
|---|
| 86 | */ | 
|---|
| 87 | AtomInfo::~AtomInfo() | 
|---|
| 88 | { | 
|---|
| 89 | }; | 
|---|
| 90 |  | 
|---|
| 91 | void AtomInfo::AppendTrajectoryStep(const unsigned int _step) | 
|---|
| 92 | { | 
|---|
| 93 | NOTIFY(TrajectoryChanged); | 
|---|
| 94 | AtomicPosition.insert( std::make_pair(_step, zeroVec) ); | 
|---|
| 95 | AtomicVelocity.insert( std::make_pair(_step, zeroVec) ); | 
|---|
| 96 | AtomicForce.insert( std::make_pair(_step, zeroVec) ); | 
|---|
| 97 | LOG(5,"AtomInfo::AppendTrajectoryStep() called, size is (" | 
|---|
| 98 | << AtomicPosition.size() << "," | 
|---|
| 99 | << AtomicVelocity.size() << "," | 
|---|
| 100 | << AtomicForce.size() << ")"); | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | void AtomInfo::eraseInTrajctory( | 
|---|
| 104 | VectorTrajectory_t &_trajectory, | 
|---|
| 105 | const unsigned int _firststep, const unsigned int _laststep) | 
|---|
| 106 | { | 
|---|
| 107 | const VectorTrajectory_t::iterator firstiter = _trajectory.lower_bound(_firststep); | 
|---|
| 108 | const VectorTrajectory_t::iterator lastiter = _trajectory.upper_bound(_laststep); | 
|---|
| 109 | _trajectory.erase(firstiter, lastiter); | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | void AtomInfo::removeTrajectorySteps(const unsigned int _firststep, const unsigned int _laststep) | 
|---|
| 113 | { | 
|---|
| 114 | NOTIFY(TrajectoryChanged); | 
|---|
| 115 | eraseInTrajctory(AtomicPosition, _firststep, _laststep); | 
|---|
| 116 | eraseInTrajctory(AtomicVelocity, _firststep, _laststep); | 
|---|
| 117 | eraseInTrajctory(AtomicForce, _firststep, _laststep); | 
|---|
| 118 | LOG(5,"AtomInfo::removeTrajectorySteps() called, size is (" | 
|---|
| 119 | << AtomicPosition.size() << "," | 
|---|
| 120 | << AtomicVelocity.size() << "," | 
|---|
| 121 | << AtomicForce.size() << ")"); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | const element *AtomInfo::getType() const | 
|---|
| 125 | { | 
|---|
| 126 | const element *elem = World::getInstance().getPeriode()->FindElement(AtomicElement); | 
|---|
| 127 | return elem; | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 | const element &AtomInfo::getElement() const | 
|---|
| 131 | { | 
|---|
| 132 | const element &elem = *World::getInstance().getPeriode()->FindElement(AtomicElement); | 
|---|
| 133 | return elem; | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | atomicNumber_t AtomInfo::getElementNo() const | 
|---|
| 137 | { | 
|---|
| 138 | return AtomicElement; | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 | const std::string &AtomInfo::getParticleName() const | 
|---|
| 142 | { | 
|---|
| 143 | return particlename; | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 | void AtomInfo::setParticleName(const std::string & _name) | 
|---|
| 147 | { | 
|---|
| 148 | particlename = _name; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | const double& AtomInfo::operator[](size_t i) const | 
|---|
| 152 | { | 
|---|
| 153 | return atStep(i, WorldTime::getTime()); | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | const double& AtomInfo::at(size_t i) const | 
|---|
| 157 | { | 
|---|
| 158 | return atStep(i, WorldTime::getTime()); | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 | const double& AtomInfo::atStep(size_t i, unsigned int _step) const | 
|---|
| 162 | { | 
|---|
| 163 | ASSERT(!AtomicPosition.empty(), | 
|---|
| 164 | "AtomInfo::operator[]() - AtomicPosition is empty."); | 
|---|
| 165 | VectorTrajectory_t::const_iterator iter = | 
|---|
| 166 | AtomicPosition.lower_bound(_step); | 
|---|
| 167 | return iter->second[i]; | 
|---|
| 168 | } | 
|---|
| 169 |  | 
|---|
| 170 | void AtomInfo::set(size_t i, const double value) | 
|---|
| 171 | { | 
|---|
| 172 | OBSERVE; | 
|---|
| 173 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| 174 | VectorTrajectory_t::iterator iter = AtomicPosition.find(WorldTime::getTime()); | 
|---|
| 175 | if (iter !=  AtomicPosition.end()) { | 
|---|
| 176 | iter->second[i] = value; | 
|---|
| 177 | } else { | 
|---|
| 178 | Vector newPos; | 
|---|
| 179 | newPos[i] = value; | 
|---|
| 180 | #ifndef NDEBUG | 
|---|
| 181 | std::pair<VectorTrajectory_t::iterator, bool> inserter = | 
|---|
| 182 | #endif | 
|---|
| 183 | AtomicPosition.insert( std::make_pair(WorldTime::getTime(), newPos) ); | 
|---|
| 184 | ASSERT( inserter.second, | 
|---|
| 185 | "AtomInfo::set() - time step "+toString(WorldTime::getTime()) | 
|---|
| 186 | +" present after all?"); | 
|---|
| 187 | } | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|
| 190 | void AtomInfo::setAtStep(size_t i, unsigned int _step, const double value) | 
|---|
| 191 | { | 
|---|
| 192 | OBSERVE; | 
|---|
| 193 | VectorTrajectory_t::iterator iter = AtomicPosition.find(_step); | 
|---|
| 194 | if (iter !=  AtomicPosition.end()) { | 
|---|
| 195 | iter->second[i] = value; | 
|---|
| 196 | } else { | 
|---|
| 197 | NOTIFY(TrajectoryChanged); | 
|---|
| 198 | Vector newPos; | 
|---|
| 199 | newPos[i] = value; | 
|---|
| 200 | #ifndef NDEBUG | 
|---|
| 201 | std::pair<VectorTrajectory_t::iterator, bool> inserter = | 
|---|
| 202 | #endif | 
|---|
| 203 | AtomicPosition.insert( std::make_pair(_step, newPos) ); | 
|---|
| 204 | ASSERT( inserter.second, | 
|---|
| 205 | "AtomInfo::setAtStep() - time step "+toString(_step) | 
|---|
| 206 | +" present after all?"); | 
|---|
| 207 | } | 
|---|
| 208 | if (WorldTime::getTime() == _step) | 
|---|
| 209 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| 210 | } | 
|---|
| 211 |  | 
|---|
| 212 | /** Helps to determine whether the current step really exists or getPosition() has just | 
|---|
| 213 | * delivered the one closest to it in the past. | 
|---|
| 214 | * | 
|---|
| 215 | * \param _step step to check | 
|---|
| 216 | * \param true - step exists, false - step does not exist, getPosition() delivers closest | 
|---|
| 217 | */ | 
|---|
| 218 | bool AtomInfo::isStepPresent(const unsigned int _step) const | 
|---|
| 219 | { | 
|---|
| 220 | VectorTrajectory_t::const_iterator iter = | 
|---|
| 221 | AtomicPosition.find(_step); | 
|---|
| 222 | return iter != AtomicPosition.end(); | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | const Vector& AtomInfo::getPosition() const | 
|---|
| 226 | { | 
|---|
| 227 | return getPositionAtStep(WorldTime::getTime()); | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|
| 230 | const Vector& AtomInfo::getPositionAtStep(const unsigned int _step) const | 
|---|
| 231 | { | 
|---|
| 232 | ASSERT(!AtomicPosition.empty(), | 
|---|
| 233 | "AtomInfo::operator[]() - AtomicPosition is empty."); | 
|---|
| 234 | VectorTrajectory_t::const_iterator iter = | 
|---|
| 235 | AtomicPosition.lower_bound(_step); | 
|---|
| 236 | return iter->second; | 
|---|
| 237 | } | 
|---|
| 238 |  | 
|---|
| 239 | void AtomInfo::setType(const element* _type) | 
|---|
| 240 | { | 
|---|
| 241 | OBSERVE; | 
|---|
| 242 | NOTIFY(AtomObservable::ElementChanged); | 
|---|
| 243 | AtomicElement = _type->getAtomicNumber(); | 
|---|
| 244 | } | 
|---|
| 245 |  | 
|---|
| 246 | void AtomInfo::setType(const int Z) | 
|---|
| 247 | { | 
|---|
| 248 | const element *elem = World::getInstance().getPeriode()->FindElement(Z); | 
|---|
| 249 | setType(elem); | 
|---|
| 250 | } | 
|---|
| 251 |  | 
|---|
| 252 | const Vector& AtomInfo::getAtomicVelocity() const | 
|---|
| 253 | { | 
|---|
| 254 | return getAtomicVelocityAtStep(WorldTime::getTime()); | 
|---|
| 255 | } | 
|---|
| 256 |  | 
|---|
| 257 | const Vector& AtomInfo::getAtomicVelocityAtStep(const unsigned int _step) const | 
|---|
| 258 | { | 
|---|
| 259 | ASSERT(!AtomicVelocity.empty(), | 
|---|
| 260 | "AtomInfo::operator[]() - AtomicVelocity is empty."); | 
|---|
| 261 | VectorTrajectory_t::const_iterator iter = | 
|---|
| 262 | AtomicVelocity.lower_bound(_step); | 
|---|
| 263 | // special, we only interpolate between present time steps not into the future | 
|---|
| 264 | if (_step > AtomicVelocity.begin()->first) | 
|---|
| 265 | return zeroVec; | 
|---|
| 266 | else | 
|---|
| 267 | return iter->second; | 
|---|
| 268 | } | 
|---|
| 269 |  | 
|---|
| 270 | void AtomInfo::setAtomicVelocity(const Vector &_newvelocity) | 
|---|
| 271 | { | 
|---|
| 272 | setAtomicVelocityAtStep(WorldTime::getTime(), _newvelocity); | 
|---|
| 273 | } | 
|---|
| 274 |  | 
|---|
| 275 | void AtomInfo::setAtomicVelocityAtStep(const unsigned int _step, const Vector &_newvelocity) | 
|---|
| 276 | { | 
|---|
| 277 | OBSERVE; | 
|---|
| 278 | VectorTrajectory_t::iterator iter = AtomicVelocity.find(_step); | 
|---|
| 279 | if (iter !=  AtomicVelocity.end()) { | 
|---|
| 280 | iter->second = _newvelocity; | 
|---|
| 281 | } else { | 
|---|
| 282 | NOTIFY(TrajectoryChanged); | 
|---|
| 283 | #ifndef NDEBUG | 
|---|
| 284 | std::pair<VectorTrajectory_t::iterator, bool> inserter = | 
|---|
| 285 | #endif | 
|---|
| 286 | AtomicVelocity.insert( std::make_pair(_step, _newvelocity) ); | 
|---|
| 287 | ASSERT( inserter.second, | 
|---|
| 288 | "AtomInfo::set() - time step "+toString(_step) | 
|---|
| 289 | +" present after all?"); | 
|---|
| 290 | } | 
|---|
| 291 | if (WorldTime::getTime() == _step) | 
|---|
| 292 | NOTIFY(AtomObservable::VelocityChanged); | 
|---|
| 293 | } | 
|---|
| 294 |  | 
|---|
| 295 | const Vector& AtomInfo::getAtomicForce() const | 
|---|
| 296 | { | 
|---|
| 297 | return getAtomicForceAtStep(WorldTime::getTime()); | 
|---|
| 298 | } | 
|---|
| 299 |  | 
|---|
| 300 | const Vector& AtomInfo::getAtomicForceAtStep(const unsigned int _step) const | 
|---|
| 301 | { | 
|---|
| 302 | ASSERT(!AtomicForce.empty(), | 
|---|
| 303 | "AtomInfo::operator[]() - AtomicForce is empty."); | 
|---|
| 304 | VectorTrajectory_t::const_iterator iter = | 
|---|
| 305 | AtomicForce.lower_bound(_step); | 
|---|
| 306 | // special, we only interpolate between present time steps not into the future | 
|---|
| 307 | if (_step > AtomicForce.begin()->first) | 
|---|
| 308 | return zeroVec; | 
|---|
| 309 | else | 
|---|
| 310 | return iter->second; | 
|---|
| 311 | } | 
|---|
| 312 |  | 
|---|
| 313 | void AtomInfo::setAtomicForce(const Vector &_newforce) | 
|---|
| 314 | { | 
|---|
| 315 | setAtomicForceAtStep(WorldTime::getTime(), _newforce); | 
|---|
| 316 | } | 
|---|
| 317 |  | 
|---|
| 318 | void AtomInfo::setAtomicForceAtStep(const unsigned int _step, const Vector &_newforce) | 
|---|
| 319 | { | 
|---|
| 320 | OBSERVE; | 
|---|
| 321 | VectorTrajectory_t::iterator iter = AtomicForce.find(_step); | 
|---|
| 322 | if (iter !=  AtomicForce.end()) { | 
|---|
| 323 | iter->second = _newforce; | 
|---|
| 324 | } else { | 
|---|
| 325 | NOTIFY(TrajectoryChanged); | 
|---|
| 326 | #ifndef NDEBUG | 
|---|
| 327 | std::pair<VectorTrajectory_t::iterator, bool> inserter = | 
|---|
| 328 | #endif | 
|---|
| 329 | AtomicForce.insert( std::make_pair(_step, _newforce) ); | 
|---|
| 330 | ASSERT( inserter.second, | 
|---|
| 331 | "AtomInfo::set() - time step "+toString(_step) | 
|---|
| 332 | +" present after all?"); | 
|---|
| 333 | } | 
|---|
| 334 | if (WorldTime::getTime() == _step) | 
|---|
| 335 | NOTIFY(AtomObservable::ForceChanged); | 
|---|
| 336 | } | 
|---|
| 337 |  | 
|---|
| 338 | bool AtomInfo::getFixedIon() const | 
|---|
| 339 | { | 
|---|
| 340 | return FixedIon; | 
|---|
| 341 | } | 
|---|
| 342 |  | 
|---|
| 343 | void AtomInfo::setFixedIon(const bool _fixedion) | 
|---|
| 344 | { | 
|---|
| 345 | OBSERVE; | 
|---|
| 346 | NOTIFY(AtomObservable::PropertyChanged); | 
|---|
| 347 | FixedIon = _fixedion; | 
|---|
| 348 | } | 
|---|
| 349 |  | 
|---|
| 350 | void AtomInfo::setPosition(const Vector& _vector) | 
|---|
| 351 | { | 
|---|
| 352 | setPositionAtStep(WorldTime::getTime(), _vector); | 
|---|
| 353 | } | 
|---|
| 354 |  | 
|---|
| 355 | void AtomInfo::setPositionAtStep(unsigned int _step, const Vector& _vector) | 
|---|
| 356 | { | 
|---|
| 357 | OBSERVE; | 
|---|
| 358 | VectorTrajectory_t::iterator iter = AtomicPosition.find(_step); | 
|---|
| 359 | if (iter !=  AtomicPosition.end()) { | 
|---|
| 360 | iter->second = _vector; | 
|---|
| 361 | } else { | 
|---|
| 362 | #ifndef NDEBUG | 
|---|
| 363 | std::pair<VectorTrajectory_t::iterator, bool> inserter = | 
|---|
| 364 | #endif | 
|---|
| 365 | AtomicPosition.insert( std::make_pair(_step, _vector) ); | 
|---|
| 366 | ASSERT( inserter.second, | 
|---|
| 367 | "AtomInfo::set() - time step "+toString(_step) | 
|---|
| 368 | +" present after all?"); | 
|---|
| 369 | } | 
|---|
| 370 | if (WorldTime::getTime() == _step) | 
|---|
| 371 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| 372 | } | 
|---|
| 373 |  | 
|---|
| 374 | const VectorInterface& AtomInfo::operator+=(const Vector& b) | 
|---|
| 375 | { | 
|---|
| 376 | setPosition(getPosition()+b); | 
|---|
| 377 | return *this; | 
|---|
| 378 | } | 
|---|
| 379 |  | 
|---|
| 380 | const VectorInterface& AtomInfo::operator-=(const Vector& b) | 
|---|
| 381 | { | 
|---|
| 382 | setPosition(getPosition()-b); | 
|---|
| 383 | return *this; | 
|---|
| 384 | } | 
|---|
| 385 |  | 
|---|
| 386 | Vector const AtomInfo::operator+(const Vector& b) const | 
|---|
| 387 | { | 
|---|
| 388 | Vector a(getPosition()); | 
|---|
| 389 | a += b; | 
|---|
| 390 | return a; | 
|---|
| 391 | } | 
|---|
| 392 |  | 
|---|
| 393 | Vector const AtomInfo::operator-(const Vector& b) const | 
|---|
| 394 | { | 
|---|
| 395 | Vector a(getPosition()); | 
|---|
| 396 | a -= b; | 
|---|
| 397 | return a; | 
|---|
| 398 | } | 
|---|
| 399 |  | 
|---|
| 400 | double AtomInfo::distance(const Vector &point) const | 
|---|
| 401 | { | 
|---|
| 402 | return getPosition().distance(point); | 
|---|
| 403 | } | 
|---|
| 404 |  | 
|---|
| 405 | double AtomInfo::DistanceSquared(const Vector &y) const | 
|---|
| 406 | { | 
|---|
| 407 | return getPosition().DistanceSquared(y); | 
|---|
| 408 | } | 
|---|
| 409 |  | 
|---|
| 410 | double AtomInfo::distance(const VectorInterface &_atom) const | 
|---|
| 411 | { | 
|---|
| 412 | return _atom.distance(getPosition()); | 
|---|
| 413 | } | 
|---|
| 414 |  | 
|---|
| 415 | double AtomInfo::DistanceSquared(const VectorInterface &_atom) const | 
|---|
| 416 | { | 
|---|
| 417 | return _atom.DistanceSquared(getPosition()); | 
|---|
| 418 | } | 
|---|
| 419 |  | 
|---|
| 420 | VectorInterface &AtomInfo::operator=(const Vector& _vector) | 
|---|
| 421 | { | 
|---|
| 422 | setPosition(_vector); | 
|---|
| 423 | return *this; | 
|---|
| 424 | } | 
|---|
| 425 |  | 
|---|
| 426 | void AtomInfo::ScaleAll(const double *factor) | 
|---|
| 427 | { | 
|---|
| 428 | Vector temp(getPosition()); | 
|---|
| 429 | temp.ScaleAll(factor); | 
|---|
| 430 | setPosition(temp); | 
|---|
| 431 | } | 
|---|
| 432 |  | 
|---|
| 433 | void AtomInfo::ScaleAll(const Vector &factor) | 
|---|
| 434 | { | 
|---|
| 435 | Vector temp(getPosition()); | 
|---|
| 436 | temp.ScaleAll(factor); | 
|---|
| 437 | setPosition(temp); | 
|---|
| 438 | } | 
|---|
| 439 |  | 
|---|
| 440 | void AtomInfo::Scale(const double factor) | 
|---|
| 441 | { | 
|---|
| 442 | Vector temp(getPosition()); | 
|---|
| 443 | temp.Scale(factor); | 
|---|
| 444 | setPosition(temp); | 
|---|
| 445 | } | 
|---|
| 446 |  | 
|---|
| 447 | void AtomInfo::Zero() | 
|---|
| 448 | { | 
|---|
| 449 | setPosition(zeroVec); | 
|---|
| 450 | } | 
|---|
| 451 |  | 
|---|
| 452 | void AtomInfo::One(const double one) | 
|---|
| 453 | { | 
|---|
| 454 | setPosition(Vector(one,one,one)); | 
|---|
| 455 | } | 
|---|
| 456 |  | 
|---|
| 457 | void AtomInfo::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors) | 
|---|
| 458 | { | 
|---|
| 459 | Vector newPos; | 
|---|
| 460 | newPos.LinearCombinationOfVectors(x1,x2,x3,factors); | 
|---|
| 461 | setPosition(newPos); | 
|---|
| 462 | } | 
|---|
| 463 |  | 
|---|
| 464 | /** | 
|---|
| 465 | *  returns the kinetic energy of this atom at a given time step | 
|---|
| 466 | */ | 
|---|
| 467 | double AtomInfo::getKineticEnergy(const unsigned int _step) const | 
|---|
| 468 | { | 
|---|
| 469 | return getMass() * getAtomicVelocityAtStep(_step).NormSquared(); | 
|---|
| 470 | } | 
|---|
| 471 |  | 
|---|
| 472 | Vector AtomInfo::getMomentum(const unsigned int _step) const | 
|---|
| 473 | { | 
|---|
| 474 | return getMass() * getAtomicVelocityAtStep(_step); | 
|---|
| 475 | } | 
|---|
| 476 |  | 
|---|
| 477 | Vector AtomInfo::getAcceleration(const unsigned int _step) const | 
|---|
| 478 | { | 
|---|
| 479 | return getMass() * getAtomicForceAtStep(_step); | 
|---|
| 480 | } | 
|---|
| 481 |  | 
|---|
| 482 | /** Decrease the trajectory if given \a MaxSteps is smaller. | 
|---|
| 483 | * Does nothing if \a MaxSteps is larger than current size. | 
|---|
| 484 | * | 
|---|
| 485 | * \param MaxSteps | 
|---|
| 486 | */ | 
|---|
| 487 | void AtomInfo::ResizeTrajectory(size_t MaxSteps) | 
|---|
| 488 | { | 
|---|
| 489 | // mind the reverse ordering due to std::greater, latest time steps are at beginning | 
|---|
| 490 | VectorTrajectory_t::iterator positer = AtomicPosition.lower_bound(MaxSteps); | 
|---|
| 491 | if (positer != AtomicPosition.begin()) { | 
|---|
| 492 | if (positer->first == MaxSteps) | 
|---|
| 493 | --positer; | 
|---|
| 494 | AtomicPosition.erase(AtomicPosition.begin(), positer); | 
|---|
| 495 | } | 
|---|
| 496 | VectorTrajectory_t::iterator veliter = AtomicVelocity.lower_bound(MaxSteps); | 
|---|
| 497 | if (veliter != AtomicVelocity.begin()) { | 
|---|
| 498 | if (veliter->first == MaxSteps) | 
|---|
| 499 | --veliter; | 
|---|
| 500 | AtomicVelocity.erase(AtomicVelocity.begin(), veliter); | 
|---|
| 501 | } | 
|---|
| 502 | VectorTrajectory_t::iterator forceiter = AtomicForce.lower_bound(MaxSteps); | 
|---|
| 503 | if (forceiter != AtomicForce.begin()) { | 
|---|
| 504 | if (forceiter->first == MaxSteps) | 
|---|
| 505 | --forceiter; | 
|---|
| 506 | AtomicForce.erase(AtomicForce.begin(), forceiter); | 
|---|
| 507 | } | 
|---|
| 508 | } | 
|---|
| 509 |  | 
|---|
| 510 | size_t AtomInfo::getTrajectorySize() const | 
|---|
| 511 | { | 
|---|
| 512 | // mind greater comp for map here: first element is latest in time steps! | 
|---|
| 513 | return AtomicPosition.begin()->first+1; | 
|---|
| 514 | } | 
|---|
| 515 |  | 
|---|
| 516 | double AtomInfo::getMass() const | 
|---|
| 517 | { | 
|---|
| 518 | return getType()->getMass(); | 
|---|
| 519 | } | 
|---|
| 520 |  | 
|---|
| 521 | /** Helper function to either insert or assign, depending on the element being | 
|---|
| 522 | * present already. | 
|---|
| 523 | * | 
|---|
| 524 | * \param _trajectory vector of Vectors to assign | 
|---|
| 525 | * \param dest step to insert/assign to | 
|---|
| 526 | * \param _newvalue new Vector value | 
|---|
| 527 | */ | 
|---|
| 528 | void assignTrajectoryElement( | 
|---|
| 529 | std::map<unsigned int, Vector, std::greater<unsigned int> > &_trajectory, | 
|---|
| 530 | const unsigned int dest, | 
|---|
| 531 | const Vector &_newvalue) | 
|---|
| 532 | { | 
|---|
| 533 | std::pair<std::map<unsigned int, Vector, std::greater<unsigned int> >::iterator, bool> inserter = | 
|---|
| 534 | _trajectory.insert( std::make_pair(dest, _newvalue) ); | 
|---|
| 535 | if (!inserter.second) | 
|---|
| 536 | inserter.first->second = _newvalue; | 
|---|
| 537 | } | 
|---|
| 538 |  | 
|---|
| 539 | /** Copies a given trajectory step \a src onto another \a dest | 
|---|
| 540 | * \param dest index of destination step | 
|---|
| 541 | * \param src index of source step | 
|---|
| 542 | */ | 
|---|
| 543 | void AtomInfo::CopyStepOnStep(const unsigned int dest, const unsigned int src) | 
|---|
| 544 | { | 
|---|
| 545 | if (dest == src)  // self assignment check | 
|---|
| 546 | return; | 
|---|
| 547 |  | 
|---|
| 548 | if (WorldTime::getTime() == dest){ | 
|---|
| 549 | NOTIFY(AtomObservable::PositionChanged); | 
|---|
| 550 | NOTIFY(AtomObservable::VelocityChanged); | 
|---|
| 551 | NOTIFY(AtomObservable::ForceChanged); | 
|---|
| 552 | } | 
|---|
| 553 |  | 
|---|
| 554 | VectorTrajectory_t::iterator positer = AtomicPosition.find(src); | 
|---|
| 555 | ASSERT( positer != AtomicPosition.end(), | 
|---|
| 556 | "AtomInfo::CopyStepOnStep() - step " | 
|---|
| 557 | +toString(src)+" to copy from not present in AtomicPosition."); | 
|---|
| 558 | assignTrajectoryElement(AtomicPosition, dest, positer->second); | 
|---|
| 559 | VectorTrajectory_t::iterator veliter = AtomicVelocity.find(src); | 
|---|
| 560 | if (veliter != AtomicVelocity.end()) | 
|---|
| 561 | assignTrajectoryElement(AtomicVelocity, dest, veliter->second); | 
|---|
| 562 | VectorTrajectory_t::iterator forceiter = AtomicForce.find(src); | 
|---|
| 563 | if (forceiter != AtomicForce.end()) | 
|---|
| 564 | assignTrajectoryElement(AtomicForce, dest, forceiter->second); | 
|---|
| 565 | }; | 
|---|
| 566 |  | 
|---|
| 567 | /** Performs a velocity verlet update of the position at \a NextStep from \a LastStep information only. | 
|---|
| 568 | * | 
|---|
| 569 | * We calculate \f$x(t + \delta t) = x(t) + v(t)* \delta t + .5 * \delta t * \delta t * F(t)/m \f$. | 
|---|
| 570 | * | 
|---|
| 571 | * | 
|---|
| 572 | * \param NextStep index of sequential step to set | 
|---|
| 573 | * \param Deltat time step width | 
|---|
| 574 | * \param IsAngstroem whether the force's underlying unit of length is angstroem or bohr radii | 
|---|
| 575 | */ | 
|---|
| 576 | void AtomInfo::VelocityVerletUpdateX(int nr, const unsigned int NextStep, double Deltat, bool IsAngstroem) | 
|---|
| 577 | { | 
|---|
| 578 | const unsigned int LastStep = NextStep == 0 ? 0 : NextStep-1; | 
|---|
| 579 |  | 
|---|
| 580 | LOG(2, "INFO: Particle that currently " << *this); | 
|---|
| 581 | LOG(2, "INFO: Integrating position with mass=" << getMass() << " and Deltat=" | 
|---|
| 582 | << Deltat << " at NextStep=" << NextStep); | 
|---|
| 583 |  | 
|---|
| 584 | // update position | 
|---|
| 585 | { | 
|---|
| 586 | Vector tempVector = getPositionAtStep(LastStep); | 
|---|
| 587 | LOG(4, "INFO: initial position from last step " << setprecision(4) << tempVector); | 
|---|
| 588 | tempVector += Deltat*(getAtomicVelocityAtStep(LastStep));     // s(t) = s(0) + v * deltat + 1/2 a * deltat^2 | 
|---|
| 589 | LOG(4, "INFO: position with velocity " << getAtomicVelocityAtStep(LastStep) << " from last step " << tempVector); | 
|---|
| 590 | tempVector += .5*Deltat*Deltat*(getAtomicForceAtStep(LastStep))*(1./getMass());     // F = m * a and s = | 
|---|
| 591 | LOG(4, "INFO: position with force " << getAtomicForceAtStep(LastStep) << " from last step " << tempVector); | 
|---|
| 592 | setPositionAtStep(NextStep, tempVector); | 
|---|
| 593 | LOG(3, "INFO: Position at step " << NextStep << " set to " << tempVector); | 
|---|
| 594 | } | 
|---|
| 595 | }; | 
|---|
| 596 |  | 
|---|
| 597 | /** Performs a velocity verlet update of the velocity at \a NextStep. | 
|---|
| 598 | * | 
|---|
| 599 | * \note forces at NextStep should have been calculated based on position at NextStep prior | 
|---|
| 600 | * to calling this function. | 
|---|
| 601 | * | 
|---|
| 602 | * We calculate \f$v(t) = v(t - \delta t) + \delta _t * .5 * (F(t - \delta t) + F(t))/m \f$. | 
|---|
| 603 | * | 
|---|
| 604 | * Parameters are according to those in configuration class. | 
|---|
| 605 | * \param NextStep index of sequential step to set | 
|---|
| 606 | * \param Deltat time step width | 
|---|
| 607 | * \param IsAngstroem whether the force's underlying unit of length is angstroem or bohr radii | 
|---|
| 608 | */ | 
|---|
| 609 | void AtomInfo::VelocityVerletUpdateU(int nr, const unsigned int NextStep, double Deltat, bool IsAngstroem) | 
|---|
| 610 | { | 
|---|
| 611 | const unsigned int LastStep = NextStep == 0 ? 0 : NextStep-1; | 
|---|
| 612 |  | 
|---|
| 613 | LOG(2, "INFO: Particle that currently " << *this); | 
|---|
| 614 | LOG(2, "INFO: Integrating velocity with mass=" << getMass() << " and Deltat=" | 
|---|
| 615 | << Deltat << " at NextStep=" << NextStep); | 
|---|
| 616 |  | 
|---|
| 617 | // Update U | 
|---|
| 618 | { | 
|---|
| 619 | Vector tempVector = getAtomicVelocityAtStep(LastStep); | 
|---|
| 620 | LOG(4, "INFO: initial velocity from last step " << tempVector); | 
|---|
| 621 | tempVector += Deltat * .5*(getAtomicForceAtStep(LastStep)+getAtomicForceAtStep(NextStep))*(1./getMass()); // v = F/m * t | 
|---|
| 622 | LOG(4, "INFO: Velocity with force from last " << getAtomicForceAtStep(LastStep) | 
|---|
| 623 | << " and present " << getAtomicForceAtStep(NextStep) << " step " << tempVector); | 
|---|
| 624 | setAtomicVelocityAtStep(NextStep, tempVector); | 
|---|
| 625 | LOG(3, "INFO: Velocity at step " << NextStep << " set to " << tempVector); | 
|---|
| 626 | } | 
|---|
| 627 | }; | 
|---|
| 628 |  | 
|---|
| 629 | std::ostream & AtomInfo::operator << (std::ostream &ost) const | 
|---|
| 630 | { | 
|---|
| 631 | return (ost << getPosition()); | 
|---|
| 632 | } | 
|---|
| 633 |  | 
|---|
| 634 | std::ostream & operator << (std::ostream &ost, const AtomInfo &a) | 
|---|
| 635 | { | 
|---|
| 636 | const size_t terminalstep = a.getTrajectorySize()-1; | 
|---|
| 637 | if (terminalstep) { | 
|---|
| 638 | ost << "starts at " | 
|---|
| 639 | << a.getPositionAtStep(0) << " and ends at " | 
|---|
| 640 | << a.getPositionAtStep(terminalstep) | 
|---|
| 641 | << " at time step " << terminalstep; | 
|---|
| 642 | } else { | 
|---|
| 643 | ost << "is at " | 
|---|
| 644 | << a.getPositionAtStep(0) << " with a single time step only"; | 
|---|
| 645 | } | 
|---|
| 646 | return ost; | 
|---|
| 647 | } | 
|---|
| 648 |  | 
|---|