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