00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mdsimulation.h"
00019 #include "configurationdatabase.h"
00020
00021 #include <cmath>
00022 using std::sqrt;
00023
00024 #include <fstream>
00025 using std::ostream;
00026 using std::endl;
00027
00028 MD_Simulation::MD_Simulation(const ConfigurationDatabase &conf):BaseSimulation(conf)
00029 {
00030 m_temperature = 0.0, m_timeStep = 0.0;
00031 m_accumPotentialTotal = 0.0, m_accumKineticTotal = 0.0, m_accumEnergyTotal = 0.0;
00032 m_accumPotentialSQ = 0.0, m_accumKineticSQ = 0.0, m_accumEnergySQ = 0.0;
00033 }
00034
00035 void MD_Simulation::clear()
00036 {
00037 m_temperature = 0.0, m_timeStep = 0.0;
00038 m_accumPotentialTotal = 0.0, m_accumKineticTotal = 0.0, m_accumEnergyTotal = 0.0;
00039 m_accumPotentialSQ = 0.0, m_accumKineticSQ = 0.0, m_accumEnergySQ = 0.0;
00040 BaseSimulation::clear();
00041 }
00042
00043 void MD_Simulation::writeAverages(ostream &out, const Cluster &clust)
00044 {
00045 double averagePotentialEnergy = 0.0, averageKineticEnergy = 0.0, averageEnergyTotal = 0.0, averageTemperature = 0.0;
00046 double fluctuationPotentialEnergy = 0.0, fluctuationKineticEnergy = 0.0, fluctuationEnergyTotal= 0.0, fluctuationTemperature = 0.0;
00047
00048
00049 averagePotentialEnergy = m_accumPotentialTotal/m_runSteps;
00050 averageKineticEnergy = m_accumKineticTotal/m_runSteps;
00051 averageEnergyTotal = m_accumEnergyTotal/m_runSteps;
00052 m_accumPotentialSQ = (m_accumPotentialSQ/m_runSteps) - (averagePotentialEnergy*averagePotentialEnergy);
00053 m_accumKineticSQ = (m_accumKineticSQ/m_runSteps) - (averageKineticEnergy*averageKineticEnergy);
00054 m_accumEnergySQ = (m_accumEnergySQ/m_runSteps) - (averageEnergyTotal*averageEnergyTotal);
00055 if (m_accumPotentialSQ > 0.0)
00056 fluctuationPotentialEnergy = sqrt(m_accumPotentialSQ);
00057 if (m_accumKineticSQ > 0.0)
00058 fluctuationKineticEnergy = sqrt(m_accumKineticSQ);
00059 if (m_accumEnergySQ > 0.0)
00060 fluctuationEnergyTotal = sqrt(m_accumEnergySQ);
00061 averageTemperature = averageKineticEnergy*(2.0*clust.size()/(3.0*clust.size()-6.0));
00062 fluctuationTemperature = fluctuationKineticEnergy*(2.0*clust.size()/(3.0*clust.size()-6.0));
00063
00064
00065 out << " Average potential energy: " << averagePotentialEnergy << " ± " << fluctuationPotentialEnergy << endl;
00066 out << " Average kinetic energy: " << averageKineticEnergy << " ± " << fluctuationKineticEnergy << endl;
00067 out << " Average total energy: " << averageEnergyTotal << " ± " << fluctuationEnergyTotal << endl;
00068 out << " Average m_temperature: " << averageTemperature << " ± " << fluctuationTemperature << endl;
00069 out << "Relative Energy Fluctuations: " << fluctuationEnergyTotal/averageEnergyTotal << endl;
00070 out << " Total time for run: " << m_runSteps * m_changeInStep << endl;
00071 out << " Final time: " << m_timeStep << endl;
00072 }