proj home

Files   Classes   Functions   Hierarchy  

particlesampler.cpp

Go to the documentation of this file.
00001 
00002 #include <particlesampler.h>
00003 
00004 particlesampler::particlesampler
00005 (
00006   uintc & state_,
00007   uintc samplecountermax_,
00008   uintc filecountermax_,
00009   histogram<double> const hist_,
00010   string const filename_,
00011   particle const * & pi_,
00012   uintc & numParticles_
00013   ) : 
00014   state(state_), 
00015   samplecounter(0), 
00016   filecounter(0),
00017   hist(hist_),
00018   filename(filename_),
00019   pi(pi_), 
00020   numParticles(numParticles_), 
00021   samplecountermax(samplecountermax_), 
00022   filecountermax(filecountermax_)
00023 {
00024   assert(state<4);
00025 }
00026 
00027 void particlesampler::writefile()
00028 {
00029   ofstream f(filename.c_str());
00030   //assert(!f);
00031   hist.printfrequencydistpair(f);
00032   //hist.frequencydistprintxy(f);
00033 }
00034 
00035 void particlesampler::sample()
00036 {
00037   if (!state)
00038     return;
00039 
00040   samplecounter=0;
00041   for(uint i=0; i<numParticles; ++i)
00042   {
00043     double x(pi[i].vel[0]);
00044     double y(pi[i].vel[1]);
00045     switch(state)
00046     {
00047       case 1: 
00048       hist.eval( sqrt( x*x+y*y ) );
00049       break;
00050 
00051       case 2:
00052       hist.eval( x );
00053       break;
00054 
00055       case 3:
00056       hist.eval( y );
00057       break;
00058     };
00059   };
00060 
00061   ++filecounter;
00062   if ((filecounter%filecountermax)==0)
00063     writefile();
00064 }
00065 
00066 
00067 void particlesampler::reset()
00068 {
00069   assert(!filename.empty());
00070 
00071   samplecounter=0;
00072 
00073   assert(samplecountermax!=0);
00074 }
00075 
00076 void particlesampler::operator ++ ()
00077 { 
00078   ++samplecounter; 
00079   if ((samplecounter%samplecountermax)==0) 
00080     sample(); 
00081 }
00082 
00083 

Generated on Fri Mar 4 00:49:29 2011 for Chelton Evans Source by  doxygen 1.5.8