EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_simple_application.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ simple application headers
5 # Copyright (C) 2015 National Research Council Canada
6 #
7 # This file is part of EGSnrc.
8 #
9 # EGSnrc is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU Affero General Public License as published by the
11 # Free Software Foundation, either version 3 of the License, or (at your
12 # option) any later version.
13 #
14 # EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17 # more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ###############################################################################
23 #
24 # Author: Iwan Kawrakow, 2005
25 #
26 # Contributors:
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_SIMPLE_APPLICATION_
38 #define EGS_SIMPLE_APPLICATION_
39 
40 #include "egs_libconfig.h"
41 #include "egs_base_geometry.h"
42 
43 class EGS_BaseSource;
45 class EGS_Input;
46 
61 class APP_EXPORT EGS_SimpleApplication {
62 
63 public:
64 
65  //
66  // ******************* constructor and destructor *************************
67  //
83  EGS_SimpleApplication(int argc, char **argv);
84 
90  virtual ~EGS_SimpleApplication();
91 
92  //
93  // ************************ geometry functions **********************
94  //
97  inline int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u,
98  EGS_Float &t, int *newmed) {
99  return g->howfar(ireg,x,u,t,newmed);
100  };
103  inline EGS_Float hownear(int ireg,const EGS_Vector &x) {
104  return g->hownear(ireg,x);
105  };
107  inline int getMedium(int ireg) {
108  return g->medium(ireg);
109  };
110 
111  //
112  // ******************** ausgab ***************************************
113  //
121  virtual int ausgab(int) {
122  return 0;
123  };
124 
125  //
126  // ********* finish the simulation
127  //
134  virtual void finish();
135 
136  //
137  // ********* run a simulation
138  //
147  virtual int run();
148 
149  //
150  // ********* how often to report the progress of the simulation
151  //
155  void setNProgress(int nprog) {
156  nreport = nprog;
157  };
158 
159  //
160  // ********* functions to be executed before and after a shower.
161  //
169  virtual void startHistory(EGS_I64) {};
170 
177  virtual void endHistory() {};
178 
179  //
180  // ******** fill an array with random numbers using the random
181  // number generator of this application.
182  //
185  void fillRandomArray(int n, EGS_Float *r);
186 
187  //
188  // ******** get various directories and file names
189  //
191  const char *egsHome() const;
193  const char *henHouse() const;
195  const char *pegsFile() const;
197  const char *inputFile() const;
199  const char *outputFile() const;
201  const char *userCode() const;
203  const char *workDir() const;
204 
205  //
206  // ******** the parallel run index and number of parallel jobs
207  //
209  int iParallel() const;
211  int nParallel() const;
212 
213 protected:
214 
215  EGS_I64 ncase;
216  int nreport;
221  double sum_E,
222  sum_E2,
223  sum_w,
224  sum_w2,
225  Etot;
227  EGS_I64 last_case;
228 
229 };
230 
231 #endif
232 
233 #define APP_MAIN(app_name) \
234  int main(int argc, char **argv) { \
235  app_name app(argc,argv); \
236  app.run(); \
237  app.reportResults(); \
238  app.finish(); \
239  return 0; \
240  }
241 
242 #define APP_LIB(app_name) \
243  extern "C" {\
244  APP_EXPORT EGS_SimpleApplication* createApplication(int argc, char **argv) {\
245  return new app_name(argc,argv);\
246  }\
247  }
248 
249 
EGS_I64 ncase
Number of showers to simulate.
EGS_BaseSource * source
The particle source.
A class representing 3D vectors.
Definition: egs_vector.h:56
A base class for developing simple EGSnrc applications.
EGS_Float hownear(int ireg, const EGS_Vector &x)
See the EGSnrc hownear geometry specification .
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
virtual void startHistory(EGS_I64)
Start a new shower.
Base random number generator class. All random number generators should be derived from this class...
Definition: egs_rndm.h:67
int getMedium(int ireg)
Get the medium index in region ireg.
EGS_Input * input
The input found in the input file.
EGS_RandomGenerator * rndm
The random number generator.
int nreport
How often to report the progress.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
Defines the EGS_EXPORT and EGS_LOCAL macros.
void setNProgress(int nprog)
Set the number of times the shower loop in run() reports the progress of the simulation to nprog...
EGS_BaseGeometry class header file.
EGS_I64 last_case
last statistically independent event
double sum_w2
sum of weights squared
int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed)
See the EGSnrc howfar geometry specification .
Base source class. All particle sources must be derived from this class.
EGS_BaseGeometry * g
The simulation geometry.