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

/export/development/ViennaGrid/release/ViennaGrid-1.0.0/viennagrid/forwards.h

Go to the documentation of this file.
00001 #ifndef VIENNAGRID_FORWARDS_H
00002 #define VIENNAGRID_FORWARDS_H
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 
00030 #include <iostream>
00031 #include <vector>
00032 #include <map>
00033 #include <cstddef>     //for std::size_t
00034 #include <cstdlib>     //for EXIT_SUCCESS and EXIT_FAILURE
00035 
00036 #include "viennadata/api.hpp"
00037 
00038 //Debug levels:
00039 //VIENNAGRID_DEBUG_ALL          Output every little piece of debug information
00040 //VIENNAGRID_DEBUG_IO           Debug IO operations
00041 //VIENNAGRID_DEBUG_REFINEMENT   Debug refinement algorithms
00042 //VIENNAGRID_DEBUG_STATUS       Print status messages to std::cout (very little debug info)
00043 
00044 #ifdef VIENNAGRID_DEBUG_ALL
00045   #define VIENNAGRID_DEBUG_IO
00046   #define VIENNAGRID_DEBUG_REFINEMENT
00047   #define VIENNAGRID_DEBUG_STATUS
00048 #endif
00049 
00055 namespace viennagrid
00056 {
00058   typedef std::size_t       dim_type;
00059   
00060   /********* Tags ***********************/
00061   
00063   template <long d>
00064   struct cartesian_cs;    //Cartesian coordinate system
00065   
00067   struct polar_cs;        //Polar coordinate system (r, phi)
00069   struct spherical_cs;    //Spherical coordinate system (r, theta, phi)
00071   struct cylindrical_cs;  //Cylindrical coordinate system (rho, theta, z)
00072 
00073   //Dimension Tag: (for tag dispatching)
00075   template <long d>
00076   struct dimension_tag
00077   {
00078       enum{ value = d };
00079   };
00080   
00081   //Tags for the handling of elements at different topological levels (see topology::subcell_desc)
00083   struct full_handling_tag {};
00085   struct no_handling_tag {};
00086 
00087   
00088   /********* Forward definitions of main classes *******************/
00089   
00091   struct point_tag;
00092 
00093   // Simplex family:
00095   template <long dim>
00096   struct simplex_tag;
00097   
00099   typedef simplex_tag<1>    line_tag;
00101   typedef simplex_tag<2>    triangle_tag;
00103   typedef simplex_tag<3>    tetrahedron_tag;
00104   
00105   // Hypercube family:
00107   template <long dim>
00108   struct hypercube_tag;
00109 
00110   //typedef hypercube_tag<1>    line_tag;
00112   typedef hypercube_tag<2>  quadrilateral_tag;
00114   typedef hypercube_tag<3>  hexahedron_tag;
00115 
00116 
00117   //forward declarations:
00118   template <typename CoordType, typename CoordinateSystem>
00119   class point_t;
00120   
00121   template <typename ConfigType, typename ElementTag>
00122   class element_t;
00123 
00124   template <typename ConfigType, typename ElementType>
00125   class element_key;
00126 
00127   //Segment type: 
00128   template <typename ConfigType>
00129   class segment_t;
00130 
00131   template <typename ConfigType>
00132   class domain_t;
00133   
00134   /********* Other *******************/
00135 
00136   template <typename host_element,
00137             long dim,
00138             bool is_coboundary = false>
00139   class ncell_range;
00140 
00141   template <typename host_element,
00142             long dim,
00143             bool is_coboundary = false>
00144   class const_ncell_range;
00145   
00147   template <typename T, long dim> //topological dimension of the elements over which to iterate
00148   class coboundary_key
00149   {
00150     public:
00151       coboundary_key(T const & t_) : t(&t_) {}
00152       
00154       bool operator<(coboundary_key const & other) const
00155       {
00156         return t < other.t;
00157       }
00158     private:
00159       T const * t;
00160   };
00161 
00162   template <typename T>
00163   class boundary_key;
00164 
00165   class interface_key;
00166 
00167   template <typename SegmentType>
00168   class segment_mapping_key
00169   {
00170     public:
00171       segment_mapping_key(SegmentType const & seg) : pSeg(&seg) {}
00172       
00173       //for compatibility with std::map
00174       bool operator<(segment_mapping_key const & other) const
00175       {
00176         return pSeg < other.pSeg;
00177       }
00178       
00179     private:
00180       SegmentType const * pSeg;
00181   };
00182   
00183   
00184   //proxy classes for iterator/container retrieval:
00186   template <typename T>
00187   class const_ncell_proxy
00188   {
00189     public:
00190       const_ncell_proxy(T const & t_) : t(t_) {}
00191       
00192       T const & get() const { return t; }
00193     
00194     private:
00195       T const & t;
00196   };
00197   
00199   template <typename T>
00200   class ncell_proxy
00201   {
00202     public:
00203       ncell_proxy(T & t_) : t(t_) {}
00204       
00205       T & get() const { return t; }
00206     
00207     private:
00208       T & t;
00209   };
00210   
00211 
00212   //ID handling:
00214   class pointer_id
00215   {
00216     public:
00217       typedef pointer_id *  id_type;
00218       
00219       //for compatibility:
00220       void id(const pointer_id *) { };
00221       void id(long) { };
00222       const pointer_id * id() const { return this; };
00223       pointer_id * id() { return this; };
00224   };
00225 
00227   class integral_id
00228   {
00229     public:
00230       typedef long   id_type;
00231       
00232       integral_id() : id_(-1) {};
00233 
00234       long id() const { return id_; };
00235       void id(long new_id) { id_ = new_id; };
00236 
00237     protected:
00238       long id_;
00239   };
00240   
00242   namespace topology
00243   {
00244     
00250     template <typename ElementTag, 
00251               long level = ElementTag::dim>
00252     struct bndcells
00253     {
00254       //the default case is simultaneously a pathetic case:
00255       //cell-handling within the cell
00256 
00258       enum{ num = 1 };     //1 cell
00259 
00261       typedef ElementTag            tag;
00262     };
00263 
00269     template <typename ElementTag, long k>
00270     struct bndcell_filler {};
00271     
00272   }
00273   
00274   
00276   namespace result_of
00277   {
00279     template <typename ConfigType, typename ElementTag>    //by default, every element is equipped with an ID
00280     struct element_id_handler
00281     {
00282       typedef integral_id     type;
00283     };
00284 
00285     template <typename T, long dim = 0>
00286     struct iterator;
00287     
00289     template <typename T>
00290     struct config
00291     {
00292       typedef typename T::config_type     type; 
00293     };
00294     
00296     template <typename ConfigType>
00297     struct config< domain_t<ConfigType> >
00298     {
00299       typedef ConfigType     type; 
00300     };
00301 
00303     template <typename ConfigType>
00304     struct config< segment_t<ConfigType> >
00305     {
00306       typedef ConfigType     type; 
00307     };
00308 
00310     template <typename ConfigType, typename ElementTag>
00311     struct config< element_t<ConfigType, ElementTag> >
00312     {
00313       typedef ConfigType     type; 
00314     };
00315 
00316     
00317     template <typename T,   //type of host (domain, segment, other element)
00318               long dim,
00319               long cell_level = config<T>::type::cell_tag::dim>
00320     struct element_container;
00321     
00322     template <typename T, 
00323               long dim>  //topological level
00324     struct ncell_range;
00325     
00326     
00333     template <typename Config,
00334               long dim,
00335               long cell_level = Config::cell_tag::dim>
00336     struct ncell
00337     {
00338       typedef element_t<Config, 
00339                         typename topology::bndcells<typename Config::cell_tag,
00340                                                        dim>::tag
00341                        > type;
00342     };
00343     
00345     template <typename Config,
00346               long cell_level>
00347     struct ncell <Config, cell_level, cell_level>
00348     {
00349       typedef element_t<Config, 
00350                         typename Config::cell_tag>       type;
00351     };
00352     
00354     template <typename Config>
00355     struct point
00356     {
00357       typedef viennagrid::point_t<typename Config::numeric_type, typename Config::coordinate_system_tag>   type;
00358     };
00359     
00360 
00367     template <typename ConfigType, typename T, long dim>
00368     struct bndcell_orientation
00369     {
00370       typedef full_handling_tag    type;
00371     };
00372     
00373     
00380     template <typename ConfigType, typename T, long dim>
00381     struct bndcell_handling
00382     {
00383       typedef full_handling_tag    type;
00384     };
00385 
00386     
00392     template <typename ConfigType, typename T>
00393     struct bndcell_handling<ConfigType, T, 0>
00394     {
00395       typedef full_handling_tag    type; 
00396     };
00397     
00398     
00399 
00400     //for domains
00404     template <typename ConfigType, long dim>
00405     struct bndcell_handling<ConfigType, domain_t<ConfigType>, dim>
00406     {
00407       typedef full_handling_tag    type;
00408     };
00409     
00414     template <typename ConfigType>
00415     struct bndcell_handling<ConfigType, domain_t<ConfigType>, 0>
00416     {
00417       typedef full_handling_tag    type; 
00418     };
00419 
00420     
00421     //for segments:
00425     template <typename ConfigType, long dim>
00426     struct bndcell_handling<ConfigType, segment_t<ConfigType>, dim>
00427     {
00428       typedef typename bndcell_handling<ConfigType, typename ConfigType::cell_tag, dim>::type    type;
00429     };
00430 
00435     template <typename ConfigType>
00436     struct bndcell_handling<ConfigType, segment_t<ConfigType>, 0>  //avoid ambiguities
00437     {
00438       typedef typename bndcell_handling<ConfigType, typename ConfigType::cell_tag, 0>::type    type;
00439     };
00440     
00441   }
00442   
00443   // providing forwards for the ncells function
00444   template <long dim, typename DomainConfig>
00445   ncell_range<domain_t<DomainConfig>, dim>
00446   ncells(domain_t<DomainConfig> & d);
00447 
00448   template <typename DomainConfig>
00449   ncell_proxy< domain_t<DomainConfig> >
00450   ncells(domain_t<DomainConfig> & d);
00451 
00452   template <long dim, typename DomainConfig>
00453   ncell_range<segment_t<DomainConfig>, dim>
00454   ncells(segment_t<DomainConfig> & d);
00455 
00456   template <typename DomainConfig>
00457   ncell_proxy< segment_t<DomainConfig> >
00458   ncells(segment_t<DomainConfig> & d);
00459 
00460   template <long dim, typename Config, typename ElementTag>
00461   typename result_of::ncell_range< element_t<Config, ElementTag>, dim>::type
00462   ncells(element_t<Config, ElementTag> & d);
00463   
00464   template <typename Config, typename ElementTag>
00465   ncell_proxy< element_t<Config, ElementTag> >
00466   ncells(element_t<Config, ElementTag> & d);
00467 
00468    // norm tags for: algorithm/norm.hpp
00470   struct one_tag {};
00472   struct two_tag {};
00474   struct inf_tag {};
00475    
00477   struct seg_cell_normal_tag {};
00478   
00480   struct seg_cell_normal_data {
00481     typedef viennagrid::point_t<double, cartesian_cs<3> >         point_type;
00482     typedef std::map<std::size_t, point_type>    type;
00483   };
00484    
00485    
00486   // 
00487   //refinement
00488   //
00489    
00490   template <typename T>
00491   struct element_refinement;
00492    
00494   struct refinement_key {};
00495    
00496   template <typename DomainType, typename RefinementTag>
00497   class refinement_proxy;
00498    
00500   struct uniform_refinement_tag {};
00501   
00503   struct local_refinement_tag {};
00504   
00506   namespace detail
00507   {
00508     template <typename ConfigTypeIn, typename ConfigTypeOut>
00509     void refine_impl(domain_t<ConfigTypeIn> const & domain_in,
00510                     domain_t<ConfigTypeOut> & domain_out,
00511                     uniform_refinement_tag);
00512     
00513     template <typename ConfigTypeIn, typename ConfigTypeOut>
00514     void refine_impl(domain_t<ConfigTypeIn> const & domain_in,
00515                     domain_t<ConfigTypeOut> & domain_out,
00516                     local_refinement_tag);    
00517   }
00518   
00519   //
00520   // Voronoi information:
00521   //
00523   struct voronoi_interface_area_key {};
00525   struct voronoi_box_volume_key {}; 
00526 }
00527 
00528 /*
00529 namespace viennadata
00530 {
00531   namespace config
00532   {
00533     template <>
00534     struct key_dispatch<viennagrid::refinement_key>
00535     {
00536       typedef type_key_dispatch_tag    tag;
00537     };    
00538     
00539     template <>
00540     struct key_dispatch<viennagrid::voronoi_interface_area_key>
00541     {
00542       typedef type_key_dispatch_tag    tag;
00543     };
00544     
00545     template <>
00546     struct key_dispatch<viennagrid::voronoi_box_volume_key>
00547     {
00548       typedef type_key_dispatch_tag    tag;
00549     };
00550   }
00551 }
00552 */
00553 
00554 // tell ViennaData to use a type-based key dispatch for the refinement and the voronoi keys
00555 VIENNADATA_ENABLE_TYPE_BASED_KEY_DISPATCH(viennagrid::refinement_key)
00556 VIENNADATA_ENABLE_TYPE_BASED_KEY_DISPATCH(viennagrid::voronoi_interface_area_key)
00557 VIENNADATA_ENABLE_TYPE_BASED_KEY_DISPATCH(viennagrid::voronoi_box_volume_key)
00558 
00560 
00562 #define VIENNAGRID_DISABLE_BOUNDARY_NCELL(arg_CONFIG, arg_TAG, arg_DIM) \
00563  namespace viennagrid { namespace result_of { \
00564     template <> \
00565     struct bndcell_handling<arg_CONFIG, arg_TAG, arg_DIM> { \
00566       typedef no_handling_tag    type; \
00567     }; \
00568  } }
00569 
00571 #define VIENNAGRID_ENABLE_BOUNDARY_NCELL(arg_CONFIG, arg_TAG, arg_DIM) \
00572  namespace viennagrid { namespace result_of { \
00573     template <> \
00574     struct bndcell_handling<arg_CONFIG, arg_TAG, arg_DIM> { \
00575       typedef full_handling_tag    type; \
00576     }; \
00577  } }
00578 
00580 #define VIENNAGRID_GLOBAL_DISABLE_BOUNDARY_NCELL(arg_TAG, arg_DIM) \
00581  namespace viennagrid { namespace result_of { \
00582     template <typename ConfigType> \
00583     struct bndcell_handling<ConfigType, arg_TAG, arg_DIM> { \
00584       typedef no_handling_tag    type; \
00585     }; \
00586  } }
00587 
00588 //note that VIENNAGRID_GLOBAL_ENABLE_BOUNDARY_NCELL(arg_TAG, arg_DIM)  does not make sense, since the default is full_handling already.
00589 
00590 //
00591 // Same for orientation
00592 //
00594 #define VIENNAGRID_DISABLE_BOUNDARY_NCELL_ORIENTATION(arg_CONFIG, arg_TAG, arg_DIM) \
00595  namespace viennagrid { namespace result_of { \
00596     template <> \
00597     struct bndcell_orientation<arg_CONFIG, arg_TAG, arg_DIM> { \
00598       typedef no_handling_tag    type; \
00599     }; \
00600  } }
00601 
00603 #define VIENNAGRID_ENABLE_BOUNDARY_NCELL_ORIENTATION(arg_CONFIG, arg_TAG, arg_DIM) \
00604  namespace viennagrid { namespace result_of { \
00605     template <> \
00606     struct bndcell_orientation<arg_CONFIG, arg_TAG, arg_DIM> { \
00607       typedef full_handling_tag    type; \
00608     }; \
00609  } }
00610 
00612 #define VIENNAGRID_GLOBAL_DISABLE_BOUNDARY_NCELL_ORIENTATION(arg_TAG, arg_DIM) \
00613  namespace viennagrid { namespace result_of { \
00614     template <typename ConfigType> \
00615     struct bndcell_orientation<ConfigType, arg_TAG, arg_DIM> { \
00616       typedef no_handling_tag    type; \
00617     }; \
00618  } }
00619 
00620 //
00621 // ID for elements:
00622 //
00624 #define VIENNAGRID_DISABLE_NCELL_ID(arg_CONFIG, arg_TAG) \
00625  namespace viennagrid { namespace result_of { \
00626     template <> \
00627     struct element_id_handler<arg_CONFIG, arg_TAG> { \
00628       typedef pointer_id    type; \
00629     }; \
00630  } }
00631 
00633 #define VIENNAGRID_ENABLE_NCELL_ID(arg_CONFIG, arg_TAG) \
00634  namespace viennagrid { namespace result_of { \
00635     template <> \
00636     struct element_id_handler<arg_CONFIG, arg_TAG> { \
00637       typedef integral_id    type; \
00638     }; \
00639  } }
00640  
00642 #define VIENNAGRID_GLOBAL_DISABLE_NCELL_ID(arg_TAG) \
00643  namespace viennagrid { namespace result_of { \
00644     template <typename ConfigType> \
00645     struct element_id_handler<ConfigType, arg_TAG> { \
00646       typedef pointer_id    type; \
00647     }; \
00648  } }
00649 
00650 
00651 //
00653 //
00655 #define VIENNAGRID_DISABLE_DOMAIN_NCELL(arg_CONFIG, arg_DIM) \
00656  namespace viennagrid { namespace result_of { \
00657     template <> \
00658     struct bndcell_handling<arg_CONFIG, domain_t<arg_CONFIG>, arg_DIM> { \
00659       typedef no_handling_tag    type; \
00660     }; \
00661  } }
00662 
00664 #define VIENNAGRID_ENABLE_DOMAIN_NCELL(arg_CONFIG, arg_DIM) \
00665  namespace viennagrid { namespace result_of { \
00666     template <> \
00667     struct bndcell_handling<arg_CONFIG, domain_t<arg_CONFIG>, arg_DIM> { \
00668       typedef full_handling_tag    type; \
00669     }; \
00670  } }
00671 
00673 #define VIENNAGRID_GLOBAL_DISABLE_DOMAIN_NCELL(arg_DIM) \
00674  namespace viennagrid { namespace result_of { \
00675     template <typename ConfigType> \
00676     struct bndcell_handling<ConfigType, domain_t<ConfigType>, arg_DIM> { \
00677       typedef no_handling_tag    type; \
00678     }; \
00679  } }
00680 
00681 //
00683 //
00685 #define VIENNAGRID_ENABLE_NCELL_ID_FOR_DATA(arg_CONFIG, arg_CELLTAG) \
00686 namespace viennadata { namespace config { \
00687     template <> struct object_identifier<viennagrid::element_t<arg_CONFIG, arg_CELLTAG> >  { \
00688       typedef object_provided_id    tag; \
00689       typedef size_t                id_type; \
00690       static size_t get(viennagrid::element_t<arg_CONFIG, arg_CELLTAG> const & obj) { return obj.id(); } \
00691     };  }  }
00692 
00694 #define VIENNAGRID_ENABLE_ALL_NCELL_ID_FOR_DATA(arg_CONFIG) \
00695 namespace viennadata { namespace config { \
00696     template <typename CellTag> struct object_identifier<viennagrid::element_t<arg_CONFIG, CellTag> >  { \
00697       typedef object_provided_id    tag; \
00698       typedef size_t                id_type; \
00699       static size_t get(viennagrid::element_t<arg_CONFIG, CellTag> const & obj) { return obj.id(); } \
00700     };  }  }
00701 
00703 #define VIENNAGRID_GLOBAL_ENABLE_NCELL_ID_FOR_DATA(arg_CELLTAG) \
00704 namespace viennadata { namespace config { \
00705     template <typename ConfigType> struct object_identifier<viennagrid::element_t<ConfigType, arg_CELLTAG> >  { \
00706       typedef object_provided_id    tag; \
00707       typedef size_t                id_type; \
00708       static size_t get(viennagrid::element_t<ConfigType, arg_CELLTAG> const & obj) { return obj.id(); } \
00709     };  }  }
00710 
00712 #define VIENNAGRID_GLOBAL_ENABLE_ALL_NCELL_ID_FOR_DATA() \
00713 namespace viennadata { namespace config { \
00714     template <typename ConfigType, typename CellTag> struct object_identifier<viennagrid::element_t<ConfigType, CellTag> >  { \
00715       typedef object_provided_id    tag; \
00716       typedef size_t                id_type; \
00717       static size_t get(viennagrid::element_t<ConfigType, CellTag> const & obj) { return obj.id(); } \
00718     };  }  }
00719 
00720 #endif

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