SyFi 0.3
|
00001 // Copyright (C) 2006-2009 Kent-Andre Mardal and Simula Research Laboratory. 00002 // Licensed under the GNU GPL Version 2, or (at your option) any later version. 00003 00004 #ifndef DOF_IS_INCLUDED 00005 #define DOF_IS_INCLUDED 00006 00007 #include "FE.h" 00008 00009 #include <map> 00010 #include <vector> 00011 #include <iterator> 00012 #include <iostream> 00013 #include <stdexcept> 00014 00015 namespace SyFi 00016 { 00017 00018 typedef std::pair<unsigned int, unsigned int> pair_ii; 00019 typedef std::vector< std::pair<unsigned int, unsigned int> > vector_ii; 00020 00021 class Dof 00022 { 00023 protected: 00024 // running counter for inserted global indices 00025 unsigned int counter; 00026 00027 // highest element number inserted 00028 unsigned int emax; 00029 00030 // highest local index inserted 00031 unsigned int imax; 00032 00033 // the structures loc2dof, dof2index, and doc2loc are completely dynamic 00034 // they are all initialized and updated by insert_dof(int e, int i, ex Li) 00035 00036 // (int e, int i) -> int j 00037 std::map<std::pair<unsigned int,unsigned int>, unsigned int> loc2glob; 00038 00039 // (ex j) -> vector< pair<e1, i1>, .. pair<en, in> > 00040 bool create_glob2loc; 00041 std::map< unsigned int, vector_ii > glob2loc_map; 00042 00043 // (ex Lj) -> int j 00044 std::map<GiNaC::ex , unsigned int, GiNaC::ex_is_less > dof2glob; 00045 00046 // (int j) -> ex Lj 00047 bool create_glob2dof; 00048 std::map< unsigned int, GiNaC::ex > glob2dof; 00049 00050 public: 00051 Dof(bool create_glob2dof = false, bool create_glob2loc = false): 00052 counter(0), 00053 emax(0), 00054 imax(0), 00055 create_glob2loc(create_glob2loc), 00056 create_glob2dof(create_glob2dof) 00057 { 00058 } 00059 00060 ~Dof() {} 00061 00062 void clear(); 00063 00064 // Update the internal structures with a new dof. 00065 unsigned int insert_dof(unsigned int e, unsigned int i, GiNaC::ex Li); 00066 00067 // --- Helper functions to be used after all the dofs have been inserted. 00068 // These do not modify the internal structure. --- 00069 00070 // Return the number of global dofs inserted. 00071 unsigned int size() const 00072 { return counter; } 00073 00074 // Return the number of elements inserted. 00075 unsigned int num_elements() const 00076 { return emax+1; } 00077 00078 // Return the number of dofs per elements. 00079 unsigned int max_dofs_per_element() const 00080 { return imax+1; } 00081 00082 // Return the global index for local dof i in element e. 00083 unsigned int glob_dof(unsigned int e, unsigned int i); 00084 00085 // Return the global index for dof Lj represented with GiNaC::ex. 00086 unsigned int glob_dof(GiNaC::ex Lj); 00087 00088 // Return the dof GiNaC::ex for global index j. 00089 GiNaC::ex glob_dof(unsigned int j); 00090 00091 // Return a vector of all the (element,index) pairs this global index is equivalent with. 00092 vector_ii glob2loc(unsigned int j); 00093 00094 }; 00095 00096 } 00097 #endif