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