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