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