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