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