Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

formula/vectorElementFormula.hh
Go to the documentation of this file.
00001 
00004 #ifndef vectorelementformula_hh
00005 #define vectorelementformula_hh
00006 
00007 #include <vector>
00008 #include "toolbox/sharedPointer.hh"
00009 #include "elementFormula.hh"
00010 #include "elementFormulaContainer.hh"
00011 
00012 namespace concepts {
00013 
00014 
00015   // *********************************************** VectorElementFormulaBase **
00016 
00021   template<typename F, int dim, typename G = typename Realtype<F>::type>
00022   class VectorElementFormulaBase : public ElementFormula< Point<F, dim>, G >
00023   {
00024   public:
00025     VectorElementFormulaBase<F,dim,G>() : formulas_() 
00026     {
00027       for(int i=0; i < dim; ++i)
00028         formulas_.push_back(ElementFormulaContainer<F,G>());
00029     }
00030 
00035     VectorElementFormulaBase<F,dim,G>
00036     (const std::vector<ElementFormulaContainer<F,G> >& formulas) 
00037      : formulas_(formulas)
00038     { 
00039       conceptsAssert(formulas_.size() == dim, concepts::Assertion());
00040     }
00041 
00047     Point<F, dim> operator() (const ElementWithCell<G>& elm, const Real p,
00048                               const Real t = 0.0) const
00049     {
00050       Point<F, dim> ret;
00051       for (int i=0; i < dim; ++i) 
00052         ret[i] = !formulas_[i].empty() ? formulas_[i](elm, p, t) : F(0);
00053       return ret;
00054     }
00055 
00056     Point<F, dim> operator() (const ElementWithCell<G>& elm, const Real2d& p,
00057                               const Real t = 0.0) const
00058     {
00059       Point<F, dim> ret;
00060       for (int i=0; i < dim; ++i)
00061         ret[i] = !formulas_[i].empty() ? formulas_[i](elm, p, t) : F(0);
00062 
00063       return ret;
00064     }
00065 
00066     Point<F, dim> operator() (const ElementWithCell<G>& elm, const Real3d& p,
00067                               const Real t = 0.0) const
00068     {
00069       Point<F, dim> ret;
00070       for (int i=0; i < dim; ++i)
00071         ret[i] = !formulas_[i].empty() ? formulas_[i](elm, p, t) : F(0);
00072 
00073       return ret;
00074     }
00075 
00077     virtual VectorElementFormulaBase<F,dim,G>* clone() const
00078     {
00079       return new VectorElementFormulaBase<F, dim, G>(*this);
00080     }
00081 
00082 #if 0
00083     VectorElementFormulaBase<F,dim,G>( const VectorElementFormulaBase<F,dim,G>& other) 
00084       : formulas_(other.formulas_)
00085     { }
00086 #endif
00087 
00088     virtual ~VectorElementFormulaBase() { }
00089 
00090     const std::vector<ElementFormulaContainer<F, G> >& getFormulas() 
00091     {
00092       return formulas_;
00093     }
00094 
00095     ElementFormulaContainer<F, G>& operator[](int i)
00096     {
00097       conceptsAssert(i < dim, concepts::Assertion());
00098 
00099       return formulas_[i];
00100     }
00101 
00102   protected:
00103     std::vector<ElementFormulaContainer<F, G> > formulas_;
00104 
00105     virtual std::ostream& info(std::ostream& os) const {
00106       os << "VectorElementFormula([";
00107       for (int i=0; i < dim; ++i) {
00108         if (!formulas_[i].empty())
00109           os << formulas_[i].frm();
00110         else
00111           os << "0";
00112         if (i < dim - 1)
00113           os << ", ";
00114       }
00115       return os << "])";
00116     }
00117   };
00118 
00119   // ************************************************ VectorElementFormula *****
00120 
00121   template<typename F, int dim, typename G = typename Realtype<F>::type>
00122   class VectorElementFormula : public VectorElementFormulaBase<F,dim,G> {};
00123 
00124 
00125   // ************************************************ VectorElementFormula<2> **
00126 
00127   template<typename F, typename G>  
00128   class VectorElementFormula<F,2,G> : public VectorElementFormulaBase<F,2,G>
00129   {
00130   public:
00131     VectorElementFormula<F,2,G>() : VectorElementFormulaBase<F,2,G>() {}
00132 
00133     VectorElementFormula<F,2,G>
00134     (const std::vector<ElementFormulaContainer<F,G> >& formulas) 
00135       : VectorElementFormulaBase<F,2,G>(formulas) {}
00136 
00137     VectorElementFormula<F,2,G>(const ElementFormulaContainer<F,G> frm1,
00138                                 const ElementFormulaContainer<F,G> frm2) 
00139       : VectorElementFormulaBase<F,2,G>() {
00140       (*this)[0] = frm1;
00141       (*this)[1] = frm2;
00142     }
00143   };
00144 
00145 
00146   // ************************************************ VectorElementFormula<3> **
00147 
00148   template<typename F, typename G>  
00149   class VectorElementFormula<F,3,G> : public VectorElementFormulaBase<F,3,G>
00150   {
00151   public:
00152     VectorElementFormula<F,3,G>() : VectorElementFormulaBase<F,2,G>() {}
00153 
00154     VectorElementFormula<F,3,G>
00155     (const std::vector<ElementFormulaContainer<F,G> >& formulas) 
00156       : VectorElementFormulaBase<F,3,G>(formulas) {}
00157 
00158     VectorElementFormula<F,3,G>(const ElementFormulaContainer<F,G> frm1,
00159                                 const ElementFormulaContainer<F,G> frm2, 
00160                                 const ElementFormulaContainer<F,G> frm3) 
00161       : VectorElementFormulaBase<F,3,G>() {
00162       (*this)[0] = frm1;
00163       (*this)[1] = frm2;
00164       (*this)[2] = frm3;
00165     }
00166   };
00167 
00168 
00169 } // namespace concepts
00170 
00171 
00172 #endif // vectorelementformula_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)