EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
EGS_AdvancedApplication Class Reference

Base class for advanced EGSnrc applications based on the mortran EGSnrc back-end. More...

#include <egs_advanced_application.h>

Inheritance diagram for EGS_AdvancedApplication:
EGS_Application

Public Member Functions

 EGS_AdvancedApplication (int argc, char **argv)
 Constructor. More...
 
virtual ~EGS_AdvancedApplication ()
 Destructor. More...
 
void setAusgabCall (AusgabCall call, bool on_or_off)
 Turns on or off a call to the user scoring function ausgab() More...
 
virtual void finishRun ()
 Finish a simulation. More...
 
int outputData ()
 Output intermediate results. More...
 
int readData ()
 Read intermediate results. More...
 
int addState (istream &)
 Add data from a parallel job. More...
 
void resetCounter ()
 Reset the application to a 'pristine' state. More...
 
int finishSimulation ()
 Finish the simulation. More...
 
void describeSimulation ()
 Describe the simulation. More...
 
EGS_I64 randomNumbersUsed () const
 Get the number of random numbers used. More...
 
void getElectronSteps (double &ch_steps, double &all_steps) const
 Get the number of condensed history and all electron steps. More...
 
virtual void saveRNGState ()
 
virtual void resetRNGState ()
 
void appInformation (const char *msg)
 
void appWarning (const char *msg)
 
void appFatal (const char *msg)
 
void startNewParticle ()
 Start the transport of a new particle. More...
 
void enterNewRegion ()
 
void setRayleighData (const vector< string > &str_medium, const vector< string > &str_file)
 Custom Rayleigh data setup. More...
 
void setEIIData (EGS_I32 len)
 Set EII flag and xsection file name. More...
 
EGS_Float getMediumRho (int ind)
 
EGS_Float getEdep ()
 
void setEdep (EGS_Float edep)
 
EGS_Float getEcut ()
 
EGS_Float getPcut ()
 
void setLatch (int latch)
 
EGS_Float getTVSTEP ()
 
EGS_InterpolatorgetDEDX (const int &imed, const int &iq)
 
void setLatch (const int &ip, const int &latch)
 
void incLatch (const int &ip, const int &increment)
 
int getNp ()
 
int getNpOld ()
 
EGS_Float getRM ()
 
void setRadiativeSplitting (const EGS_Float &nsplit)
 
- Public Member Functions inherited from EGS_Application
 EGS_Application (int argc, char **argv)
 Construct an EGSnrc application. More...
 
virtual ~EGS_Application ()
 Destruct the EGSnrc application. More...
 
virtual int initSimulation ()
 Initializes the EGSnrc application. More...
 
virtual void setSimulationChunk (EGS_I64 nstart, EGS_I64 nrun)
 Set the simulation chunk. More...
 
virtual int runSimulation ()
 Runs an EGSnrc simulation. More...
 
virtual int simulateSingleShower ()
 Simulates a single particle shower. More...
 
virtual void getCurrentResult (double &sum, double &sum2, double &norm, double &count)
 Report the current result. More...
 
virtual void analyzeResults ()
 Analyze the simulation results. More...
 
virtual void outputResults ()
 Output the simulation results. More...
 
virtual int combineResults ()
 Combine results from parallel runs. More...
 
virtual int combinePartialResults ()
 Combine intermediate results from parallel runs. More...
 
int howManyJobsDone ()
 Counts how many *.egsdat files in app folder. More...
 
EGS_InputgetInput ()
 Returns a pointer to the EGS_Input object containing the user input to the application found in the input file.
 
const string & getAppName () const
 Returns the application name.
 
const string & getEgsHome () const
 Returns the EGS_HOME directory.
 
const string & getHenHouse () const
 Returns the HEN_HOUSE directory.
 
const string & getOutputFile () const
 Returns the base name of the output file(s)
 
const string & getFinalOutputFile () const
 Returns the base name of the final output file(s) More...
 
string constructIOFileName (const char *extension, bool with_run_dir) const
 Constructs and returns the name of an input/output file. More...
 
const string & getAppDir () const
 Returns the absolute path to the user code directory.
 
const string & getRunDir () const
 Returns the name of the working directory.
 
const string & getWorkDir () const
 Returns the name of the working directory.
 
int getNparallel () const
 Returns the number of parallel jobs executing. More...
 
int getIparallel () const
 Returns the job number in a parallel run. More...
 
int getFirstParallel () const
 Returns the first job number in a parallel run. More...
 
int howfar (int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed)
 Calculates distance to a boundary along the current direction. More...
 
