EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_point_source.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ point 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 # Author: Iwan Kawrakow, 2005
25 #
26 # Contributors: Hannah Gallop
27 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_point_source.h"
38 #include "egs_input.h"
39 
40 static bool EGS_POINT_SOURCE_LOCAL inputSet = false;
41 
43  EGS_BaseSimpleSource(input,f), xo(), valid(true) {
44  vector<EGS_Float> pos;
45  int err = input->getInput("position",pos);
46  if (!err && pos.size() == 3) {
47  xo = EGS_Vector(pos[0],pos[1],pos[2]);
48  }
49  else {
50  egsWarning("EGS_PointSource: missing/wrong 'position' input\n");
51  valid = false;
52  }
53  setUp();
54 }
55 
57  otype = "EGS_PointSource";
58  if (!isValid()) {
59  description = "Invalid point source";
60  }
61  else {
62  description = "Point source with ";
63  description += s->getType();
64  if (q == -1) {
65  description += ", electrons";
66  }
67  else if (q == 0) {
68  description += ", photons";
69  }
70  else if (q == 1) {
71  description += ", positrons";
72  }
73  else {
74  description += ", unknown particle type";
75  }
76  }
77 }
78 
79 
80 extern "C" {
81 
82  static void setInputs() {
83  inputSet = true;
84 
85  setBaseSourceInputs();
86 
87  srcBlockInput->getSingleInput("library")->setValues({"egs_point_source"});
88 
89  // Format: name, isRequired, description, vector string of allowed values
90  srcBlockInput->addSingleInput("position", true, "The position of the point source: 'x y z'");
91  }
92 
93  EGS_POINT_SOURCE_EXPORT string getExample() {
94  string example;
95  example = {
96  R"(
97  # Example of egs_point_source
98  #:start source:
99  library = egs_point_source
100  name = my_source
101  position = 0 0 0
102  :start spectrum:
103  type = monoenergetic
104  energy = 1
105  :stop spectrum:
106  charge = 0
107  :stop source:
108 )"};
109  return example;
110  }
111 
112  EGS_POINT_SOURCE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
113  if(!inputSet) {
114  setInputs();
115  }
116  return srcBlockInput;
117  }
118 
119  EGS_POINT_SOURCE_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
120  EGS_ObjectFactory *f) {
121  return createSourceTemplate<EGS_PointSource>(input,f,"point source");
122  }
123 
124 }
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.
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.
string otype
The object type.
void setUp()
Sets up the source type and description.
EGS_PointSource(int Q, EGS_BaseSpectrum *Spec, const EGS_Vector &Xo, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
A class representing 3D vectors.
Definition: egs_vector.h:57
EGS_Input class header file.
A point source.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.