topologytypes.hh
00001 #ifndef DUNE_GENERICGEOMETRY_TOPOLOGYTYPES_HH
00002 #define DUNE_GENERICGEOMETRY_TOPOLOGYTYPES_HH
00003
00004 #include <string>
00005
00006 #include <dune/common/static_assert.hh>
00007 #include <dune/grid/genericgeometry/misc.hh>
00008
00009 namespace Dune
00010 {
00011
00012 namespace GenericGeometry
00013 {
00014
00015 struct Point
00016 {
00017 static const unsigned int dimension = 0;
00018 static const unsigned int numCorners = 1;
00019
00020 static const unsigned int id = 0;
00021
00022 static std :: string name ()
00023 {
00024 return "p";
00025 }
00026 };
00027
00028
00029 template< class BaseTopology >
00030 struct Prism
00031 {
00032 static const unsigned int dimension = BaseTopology :: dimension + 1;
00033 static const unsigned int numCorners = 2 * BaseTopology :: numCorners;
00034
00035 static const unsigned int id = BaseTopology :: id + (1 << (dimension-1));
00036
00037 static std :: string name ()
00038 {
00039 return BaseTopology :: name() + "'";
00040 }
00041 };
00042
00043
00044 template< class BaseTopology >
00045 struct Pyramid
00046 {
00047 static const unsigned int dimension = BaseTopology :: dimension + 1;
00048 static const unsigned int numCorners = BaseTopology :: numCorners + 1;
00049
00050 static const unsigned int id = BaseTopology :: id;
00051
00052 static std :: string name ()
00053 {
00054 return BaseTopology :: name() + "°";
00055 }
00056 };
00057
00058
00059
00060 template< class Topology >
00061 struct BaseTopology;
00062
00063 template< class Base >
00064 struct BaseTopology< Prism< Base > >
00065 {
00066 typedef Base type;
00067 };
00068
00069 template< class Base >
00070 struct BaseTopology< Pyramid< Base > >
00071 {
00072 typedef Base type;
00073 };
00074
00075
00076
00077 template< class Topology >
00078 struct IsSimplex
00079 {
00080 static const bool value = ((Topology::id >> 1) == 0);
00081 };
00082
00083 template< class Topology >
00084 struct IsCube
00085 {
00086 static const bool value = ((Topology::id | 1) == (1 << Topology::dimension) - 1);
00087 };
00088
00089 template< class Topology >
00090 struct IsHybrid
00091 {
00092 static const bool value
00093 = !(IsSimplex< Topology >::value || IsCube< Topology >::value);
00094 };
00095
00096
00097
00098 template< unsigned int id, unsigned int dim >
00099 class Topology
00100 {
00101 static const unsigned int dimension = dim;
00102
00103 dune_static_assert( (id < (1 << dimension)), "id too large." );
00104
00105 static const bool isPrism = ((id >> (dimension-1)) != 0);
00106
00107 typedef typename Topology< (id & ~(1 << (dimension-1))), dimension-1 > :: type
00108 BaseTopology;
00109
00110 template< bool >
00111 struct Prism
00112 {
00113 typedef GenericGeometry :: Prism< BaseTopology > type;
00114 };
00115
00116 template< bool >
00117 struct Pyramid
00118 {
00119 typedef GenericGeometry :: Pyramid< BaseTopology > type;
00120 };
00121
00122 public:
00123 typedef typename ProtectedIf< isPrism, Prism, Pyramid > :: type type;
00124 };
00125
00126 template< unsigned int id >
00127 class Topology< id, 0 >
00128 {
00129 static const unsigned int dimension = 0;
00130
00131 dune_static_assert( (id < (1 << dimension)), "id too large." );
00132
00133 public:
00134 typedef Point type;
00135 };
00136
00137 }
00138
00139 }
00140
00141 #endif