EGS_Float hownear (int ireg, const EGS_Vector &x)
 Calculates nearest distance to a boundary in any direction. More...
 
int getMedium (int ireg)
 Returns the medium index in region ireg using C-style indexing.
 
bool isRealRegion (int ireg)
 Returns true if ireg is a real region, false otherwise. More...
 
int isWhere (EGS_Vector &r)
 
void getNumberRegions (const string &str, vector< int > &regs)
 Gets numbers out of str and pushes them onto regs. More...
 
void getLabelRegions (const string &str, vector< int > &regs)
 Gets the regions for the labels in str and pushes onto regs. More...
 
EGS_Float getMU ()
 Returns the value of the mu synchronization parameter. More...
 
int userScoring (int iarg, int ir=-1)
 User scoring function for accumulation of results and VRT implementation. More...
 
virtual int ausgab (int)
 User scoring function. More...
 
virtual void fillRandomArray (int n, EGS_Float *rns)
 Fill an array with random numbers using the application's RNG. More...
 
virtual void describeUserCode () const
 Describe the user code. More...
 
void checkDeviceFull (FILE *)
 Check if a device holding a given stream is full.
 
EGS_Float getFluence ()
 
int getnRegions ()
 
int getnMedia ()
 
const char * getMediumName (int ind)
 
string sourceType ()
 
int sourceCharge ()
 
int sourceEmax ()
 

Protected Member Functions

int initEGSnrcBackEnd ()
 Initialize the EGSnrc mortran back-end. More...
 
int initCrossSections ()
 Initialize the run-time cross section data. More...
 
int shower ()
 Simulate a single shower. More...
 
int helpInit (EGS_Input *, bool do_hatch)
 Helper function used in initCrossSections() and describeSimulation().
 
- Protected Member Functions inherited from EGS_Application
virtual int initGeometry ()
 Initialize the simulation geometry. More...
 
virtual int initSource ()
 Initialize the particle source. More...
 
virtual int initScoring ()
 Initialize the scoring of quantities of interest. More...
 
virtual int initRunControl ()
 Construct the run control object. More...
 
virtual int initRNG ()
 Initialize the random number generator. More...
 
void initAusgabObjects ()
 Initialize ausgab objects. More...
 
void addAusgabObject (EGS_AusgabObject *o)
 Adds an ausgab object to the list of ausgab objects.
 
virtual int startNewShower ()
 Called just before the shower() function. More...
 
virtual int finishShower ()
 Called just after the shower() function. More...
 
void storeGeometryStep (int ireg, int inew, const EGS_Vector &x, const EGS_Vector &u, EGS_Float twant, EGS_Float t)
 
void reportGeometryError ()
 

Protected Attributes

int nmed
 number of media
 
EGS_Interpolatori_ededx
 electron stopping power interpolator
 
EGS_Interpolatori_pdedx
 positron stopping power interpolator
 
EGS_Interpolatori_esig
 electron cross section interpolator
 
EGS_Interpolatori_psig
 positron cross section interpolator
 
EGS_Interpolatori_ebr1
 electron branching interpolator
 
EGS_Interpolatori_pbr1
 positron branching 1 interpolator
 
EGS_Interpolatori_pbr2
 positron branching 2 interpolator
 
EGS_Interpolatori_gmfp
 photon mean-free-path interpolator
 
EGS_Interpolatori_gbr1
 photon branching 1 interpolator
 
EGS_Interpolatori_gbr2
 photon branching 2 interpolator
 
EGS_Interpolatori_cohe
 photon Rayleigh interpolator
 
EGS_Interpolatori_photonuc
 photonuclear interpolator
 
int n_rng_buffer
 Size of the RNG buffer.
 
int i_rng_buffer
 Pointer to the RNG buffer.
 
EGS_Float * rng_buffer
 RNG buffer.
 
bool final_job
 Is this the final job of a parallel run ?
 
int io_flag
 determines how to write info
 
- Protected Attributes inherited from EGS_Application
EGS_Inputinput
 the input to this simulation.
 
EGS_BaseGeometrygeometry
 the geometry of this simulation
 
EGS_BaseSourcesource
 the particle source
 
EGS_RandomGeneratorrndm
 the random number generator
 
EGS_RunControlrun
 the run control object.
 
bool ausgab_flag [UnknownCall]
 on/off flags for ausgab calls
 
string app_name
 The application name.
 
string egs_home
 The EGS_HOME directory.
 
string hen_house
 The HEN_HOUSE directory.
 
string app_dir
 The user code directory.
 
string run_dir
 The working directory during the run.
 
string egs_config
 The EGSnrc config.
 
string input_file
 The input file name.
 
