source: src/atom_atominfo.cpp@ 936a02

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

FIX: atominfo::getType() does not care whether element exists.

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