include/deal.II/meshworker/vector_selector.h

00001 //---------------------------------------------------------------------------
00002 //    @f$Id: vector_selector.h 25345 2012-03-31 08:37:04Z bangerth @f$
00003 //
00004 //    Copyright (C) 2009, 2010, 2011, 2012 by the deal.II authors
00005 //
00006 //    This file is subject to QPL and may not be  distributed
00007 //    without copyright and license information. Please refer
00008 //    to the file deal.II/doc/license.html for the  text  and
00009 //    further information on this license.
00010 //
00011 //---------------------------------------------------------------------------
00012 #ifndef __deal2__mesh_worker_vector_selector_h
00013 #define __deal2__mesh_worker_vector_selector_h
00014 
00015 #include <deal.II/base/named_data.h>
00016 #include <deal.II/base/tensor.h>
00017 #include <deal.II/base/smartpointer.h>
00018 #include <deal.II/base/mg_level_object.h>
00019 
00020 DEAL_II_NAMESPACE_OPEN
00021 
00022 template<int,int> class FEValuesBase;
00023 
00024 namespace MeshWorker
00025 {
00026 
00042   class VectorSelector :
00043       public Subscriptor
00044   {
00045     public:
00065       void add(const std::string& name,
00066                bool values = true,
00067                bool gradients = false,
00068                bool hessians = false);
00069 
00076 //      void add(const std::string& name,
00077 //               const unsigned int selected_block,
00078 //             bool values = true,
00079 //             bool gradients = false,
00080 //             bool hessians = false);
00081 
00099       template <class DATA>
00100       void initialize(const NamedData<DATA>&);
00101 
00105       bool empty () const;
00106 
00111       bool has_values () const;
00112 
00117       bool has_gradients () const;
00118 
00123       bool has_hessians () const;
00124 
00128       unsigned int n_values () const;
00129 
00133       unsigned int n_gradients () const;
00134 
00138       unsigned int n_hessians () const;
00139 
00143       unsigned int value_index (unsigned int i) const;
00144 
00148       unsigned int gradient_index (unsigned int i) const;
00149 
00153       unsigned int hessian_index (unsigned int i) const;
00154 
00159       template <class STREAM, typename DATA>
00160       void print (STREAM& s, const NamedData<DATA>& v) const;
00161 
00165       template <class STREAM>
00166       void print (STREAM& s) const;
00167 
00171       std::size_t memory_consumption () const;
00172 
00173     protected:
00178       NamedSelection value_selection;
00179 
00184       NamedSelection gradient_selection;
00185 
00190       NamedSelection hessian_selection;
00191   };
00192 
00200   template <int dim, int spacedim = dim>
00201   class VectorDataBase :
00202       public VectorSelector
00203   {
00204     public:
00208       VectorDataBase();
00209 
00214       VectorDataBase(const VectorSelector&);
00215 
00220       virtual ~VectorDataBase();
00288       virtual void fill(
00289         std::vector<std::vector<std::vector<double> > >& values,
00290         std::vector<std::vector<std::vector<Tensor<1,dim> > > >& gradients,
00291         std::vector<std::vector<std::vector<Tensor<2,dim> > > >& hessians,
00292         const FEValuesBase<dim,spacedim>& fe,
00293         const std::vector<unsigned int>& index,
00294         unsigned int component,
00295         unsigned int n_comp,
00296         unsigned int start,
00297         unsigned int size) const;
00298 
00310        virtual void mg_fill(
00311         std::vector<std::vector<std::vector<double> > >& values,
00312         std::vector<std::vector<std::vector<Tensor<1,dim> > > >& gradients,
00313         std::vector<std::vector<std::vector<Tensor<2,dim> > > >& hessians,
00314         const FEValuesBase<dim,spacedim>& fe,
00315         unsigned int level,
00316         const std::vector<unsigned int>& index,
00317         unsigned int component,
00318         unsigned int n_comp,
00319         unsigned int start,
00320         unsigned int size) const;
00321 
00325       std::size_t memory_consumption () const;
00326   };
00327 
00328 
00337   template <class VECTOR, int dim, int spacedim = dim>
00338   class VectorData :
00339       public VectorDataBase<dim, spacedim>
00340   {
00341     public:
00345       VectorData();
00350       VectorData(const VectorSelector&);
00351 
00364       void initialize(const NamedData<VECTOR*>&);
00365 
00378       void initialize(const VECTOR*, const std::string& name);
00379 
00380       virtual void fill(
00381         std::vector<std::vector<std::vector<double> > >& values,
00382         std::vector<std::vector<std::vector<Tensor<1,dim> > > >& gradients,
00383         std::vector<std::vector<std::vector<Tensor<2,dim> > > >& hessians,
00384         const FEValuesBase<dim,spacedim>& fe,
00385         const std::vector<unsigned int>& index,
00386         unsigned int component,
00387         unsigned int n_comp,
00388         unsigned int start,
00389         unsigned int size) const;
00390 
00394       std::size_t memory_consumption () const;
00395 
00396     private:
00397       NamedData<SmartPointer<const VECTOR,VectorData<VECTOR,dim,spacedim> > > data;
00398   };
00399 
00400 
00409   template <class VECTOR, int dim, int spacedim = dim>
00410   class MGVectorData :
00411       public VectorDataBase<dim, spacedim>
00412   {
00413     public:
00417       MGVectorData();
00422       MGVectorData(const VectorSelector&);
00423 
00436       void initialize(const NamedData<MGLevelObject<VECTOR>*>&);
00437 
00450       void initialize(const MGLevelObject<VECTOR>*, const std::string& name);
00451 
00452       virtual void mg_fill(
00453         std::vector<std::vector<std::vector<double> > >& values,
00454         std::vector<std::vector<std::vector<Tensor<1,dim> > > >& gradients,
00455         std::vector<std::vector<std::vector<Tensor<2,dim> > > >& hessians,
00456         const FEValuesBase<dim,spacedim>& fe,
00457         unsigned int level,
00458         const std::vector<unsigned int>& index,
00459         unsigned int component,
00460         unsigned int n_comp,
00461         unsigned int start,
00462         unsigned int size) const;
00463 
00467       std::size_t memory_consumption () const;
00468 
00469     private:
00470       NamedData<SmartPointer<const MGLevelObject<VECTOR>,MGVectorData<VECTOR,dim,spacedim> > > data;
00471   };
00472 
00473 
00474 //----------------------------------------------------------------------//
00475 
00476   inline void
00477   VectorSelector::add(const std::string& name, bool values, bool gradients, bool hessians)
00478   {
00479     if (values) value_selection.add(name);
00480     if (gradients) gradient_selection.add(name);
00481     if (hessians) hessian_selection.add(name);
00482   }
00483 
00484 
00485   //inline void
00486   //VectorSelector::add(const std::string& name,
00487   //   const unsigned int block,
00488   //   bool values, bool gradients, bool hessians)
00489   //{
00490   //  if (values) value_selection.add(name, block);
00491   //  if (gradients) gradient_selection.add(name, block);
00492   //  if (hessians) hessian_selection.add(name, block);
00493   //}
00494 
00495 
00496   template <typename DATA>
00497   inline void
00498   VectorSelector::initialize(const NamedData<DATA>& src)
00499   {
00500     value_selection.initialize(src);
00501     gradient_selection.initialize(src);
00502     hessian_selection.initialize(src);
00503   }
00504 
00505   inline bool
00506   VectorSelector::empty() const
00507   {
00508     return (value_selection.size() == 0 &&
00509             gradient_selection.size() == 0 &&
00510             hessian_selection.size() == 0);
00511   }
00512 
00513 
00514   inline bool
00515   VectorSelector::has_values() const
00516   {
00517     return value_selection.size() != 0;
00518   }
00519 
00520 
00521   inline bool
00522   VectorSelector::has_gradients() const
00523   {
00524     return gradient_selection.size() != 0;
00525   }
00526 
00527 
00528   inline bool
00529   VectorSelector::has_hessians() const
00530   {
00531     return hessian_selection.size() != 0;
00532   }
00533 
00534 
00535   inline unsigned int
00536   VectorSelector::n_values() const
00537   {
00538     return value_selection.size();
00539   }
00540 
00541 
00542   inline unsigned int
00543   VectorSelector::n_gradients() const
00544   {
00545     return gradient_selection.size();
00546   }
00547 
00548 
00549   inline unsigned int
00550   VectorSelector::n_hessians() const
00551   {
00552     return hessian_selection.size();
00553   }
00554 
00555 
00556   inline unsigned int
00557   VectorSelector::value_index(unsigned int i) const
00558   {
00559     return value_selection(i);
00560   }
00561 
00562 
00563   inline unsigned int
00564   VectorSelector::gradient_index(unsigned int i) const
00565   {
00566     return gradient_selection(i);
00567   }
00568 
00569 
00570   inline unsigned int
00571   VectorSelector::hessian_index(unsigned int i) const
00572   {
00573     return hessian_selection(i);
00574   }
00575 
00576 
00577   template <class STREAM>
00578   inline void
00579   VectorSelector::print(STREAM& s) const
00580   {
00581     s << "values: " << n_values()
00582       << " gradients: " << n_gradients()
00583       << " hessians: " << n_hessians()
00584       << std::endl;
00585   }
00586 
00587 
00588   template <class STREAM, typename DATA>
00589   inline void
00590   VectorSelector::print(STREAM& s, const NamedData<DATA>& v) const
00591   {
00592     s << "values:   ";
00593     for (unsigned int i=0;i<n_values();++i)
00594       s << " '" << v.name(value_selection(i)) << '\'';
00595     s << std::endl << "gradients:";
00596     for (unsigned int i=0;i<n_gradients();++i)
00597       s << " '" << v.name(gradient_selection(i)) << '\'';
00598     s << std::endl << "hessians: ";
00599     for (unsigned int i=0;i<n_hessians();++i)
00600       s << " '" << v.name(hessian_selection(i)) << '\'';
00601     s << std::endl;
00602   }
00603 
00604 
00605   inline
00606   std::size_t
00607   VectorSelector::memory_consumption () const
00608   {
00609     return sizeof(*this);
00610   }
00611 }
00612 
00613 
00614 DEAL_II_NAMESPACE_CLOSE
00615 
00616 #endif
00617 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Wed May 23 2012 12:03:32 by doxygen 1.7.3