EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_fano_source.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ Fano source
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 # Authors: Ernesto Mainegra-Hing, 2016
25 # Hugo Bouchard, 2016
26 #
27 # Contributors: Reid Townson
28 # Hannah Gallop
29 #
30 ###############################################################################
31 */
32 
33 
40 #include "egs_fano_source.h"
41 #include "egs_input.h"
42 #include "egs_math.h"
43 #include <sstream>
44 
45 static bool EGS_FANO_SOURCE_LOCAL inputSet = false;
46 
48  EGS_ObjectFactory *f) :
49  EGS_BaseSimpleSource(input,f), shape(0), geom(0),
50  regions(0), nrs(0), min_theta(0), max_theta(M_PI), min_phi(0), max_phi(2*M_PI),
51  max_mass_density(0.0) {
52 
53  vector<EGS_Float> pos;
54  EGS_Input *ishape = input->takeInputItem("shape");
55  if (ishape) {
56  egsWarning("EGS_FanoSource: trying to construct the shape\n");
58  delete ishape;
59  }
60  if (!shape) {
61  string sname;
62  int err = input->getInput("shape name",sname);
63  if (err)
64  egsWarning("EGS_FanoSource: missing/wrong inline shape "
65  "definition and missing wrong 'shape name' input\n");
66  else {
68  if (!shape) egsWarning("EGS_FanoSource: a shape named %s"
69  " does not exist\n");
70  }
71  }
72  string geom_name;
73  int err = input->getInput("geometry",geom_name);
74  if (!err) {
75  geom = EGS_BaseGeometry::getGeometry(geom_name);
76  if (!geom) egsFatal("EGS_FanoSource: no geometry named %s in input file!\n",
77  geom_name.c_str());
78  else {
79  int errF = input->getInput("max mass density", max_mass_density);
80  if (errF) {
81  egsFatal("EGS_FanoSource: A Fano source requires a maximum density input.\n");
82  }
83  }
84  }
85  else {
86  egsFatal("EGS_FanoSource: A Fano source requires a valid geometry name.\n");
87  }
88 
89  EGS_Float tmp_theta;
90  err = input->getInput("min theta", tmp_theta);
91  if (!err) {
92  min_theta = tmp_theta/180.0*M_PI;
93  }
94 
95  err = input->getInput("max theta", tmp_theta);
96  if (!err) {
97  max_theta = tmp_theta/180.0*M_PI;
98  }
99 
100  err = input->getInput("min phi", tmp_theta);
101  if (!err) {
102  min_phi = tmp_theta/180.0*M_PI;
103  }
104 
105  err = input->getInput("max phi", tmp_theta);
106  if (!err) {
107  max_phi = tmp_theta/180.0*M_PI;
108  }
109 
110  buf_1 = cos(min_theta);
111  buf_2 = cos(max_theta);
112 
113  setUp();
114 }
115 
116 void EGS_FanoSource::setUp() {
117  otype = "EGS_FanoSource";
118  if (!isValid()) {
119  description = "Invalid Fano source";
120  }
121  else {
122  description = "Fano source from a shape of type ";
124  description += " with ";
125  description += s->getType();
126  if (q == -1) {
127  description += ", electrons";
128  }
129  else if (q == 0) {
130  description += ", photons";
131  }
132  else if (q == 1) {
133  description += ", positrons";
134  }
135  else {
136  description += ", unknown particle type";
137  }
138  ostringstream str_density;
139  str_density << scientific << max_mass_density;
140  description += "\n maximum density = " + str_density.str() + " g/cm3";
141  description += "\n Fano geometry = " + geom->getName();
142  if (geom) {
143  geom->ref();
144  }
145  }
146 }
147 
148 extern "C" {
149 
150  static void setInputs() {
151  inputSet = true;
152 
153  setBaseSourceInputs();
154 
155  srcBlockInput->getSingleInput("library")->setValues({"egs_fano_source"});
156 
157  // Format: name, isRequired, description, vector string of allowed values
158  auto shapePtr = srcBlockInput->addBlockInput("shape");
159  setShapeInputs(shapePtr);
160 
161  srcBlockInput->addSingleInput("geometry", true, "The name of a predefined geometry");
162  srcBlockInput->addSingleInput("max mass density", true, "The maximum mass density within the geometry");
163  }
164 
165  EGS_FANO_SOURCE_EXPORT string getExample() {
166  string example;
167  example = {
168  R"(
169  # Example of egs_fano_source
170  #:start source:
171  library = egs_fano_source
172  name = my_fano_source
173  :start shape:
174  type = box
175  box size = 1 2 3
176  :start media input:
177  media = water
178  :stop media input:
179  :stop shape:
180  :start spectrum:
181  type = monoenergetic
182  energy = 1
183  :stop spectrum:
184  charge = 0
185  max mass density = 1.2
186  geometry = some_name
187  #create a geometry called some_name
188  :stop source:
189 )"};
190  return example;
191  }
192 
193  EGS_FANO_SOURCE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
194  if(!inputSet) {
195  setInputs();
196  }
197  return srcBlockInput;
198  }
199 
200  EGS_FANO_SOURCE_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
201  EGS_ObjectFactory *f) {
202  return createSourceTemplate<EGS_FanoSource>(input, f, "fano source");
203  }
204 
205 }
const string & getName() const
Get the name of this geometry.
int ref()
Increase the reference count to this geometry.
static EGS_BaseGeometry * getGeometry(const string &Name)
Get a pointer to the geometry named Name.
static EGS_BaseShape * getShape(const string &Name)
Get a pointer to the shape named Name.
Definition: egs_shapes.cpp:64
static EGS_BaseShape * createShape(EGS_Input *inp)
Create a shape from the information pointed to by inp.
Definition: egs_shapes.cpp:51
Base class for 'simple' particle sources.
int q
The charge of this simple source.
EGS_BaseSpectrum * s
The energy spectrum of this source.
Base source class. All particle sources must be derived from this class.
string description
A short source description.
const string & getType() const
Get the spectrum type.
EGS_Float min_phi
avoid multi-calculating cos(min_theta) and cos(max_theta)
EGS_FanoSource(int Q, EGS_BaseSpectrum *Spec, EGS_BaseShape *Shape, EGS_BaseGeometry *geometry, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
EGS_BaseShape * shape
The shape from which particles are emitted.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
EGS_Input * takeInputItem(const string &key, bool self=true)
Get the property named key.
Definition: egs_input.cpp:229
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.
string otype
The object type.
const string & getObjectType() const
Get the object type.
A Fano source.
EGS_Input class header file.
Attempts to fix broken math header files.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.