EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_radiative_splitting.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ radiative splitting object
5 # Copyright (C) 2018 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: Ernesto Mainegra-Hing, 2018
25 #
26 # Contributors: Hannah Gallop
27 #
28 ###############################################################################
29 #
30 # A general radiative splitting tool.
31 #
32 # TODO:
33 #
34 # - Add directional radiative splitting (DRS)
35 #
36 ###############################################################################
37 */
38 
39 
45 #include <fstream>
46 #include <string>
47 #include <cstdlib>
48 
50 #include "egs_input.h"
51 #include "egs_functions.h"
52 
53 static bool EGS_RADIATIVE_SPLITTING_LOCAL inputSet = false;
54 
55 EGS_RadiativeSplitting::EGS_RadiativeSplitting(const string &Name,
56  EGS_ObjectFactory *f) :
57  nsplit(1) {
58  otype = "EGS_RadiativeSplitting";
59 }
60 
61 EGS_RadiativeSplitting::~EGS_RadiativeSplitting() {
62 }
63 
64 void EGS_RadiativeSplitting::setApplication(EGS_Application *App) {
66  if (!app) {
67  return;
68  }
69 
70  char buf[32];
71 
72  // Set EGSnrc internal UBS + RR
73  if (i_play_RR) {
74  app->setRussianRoulette(nsplit);
75  i_play_RR = true;
76  }
77  // Set EGSnrc internal radiative splitting number.
78  else if (nsplit > 0) {
79  app->setRadiativeSplitting(nsplit);
80  i_play_RR = false;
81  }
82 
83  description = "\n===========================================\n";
84  description += "Radiative splitting Object (";
85  description += name;
86  description += ")\n";
87  description += "===========================================\n";
88  if (i_play_RR) {
89  description +="\n - Splitting radiative events in ";
90  sprintf(buf,"%d",nsplit);
91  description += buf;
92  description +="\n - Play RR with higher order e-/e+ with probability 1/";
93  sprintf(buf,"%d\n\n",nsplit);
94  description += buf;
95  }
96  else if (nsplit > 1) {
97  description +="\n - Splitting radiative events in ";
98  sprintf(buf,"%d\n\n",nsplit);
99  description += buf;
100  }
101  else if (nsplit == 1) {
102  description +="\n - NO radiative splitting";
103  }
104  else {
105  description +="\n - BEWARE: Turning OFF radiative events !!!";
106  }
107  description += "\n===========================================\n\n";
108 }
109 
110 //*********************************************************************
111 // Process input for this ausgab object
112 //
113 //**********************************************************************
114 extern "C" {
115 
116  static void setInputs() {
117  inputSet = true;
118 
119  setBaseAusgabObjectInputs();
120 
121  ausBlockInput->getSingleInput("library")->setValues({"egs_radiative_splitting"});
122 
123  // Format: name, isRequired, description, vector string of allowed values
124  ausBlockInput->addSingleInput("splitting", false, "The number of times to split every radiative event");
125  }
126 
127  EGS_RADIATIVE_SPLITTING_EXPORT string getExample() {
128  string example;
129  example = {
130  R"(
131  # Example of egs_radiative_splitting
132  :start ausgab object:
133  library = egs_radiative_splitting
134  name = my_score
135  splitting = 128
136  :stop ausgab object:
137 )"};
138  return example;
139  }
140 
141  EGS_RADIATIVE_SPLITTING_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
142  if (!inputSet) {
143  setInputs();
144  }
145  return ausBlockInput;
146  }
147 
148  EGS_RADIATIVE_SPLITTING_EXPORT EGS_AusgabObject *createAusgabObject(EGS_Input *input,
149  EGS_ObjectFactory *f) {
150  const static char *func = "createAusgabObject(radiative_splitting)";
151  if (!input) {
152  egsWarning("%s: null input?\n",func);
153  return 0;
154  }
155 
156  EGS_Float nsplit = 1.0;
158  int err = input->getInput("splitting",nsplit);
159 
160  //=================================================
161 
162  /* Setup radiative splitting object with input parameters */
164  result->setSplitting(nsplit);
165  result->setName(input);
166  return result;
167  }
168 }
Base class for advanced EGSnrc C++ applications.
virtual void setApplication(EGS_Application *App)
Set the application this object belongs to.
string description
A short ausgab object description.
EGS_Application * app
The application this object belongs to.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
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:341
An object factory.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
string name
The object name.
A radiative splitting object: header.
void setSplitting(const int &n_s)
Global egspp functions header file.
EGS_Input class header file.
EGS_RADIATIVE_SPLITTING_EXPORT EGS_AusgabObject * createAusgabObject(EGS_Input *input, EGS_ObjectFactory *f)
A radiative splitting ausgab object: header.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.