Dof.cpp
Go to the documentation of this file.00001
00002
00003
00004 #include "Dof.h"
00005
00006 using namespace std;
00007
00008 namespace SyFi
00009 {
00010
00011 void Dof::clear()
00012 {
00013 counter = 0;
00014 emax = 0;
00015 imax = 0;
00016
00017 loc2glob.clear();
00018 dof2glob.clear();
00019 glob2dof.clear();
00020 glob2loc_map.clear();
00021 }
00022
00023 unsigned int Dof:: insert_dof(unsigned int e, unsigned int i, GiNaC::ex Li)
00024 {
00025 if (e > emax) emax = e;
00026 if (i > imax) imax = i;
00027
00028 unsigned int return_dof;
00029
00030
00031
00032
00033
00034 std::map< GiNaC::ex, unsigned int, GiNaC::ex_is_less >::iterator index_iter = dof2glob.find(Li);
00035
00036 if( index_iter == dof2glob.end() )
00037 {
00038
00039 return_dof = counter;
00040
00041
00042 counter++;
00043
00044
00045 dof2glob[Li] = return_dof;
00046
00047 if ( create_glob2dof )
00048 {
00049 std::pair<unsigned int, GiNaC::ex> p(return_dof, Li);
00050 glob2dof.insert(p);
00051 }
00052
00053 if ( create_glob2loc )
00054 {
00055
00056 glob2loc_map[return_dof] = vector_ii();
00057 glob2loc_map[return_dof].reserve(imax);
00058 }
00059 }
00060 else
00061 {
00062 return_dof = index_iter->second;
00063 }
00064
00065
00066 pair_ii index(e, i);
00067 loc2glob[index] = return_dof;
00068
00069
00070 if ( create_glob2loc )
00071 {
00072 glob2loc_map[return_dof].push_back(index);
00073 }
00074
00075 return return_dof;
00076 }
00077
00078 unsigned int Dof::glob_dof(unsigned int e, unsigned int i)
00079 {
00080 pair_ii index(e, i);
00081 std::map<pair_ii, unsigned int >::iterator res = loc2glob.find(index);
00082
00083 if ( res == loc2glob.end() )
00084 {
00085
00086 return -1;
00087 }
00088
00089 return res->second;
00090 }
00091
00092 unsigned int Dof::glob_dof(GiNaC::ex Lj)
00093 {
00094 std::map<GiNaC::ex, unsigned int, GiNaC::ex_is_less>::iterator res = dof2glob.find(Lj);
00095
00096 if ( res == dof2glob.end() )
00097 {
00098
00099 return -1;
00100 }
00101
00102 return res->second;
00103 }
00104
00105 GiNaC::ex Dof::glob_dof(unsigned int j)
00106 {
00107 if ( !create_glob2dof )
00108 {
00109 throw std::runtime_error("This structure has not been created, you must turn on the create_glob2dof flag before initialization!");
00110 }
00111
00112 std::map<unsigned int, GiNaC::ex>::iterator iter = glob2dof.find(j);
00113
00114 if ( iter == glob2dof.end() )
00115 {
00116
00117 std::cerr << "In glob_dof(j): Not found" << std::endl;
00118 return GiNaC::ex();
00119 }
00120
00121 return iter->second;
00122 }
00123
00124 vector_ii Dof::glob2loc(unsigned int j)
00125 {
00126 if ( !create_glob2loc )
00127 {
00128 throw std::runtime_error("This structure has not been created, you must turn on the create_glob2loc flag before initialization!");
00129 }
00130
00131 return glob2loc_map[j];
00132 }
00133
00134 }