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