string output_file
 The output file name (no extension)
 
string final_output_file
 The final output file name.
 
string pegs_file
 The pegs file name.
 
string abs_pegs_file
 The pegs file name including absolute path.
 
int n_parallel
 Number of parallel jobs.
 
int i_parallel
 Job index in parallel runs.
 
int first_parallel
 first parallel job number
 
bool batch_run
 Interactive or batch run.
 
bool simple_run
 Use a simple run control object for parallel runs.
 
bool uniform_run
 Use a uniform run control object for parallel runs.
 
bool is_pegsless
 set to true if a pegsless run
 
EGS_Particle p
 
EGS_I64 current_case
 The current case as returned from the source.
 
EGS_I64 last_case
 The last case simulated.
 
ostream * data_out
 data output stream More...
 
istream * data_in
 data input stream More...
 
int app_index
 the index of this application. More...
 
EGS_SimpleContainer
< EGS_AusgabObject * > 
a_objects_list
 The ausgab objects.
 
EGS_SimpleContainer
< EGS_AusgabObject * > * 
a_objects
 The ausgab objects for the various ausgab calls.
 
EGS_GeometryHistoryghistory
 

Static Protected Attributes

static string base_revision = " "
 Holds the CVS revision number of the egs_advanced_application.cpp file.
 

Additional Inherited Members

- Public Types inherited from EGS_Application
enum  AusgabCall {
  BeforeTransport = 0, EgsCut = 1, PegsCut = 2, UserDiscard = 3,
  ExtraEnergy = 4, AfterTransport = 5, BeforeBrems = 6, AfterBrems = 7,
  BeforeMoller = 8, AfterMoller = 9, BeforeBhabha = 10, AfterBhabha = 11,
  BeforeAnnihFlight = 12, AfterAnnihFlight = 13, BeforeAnnihRest = 28, AfterAnnihRest = 14,
  BeforePair = 15, AfterPair = 16, BeforeCompton = 17, AfterCompton = 18,
  BeforePhoto = 19, AfterPhoto = 20, EnteringUphi = 21, LeavingUphi = 22,
  BeforeRayleigh = 23, AfterRayleigh = 24, FluorescentEvent = 25, CosterKronigEvent = 26,
  AugerEvent = 27, BeforePhotoNuc = 29, AfterPhotoNuc = 30, BeforeEII = 31,
  AfterEII = 32, AfterSubPhoton = 33, AfterSubElectron = 34, UnknownCall = 35
}
 Possible calls to the user scoring function ausgab(). More...
 
- Static Public Member Functions inherited from EGS_Application
static EGS_ApplicationactiveApplication ()
 Get the active application. More...
 
static void setActiveApplication (EGS_Application *)
 Set the active EGS_Application class. More...
 
static bool getArgument (int &argc, char **argv, const char *name1, const char *name2, string &arg)
 Finds a command line argument. More...
 
static void checkEnvironmentVar (int &argc, char **argv, const char *env, const char *n1, const char *n2, string &var)
 Finds a command line argument. More...
 
- Public Attributes inherited from EGS_Application
EGS_Particle top_p
 The top particle on the stack (i.e., the particle being transported)
 
int Np
 The index of the top particle on the stack.
 

Detailed Description

Base class for advanced EGSnrc applications based on the mortran EGSnrc back-end.

The EGS_AdvancedApplication class provides implementation of functions that are specific to the mortran version of EGSnrc but independent from the user code. EGSnrc C++ application using the mortran version of EGSnrc should be derived from this class. See the EGS_Application class description for a quick guideline on writing EGSnrc C++ applications.

Examples:
tutor7pp.cpp.

Definition at line 59 of file egs_advanced_application.h.

Constructor & Destructor Documentation

EGS_AdvancedApplication::EGS_AdvancedApplication ( int  argc,
char **  argv 
)

Constructor.

The EGS_AdvancedApplication constructors basically consist of a call to the EGS_Application constructor.

Definition at line 402 of file egs_advanced_application.cpp.

EGS_AdvancedApplication::~EGS_AdvancedApplication ( )
virtual

Destructor.

Does nothing in addition to the EGS_Application destructor.

Definition at line 405 of file egs_advanced_application.cpp.

References i_cohe, i_ebr1, i_ededx, i_esig, i_gbr1, i_gbr2, i_gmfp, i_pbr1, i_pbr2, i_pdedx, i_photonuc, i_psig, n_rng_buffer, nmed, and rng_buffer.

Member Function Documentation

void EGS_AdvancedApplication::setAusgabCall ( AusgabCall  call,
bool  on_or_off 
)
virtual

