geometry.hpp
Go to the documentation of this file.
00001 00005 /* Copyright (c) 2005-2011 Taneli Kalvas. All rights reserved. 00006 * 00007 * You can redistribute this software and/or modify it under the terms 00008 * of the GNU General Public License as published by the Free Software 00009 * Foundation; either version 2 of the License, or (at your option) 00010 * any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this library (file "COPYING" included in the package); 00019 * if not, write to the Free Software Foundation, Inc., 51 Franklin 00020 * Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 * 00022 * If you have questions about your rights to use or distribute this 00023 * software, please contact Berkeley Lab's Technology Transfer 00024 * Department at TTD@lbl.gov. Other questions, comments and bug 00025 * reports should be sent directly to the author via email at 00026 * taneli.kalvas@jyu.fi. 00027 * 00028 * NOTICE. This software was developed under partial funding from the 00029 * U.S. Department of Energy. As such, the U.S. Government has been 00030 * granted for itself and others acting on its behalf a paid-up, 00031 * nonexclusive, irrevocable, worldwide license in the Software to 00032 * reproduce, prepare derivative works, and perform publicly and 00033 * display publicly. Beginning five (5) years after the date 00034 * permission to assert copyright is obtained from the U.S. Department 00035 * of Energy, and subject to any subsequent five (5) year renewals, 00036 * the U.S. Government is granted for itself and others acting on its 00037 * behalf a paid-up, nonexclusive, irrevocable, worldwide license in 00038 * the Software to reproduce, prepare derivative works, distribute 00039 * copies to the public, perform publicly and display publicly, and to 00040 * permit others to do so. 00041 */ 00042 00043 #ifndef GEOMETRY_HPP 00044 #define GEOMETRY_HPP 1 00045 00046 00047 #include <stdint.h> 00048 #include <vector> 00049 #include <iostream> 00050 #include "file.hpp" 00051 #include "vec3d.hpp" 00052 #include "solid.hpp" 00053 #include "mesh.hpp" 00054 #include "types.hpp" 00055 00056 00069 struct Bound 00070 { 00071 bound_e type; 00072 double val; 00073 00076 Bound( bound_e t, double v ) : type(t), val(v) {} 00077 00080 Bound( std::istream &s ) { 00081 type = (bound_e)read_int32( s ); 00082 val = read_double( s ); 00083 } 00084 00087 void save( std::ostream &os ) const { 00088 write_int32( os, type ); 00089 write_double( os, val ); 00090 } 00091 00094 friend std::ostream &operator<<( std::ostream &os, const Bound &b ); 00095 }; 00096 00097 00131 class Geometry : public Mesh 00132 { 00133 uint32_t _n; 00134 std::vector<const Solid*> _sdata; 00135 std::vector<Bound> _bound; 00137 bool _built; 00138 signed char *_smesh; 00140 int32_t _brktc; 00145 bool vac_or_neu( int32_t i, int32_t j, int32_t k ); 00146 00149 void check_definition(); 00150 00151 Vec3D surface_normal_2d( const Vec3D &x ) const; 00152 Vec3D surface_normal_3d( const Vec3D &x ) const; 00153 00154 public: 00155 00161 Geometry( geom_mode_e geom_mode, Int3D size, Vec3D origo, double h ); 00162 00165 Geometry( std::istream &is ); 00166 00169 ~Geometry(); 00170 00173 uint32_t number_of_solids() const; 00174 00179 uint32_t number_of_boundaries() const; 00180 00190 void set_solid( uint32_t n, const Solid *s ); 00191 00196 const Solid *get_solid( uint32_t n ) const; 00197 00213 void set_boundary( uint32_t n, const Bound &b ); 00214 00217 Bound get_boundary( uint32_t n ) const; 00218 00221 std::vector<Bound> get_boundaries() const; 00222 00236 void set_bracket_count( uint32_t n ); 00237 00240 uint32_t get_bracket_count( void ) const; 00241 00248 uint32_t inside( const Vec3D &x ) const; 00249 00252 bool inside( uint32_t n, const Vec3D &x ) const; 00253 00263 double bracket_surface( uint32_t n, const Vec3D &xin, const Vec3D &xout, Vec3D &xsurf ) const; 00264 00269 Vec3D surface_normal( const Vec3D &x ) const; 00270 00273 bool built( void ) const { return( _built ); } 00274 00278 void build_mesh( void ); 00279 00282 const signed char &mesh( int32_t i ) const { return( _smesh[i] ); } 00283 00286 const signed char &mesh( int32_t i, int32_t j ) const { 00287 return( _smesh[i + j*_size[0]] ); 00288 } 00289 00292 const signed char &mesh( int32_t i, int32_t j, int32_t k ) const { 00293 return( _smesh[i + j*_size[0] + k*_size[0]*_size[1]] ); 00294 } 00295 00298 signed char &mesh( int32_t i ) { return( _smesh[i] ); } 00299 00302 signed char &mesh( int32_t i, int32_t j ) { 00303 return( _smesh[i + j*_size[0]] ); 00304 } 00305 00308 signed char &mesh( int32_t i, int32_t j, int32_t k ) { 00309 return( _smesh[i + j*_size[0] + k*_size[0]*_size[1]] ); 00310 } 00311 00315 signed char mesh_check( int32_t i, int32_t j, int32_t k ) const; 00316 00319 void save( const std::string &filename ) const; 00320 00323 void save( std::ostream &os ) const; 00324 00327 void debug_print( std::ostream &os ) const; 00328 }; 00329 00330 00331 #endif