EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_stack_geometry.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ stack geometry
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: Frederic Tessier
27 # Marc Chamberland
28 # Ernesto Mainegra-Hing
29 # Reid Townson
30 #
31 ###############################################################################
32 */
33 
34 
41 #include "egs_stack_geometry.h"
42 #include "egs_input.h"
43 #include "egs_functions.h"
44 
45 string EGS_StackGeometry::type = "EGS_StackGeometry";
46 
47 EGS_StackGeometry::EGS_StackGeometry(const vector<EGS_BaseGeometry *> &geoms,
48  const string &Name) : EGS_BaseGeometry(Name) {
49  if (geoms.size() < 2) egsFatal("EGS_StackGeometry::EGS_StackGeometry: "
50  " less than 2 geometries is not mermitted\n");
51  ng = geoms.size();
52  g = new EGS_BaseGeometry* [ng];
53  nmax = 1;
54  has_rho_scaling = false;
55  for (int j=0; j<ng; j++) {
56  g[j] = geoms[j];
57  g[j]->ref();
58  int n = g[j]->regions();
59  if (n > nmax) {
60  nmax = n;
61  }
62  if (!has_rho_scaling) {
64  }
65  }
66  has_B_scaling = false;
67  for (int j=0; j<ng; j++) {
68  g[j] = geoms[j];
69  g[j]->ref();
70  int n = g[j]->regions();
71  if (n > nmax) {
72  nmax = n;
73  }
74  if (!has_B_scaling) {
75  has_B_scaling = g[j]->hasBScaling();
76  }
77  }
78  nreg = ng*nmax;
79  is_convex = false;
80 }
81 
82 EGS_StackGeometry::~EGS_StackGeometry() {
83  for (int j=0; j<ng; j++)
84  if (!g[j]->deref()) {
85  delete g[j];
86  }
87  delete [] g;
88 }
89 
90 void EGS_StackGeometry::printInfo() const {
92  egsInformation(" geometries:\n");
93  for (int j=0; j<ng; j++) egsInformation(" %s (type %s)\n",
94  g[j]->getName().c_str(),g[j]->getType().c_str());
96  "=======================================================\n");
97 }
98 
99 void EGS_StackGeometry::setMedia(EGS_Input *,int,const int *) {
100  egsWarning("EGS_StackGeometry::setMedia: don't use this method. Use the\n"
101  " setMedia() methods of the geometry objects that make up this geometry\n");
102 }
103 
104 void EGS_StackGeometry::setRelativeRho(int start, int end, EGS_Float rho) {
105  setRelativeRho(0);
106 }
107 
108 void EGS_StackGeometry::setRelativeRho(EGS_Input *) {
109  egsWarning("EGS_StackGeometry::setRelativeRho(): don't use this method.\n"
110  " Use the setRelativeRho methods of the geometry objects that make up"
111  " this geometry\n");
112 }
113 
114 void EGS_StackGeometry::setBScaling(int start, int end, EGS_Float rho) {
115  setBScaling(0);
116 }
117 
118 void EGS_StackGeometry::setBScaling(EGS_Input *) {
119  egsWarning("EGS_StackGeometry::setBScaling(): don't use this method.\n"
120  " Use the setBScaling methods of the geometry objects that make up"
121  " this geometry\n");
122 }
123 
124 extern "C" {
125 
126  EGS_STACKG_EXPORT EGS_BaseGeometry *createGeometry(EGS_Input *input) {
127  if (!input) {
128  egsWarning("createGeometry(stack): null input?\n");
129  return 0;
130  }
131  vector<string> gnames;
132  vector<EGS_BaseGeometry *> geoms;
133  int err = input->getInput("geometries",gnames);
134  if (err || gnames.size() < 2) {
135  egsWarning("createGeometry(stack): missing/wrong 'geometries' input\n");
136  return 0;
137  }
138  for (unsigned int j=0; j<gnames.size(); j++) {
140  if (!gj) egsWarning("createGeometry(stack): no geometry named %s "
141  " defined\n",gnames[j].c_str());
142  else {
143  geoms.push_back(gj);
144  }
145  }
146  if (geoms.size() < 2) {
147  egsWarning("createGeometry(stack): must have at least 2 geometries\n");
148  return 0;
149  }
150  EGS_BaseGeometry *result = new EGS_StackGeometry(geoms);
151  result->setName(input);
152  result->setBoundaryTolerance(input);
153  result->setLabels(input);
154  EGS_Float tol = epsilon;
155  err = input->getInput("tolerance",tol);
156  if (!err) {
157  result->setBoundaryTolerance(tol);
158  }
159  return result;
160  }
161 
162 
163  void EGS_StackGeometry::getLabelRegions(const string &str, vector<int> &regs) {
164 
165  vector<int> local_regs;
166 
167  // label defined in the stacked geometries
168  for (int i=0; i<ng; i++) {
169  local_regs.clear();
170  g[i]->getLabelRegions(str, local_regs);
171  for (int j=0; j<local_regs.size(); j++) {
172  regs.push_back(i*nmax + local_regs[j]);
173  }
174  }
175 
176  // label defined in self (stack input block)
178 
179  }
180 
181 
182 }
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
int deref()
Decrease the reference count to this geometry.
virtual void getLabelRegions(const string &str, vector< int > &regs)
Get the list of all regions labeled with str.
int nreg
Number of local regions in this geometry.
bool has_B_scaling
Does this geometry has B field scaling factor?
bool is_convex
Is this geometry convex?
bool has_rho_scaling
Does this geometry have relative mass density scvaling?
bool hasBScaling() const
Does this geometry object have a B field scaling feature?
void setName(EGS_Input *inp)
Set the name of the geometry from the input inp.
const string & getName() const
Get the name of this geometry.
bool hasRhoScaling() const
Does this geometry object have a mass density scaling feature?
int regions() const
Returns the number of local regions in this geometry.
int setLabels(EGS_Input *input)
Set the labels from an input block.
virtual void printInfo() const
Print information about 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.
void setBoundaryTolerance(EGS_Input *inp)
Set the value of the boundary tolerance from the input inp.
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:338
A stack of geometries.
EGS_StackGeometry(const vector< EGS_BaseGeometry * > &geoms, const string &Name="")
Construct a geometry stack from the vector of geometries geom.
Global egspp functions header file.
EGS_GLIB_EXPORT EGS_BaseGeometry * createGeometry(EGS_Input *input)
Definition: egs_glib.cpp:57
EGS_Input class header file.
A geometry stack: header.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
Definition: egs_functions.h:62
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.