geometry.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2011 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef GEOMETRY_HPP
44 #define GEOMETRY_HPP 1
45 
46 
47 #include <stdint.h>
48 #include <vector>
49 #include <iostream>
50 #include "file.hpp"
51 #include "vec3d.hpp"
52 #include "solid.hpp"
53 #include "mesh.hpp"
54 #include "types.hpp"
55 
56 
69 struct Bound
70 {
72  double val;
73 
76  Bound( bound_e t, double v ) : type(t), val(v) {}
77 
80  Bound( std::istream &s ) {
81  type = (bound_e)read_int32( s );
82  val = read_double( s );
83  }
84 
87  void save( std::ostream &os ) const {
88  write_int32( os, type );
89  write_double( os, val );
90  }
91 
94  friend std::ostream &operator<<( std::ostream &os, const Bound &b );
95 };
96 
97 
131 class Geometry : public Mesh
132 {
133  uint32_t _n;
134  std::vector<const Solid*> _sdata;
135  std::vector<Bound> _bound;
137  bool _built;
138  signed char *_smesh;
140  int32_t _brktc;
145  bool vac_or_neu( int32_t i, int32_t j, int32_t k );
146 
149  void check_definition();
150 
151  Vec3D surface_normal_2d( const Vec3D &x ) const;
152  Vec3D surface_normal_3d( const Vec3D &x ) const;
153 
154 public:
155 
162 
165  Geometry( std::istream &is );
166 
169  ~Geometry();
170 
173  uint32_t number_of_solids() const;
174 
179  uint32_t number_of_boundaries() const;
180 
190  void set_solid( uint32_t n, const Solid *s );
191 
196  const Solid *get_solid( uint32_t n ) const;
197 
213  void set_boundary( uint32_t n, const Bound &b );
214 
217  Bound get_boundary( uint32_t n ) const;
218 
221  std::vector<Bound> get_boundaries() const;
222 
236  void set_bracket_count( uint32_t n );
237 
240  uint32_t get_bracket_count( void ) const;
241 
248  uint32_t inside( const Vec3D &x ) const;
249 
252  bool inside( uint32_t n, const Vec3D &x ) const;
253 
263  double bracket_surface( uint32_t n, const Vec3D &xin, const Vec3D &xout, Vec3D &xsurf ) const;
264 
269  Vec3D surface_normal( const Vec3D &x ) const;
270 
273  bool built( void ) const { return( _built ); }
274 
278  void build_mesh( void );
279 
282  const signed char &mesh( int32_t i ) const { return( _smesh[i] ); }
283 
286  const signed char &mesh( int32_t i, int32_t j ) const {
287  return( _smesh[i + j*_size[0]] );
288  }
289 
292  const signed char &mesh( int32_t i, int32_t j, int32_t k ) const {
293  return( _smesh[i + j*_size[0] + k*_size[0]*_size[1]] );
294  }
295 
298  signed char &mesh( int32_t i ) { return( _smesh[i] ); }
299 
302  signed char &mesh( int32_t i, int32_t j ) {
303  return( _smesh[i + j*_size[0]] );
304  }
305 
308  signed char &mesh( int32_t i, int32_t j, int32_t k ) {
309  return( _smesh[i + j*_size[0] + k*_size[0]*_size[1]] );
310  }
311 
315  signed char mesh_check( int32_t i, int32_t j, int32_t k ) const;
316 
319  void save( const std::string &filename ) const;
320 
323  void save( std::ostream &os ) const;
324 
327  void debug_print( std::ostream &os ) const;
328 };
329 
330 
331 #endif
332