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