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