00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 #ifndef MSHELL_H
00014 #define MSHELL_H
00015 #include <map>
00016 #include <vector>
00017 #include <algorithm>
00018 #include <cassert>
00019 #include <istream>
00020 #include <utility>
00021 
00022 
00023 namespace shells {
00024     class MShell;
00025     struct SVertexS;
00026     struct SElementS;
00027     struct SEdgeS;
00028 }
00029 
00030 
00031 class shells::MShell {
00032 public:
00033     MShell(std::istream& is);
00034     virtual ~MShell(){};
00035 
00036     enum ElementType {
00037         active = 0,          
00038         parallelGhost = 1,   
00039         boundaryGhost = 2,   
00040         fragmentGhost = 3    
00041     };
00042 
00043     enum EdgeType {
00044         bothActive = 0,      
00045         boundary = 1,        
00046         procBoundary = 2     
00047     };
00048     
00049     
00050     virtual void initializeComputation();
00051     virtual void resetActiveElements(const std::vector<unsigned>& newActiveID);
00052     virtual void verticesToBeCoupled(std::vector<shells::SVertexS *>& vertices);
00053 
00054     
00055     template <typename T>
00056     T iterateOverElements(const T& op, const ElementType& type);    
00057     template <typename T>
00058     T iterateOverEdges(const T& op, const EdgeType& type); 
00059     template <typename T>
00060     T iterateOverVertices(const T& op);
00061 
00062     
00063     template <typename VIZ>
00064     void visualizeMesh(VIZ& v);
00065 
00066     
00067     size_t numberOfElements(const ElementType& type) const;
00068     size_t numberOfVertices() const {return _vertices.size();} 
00069 
00070 
00071 private:
00072     MShell(const MShell &);
00073     const MShell & operator=(const MShell &);
00074 
00075 
00076 
00077 protected:
00078     typedef std::vector<shells::SElementS * >        _SElementCont; 
00079     typedef std::map<ElementType, _SElementCont>     _SElementTypeCont;
00080     typedef _SElementCont::iterator                  _SElementIt; 
00081 
00082     typedef std::vector<shells::SEdgeS * >           _SEdgeCont; 
00083     typedef std::map<EdgeType, _SEdgeCont>           _SEdgeTypeCont;
00084     typedef _SEdgeCont::iterator                     _SEdgeIt; 
00085         
00086     typedef std::vector<shells::SVertexS *>          _VertexCont;
00087     typedef _VertexCont::iterator                    _VertexIt;
00088     
00089     
00090     _SElementTypeCont                                _elements;
00091 
00092     
00093     _VertexCont                                      _vertices;
00094 
00095     
00096     _SEdgeTypeCont                                   _edges;    
00097 
00098 
00099 private:
00100     void mirrorBoundaryElements();
00101     void addRemainingGhostElements();
00102     void createGhostElements();
00103     void readMesh(std::istream& is);
00104     void resetProcBoundaryBothActiveEdges(const _SElementCont& newActiveElem);
00105     void resetBoundaryEdges(_SElementCont& newActiveElem);
00106     void resetVertices();
00107 };
00108 
00109 
00110 
00111 
00112 namespace shells {
00113 
00114     template <typename T>
00115     T MShell::iterateOverElements(const T& op, const ElementType& type) 
00116     {
00117         _SElementTypeCont::iterator it;
00118         
00119         it = _elements.find(type);
00120         if (it==_elements.end()) assert(false); 
00121         
00122         _SElementIt begin = it->second.begin();
00123         _SElementIt end = it->second.end();    
00124 
00125         return std::for_each(begin, end, op);
00126     }
00127     
00128     template <typename T>
00129     T MShell::iterateOverEdges(const T& op, const EdgeType& type) 
00130     {
00131         _SEdgeTypeCont::iterator it;
00132         
00133         it = _edges.find(type);
00134         if (it==_edges.end()) assert(false); 
00135         
00136         _SEdgeIt begin = it->second.begin();
00137         _SEdgeIt end = it->second.end();    
00138         
00139         return std::for_each(begin, end, op);
00140     }    
00141 
00142     template <typename T>
00143     T MShell::iterateOverVertices(const T& op) 
00144     {
00145         _VertexIt begin = _vertices.begin();
00146         _VertexIt end = _vertices.end();
00147         return std::for_each(begin, end, op);
00148     }
00149  
00150     template <typename VIZ>
00151     void MShell::visualizeMesh(VIZ& v) 
00152     {
00153         v.initialize(this);
00154         iterateOverVertices(v);
00155         iterateOverElements(v, v.elementType());
00156         v.finalize(this);
00157     }    
00158 }
00159 
00160 #endif
00161 
00162