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