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

radialdensityhist.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 "radialdensityhist.h"
00019 #include "cluster.h"
00020 #include "configurationdatabase.h"
00021 
00022 #include <cmath>
00023 
00024 #include <fstream>
00025 using std::ofstream;
00026 
00027 #include <iomanip>
00028 using std::ios;
00029 using std::scientific;
00030 using std::showpos;
00031 
00032 // class constructor
00033 RadialDensityHistogram::RadialDensityHistogram(const ConfigurationDatabase &conf):BaseHistogram(conf.doubleValue("RadialDensityHistogram", "min"), conf.doubleValue("RadialDensityHistogram", "max"), conf.intValue("RadialDensityHistogram", "bins"))
00034 {
00035     m_pullingInterval=conf.intValue("RadialDensityHistogram", "pull");
00036     m_pi=conf.doubleValue("RadialDensityHistogram", "PI");
00037 }
00038 
00039 void RadialDensityHistogram::acquire(const Cluster& cluster)
00040 {
00041     int clusterSize = int(cluster.size());
00042     double del = (m_max - m_min)/m_bins;
00043     ++m_numberHistogramsTaken;
00044 
00045     for(int i = 0; i < clusterSize ; ++i)
00046     {
00047         double rsep = sqrt((cluster[i].properties.position.x - cluster.positionCentreMass().x) * (cluster[i].properties.position.x - cluster.positionCentreMass().x) + (cluster[i].properties.position.y - cluster.positionCentreMass().y) * (cluster[i].properties.position.y - cluster.positionCentreMass().y) + (cluster[i].properties.position.z - cluster.positionCentreMass().z) * (cluster[i].properties.position.z - cluster.positionCentreMass().z));
00048 
00049         int nbin=static_cast<int>((rsep - m_min)/del);
00050         if((nbin < m_bins) && (nbin >= 0))
00051             m_histogramBin.at(nbin)++;
00052     }
00053     return;
00054 }
00055 
00056 void RadialDensityHistogram::write(int numAtoms, string base_name)
00057 {
00058 
00059     //  cout << "\n opening output file:\n";
00060     ofstream out((base_name+".rdh").c_str());
00061     out.precision(Cluster::PRECISION);
00062     out.setf(ios::scientific);
00063     out.setf(ios::showpos);
00064 
00065     double aconst=(4.0*m_pi/3.0);
00066     double del = (m_max - m_min)/m_bins;
00067 
00068     //  cout << "delr = " << delr << "\n";
00069 
00070     double rlower,rupper,ravge,vol,r;
00071     for(int i = 0; i < m_bins; ++i)
00072     {
00073         rlower=i*del + m_min;
00074         rupper=rlower + del;
00075         ravge=(rupper + rlower)/2.;
00076         vol=aconst*( pow(rupper,3) - pow(rlower,3) );
00077         if(m_histogramBin[i] != 0)
00078             r=( (double)(m_histogramBin[i]) )/(( (double)(m_numberHistogramsTaken) )*vol);
00079         else
00080             r=0.;
00081         out << ravge << " " << r << "\n";
00082     }
00083 
00084     out.close();
00085 
00086     //  cout << "\n leaving writerho:\n";
00087     return;
00088 }
00089 
00090 

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