Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

mdsimulation.cpp

Go to the documentation of this file.
00001 /***************************************************************************************************
00002 *****           Copyright (C) 2005  John Schneiderman <JohnMS@member.fsf.org>                  *****
00003 *****                                                                                          *****
00004 *****           This program is free software; you can redistribute it and/or modify           *****
00005 *****           it under the terms of the GNU General Public License as published by           *****
00006 *****           the Free Software Foundation; either version 2 of the License, or              *****
00007 *****           (at your option) any later version.                                            *****
00008 *****                                                                                          *****
00009 *****           This program is distributed in the hope that it will be useful,                *****
00010 *****           but WITHOUT ANY WARRANTY; without even the implied warranty of                 *****
00011 *****           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  *****
00012 *****           GNU General Public License for more details.                                   *****
00013 *****                                                                                          *****
00014 *****           You should have received a copy of the GNU General Public License              *****
00015 *****           along with this program; if not, write to the Free Software                    *****
00016 *****           Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA     *****
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     //Calculate the averages
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     //Write out the averages
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 }

Generated on Tue Mar 28 23:28:03 2006 for ClusterSim by  doxygen 1.4.4