Skip to content

Commit

Permalink
More elegant logging
Browse files Browse the repository at this point in the history
using particle-specific static member variables for logfile streams.
  • Loading branch information
wschreyer committed Jul 15, 2014
1 parent fda94da commit 98d1950
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 91 deletions.
14 changes: 7 additions & 7 deletions bruteforce.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct TBFIntegrator{
*
* @return Probability, that NO spin flip occured (usually close to 1).
*/
long double Integrate(long double x1, long double y1[6], long double x2, long double y2[6], TFieldManager *field, ofstream *&spinout){
long double Integrate(long double x1, long double y1[6], long double x2, long double y2[6], TFieldManager *field, ofstream &spinout){
if (gamma == 0)
return 1;

Expand Down Expand Up @@ -214,19 +214,19 @@ struct TBFIntegrator{
* @param out Output struct of Odeint integrator.
* @param BFderivs Magnetic field interpolator to print field values.
*/
void PrintBFStep(ofstream *&spinout, Output &out, TBFderivs &BFderivs){
void PrintBFStep(ofstream &spinout, Output &out, TBFderivs &BFderivs){
for (int i = 0; i < out.count; i++){
if (!spinout){
if (!spinout.is_open()){
ostringstream BFoutfile1;
BFoutfile1 << outpath << "/" << setw(12) << setfill('0') << jobnumber << setw(0) << particlename << "spin.out";
cout << "Creating " << BFoutfile1.str() << '\n';
spinout = new ofstream(BFoutfile1.str().c_str());
if(!spinout || !spinout->is_open())
spinout.open(BFoutfile1.str().c_str());
if(!spinout.is_open())
{
cout << "Could not open " << BFoutfile1.str() << '\n';
exit(-1);
}
*spinout << "t Babs Polar logPolar Ix Iy Iz Bx By Bz\n";
spinout << "t Babs Polar logPolar Ix Iy Iz Bx By Bz\n";
}

long double B[3];
Expand All @@ -238,7 +238,7 @@ struct TBFIntegrator{
BFlogpol = log10(0.5-BFpol);
else if (BFpol==0.5)
BFlogpol = 0.0;
*spinout << out.xsave[i] << " " << BFBws << " " << BFpol << " " << BFlogpol << " "
spinout << out.xsave[i] << " " << BFBws << " " << BFpol << " " << BFlogpol << " "
<< 2*out.ysave[0][i] << " " << 2*out.ysave[1][i] << " " << 2*out.ysave[2][i] << " "
<< B[0]/BFBws << " " << B[1]/BFBws << " " << B[2]/BFBws << '\n';
}
Expand Down
81 changes: 81 additions & 0 deletions electron.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ struct TElectron: TParticle{
};

protected:
static ofstream endout; ///< endlog file stream
static ofstream snapshotout; ///< snapshot file stream
static ofstream trackout; ///< tracklog file stream
static ofstream hitout; ///< hitlog file stream
static ofstream spinout; ///< spinlog file stream

/**
* This method is executed, when a particle crosses a material boundary.
*
Expand Down Expand Up @@ -115,8 +121,83 @@ struct TElectron: TParticle{

}

/**
* Write the particle's start properties and current values into a file.
*
* Calls the simple prototype TParticle::Print.
*
* @param x Current time
* @param y Current state vector
* @param polarisation Current polarisation
*/
void Print(long double x, long double y[6], int polarisation){
TParticle::Print(endout, x, y, polarisation);
};


/**
* Write the particle's start properties and current values into a file.
*
* Calls the simple prototype TParticle::Print.
*
* @param x Current time
* @param y Current state vector
* @param polarisation Current polarisation
*/
virtual void PrintSnapshot(long double x, long double y[6], int polarisation){
TParticle::Print(snapshotout, x, y, polarisation, "snapshot.out");
};


/**
* Write the particle's trajectory into a file.
*
* Calls the simple prototype TParticle::PrintTrack.
*
* @param x Current time
* @param y Current state vector
* @param polarisation Current polarisation
*/
virtual void PrintTrack(long double x, long double y[6], int polarisation){
TParticle::PrintTrack(trackout, x, y, polarisation);
};


/**
* Write the particle properties into a file, before and after it hit a material boundary.
*
* Calls the simple prototype TParticle::PrintHit.
*
* @param x Time of material hit
* @param y1 State vector before material hit
* @param y2 State vector after material hit
* @param pol1 Polarisation before material hit
* @param pol2 Polarisation after material hit
* @param normal Normal vector of hit surface
* @param leaving Material which is left at this boundary
* @param entering Material which is entered at this boundary
*/
virtual void PrintHit(long double x, long double *y1, long double *y2, int pol1, int pol2, const long double *normal, solid *leaving, solid *entering){
TParticle::PrintHit(hitout, x, y1, y2, pol1, pol2, normal, leaving, entering);
};


/**
* Get spin log stream.
*
* @return Returns static spinout stream to use same stream for all TNeutrons
*/
ofstream& GetSpinOut(){
return spinout;
};

};

ofstream TElectron::endout; ///< endlog file stream
ofstream TElectron::snapshotout; ///< snapshot file stream
ofstream TElectron::trackout; ///< tracklog file stream
ofstream TElectron::hitout; ///< hitlog file stream
ofstream TElectron::spinout; ///< spinlog file stream


#endif // ELECTRON_H_
5 changes: 2 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ int secondaries = 1; ///< should secondary particles be simulated? (read from co
long double BCutPlanePoint[9]; ///< 3 points on plane for field slice (read from config)
int BCutPlaneSampleCount1; ///< number of field samples in BCutPlanePoint[3..5]-BCutPlanePoint[0..2] direction (read from config)
int BCutPlaneSampleCount2; ///< number of field samples in BCutPlanePoint[6..8]-BCutPlanePoint[0..2] direction (read from config)
map<string, TOutput> output; ///< map assigning each simulated particle type a TOutput struct

/**
* Catch signals.
Expand Down Expand Up @@ -195,15 +194,15 @@ int main(int argc, char **argv){
for (int iMC = 1; iMC <= simcount; iMC++)
{
TParticle *p = source.CreateParticle(mc, geom, &field);
p->Integrate(SimTime, geom, mc, &field, particlein[p->name], output[p->name]); // integrate particle
p->Integrate(SimTime, geom, mc, &field, particlein[p->name]); // integrate particle
ID_counter[p->name][p->ID]++; // increment counters
ntotalsteps += p->Nstep;
IntegratorTime += p->inttime;
ReflTime += p->refltime;

if (secondaries == 1){
for (vector<TParticle*>::iterator i = p->secondaries.begin(); i != p->secondaries.end(); i++){
(*i)->Integrate(SimTime, geom, mc, &field, particlein[(*i)->name], output[(*i)->name]); // integrate secondary particles
(*i)->Integrate(SimTime, geom, mc, &field, particlein[(*i)->name]); // integrate secondary particles
ID_counter[(*i)->name][(*i)->ID]++;
ntotalsteps += (*i)->Nstep;
IntegratorTime += (*i)->inttime;
Expand Down
83 changes: 83 additions & 0 deletions neutron.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ struct TNeutron: TParticle{
};

protected:
static ofstream endout; ///< endlog file stream
static ofstream snapshotout; ///< snapshot file stream
static ofstream trackout; ///< tracklog file stream
static ofstream hitout; ///< hitlog file stream
static ofstream spinout; ///< spinlog file stream

/**
* Check for reflection on surfaces.
*
Expand Down Expand Up @@ -259,7 +265,84 @@ struct TNeutron: TParticle{
}


/**
* Write the particle's start properties and current values into a file.
*
* Calls the simple prototype TParticle::Print.
*
* @param x Current time
* @param y Current state vector
* @param polarisation Current polarisation
*/
void Print(long double x, long double y[6], int polarisation){
TParticle::Print(endout, x, y, polarisation);
};


/**
* Write the particle's start properties and current values into a file.
*
* Calls the simple prototype TParticle::Print.
*
* @param x Current time
* @param y Current state vector
* @param polarisation Current polarisation
*/
virtual void PrintSnapshot(long double x, long double y[6], int polarisation){
TParticle::Print(snapshotout, x, y, polarisation, "snapshot.out");
};


/**
* Write the particle's trajectory into a file.
*
* Calls the simple prototype TParticle::PrintTrack.
*
* @param x Current time
* @param y Current state vector
* @param polarisation Current polarisation
*/
virtual void PrintTrack(long double x, long double y[6], int polarisation){
TParticle::PrintTrack(trackout, x, y, polarisation);
};


/**
* Write the particle properties into a file, before and after it hit a material boundary.
*
* Calls the simple prototype TParticle::PrintHit.
*
* @param x Time of material hit
* @param y1 State vector before material hit
* @param y2 State vector after material hit
* @param pol1 Polarisation before material hit
* @param pol2 Polarisation after material hit
* @param normal Normal vector of hit surface
* @param leaving Material which is left at this boundary
* @param entering Material which is entered at this boundary
*/
virtual void PrintHit(long double x, long double *y1, long double *y2, int pol1, int pol2, const long double *normal, solid *leaving, solid *entering){
TParticle::PrintHit(hitout, x, y1, y2, pol1, pol2, normal, leaving, entering);
};


/**
* Get spin log stream.
*
* @return Returns static spinout stream to use same stream for all TNeutrons
*/
ofstream& GetSpinOut(){
return spinout;
};

};


ofstream TNeutron::endout; ///< endlog file stream
ofstream TNeutron::snapshotout; ///< snapshot file stream
ofstream TNeutron::trackout; ///< tracklog file stream
ofstream TNeutron::hitout; ///< hitlog file stream
ofstream TNeutron::spinout; ///< spinlog file stream


#endif // NEUTRON_H_
Loading

0 comments on commit 98d1950

Please sign in to comment.