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

integration/karniadakis.hh
Go to the documentation of this file.
00001 /* Expansion bases for tensorial shape functions not only for
00002  * quads and hexahedrons but also for triangles and tetrahedrons.
00003  * Due to Karniadakis, Sherwin
00004  */
00005 
00006 #ifndef karniadakis_hh
00007 #define karniadakis_hh
00008 
00009 #include <iostream>
00010 
00011 #if __ICC == 800
00012 #  include <hash_map>
00013 #  define __gnu_cxx std
00014 #else
00015 #  if __GNUC__ > 2
00016 #    include <ext/hash_map>
00017 #    if __GNUC__==3 && __GNUC_MINOR__ < 1
00018 #      define __gnu_cxx std
00019 #    endif
00020 #  else
00021 #    include <hash_map>
00022 #    define __gnu_cxx std
00023 #  endif
00024 #endif
00025 
00026 #include "basics/typedefs.hh"
00027 #include "shapefunction.hh"
00028 
00029 namespace concepts {
00030 
00031   // **************************************************************** Orders **
00032 
00037   class OrdersBase {
00038     public:
00040       OrdersBase() : P_(0) {}
00041 
00043       OrdersBase(const int P) : P_(P) {}
00044 
00046       inline int P() const { return P_; }
00047     protected:
00049       int P_;
00050   };
00051 
00052   template<int number>
00053     class Orders;
00054 
00055   template<int number>
00056     std::ostream& operator<< (std::ostream& os, const Orders<number>& o) { 
00057       for (unsigned int i = 0; i < number; ++i) {
00058         os << "p(" << i << ") = " << o.p_[i] << ", ";
00059       }
00060       os << "P = " << o.P_;
00061       return os;
00062     }
00063 
00069   template<int number>
00070     class Orders : public OrdersBase {
00071       friend std::ostream& operator<< <>(std::ostream& os,
00072           const Orders<number>& o);
00073       public:
00075       Orders();
00076 
00078       Orders(const int p0, const int P, const int p1 = 0, const int p2 = 0);
00079 
00081       inline int p(const uint i) const { 
00082         if (i < number) return p_[i];
00083         else return 0;
00084       }
00085 
00087       inline bool operator==(const Orders<number>& o) const {
00088         bool equal = true && (P_ == o.P_);
00089         for (uint i = 0; i < number; ++i)
00090           equal &= (p_[i] == o.p_[i]);
00091         return equal;
00092       }
00093 
00095       inline bool operator<(const Orders<number>& o) const {
00096         for (uint i = 0; i < number; ++i)
00097           if (p_[i] < o.p_[i]) return true;
00098         return false;
00099       }
00100       private:
00102       int p_[number];
00103     };
00104 
00105 } // namespace concepts
00106 
00107 namespace __gnu_cxx {
00108 
00109   template<int number>
00110     size_t hash_value(const concepts::Orders<number>& o);
00111 
00112   template<int number>
00113     struct hash<concepts::Orders<number> > {
00114       size_t operator()(const concepts::Orders<number>& o) const {
00115         return hash_value(o);
00116       }
00117     };
00118 
00120   template<int number>
00121     struct OrdersEqual {
00122       bool operator()(const concepts::Orders<number>& x,
00123           const concepts::Orders<number>& y) const {
00124         return x == y;
00125       }
00126     };
00127 } // namespace __gnu_cxx
00128 
00129 namespace concepts {
00130 
00131   // *********************************************************** Karniadakis **
00132 
00175   template<int type, int mode>
00176     class Karniadakis : public ShapeFunction1D<Real> {
00177       public:
00192         Karniadakis(const int P, const Real* xP, const int NxP,
00193             const int Q = 0, const int R = 0, const bool cache = true);
00194 
00196         Karniadakis(const Karniadakis<type, mode>& arg);
00197         static void clearCache() { principal_H.clear(); }
00198 
00199         ~Karniadakis();
00200       protected:
00201         virtual std::ostream& info(std::ostream& os) const;
00202       private:
00204         Orders<type> orders_;
00205 
00210         static typename __gnu_cxx::hash_map<Orders<type>, Real*,
00211                         __gnu_cxx::hash<Orders<type> >,
00212                         __gnu_cxx::OrdersEqual<type> > principal_H;
00213 
00215         bool cache_;
00216     };
00217 
00218 
00219 } // namespace concepts
00220 
00221 #endif // karniadakis_hh

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