EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_stack_geometry.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ stack geometry headers
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 # Reid Townson
29 # Ernesto Mainegra-Hing
30 #
31 ###############################################################################
32 */
33 
34 
40 #ifndef EGS_STACK_GEOMETRY_
41 #define EGS_STACK_GEOMETRY_
42 
43 #ifdef WIN32
44 
45  #ifdef BUILD_STACKG_DLL
46  #define EGS_STACKG_EXPORT __declspec(dllexport)
47  #else
48  #define EGS_STACKG_EXPORT __declspec(dllimport)
49  #endif
50  #define EGS_STACKG_LOCAL
51 
52 #else
53 
54  #ifdef HAVE_VISIBILITY
55  #define EGS_STACKG_EXPORT __attribute__ ((visibility ("default")))
56  #define EGS_STACKG_LOCAL __attribute__ ((visibility ("hidden")))
57  #else
58  #define EGS_STACKG_EXPORT
59  #define EGS_STACKG_LOCAL
60  #endif
61 
62 #endif
63 
64 
65 #include "egs_base_geometry.h"
66 #include "egs_functions.h"
67 
68 #include<vector>
69 using std::vector;
70 
174 
175 public:
176 
180  EGS_StackGeometry(const vector<EGS_BaseGeometry *> &geoms, const string &Name = "");
181 
183 
184  bool isRealRegion(int ireg) const {
185  if (ireg < 0 || ireg >= nreg) {
186  return false;
187  }
188  int jg = ireg/nmax;
189  int jl = ireg - jg*nmax;
190  return g[jg]->isRealRegion(jl);
191  };
192 
193  bool isInside(const EGS_Vector &x) {
194  for (int j=0; j<ng; j++) if (g[j]->isInside(x)) {
195  return true;
196  }
197  return false;
198  };
199 
200  int isWhere(const EGS_Vector &x) {
201  for (int j=0; j<ng; j++) {
202  int i = g[j]->isWhere(x);
203  if (i >= 0) {
204  return nmax*j + i;
205  }
206  }
207  return -1;
208  };
209 
210  int inside(const EGS_Vector &x) {
211  return isWhere(x);
212  };
213 
214  int medium(int ireg) const {
215  int j = ireg/nmax;
216  return g[j]->medium(ireg-j*nmax);
217  };
218 
219  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u,
220  EGS_Float &t, int *newmed=0, EGS_Vector *normal=0) {
221  if (ireg >= 0) {
222  // inside the geometry.
223  int jg = ireg/nmax;
224  int jl = ireg - jg*nmax;
225  // jg is the stack index, jl the local region index in jg.
226  // see if we hit a boundary in jg.
227  int inew = g[jg]->howfar(jl,x,u,t,newmed,normal);
228  // inew>=0 implies that we either stay in the same local region
229  // or enter a new region still inside of jg => simply calculate
230  // the new gloabal region and return
231  if (inew >= 0) {
232  return jg*nmax + inew;
233  }
234  // inew < 0 implies that we have exited jg.
235  // to prevent roundoff problems, we add boundaryTolerance to the path-length
236  // to the boundary of jg.
237  t += boundaryTolerance;
238  if (jg > 0) {
239  // check if we enter the jg-1'th geometry in the stack.
240  inew = g[jg-1]->howfar(-1,x,u,t,newmed,normal);
241  if (inew >= 0) {
242  return (jg-1)*nmax + inew; // yes, we do.
243  }
244  }
245  if (jg < ng-1) {
246  // check if we enter the jg+1'th geometry in the stack.
247  inew = g[jg+1]->howfar(-1,x,u,t,newmed,normal);
248  if (inew >= 0) {
249  return (jg+1)*nmax + inew; // yes, we do
250  }
251  }
252  // if here, we don't enter either of the "stack neighbours"
253  // => we exit the geometry.
254  t -= boundaryTolerance;
255  return -1;
256  }
257  int i1 = g[0]->howfar(-1,x,u,t,newmed,normal);
258  int i2 = g[ng-1]->howfar(-1,x,u,t,newmed,normal);
259  if (i2 >= 0) {
260  return (ng-1)*nmax + i2;
261  }
262  if (i1 >= 0) {
263  return i1;
264  }
265  return -1;
266  };
267 
268  EGS_Float hownear(int ireg, const EGS_Vector &x) {
269  if (ireg >= 0) {
270  int jg = ireg/nmax;
271  return g[jg]->hownear(ireg-jg*nmax,x);
272  }
273  EGS_Float t1 = g[0]->hownear(-1,x);
274  EGS_Float t2 = g[ng-1]->hownear(-1,x);
275  if (t2 < t1) {
276  return t2;
277  }
278  return t1;
279  };
280 
281  bool hasBooleanProperty(int ireg, EGS_BPType prop) const {
282  if (ireg >= 0 && ireg < nreg) {
283  int jg = ireg/nmax;
284  return g[jg]->hasBooleanProperty(ireg-jg*nmax,prop);
285  }
286  return false;
287  };
288  void setBooleanProperty(EGS_BPType) {
289  setPropertError("setBooleanProperty()");
290  };
291  void addBooleanProperty(int) {
292  setPropertError("addBooleanProperty()");
293  };
294  void setBooleanProperty(EGS_BPType,int,int,int step=1) {
295  setPropertError("setBooleanProperty()");
296  };
297  void addBooleanProperty(int,int,int,int step=1) {
298  setPropertError("addBooleanProperty()");
299  };
300 
301  const string &getType() const {
302  return type;
303  };
304 
305  void printInfo() const;
306 
307  EGS_Float getRelativeRho(int ireg) const {
308  if (ireg < 0 || ireg >= nreg) {
309  return 1;
310  }
311  int jg = ireg/nmax;
312  return g[jg]->getRelativeRho(ireg-jg*nmax);
313  };
314  void setRelativeRho(int start, int end, EGS_Float rho);
315  void setRelativeRho(EGS_Input *);
316 
317  EGS_Float getBScaling(int ireg) const {
318  if (ireg < 0 || ireg >= nreg) {
319  return 1;
320  }
321  int jg = ireg/nmax;
322  return g[jg]->getBScaling(ireg-jg*nmax);
323  };
324  void setBScaling(int start, int end, EGS_Float bf);
325  void setBScaling(EGS_Input *);
326 
327  virtual void getLabelRegions(const string &str, vector<int> &regs);
328 
329 protected:
330 
331  int ng;
332  int nmax;
333  EGS_BaseGeometry **g;
334  static string type;
335 
336  void setMedia(EGS_Input *,int,const int *);
337 
338  vector<label> stack_labels;
339 
340 private:
341 
342  void setPropertError(const char *funcname) {
343  egsFatal("EGS_StackGeometry::%s: don't use this method\n Define "
344  "properties in the constituent geometries instead\n");
345  };
346 
347 
348 };
349 
350 #endif
virtual bool hasBooleanProperty(int ireg, EGS_BPType prop) const
Is the boolean property prop set for region ireg ?
virtual int medium(int ireg) const
Returns the medium index in region ireg.
A class representing 3D vectors.
Definition: egs_vector.h:56
Global egspp functions header file.
virtual int isWhere(const EGS_Vector &x)=0
In which region is poisition x?
virtual int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed=0, EGS_Vector *normal=0)=0
Calculate the distance to a boundary from x along the direction u.
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
virtual EGS_Float getBScaling(int ireg) const
Get the B field scaling factor in region ireg.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
virtual EGS_Float hownear(int ireg, const EGS_Vector &x)=0
Calculate the distance to a boundary for position x in any direction.
EGS_StackGeometry(const vector< EGS_BaseGeometry * > &geoms, const string &Name="")
Construct a geometry stack from the vector of geometries geom.
virtual EGS_Float getRelativeRho(int ireg) const
Get the relative mass density in region ireg.
EGS_Float boundaryTolerance
Boundary tolerance for geometries that need it.
virtual bool isRealRegion(int ireg) const
Returnes true if ireg is a real region, false otherwise.
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_BaseGeometry class header file.
int nreg
Number of local regions in this geometry.
A stack of geometries.