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

radialdistribution.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 "radialdistribution.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 RadialDistributionFunction::RadialDistributionFunction(const ConfigurationDatabase &conf):BaseHistogram(conf.doubleValue("RadialDistributionFunction", "min"), conf.doubleValue("RadialDistributionFunction", "max"), conf.intValue("RadialDistributionFunction", "bins"))
00034 {
00035     m_pullingInterval=conf.intValue("RadialDistributionFunction", "pull");
00036     m_pi=conf.doubleValue("RadialDistributionFunction", "PI");
00037 }
00038 
00039 void RadialDistributionFunction::acquire(const Cluster& cluster)
00040 {
00041     Coordinate ri,rij;
00042     double del = (m_max - m_min)/m_bins, rijsq;
00043     ++m_numberHistogramsTaken;
00044 
00045     int n = int(cluster.size());
00046 
00047     //  cout << "entering acquiregr\n";
00048     //  cout << "acquiring gr, ngr = " << ngr << "\n";
00049 
00050     /* Outer loop begins here */
00051 
00052     for(int i = 0; i < n - 1 ; ++i)
00053     {
00054 
00055         ri = cluster[i].properties.position;
00056 
00057         /* Inner loop begins here */
00058 
00059         for(int j = i + 1; j < n ; ++j)
00060         {
00061 
00062             rij = ri - cluster[j].properties.position;
00063             rijsq = rij.x*rij.x + rij.y*rij.y + rij.z*rij.z;
00064 
00065             int nbin=( (int)( (sqrt(rijsq)-m_min)/del ) );
00066             if(nbin < m_bins && nbin >= 0)
00067                 m_histogramBin.at(nbin)++;
00068         }
00069 
00070         /* End of inner loop */
00071 
00072     }
00073 
00074     /* End of outer loop */
00075 
00076     //  cout << "leaving acquiregr\n";
00077 }
00078 
00079 void RadialDistributionFunction::write(int numAtoms, string base_name)
00080 {
00081     //  cout << "\n opening output file:\n";
00082     ofstream out((base_name+".rdf").c_str());
00083     out.precision(Cluster::PRECISION);
00084     out.setf(ios::scientific);
00085     out.setf(ios::showpos);
00086 
00087     double aconst=(4.*m_pi/3.);
00088     double del = (m_max - m_min)/m_bins;
00089 
00090     //  cout << "delr = " << delr << "\n";
00091 
00092     double rlower,rupper,ravge,rnideal,gr;
00093     for(int i = 0; i < m_bins; ++i)
00094     {
00095         rlower=i*del + m_min;
00096         rupper=rlower + del;
00097         ravge=(rupper + rlower)/2.;
00098         rnideal=aconst*(pow(rupper,3) - pow(rlower,3));
00099         gr=m_histogramBin.at(i)/( 0.5*numAtoms*rnideal*1.0*m_numberHistogramsTaken );
00100         out << ravge << " " << gr << "\n";
00101     }
00102 
00103     out.close();
00104 
00105     //  cout << "\n leaving writegr:\n";
00106 }

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