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