Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   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,2019 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 
542  Vec3D surface_triangle_normal( const Vec3D &x ) const;
543 
546  Vec3D surface_triangle_normal( int32_t a ) const;
547 
550  const VTriangle &surface_triangle( int32_t a ) const {
551  return( _surface.triangle(a) );
552  }
553 
556  uint32_t surface_triangle_ptr( int32_t i, int32_t j, int32_t k ) const {
557  return( _triptr[(k*(_size[1]-1) + j)*(_size[0]-1) + i] );
558  }
559 
562  int32_t surface_trianglec( int32_t i, int32_t j, int32_t k ) const;
563 
570  void save( const std::string &filename, bool save_solids = false ) const;
571 
578  void save( std::ostream &os, bool save_solids = false ) const;
579 
582  void debug_print( std::ostream &os ) const;
583 };
584 
585 
586 #endif
587 
General callback functors.
Boundary condition definition class.
Definition: geometry.hpp:72
void save(std::ostream &os) const
Saves data to stream os.
Definition: geometry.cpp:132
Bound(bound_e type, double value)
Constructor for constant value boundary.
Definition: geometry.cpp:65
bool is_constant() const
Return if boundary value is constant.
Definition: geometry.cpp:108
double value(void) const
Return constant boundary value.
Definition: geometry.cpp:92
bound_e type(void) const
Return boundary type.
Definition: geometry.cpp:79
friend std::ostream & operator<<(std::ostream &os, const Bound &b)
Outputting to stream.
Definition: geometry.cpp:146
void set_value(double value)
Set constant boundary value.
Definition: geometry.cpp:85
Definition: callback.hpp:61
Geometry defining class.
Definition: geometry.hpp:180
uint32_t surface_trianglec(void) const
Return total surface triangle count.
Definition: geometry.hpp:528
uint32_t number_of_boundaries() const
Return number of boundaries.
Definition: geometry.cpp:287
const Vec3D & surface_vertex(int32_t a) const
Return reference to surface vertex a.
Definition: geometry.hpp:534
void debug_print(std::ostream &os) const
Print debugging information to stream os.
Definition: geometry.cpp:2565
bool built(void) const
Is the solid mesh built?
Definition: geometry.hpp:390
void set_solid(uint32_t n, const Solid *s)
Sets solid number n to s.
Definition: geometry.cpp:264
uint32_t & mesh(int32_t i, int32_t j, int32_t k)
Returns a reference to solid mesh array.
Definition: geometry.hpp:425
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:830
uint32_t number_of_solids() const
Return number of solids.
Definition: geometry.cpp:281
Geometry(geom_mode_e geom_mode, Int3D size, Vec3D origo, double h)
Constructor for geometry class.
Definition: geometry.cpp:161
void build_mesh(void)
Builds (or rebuilds) the solid mesh and near solid data from solid definitions.
Definition: geometry.cpp:1318
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:431
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:2480
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
bool surface_built(void) const
Is the solid surface representation built?
Definition: geometry.hpp:503
uint32_t inside(const Vec3D &x) const
Return if point is inside solids.
Definition: geometry.cpp:334
uint32_t surface_vertexc(void) const
Return total surface vertex count.
Definition: geometry.hpp:522
Vec3D surface_normal(const Vec3D &x) const
Find surface outward normal at location x.
Definition: geometry.cpp:519
const uint32_t & mesh(int32_t i, int32_t j) const
Returns a const reference to solid mesh array.
Definition: geometry.hpp:403
const uint32_t & mesh(int32_t i) const
Returns a const reference to solid mesh array.
Definition: geometry.hpp:399
bool have_solid_data(void) const
Returns true if full solid data available.
Definition: geometry.cpp:323
uint32_t & mesh(int32_t i)
Returns a reference to solid mesh array.
Definition: geometry.hpp:415
Bound get_boundary(uint32_t n) const
Returns boundary condition for solid number n.
Definition: geometry.cpp:314
uint32_t surface_inside(const Vec3D &x) const
Finds if point is inside surface triangulation.
Definition: geometry.cpp:2243
const Solid * get_solid(uint32_t n) const
Returns a const pointer to solid number n.
Definition: geometry.cpp:293
uint32_t mesh_check(int32_t i) const
Returns number from solid mesh array.
Definition: geometry.cpp:386
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
Vec3D surface_triangle_normal(const Vec3D &x) const
Return normal of surface triangle near point x.
Definition: geometry.cpp:2374
void save(const std::string &filename, bool save_solids=false) const
Saves data to a new file filename.
Definition: geometry.cpp:2530
~Geometry()
Destructor for geometry.
Definition: geometry.cpp:236
std::vector< Bound > get_boundaries() const
Returns a vector of boundary conditions.
const VTriangle & surface_triangle(int32_t a) const
Return reference to surface triangle a.
Definition: geometry.hpp:550
void build_surface(void)
Build surface triangulation data.
Definition: geometry.cpp:1931
uint32_t surface_triangle_ptr(int32_t i, int32_t j, int32_t k) const
Return index of first surface triangle at mesh cube (i,j,k).
Definition: geometry.hpp:556
void set_boundary(uint32_t n, const Bound &b)
Sets boundary condition b for solid number n.
Definition: geometry.cpp:302
uint32_t & mesh(int32_t i, int32_t j)
Returns a reference to solid mesh array.
Definition: geometry.hpp:419
3D Integer vector class.
Definition: vec3d.hpp:320
Mesh geometry definion.
Definition: mesh.hpp:68
double h(void) const
Returns mesh cell size.
Definition: mesh.hpp:146
Int3D size(void) const
Returns size array of geometry.
Definition: mesh.hpp:116
Vec3D origo(void) const
Returns origo vector of geometry.
Definition: mesh.hpp:128
Int3D _size
Size of mesh.
Definition: mesh.hpp:71
geom_mode_e geom_mode(void) const
Returns geometry mode.
Definition: mesh.hpp:108
Solid base class.
Definition: solid.hpp:57
VTriangleSolid solid.
Definition: vtriangle.hpp:209
VTriangle surface.
Definition: vtriangle.hpp:87
uint32_t trianglec(void) const
Return triangle count.
Definition: vtriangle.hpp:129
const Vec3D & vertex(uint32_t i) const
Return vertex i coordinates.
Definition: vtriangle.hpp:123
uint32_t vertexc(void) const
Return vertex count.
Definition: vtriangle.hpp:117
const VTriangle & triangle(uint32_t i) const
Return triangle i.
Definition: vtriangle.hpp:135
Vertex-based triangle representation.
Definition: vtriangle.hpp:56
Three dimensional vector.
Definition: vec3d.hpp:58
Bindary file writing and reading tools.
Rectangular mesh definition.
Base for solid definition.
Base types.
bound_e
Boundary type.
Definition: types.hpp:123
geom_mode_e
Geometry mode enum.
Definition: types.hpp:59
Three dimensional vectors.
Vertex-based triangle representation.


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.