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