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

geometry/cell2D.hh
Go to the documentation of this file.
00001 /* 2D Cells, ie. triangles and quads
00002  * Geometrical information (coordinates), brings element maps and
00003  * topology together
00004  */
00005 
00006 #ifndef cell2D_hh
00007 #define cell2D_hh
00008 
00009 #include <iostream>
00010 
00011 #include "basics/outputOperator.hh"
00012 #include "basics/typedefs.hh"
00013 #include "basics/level.hh"
00014 #include "topology.hh"
00015 #include "cell.hh"
00016 #include "cell1D.hh"
00017 #include "elementMaps.hh"
00018 
00019 namespace concepts {
00020 
00021   // ************************************************************ Triangle2d **
00022 
00028   class Triangle2d : public Cell2 {
00029     public:
00031       struct Index {
00033         uchar  l_;
00034 
00039         ushort i_;
00040 
00045         ushort j_;
00046 
00047         Index();
00048         Index(uchar l, ushort i, ushort j);
00049         std::ostream& info(std::ostream& os) const;
00050       };
00051 
00052       friend std::ostream& operator<<(std::ostream& os,
00053           const Triangle2d::Index& i);
00054 
00060       Triangle2d(Triangle& cntr, const MappingTriangle2d& map);
00061       virtual ~Triangle2d();
00062 
00068       virtual Triangle2d* child(uint i);
00073       virtual const Triangle2d* child(uint i) const;
00074 
00076       inline Triangle& connector() const { return cntr_; }
00077 
00083       ushort level() const { return idx_.l_; }
00084 
00094       Real2d chi(Real xi, Real eta) const;
00095 
00096 
00097       Real3d elemMap(const Real2d& coord_local) const
00098       {
00099         return chi(coord_local[0], coord_local[1]);
00100       }
00101 
00105       Real jacobianDeterminant(const Real x, const Real y) const;
00106 
00117       MapReal2d jacobian(Real x, Real y) const;
00118 
00120       Real area() const;
00121 
00125       MapReal2d jacobianInverse(const Real x, const Real y) const;
00126 
00127       Real3d vertex(uint i) const;
00128       Real3d center() const {return chi(0.66666666666, 0.5);};
00130       inline const MappingTriangle2d* map() const {return map_;};
00131 
00133       inline Triangle2d* clone(Triangle& cntr, MappingTriangle2d* map) const {
00134         return new Triangle2d(cntr, map, idx_);};
00135 
00140       static Real2d duffyInv(const Real2d& x);
00141     protected:
00142       virtual std::ostream& info(std::ostream& os) const;
00143     private:
00145       Index idx_;
00146 
00148       Triangle& cntr_;
00149 
00151       Triangle2d* lnk_;
00152 
00156       Triangle2d* chld_;
00157 
00159       MappingTriangle2d* map_;
00160 
00162       Triangle2d(Triangle& cntr, MappingTriangle2d* map, const Index& idx);
00163   };
00164 
00165   std::ostream& operator<<(std::ostream& os, const Triangle2d::Index& i);
00166 
00167   // ***************************************************** Quad2dSubdivision **
00168 
00169   class Quad2d;
00170 
00183   class Quad2dSubdivision : public OutputOperator {
00184     public:
00187       virtual void createChildren(Quad2d& q) const = 0;
00190       virtual void removeChildren(Quad2d& q) const;
00193       virtual const QuadSubdivision* topologicalStrategy() const = 0;
00194   };
00195 
00196   // ********************************************************* Quad2dSubdiv4 **
00197 
00206   class Quad2dSubdiv4 : public Quad2dSubdivision {
00207     public:
00208       virtual void createChildren(Quad2d& q) const;
00209       virtual const QuadSubdiv4* topologicalStrategy() const;
00210       static const Quad2dSubdiv4* instance();
00211       virtual ~Quad2dSubdiv4();
00212     protected:
00213       virtual std::ostream& info(std::ostream& os) const;
00214     private:
00215       static std::auto_ptr<Quad2dSubdiv4> instance_;
00216   };
00217 
00218   // ******************************************************** Quad2dSubdiv2H **
00219 
00226   class Quad2dSubdiv2H : public Quad2dSubdivision {
00227     public:
00228       virtual void createChildren(Quad2d& q) const;
00229       virtual const QuadSubdiv2H* topologicalStrategy() const;
00230       static const Quad2dSubdiv2H* instance();
00231       virtual ~Quad2dSubdiv2H();
00232     protected:
00233       virtual std::ostream& info(std::ostream& os) const;
00234     private:
00235       static std::auto_ptr<Quad2dSubdiv2H> instance_;
00236   };
00237 
00238   // ******************************************************** Quad2dSubdiv2V **
00239 
00246   class Quad2dSubdiv2V : public Quad2dSubdivision {
00247     public:
00248       virtual void createChildren(Quad2d& q) const;
00249       virtual const QuadSubdiv2V* topologicalStrategy() const;
00250       static const Quad2dSubdiv2V* instance();
00251       virtual ~Quad2dSubdiv2V();
00252     protected:
00253       virtual std::ostream& info(std::ostream& os) const;
00254     private:
00255       static std::auto_ptr<Quad2dSubdiv2V> instance_;
00256   };
00257 
00258   // **************************************************************** Quad2d **
00259 
00278   class Quad2d : public Cell2 {
00279     friend class Quad2dSubdivision;
00280     friend class Quad2dSubdiv4;
00281     friend class Quad2dSubdiv2H;
00282     friend class Quad2dSubdiv2V;
00283   public:
00285     struct Index {
00287       Level<2> level_;
00288 
00293       ushort i_;
00294 
00299       ushort j_;
00300 
00301       Index() : level_(0), i_(0), j_(0) {}
00302       Index(uchar k, uchar l, ushort i, ushort j) :
00303         level_(k), i_(i), j_(j) { level_.l_[1] = l; }
00304       std::ostream& info(std::ostream& os) const;
00305     };
00306 
00307     friend std::ostream& operator<<(std::ostream& os,
00308         const Quad2d::Index& i);
00309 
00315     Quad2d(Quad& cntr, const MappingQuad2d& map);
00316     virtual ~Quad2d();
00317 
00318   private:
00319     Quad2d(const Quad2d& other);
00320     Quad2d& operator=(const Quad2d& other);
00321 
00322   public:
00323 
00329     virtual Quad2d* child(uint i);
00334     virtual const Quad2d* child(uint i) const;
00335     inline bool hasChildren() const { return chld_ != 0; }
00336 
00344     const Quad2d* 
00345       child(uint i, Real xi, Real eta, Real& xiC, Real& etaC) const {
00346         const Quad2d* chld = child(i);
00347         if (chld == 0) return 0;
00348 
00349         Level<2> l = chld->level();
00350         if (idx_.level_.l_[0] == l.l_[0]) xiC = xi;
00351         else {
00352           xiC = (xi + idx_.i_) * 2.0 - chld->idx_.i_;
00353           if (xiC < 0.0 || xiC > 1.0) return 0;
00354         }
00355         if (idx_.level_.l_[1] == l.l_[1]) etaC = eta;
00356         else {
00357           etaC = (eta + idx_.j_) * 2.0 - chld->idx_.j_;
00358           if (etaC < 0.0 || etaC > 1.0) return 0;
00359         }
00360         return chld;
00361       }
00362 
00364     inline Quad& connector() const;
00365 
00373     Real2d chi(Real xi, Real eta) const;
00374 
00375     Real3d elemMap(const Real2d& coord_local) const
00376     {
00377       return chi(coord_local[0], coord_local[1]);
00378     }
00379 
00403     MapReal2d jacobian(const Real xi, const Real eta) const;
00404 
00406     MapReal2d jacobianInverse(const Real xi, const Real eta) const {
00407       return jacobian(xi, eta).inverse();
00408     }
00409 
00413     Real jacobianDeterminant(const Real xi, const Real eta) const {
00414       return jacobian(xi, eta).determinant();
00415     }
00416 
00422     Real lineElement(const Real xi, const uint edge) const;
00423 
00429     Level<2> level() const { return idx_.level_; }
00430 
00431     Real3d vertex(uint i) const;
00432     Real3d center() const {return chi(0.5, 0.5);};
00433 
00437     inline const MappingQuad2d* map() const {return map_;};
00448     const MappingEdge2d* edgeMap(uint edge) const;
00449     
00451     inline Quad2d* clone(Quad& cntr, MappingQuad2d* map) const {
00452       return new Quad2d(cntr, map, idx_);};
00453 
00466     virtual void setStrategy(const Quad2dSubdivision* strategy = 0)
00467       throw(StrategyChange);
00468 
00474     const Quad2dSubdivision* getStrategy() const { return subdivStrategy_; }
00475     protected:
00476     virtual std::ostream& info(std::ostream& os) const;
00477 
00479     MappingQuad2d* map_;
00481     Index idx_;
00482 
00486     Quad2d* createChild_(Quad& cntr, const Index& idx, bool flag) const;
00487 
00489     Quad2d(Quad& cntr, MappingQuad2d* map, const Index& idx);
00490     private:
00491 
00493     Quad& cntr_;
00494 
00496     Quad2d* lnk_;
00497 
00501     Quad2d* chld_;
00502 
00504     const Quad2dSubdivision* subdivStrategy_;
00505 
00506     // Edges as cells
00507     mutable concepts::Array<Edge2d*> edge_;
00508 
00515     virtual Quad2d* createChild_(Quad& cntr, const Index& idx) const;
00516   };
00517 
00518   Quad& Quad2d::connector() const { 
00519     return cntr_; 
00520   }
00521 
00522   std::ostream& operator<<(std::ostream& os, const Quad2d::Index& i);
00523 
00524   // ******************************************************** InfiniteQuad2d **
00525 
00533   class InfiniteQuad2d : public Cell2 {
00534   public:
00543     InfiniteQuad2d(InfiniteQuad& cntr, const Real2d& vtx0, const Real2d& vtx1);
00544 
00545     virtual Real2d chi(Real xi, Real eta) const = 0;
00546 
00547     Real3d vertex(uint i) const;
00548 
00549     virtual MapReal2d jacobian(const Real xi, const Real eta) const = 0;
00550 
00552     inline InfiniteQuad& connector() const { return cntr_; }
00553   protected:
00554     virtual std::ostream& info(std::ostream& os) const;
00555   private:
00557     Real2d vtx_[2];
00559     InfiniteQuad& cntr_;
00560   };
00561 
00562   // ******************************************************** InfiniteRect2d **
00563 
00571   class InfiniteRect2d : public InfiniteQuad2d {
00572     public:
00578     InfiniteRect2d(InfiniteQuad& cntr, const Real2d& vtx0, const Real2d& vtx1);
00579     virtual ~InfiniteRect2d();
00580 
00586     virtual InfiniteRect2d* child(uint i);
00591     virtual const InfiniteRect2d* child(uint i) const;
00592     inline bool hasChildren() const { return chld_ != 0; }
00593 
00601     virtual Real2d chi(Real xi, Real eta) const;
00602 
00603     Real3d elemMap(const Real2d& coord_local) const
00604     {
00605       return chi(coord_local[0], coord_local[1]);
00606     }
00607 
00608     virtual MapReal2d jacobian(const Real xi, const Real eta) const;
00609 
00611     Real3d center() const;
00612 
00614     inline InfiniteRect2d* clone(InfiniteQuad& cntr,
00615          const Real2d& vtx0, const Real2d& vtx1) const
00616     {
00617       return new InfiniteRect2d(cntr, vtx0, vtx1);
00618     }
00619 
00620   protected:
00621     virtual std::ostream& info(std::ostream& os) const;
00622   private:
00624     UnitNd<2> n_;
00625 
00627     InfiniteRect2d* lnk_;
00628 
00632     InfiniteRect2d* chld_;
00633   };
00634 
00635   // ************************************************************ Triangle3d **
00636 
00642   class Triangle3d : public Cell2 {
00643     public:
00645       struct Index {
00647         uchar  l_;
00648 
00653         ushort i_;
00654 
00659         ushort j_;
00660 
00661         Index();
00662         Index(uchar l, ushort i, ushort j);
00663         std::ostream& info(std::ostream& os) const;
00664       };
00665 
00666       friend std::ostream& operator<<(std::ostream& os,
00667           const Triangle3d::Index& i);
00668 
00674       Triangle3d(Triangle& cntr, const MapTriangle3d& map);
00675       virtual ~Triangle3d();
00676 
00682       virtual Triangle3d* child(uint i);
00687       virtual const Triangle3d* child(uint i) const;
00688 
00690       Triangle& connector() const { return cntr_; }
00691 
00699       Real3d chi(Real xi, Real eta) const;
00700 
00701       Real3d elemMap(const Real2d& coord_local) const
00702       {
00703         return chi(coord_local[0], coord_local[1]);
00704       }
00705 
00706       Real3d vertex(uint i) const;
00707       Real3d center() const {return chi(0.66666666666, 0.5);};
00708 
00710       inline const MapTriangle3d* map() const {return map_;};
00711 
00713       inline Triangle3d* clone(Triangle& cntr, MapTriangle3d* map) const {
00714         return new Triangle3d(cntr, map, idx_);};
00715     protected:
00716       virtual std::ostream& info(std::ostream& os) const;
00717     private:
00719       Index idx_;
00720 
00722       Triangle& cntr_;
00723 
00725       Triangle3d* lnk_;
00726 
00730       Triangle3d* chld_;
00731 
00733       MapTriangle3d* map_;
00734 
00736       Triangle3d(Triangle& cntr, MapTriangle3d* map, const Index& key);
00737   };
00738 
00739   std::ostream& operator<<(std::ostream& os, const Triangle3d::Index& i);
00740 
00741 
00742 } // namespace concepts
00743 
00744 #endif // cell2D_hh

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