EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_advanced_application.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ advanced application
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: Ernesto Mainegra-Hing
27 # Frederic Tessier
28 # Blake Walters
29 # Randle Taylor
30 # Reid Townson
31 #
32 ###############################################################################
33 */
34 
35 
45 #include "egs_functions.h"
46 #include "egs_interface2.h"
47 #include "egs_run_control.h"
48 #include "egs_base_source.h"
49 #include "egs_input.h"
50 #include "egs_interpolator.h"
51 #include "egs_rndm.h"
52 #include "egs_math.h"
53 #include "egs_ausgab_object.h"
54 
55 #include <string>
56 #include <cstdio>
57 #include <cstdarg>
58 #include <cstdlib>
59 #include <cstring>
60 
61 using namespace std;
62 
63 #ifdef DEBUG_APPLICATION
64 #define CHECK_GET_APPLICATION(a,b) \
65  EGS_Application *a = EGS_Application::activeApplication(); \
66  if( !a ) egsFatal("%s: no active application!\n",b);
67 #else
68 #define CHECK_GET_APPLICATION(a,b) \
69  EGS_Application *a = EGS_Application::activeApplication();
70 #endif
71 
73 
74 /*
75 extern __extc__ struct EGS_Stack F77_OBJ(stack,STACK);
76 extern __extc__ struct EGS_Bounds F77_OBJ(bounds,BOUNDS);
77 extern __extc__ struct EGS_Thresh F77_OBJ(thresh,THRESH);
78 extern __extc__ struct EGS_Epcont F77_OBJ(epcont,EPCONT);
79 extern __extc__ struct EGS_EtControl F77_OBJ_(et_control,ET_CONTROL);
80 extern __extc__ struct EGS_Media F77_OBJ(media,MEDIA);
81 extern __extc__ struct EGS_Useful F77_OBJ(useful,USEFUL);
82 extern __extc__ struct EGS_XOptions F77_OBJ_(xsection_options,XSECTION_OPTIONS);
83 extern __extc__ struct EGS_IO F77_OBJ_(egs_io,EGS_IO);
84 extern __extc__ struct EGS_VarianceReduction F77_OBJ_(egs_vr,EGS_VR);
85 
86 struct EGS_Stack *the_stack = & F77_OBJ(stack,STACK);
87 struct EGS_Bounds *the_bounds = & F77_OBJ(bounds,BOUNDS);
88 struct EGS_Thresh *the_thresh = & F77_OBJ(thresh,THRESH);
89 struct EGS_Epcont *the_epcont = & F77_OBJ(epcont,EPCONT);
90 struct EGS_EtControl *the_etcontrol = & F77_OBJ_(et_control,ET_CONTROL);
91 struct EGS_Media *the_media = & F77_OBJ(media,MEDIA);
92 struct EGS_Useful *the_useful = & F77_OBJ(useful,USEFUL);
93 struct EGS_XOptions *the_xoptions = & F77_OBJ_(xsection_options,XSECTION_OPTIONS);
94 struct EGS_IO *the_egsio = & F77_OBJ_(egs_io,EGS_IO);
95 struct EGS_VarianceReduction *the_egsvr = & F77_OBJ_(egs_vr,EGS_VR);
96 */
97 
98 #define egsGetRNGPointers F77_OBJ_(egs_get_rng_pointers,EGS_GET_RNG_POINTERS)
99 extern __extc__ void egsGetRNGPointers(EGS_I32 *, EGS_I32 *);
100 #define egsGetRNGArray F77_OBJ_(egs_get_rng_array,EGS_GET_RNG_ARRAY)
101 extern __extc__ void egsGetRNGArray(EGS_Float *);
102 #define egsSetRNGState F77_OBJ_(egs_set_rng_state,EGS_SET_RNG_STATE)
103 extern __extc__ void egsSetRNGState(const EGS_I32 *, const EGS_Float *);
104 #define egsGetSteps F77_OBJ_(egs_get_steps,EGS_GET_STEPS)
105 extern __extc__ void egsGetSteps(double *, double *);
106 #define egsSetSteps F77_OBJ_(egs_set_steps,EGS_SET_STEPS)
107 extern __extc__ void egsSetSteps(const double *, const double *);
108 #define egsOpenUnits F77_OBJ_(egs_open_units,EGS_OPEN_UNITS)
109 extern __extc__ void egsOpenUnits(const EGS_I32 *);
110 #define egsGetElectronData F77_OBJ_(egs_get_electron_data,EGS_GET_ELECTRON_DATA)
111 extern __extc__ void egsGetElectronData(void (*func)(EGS_I32 *,EGS_Float *,
112  EGS_Float *,EGS_Float *,EGS_Float *),const EGS_I32 *,const EGS_I32 *);
113 #define egsGetPhotonData F77_OBJ_(egs_get_photon_data,EGS_GET_PHOTON_DATA)
114 extern __extc__ void egsGetPhotonData(void (*func)(EGS_I32 *,EGS_Float *,
115  EGS_Float *,EGS_Float *,EGS_Float *),const EGS_I32 *,const EGS_I32 *);
116 
117 static EGS_Float *__help1, *__help2, *__help3, *__help4;
118 static EGS_I32 *__ihelp;
119 static void __help_get_data(EGS_I32 *nbin,EGS_Float *emin, EGS_Float *emax,
120  EGS_Float *a, EGS_Float *b) {
121  __ihelp = nbin;
122  __help1 = emin;
123  __help2 = emax;
124  __help3 = a;
125  __help4 = b;
126 }
127 
128 static void __init_interpolator(int q, int imed, int type,
129  EGS_Interpolator &i) {
130  if (q) {
131  egsGetElectronData(__help_get_data,&imed,&type);
132  }
133  else {
134  egsGetPhotonData(__help_get_data,&imed,&type);
135  }
136  i.initialize(*__ihelp,*__help1,*__help2,__help3,__help4);
137 }
138 
140  \
141  EGS_Application::setAusgabCall(call,on_or_off);
142  the_epcont->iausfl[call] = (int) on_or_off;
143 }
144 
145 static EGS_LOCAL void __egs_iovar(int nio, int ns,
146  const char *source, char *var) {
147  if (ns > nio-1) {
148  egsFatal("Mortran variable is not long enough to hold %s\n",source);
149  }
150  int j;
151  for (j=0; j<ns; j++) {
152  var[j] = source[j];
153  }
154  var[ns] = 0;
155  for (j=ns+1; j<nio; j++) {
156  var[j] = ' ';
157  }
158 }
159 
160 static EGS_LOCAL char __write_buf[8192];
161 extern __extc__ void F77_OBJ_(egs_write_string,EGS_WRITE_STRING)(int *,
162  const char *,int);
163 void EGS_LOCAL __write_to_fortran_file(const char *msg, ...) {
164  va_list ap;
165  va_start(ap, msg);
166  vsprintf(__write_buf,msg,ap);
167  va_end(ap);
168  int ounit=the_egsio->i_log;
169  F77_OBJ_(egs_write_string,EGS_WRITE_STRING)(&ounit,__write_buf,
170  strlen(__write_buf));
171 }
172 void EGS_LOCAL __write_to_fortran_file_and_exit(const char *msg, ...) {
173  va_list ap;
174  va_start(ap, msg);
175  vsprintf(__write_buf,msg,ap);
176  va_end(ap);
177  int ounit=the_egsio->i_log;
178  F77_OBJ_(egs_write_string,EGS_WRITE_STRING)(&ounit,__write_buf,
179  strlen(__write_buf));
180  exit(1);
181 }
182 
183 extern __extc__ void F77_OBJ_(egs_set_defaults,EGS_SET_DEFAULTS)();
184 extern __extc__ void F77_OBJ_(egs_init1,EGS_INIT1)();
186  F77_OBJ_(egs_set_defaults,EGS_SET_DEFAULTS)();
187  __egs_iovar(64,app_name.size(),app_name.c_str(),the_egsio->user_code);
188  __egs_iovar(128,hen_house.size(),hen_house.c_str(),the_egsio->hen_house);
189  __egs_iovar(128,egs_home.size(),egs_home.c_str(),the_egsio->egs_home);
190  __egs_iovar(256,input_file.size(),input_file.c_str(),the_egsio->input_file);
191  __egs_iovar(256,final_output_file.size(),final_output_file.c_str(),
192  the_egsio->output_file);
193  __egs_iovar(256,pegs_file.size(),pegs_file.c_str(),the_egsio->pegs_file);
194  the_egsio->i_parallel = i_parallel;
195  the_egsio->n_parallel = n_parallel;
196  the_egsio->is_pegsless = is_pegsless;
197  if (run) {
198  the_egsio->n_chunk = run->getNchunk();
199  }
200  the_egsio->is_batch = (int) batch_run;
201  F77_OBJ_(egs_init1,EGS_INIT1)();
202  /*
203  if( batch_run ) {
204  egsSetInfoFunction(Information,__write_to_fortran_file);
205  egsSetInfoFunction(Warning,__write_to_fortran_file);
206  egsSetInfoFunction(Fatal,__write_to_fortran_file_and_exit);
207  }
208  */
209  io_flag = 1;
210  return 0;
211 }
212 
213 /* The following 2 functions were used in an attempt to redirect
214  all fortran I/O to use egsInformationn a degsWarning.
215  Unfortunately, there were segmentation violations in the
216  fortran I/O functions that I don't understand.
217 
218 extern __extc__ void F77_OBJ_(egs_info_output,EGS_INFO_OUTPUT)
219  (char *msg, int len) {
220  int j; for(j=len-1; j>=0; j--) if( !isspace(msg[j]) ) break;
221  if( j<len-1 ) ++j;
222  char c = msg[j]; msg[j] = 0;
223  egsInformation("%s\n",msg);
224  msg[j] = c;
225 }
226 
227 extern __extc__ void F77_OBJ_(egs_warning_output,EGS_WARNING_OUTPUT)
228  (char *msg, int len) {
229  int j; for(j=len-1; j>=0; j--) if( !isspace(msg[j]) ) break;
230  if( j<len-1 ) ++j;
231  char c = msg[j]; msg[j] = 0;
232  egsWarning("%s\n",msg);
233  msg[j] = c;
234 }
235 */
236 
237 #ifndef SKIP_DOXYGEN
238 
245 class EGS_LOCAL EGS_TransportProperty {
246 
247  string name;
248  vector<string> options;
249  vector<string> *str_v;
250  vector<EGS_Float> *f_v;
251  string charinp;
252  int type;
253  EGS_I32 *int_input;
254  EGS_Float *float_input;
255  int len,nitem;
256  char *char_input;
257 
258 public:
259 
260  /* Integer input type = 0 */
261  EGS_TransportProperty(const char *Name, EGS_I32 *val) :
262  name(Name), type(0), int_input(val) {};
263  /* Real input type = 1 */
264  EGS_TransportProperty(const char *Name, EGS_Float *val) :
265  name(Name), type(1), float_input(val) {};
266  /* Character string input type = 3 */
267  EGS_TransportProperty(const char *Name, int L, char *val) :
268  name(Name), type(3), len(L), char_input(val) {};
269  /* Character string array input type = 4 */
270  EGS_TransportProperty(const char *Name,int L,int N,vector<string> *str):
271  name(Name), str_v(str), type(4), len(L), nitem(N) {};
272  /* Real array input type = 5 */
273  EGS_TransportProperty(const char *Name,int N,vector<EGS_Float> *f):
274  name(Name), f_v(f), type(5), nitem(N) {};
275  /* Integer input with allowed values => type = 2 */
276  void addOption(const char *opt) {
277  options.push_back(opt);
278  type = 2;
279  };
280  void setOption(const int &index, const char *opt) {
281  options[index] = opt;
282  };
283  void getInput(EGS_Input *input) {
284  if (type == 1) {
285  EGS_Float aux;
286  int err = input->getInput(name,aux);
287  if (!err) {
288  *float_input = aux;
289  }
290  }
291  else if (type == 0) {
292  EGS_I32 aux;
293  int err = input->getInput(name,aux);
294  if (!err) {
295  *int_input = aux;
296  }
297  }
298  else if (type == 3) {
299  int err = input->getInput(name,charinp);
300  if (!err) {
301  int l = charinp.size();
302  if (l > len) {
303  l = len;
304  }
305  int j;
306  for (j=0; j<l; j++) {
307  char_input[j] = charinp[j];
308  }
309  for (j=l; j<len; j++) {
310  char_input[j] = ' ';
311  }
312  }
313  else {
314  charinp = string(char_input).substr(0,len);
315  }
316  }
317  else if (type == 4) {
318  int err = input->getInput(name,*str_v);
319  if (!err) {
320  vector<string> str = *str_v;
321  str_v->clear();
322  int number = str.size();
323  if (number>nitem) {
324  str.erase(str.begin()+nitem,str.end());
325  number=nitem;
326  }
327  for (int i=0; i<number; i++) {
328  if (str[i].size()>len) {
329  str[i] = str[i].substr(0,len);
330  }
331  }
332  *str_v = str;
333  }
334  }
335  else if (type == 5) {
336  int err = input->getInput(name,*f_v);
337  if (!err) {
338  vector<EGS_Float> fv = *f_v;
339  f_v->clear();
340  int number = fv.size();
341  if (number>nitem) {
342  fv.erase(fv.begin()+nitem,fv.end());
343  number=nitem;
344  }
345  *f_v = fv;
346  }
347  }
348  else {
349  bool is_ok;
350  EGS_I32 iaux = input->getInput(name,options,0,&is_ok);
351  if (is_ok) {
352  *int_input = iaux;
353  }
354  egsWarning("Property %s: %d\n",name.c_str(),*int_input);
355  }
356  };
357  void info(int nc) {
358  egsInformation("%s",name.c_str());
359  for (int j=name.size(); j<nc; j++) {
360  egsInformation(" ");
361  }
362  if (type == 0) {
363  egsInformation("%d\n",*int_input);
364  }
365  else if (type == 1) {
366  egsInformation("%g\n",*float_input);
367  }
368  else if (type == 3) {
369  egsInformation("%s\n",(string(char_input).substr(0,len)).c_str());
370  }
371  else if (type == 5) {
372  for (vector<EGS_Float>::iterator it = f_v->begin() ; it != f_v->end(); ++it) {
373  egsInformation("%g ",*it);
374  }
375  egsInformation("\n");
376  }
377  else {
378  egsInformation("%s\n",options[*int_input].c_str());
379  }
380  };
381  int size() {
382  if (type == 1) {
383  return sizeof(EGS_Float);
384  }
385  else if (type == 3) {
386  return len;
387  }
388  else if (type == 4) {
389  return nitem;
390  }
391  else if (type == 5) {
392  return f_v->size();
393  }
394  else {
395  return sizeof(EGS_I32);
396  }
397  };
398 
399 };
400 #endif
401 
403  EGS_Application(argc,argv), nmed(0), n_rng_buffer(0), final_job(false), io_flag(0) { }
404 
406  if (n_rng_buffer > 0) {
407  delete [] rng_buffer;
408  }
409  if (nmed > 0) {
410  delete [] i_ededx;
411  delete [] i_pdedx;
412  delete [] i_esig;
413  delete [] i_psig;
414  delete [] i_ebr1;
415  delete [] i_pbr1;
416  delete [] i_pbr2;
417  delete [] i_gmfp;
418  delete [] i_gbr1;
419  delete [] i_gbr2;
420  delete [] i_cohe;
421  delete [] i_photonuc;
422  }
423 }
424 
427  if (final_job) {
428  helpInit(0,false);
429  }
430 }
431 
433  egsWarning("In initCrossSections(): spin effects = %d\n",
435  EGS_Input *transportp = input->getInputItem("MC transport parameter");
436  if (!transportp) {
437  transportp = input->getInputItem("transport parameter");
438  }
439  return helpInit(transportp,true);
440 }
441 
442 extern "C" void F77_OBJ_(set_elastic_parameter,SET_ELASTIC_PARAMETER)();
443 
444 int EGS_AdvancedApplication::helpInit(EGS_Input *transportp, bool do_hatch) {
445  if (!geometry) {
446  egsWarning("initCrossSections(): no geometry?\n");
447  return 1;
448  }
450  int nmed_new = EGS_BaseGeometry::nMedia(), j;
451  if (nmed_new < 1) {
452  egsWarning("initCrossSections(): no media in this geometry?\n");
453  return 2;
454  }
455  int nmed_old = nmed;
456  nmed = nmed_new;
457  int *ind = new int [nmed];
458  for (j=0; j<nmed; j++) {
459  const char *medname = geometry->getMediumName(j);
460  int len = strlen(medname);
461  ind[j] = egsAddMedium(medname, len);
462  }
463 
464  vector<string> ff_media, ff_names;
465  string eii_xsect;
466  vector<EGS_Float> efield_v, bfield_v;
467  //
468  // The Intel compiler uses -1 for .true. => all logical
469  // variables don't work!
470  // This is a fix for this
471  //
472  if (the_xoptions->spin_effects != 0) {
474  }
475  //if( the_xoptions->exact_bca != 0 ) the_xoptions->exact_bca=1;
476 
477  //
478  // See if there are transport parameters set in the input file.
479  //
480  EGS_TransportProperty efield("Electric Field",3,&efield_v);
481  EGS_TransportProperty bfield("Magnetic Field",3,&bfield_v);
482  EGS_TransportProperty estepem("EM ESTEPE",&the_emf->EMLMTIN);
483  EGS_TransportProperty ecut("Global Ecut",&the_bounds->ecut);
484  EGS_TransportProperty pcut("Global Pcut",&the_bounds->pcut);
485  EGS_TransportProperty smax("Global Smax",&the_etcontrol->smaxir);
486  EGS_TransportProperty estep("ESTEPE",&the_etcontrol->estepe);
487  EGS_TransportProperty ximax("Ximax",&the_etcontrol->ximax);
488  EGS_TransportProperty skind("Skin depth for BCA",
490  EGS_TransportProperty pxsec("Photon cross sections",16,the_media->pxsec);
491  EGS_TransportProperty pxsec_out("Photon cross-sections output",&the_egsio->xsec_out);
492  pxsec_out.addOption("Off");
493  pxsec_out.addOption("On");
494  EGS_TransportProperty cxsec("Compton cross sections",16,the_media->compxsec);
495  EGS_TransportProperty bc("Bound Compton scattering",&the_xoptions->ibcmp);
496  bc.addOption("Off");
497  bc.addOption("On");
498  bc.addOption("Simple");
499  bc.addOption("norej");
500  EGS_TransportProperty radc("Radiative Compton corrections",
502  radc.addOption("Off");
503  radc.addOption("On");
504  /* Photonuclear input parameters */
505  EGS_TransportProperty photonucxsec("Photonuclear cross sections",16,the_media->photonucxsec);
506  EGS_TransportProperty photonuc("Photonuclear attenuation",&the_xoptions->iphotonuc);
507  photonuc.addOption("Off");
508  photonuc.addOption("On");
509 
510  EGS_TransportProperty rayl("Rayleigh scattering",&the_xoptions->iraylr);
511  rayl.addOption("Off");
512  rayl.addOption("On");
513  rayl.addOption("custom");
514  EGS_TransportProperty ff_med("ff media names",24,MXMED,&ff_media);
515  EGS_TransportProperty ff_files("ff file names",128,MXMED, &ff_names);
516 
517  EGS_TransportProperty relax("Atomic relaxations",&the_xoptions->iedgfl);
518  relax.addOption("Off");
519  relax.addOption("On");
520  relax.addOption("eadl");
521  relax.addOption("simple");
522 
523  EGS_TransportProperty iphter("Photoelectron angular sampling",
524  &the_xoptions->iphter);
525  iphter.addOption("Off");
526  iphter.addOption("On");
527  EGS_TransportProperty spin("Spin effects",&the_xoptions->spin_effects);
528  spin.addOption("Off");
529  spin.addOption("On");
530  EGS_TransportProperty trip("Triplet production",&the_xoptions->itriplet);
531  trip.addOption("Off");
532  trip.addOption("On");
533  EGS_TransportProperty eii("Electron Impact Ionization",16,the_media->eiixsec);
534  EGS_TransportProperty brem("Brems cross sections",&the_xoptions->ibr_nist);
535  brem.addOption("BH");
536  brem.addOption("NIST");
537  brem.addOption("NRC");
538  EGS_TransportProperty bang("Brems angular sampling",&the_xoptions->ibrdst);
539  bang.addOption("Simple");
540  bang.addOption("KM");
541  EGS_TransportProperty pair("Pair cross sections",&the_xoptions->pair_nrc);
542  pair.addOption("BH");
543  pair.addOption("NRC");
544  EGS_TransportProperty pang("Pair angular sampling",&the_xoptions->iprdst);
545  pang.addOption("Off");
546  pang.addOption("Simple");
547  pang.addOption("KM");
548  pang.addOption("Uniform");
549  pang.addOption("Blend");
550  EGS_TransportProperty tran("Electron-step algorithm",
552  tran.addOption("EGSnrc");
553  tran.addOption("PRESTA-I");
554  tran.addOption("PRESTA-II");
555  tran.addOption("default");
556  EGS_TransportProperty bca("Boundary crossing algorithm",
558  bca.addOption("Exact");
559  bca.addOption("PRESTA-I");
560 
561  if (transportp) {
562  efield.getInput(transportp);
563  bfield.getInput(transportp);
564  estepem.getInput(transportp);
565  ecut.getInput(transportp);
566  pcut.getInput(transportp);
567  smax.getInput(transportp);
569  estep.getInput(transportp);
570  ximax.getInput(transportp);
571  skind.getInput(transportp);
572  pxsec.getInput(transportp);
573  pxsec_out.getInput(transportp);
574  cxsec.getInput(transportp);
575  photonucxsec.getInput(transportp);
576  photonuc.getInput(transportp);
577  bc.getInput(transportp);
578  radc.getInput(transportp);
579  rayl.getInput(transportp);
580  if (the_xoptions->iraylr>1) {
581  ff_med.getInput(transportp);
582  ff_files.getInput(transportp);
583  setRayleighData(ff_media,ff_names);
584  }
585  relax.getInput(transportp);
586  if (the_xoptions->iedgfl == 0 || the_xoptions->iedgfl == 3) {
587  the_xoptions->eadl_relax = 0;
588  }
589  else {
590  the_xoptions->eadl_relax = 1;
591  // Now, 'On' means EADL relaxation
592  if (the_xoptions->iedgfl == 1) {
593  relax.setOption(1,"eadl");
594  }
595  }
596  iphter.getInput(transportp);
597  spin.getInput(transportp);
598  trip.getInput(transportp);
599  eii.getInput(transportp);
600  setEIIData(eii.size());
601  brem.getInput(transportp);
602  bang.getInput(transportp);
603  pair.getInput(transportp);
604  pang.getInput(transportp);
605  tran.getInput(transportp);
608  }
609  bca.getInput(transportp);
610 
611  if (egsEquivStr(string("mcdf-xcom "),
612  string(the_media->pxsec).substr(0,pxsec.size()))) {
613  the_xoptions->mcdf_pe_xsections = 1;
614  string("xcom ").copy(the_media->pxsec,16,0);
615  }
616  else if (egsEquivStr(string("mcdf-epdl "),
617  string(the_media->pxsec).substr(0,pxsec.size()))) {
618  the_xoptions->mcdf_pe_xsections = 1;
619  string("epdl ").copy(the_media->pxsec,16,0);
620  }
621  else {
622  the_xoptions->mcdf_pe_xsections = 0;
623  }
624 
625  // iedgfl == 3 implies eadl_relax == 0
626  if (the_xoptions->iedgfl == 3 &&
627  the_xoptions->mcdf_pe_xsections == 1) {
628  egsWarning("\n**** Warning:"
629  "\n Simplified atomic relaxation not allowed"
630  "\n with shellwise PE cross sections. Resetting"
631  "\n to detailed EADL atomic relaxation!!!\n\n");
632  the_xoptions->eadl_relax = 1;
633  the_xoptions->iedgfl = 2;
634  relax.setOption(1,"eadl");
635  }
636  delete transportp;
637  }
638 
639  if (do_hatch) {
640 
641  egsHatch();
642  F77_OBJ_(set_elastic_parameter,SET_ELASTIC_PARAMETER)();
643 
646 
647  if (nmed_old > 0) {
648  delete [] i_ededx;
649  delete [] i_pdedx;
650  delete [] i_esig;
651  delete [] i_psig;
652  delete [] i_ebr1;
653  delete [] i_pbr1;
654  delete [] i_pbr2;
655  delete [] i_gmfp;
656  delete [] i_gbr1;
657  delete [] i_gbr2;
658  delete [] i_cohe;
659  delete [] i_photonuc;
660  }
661  if (nmed > 0) {
662  i_ededx = new EGS_Interpolator [nmed];
663  i_pdedx = new EGS_Interpolator [nmed];
664  i_esig = new EGS_Interpolator [nmed];
665  i_psig = new EGS_Interpolator [nmed];
666  i_ebr1 = new EGS_Interpolator [nmed];
667  i_pbr1 = new EGS_Interpolator [nmed];
668  i_pbr2 = new EGS_Interpolator [nmed];
669  i_gmfp = new EGS_Interpolator [nmed];
670  i_gbr1 = new EGS_Interpolator [nmed];
671  i_gbr2 = new EGS_Interpolator [nmed];
672  i_cohe = new EGS_Interpolator [nmed];
674  for (int imed=0; imed<nmed; imed++) {
675  int type;
676  int imed1 = imed+1;
677  type = 3;
678  __init_interpolator(1,imed1,type,i_ededx[imed]);
679  type = 4;
680  __init_interpolator(1,imed1,type,i_pdedx[imed]);
681  type = 1;
682  __init_interpolator(1,imed1,type,i_esig[imed]);
683  type = 2;
684  __init_interpolator(1,imed1,type,i_psig[imed]);
685  type = 5;
686  __init_interpolator(1,imed1,type,i_ebr1[imed]);
687  type = 6;
688  __init_interpolator(1,imed1,type,i_pbr1[imed]);
689  type = 7;
690  __init_interpolator(1,imed1,type,i_pbr2[imed]);
691  type = 1;
692  __init_interpolator(0,imed1,type,i_gmfp[imed]);
693  type = 2;
694  __init_interpolator(0,imed1,type,i_gbr1[imed]);
695  type = 3;
696  __init_interpolator(0,imed1,type,i_gbr2[imed]);
697  type = 4;
698  __init_interpolator(0,imed1,type,i_cohe[imed]);
699  type = 5;
700  __init_interpolator(0,imed1,type,i_photonuc[imed]);
701  }
702  }
703  }
704 
705  egsInformation("\n\nThe following media are defined:\n"
706  "================================\n\n");
707  EGS_Float Emax = source ? source->getEmax() : 0;
708  bool data_ok = true;
709  for (j=0; j<nmed; j++) {
710  int imed = ind[j]-1;
711  egsInformation("%3d %-24s AE=%7.4f AP=%7.4f %d\n",j,
712  geometry->getMediumName(j),the_thresh->ae[imed],
713  the_thresh->ap[imed],imed);
714  if (Emax > the_thresh->ue[imed]-the_useful->rm ||
715  Emax > the_thresh->up[imed]) {
716  egsInformation(" upper limits (UE=%g UP=%g) not enough for "
717  "maximum source energy (%g)\n",the_thresh->ue[imed],
718  the_thresh->up[imed],Emax);
719  data_ok = false;
720  }
721  }
722  if (!data_ok) {
723  delete [] ind;
724  return 3;
725  }
726 
727  egsInformation("\n\nTransport parameter and cross section options:\n"
728  "==============================================\n");
729  int nc = 50;
730  // Recover initial input string to reflect what's actually being used
731  // the_media->pxsec was already used in egsHatch() to read photon data
732  if (the_xoptions->mcdf_pe_xsections &&
733  egsEquivStr(string("xcom "),
734  string(the_media->pxsec).substr(0,pxsec.size()))) {
735  string("mcdf-xcom ").copy(the_media->pxsec,16,0);
736  }
737  else if (the_xoptions->mcdf_pe_xsections &&
738  egsEquivStr(string("epdl "),
739  string(the_media->pxsec).substr(0,pxsec.size()))) {
740  string("mcdf-epdl ").copy(the_media->pxsec,16,0);
741  }
742 
743  if (!isspace(the_media->pxsec[0])) {
744  pxsec.info(nc);
745  }
746  if (!isspace(the_media->compxsec[0])) {
747  cxsec.info(nc);
748  }
749  pcut.info(nc);
750  pair.info(nc);
751  pang.info(nc);
752  trip.info(nc);
753  bc.info(nc);
754  radc.info(nc);
755  rayl.info(nc);
756  relax.info(nc);
757  iphter.info(nc);
758  photonuc.info(nc);
759  photonucxsec.info(nc);
760  egsInformation("\n");
761  ecut.info(nc);
762  brem.info(nc);
763  bang.info(nc);
764  spin.info(nc);
765  eii.info(nc);
766  smax.info(nc);
767  estep.info(nc);
768  ximax.info(nc);
769  bca.info(nc);
770  skind.info(nc);
771  tran.info(nc);
772  if (efield.size()==3) {
773  efield.info(nc);
774  the_emf->ExIN=efield_v[0];
775  the_emf->EyIN=efield_v[1];
776  the_emf->EzIN=efield_v[2];
777  if (efield_v[0]*efield_v[0]+efield_v[1]*efield_v[1]+efield_v[2]*efield_v[2] > 0) {
778  the_emf->emfield_on = true;
779  }
780 
781  }
782  if (bfield.size()==3) {
783  bfield.info(nc);
784  the_emf->BxIN=bfield_v[0];
785  the_emf->ByIN=bfield_v[1];
786  the_emf->BzIN=bfield_v[2];
787  the_emf->Bx=bfield_v[0];
788  the_emf->By=bfield_v[1];
789  the_emf->Bz=bfield_v[2];
790  }
791  if (efield.size()==3 || bfield.size()==3) {
792  estepem.info(nc);
793  if (bfield_v[0]*bfield_v[0]+bfield_v[1]*bfield_v[1]+bfield_v[2]*bfield_v[2] > 0) {
794  the_emf->emfield_on = true;
795  }
796  }
797  egsInformation("==============================================\n\n");
798 
799  delete [] ind;
800  return 0;
801 }
802 
803 /**********************************************************************
804  Set media and corresponding ff file names for custom Rayleigh data
805 
806  Since the_xoptions->iraylr is reset to 1 here, output will only
807  indicate coherent scatter is on, but not whether custom input
808  requested. Perhaps should make EGS check for iraylm(medium)>0
809  instead of iraylm(medium)=1. The latter has been kept over
810  the years for historic reasons.
811  EMH April 6th 2011
812 **********************************************************************/
814  const vector<string> &str_medium,
815  const vector<string> &str_file) {
816  the_xoptions->iraylr=1;
817  int i,k;
818  for (i=0; i<str_medium.size(); i++) {
819  for (k=0; k<str_medium[i].size(); k++) {
820  the_rayleigh->ff_media[i][k]= str_medium[i][k];
821  }
822  }
823  for (i=0; i<str_file.size(); i++) {
824  for (k=0; k<str_file[i].size(); k++) {
825  the_rayleigh->ff_file[i][k]=str_file[i][k];
826  }
827  }
828 }
829 
830 /**********************************************************************
831  Set EII flag and xsection file name.
832 
833  The EII input is of a mixed type, i.e., one should be able to turn
834  this option on/off, but there is also the possibility of using an
835  arbitrary EII xsection compilation, including the available EII
836  xsections with EGSnrc.
837  EMH April 6th 2011
838 **********************************************************************/
840  string str_eii,off,on;
841  the_xoptions->eii_flag = 1;
842  string ik="ik";
843  for (int i=0; i<len; i++) {
844  str_eii += toupper(the_media->eiixsec[i]);
845  off+=' ';
846  on+=' ';
847  }
848  off[0]='O';
849  off[1]='F';
850  off[2]='F';
851  on[0]='O';
852  on[1]='N';
853  if (str_eii == off) {
854  the_xoptions->eii_flag = 0;
855  }
856  else if (str_eii == on) {
857  ik.copy(the_media->eiixsec,16,0);
858  }
859 }
860 
861 #ifdef GDEBUG
862  #define MAX_STEP 100000
863  EGS_Vector steps_x[MAX_STEP], steps_u[MAX_STEP];
864  int steps_ireg[MAX_STEP], steps_inew[MAX_STEP];
865  EGS_Float steps_ustepi[MAX_STEP], steps_ustepf[MAX_STEP];
866  int steps_n = 0;
867 #endif
868 
870  if (!p.wt) {
871  return 0;
872  }
873  the_stack->E[0] = (p.q) ? p.E + the_useful->rm : p.E;
874  the_stack->x[0] = p.x.x;
875  the_stack->y[0] = p.x.y;
876  the_stack->z[0] = p.x.z;
877  the_stack->u[0] = p.u.x;
878  the_stack->v[0] = p.u.y;
879  the_stack->w[0] = p.u.z;
880  the_stack->dnear[0] = 0;
881  the_stack->wt[0] = p.wt;
882  the_stack->ir[0] = p.ir + 2;
883  the_stack->iq[0] = p.q;
884  the_stack->latch[0] = p.latch;
885  the_stack->np = 1;
886 #ifdef GDEBUG
887  steps_n = 0;
888 #endif
889  egsShower();
890  return 0;
891 }
892 
894  egsFinish();
895  //egsSetDefaultIOFunctions();
896  io_flag = 0;
897  // so that if extra output is being produced somewhere, it does not
898  // go to fort.6 as it would without this as all fortran units are
899  // closed after egsFinish().
900 }
901 
904  egsInformation("finishSimulation(%s) %d\n",app_name.c_str(),err);
905  if (err <= 0) {
906  return err;
907  }
908  //egsInformation("\n\n********** I'm last job! **********\n\n");
909  //return 0;
910  // if err is positive, this is the last job in a parallel run
911  // => we have to combine the results
912  // EGS_Application::finishSimulation() has already called
913  // our finishRun() which has called egs_finish => all data has been
914  // moved to the user code directory and the working directory has been
915  // reset to be the user code directory. We must now reset the
916  // output_file name and re-open units.
918  the_egsio->i_parallel = 0;
919  i_parallel=0;
920  int flag = 0;
921  egsOpenUnits(&flag);
922  // The following is necessary because finishRun() was called from
923  // EGS_Application::finishSimulation() and this resets I/O
924  // to stdout and stderr. But if we are here, we are combining
925  // the results of a parallel run and we want the output to go
926  // into the combined run log file.
927  //egsSetInfoFunction(Information,__write_to_fortran_file);
928  //egsSetInfoFunction(Warning,__write_to_fortran_file);
929  //egsSetInfoFunction(Fatal,__write_to_fortran_file_and_exit);
930  io_flag = 1;
931  final_job = true;
934  err = combineResults();
935  if (err) {
936  return err;
937  }
939  for (int j=0; j<a_objects_list.size(); ++j) {
940  a_objects_list[j]->reportResults();
941  }
942  outputResults();
943  finishRun();
944  return 0;
945 }
946 
948  int err = EGS_Application::outputData();
949  if (err) {
950  return err;
951  }
952  EGS_I32 np, ip;
953  egsGetRNGPointers(&np,&ip);
954  if (np < 1) {
955  return 11;
956  }
957  if (np > 10000000) {
958  egsWarning("EGS_AdvancedApplication::outputData(): egsGetRNGPointers"
959  " returns a huge number? (%d)\n",np);
960  return 12;
961  }
962  EGS_Float *array = new EGS_Float [np];
963  egsGetRNGArray(array);
964  (*data_out) << " " << np << " " << ip << endl;
965  for (int j=0; j<np; j++) {
966  (*data_out) << array[j] << " ";
967  }
968  (*data_out) << endl;
969  double ch_steps, all_steps;
970  egsGetSteps(&ch_steps,&all_steps);
971  (*data_out) << ch_steps << " " << all_steps << endl;
972  delete [] array;
973  return data_out->good() ? 0 : 13;
974 }
975 
977  int err = EGS_Application::readData();
978  if (err) {
979  return err;
980  }
981  int np, ip;
982  (*data_in) >> np >> ip;
983  if (np < 1) {
984  return 11;
985  }
986  if (np > 10000000) {
987  egsWarning("EGS_AdvancedApplication::readData(): got huge size "
988  "for the mortran random array? (%d)\n",np);
989  return 12;
990  }
991  EGS_Float *array = new EGS_Float [np];
992  for (int j=0; j<np; j++) {
993  (*data_in) >> array[j];
994  }
995  if (!data_in->good()) {
996  return 13;
997  }
998  egsSetRNGState(&ip,array);
999  delete [] array;
1000  double ch_steps, all_steps;
1001  (*data_in) >> ch_steps >> all_steps;
1002  egsSetSteps(&ch_steps,&all_steps);
1003  return data_in->good() ? 0 : 13;
1004 }
1005 
1007  int err = EGS_Application::addState(data);
1008  if (err) {
1009  return err;
1010  }
1011  int np, ip;
1012  data >> np >> ip;
1013  if (np < 1) {
1014  egsWarning("Got np=%d\n",np);
1015  return 11;
1016  }
1017  if (np > 10000000) {
1018  egsWarning("EGS_AdvancedApplication::addState(): got huge size "
1019  "for the mortran random array? (%d)\n",np);
1020  return 12;
1021  }
1022  EGS_Float *array = new EGS_Float [np];
1023  for (int j=0; j<np; j++) {
1024  data >> array[j];
1025  }
1026  if (!data.good()) {
1027  return 13;
1028  }
1029  egsSetRNGState(&ip,array);
1030  delete [] array;
1031  double ch_steps, all_steps;
1032  data >> ch_steps >> all_steps;
1033  double ch_steps_old, all_steps_old;
1034  egsGetSteps(&ch_steps_old,&all_steps_old);
1035  ch_steps += ch_steps_old;
1036  all_steps += all_steps_old;
1037  egsSetSteps(&ch_steps,&all_steps);
1038  return data.good() ? 0 : 13;
1039 }
1040 
1043  double ch_steps = 0, all_steps = 0;
1044  egsSetSteps(&ch_steps,&all_steps);
1045 }
1046 
1048  EGS_I64 nused = EGS_Application::randomNumbersUsed();
1049  EGS_I32 np, ip;
1050  egsGetRNGPointers(&np,&ip);
1051  if (ip <= np) {
1052  nused -= (np+1-ip);
1053  }
1054  return nused;
1055 }
1056 
1057 void EGS_AdvancedApplication::appInformation(const char *msg) {
1058  if (!msg) {
1059  return;
1060  }
1061  if (!io_flag) {
1063  }
1064  else {
1065  int ounit = the_egsio->i_log;
1066  F77_OBJ_(egs_write_string,EGS_WRITE_STRING)(&ounit,msg,strlen(msg));
1067  checkDeviceFull(stdout);
1068  }
1069 }
1070 
1071 void EGS_AdvancedApplication::appWarning(const char *msg) {
1072  if (!msg) {
1073  return;
1074  }
1075  if (!io_flag) {
1077  }
1078  else {
1079  int ounit = the_egsio->i_log;
1080  F77_OBJ_(egs_write_string,EGS_WRITE_STRING)(&ounit,msg,strlen(msg));
1081  checkDeviceFull(stdout);
1082  }
1083 }
1084 
1085 void EGS_AdvancedApplication::appFatal(const char *msg) {
1086  if (!io_flag) {
1088  }
1089  else {
1090  if (msg) {
1091  int ounit = the_egsio->i_log;
1092  F77_OBJ_(egs_write_string,EGS_WRITE_STRING)(&ounit,msg,strlen(msg));
1093  }
1094  exit(1);
1095  }
1096 }
1097 
1099  double &all_steps) const {
1100  egsGetSteps(&ch_steps,&all_steps);
1101 }
1102 
1104  if (geometry->hasRhoScaling()) {
1105  int ireg = the_stack->ir[the_stack->np-1] - 2;
1106  EGS_Float rho = geometry->getRelativeRho(ireg);
1107  the_useful->rhor = rho;
1108  the_useful->rhor_new = rho;
1109  }
1110  else {
1111  the_useful->rhor = 1;
1112  the_useful->rhor_new = 1;
1113  }
1114  if (geometry->hasBScaling()) {
1115  int ireg = the_stack->ir[the_stack->np-1] - 2;
1116  EGS_Float bf = geometry->getBScaling(ireg);
1117  the_emf->Bx = bf*the_emf->BxIN;
1118  the_emf->By = bf*the_emf->ByIN;
1119  the_emf->Bz = bf*the_emf->BzIN;
1120  the_emf->Bx_new = the_emf->Bx;
1121  the_emf->By_new = the_emf->By;
1122  the_emf->Bz_new = the_emf->Bz;
1123  }
1124  else {
1125  the_emf->Bx = the_emf->BxIN;
1126  the_emf->By = the_emf->ByIN;
1127  the_emf->Bz = the_emf->BzIN;
1128  the_emf->Bx_new = the_emf->Bx;
1129  the_emf->By_new = the_emf->By;
1130  the_emf->Bz_new = the_emf->Bz;
1131  }
1132 }
1133 
1134 void EGS_AdvancedApplication::enterNewRegion() {
1135  if (geometry->hasRhoScaling()) {
1136  int ireg = the_epcont->irnew-2;
1137  if (ireg >= 0) {
1138  EGS_Float rho = geometry->getRelativeRho(ireg);
1139  the_useful->rhor_new = rho;
1140  }
1141  }
1142  else {
1143  the_useful->rhor_new = 1;
1144  }
1145  if (geometry->hasBScaling()) {
1146  int ireg = the_epcont->irnew-2;
1147  if (ireg >= 0) {
1148  EGS_Float bf = geometry->getBScaling(ireg);
1149  the_emf->Bx_new = bf*the_emf->BxIN;
1150  the_emf->By_new = bf*the_emf->ByIN;
1151  the_emf->Bz_new = bf*the_emf->BzIN;
1152  }
1153  }
1154  else {
1155  the_emf->Bx_new = the_emf->BxIN;
1156  the_emf->By_new = the_emf->ByIN;
1157  the_emf->Bz_new = the_emf->BzIN;
1158  }
1159 }
1160 
1162  rndm->saveState();
1163  int np,ip;
1164  egsGetRNGPointers(&np,&ip);
1165  if (n_rng_buffer > 0) {
1166  if (np != n_rng_buffer) egsFatal("EGS_AdvancedApplication::saveRNGState:\n"
1167  " new buffer size (%d) is not the same as previous size(%d) ?\n",
1168  np,n_rng_buffer);
1169  }
1170  else {
1171  rng_buffer = new EGS_Float [np];
1172  n_rng_buffer = np;
1173  }
1174  i_rng_buffer = ip;
1175  egsGetRNGArray(rng_buffer);
1176 }
1177 
1179  rndm->resetState();
1180  if (n_rng_buffer > 0) {
1181  egsSetRNGState(&i_rng_buffer,rng_buffer);
1182  }
1183 }
1184 
1185 //************************************************************
1186 // Utility functions for use with ausgab dose scoring object
1187 //************************************************************
1188 // Returns density for medium ind
1189 EGS_Float EGS_AdvancedApplication::getMediumRho(int ind) {
1190  // handle the negative medium index for vacuum
1191  if (ind < 0) {
1192  return 0.0;
1193  }
1194  return the_media->rho[ind];
1195 }
1196 // Returns edep
1197 EGS_Float EGS_AdvancedApplication::getEdep() {
1198  return the_epcont->edep;
1199 }
1200 // Sets edep
1201 void EGS_AdvancedApplication::setEdep(EGS_Float edep) {
1202  the_epcont->edep = edep;
1203 }
1204 // Get the ecut
1205 EGS_Float EGS_AdvancedApplication::getEcut() {
1206  return the_bounds->ecut;
1207 }
1208 // Get the pcut
1209 EGS_Float EGS_AdvancedApplication::getPcut() {
1210  return the_bounds->pcut;
1211 }
1212 // Returns rest mass
1213 EGS_Float EGS_AdvancedApplication::getRM() {
1214  return the_useful->rm;
1215 }
1216 // Turns ON/OFF radiative splitting
1217 void EGS_AdvancedApplication::setRadiativeSplitting(const EGS_Float &nsplit) {
1218  the_egsvr->nbr_split = nsplit;
1219 }
1220 
1221 //************************************************************
1222 // Utility functions for fluence scoring objects
1223 //************************************************************
1224 EGS_Float EGS_AdvancedApplication::getTVSTEP() {
1225  return the_epcont->tvstep;
1226 }
1227 
1228 EGS_Interpolator *EGS_AdvancedApplication::getDEDX(const int &imed, const int &iq) {
1229  if (iq == -1) {
1230  return &i_ededx[imed];
1231  }
1232  else if (iq == 1) {
1233  return &i_pdedx[imed];
1234  }
1235  else {
1236  return 0;
1237  }
1238 }
1239 
1240 void EGS_AdvancedApplication::setLatch(const int &ip, const int &latch) {
1241  the_stack->latch[ip] = latch;
1242 }
1243 
1244 void EGS_AdvancedApplication::incLatch(const int &ip, const int &increment) {
1245  the_stack->latch[ip] += increment;
1246 }
1247 
1248 int EGS_AdvancedApplication::getNp() {
1249  return the_stack->np-1;;
1250 }
1251 
1252 int EGS_AdvancedApplication::getNpOld() {
1253  return the_stack->npold-1;
1254 }
1255 
1256 //************************************************************
1257 // Utility function for ausgab phase space scoring objects
1258 //************************************************************
1259 void EGS_AdvancedApplication::setLatch(int latch) {
1260  int np = the_stack->np-1;
1261  the_stack->latch[np] = latch;
1262 }
1263 
1264 extern __extc__ void egsHowfar() {
1265  CHECK_GET_APPLICATION(app,"egsHowfar()");
1266  int np = the_stack->np-1;
1267  int ireg = the_stack->ir[np]-2;
1268  if (ireg < 0 || the_stack->wt[np] == 0) {
1269  the_epcont->idisc = 1;
1270  return;
1271  }
1272  int newmed;
1273  int inew = app->howfar(ireg,
1274  EGS_Vector(the_stack->x[np],the_stack->y[np],the_stack->z[np]),
1275  EGS_Vector(the_stack->u[np],the_stack->v[np],the_stack->w[np]),
1276  the_epcont->ustep,&newmed);
1277 #ifdef GDEBUG
1278  EGS_Float tsave = the_epcont->ustep;
1279  if (steps_n < MAX_STEP) {
1280  steps_x[steps_n] =
1281  EGS_Vector(the_stack->x[np],the_stack->y[np],the_stack->z[np]);
1282  steps_u[steps_n] =
1283  EGS_Vector(the_stack->u[np],the_stack->v[np],the_stack->w[np]);
1284  steps_ireg[steps_n] = ireg;
1285  steps_inew[steps_n] = inew;
1286  steps_ustepi[steps_n] = tsave;
1287  steps_ustepf[steps_n++] = the_epcont->ustep;
1288  }
1289  if (the_epcont->ustep < -1e-4) {
1290  egsWarning("Negative step: %g\n",the_epcont->ustep);
1291  for (int j=0; j<steps_n; j++)
1292  egsWarning("%d x=(%g,%g,%g) u=(%g,%g,%g) ireg=%d inew=%d ustepi=%g"
1293  " ustepf=%g\n",j,steps_x[j].x,steps_x[j].y,steps_x[j].z,
1294  steps_u[j].x,steps_u[j].y,steps_u[j].z,
1295  steps_ireg[j],steps_inew[j],steps_ustepi[j],
1296  steps_ustepf[j]);
1297  exit(1);
1298  }
1299 #endif
1300  if (inew != ireg) {
1301  the_epcont->irnew = inew+2;
1302  the_useful->medium_new = newmed+1;
1303  app->enterNewRegion();
1304  if (inew < 0) {
1305  the_epcont->idisc = -1; // i.e. discard after the step.
1306  the_useful->medium_new = 0;
1307  }
1308  }
1309 }
1310 
1311 extern __extc__ void egsHownear(EGS_Float *tperp) {
1312  CHECK_GET_APPLICATION(app,"egsHownear()");
1313  int np = the_stack->np-1;
1314  int ireg = the_stack->ir[np]-2;
1315  *tperp = app->hownear(ireg,EGS_Vector(the_stack->x[np],the_stack->y[np],
1316  the_stack->z[np]));
1317 }
1318 
1319 extern __extc__ void egsFillRandomArray(const EGS_I32 *n, EGS_Float *rarray) {
1320  CHECK_GET_APPLICATION(app,"egsFillRandomArray()");
1321  app->fillRandomArray(*n,rarray);
1322 }
1323 
1324 //extern __extc__ int egsAusgab(const EGS_I32 *iarg) {
1325 // CHECK_GET_APPLICATION(app,"egsAusgab()");
1326 // return app->ausgab(*iarg);
1327 //}
1328 extern __extc__ void egsAusgab(EGS_I32 *iarg) {
1329  CHECK_GET_APPLICATION(app,"egsAusgab()");
1330  //*iarg = app->ausgab(*iarg);
1331  int np = the_stack->np-1;
1332  app->top_p.E = the_stack->E[np];
1333  app->top_p.wt = the_stack->wt[np];
1334  app->top_p.x = EGS_Vector(the_stack->x[np],the_stack->y[np],the_stack->z[np]);
1335  app->top_p.u = EGS_Vector(the_stack->u[np],the_stack->v[np],the_stack->w[np]);
1336  app->top_p.q = the_stack->iq[np];
1337  app->top_p.ir = the_stack->ir[np]-2;
1338  app->top_p.latch = the_stack->latch[np];
1339  app->Np = the_stack->np-1;
1340  *iarg = app->userScoring(*iarg);
1341 }
1342 
1343 extern __extc__ void egsStartParticle() {
1344  CHECK_GET_APPLICATION(app,"egsStartParticle()");
1345  int np = the_stack->np - 1;
1346  int ir = the_stack->ir[np]-2;
1347  if (ir < 0) {
1348  the_epcont->idisc = 1;
1349  return;
1350  }
1351  the_epcont->idisc = 0;
1352  the_useful->medium = app->getMedium(ir)+1;
1353  //egsInformation("start particle: ir=%d medium=%d\n",ir,the_useful->medium);
1354  app->startNewParticle();
1355 }
__extc__ struct EGS_VarianceReduction * the_egsvr
The address of the mortran egs_vr common block as a pointer to a C-structure of type EGS_VarianceRedu...
int io_flag
determines how to write info
EGS_I32 transport_algorithm
EGS_I32 iq[MXSTACK]
void getElectronSteps(double &ch_steps, double &all_steps) const
Get the number of condensed history and all electron steps.
EGS_Float rhor_new
Mass density ratio in the new region.
int i_rng_buffer
Pointer to the RNG buffer.
__extc__ struct EGS_Stack * the_stack
The address of the mortran STACK common block as a pointer to a C-structure of type EGS_Stack...
EGS_Float ue[MXMED]
virtual void resetState()=0
Reset the state to a previously saved state.
EGS_I32 medium
Current medium.
int initCrossSections()
Initialize the run-time cross section data.
EGS_Float v[MXSTACK]
__extc__ struct EGS_Rayleigh * the_rayleigh
The address of the mortran rayleigh_inputs common block as a pointer to a C-structure of type EGS_Ray...
virtual int readData()
Read intermediate results.
EGS_Float E
particle energy in MeV
EGS_Float rho[MXMED]
EGS_Float estepe
__extc__ struct EGS_EtControl * the_etcontrol
The address of the mortran Et_Control common block as a pointer to a C-structure of type EGS_EtContro...
char pxsec[16]
EGS_Float pcut_new
EGS_Float rhor
Mass density ratio.
virtual void describeSimulation()
Describe the simulation.
EGS_AusgabObject interface class header file.
EGS_I32 ir[MXSTACK]
virtual int combineResults()
Combine results from parallel runs.
virtual void describeUserCode() const
Describe the user code.
EGS_I32 npold
EGS_BaseSource class header file.
void setRayleighData(const vector< string > &str_medium, const vector< string > &str_file)
Custom Rayleigh data setup.
virtual void resetCounter()
Reset the application to a &#39;pristine&#39; state.
EGS_Float ae[MXMED]
EGS_Interpolator * i_pbr2
positron branching 2 interpolator
EGS_I32 radc_flag
char photonucxsec[16]
int outputData()
Output intermediate results.
virtual ~EGS_AdvancedApplication()
Destructor.
EGS_Float ap[MXMED]
virtual void saveState()=0
Save the RNG state.
int q
particle charge
This file defines the C/C++ interface to the EGSnrc mortran back-end.
EGS_Input class header file.
EGS_Float y
y-component
Definition: egs_vector.h:61
EGS_Float pcut
EGS_Float w[MXSTACK]
AusgabCall
Possible calls to the user scoring function ausgab().
int finishSimulation()
Finish the simulation.
virtual void outputResults()
Output the simulation results.
A class representing 3D vectors.
Definition: egs_vector.h:56
char ff_file[MXMED][128]
__extc__ struct EGS_IO * the_egsio
The address of the mortran egs_io common block as a pointer to a C-structure of type EGS_IO...
#define egsStartParticle
int readData()
Read intermediate results.
EGS_Interpolator * i_gbr2
photon branching 2 interpolator
bool hasRhoScaling() const
Does this geometry object have a mass density scaling feature?
EGS_I32 spin_effects
EGS_I32 medium_new
Medium in the new region.
EGS_I32 iphotonuc
EGS_Float dnear[MXSTACK]
Global egspp functions header file.
EGS_AdvancedApplication class header file.
__extc__ struct EGS_emfInputs * the_emf
The address of the mortran EMF-INPUTS common block as a pointer to a C-structure of type EGS_emfInput...
virtual void appInformation(const char *)
Write an information message.
EGS_Float ximax
__extc__ void egsFinish(void)
Finish a simulation.
virtual void finishRun()
Finish a simulation.
virtual void appFatal(const char *)
Write a warning message and exit.
EGS_I32 pair_nrc
EGS_Vector x
position
EGS_Float ecut_new
EGS_Interpolator * i_cohe
photon Rayleigh interpolator
__extc__ struct EGS_Epcont * the_epcont
The address of the mortran EPCONT common block as a pointer to a C-structure of type EGS_Epcont...
bool final_job
Is this the final job of a parallel run ?
__extc__ struct EGS_Bounds * the_bounds
The address of the morrtan BOUNDS common block as a pointer to a C-structure of type EGS_Bounds...
void setAusgabCall(AusgabCall call, bool on_or_off)
Turns on or off a call to the user scoring function ausgab()
__extc__ EGS_I32 egsAddMedium(const char *medname, EGS_I32 length)
Add a medium to the list of media.
char compxsec[16]
void startNewParticle()
Start the transport of a new particle.
static void setActiveGeometryList(int list)
Set the currently active geometry list.
EGS_Float smaxir
EGS_Interpolator * i_gmfp
photon mean-free-path interpolator
EGS_Interpolator * i_ededx
electron stopping power interpolator
EGS_I32 bca_algorithm
virtual EGS_Float getBScaling(int ireg) const
Get the B field scaling factor in region ireg.
EGS_I32 ibr_nist
EGS_I32 latch[MXSTACK]
EGS_Float z
z-component
Definition: egs_vector.h:62
EGS_RandomGenerator * rndm
the random number generator
EGS_Float * rng_buffer
RNG buffer.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
int initEGSnrcBackEnd()
Initialize the EGSnrc mortran back-end.
EGS_I32 np
static int nMedia()
Get the number of media registered so far by all geometries.
EGS_Float x[MXSTACK]
EGS_RandomGenerator class header file.
EGS_I32 itriplet
EGS_Input * getInputItem(const string &key) const
Same as the previous function but now ownership remains with the EGS_Input object.
Definition: egs_input.cpp:245
ostream * data_out
data output stream
EGS_Interpolator * i_gbr1
photon branching 1 interpolator
int shower()
Simulate a single shower.
__extc__ struct EGS_Useful * the_useful
The address of the mortran USEFUL common block as a pointer to a C-structure of type EGS_Useful...
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
#define egsFillRandomArray
A class for fast run-time interpolations.
EGS_RunControl * run
the run control object.
static string base_revision
Holds the CVS revision number of the egs_advanced_application.cpp file.
istream * data_in
data input stream
bool hasBScaling() const
Does this geometry object have a B field scaling feature?
#define egsAusgab
EGS_Float smax_new
void describeSimulation()
Describe the simulation.
double E[MXSTACK]
int i_parallel
Job index in parallel runs.
Attempts to fix broken math header files.
int ir
particle region index
EGS_Float ustep
void setEIIData(EGS_I32 len)
Set EII flag and xsection file name.
virtual EGS_Float getRelativeRho(int ireg) const
Get the relative mass density in region ireg.
EGS_Float tvstep
string app_name
The application name.
void initialize(int nbin, EGS_Float Xmin, EGS_Float Xmax, const EGS_Float *values)
Initialize the interpolator.
virtual int outputData()
Output intermediate results.
__extc__ struct EGS_Media * the_media
The address of the mortran MEDIA common block as a pointer to a C-structure of type EGS_Media...
EGS_Interpolator * i_ebr1
electron branching interpolator
EGS_I32 iausfl[MXAUS]
int app_index
the index of this application.
__extc__ struct EGS_XOptions * the_xoptions
The address of the mortran cross section options common block as a pointer to a C-structure of type E...
EGS_Float ExIN
EGS_Float x
x-component
Definition: egs_vector.h:60
virtual int finishSimulation()
Analyze and output the results.
EGS_Float y[MXSTACK]
EGS_Float rm
Electron rest energy.
virtual EGS_I64 randomNumbersUsed() const
Returns the number of random numbers used.
EGS_Float wt[MXSTACK]
EGS_Interpolator * i_psig
positron cross section interpolator
virtual int addState(istream &data)
Add data from a parallel job.
#define egsHowfar
int latch
latch variable (useful as a flag on many occasions)
EGS_Vector u
direction
int n_rng_buffer
Size of the RNG buffer.
EGS_I64 randomNumbersUsed() const
Get the number of random numbers used.
EGS_Float skindepth_for_bca
EGS_SimpleContainer< EGS_AusgabObject * > a_objects_list
The ausgab objects.
virtual void appWarning(const char *)
Write a warning message.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
static const char * getMediumName(int ind)
Get the name of medium with index ind.
#define egsHownear
void resetCounter()
Reset the application to a &#39;pristine&#39; state.
string output_file
The output file name (no extension)
virtual void setAusgabCall(AusgabCall call, bool on_or_off)
Turns on or off a call to the user scoring function ausgab.
__extc__ struct EGS_Thresh * the_thresh
The address of the mortran THRESH common block as a pointer to a C-structure of type EGS_Thresh...
EGS_Float up[MXMED]
EGS_Float u[MXSTACK]
EGS_I32 eii_flag
__extc__ void egsShower(void)
Transport the particles currently on the particle stack.
__extc__ void egsHatch(void)
Initialize cross section data from a PEGS4 data file.
EGS_Float ecut
EGS_Float wt
statistical weight
EGS_Interpolator * i_pdedx
positron stopping power interpolator
int helpInit(EGS_Input *, bool do_hatch)
Helper function used in initCrossSections() and describeSimulation().
char ff_media[MXMED][24]
EGS_Interpolator class header file.
EGS_BaseGeometry * geometry
the geometry of this simulation
EGS_I32 irnew
void checkDeviceFull(FILE *)
Check if a device holding a given stream is full.
virtual int finishSimulation()
Finish the simulation.
char eiixsec[16]
int addState(istream &)
Add data from a parallel job.
int getInput(const string &key, vector< string > &values) const
Assign values to an array of strings from an input identified by key.
Definition: egs_input.cpp:338
Base class for advanced EGSnrc C++ applications.
EGS_RunControl and EGS_JCFControl class header file.
EGS_Interpolator * i_photonuc
photonuclear interpolator
EGS_AdvancedApplication(int argc, char **argv)
Constructor.
EGS_I32 idisc
EGS_Interpolator * i_pbr1
positron branching 1 interpolator
EGS_Interpolator * i_esig
electron cross section interpolator
EGS_Float z[MXSTACK]
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.
string final_output_file
The final output file name.