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