• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

/export/development/ViennaGrid/release/ViennaGrid-1.0.0/viennagrid/element.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAGRID_ELEMENT_HPP
00002 #define VIENNAGRID_ELEMENT_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2011, Institute for Microelectronics,
00006                        Institute for Analysis and Scientific Computing,
00007                        TU Wien.
00008 
00009                             -----------------
00010                      ViennaGrid - The Vienna Grid Library
00011                             -----------------
00012 
00013    Authors:      Karl Rupp                           rupp@iue.tuwien.ac.at
00014                  Josef Weinbub                    weinbub@iue.tuwien.ac.at
00015                
00016    (A list of additional contributors can be found in the PDF manual)
00017 
00018    License:      MIT (X11), see file LICENSE in the base directory
00019 ======================================================================= */
00020 
00021 
00022 #include "viennagrid/forwards.h"
00023 #include "viennagrid/detail/element_iterators.hpp"
00024 #include "viennagrid/detail/boundary_ncell_layer.hpp"
00025 
00026 #include <vector>
00027 
00032 namespace viennagrid
00033 {
00034   
00036 
00041   template <typename ConfigType,
00042             typename ElementTag>
00043   class element_t :
00044       public boundary_ncell_layer < ConfigType, ElementTag, ElementTag::dim - 1>,
00045       public result_of::element_id_handler<ConfigType, ElementTag>::type
00046   {
00047       typedef typename ConfigType::numeric_type                   ScalarType;
00048       typedef boundary_ncell_layer < ConfigType, ElementTag, ElementTag::dim - 1>             Base;
00049       typedef typename result_of::point<ConfigType>::type         PointType;
00050       typedef typename result_of::ncell<ConfigType, 0>::type      VertexType;
00051       typedef topology::bndcells<ElementTag, 0>                                 VertexSpecs;
00052 
00053     public:
00055       typedef ConfigType                                       config_type;
00057       typedef ElementTag                                       tag;
00059       typedef typename result_of::element_id_handler<ConfigType, point_tag>::type::id_type    id_type;
00060 
00061       element_t ( ) {};   //construction of "template" for this type
00062 
00063       element_t (const element_t & e2) : Base(e2)
00064       {
00065         //std::cout << "Copy constructor Element " << this << std::endl;
00066         this->id(e2.id());
00067       };
00068 
00070       template <typename DomainType>
00071       void fill(DomainType & dom)
00072       {
00073         Base::fill_level(dom);
00074       }
00075 
00077       void vertices(VertexType **vertices_)
00078       {
00079         for(int i=0; i<VertexSpecs::num; i++)
00080         {
00081           Base::vertices_[i] = vertices_[i];
00082           //std::cout << i << " ";
00083         }
00084         //std::cout << std::endl;
00085       }
00086 
00087   };
00088 
00090   template <typename ConfigType, typename ElementTag>
00091   std::ostream & operator<<(std::ostream & os, element_t<ConfigType, ElementTag> const & el)
00092   {
00093     typedef element_t<ConfigType, ElementTag>                ElementType;
00094     typedef typename viennagrid::result_of::const_ncell_range<ElementType, 0>::type    VertexRange;
00095     typedef typename viennagrid::result_of::iterator<VertexRange>::type          VertexIterator;
00096     
00097     os << "-- " << ElementTag::name() << ", ID: " << el.id() << " --";
00098     VertexRange vertices = viennagrid::ncells(el);
00099     for (VertexIterator vit  = vertices.begin();
00100                         vit != vertices.end();
00101                       ++vit)
00102       os << std::endl << "  " << *vit;
00103     
00104     return os;
00105   }
00106 
00107   
00108   
00109   //vertex-type needs separate treatment:
00111   template <typename ConfigType>
00112   class element_t <ConfigType, point_tag> :
00113     public result_of::element_id_handler<ConfigType, point_tag>::type
00114   {
00115       typedef typename result_of::point<ConfigType>::type          PointType;
00116       typedef typename ConfigType::numeric_type                    CoordType;
00117       typedef typename result_of::ncell<ConfigType, 0>::type       VertexType;
00118       typedef typename ConfigType::cell_tag                        CellTag;
00119 
00120     public:
00121       typedef ConfigType                                       config_type;
00122       typedef point_tag                                        tag;
00123       typedef typename result_of::element_id_handler<ConfigType, point_tag>::type::id_type    id_type;
00124 
00125       element_t() { };
00126 
00127       element_t(PointType const & p, long id = -1) : point_(p)
00128       {
00129         this->id(id);
00130       };
00131 
00132       element_t(const element_t & e2)
00133       {
00134         //std::cout << "Copy constructor Element (Vertex) " << this << std::endl;
00135         point_ = e2.point_;
00136         this->id(e2.id());
00137       }
00138 
00139       //clean up any data associated with the element if it is destroyed:
00140       ~element_t() { viennadata::erase<viennadata::all, viennadata::all>()(*this); }
00141 
00142       element_t & operator=(const element_t & other)
00143       {
00144         point_ = other.point_;
00145         this->id(other.id());                
00146         return *this;
00147       }
00148 
00150       PointType & point() { return point_; }
00152       PointType const & point() const { return point_; }
00153       
00154       //convenience access to coordinates of the vertex:
00156       CoordType & operator[](std::size_t i) { return point_[i]; }
00158       CoordType const & operator[](std::size_t i) const { return point_[i]; }
00159       
00161       std::size_t size() const { return point_.size(); }
00162 
00164       bool operator<(const element_t e2) const { return point_ < e2.point_; }
00166       bool operator>(const element_t e2) const { return point_ > e2.point_; }
00167 
00168     private:
00169       PointType point_;
00170   };
00171 
00173   template <typename ConfigType>
00174   std::ostream & operator<<(std::ostream & os, element_t<ConfigType, point_tag> const & el)
00175   {
00176     os << "-- Vertex, ID: " << el.id() << "; Point: " << el.point();
00177     
00178     return os;
00179   }
00180 
00181   
00182 }
00183 
00184 
00185 #endif

Generated on Wed Sep 14 2011 19:21:30 for ViennaGrid by  doxygen 1.7.1