SyFi
0.3
|
00001 // Copyright (C) 2006-2009 Kent-Andre Mardal and Simula Research Laboratory 00002 // 00003 // This file is part of SyFi. 00004 // 00005 // SyFi is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 2 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // SyFi is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with SyFi. If not, see <http://www.gnu.org/licenses/>. 00017 00018 #include "Dof.h" 00019 00020 using namespace std; 00021 00022 namespace SyFi 00023 { 00024 00025 void Dof::clear() 00026 { 00027 counter = 0; 00028 emax = 0; 00029 imax = 0; 00030 00031 loc2glob.clear(); 00032 dof2glob.clear(); 00033 glob2dof.clear(); 00034 glob2loc_map.clear(); 00035 } 00036 00037 unsigned int Dof:: insert_dof(unsigned int e, unsigned int i, GiNaC::ex Li) 00038 { 00039 if (e > emax) emax = e; 00040 if (i > imax) imax = i; 00041 00042 unsigned int return_dof; 00043 00044 // check if the dof is new, if so 00045 // update counter, dof2glob and create 00046 // a new vector in glob2loc_map 00047 00048 std::map< GiNaC::ex, unsigned int, GiNaC::ex_is_less >::iterator index_iter = dof2glob.find(Li); 00049 00050 if( index_iter == dof2glob.end() ) 00051 { 00052 // define a new dof 00053 return_dof = counter; 00054 00055 // count inserted global indices 00056 counter++; 00057 00058 // the central "D -> global index" map 00059 dof2glob[Li] = return_dof; 00060 00061 if ( create_glob2dof ) 00062 { 00063 std::pair<unsigned int, GiNaC::ex> p(return_dof, Li); 00064 glob2dof.insert(p); 00065 } 00066 00067 if ( create_glob2loc ) 00068 { 00069 // initialize with empty vector 00070 glob2loc_map[return_dof] = vector_ii(); 00071 glob2loc_map[return_dof].reserve(imax); 00072 } 00073 } 00074 else // dof is not new 00075 { 00076 return_dof = index_iter->second; 00077 } 00078 00079 // loc2glob should always be updated 00080 pair_ii index(e, i); 00081 loc2glob[index] = return_dof; 00082 00083 // insert (e,i) in glob2loc_map[Li] 00084 if ( create_glob2loc ) 00085 { 00086 glob2loc_map[return_dof].push_back(index); 00087 } 00088 00089 return return_dof; 00090 } 00091 00092 unsigned int Dof::glob_dof(unsigned int e, unsigned int i) 00093 { 00094 pair_ii index(e, i); 00095 std::map<pair_ii, unsigned int >::iterator res = loc2glob.find(index); 00096 00097 if ( res == loc2glob.end() ) 00098 { 00099 //throw std::runtime_error("In glob_dof(e,i): Not found"); 00100 return -1; 00101 } 00102 00103 return res->second; 00104 } 00105 00106 unsigned int Dof::glob_dof(GiNaC::ex Lj) 00107 { 00108 std::map<GiNaC::ex, unsigned int, GiNaC::ex_is_less>::iterator res = dof2glob.find(Lj); 00109 00110 if ( res == dof2glob.end() ) 00111 { 00112 //throw std::runtime_error("In glob_dof(Lj): Not found"); 00113 return -1; 00114 } 00115 00116 return res->second; 00117 } 00118 00119 GiNaC::ex Dof::glob_dof(unsigned int j) 00120 { 00121 if ( !create_glob2dof ) 00122 { 00123 throw std::runtime_error("This structure has not been created, you must turn on the create_glob2dof flag before initialization!"); 00124 } 00125 00126 std::map<unsigned int, GiNaC::ex>::iterator iter = glob2dof.find(j); 00127 00128 if ( iter == glob2dof.end() ) 00129 { 00130 //throw std::runtime_error("In glob_dof(j): Not found"); 00131 std::cerr << "In glob_dof(j): Not found" << std::endl; 00132 return GiNaC::ex(); 00133 } 00134 00135 return iter->second; 00136 } 00137 00138 vector_ii Dof::glob2loc(unsigned int j) 00139 { 00140 if ( !create_glob2loc ) 00141 { 00142 throw std::runtime_error("This structure has not been created, you must turn on the create_glob2loc flag before initialization!"); 00143 } 00144 00145 return glob2loc_map[j]; 00146 } 00147 00148 }