source: src/Atom/atom_atominfo.cpp@ 08a0f52

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

AtomInfo has new functions getElement() and getElementNo().

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