| [8009ce] | 1 | /*
 | 
|---|
| [d40189] | 2 |  * OutputEnergies.hpp
 | 
|---|
| [8009ce] | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Feb 23, 2011
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef OUTPUTTEMPERATURE_HPP_
 | 
|---|
 | 9 | #define OUTPUTTEMPERATURE_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
| [255829] | 16 | #include "Helpers/defs.hpp"
 | 
|---|
 | 17 | 
 | 
|---|
| [8009ce] | 18 | template <class T>
 | 
|---|
| [d40189] | 19 | class OutputEnergies
 | 
|---|
| [8009ce] | 20 | {
 | 
|---|
 | 21 | public:
 | 
|---|
| [d40189] | 22 |   OutputEnergies(AtomSetMixin<T> &_atoms) :
 | 
|---|
| [8009ce] | 23 |     atoms(_atoms)
 | 
|---|
 | 24 |   {}
 | 
|---|
| [d40189] | 25 |   ~OutputEnergies()
 | 
|---|
| [8009ce] | 26 |   {}
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 |   /** Stores the temperature evaluated from velocities in molecule::Trajectories.
 | 
|---|
 | 29 |    * We simply use the formula equivaleting temperature and kinetic energy:
 | 
|---|
 | 30 |    * \f$k_B T = \sum_i m_i v_i^2\f$
 | 
|---|
 | 31 |    * \param *output output stream of temperature file
 | 
|---|
 | 32 |    * \param startstep first MD step in molecule::Trajectories
 | 
|---|
 | 33 |    * \param endstep last plus one MD step in molecule::Trajectories
 | 
|---|
 | 34 |    * \return file written (true), failure on writing file (false)
 | 
|---|
 | 35 |    */
 | 
|---|
 | 36 |   bool operator()(ofstream * const output, int startstep, int endstep)
 | 
|---|
 | 37 |   {
 | 
|---|
 | 38 |     double temperature;
 | 
|---|
| [d40189] | 39 |     Vector force, abs_force;
 | 
|---|
 | 40 |     Vector momentum, abs_momentum;
 | 
|---|
| [8009ce] | 41 |     // test stream
 | 
|---|
 | 42 |     if (output == NULL)
 | 
|---|
 | 43 |       return false;
 | 
|---|
 | 44 |     else
 | 
|---|
| [d40189] | 45 |       *output << "# Step"
 | 
|---|
 | 46 |         << "\tTemperature [K]"
 | 
|---|
 | 47 |         << "\tTemperature [a.u.]"
 | 
|---|
 | 48 |         << "\tMomentum"
 | 
|---|
 | 49 |         << "\tAbolute Momentum"
 | 
|---|
 | 50 |         << "\tForce"
 | 
|---|
 | 51 |         << "\tAbsolute Force"
 | 
|---|
 | 52 |         << endl;
 | 
|---|
| [8009ce] | 53 |     for (int step=startstep;step < endstep; step++) { // loop over all time steps
 | 
|---|
 | 54 |       temperature = atoms.totalTemperatureAtStep(step);
 | 
|---|
| [d40189] | 55 |       momentum = atoms.totalMomentumAtStep(step);
 | 
|---|
 | 56 |       force = atoms.totalForceAtStep(step);
 | 
|---|
 | 57 |       abs_momentum = atoms.totalAbsoluteMomentumAtStep(step);
 | 
|---|
 | 58 |       abs_force = atoms.totalAbsoluteForceAtStep(step);
 | 
|---|
 | 59 |       *output << step
 | 
|---|
| [4b2207] | 60 |           << "\t" << temperature*AtomicMassUnitsAngstroemOverAtomictimeSquaredToHt*AtomicEnergyToKelvin
 | 
|---|
 | 61 |           << "\t" << temperature*AtomicMassUnitsAngstroemOverAtomictimeSquaredToHt
 | 
|---|
 | 62 |           << "\t" << momentum.Norm()*AtomicMassUnitsAngstroemOverAtomictimeToAtomicMomentum
 | 
|---|
 | 63 |           << "\t" << abs_momentum.Norm()*AtomicMassUnitsAngstroemOverAtomictimeToAtomicMomentum
 | 
|---|
| [d40189] | 64 |           << "\t" << force.Norm()
 | 
|---|
 | 65 |           << "\t" << abs_force.Norm()
 | 
|---|
 | 66 |           << endl;
 | 
|---|
| [8009ce] | 67 |     }
 | 
|---|
 | 68 |     return true;
 | 
|---|
 | 69 |   };
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | private:
 | 
|---|
 | 72 |   AtomSetMixin<T> atoms;
 | 
|---|
 | 73 | };
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | #endif /* OUTPUTTEMPERATURE_HPP_ */
 | 
|---|