source: src/atom_atominfo.cpp@ 50e4e5

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 50e4e5 was a9b86d, checked in by Frederik Heber <heber@…>, 13 years ago

Split up modules parser.[ch]pp into one module per class.

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