source: src/Atom/atom_atominfo.cpp@ 46ce1c

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 46ce1c was 8cc22f, checked in by Frederik Heber <heber@…>, 11 years ago

Changed how trajectories are stored, not as vecor but as map.

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