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