EGSnrc C++ class library
Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
|
Base class for advanced EGSnrc applications based on the mortran EGSnrc back-end. More...
#include <egs_advanced_application.h>
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_Interpolator * | getDEDX (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_Input * | getInput () |
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 > ®s) |
Gets numbers out of str and pushes them onto regs. More... | |
void | getLabelRegions (const string &str, vector< int > ®s) |
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_Interpolator * | i_ededx |
electron stopping power interpolator | |
EGS_Interpolator * | i_pdedx |
positron stopping power interpolator | |
EGS_Interpolator * | i_esig |
electron cross section interpolator | |
EGS_Interpolator * | i_psig |
positron cross section interpolator | |
EGS_Interpolator * | i_ebr1 |
electron branching interpolator | |
EGS_Interpolator * | i_pbr1 |
positron branching 1 interpolator | |
EGS_Interpolator * | i_pbr2 |
positron branching 2 interpolator | |
EGS_Interpolator * | i_gmfp |
photon mean-free-path interpolator | |
EGS_Interpolator * | i_gbr1 |
photon branching 1 interpolator | |
EGS_Interpolator * | i_gbr2 |
photon branching 2 interpolator | |
EGS_Interpolator * | i_cohe |
photon Rayleigh interpolator | |
EGS_Interpolator * | i_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_Input * | input |
the input to this simulation. | |
EGS_BaseGeometry * | geometry |
the geometry of this simulation | |
EGS_BaseSource * | source |
the particle source | |
EGS_RandomGenerator * | rndm |
the random number generator | |
EGS_RunControl * | run |
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_GeometryHistory * | ghistory |
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_Application * | activeApplication () |
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. | |
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.
Definition at line 59 of file egs_advanced_application.h.
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.
|
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.
|
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.
|
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().
|
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.
Definition at line 947 of file egs_advanced_application.cpp.
References EGS_Application::data_out, egsWarning, and EGS_Application::outputData().
|
virtual |
Read intermediate results.
Re-implemented to read the additional data stored by outputData().
Reimplemented from EGS_Application.
Definition at line 976 of file egs_advanced_application.cpp.
References EGS_Application::data_in, egsWarning, and EGS_Application::readData().
|
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.
Definition at line 1006 of file egs_advanced_application.cpp.
References EGS_Application::addState(), and egsWarning.
|
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.
Definition at line 1041 of file egs_advanced_application.cpp.
References EGS_Application::resetCounter().
|
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.
|
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().
|
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().
|
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.
|
virtual |
Save the state of the RNG
Definition at line 1161 of file egs_advanced_application.cpp.
References egsFatal, i_rng_buffer, n_rng_buffer, EGS_Application::rndm, rng_buffer, and EGS_RandomGenerator::saveState().
|
virtual |
Reset the RNG state
Definition at line 1178 of file egs_advanced_application.cpp.
References i_rng_buffer, n_rng_buffer, EGS_RandomGenerator::resetState(), EGS_Application::rndm, and rng_buffer.
|
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().
|
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.
|
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.
|
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.