Reference documentation for deal.II version 8.1.0
vector_selector.h
1 // ---------------------------------------------------------------------
2 // @f$Id: vector_selector.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2009 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__mesh_worker_vector_selector_h
18 #define __deal2__mesh_worker_vector_selector_h
19 
20 #include <deal.II/base/named_data.h>
21 #include <deal.II/base/tensor.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/base/mg_level_object.h>
24 
26 
27 template<int,int> class FEValuesBase;
28 
29 namespace MeshWorker
30 {
31 
48  public Subscriptor
49  {
50  public:
70  void add(const std::string &name,
71  const bool values = true,
72  const bool gradients = false,
73  const bool hessians = false);
74 
81 // void add(const std::string& name,
82 // const unsigned int selected_block,
83 // bool values = true,
84 // bool gradients = false,
85 // bool hessians = false);
86 
104  template <class DATA>
105  void initialize(const NamedData<DATA> &);
106 
110  bool empty () const;
111 
116  bool has_values () const;
117 
122  bool has_gradients () const;
123 
128  bool has_hessians () const;
129 
133  unsigned int n_values () const;
134 
138  unsigned int n_gradients () const;
139 
143  unsigned int n_hessians () const;
144 
148  unsigned int value_index (const unsigned int i) const;
149 
153  unsigned int gradient_index (const unsigned int i) const;
154 
158  unsigned int hessian_index (const unsigned int i) const;
159 
164  template <class STREAM, typename DATA>
165  void print (STREAM &s, const NamedData<DATA> &v) const;
166 
170  template <class STREAM>
171  void print (STREAM &s) const;
172 
176  std::size_t memory_consumption () const;
177 
178  protected:
184 
190 
196  };
197 
205  template <int dim, int spacedim = dim>
207  public VectorSelector
208  {
209  public:
213  VectorDataBase();
214 
220 
225  virtual ~VectorDataBase();
293  virtual void fill(
294  std::vector<std::vector<std::vector<double> > > &values,
295  std::vector<std::vector<std::vector<Tensor<1,dim> > > > &gradients,
296  std::vector<std::vector<std::vector<Tensor<2,dim> > > > &hessians,
297  const FEValuesBase<dim,spacedim> &fe,
298  const std::vector<types::global_dof_index> &index,
299  const unsigned int component,
300  const unsigned int n_comp,
301  const unsigned int start,
302  const unsigned int size) const;
303 
315  virtual void mg_fill(
316  std::vector<std::vector<std::vector<double> > > &values,
317  std::vector<std::vector<std::vector<Tensor<1,dim> > > > &gradients,
318  std::vector<std::vector<std::vector<Tensor<2,dim> > > > &hessians,
319  const FEValuesBase<dim,spacedim> &fe,
320  const unsigned int level,
321  const std::vector<types::global_dof_index> &index,
322  const unsigned int component,
323  const unsigned int n_comp,
324  const unsigned int start,
325  const unsigned int size) const;
326 
330  std::size_t memory_consumption () const;
331  };
332 
333 
342  template <class VECTOR, int dim, int spacedim = dim>
343  class VectorData :
344  public VectorDataBase<dim, spacedim>
345  {
346  public:
350  VectorData();
355  VectorData(const VectorSelector &);
356 
369  void initialize(const NamedData<VECTOR *> &);
370 
383  void initialize(const VECTOR *, const std::string &name);
384 
385  virtual void fill(
386  std::vector<std::vector<std::vector<double> > > &values,
387  std::vector<std::vector<std::vector<Tensor<1,dim> > > > &gradients,
388  std::vector<std::vector<std::vector<Tensor<2,dim> > > > &hessians,
389  const FEValuesBase<dim,spacedim> &fe,
390  const std::vector<types::global_dof_index> &index,
391  const unsigned int component,
392  const unsigned int n_comp,
393  const unsigned int start,
394  const unsigned int size) const;
395 
399  std::size_t memory_consumption () const;
400 
401  private:
403  };
404 
405 
414  template <class VECTOR, int dim, int spacedim = dim>
415  class MGVectorData :
416  public VectorDataBase<dim, spacedim>
417  {
418  public:
422  MGVectorData();
427  MGVectorData(const VectorSelector &);
428 
442 
455  void initialize(const MGLevelObject<VECTOR> *, const std::string &name);
456 
457  virtual void mg_fill(
458  std::vector<std::vector<std::vector<double> > > &values,
459  std::vector<std::vector<std::vector<Tensor<1,dim> > > > &gradients,
460  std::vector<std::vector<std::vector<Tensor<2,dim> > > > &hessians,
461  const FEValuesBase<dim,spacedim> &fe,
462  const unsigned int level,
463  const std::vector<types::global_dof_index> &index,
464  const unsigned int component,
465  const unsigned int n_comp,
466  const unsigned int start,
467  const unsigned int size) const;
468 
472  std::size_t memory_consumption () const;
473 
474  private:
476  };
477 
478 
479 //----------------------------------------------------------------------//
480 
481  inline void
482  VectorSelector::add(const std::string &name,
483  const bool values,
484  const bool gradients,
485  const bool hessians)
486  {
487  if (values)
488  value_selection.add(name);
489  if (gradients)
490  gradient_selection.add(name);
491  if (hessians)
492  hessian_selection.add(name);
493  }
494 
495 
496  //inline void
497  //VectorSelector::add(const std::string& name,
498  // const unsigned int block,
499  // bool values, bool gradients, bool hessians)
500  //{
501  // if (values) value_selection.add(name, block);
502  // if (gradients) gradient_selection.add(name, block);
503  // if (hessians) hessian_selection.add(name, block);
504  //}
505 
506 
507  template <typename DATA>
508  inline void
510  {
514  }
515 
516  inline bool
518  {
519  return (value_selection.size() == 0 &&
520  gradient_selection.size() == 0 &&
521  hessian_selection.size() == 0);
522  }
523 
524 
525  inline bool
527  {
528  return value_selection.size() != 0;
529  }
530 
531 
532  inline bool
534  {
535  return gradient_selection.size() != 0;
536  }
537 
538 
539  inline bool
541  {
542  return hessian_selection.size() != 0;
543  }
544 
545 
546  inline unsigned int
548  {
549  return value_selection.size();
550  }
551 
552 
553  inline unsigned int
555  {
556  return gradient_selection.size();
557  }
558 
559 
560  inline unsigned int
562  {
563  return hessian_selection.size();
564  }
565 
566 
567  inline unsigned int
568  VectorSelector::value_index(const unsigned int i) const
569  {
570  return value_selection(i);
571  }
572 
573 
574  inline unsigned int
575  VectorSelector::gradient_index(const unsigned int i) const
576  {
577  return gradient_selection(i);
578  }
579 
580 
581  inline unsigned int
582  VectorSelector::hessian_index(const unsigned int i) const
583  {
584  return hessian_selection(i);
585  }
586 
587 
588  template <class STREAM>
589  inline void
590  VectorSelector::print(STREAM &s) const
591  {
592  s << "values: " << n_values()
593  << " gradients: " << n_gradients()
594  << " hessians: " << n_hessians()
595  << std::endl;
596  }
597 
598 
599  template <class STREAM, typename DATA>
600  inline void
601  VectorSelector::print(STREAM &s, const NamedData<DATA> &v) const
602  {
603  s << "values: ";
604  for (unsigned int i=0; i<n_values(); ++i)
605  s << " '" << v.name(value_selection(i)) << '\'';
606  s << std::endl << "gradients:";
607  for (unsigned int i=0; i<n_gradients(); ++i)
608  s << " '" << v.name(gradient_selection(i)) << '\'';
609  s << std::endl << "hessians: ";
610  for (unsigned int i=0; i<n_hessians(); ++i)
611  s << " '" << v.name(hessian_selection(i)) << '\'';
612  s << std::endl;
613  }
614 
615 
616  inline
617  std::size_t
619  {
620  return sizeof(*this);
621  }
622 }
623 
624 
625 DEAL_II_NAMESPACE_CLOSE
626 
627 #endif
NamedSelection gradient_selection
void initialize(const NamedData< VECTOR * > &)
const std::string & name(unsigned int i) const
Name of object at index.
Definition: named_data.h:374
std::size_t memory_consumption() const
void add(const std::string &name)
Definition: named_data.h:409
void initialize(const NamedData< DATA > &)
unsigned int gradient_index(const unsigned int i) const
void add(const std::string &name, const bool values=true, const bool gradients=false, const bool hessians=false)
unsigned int n_values() const
unsigned int hessian_index(const unsigned int i) const
virtual void fill(std::vector< std::vector< std::vector< double > > > &values, std::vector< std::vector< std::vector< Tensor< 1, dim > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, dim > > > > &hessians, const FEValuesBase< dim, spacedim > &fe, const std::vector< types::global_dof_index > &index, const unsigned int component, const unsigned int n_comp, const unsigned int start, const unsigned int size) const
void initialize(const NamedData< DATA > &data)
Definition: named_data.h:417
void initialize(const NamedData< MGLevelObject< VECTOR > * > &)
unsigned int size() const
Definition: named_data.h:427
unsigned int n_hessians() const
unsigned int value_index(const unsigned int i) const
std::size_t memory_consumption() const
std::size_t memory_consumption() const
std::size_t memory_consumption() const
virtual void mg_fill(std::vector< std::vector< std::vector< double > > > &values, std::vector< std::vector< std::vector< Tensor< 1, dim > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, dim > > > > &hessians, const FEValuesBase< dim, spacedim > &fe, const unsigned int level, const std::vector< types::global_dof_index > &index, const unsigned int component, const unsigned int n_comp, const unsigned int start, const unsigned int size) const
NamedSelection hessian_selection
virtual void fill(std::vector< std::vector< std::vector< double > > > &values, std::vector< std::vector< std::vector< Tensor< 1, dim > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, dim > > > > &hessians, const FEValuesBase< dim, spacedim > &fe, const std::vector< types::global_dof_index > &index, const unsigned int component, const unsigned int n_comp, const unsigned int start, const unsigned int size) const
void print(STREAM &s, const NamedData< DATA > &v) const
unsigned int n_gradients() const
virtual void mg_fill(std::vector< std::vector< std::vector< double > > > &values, std::vector< std::vector< std::vector< Tensor< 1, dim > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, dim > > > > &hessians, const FEValuesBase< dim, spacedim > &fe, const unsigned int level, const std::vector< types::global_dof_index > &index, const unsigned int component, const unsigned int n_comp, const unsigned int start, const unsigned int size) const