Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

linDG2D/space.hh
Go to the documentation of this file.
00001 // Space for linear DG FEM in 2D
00002 
00003 #ifndef linDG2Dspace_hh
00004 #define linDG2Dspace_hh
00005 
00006 #if __ICC == 800
00007 #  include <hash_map>
00008 #  define __gnu_cxx std
00009 #else
00010 #  if __GNUC__ >= 3
00011 #    include <ext/hash_map>
00012 #    if __GNUC_MINOR__ < 1 && __GNUC__ == 3
00013 #      define __gnu_cxx std
00014 #    endif
00015 #  else
00016 #    include <hash_map>
00017 #    define __gnu_cxx std
00018 #  endif
00019 #endif
00020 
00021 #include "space/space.hh"
00022 #include "toolbox/scannerConnectors.hh"
00023 #include "graphics/spaceTraits.hh"
00024 
00025 #include "triangle.hh"
00026 
00027 namespace concepts {
00028   // forward declarations
00029   class Mesh2;
00030   class BoundaryConditions;
00031 }  
00032 
00033 namespace linDG2D {
00034 
00035   using concepts::Real;
00036 
00037   // ***************************************************************** Space **
00038 
00042   class Space : public concepts::Space<Real> {
00043   public:
00044     typedef void (*SMap)(const concepts::TColumn<Real>&,
00045                          concepts::TColumn<Real>&);
00046     typedef __gnu_cxx::hash_map<uint, Triangle*> Map;
00047     Space() : dim_(0), nelm_(0) {}
00048     virtual ~Space();
00049     virtual Scanner* scan() const { return new S(elm_); }
00051     virtual uint dim() const { return dim_; }
00053     virtual uint nelm() const { return nelm_; }
00055     virtual const Triangle& elm(const concepts::Triangle2d* cell) const {
00056       conceptsAssert(cell, concepts::Assertion());
00057       const Map::const_iterator i = elm_.find(cell->connector().key());
00058       conceptsAssert(!(i == elm_.end()), concepts::Assertion());
00059       return *(i->second);
00060     }
00061   protected:
00062     virtual std::ostream& info(std::ostream& os) const;
00063     virtual Triangle* newElm_(const concepts::Triangle2d& cell,
00064                               uint idx[]) const = 0;
00065     virtual uint nDoF_() const = 0;
00066     virtual void constructor_(concepts::Mesh2& mesh);
00067   private:
00069     class S : public Scanner {
00070     public:
00071       inline S(const Map& elm) : idx_(elm.begin()), elm_(elm) {}
00072       inline S(const S& scan) : idx_(scan.idx_), elm_(scan.elm_) {}
00073       inline bool eos() const { return idx_ == elm_.end(); }
00074       inline Triangle& operator++(int) { 
00075         return const_cast<Triangle&>(*((*idx_++).second));
00076       }
00077       inline S* clone() const { return new S(*this); }
00078     private:
00079       Map::const_iterator idx_;
00080       const Map& elm_;
00081     };
00083     uint dim_;
00085     uint nelm_;
00087     Map elm_;
00088   };
00089 
00090   // ************************************************************** SpaceP1 **
00091 
00095   class SpaceP1 : public Space {
00096   public:
00097     typedef TriangleP1 Element;
00101     SpaceP1(concepts::Mesh2& msh) { constructor_(msh); }
00102   protected:
00103     virtual std::ostream& info(std::ostream& os) const;
00104     virtual Triangle* newElm_(const concepts::Triangle2d& cell,
00105                               uint idx[]) const {
00106       return new TriangleP1(cell, idx);
00107     }
00109     virtual uint nDoF_() const { return 3; }
00110   };
00111 
00112   // ************************************************************** SpaceP0 **
00113 
00117   class SpaceP0 : public Space {
00118   public:
00119     typedef TriangleP0 Element;
00123     SpaceP0(concepts::Mesh2& msh) { constructor_(msh); }
00124   protected:
00125     virtual std::ostream& info(std::ostream& os) const;
00126     virtual Triangle* newElm_(const concepts::Triangle2d& cell,
00127                               uint idx[]) const {
00128       return new TriangleP0(cell, idx);
00129     }
00130     virtual uint nDoF_() const { return 1; }
00131   };
00132 
00133 } // namespace linDG2D
00134 
00135 // *********************************************** Space Traits for Graphics **
00136 
00137 namespace graphics {
00138   template<>
00139   struct spaceTraits<linDG2D::Space> {
00140     static inline uint dim() { return 2; }
00141     static inline bool positionConnection() { return false; }
00142     static inline bool boundaryElements() { return false; }
00143   };
00144   template<>
00145   struct spaceTraits<linDG2D::SpaceP1> {
00146     static inline uint dim() { return 2; }
00147     static inline bool positionConnection() { return false; }
00148     static inline bool boundaryElements() { return false; }
00149   };
00150   template<>
00151   struct spaceTraits<linDG2D::SpaceP0> {
00152     static inline uint dim() { return 2; }
00153     static inline bool positionConnection() { return false; }
00154     static inline bool boundaryElements() { return false; }
00155   };
00156 } // namespace graphics
00157 
00158 #endif // linDG2Dspace_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)