Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.5new_solver
      Class Index
      File List
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
geometry.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2013 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 <pthread.h>
49 #include <vector>
50 #include <iostream>
51 #include "file.hpp"
52 #include "vec3d.hpp"
53 #include "vtriangle.hpp"
54 #include "solid.hpp"
55 #include "mesh.hpp"
56 #include "types.hpp"
57 #include "callback.hpp"
58 
59 
71 class Bound
72 {
73  bound_e _type;
74  double _value;
75  const CallbackFunctorD_V *_functor;
77 public:
78 
81  Bound( bound_e type, double value );
82 
85  Bound( bound_e type, const CallbackFunctorD_V *functor );
86 
89  Bound( std::istream &is );
90 
93  bound_e type( void ) const;
94 
97  void set_value( double value );
98 
104  double value( void ) const;
105 
108  double value( const Vec3D &x ) const;
109 
115  bool is_constant() const;
116 
119  void save( std::ostream &os ) const;
120 
123  friend std::ostream &operator<<( std::ostream &os, const Bound &b );
124 };
125 
126 
127 #define SMESH_NODE_ID_MASK 0xE0000000 // 111...
128 
129 #define SMESH_NODE_ID_PURE_VACUUM 0x00000000 // 000...
130 #define SMESH_NODE_ID_NEAR_SOLID 0x20000000 // 001...
131 #define SMESH_NODE_ID_NEUMANN 0x40000000 // 010...
132 #define SMESH_NODE_ID_ROUGH_BOUNDARY 0x60000000 // 011...
133 
134 #define SMESH_NODE_ID_PURE_VACUUM_FIX 0x80000000 // 100...
135 #define SMESH_NODE_ID_NEAR_SOLID_FIX 0xA0000000 // 101...
136 #define SMESH_NODE_ID_DIRICHLET 0xC0000000 // 110...
137 #define SMESH_NODE_ID_FINE_BOUNDARY 0xE0000000 // 111...
138 
139 #define SMESH_NODE_FIXED 0x80000000 // 100...
140 
141 
142 #define SMESH_BOUNDARY_NUMBER_MASK 0x000000FF // limit to 0-255
143 #define SMESH_NEAR_SOLID_INDEX_MASK 0x1FFFFFFF // limit to 0-2^29 (5.4e8)
144 
145 
179 class Geometry : public Mesh
180 {
181  struct BuildMeshData {
182  pthread_t thread;
183  uint32_t index;
184  Geometry *geom;
185  };
186 
187  uint32_t _n;
188  std::vector<const Solid*> _sdata;
189  std::vector<Bound> _bound;
191  bool _built;
192  uint32_t *_smesh;
193  std::vector<uint8_t> _nearsolid;
195  pthread_mutex_t _mutex;
196  pthread_cond_t _cond;
197  uint32_t _done;
199  double _surface_eps;
200  VTriangleSurface _surface;
201  std::vector<int32_t> _triptr;
209  uint32_t is_solid( int32_t i, int32_t j, int32_t k ) const;
210 
217  void add_near_solid_entry( uint32_t &near_solid_index, int32_t i, int32_t j, int32_t k );
218 
227  uint8_t bracket_ndist( int32_t i, int32_t j, int32_t k, int32_t solid, int sign, int coord ) const;
228 
231  void check_definition();
232 
233  Vec3D surface_normal_2d( const Vec3D &x ) const;
234  Vec3D surface_normal_3d( const Vec3D &x ) const;
235 
236 
237  void build_mesh_parallel_near_solid( uint32_t ind, int32_t i, int32_t j, int32_t k );
238  void build_mesh_parallel_prepare_near_solid( uint32_t &near_solid_index,
239  int32_t i, int32_t j, int32_t k );
240  void build_mesh_parallel_prepare_3d( void );
241  void build_mesh_parallel_prepare_2d( void );
242  void build_mesh_parallel_prepare_1d( void );
243 
244  void build_mesh_parallel_thread_3d( BuildMeshData *bmd );
245  void build_mesh_parallel_thread_2d( BuildMeshData *bmd );
246  void build_mesh_parallel_thread_1d( void );
247  void build_mesh_parallel_thread( BuildMeshData *bmd );
248 
249  static void *build_mesh_parallel_entry( void *data );
250  void build_mesh_parallel( void );
251 
252  static const int32_t mc_faces[15*256];
253 
254  Vec3D mc_surface( int32_t i, int32_t j, int32_t k, uint8_t cn, int32_t ei ) const;
255  uint8_t mc_case( int32_t i, int32_t j, int32_t k ) const;
256  uint32_t mc_trianglec( uint8_t cn ) const;
257  int32_t mc_add_vertex_try( const Vec3D &x, int32_t i, int32_t j, int32_t k ) const;
258  uint32_t mc_add_vertex( const Vec3D &x, int32_t i, int32_t j, int32_t k, uint32_t firstv );
259  void mc_triangulate( int32_t i, int32_t j, int32_t k );
260 
261  uint8_t surface_cell_face_case_2d( const int32_t i[3], const int32_t vb[3] ) const;
262  double surface_cell_face_dist( const int32_t i[3], const int32_t vb[3],
263  int32_t dx, int32_t dy,
264  int32_t dir ) const;
265  uint32_t surface_cell_face_add_vertex( VTriangleSurfaceSolid &solid,
266  const int32_t i[3], const int32_t vb[3],
267  double dx, double dy ) const;
268  void surface_cell_face_add_triangles( VTriangleSurfaceSolid &solid,
269  int32_t i0, int32_t i1, int32_t i2,
270  int32_t vb0, int32_t vb1, int32_t vb2 ) const;
271  void surface_cell_face_add_triangles( VTriangleSurfaceSolid &solid,
272  const int32_t i[3], const int32_t vb[3] ) const;
273  uint32_t surface_inside_solid_number( int32_t i, int32_t j,int32_t k ) const;
274 
275 public:
276 
283 
286  explicit Geometry( std::istream &is );
287 
290  ~Geometry();
291 
294  uint32_t number_of_solids() const;
295 
300  uint32_t number_of_boundaries() const;
301 
311  void set_solid( uint32_t n, const Solid *s );
312 
317  const Solid *get_solid( uint32_t n ) const;
318 
334  void set_boundary( uint32_t n, const Bound &b );
335 
338  Bound get_boundary( uint32_t n ) const;
339 
342  std::vector<Bound> get_boundaries() const;
343 
348  bool have_solid_data( void ) const;
349 
360  uint32_t inside( const Vec3D &x ) const;
361 
366  bool inside( uint32_t n, const Vec3D &x ) const;
367 
379  double bracket_surface( uint32_t n, const Vec3D &xin, const Vec3D &xout, Vec3D &xsurf ) const;
380 
386  Vec3D surface_normal( const Vec3D &x ) const;
387 
390  bool built( void ) const { return( _built ); }
391 
395  void build_mesh( void );
396 
399  const uint32_t &mesh( int32_t i ) const { return( _smesh[i] ); }
400 
403  const uint32_t &mesh( int32_t i, int32_t j ) const {
404  return( _smesh[i + j*_size[0]] );
405  }
406 
409  const uint32_t &mesh( int32_t i, int32_t j, int32_t k ) const {
410  return( _smesh[i + j*_size[0] + k*_size[0]*_size[1]] );
411  }
412 
415  uint32_t &mesh( int32_t i ) { return( _smesh[i] ); }
416 
419  uint32_t &mesh( int32_t i, int32_t j ) {
420  return( _smesh[i + j*_size[0]] );
421  }
422 
425  uint32_t &mesh( int32_t i, int32_t j, int32_t k ) {
426  return( _smesh[i + j*_size[0] + k*_size[0]*_size[1]] );
427  }
428 
435  uint32_t mesh_check( int32_t i ) const;
436 
443  uint32_t mesh_check( int32_t i, int32_t j ) const;
444 
450  uint32_t mesh_check( int32_t i, int32_t j, int32_t k ) const;
451 
458  bool is_near_solid( int32_t i, int32_t j, int32_t k ) const;
459 
474  const uint8_t *nearsolid_ptr( int32_t index ) const {
475  return( &_nearsolid[index] );
476  }
477 
488  uint8_t solid_dist( uint32_t i, uint32_t j, uint32_t k, uint32_t dir ) const;
489 
495  uint8_t solid_dist( uint32_t i, uint32_t dir ) const;
496 
499  void build_surface( void );
500 
503  bool surface_built( void ) const { return( _triptr.size() ); }
504 
518  uint32_t surface_inside( const Vec3D &x ) const;
519 
522  uint32_t surface_vertexc( void ) const {
523  return( _surface.vertexc() );
524  }
525 
528  uint32_t surface_trianglec( void ) const {
529  return( _surface.trianglec() );
530  }
531 
534  const Vec3D &surface_vertex( int32_t a ) const {
535  return( _surface.vertex(a) );
536  }
537 
540  const VTriangle &surface_triangle( int32_t a ) const {
541  return( _surface.triangle(a) );
542  }
543 
546  uint32_t surface_triangle_ptr( int32_t i, int32_t j, int32_t k ) const {
547  return( _triptr[(k*(_size[1]-1) + j)*(_size[0]-1) + i] );
548  }
549 
552  int32_t surface_trianglec( int32_t i, int32_t j, int32_t k ) const;
553 
560  void save( const std::string &filename, bool save_solids = false ) const;
561 
568  void save( std::ostream &os, bool save_solids = false ) const;
569 
572  void debug_print( std::ostream &os ) const;
573 };
574 
575 
576 #endif
577 
Geometry(geom_mode_e geom_mode, Int3D size, Vec3D origo, double h)
Constructor for geometry class.
Definition: geometry.cpp:159
Boundary condition definition class.
Definition: geometry.hpp:71
double value(void) const
Return constant boundary value.
Definition: geometry.cpp:90
uint32_t inside(const Vec3D &x) const
Return if point is inside solids.
Definition: geometry.cpp:332
uint32_t & mesh(int32_t i)
Returns a reference to solid mesh array.
Definition: geometry.hpp:415
void set_solid(uint32_t n, const Solid *s)
Sets solid number n to s.
Definition: geometry.cpp:262
uint32_t number_of_solids() const
Return number of solids.
Definition: geometry.cpp:279
void debug_print(std::ostream &os) const
Print debugging information to stream os.
Definition: geometry.cpp:2454
Base for solid definition.
uint32_t mesh_check(int32_t i) const
Returns number from solid mesh array.
Definition: geometry.cpp:367
Vertex-based triangle representation.
Definition: vtriangle.hpp:56
void save(const std::string &filename, bool save_solids=false) const
Saves data to a new file filename.
Definition: geometry.cpp:2419
std::vector< Bound > get_boundaries() const
Returns a vector of boundary conditions.
bool surface_built(void) const
Is the solid surface representation built?
Definition: geometry.hpp:503
Vec3D surface_normal(const Vec3D &x) const
Find surface outward normal at location x.
Definition: geometry.cpp:500
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.
Definition: geometry.cpp:412
friend std::ostream & operator<<(std::ostream &os, const Bound &b)
Outputting to stream.
Definition: geometry.cpp:144
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.
Definition: geometry.cpp:285
Three dimensional vectors.
const Vec3D & vertex(uint32_t i) const
Return vertex i coordinates.
Definition: vtriangle.hpp:123
Base types.
const VTriangle & surface_triangle(int32_t a) const
Return reference to surface triangle a.
Definition: geometry.hpp:540
uint32_t trianglec(void) const
Return triangle count.
Definition: vtriangle.hpp:129
bool have_solid_data(void) const
Returns true if full solid data available.
Definition: geometry.cpp:321
VTriangleSolid solid.
Definition: vtriangle.hpp:209
const VTriangle & triangle(uint32_t i) const
Return triangle i.
Definition: vtriangle.hpp:135
void set_boundary(uint32_t n, const Bound &b)
Sets boundary condition b for solid number n.
Definition: geometry.cpp:300
Geometry defining class.
Definition: geometry.hpp:179
const uint32_t & mesh(int32_t i) const
Returns a const reference to solid mesh array.
Definition: geometry.hpp:399
const Vec3D & surface_vertex(int32_t a) const
Return reference to surface vertex a.
Definition: geometry.hpp:534
bool is_near_solid(int32_t i, int32_t j, int32_t k) const
Returns true if node is a potential near solid point.
Definition: geometry.cpp:811
uint8_t solid_dist(uint32_t i, uint32_t j, uint32_t k, uint32_t dir) const
Returns distance of solid boundary from point.
Definition: geometry.cpp:2369
const uint32_t & mesh(int32_t i, int32_t j, int32_t k) const
Returns a const reference to solid mesh array.
Definition: geometry.hpp:409
uint32_t & mesh(int32_t i, int32_t j)
Returns a reference to solid mesh array.
Definition: geometry.hpp:419
double h(void) const
Returns mesh cell size.
Definition: mesh.hpp:146
Definition: callback.hpp:61
void build_surface(void)
Build surface triangulation data.
Definition: geometry.cpp:1912
uint32_t surface_trianglec(void) const
Return total surface triangle count.
Definition: geometry.hpp:528
uint32_t & mesh(int32_t i, int32_t j, int32_t k)
Returns a reference to solid mesh array.
Definition: geometry.hpp:425
Solid base class.
Definition: solid.hpp:57
const uint8_t * nearsolid_ptr(int32_t index) const
Returns a const pointer to start of near-solid data for near-solid node index.
Definition: geometry.hpp:474
bool is_constant() const
Return if boundary value is constant.
Definition: geometry.cpp:106
void save(std::ostream &os) const
Saves data to stream os.
Definition: geometry.cpp:130
3D Integer vector class.
Definition: vec3d.hpp:304
Int3D _size
Size of mesh.
Definition: mesh.hpp:71
uint32_t surface_triangle_ptr(int32_t i, int32_t j, int32_t k) const
Return index of surface triangle at mesh cube (i,j,k).
Definition: geometry.hpp:546
Bound get_boundary(uint32_t n) const
Returns boundary condition for solid number n.
Definition: geometry.cpp:312
bool built(void) const
Is the solid mesh built?
Definition: geometry.hpp:390
bound_e
Boundary type.
Definition: types.hpp:123
Rectangular mesh definition.
General callback functors.
uint32_t vertexc(void) const
Return vertex count.
Definition: vtriangle.hpp:117
VTriangle surface.
Definition: vtriangle.hpp:87
~Geometry()
Destructor for geometry.
Definition: geometry.cpp:234
void build_mesh(void)
Builds (or rebuilds) the solid mesh and near solid data from solid definitions.
Definition: geometry.cpp:1299
Int3D size(void) const
Returns size array of geometry.
Definition: mesh.hpp:116
const uint32_t & mesh(int32_t i, int32_t j) const
Returns a const reference to solid mesh array.
Definition: geometry.hpp:403
Three dimensional vector.
Definition: vec3d.hpp:58
void set_value(double value)
Set constant boundary value.
Definition: geometry.cpp:83
bound_e type(void) const
Return boundary type.
Definition: geometry.cpp:77
Bound(bound_e type, double value)
Constructor for constant value boundary.
Definition: geometry.cpp:63
const Solid * get_solid(uint32_t n) const
Returns a const pointer to solid number n.
Definition: geometry.cpp:291
Vertex-based triangle representation.
geom_mode_e geom_mode(void) const
Returns geometry mode.
Definition: mesh.hpp:108
uint32_t surface_vertexc(void) const
Return total surface vertex count.
Definition: geometry.hpp:522
uint32_t surface_inside(const Vec3D &x) const
Finds if point is inside surface triangulation.
Definition: geometry.cpp:2224


Reference manual for Ion Beam Simulator 1.0.5new_solver
Generated by Doxygen 1.8.5 on Tue May 19 2015 09:15:42.