SyFi  0.3
Dof.h
Go to the documentation of this file.
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 #ifndef DOF_IS_INCLUDED
00019 #define DOF_IS_INCLUDED
00020 
00021 #include "FE.h"
00022 
00023 #include <map>
00024 #include <vector>
00025 #include <iterator>
00026 #include <iostream>
00027 #include <stdexcept>
00028 
00029 namespace SyFi
00030 {
00031 
00032         typedef std::pair<unsigned int, unsigned int> pair_ii;
00033         typedef std::vector< std::pair<unsigned int, unsigned int> > vector_ii;
00034 
00035         class Dof
00036         {
00037                 protected:
00038                         // running counter for inserted global indices
00039                         unsigned int counter;
00040 
00041                         // highest element number inserted
00042                         unsigned int emax;
00043 
00044                         // highest local index inserted
00045                         unsigned int imax;
00046 
00047                         // the structures loc2dof, dof2index, and doc2loc  are completely dynamic
00048                         // they are all initialized and updated by insert_dof(int e, int i, ex Li)
00049 
00050                         // (int e, int i) -> int j
00051                         std::map<std::pair<unsigned int,unsigned int>, unsigned int>          loc2glob;
00052 
00053                         // (ex j)                -> vector< pair<e1, i1>, ..  pair<en, in> >
00054                         bool create_glob2loc;
00055                         std::map< unsigned int, vector_ii >  glob2loc_map;
00056 
00057                         // (ex Lj)               ->  int j
00058                         std::map<GiNaC::ex , unsigned int, GiNaC::ex_is_less >       dof2glob;
00059 
00060                         // (int j)               -> ex Lj
00061                         bool create_glob2dof;
00062                         std::map< unsigned int, GiNaC::ex >          glob2dof;
00063 
00064                 public:
00065                         Dof(bool create_glob2dof = false, bool create_glob2loc = false):
00066                         counter(0),
00067                                 emax(0),
00068                                 imax(0),
00069                                 create_glob2loc(create_glob2loc),
00070                                 create_glob2dof(create_glob2dof)
00071                         {
00072                         }
00073 
00074                         ~Dof() {}
00075 
00076                         void clear();
00077 
00078                         // Update the internal structures with a new dof.
00079                         unsigned int insert_dof(unsigned int e, unsigned int i, GiNaC::ex Li);
00080 
00081                         // --- Helper functions to be used after all the dofs have been inserted.
00082                         // These do not modify the internal structure. ---
00083 
00084                         // Return the number of global dofs inserted.
00085                         unsigned int size() const
00086                                 { return counter; }
00087 
00088                         // Return the number of elements inserted.
00089                         unsigned int num_elements() const
00090                                 { return emax+1; }
00091 
00092                         // Return the number of dofs per elements.
00093                         unsigned int max_dofs_per_element() const
00094                                 { return imax+1; }
00095 
00096                         // Return the global index for local dof i in element e.
00097                         unsigned int glob_dof(unsigned int e, unsigned int i);
00098 
00099                         // Return the global index for dof Lj represented with GiNaC::ex.
00100                         unsigned int glob_dof(GiNaC::ex Lj);
00101 
00102                         // Return the dof GiNaC::ex for global index j.
00103                         GiNaC::ex glob_dof(unsigned int j);
00104 
00105                         // Return a vector of all the (element,index) pairs this global index is equivalent with.
00106                         vector_ii glob2loc(unsigned int j);
00107 
00108         };
00109 
00110 }
00111 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator