Cell.hpp

00001 #ifndef __FIBER_FIELD_CELL_HPP
00002 #define __FIBER_FIELD_CELL_HPP
00003 
00004 #include "FiberType.hpp"
00005 #include <vector/MultiIndex.hpp>
00006 #include <eagle/FixedArray.hpp>
00007 
00008 
00009 namespace Fiber
00010 {
00011 
00012 template <int DIMS, int Elements, class IndexType>
00013 struct  Cell : public Eagle::FixedArray<IndexType, Elements>
00014 {
00015         enum { Dims = DIMS };
00016 
00017         typedef Eagle::FixedArray<IndexType, Elements> FixedArray_t;
00018 
00019         using FixedArray_t::operator=;
00020 };
00021 
00022 
00023 template <int Dims, class IndexType>
00024 struct SimplexCell : Cell<Dims, Dims+1, IndexType>
00025 {
00026         typedef Cell<Dims, Dims+1, IndexType> Base_t;
00027 
00028         using Base_t::operator=;
00029 
00030 static  const char*coordinate_name(int i)
00031         {
00032         static const char *n[] = 
00033                 {
00034                 "i","j","k","l","m","n","o"
00035                 }; 
00036                 assert(i<7);
00037                 return n[i];
00038         }
00039 };
00040 
00041 
00042 template <int Dims, class IndexType>
00043 struct RegularCell : Cell<Dims, (1<<Dims), IndexType>
00044 {
00045         typedef Cell<Dims, (1<<Dims), IndexType > Base_t;
00046 
00047         using Base_t::operator=;
00048 
00049 static  const char*coordinate_name(int i)
00050         {
00051 static const char*dims0[] = {"00"},
00052                  *dims1[] = {"i0", "i1"},
00053                  *dims2[] = {"i00", "i01", "i10", "i11"},
00054                  *dims3[] = {"i000", "i001", "i010", "i011" ,
00055                              "i100", "i101", "i110", "i111"},
00056                  *dims4[] = {"i0000", "i0001", "i0010", "i0011" ,
00057                              "i0100", "i0101", "i0110", "i0111" , 
00058                              "i1000", "i1001", "i1010", "i1011" ,
00059                              "i1100", "i1101", "i1110", "i1111" } 
00060                  ; 
00061 
00062  static const char**n[] = { dims0, dims1, dims2, dims3, dims4 };
00063 
00064                 return n[Dims][i];
00065         }
00066 };
00067 
00068 
00069 typedef SimplexCell<1, uint32_t> EdgeCell32;
00070 typedef SimplexCell<2, uint32_t> TriangleCell32;
00071 typedef SimplexCell<3, uint32_t> TetrahedronCell32;
00072 
00073 typedef RegularCell<2, uint32_t> QuadCell32;
00074 typedef RegularCell<3, uint32_t> HexahedronCell32;
00075 
00076 
00077 
00078 typedef SimplexCell<1, uint64_t> EdgeCell64;
00079 typedef SimplexCell<2, uint64_t> TriangleCell64;
00080 typedef SimplexCell<3, uint64_t> TetrahedronCell64;
00081 
00082 typedef RegularCell<2, uint64_t> QuadCell64;
00083 typedef RegularCell<3, uint64_t> HexahedronCell64;
00084 
00085 
00086 
00087 typedef EdgeCell32              EdgeCell;
00088 typedef TriangleCell32          TriangleCell;
00089 typedef TetrahedronCell32       TetrahedronCell;
00090 
00091 typedef QuadCell32              QuadCell;
00092 typedef HexahedronCell32        HexahedronCell;
00093 
00094 
00095 
00096 } // namespace Fiber
00097 
00098 
00099 
00100 namespace Eagle
00101 {
00102 
00103 template <int Dims, int Elements, class IndexType>
00104 struct MetaInfo<Fiber::Cell<Dims, Elements, IndexType> >
00105 {
00106         enum 
00107         { 
00109                 MULTIPLICITY = Elements,
00110                 RANK = Dims,
00111                 GRADE = 0
00112         };
00113 
00115         typedef IndexType element_t;
00116 
00117         // An eventually associated coordinate system
00118         typedef void Chart_t;
00119 
00120 static  const element_t&getComponent(const Fiber::Cell<Dims, Elements, IndexType>&t, int i) 
00121         {
00122                 return t[i];
00123         }
00124 };
00125 
00126 
00127 template <int Dims, class IndexType>
00128 struct MetaInfo<Fiber::SimplexCell<Dims,IndexType> > : MetaInfo<typename Fiber::SimplexCell<Dims,IndexType>::Base_t>
00129 {
00130         typedef Fiber::SimplexCell<Dims,IndexType> Chart_t;
00131 };
00132 
00133 template <int Dims, class IndexType>
00134 struct MetaInfo<Fiber::RegularCell<Dims,IndexType> > : MetaInfo<typename Fiber::RegularCell<Dims,IndexType>::Base_t>
00135 {
00136         typedef Fiber::RegularCell<Dims,IndexType> Chart_t;
00137 };
00138 
00139 
00140 } // Eagle
00141 
00142 #endif // __FIBER_FIELD_CELL_HPP