Turns on or off a call to the user scoring function ausgab()

This function is re-implemented to also set the corresponding iausfl element in the the_epcont mortran back-end structure to on_or_off.

Reimplemented from EGS_Application.

Definition at line 139 of file egs_advanced_application.cpp.

References EGS_Epcont::iausfl, EGS_Application::setAusgabCall(), and the_epcont.

void EGS_AdvancedApplication::finishRun ( )
virtual

Finish a simulation.

The default implementation consists of calling the egsFinish() function, which removes the temporary working directory after moving all output to the user code directory, and the egsSetDefaultIOFunctions() function, which makes the output of egsInformation(), egsWarning() and egsFatal() to go to the application standard output and standard error.

Reimplemented from EGS_Application.

Definition at line 893 of file egs_advanced_application.cpp.

References egsFinish(), and io_flag.

Referenced by finishSimulation().

int EGS_AdvancedApplication::outputData ( )
virtual

Output intermediate results.

Re-implemented to store information from the mortran back-end in addition to the information sored by EGS_Application::outputData(). The additional data being stored is the RNG array used by the mortran backend and the number of steps taken so far.

Reimplemented from EGS_Application.

Examples:
tutor7pp.cpp.

Definition at line 947 of file egs_advanced_application.cpp.

References EGS_Application::data_out, egsWarning, and EGS_Application::outputData().

int EGS_AdvancedApplication::readData ( )
virtual

Read intermediate results.

Re-implemented to read the additional data stored by outputData().

Reimplemented from EGS_Application.

Examples:
tutor7pp.cpp.

Definition at line 976 of file egs_advanced_application.cpp.

References EGS_Application::data_in, egsWarning, and EGS_Application::readData().

int EGS_AdvancedApplication::addState ( istream &  data)
virtual

Add data from a parallel job.

Re-implemented to add the additional data stored in outputData(), i.e. the random number array used by the mortran back-end and the number of electron steps taken so far.

Reimplemented from EGS_Application.

Examples:
tutor7pp.cpp.

Definition at line 1006 of file egs_advanced_application.cpp.

References EGS_Application::addState(), and egsWarning.

void EGS_AdvancedApplication::resetCounter ( )
virtual

Reset the application to a 'pristine' state.

Re-implemented to set the number of electron steps and condensed history steps taken to zero in addition to the data reset in EGS_Application::resetCounter().

Reimplemented from EGS_Application.

Examples:
tutor7pp.cpp.

Definition at line 1041 of file egs_advanced_application.cpp.

References EGS_Application::resetCounter().

int EGS_AdvancedApplication::finishSimulation ( )
virtual

Finish the simulation.

Re-implemented to also output the combined results of parallel runs, if necessary. This part is unfortunately dependent on the mortran back-end and must therefore be done here instead of in the base class implementation. The dependence comes from the fact that when using the mortran back-end all I/O is redirected to a Fortran function so that there are no conflicts between I/O in the C++ portion and I/O in the mortran back-end.

Reimplemented from EGS_Application.

Definition at line 902 of file egs_advanced_application.cpp.

References EGS_Application::a_objects_list, EGS_Application::app_name, EGS_Application::combineResults(), describeSimulation(), EGS_Application::describeUserCode(), egsInformation, final_job, EGS_Application::final_output_file, finishRun(), EGS_RunControl::finishSimulation(), EGS_Application::finishSimulation(), EGS_Application::i_parallel, io_flag, EGS_Application::output_file, EGS_Application::outputResults(), EGS_Application::run, and the_egsio.

void EGS_AdvancedApplication::describeSimulation ( )
virtual

Describe the simulation.

Re-implemented to also output the values of the various cross section and trannsport parameter options.

Reimplemented from EGS_Application.

Definition at line 425 of file egs_advanced_application.cpp.

References EGS_Application::describeSimulation(), final_job, and helpInit().

Referenced by finishSimulation().

EGS_I64 EGS_AdvancedApplication::randomNumbersUsed ( ) const
virtual

Get the number of random numbers used.

Re-implemented to take into account the random numbers used by the mortran back-end.

Reimplemented from EGS_Application.

Definition at line 1047 of file egs_advanced_application.cpp.

References EGS_Application::randomNumbersUsed().

void EGS_AdvancedApplication::getElectronSteps ( double &  ch_steps,
double &  all_steps 
) const
virtual

Get the number of condensed history and all electron steps.

Implemented using the egsGetSteps() function provided by the mortran back-end.

Reimplemented from EGS_Application.

Definition at line 1098 of file egs_advanced_application.cpp.

