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 "atom_atominfo.hpp"
|
---|
30 |
|
---|
31 | /** Constructor of class AtomInfo.
|
---|
32 | */
|
---|
33 | AtomInfo::AtomInfo() :
|
---|
34 | AtomicElement(NULL),
|
---|
35 | FixedIon(false)
|
---|
36 | {
|
---|
37 | AtomicPosition.reserve(1);
|
---|
38 | AtomicPosition.push_back(zeroVec);
|
---|
39 | AtomicVelocity.reserve(1);
|
---|
40 | AtomicVelocity.push_back(zeroVec);
|
---|
41 | AtomicForce.reserve(1);
|
---|
42 | AtomicForce.push_back(zeroVec);
|
---|
43 | };
|
---|
44 |
|
---|
45 | /** Copy constructor of class AtomInfo.
|
---|
46 | */
|
---|
47 | AtomInfo::AtomInfo(const AtomInfo &_atom) :
|
---|
48 | AtomicPosition(_atom.AtomicPosition),
|
---|
49 | AtomicElement(_atom.AtomicElement),
|
---|
50 | FixedIon(false)
|
---|
51 | {
|
---|
52 | AtomicVelocity.reserve(1);
|
---|
53 | AtomicVelocity.push_back(zeroVec);
|
---|
54 | AtomicForce.reserve(1);
|
---|
55 | AtomicForce.push_back(zeroVec);
|
---|
56 | };
|
---|
57 |
|
---|
58 | AtomInfo::AtomInfo(const VectorInterface &_v) :
|
---|
59 | AtomicElement(NULL),
|
---|
60 | FixedIon(false)
|
---|
61 | {
|
---|
62 | AtomicPosition[0] = _v.getPosition();
|
---|
63 | AtomicVelocity.reserve(1);
|
---|
64 | AtomicVelocity.push_back(zeroVec);
|
---|
65 | AtomicForce.reserve(1);
|
---|
66 | AtomicForce.push_back(zeroVec);
|
---|
67 | };
|
---|
68 |
|
---|
69 | /** Destructor of class AtomInfo.
|
---|
70 | */
|
---|
71 | AtomInfo::~AtomInfo()
|
---|
72 | {
|
---|
73 | };
|
---|
74 |
|
---|
75 | const element *AtomInfo::getType() const
|
---|
76 | {
|
---|
77 | return AtomicElement;
|
---|
78 | }
|
---|
79 |
|
---|
80 | const double& AtomInfo::operator[](size_t i) const
|
---|
81 | {
|
---|
82 | return AtomicPosition[0][i];
|
---|
83 | }
|
---|
84 |
|
---|
85 | const double& AtomInfo::at(size_t i) const
|
---|
86 | {
|
---|
87 | return AtomicPosition[0].at(i);
|
---|
88 | }
|
---|
89 |
|
---|
90 | void AtomInfo::set(size_t i, const double value)
|
---|
91 | {
|
---|
92 | AtomicPosition[0].at(i) = value;
|
---|
93 | }
|
---|
94 |
|
---|
95 | const Vector& AtomInfo::getPosition() const
|
---|
96 | {
|
---|
97 | return AtomicPosition[0];
|
---|
98 | }
|
---|
99 |
|
---|
100 | const Vector& AtomInfo::getPosition(const int _step) const
|
---|
101 | {
|
---|
102 | ASSERT(_step < AtomicPosition.size(),
|
---|
103 | "AtomInfo::getPosition() - Access out of range.");
|
---|
104 | return AtomicPosition[_step];
|
---|
105 | }
|
---|
106 |
|
---|
107 | void AtomInfo::setType(const element* _type) {
|
---|
108 | AtomicElement = _type;
|
---|
109 | }
|
---|
110 |
|
---|
111 | void AtomInfo::setType(const int Z) {
|
---|
112 | const element *elem = World::getInstance().getPeriode()->FindElement(Z);
|
---|
113 | setType(elem);
|
---|
114 | }
|
---|
115 |
|
---|
116 | Vector& AtomInfo::getAtomicVelocity()
|
---|
117 | {
|
---|
118 | return AtomicVelocity[0];
|
---|
119 | }
|
---|
120 |
|
---|
121 | Vector& AtomInfo::getAtomicVelocity(const int _step)
|
---|
122 | {
|
---|
123 | ASSERT(_step < AtomicVelocity.size(),
|
---|
124 | "AtomInfo::getAtomicVelocity() - Access out of range.");
|
---|
125 | return AtomicVelocity[_step];
|
---|
126 | }
|
---|
127 |
|
---|
128 | const Vector& AtomInfo::getAtomicVelocity() const
|
---|
129 | {
|
---|
130 | return AtomicVelocity[0];
|
---|
131 | }
|
---|
132 |
|
---|
133 | const Vector& AtomInfo::getAtomicVelocity(const int _step) const
|
---|
134 | {
|
---|
135 | ASSERT(_step < AtomicVelocity.size(),
|
---|
136 | "AtomInfo::getAtomicVelocity() - Access out of range.");
|
---|
137 | return AtomicVelocity[_step];
|
---|
138 | }
|
---|
139 |
|
---|
140 | void AtomInfo::setAtomicVelocity(const Vector &_newvelocity)
|
---|
141 | {
|
---|
142 | AtomicVelocity[0] = _newvelocity;
|
---|
143 | }
|
---|
144 |
|
---|
145 | void AtomInfo::setAtomicVelocity(const int _step, const Vector &_newvelocity)
|
---|
146 | {
|
---|
147 | ASSERT(_step <= AtomicVelocity.size(),
|
---|
148 | "AtomInfo::setAtomicVelocity() - Access out of range.");
|
---|
149 | if(_step < (int)AtomicVelocity.size()) {
|
---|
150 | AtomicVelocity[_step] = _newvelocity;
|
---|
151 | } else if (_step == (int)AtomicVelocity.size()) {
|
---|
152 | AtomicVelocity.push_back(_newvelocity);
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | const Vector& AtomInfo::getAtomicForce() const
|
---|
157 | {
|
---|
158 | return AtomicForce[0];
|
---|
159 | }
|
---|
160 |
|
---|
161 | const Vector& AtomInfo::getAtomicForce(const int _step) const
|
---|
162 | {
|
---|
163 | ASSERT(_step < AtomicForce.size(),
|
---|
164 | "AtomInfo::getAtomicForce() - Access out of range.");
|
---|
165 | return AtomicForce[_step];
|
---|
166 | }
|
---|
167 |
|
---|
168 | void AtomInfo::setAtomicForce(const Vector &_newforce)
|
---|
169 | {
|
---|
170 | AtomicForce[0] = _newforce;
|
---|
171 | }
|
---|
172 |
|
---|
173 | void AtomInfo::setAtomicForce(const int _step, const Vector &_newforce)
|
---|
174 | {
|
---|
175 | ASSERT(_step <= AtomicForce.size(),
|
---|
176 | "AtomInfo::setAtomicForce() - Access out of range.");
|
---|
177 | if(_step < (int)AtomicForce.size()) {
|
---|
178 | AtomicForce[_step] = _newforce;
|
---|
179 | } else if (_step == (int)AtomicForce.size()) {
|
---|
180 | AtomicForce.push_back(_newforce);
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | bool AtomInfo::getFixedIon() const
|
---|
185 | {
|
---|
186 | return FixedIon;
|
---|
187 | }
|
---|
188 |
|
---|
189 | void AtomInfo::setFixedIon(const bool _fixedion)
|
---|
190 | {
|
---|
191 | FixedIon = _fixedion;
|
---|
192 | }
|
---|
193 |
|
---|
194 | void AtomInfo::setPosition(const Vector& _vector)
|
---|
195 | {
|
---|
196 | AtomicPosition[0] = _vector;
|
---|
197 | //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl;
|
---|
198 | }
|
---|
199 |
|
---|
200 | void AtomInfo::setPosition(int _step, const Vector& _vector)
|
---|
201 | {
|
---|
202 | ASSERT(_step <= AtomicPosition.size(),
|
---|
203 | "AtomInfo::setPosition() - Access out of range.");
|
---|
204 | if(_step < (int)AtomicPosition.size()) {
|
---|
205 | AtomicPosition[_step] = _vector;
|
---|
206 | } else if (_step == (int)AtomicPosition.size()) {
|
---|
207 | AtomicPosition.push_back(_vector);
|
---|
208 | }
|
---|
209 | //cout << "AtomInfo::setPosition: " << getType()->symbol << " at " << getPosition() << endl;
|
---|
210 | }
|
---|
211 |
|
---|
212 | const VectorInterface& AtomInfo::operator+=(const Vector& b)
|
---|
213 | {
|
---|
214 | AtomicPosition[0] += b;
|
---|
215 | return *this;
|
---|
216 | }
|
---|
217 |
|
---|
218 | const VectorInterface& AtomInfo::operator-=(const Vector& b)
|
---|
219 | {
|
---|
220 | AtomicPosition[0] -= b;
|
---|
221 | return *this;
|
---|
222 | }
|
---|
223 |
|
---|
224 | Vector const AtomInfo::operator+(const Vector& b) const
|
---|
225 | {
|
---|
226 | Vector a(AtomicPosition[0]);
|
---|
227 | a += b;
|
---|
228 | return a;
|
---|
229 | }
|
---|
230 |
|
---|
231 | Vector const AtomInfo::operator-(const Vector& b) const
|
---|
232 | {
|
---|
233 | Vector a(AtomicPosition[0]);
|
---|
234 | a -= b;
|
---|
235 | return a;
|
---|
236 | }
|
---|
237 |
|
---|
238 | double AtomInfo::distance(const Vector &point) const
|
---|
239 | {
|
---|
240 | return AtomicPosition[0].distance(point);
|
---|
241 | }
|
---|
242 |
|
---|
243 | double AtomInfo::DistanceSquared(const Vector &y) const
|
---|
244 | {
|
---|
245 | return AtomicPosition[0].DistanceSquared(y);
|
---|
246 | }
|
---|
247 |
|
---|
248 | double AtomInfo::distance(const VectorInterface &_atom) const
|
---|
249 | {
|
---|
250 | return _atom.distance(AtomicPosition[0]);
|
---|
251 | }
|
---|
252 |
|
---|
253 | double AtomInfo::DistanceSquared(const VectorInterface &_atom) const
|
---|
254 | {
|
---|
255 | return _atom.DistanceSquared(AtomicPosition[0]);
|
---|
256 | }
|
---|
257 |
|
---|
258 | VectorInterface &AtomInfo::operator=(const Vector& _vector)
|
---|
259 | {
|
---|
260 | AtomicPosition[0] = _vector;
|
---|
261 | return *this;
|
---|
262 | }
|
---|
263 |
|
---|
264 | void AtomInfo::ScaleAll(const double *factor)
|
---|
265 | {
|
---|
266 | AtomicPosition[0].ScaleAll(factor);
|
---|
267 | }
|
---|
268 |
|
---|
269 | void AtomInfo::ScaleAll(const Vector &factor)
|
---|
270 | {
|
---|
271 | AtomicPosition[0].ScaleAll(factor);
|
---|
272 | }
|
---|
273 |
|
---|
274 | void AtomInfo::Scale(const double factor)
|
---|
275 | {
|
---|
276 | AtomicPosition[0].Scale(factor);
|
---|
277 | }
|
---|
278 |
|
---|
279 | void AtomInfo::Zero()
|
---|
280 | {
|
---|
281 | AtomicPosition[0].Zero();
|
---|
282 | }
|
---|
283 |
|
---|
284 | void AtomInfo::One(const double one)
|
---|
285 | {
|
---|
286 | AtomicPosition[0].One(one);
|
---|
287 | }
|
---|
288 |
|
---|
289 | void AtomInfo::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors)
|
---|
290 | {
|
---|
291 | AtomicPosition[0].LinearCombinationOfVectors(x1,x2,x3,factors);
|
---|
292 | }
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * returns the kinetic energy of this atom at a given time step
|
---|
296 | */
|
---|
297 | double AtomInfo::getKineticEnergy(unsigned int step) const{
|
---|
298 | return getMass() * AtomicVelocity[step].NormSquared();
|
---|
299 | }
|
---|
300 |
|
---|
301 | Vector AtomInfo::getMomentum(unsigned int step) const{
|
---|
302 | return getMass()*AtomicVelocity[step];
|
---|
303 | }
|
---|
304 |
|
---|
305 | /** Extends the trajectory STL vector to the new size.
|
---|
306 | * Does nothing if \a MaxSteps is smaller than current size.
|
---|
307 | * \param MaxSteps
|
---|
308 | */
|
---|
309 | void AtomInfo::ResizeTrajectory(size_t MaxSteps)
|
---|
310 | {
|
---|
311 | if (AtomicPosition.size() <= (unsigned int)(MaxSteps)) {
|
---|
312 | DoLog(0) && (Log() << Verbose(0) << "Increasing size for trajectory array from " << AtomicPosition.size() << " to " << (MaxSteps+1) << "." << endl);
|
---|
313 | AtomicPosition.resize(MaxSteps+1, zeroVec);
|
---|
314 | AtomicVelocity.resize(MaxSteps+1, zeroVec);
|
---|
315 | AtomicForce.resize(MaxSteps+1, zeroVec);
|
---|
316 | }
|
---|
317 | };
|
---|
318 |
|
---|
319 | size_t AtomInfo::getTrajectorySize() const
|
---|
320 | {
|
---|
321 | return AtomicPosition.size();
|
---|
322 | }
|
---|
323 |
|
---|
324 | double AtomInfo::getMass() const{
|
---|
325 | return AtomicElement->getMass();
|
---|
326 | }
|
---|
327 |
|
---|
328 | /** Copies a given trajectory step \a src onto another \a dest
|
---|
329 | * \param dest index of destination step
|
---|
330 | * \param src index of source step
|
---|
331 | */
|
---|
332 | void AtomInfo::CopyStepOnStep(int dest, int src)
|
---|
333 | {
|
---|
334 | if (dest == src) // self assignment check
|
---|
335 | return;
|
---|
336 |
|
---|
337 | ASSERT(dest < AtomicPosition.size(),
|
---|
338 | "AtomInfo::CopyStepOnStep() - destination outside of current trajectory array.");
|
---|
339 | ASSERT(src < AtomicPosition.size(),
|
---|
340 | "AtomInfo::CopyStepOnStep() - source outside of current trajectory array.");
|
---|
341 | for (int n=NDIM;n--;) {
|
---|
342 | AtomicPosition.at(dest)[n] = AtomicPosition.at(src)[n];
|
---|
343 | AtomicVelocity.at(dest)[n] = AtomicVelocity.at(src)[n];
|
---|
344 | AtomicForce.at(dest)[n] = AtomicForce.at(src)[n];
|
---|
345 | }
|
---|
346 | };
|
---|
347 |
|
---|
348 | /** Performs a velocity verlet update of the trajectory.
|
---|
349 | * Parameters are according to those in configuration class.
|
---|
350 | * \param NextStep index of sequential step to set
|
---|
351 | * \param *configuration pointer to configuration with parameters
|
---|
352 | * \param *Force matrix with forces
|
---|
353 | */
|
---|
354 | void AtomInfo::VelocityVerletUpdate(int nr, int NextStep, config *configuration, ForceMatrix *Force, const size_t offset)
|
---|
355 | {
|
---|
356 | //a = configuration.Deltat*0.5/walker->type->mass; // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a
|
---|
357 | if ((int)AtomicPosition.size() <= NextStep)
|
---|
358 | ResizeTrajectory(NextStep+10);
|
---|
359 | for (int d=0; d<NDIM; d++) {
|
---|
360 | AtomicForce.at(NextStep)[d] = -Force->Matrix[0][nr][d+offset]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.);
|
---|
361 | AtomicPosition.at(NextStep)[d] = AtomicPosition.at(NextStep-1)[d];
|
---|
362 | AtomicPosition.at(NextStep)[d] += configuration->Deltat*(AtomicVelocity.at(NextStep-1)[d]); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
|
---|
363 | AtomicPosition.at(NextStep)[d] += 0.5*configuration->Deltat*configuration->Deltat*(AtomicForce.at(NextStep)[d]/getMass()); // F = m * a and s =
|
---|
364 | }
|
---|
365 | // Update U
|
---|
366 | for (int d=0; d<NDIM; d++) {
|
---|
367 | AtomicVelocity.at(NextStep)[d] = AtomicVelocity.at(NextStep-1)[d];
|
---|
368 | AtomicVelocity.at(NextStep)[d] += configuration->Deltat * (AtomicForce.at(NextStep)[d]+AtomicForce.at(NextStep-1)[d]/getMass()); // v = F/m * t
|
---|
369 | }
|
---|
370 | // Update R (and F)
|
---|
371 | // out << "Integrated position&velocity of step " << (NextStep) << ": (";
|
---|
372 | // for (int d=0;d<NDIM;d++)
|
---|
373 | // out << AtomicPosition.at(NextStep).x[d] << " "; // next step
|
---|
374 | // out << ")\t(";
|
---|
375 | // for (int d=0;d<NDIM;d++)
|
---|
376 | // Log() << Verbose(0) << AtomicVelocity.at(NextStep).x[d] << " "; // next step
|
---|
377 | // out << ")" << endl;
|
---|
378 | };
|
---|
379 |
|
---|
380 | const AtomInfo& operator*=(AtomInfo& a, const double m)
|
---|
381 | {
|
---|
382 | a.Scale(m);
|
---|
383 | return a;
|
---|
384 | }
|
---|
385 |
|
---|
386 | AtomInfo const operator*(const AtomInfo& a, const double m)
|
---|
387 | {
|
---|
388 | AtomInfo copy(a);
|
---|
389 | copy *= m;
|
---|
390 | return copy;
|
---|
391 | }
|
---|
392 |
|
---|
393 | AtomInfo const operator*(const double m, const AtomInfo& a)
|
---|
394 | {
|
---|
395 | AtomInfo copy(a);
|
---|
396 | copy *= m;
|
---|
397 | return copy;
|
---|
398 | }
|
---|
399 |
|
---|
400 | std::ostream & AtomInfo::operator << (std::ostream &ost) const
|
---|
401 | {
|
---|
402 | return (ost << getPosition());
|
---|
403 | }
|
---|
404 |
|
---|
405 | std::ostream & operator << (std::ostream &ost, const AtomInfo &a)
|
---|
406 | {
|
---|
407 | ost << a;
|
---|
408 | return ost;
|
---|
409 | }
|
---|
410 |
|
---|