Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Search for

# DofT.h

Go to the documentation of this file.

    00001 #ifndef DOFT_IS_INCLUDED
    00002 #define DOFT_IS_INCLUDED
    00003
    00004
    00005 #include <map>
    00006 #include <vector>
    00007 #include <iterator>
    00008 #include <iostream>
    00009
    00010
    00011 using namespace std;
    00012
    00013
    00014 template <class D, class C>
    00015 class DofT {
    00016   protected:
    00017   bool create_index2dof, create_dof2loc;
    00018   int counter;
    00019   // the structures loc2dof, dof2index, and doc2loc  are completely dynamic
    00020   // they are all initialized and updated by insert_dof(int e, int i, ex Li).
    00021
    00022   // (int e, int i) ->  int j
    00023   map<pair<int,int>, int>          loc2dof;
    00024   // (ex Lj)    -> int j
    00025   map<D,int,C>                     dof2index;
    00026   typename map<D,int,C>:: iterator iter;
    00027
    00028   // (int j)        -> ex Lj
    00029   map<int,D>                     index2dof;
    00030   // (ex j)    -> vector< pair<e1, i1>, ..  pair<en, in> >
    00031   map <int, vector<pair<int,int> > >  dof2loc;
    00032
    00033   public:
    00034   DofT( bool create_index2dof_ = false, bool create_dof2loc_ = false ) {
    00035     counter = -1;
    00036     create_index2dof = create_index2dof_;
    00037     create_dof2loc   = create_dof2loc;
    00038   }
    00039   ~DofT() {}
    00040   int insert_dof(int e, int i, D Li);  // to update the internal structures
    00041
    00042   // Helper functions to be used when the dofs have been set.
    00043   // These do not modify the internal structure.
    00044   int glob_dof(int e, int i);
    00045   int glob_dof(D Lj);
    00046   D  glob_dof(int j);
    00047   int size();
    00048   vector<pair<int, int> > glob2loc(int j);
    00049   void clear();
    00050 };
    00051
    00052
    00053
    00054
    00055 template <class D, class C>
    00056 int
    00057 DofT<D, C> :: size() {
    00058   return counter+1;
    00059 }
    00060
    00061 template <class D, class C>
    00062 int
    00063 DofT<D, C>:: insert_dof(int e, int i, D Li){
    00064   // first we update loc2dof, which always should be updated
    00065   pair<int,int> index;
    00066   index.first = e;
    00067   index.second = i;
    00068   int return_dof;
    00069
    00070   // check if the dof is new, if so
    00071   // update counter, dof2index and create
    00072   // a new vector in dof2loc
    00073   iter = dof2index.find(Li);
    00074   if ( iter == dof2index.end() ) { //dof is new
    00075     counter++;
    00076     return_dof = counter;
    00077     dof2index[Li]  = counter;
    00078     loc2dof[index] = counter;
    00079     if ( create_index2dof) {
    00080       index2dof[counter] = Li;
    00081     }
    00082     if ( create_dof2loc ) {
    00083       vector<pair<int,int> > v;
    00084       dof2loc[counter] = v;
    00085     }
    00086   } else {                       // dof is not new
    00087     loc2dof[index] = (*iter).second;
    00088     return_dof = (*iter).second;
    00089   }
    00090
    00091   // insert (e,i) in dof2loc[Li]
    00092   if (create_dof2loc) {
    00093     dof2loc[counter].push_back(index);
    00094   }
    00095
    00096   return return_dof;
    00097 }
    00098
    00099 template <class D, class C>
    00100 int
    00101 DofT<D, C>:: glob_dof(int e, int i) {
    00102   pair<int,int> index;
    00103   index.first = e;
    00104   index.second = i;
    00105   if ( loc2dof.find(index) != loc2dof.end())  {
    00106     return (*(loc2dof.find(index))).second;
    00107   } else {
    00108     return -1;
    00109   }
    00110 }
    00111
    00112 template <class D, class C>
    00113 int
    00114 DofT<D, C>:: glob_dof(D Lj) {
    00115   if ( dof2index.find(Lj) != dof2index.end())  {
    00116     return (*(dof2index.find(Lj))).second;
    00117   } else {
    00118     return -1;
    00119   }
    00120 }
    00121
    00122 template <class D, class C>
    00123 D
    00124 DofT<D, C>:: glob_dof(int j) {
    00125   if ( create_index2dof) {
    00126     if ( index2dof.find(j) != index2dof.end() ) {
    00127     return (*(index2dof.find(j))).second;
    00128   } else {
    00129     std::cout <<"not found "<<std::endl;
    00130     return D();
    00131   }
    00132   } else {
    00133     std::cout <<"This structure has not been created "<<std::endl;
    00134     std::cout <<"You must turn on the create_index2dof flag before initialization!"<<std::endl;
    00135     return D();
    00136   }
    00137 }
    00138
    00139 template <class D, class C>
    00140 vector<pair<int, int> >
    00141 DofT<D, C>:: glob2loc(int j){
    00142   if ( create_dof2loc) {
    00143     return dof2loc[j];
    00144   } else {
    00145     std::cout <<"This structure has not been created "<<std::endl;
    00146     std::cout <<"You must turn on the create_dof2loc lag before initialization!"<<std::endl;
    00147     return vector<pair<int,int> >();
    00148   }
    00149
    00150 }
    00151
    00152 template <class D, class C>
    00153 void
    00154 DofT<D,C>:: clear() {
    00155   counter = -1;
    00156   loc2dof.clear();
    00157   dof2index.clear();
    00158   index2dof.clear();
    00159   dof2loc.clear();
    00160 }
    00161
    00162
    00163 //vector<pair<int, int> > glob2loc(D global_dof);
    00164
    00165
    00166
    00167
    00168
    00169
    00170
    00171 #endif
    00172