void EGS_AdvancedApplication::saveRNGState ( )
virtual
void EGS_AdvancedApplication::resetRNGState ( )
virtual
void EGS_AdvancedApplication::startNewParticle ( )
virtual

Start the transport of a new particle.

This function is called just before the transport of a new particle begins and should be re-implemented in derived classes. Its default re-implementation in EGS_AdvancedApplication is to get the relative mass density in the current particle region and pass it to the Mortran back-end part of the system. It can be re-implemented in derived classes to set other quantities such as ecut, pcut, etc. in order to have such quantities varying on a region-by-region bases.

Reimplemented from EGS_Application.

Definition at line 1103 of file egs_advanced_application.cpp.

References EGS_Application::geometry, EGS_BaseGeometry::getBScaling(), EGS_BaseGeometry::getRelativeRho(), EGS_BaseGeometry::hasBScaling(), EGS_BaseGeometry::hasRhoScaling(), EGS_Stack::ir, EGS_Stack::np, EGS_Useful::rhor, EGS_Useful::rhor_new, the_emf, the_stack, and the_useful.

void EGS_AdvancedApplication::setRayleighData ( const vector< string > &  str_medium,
const vector< string > &  str_file 
)

Custom Rayleigh data setup.

Set media and corresponding ff file names for custom Rayleigh data.

Definition at line 813 of file egs_advanced_application.cpp.

References EGS_Rayleigh::ff_file, EGS_Rayleigh::ff_media, EGS_XOptions::iraylr, the_rayleigh, and the_xoptions.

Referenced by helpInit().

void EGS_AdvancedApplication::setEIIData ( EGS_I32  len)

Set EII flag and xsection file name.

The EII input is of a mixed type, i.e., one should be able to turn this option on/off, but there is also the possibility of using an arbitrary EII xsection compilation, including the available EII xsections with EGSnrc.

Definition at line 839 of file egs_advanced_application.cpp.

References EGS_XOptions::eii_flag, EGS_Media::eiixsec, the_media, and the_xoptions.

Referenced by helpInit().

int EGS_AdvancedApplication::initEGSnrcBackEnd ( )
protectedvirtual

Initialize the EGSnrc mortran back-end.

This function transfers the various file and directory names, number of pareallel jobs, parallel job index and the batch vs interactive run flag, obtained in the EGS_Application constructor from the command line arguments, to the appropriate EGSnrc common block and calls the egs_init1 mortran subroutine. If the simulation is a batch run and therefore all output should go to a log file instead of standard output/error, the egsInformation, egsWarning and egsFatal variables are changed to point to functions which redirect the output to a Fortran subroutine.

Reimplemented from EGS_Application.

Definition at line 185 of file egs_advanced_application.cpp.

References the_egsio.

int EGS_AdvancedApplication::initCrossSections ( )
protectedvirtual

Initialize the run-time cross section data.

This function initializes the cross section data and transport parameter/ cross section options. It first looks for transport parameter input within a section of the input file delimited by MC transport parameter and if found, sets parameter such as ecut, pcut, smax, ibr_nist , etc. It then adds all media present in the geometry to the mortran back-end using egsAddMedium() and calls the HATCH subroutine. If this succeeds, the various interpolators (i_ededx, i_pdedx, etc) are initialized to use the cross section data just obtained. Finally, information about the media found in the geometry along with their cutoff energies and the values of all transport parameter and cross section options are printed using egsInformation.

Reimplemented from EGS_Application.

Definition at line 432 of file egs_advanced_application.cpp.

References egsWarning, EGS_Input::getInputItem(), helpInit(), EGS_XOptions::spin_effects, and the_xoptions.

int EGS_AdvancedApplication::shower ( )
protectedvirtual

Simulate a single shower.

The default implementation of this function is to put the particle found in the protected data member p into the mortran particle stack as the first and only particle and to call egsShower().

Reimplemented from EGS_Application.

Definition at line 869 of file egs_advanced_application.cpp.

References EGS_Stack::dnear, EGS_Particle::E, EGS_Stack::E, egsShower(), EGS_Stack::iq, EGS_Particle::ir, EGS_Stack::ir, EGS_Particle::latch, EGS_Stack::latch, EGS_Stack::np, EGS_Application::p, EGS_Particle::q, EGS_Useful::rm, the_stack, the_useful, EGS_Particle::u, EGS_Stack::u, EGS_Stack::v, EGS_Stack::w, EGS_Particle::wt, EGS_Stack::wt, EGS_Vector::x, EGS_Particle::x, EGS_Stack::x, EGS_Vector::y, EGS_Stack::y, EGS_Vector::z, and EGS_Stack::z.


The documentation for this class was generated from the following files: