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