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_trajectoryparticle.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 "atom.hpp"
|
---|
23 | #include "atom_trajectoryparticle.hpp"
|
---|
24 | #include "config.hpp"
|
---|
25 | #include "element.hpp"
|
---|
26 | #include "CodePatterns/Info.hpp"
|
---|
27 | #include "CodePatterns/Log.hpp"
|
---|
28 | #include "parser.hpp"
|
---|
29 | #include "ThermoStatContainer.hpp"
|
---|
30 | #include "CodePatterns/Verbose.hpp"
|
---|
31 |
|
---|
32 | /** Constructor of class TrajectoryParticle.
|
---|
33 | */
|
---|
34 | TrajectoryParticle::TrajectoryParticle()
|
---|
35 | {
|
---|
36 | };
|
---|
37 |
|
---|
38 | /** Destructor of class TrajectoryParticle.
|
---|
39 | */
|
---|
40 | TrajectoryParticle::~TrajectoryParticle()
|
---|
41 | {
|
---|
42 | };
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * returns the kinetic energy of this atom at a given time step
|
---|
46 | */
|
---|
47 | double TrajectoryParticle::getKineticEnergy(unsigned int step) const{
|
---|
48 | return getType()->getMass() * Trajectory.U.at(step).NormSquared();
|
---|
49 | }
|
---|
50 |
|
---|
51 | Vector TrajectoryParticle::getMomentum(unsigned int step) const{
|
---|
52 | return getType()->getMass()*Trajectory.U.at(step);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /** Extends the trajectory STL vector to the new size.
|
---|
56 | * Does nothing if \a MaxSteps is smaller than current size.
|
---|
57 | * \param MaxSteps
|
---|
58 | */
|
---|
59 | void TrajectoryParticle::ResizeTrajectory(int MaxSteps)
|
---|
60 | {
|
---|
61 | Info FunctionInfo(__func__);
|
---|
62 | if (Trajectory.R.size() <= (unsigned int)(MaxSteps)) {
|
---|
63 | DoLog(0) && (Log() << Verbose(0) << "Increasing size for trajectory array of " << nr << " from " << Trajectory.R.size() << " to " << (MaxSteps+1) << "." << endl);
|
---|
64 | Trajectory.R.resize(MaxSteps+1);
|
---|
65 | Trajectory.U.resize(MaxSteps+1);
|
---|
66 | Trajectory.F.resize(MaxSteps+1);
|
---|
67 | }
|
---|
68 | };
|
---|
69 |
|
---|
70 | /** Copies a given trajectory step \a src onto another \a dest
|
---|
71 | * \param dest index of destination step
|
---|
72 | * \param src index of source step
|
---|
73 | */
|
---|
74 | void TrajectoryParticle::CopyStepOnStep(int dest, int src)
|
---|
75 | {
|
---|
76 | if (dest == src) // self assignment check
|
---|
77 | return;
|
---|
78 |
|
---|
79 | for (int n=NDIM;n--;) {
|
---|
80 | Trajectory.R.at(dest)[n] = Trajectory.R.at(src)[n];
|
---|
81 | Trajectory.U.at(dest)[n] = Trajectory.U.at(src)[n];
|
---|
82 | Trajectory.F.at(dest)[n] = Trajectory.F.at(src)[n];
|
---|
83 | }
|
---|
84 | };
|
---|
85 |
|
---|
86 | /** Performs a velocity verlet update of the trajectory.
|
---|
87 | * Parameters are according to those in configuration class.
|
---|
88 | * \param NextStep index of sequential step to set
|
---|
89 | * \param *configuration pointer to configuration with parameters
|
---|
90 | * \param *Force matrix with forces
|
---|
91 | */
|
---|
92 | void TrajectoryParticle::VelocityVerletUpdate(int NextStep, config *configuration, ForceMatrix *Force, const size_t offset)
|
---|
93 | {
|
---|
94 | //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
|
---|
95 | for (int d=0; d<NDIM; d++) {
|
---|
96 | Trajectory.F.at(NextStep)[d] = -Force->Matrix[0][nr][d+offset]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.);
|
---|
97 | Trajectory.R.at(NextStep)[d] = Trajectory.R.at(NextStep-1)[d];
|
---|
98 | Trajectory.R.at(NextStep)[d] += configuration->Deltat*(Trajectory.U.at(NextStep-1)[d]); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
|
---|
99 | Trajectory.R.at(NextStep)[d] += 0.5*configuration->Deltat*configuration->Deltat*(Trajectory.F.at(NextStep)[d]/getType()->getMass()); // F = m * a and s =
|
---|
100 | }
|
---|
101 | // Update U
|
---|
102 | for (int d=0; d<NDIM; d++) {
|
---|
103 | Trajectory.U.at(NextStep)[d] = Trajectory.U.at(NextStep-1)[d];
|
---|
104 | Trajectory.U.at(NextStep)[d] += configuration->Deltat * (Trajectory.F.at(NextStep)[d]+Trajectory.F.at(NextStep-1)[d]/getType()->getMass()); // v = F/m * t
|
---|
105 | }
|
---|
106 | // Update R (and F)
|
---|
107 | // out << "Integrated position&velocity of step " << (NextStep) << ": (";
|
---|
108 | // for (int d=0;d<NDIM;d++)
|
---|
109 | // out << Trajectory.R.at(NextStep).x[d] << " "; // next step
|
---|
110 | // out << ")\t(";
|
---|
111 | // for (int d=0;d<NDIM;d++)
|
---|
112 | // Log() << Verbose(0) << Trajectory.U.at(NextStep).x[d] << " "; // next step
|
---|
113 | // out << ")" << endl;
|
---|
114 | };
|
---|
115 |
|
---|
116 | std::ostream & TrajectoryParticle::operator << (std::ostream &ost) const
|
---|
117 | {
|
---|
118 | ParticleInfo::operator<<(ost);
|
---|
119 | ost << "," << getPosition();
|
---|
120 | return ost;
|
---|
121 | }
|
---|
122 |
|
---|
123 | std::ostream & operator << (std::ostream &ost, const TrajectoryParticle &a)
|
---|
124 | {
|
---|
125 | a.ParticleInfo::operator<<(ost);
|
---|
126 | ost << "," << a.getPosition();
|
---|
127 | return ost;
|
---|
128 | }
|
---|
129 |
|
---|