MixedFE.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 "MixedFE.h"
00005 
00006 using namespace std;
00007 
00008 namespace SyFi
00009 {
00010 
00011         MixedFE::MixedFE() : FE()
00012         {
00013                 description = "MixedFE";
00014         }
00015 
00016         MixedFE::MixedFE(StandardFE* fe1, StandardFE* fe2) : FE()
00017         {
00018                 mfe.push_back(fe1);
00019                 mfe.push_back(fe2);
00020                 description = "MixedFE_" + fe1->str() + "_" +  fe2->str();
00021         }
00022 
00023         MixedFE::~MixedFE()
00024         {
00025                 mfe.clear();
00026         }
00027 
00028         StandardFE* MixedFE::get(unsigned int i)
00029         {
00030                 if ( i < 0 || i > mfe.size())
00031                 {
00032                         throw(std::out_of_range("The index is out of range!"));
00033                 }
00034                 return mfe[i];
00035         }
00036 
00037         void MixedFE::append(StandardFE* fe)
00038         {
00039                 mfe.push_back(fe);
00040                 description = description + "_" + fe->str();
00041         }
00042 
00043         GiNaC::ex MixedFE::N(unsigned int i)
00044         {
00045 
00046                 if ( i < 0 || i > nbf()-1)
00047                 {
00048                         throw(std::out_of_range("The index is out of range!"));
00049                 }
00050 
00051                 bool found = false;
00052                 unsigned int e = 0;
00053                 unsigned int tmp_nbf = (*mfe[0]).nbf() ;
00054                 unsigned int tmp_i = i;
00055 
00056                 while ( e < mfe.size() && !found)
00057                 {
00058                         tmp_nbf = (*mfe[0]).nbf() ;
00059                         if ( tmp_i < tmp_nbf )
00060                         {
00061                                 found = true;
00062                         }
00063                         else
00064                         {
00065                                 tmp_i -= (*mfe[e]).nbf();
00066                                 e++;
00067                         }
00068                 }
00069                 return (*mfe[e]).N(tmp_i);
00070         }
00071 
00072         GiNaC::ex MixedFE::dof(unsigned int i)
00073         {
00074 
00075                 if ( i < 0 || i > nbf()-1)
00076                 {
00077                         throw(std::out_of_range("The index is out of range!"));
00078                 }
00079 
00080                 bool found = false;
00081                 unsigned int e = 0;
00082                 unsigned int tmp_nbf = (*mfe[0]).nbf() ;
00083                 unsigned int tmp_i = i;
00084 
00085                 while ( e < mfe.size() && !found)
00086                 {
00087                         if ( tmp_i < tmp_nbf)
00088                         {
00089                                 found = true;
00090                         }
00091                         else
00092                         {
00093                                 tmp_i -= (*mfe[e]).nbf();
00094                                 e++;
00095                         }
00096                 }
00097                 return (*mfe[e]).dof(tmp_i);
00098         }
00099 
00100         unsigned int MixedFE::nbf() const
00101         {
00102                 int sum = 0;
00103                 for (unsigned int i=0; i< mfe.size(); i++)
00104                 {
00105                         sum += (*mfe[i]).nbf();
00106                 }
00107                 return sum;
00108         }
00109 
00110         std::string MixedFE:: str()
00111         {
00112                 return description;
00113         }
00114 
00115 }

Generated on Mon Aug 31 16:16:45 2009 for SyFi by  doxygen 1.5.9