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