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 
Geometry(geom_mode_e geom_mode, Int3D size, Vec3D origo, double h)
Constructor for geometry class.
uint32_t inside(const Vec3D &x) const
Returns 0 if point x is vacuum or the number of solid of x is inside a defined solid. Returns a number from 1 to 6 if point x is outside the defined geometry. If the point is inside several defined solids, the solid with the highest solid number is returned.
Bound(bound_e t, double v)
Constructor.
Definition: geometry.hpp:76
void set_solid(uint32_t n, const Solid *s)
Sets solid number n to s.
uint32_t number_of_solids() const
Return number of solids.
void write_int32(std::ostream &os, int32_t value)
Write int32_t value into stream os.
bound_e type
Definition: geometry.hpp:71
void debug_print(std::ostream &os) const
Print debugging information to stream os.
double val
Definition: geometry.hpp:72
friend std::ostream & operator<<(std::ostream &os, const Bound &b)
Outputting to stream.
Base for solid definition.
std::vector< Bound > get_boundaries() const
Returns a vector of boundary conditions.
void save(std::ostream &os) const
Saves data to stream os.
Definition: geometry.hpp:87
uint32_t get_bracket_count(void) const
Returns the solid bracketing count number.
void save(const std::string &filename) const
Saves data to a new file filename.
signed char & mesh(int32_t i)
Returns a reference to solid mesh.
Definition: geometry.hpp:298
Vec3D surface_normal(const Vec3D &x) const
Find surface outward normal at location x.
Bindary file writing and reading tools.
double bracket_surface(uint32_t n, const Vec3D &xin, const Vec3D &xout, Vec3D &xsurf) const
Find solid n surface location by bracketing.
Mesh geometry definion.
Definition: mesh.hpp:67
Vec3D origo(void) const
Returns origo vector of geometry.
Definition: mesh.hpp:128
geom_mode_e
Geometry mode enum.
Definition: types.hpp:59
uint32_t number_of_boundaries() const
Return number of boundaries.
Three dimensional vectors.
Base types.
const signed char & mesh(int32_t i, int32_t j, int32_t k) const
Returns a const reference to solid mesh.
Definition: geometry.hpp:292
void write_double(std::ostream &os, double value)
Write double value into stream os.
void set_boundary(uint32_t n, const Bound &b)
Sets boundary condition b for solid number n.
signed char & mesh(int32_t i, int32_t j, int32_t k)
Returns a reference to solid mesh.
Definition: geometry.hpp:308
Geometry defining class.
Definition: geometry.hpp:131
double h(void) const
Returns mesh cell size.
Definition: mesh.hpp:146
Bound(std::istream &s)
Constructor for loading boundary condition from a file.
Definition: geometry.hpp:80
Abstract solid class.
Definition: solid.hpp:56
signed char mesh_check(int32_t i, int32_t j, int32_t k) const
Returns solid node number from solid mesh at i, j, k or number from 1 to 6 if point is outside mesh...
3D Integer vector class.
Definition: vec3d.hpp:289
Int3D _size
Size of mesh.
Definition: mesh.hpp:71
Bound get_boundary(uint32_t n) const
Returns boundary condition for solid number n.
bool built(void) const
Is the solid mesh built?
Definition: geometry.hpp:273
bound_e
Boundary type.
Definition: types.hpp:117
Rectangular mesh definition.
int32_t read_int32(std::istream &is)
Read int32_t from stream is.
const signed char & mesh(int32_t i, int32_t j) const
Returns a const reference to solid mesh.
Definition: geometry.hpp:286
const signed char & mesh(int32_t i) const
Returns a const reference to solid mesh.
Definition: geometry.hpp:282
~Geometry()
Destructor for geometry.
void build_mesh(void)
Builds (or rebuilds) the solid mesh from solid definitions.
Int3D size(void) const
Returns size array of geometry.
Definition: mesh.hpp:116
Three dimensional vector.
Definition: vec3d.hpp:58
void set_bracket_count(uint32_t n)
Set the solid bracketing count number.
signed char & mesh(int32_t i, int32_t j)
Returns a reference to solid mesh.
Definition: geometry.hpp:302
geom_mode_e geom_mode(void) const
Returns geometry mode.
Definition: mesh.hpp:108
Boundary condition definition class.
Definition: geometry.hpp:69
double read_double(std::istream &is)
Readd double from stream is.
const Solid * get_solid(uint32_t n) const
Returns a const pointer to solid number n.