| 1 | /* | 
|---|
| 2 | * OutputEnergies.hpp | 
|---|
| 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 |  | 
|---|
| 16 | #include "Helpers/defs.hpp" | 
|---|
| 17 |  | 
|---|
| 18 | template <class T> | 
|---|
| 19 | class OutputEnergies | 
|---|
| 20 | { | 
|---|
| 21 | public: | 
|---|
| 22 | OutputEnergies(AtomSetMixin<T> &_atoms) : | 
|---|
| 23 | atoms(_atoms) | 
|---|
| 24 | {} | 
|---|
| 25 | ~OutputEnergies() | 
|---|
| 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; | 
|---|
| 39 | Vector force, abs_force; | 
|---|
| 40 | Vector momentum, abs_momentum; | 
|---|
| 41 | // test stream | 
|---|
| 42 | if (output == NULL) | 
|---|
| 43 | return false; | 
|---|
| 44 | else | 
|---|
| 45 | *output << "# Step" | 
|---|
| 46 | << "\tTemperature [K]" | 
|---|
| 47 | << "\tTemperature [a.u.]" | 
|---|
| 48 | << "\tMomentum" | 
|---|
| 49 | << "\tAbolute Momentum" | 
|---|
| 50 | << "\tForce" | 
|---|
| 51 | << "\tAbsolute Force" | 
|---|
| 52 | << endl; | 
|---|
| 53 | for (int step=startstep;step < endstep; step++) { // loop over all time steps | 
|---|
| 54 | temperature = atoms.totalTemperatureAtStep(step); | 
|---|
| 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 | 
|---|
| 60 | << "\t" << temperature*AtomicEnergyToKelvin | 
|---|
| 61 | << "\t" << temperature | 
|---|
| 62 | << "\t" << momentum.Norm() | 
|---|
| 63 | << "\t" << abs_momentum.Norm() | 
|---|
| 64 | << "\t" << force.Norm() | 
|---|
| 65 | << "\t" << abs_force.Norm() | 
|---|
| 66 | << endl; | 
|---|
| 67 | } | 
|---|
| 68 | return true; | 
|---|
| 69 | }; | 
|---|
| 70 |  | 
|---|
| 71 | private: | 
|---|
| 72 | AtomSetMixin<T> atoms; | 
|---|
| 73 | }; | 
|---|
| 74 |  | 
|---|
| 75 | #endif /* OUTPUTTEMPERATURE_HPP_ */ | 
|---|