| 1 | /*
|
|---|
| 2 | * atom_trajectoryparticle.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Oct 19, 2009
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | // include config.h
|
|---|
| 9 | #ifdef HAVE_CONFIG_H
|
|---|
| 10 | #include <config.h>
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| 13 | #include "Helpers/MemDebug.hpp"
|
|---|
| 14 |
|
|---|
| 15 | #include "atom.hpp"
|
|---|
| 16 | #include "atom_trajectoryparticle.hpp"
|
|---|
| 17 | #include "config.hpp"
|
|---|
| 18 | #include "element.hpp"
|
|---|
| 19 | #include "Helpers/Info.hpp"
|
|---|
| 20 | #include "Helpers/Log.hpp"
|
|---|
| 21 | #include "parser.hpp"
|
|---|
| 22 | #include "ThermoStatContainer.hpp"
|
|---|
| 23 | #include "Helpers/Verbose.hpp"
|
|---|
| 24 |
|
|---|
| 25 | /** Constructor of class TrajectoryParticle.
|
|---|
| 26 | */
|
|---|
| 27 | TrajectoryParticle::TrajectoryParticle()
|
|---|
| 28 | {
|
|---|
| 29 | };
|
|---|
| 30 |
|
|---|
| 31 | /** Destructor of class TrajectoryParticle.
|
|---|
| 32 | */
|
|---|
| 33 | TrajectoryParticle::~TrajectoryParticle()
|
|---|
| 34 | {
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * returns the kinetic energy of this atom at a given time step
|
|---|
| 39 | */
|
|---|
| 40 | double TrajectoryParticle::getKineticEnergy(unsigned int step) const{
|
|---|
| 41 | return getType()->mass * Trajectory.U.at(step).NormSquared();
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | /** Evaluates some constraint potential if atom moves from \a startstep at once to \endstep in trajectory.
|
|---|
| 45 | * \param startstep trajectory begins at
|
|---|
| 46 | * \param endstep trajectory ends at
|
|---|
| 47 | * \param **PermutationMap if atom switches places with some other atom, there is no translation but a permutaton noted here (not in the trajectories of ea
|
|---|
| 48 | * \param *Force Force matrix to store result in
|
|---|
| 49 | */
|
|---|
| 50 | void TrajectoryParticle::EvaluateConstrainedForce(int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force) const
|
|---|
| 51 | {
|
|---|
| 52 | double constant = 10.;
|
|---|
| 53 | TrajectoryParticle *Sprinter = PermutationMap[nr];
|
|---|
| 54 | // set forces
|
|---|
| 55 | for (int i=NDIM;i++;)
|
|---|
| 56 | Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).distance(Sprinter->Trajectory.R.at(endstep)));
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 | /** Correct velocity against the summed \a CoGVelocity for \a step.
|
|---|
| 60 | * \param *ActualTemp sum up actual temperature meanwhile
|
|---|
| 61 | * \param Step MD step in atom::Tracjetory
|
|---|
| 62 | * \param *CoGVelocity remnant velocity (i.e. vector sum of all atom velocities)
|
|---|
| 63 | */
|
|---|
| 64 | void TrajectoryParticle::CorrectVelocity(double *ActualTemp, int Step, Vector *CoGVelocity)
|
|---|
| 65 | {
|
|---|
| 66 | for(int d=0;d<NDIM;d++) {
|
|---|
| 67 | Trajectory.U.at(Step)[d] -= CoGVelocity->at(d);
|
|---|
| 68 | *ActualTemp += 0.5 * getType()->mass * Trajectory.U.at(Step)[d] * Trajectory.U.at(Step)[d];
|
|---|
| 69 | }
|
|---|
| 70 | };
|
|---|
| 71 |
|
|---|
| 72 | /** Extends the trajectory STL vector to the new size.
|
|---|
| 73 | * Does nothing if \a MaxSteps is smaller than current size.
|
|---|
| 74 | * \param MaxSteps
|
|---|
| 75 | */
|
|---|
| 76 | void TrajectoryParticle::ResizeTrajectory(int MaxSteps)
|
|---|
| 77 | {
|
|---|
| 78 | Info FunctionInfo(__func__);
|
|---|
| 79 | if (Trajectory.R.size() <= (unsigned int)(MaxSteps)) {
|
|---|
| 80 | DoLog(0) && (Log() << Verbose(0) << "Increasing size for trajectory array of " << nr << " from " << Trajectory.R.size() << " to " << (MaxSteps+1) << "." << endl);
|
|---|
| 81 | Trajectory.R.resize(MaxSteps+1);
|
|---|
| 82 | Trajectory.U.resize(MaxSteps+1);
|
|---|
| 83 | Trajectory.F.resize(MaxSteps+1);
|
|---|
| 84 | }
|
|---|
| 85 | };
|
|---|
| 86 |
|
|---|
| 87 | /** Copies a given trajectory step \a src onto another \a dest
|
|---|
| 88 | * \param dest index of destination step
|
|---|
| 89 | * \param src index of source step
|
|---|
| 90 | */
|
|---|
| 91 | void TrajectoryParticle::CopyStepOnStep(int dest, int src)
|
|---|
| 92 | {
|
|---|
| 93 | if (dest == src) // self assignment check
|
|---|
| 94 | return;
|
|---|
| 95 |
|
|---|
| 96 | for (int n=NDIM;n--;) {
|
|---|
| 97 | Trajectory.R.at(dest)[n] = Trajectory.R.at(src)[n];
|
|---|
| 98 | Trajectory.U.at(dest)[n] = Trajectory.U.at(src)[n];
|
|---|
| 99 | Trajectory.F.at(dest)[n] = Trajectory.F.at(src)[n];
|
|---|
| 100 | }
|
|---|
| 101 | };
|
|---|
| 102 |
|
|---|
| 103 | /** Performs a velocity verlet update of the trajectory.
|
|---|
| 104 | * Parameters are according to those in configuration class.
|
|---|
| 105 | * \param NextStep index of sequential step to set
|
|---|
| 106 | * \param *configuration pointer to configuration with parameters
|
|---|
| 107 | * \param *Force matrix with forces
|
|---|
| 108 | */
|
|---|
| 109 | void TrajectoryParticle::VelocityVerletUpdate(int NextStep, config *configuration, ForceMatrix *Force, const size_t offset)
|
|---|
| 110 | {
|
|---|
| 111 | //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
|
|---|
| 112 | for (int d=0; d<NDIM; d++) {
|
|---|
| 113 | Trajectory.F.at(NextStep)[d] = -Force->Matrix[0][nr][d+offset]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.);
|
|---|
| 114 | Trajectory.R.at(NextStep)[d] = Trajectory.R.at(NextStep-1)[d];
|
|---|
| 115 | Trajectory.R.at(NextStep)[d] += configuration->Deltat*(Trajectory.U.at(NextStep-1)[d]); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
|
|---|
| 116 | Trajectory.R.at(NextStep)[d] += 0.5*configuration->Deltat*configuration->Deltat*(Trajectory.F.at(NextStep)[d]/getType()->mass); // F = m * a and s =
|
|---|
| 117 | }
|
|---|
| 118 | // Update U
|
|---|
| 119 | for (int d=0; d<NDIM; d++) {
|
|---|
| 120 | Trajectory.U.at(NextStep)[d] = Trajectory.U.at(NextStep-1)[d];
|
|---|
| 121 | Trajectory.U.at(NextStep)[d] += configuration->Deltat * (Trajectory.F.at(NextStep)[d]+Trajectory.F.at(NextStep-1)[d]/getType()->mass); // v = F/m * t
|
|---|
| 122 | }
|
|---|
| 123 | // Update R (and F)
|
|---|
| 124 | // out << "Integrated position&velocity of step " << (NextStep) << ": (";
|
|---|
| 125 | // for (int d=0;d<NDIM;d++)
|
|---|
| 126 | // out << Trajectory.R.at(NextStep).x[d] << " "; // next step
|
|---|
| 127 | // out << ")\t(";
|
|---|
| 128 | // for (int d=0;d<NDIM;d++)
|
|---|
| 129 | // Log() << Verbose(0) << Trajectory.U.at(NextStep).x[d] << " "; // next step
|
|---|
| 130 | // out << ")" << endl;
|
|---|
| 131 | };
|
|---|
| 132 |
|
|---|
| 133 | /** Sums up mass and kinetics.
|
|---|
| 134 | * \param Step step to sum for
|
|---|
| 135 | * \param *TotalMass pointer to total mass sum
|
|---|
| 136 | * \param *TotalVelocity pointer to tota velocity sum
|
|---|
| 137 | */
|
|---|
| 138 | void TrajectoryParticle::SumUpKineticEnergy( int Step, double *TotalMass, Vector *TotalVelocity ) const
|
|---|
| 139 | {
|
|---|
| 140 | *TotalMass += getType()->mass; // sum up total mass
|
|---|
| 141 | for(int d=0;d<NDIM;d++) {
|
|---|
| 142 | TotalVelocity->at(d) += Trajectory.U.at(Step)[d]*getType()->mass;
|
|---|
| 143 | }
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| 146 | std::ostream & TrajectoryParticle::operator << (std::ostream &ost) const
|
|---|
| 147 | {
|
|---|
| 148 | ParticleInfo::operator<<(ost);
|
|---|
| 149 | ost << "," << getPosition();
|
|---|
| 150 | return ost;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | std::ostream & operator << (std::ostream &ost, const TrajectoryParticle &a)
|
|---|
| 154 | {
|
|---|
| 155 | a.ParticleInfo::operator<<(ost);
|
|---|
| 156 | ost << "," << a.getPosition();
|
|---|
| 157 | return ost;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|