SyFi 0.3
Dof.cpp
Go to the documentation of this file.
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 #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                 // check if the dof is new, if so
00031                 // update counter, dof2glob and create
00032                 // a new vector in glob2loc_map
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                         // define a new dof
00039                         return_dof = counter;
00040 
00041                         // count inserted global indices
00042                         counter++;
00043 
00044                         // the central "D -> global index" map
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                                 // initialize with empty vector
00056                                 glob2loc_map[return_dof] = vector_ii();
00057                                 glob2loc_map[return_dof].reserve(imax);
00058                         }
00059                 }
00060                 else                                     // dof is not new
00061                 {
00062                         return_dof = index_iter->second;
00063                 }
00064 
00065                 // loc2glob should always be updated
00066                 pair_ii index(e, i);
00067                 loc2glob[index] = return_dof;
00068 
00069                 // insert (e,i) in glob2loc_map[Li]
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                         //throw std::runtime_error("In glob_dof(e,i): Not found");
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                         //throw std::runtime_error("In glob_dof(Lj): Not found");
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                         //throw std::runtime_error("In glob_dof(j): Not found");
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 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines