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

space/integral.hh
Go to the documentation of this file.
00001 /* Integrals of formulas on elements
00002 
00003     Kersten Schmidt, 2005
00004  */
00005 
00006 #ifndef spcIntegral_hh
00007 #define spcIntegral_hh
00008 
00009 #include <set>
00010 #include "basics/typedefs.hh"
00011 #include "basics/vectorsMatrices.hh"
00012 #include "basics/vectorsMatricesForward.hh"
00013 #include "geometry/integral.hh"
00014 #include "space/element.hh"
00015 #include "space/formula.hh"
00016 #include "space/postProcess.hh"
00017 #include "space/space.hh"
00018 
00019 #define ElemFrmIntegrate_D 0
00020 #define PWintegrate_D      0
00021 #define SpaceIntegrate_D   0
00022 #define ElemFrmL2Product_D 0
00023 #define SpcFrmL2Product_D  0
00024 
00025 namespace concepts {
00026 
00027   // forward declaration
00028   template<typename F, typename G>
00029   class ElementFormula;
00030 
00031 
00032   // ************************************************************* integrate **
00033 
00038   template<typename G>
00039   Real integrate(const Element<G>& elm)
00040   {
00041     const IntegrationCell* cell = dynamic_cast<const IntegrationCell*>(&elm);
00042     if (!cell)
00043       throw conceptsException(MissingFeature("not a integration cell"));
00044 
00045     Real val(0);
00046     uint i = 0;
00047     IntegrationCell::intPoint p;
00048 
00049     while(cell->quadraturePoint(i++, p)) val += p.intermediate;
00050 
00051     return val;
00052   }
00053 
00059   template<typename F, typename G>
00060   F integrate(const ElementWithCell<G>& elm, const ElementFormula<F,G>& frm,
00061               const Real t = 0.0,
00062               IntegrationCell::intFormType form = IntegrationCell::ZERO) {
00063     const IntegrationCell* cell = dynamic_cast<const IntegrationCell*>(&elm);
00064     if (!cell)
00065       throw conceptsException(MissingFeature("not a integration cell"));
00066 
00067     F val(0);
00068     uint i = 0;
00069     IntegrationCell::intPoint p;
00070     DEBUGL(ElemFrmIntegrate_D, "elm = " << elm);
00071     
00072     while(cell->quadraturePoint(i++, p, form, true)) {
00073       DEBUGL(ElemFrmIntegrate_D, "coord = " << p.coord << ", frm(coord) = " <<
00074              frm(elm, p.coord, t) << ", interme = " << p.intermediate);
00075       val += frm(elm, p.coord, t) * p.intermediate;
00076     }
00077     return val;
00078   }
00079 
00089   template<class F, typename G>
00090   F integrate(SpaceOnCells<G>& spc, const ElementFormula<F,G>& frm,
00091               const Real t = 0.0,
00092               IntegrationCell::intFormType form = IntegrationCell::ZERO) {
00093     F val(0);
00094 #if SpaceIntegrate_D
00095     uint i = 0;
00096 #endif
00097     // loop over elements
00098     Scan<ElementWithCell<G> >* sc(spc.scan());
00099     while (*sc) {
00100       const ElementWithCell<G>& elm = (*sc)++;
00101 #if SpaceIntegrate_D
00102       DEBUGL(1, ++i << ".Element: " << elm);
00103       F tmp = integrate(elm, frm, t, form);
00104       val += tmp;
00105       DEBUGL(1, "    Integral: " << tmp);
00106 #else
00107       val += integrate(elm, frm, t, form);
00108 #endif
00109     }
00110     return val;
00111   }
00112 
00113   // ************************************************************* L2product **
00114 
00123   template<typename F, typename G>
00124   Real L2product(const ElementWithCell<G>& elm, const ElementFormula<F,G>& u,
00125                  const ElementFormula<Real>* c = 0, const Real t = 0.0,
00126                  IntegrationCell::intFormType form = IntegrationCell::ZERO) {
00127     const IntegrationCell* cell = dynamic_cast<const IntegrationCell*>(&elm);
00128     if (!cell)
00129       throw conceptsException(MissingFeature("not a integration cell"));
00130 
00131     DEBUGL(ElemFrmL2Product_D, "Element = " << elm);
00132     DEBUGL(ElemFrmL2Product_D, "u       = " << u);
00133     Real val(0);
00134     uint i = 0;
00135     IntegrationCell::intPoint p;
00136 
00137     while(cell->quadraturePoint(i++, p, form, true)) {
00138 #if ElemFrmL2Product_D
00139       if (!c) {
00140         DEBUGL(1, "coord = " << p.coord << ", u(coord) = " <<
00141                u(elm, p.coord, t) << ", interme = " << p.intermediate);
00142       } else {
00143         DEBUGL(1, "coord = " << p.coord << ", u(coord) = " <<
00144                u(elm, p.coord, t) << ", interme = " << p.intermediate <<
00145                ", formula = " << (*c)(elm, p.coord, t) << ", contribution = " <<
00146                u(elm, p.coord, t)*u(elm, p.coord, t)*
00147                p.intermediate*(*c)(elm, p.coord, t));
00148       }
00149 #endif
00150       F f = u(elm, p.coord, t);
00151       Real add = std::norm(f) * p.intermediate;
00152       if (c) add *= (*c)(elm, p.coord, t);
00153       val += add;
00154     }
00155     // one could introduce special handling for piecewise constant
00156     // formulas which might be zero on some elements or formulas whose
00157     // support are just some elements
00158 
00159     DEBUGL(ElemFrmL2Product_D, "val = " << val);
00160     return val;
00161   }
00162 
00176   template<class F, typename G>
00177   Real L2product(SpaceOnCells<F>& spc, const G& u,
00178                  const ElementFormula<Real>* c = 0, const Real t = 0.0,
00179                  IntegrationCell::intFormType form = IntegrationCell::ZERO) {
00180     Real val(0);
00181     DEBUGL(SpcFrmL2Product_D, "spc = " << spc);
00182     DEBUGL(SpcFrmL2Product_D, "u = " << u);
00183     // loop over elements
00184     Scan<ElementWithCell<F> >* sc(spc.scan());
00185     uint j = 0;
00186     while (*sc) {
00187       const ElementWithCell<F>& elm = (*sc)++;
00188       DEBUGL(SpcFrmL2Product_D, ++j << "th element = " << elm.cell());
00189       val += L2product(elm, u, c, t, form);
00190       DEBUGL(SpcFrmL2Product_D, "val = " << val);
00191     }
00192     DEBUGL(SpcFrmL2Product_D, "done.");
00193     return val;
00194   }
00195 
00196   // ********************************************************** CellIntegral **
00197 
00200   template<class F>
00201     class CellIntegral : public CellPostprocess<Real> {
00202       public:
00208         CellIntegral(F& val, const Formula<F>& formula,
00209             const std::set<uint>* attributes = 0);
00210       protected:
00211         virtual std::ostream& info(std::ostream& os) const;
00213         F& val_;
00215         const concepts::Formula<F>& formula_;
00217         const std::set<uint>* attributes_;
00218     };
00219 
00220   // ****************************************************** CellFaceIntegral **
00221 
00224   template<class F>
00225     class CellFaceIntegral : public CellIntegral<F> {
00226       public:
00232         CellFaceIntegral(F& val, const concepts::Formula<F>& formula,
00233             const std::set<uint>* attributes = 0);
00234         virtual void operator() (const Element<Real>& elm);
00235         virtual void operator() (const Cell& cell);
00236 
00237       protected:
00238         virtual std::ostream& info(std::ostream& os) const;
00239       private:
00240         template<class G>
00241           F compute_(const G& elm);
00242     };
00243 
00244   // ****************************************************** CellEdgeIntegral **
00245 
00248   template<class F>
00249     class CellEdgeIntegral : public CellIntegral<F> {
00250       public:
00256         CellEdgeIntegral(F& val, const concepts::Formula<F>& formula,
00257             const std::set<uint>* attributes = 0);
00258         virtual void operator() (const Element<Real>& elm);
00259         virtual void operator() (const Cell& cell);
00260       protected:
00261         virtual std::ostream& info(std::ostream& os) const;
00262       private:
00263         template<class G>
00264           F compute_(const G& elm);
00265     };
00266 
00267 } // namespace concepts
00268 
00269 #endif // spcIntegral_hh

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