src/tetmesh/tetmesh.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           tetmesh.h  -  description
00003                              -------------------
00004     begin                : Mon Dec 15 2003
00005     copyright            : (C) 2003 by Roman Geus
00006     email                : roman.geus@psi.ch
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef TETMESH_H
00019 #define TETMESH_H
00020 
00021 #include <limits>
00022 #include <map>
00023 #include <string>
00024 #include <utility>
00025 #include <vector>
00026 #include <iostream>
00027 #include "utility/triple.h"
00028 #include "point.h"
00029 #include "edge.h"
00030 #include "face.h"
00031 #include "tet.h"
00032 #include <fstream>
00033 #include "looseoctree.h"
00034 
00035 #include "materials.h"
00036 
00037 namespace mesh {
00038 
00046 class TetMesh {
00047 public: /* public types */
00049     typedef std::vector<Tet>::iterator tet_iterator;
00051     typedef std::vector<Face>::iterator face_iterator;
00053     typedef std::vector<Edge>::iterator edge_iterator;
00055     typedef std::vector<Point>::iterator point_iterator;
00057     class surface_iterator {
00058         friend class TetMesh;
00059     public:
00061         surface_iterator()
00062         { }
00064         Face* operator*() const
00065         { return &*cur_; }
00067         surface_iterator& operator++ () {
00068             ++ cur_;
00069             search();
00070             return *this;
00071         }
00073         bool operator== (const surface_iterator& rhs) const
00074         { return cur_ == rhs.cur_; }
00076         bool operator!= (const surface_iterator& rhs) const
00077         { return cur_ != rhs.cur_; }
00078     protected:
00080         surface_iterator(const face_iterator& current, const face_iterator& end)
00081             : cur_(current), end_(end) { }
00083         void search()
00084         { while (cur_ != end_ && !((*cur_).on_boundary())) ++ cur_; }
00085     private:
00086         face_iterator cur_;
00087         face_iterator end_;
00088     };
00089 
00090 public: /* public methods */
00091 
00093     TetMesh();
00094 
00096     virtual ~TetMesh();
00097 
00098 private:
00101     TetMesh(const TetMesh&);
00102 
00105     TetMesh& operator=(const TetMesh&);
00106 
00107 public:
00109     virtual void initPoint(int nofPoint);
00110 
00112     virtual void insertPoint(int id, double x, double y, double z);
00113   
00115     virtual void initTet(int nofTet);
00116 
00125     virtual void insertTet(id_t global_id, id_t id0, id_t id1, id_t id2, id_t id3, id_t material);
00126 
00132     void setBoundaryOnFace(id_t face);
00133   
00141     void setSymmetryPlaneOnFace(id_t face, int symId);
00142 
00147     void generateEdges();
00148 
00152     void generateFaces();
00153 
00155     void load_materials(const char* fileName);
00156 
00158     Materials* get_materials() const;
00159     
00161     Tet* get_tet(id_t id) const;
00162     
00164     Face* get_face(id_t id) const;
00165     
00167     Edge* get_edge(id_t id) const;
00168     
00170     Point* get_point(id_t id) const;
00171     
00173     const id_t& get_nof_tets() const
00174     { return _nofTet; }
00175  
00177     const id_t& get_nof_faces() const
00178     { return _nofFace; }
00179 
00181     const id_t& get_nof_edges() const
00182     { return _nofEdge; }
00184     const id_t& get_nof_points() const
00185     { return _nofPoint; }
00187     LooseOctree<Tet>* get_octree() const
00188     { return _octree; }
00191     void get_bounding_box(Vector3& center, Vector3& extent) const;
00192 
00201     id_t insertEdge(id_t node0, id_t node1);
00202 
00213     id_t insertFace(id_t tet, id_t node0, id_t node1, id_t node2);
00214 
00218     virtual id_t lookupEdge(id_t node0, id_t node1);
00219 
00223     virtual id_t lookupFace(id_t node0, id_t node1, id_t node2);
00228     virtual void finalize_mesh(int nofSym);
00230     void log_mesh_info();
00233     void construct_octree();
00234 
00236     bool is_inside(const Vector3& p) const {
00237         std::vector<Tet *> tets;
00238         find_tets_by_point(p, tets);
00239         return tets.size() > 0;
00240     }
00241 
00247     void find_tets_by_point(const Vector3& p, std::vector<Tet *>& tets) const;
00248 
00250     template <typename CurveType>
00251     double find_boundary(const CurveType& curve, double x_in, double x_out) const {
00252         const double eps = std::numeric_limits<double>::epsilon();
00253 
00254         Vector3 a(curve(x_in));
00255         assert(is_inside(a));
00256 
00257         Vector3 b(curve(x_out));
00258         assert(!is_inside(b));
00259 
00260         // Bisection until interval as small as machine precision
00261         while (fabs(x_in - x_out) > eps * fabs(x_in)) {
00262             double x_mid = 0.5 * (x_in + x_out);
00263             if (is_inside(curve(x_mid)))
00264                 x_in = x_mid;
00265             else
00266                 x_out = x_mid;
00267         }
00268 
00269         // Return point which at the boundary but inside the mesh.
00270         return x_in;
00271     }
00272 
00274     tet_iterator tet_begin()
00275     { return _tets.begin(); }
00276 
00278     tet_iterator tet_end()
00279     { return _tets.end(); }
00280 
00282     face_iterator face_begin()
00283     { return _faces.begin(); }
00284 
00286     face_iterator face_end()
00287     { return _faces.end(); }
00288 
00290     edge_iterator edge_begin()
00291     { return _edges.begin(); }
00292 
00294     edge_iterator edge_end()
00295     { return _edges.end(); }
00296 
00298     point_iterator point_begin()
00299     { return _points.begin(); }
00300 
00302     point_iterator point_end()
00303     { return _points.end(); }
00304 
00306     surface_iterator surface_begin() {
00307         surface_iterator it(face_begin(), face_end());
00308         it.search();
00309         return it;
00310     }
00311 
00313     surface_iterator surface_end() {
00314         return surface_iterator(face_end(), face_end());
00315     }
00316 
00320      static TetMesh* get_instance() {
00321         return instance_;
00322      }
00323 protected:
00324     void dump_face_map(std::ostream& os);
00325     
00326 private: // Private types    
00327     typedef std::pair<id_t, id_t> EdgeMapKey;
00328     typedef utility::triple<id_t, id_t, id_t> FaceMapKey;
00329     typedef std::map<EdgeMapKey,id_t> EdgeMap;
00330     typedef std::map<FaceMapKey,id_t> FaceMap;
00331 
00332 private: // Private members
00333     id_t _nofTet;
00334     id_t _nofPoint;
00335     id_t _nofEdge;
00336     id_t _nofFace;
00337 
00338     Materials* _materials;
00339 
00340     int _nofSym;
00341     id_t _tetCounter;
00345     std::vector<Tet> _tets;
00349     std::vector<Face> _faces;
00353     std::vector<Edge> _edges;
00357     std::vector<Point> _points;
00358     EdgeMap _edgeMap;
00359     FaceMap _faceMap;
00360     LooseOctree<Tet>* _octree;
00364     static TetMesh* instance_;
00365 };
00366 
00367 } // namespace mesh 
00368 
00369 #endif

Generated on Fri Oct 26 13:35:13 2007 for FEMAXX (Finite Element Maxwell Eigensolver) by  doxygen 1.4.7