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