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