Reference documentation for deal.II version 8.5.1
vector_selector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2009 - 2016 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__mesh_worker_vector_selector_h
17 #define dealii__mesh_worker_vector_selector_h
18 
19 #include <deal.II/algorithms/any_data.h>
20 #include <deal.II/algorithms/named_selection.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 
25 DEAL_II_NAMESPACE_OPEN
26 
27 template<int,int> class FEValuesBase;
28 
29 namespace MeshWorker
30 {
31 
47  public Subscriptor
48  {
49  public:
58  void add(const std::string &name,
59  const bool values = true,
60  const bool gradients = false,
61  const bool hessians = false);
62 
67 // void add(const std::string& name,
68 // const unsigned int selected_block,
69 // bool values = true,
70 // bool gradients = false,
71 // bool hessians = false);
72 
82  void initialize(const AnyData &);
83 
87  bool empty () const;
88 
92  bool has_values () const;
93 
97  bool has_gradients () const;
98 
102  bool has_hessians () const;
103 
107  unsigned int n_values () const;
108 
112  unsigned int n_gradients () const;
113 
117  unsigned int n_hessians () const;
118 
122  unsigned int value_index (const unsigned int i) const;
123 
127  unsigned int gradient_index (const unsigned int i) const;
128 
132  unsigned int hessian_index (const unsigned int i) const;
133 
137  template <class StreamType, typename DATA>
138  void print (StreamType &s, const AnyData &v) const;
139 
143  template <class StreamType>
144  void print (StreamType &s) const;
145 
149  std::size_t memory_consumption () const;
150 
151  protected:
156 
161 
166  };
167 
175  template <int dim, int spacedim = dim, typename Number=double>
177  public VectorSelector
178  {
179  public:
183  VectorDataBase();
184 
189 
197  void initialize(const AnyData &);
198 
202  virtual ~VectorDataBase();
203 
242  virtual void fill(
243  std::vector<std::vector<std::vector<Number> > > &values,
244  std::vector<std::vector<std::vector<Tensor<1,dim,Number> > > > &gradients,
245  std::vector<std::vector<std::vector<Tensor<2,dim,Number> > > > &hessians,
246  const FEValuesBase<dim,spacedim> &fe,
247  const std::vector<types::global_dof_index> &index,
248  const unsigned int component,
249  const unsigned int n_comp,
250  const unsigned int start,
251  const unsigned int size) const;
252 
259  virtual void mg_fill(
260  std::vector<std::vector<std::vector<Number> > > &values,
261  std::vector<std::vector<std::vector<Tensor<1,dim,Number> > > > &gradients,
262  std::vector<std::vector<std::vector<Tensor<2,dim,Number> > > > &hessians,
263  const FEValuesBase<dim,spacedim> &fe,
264  const unsigned int level,
265  const std::vector<types::global_dof_index> &index,
266  const unsigned int component,
267  const unsigned int n_comp,
268  const unsigned int start,
269  const unsigned int size) const;
270 
274  std::size_t memory_consumption () const;
275  protected:
276  AnyData data;
277  };
278 
279 
288  template <typename VectorType, int dim, int spacedim = dim>
289  class VectorData :
290  public VectorDataBase<dim, spacedim,typename VectorType::value_type>
291  {
292  public:
296  VectorData();
300  VectorData(const VectorSelector &);
301 
305  void initialize(const AnyData &);
306 
314  void initialize(const VectorType *, const std::string &name);
315 
316  virtual void fill(
317  std::vector<std::vector<std::vector<typename VectorType::value_type> > > &values,
318  std::vector<std::vector<std::vector<Tensor<1,dim,typename VectorType::value_type> > > > &gradients,
319  std::vector<std::vector<std::vector<Tensor<2,dim,typename VectorType::value_type> > > > &hessians,
320  const FEValuesBase<dim,spacedim> &fe,
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 
327  virtual void mg_fill(
328  std::vector<std::vector<std::vector<typename VectorType::value_type> > > &values,
329  std::vector<std::vector<std::vector<Tensor<1,dim,typename VectorType::value_type> > > > &gradients,
330  std::vector<std::vector<std::vector<Tensor<2,dim,typename VectorType::value_type> > > > &hessians,
331  const FEValuesBase<dim,spacedim> &fe,
332  const unsigned int level,
333  const std::vector<types::global_dof_index> &index,
334  const unsigned int component,
335  const unsigned int n_comp,
336  const unsigned int start,
337  const unsigned int size) const;
338 
342  std::size_t memory_consumption () const;
343  };
344 
345 
354  template <typename VectorType, int dim, int spacedim = dim>
355  class MGVectorData :
356  public VectorData<VectorType, dim, spacedim>
357  {
358  public:
362  MGVectorData();
363 
367  MGVectorData(const VectorSelector &);
368 
372  void initialize(const AnyData &);
373 
381  void initialize(const MGLevelObject<VectorType> *, const std::string &name);
382 
383 
387  std::size_t memory_consumption () const;
388  };
389 
390 
391 //----------------------------------------------------------------------//
392 
393  inline void
394  VectorSelector::add(const std::string &name,
395  const bool values,
396  const bool gradients,
397  const bool hessians)
398  {
399  if (values)
400  value_selection.add(name);
401  if (gradients)
402  gradient_selection.add(name);
403  if (hessians)
404  hessian_selection.add(name);
405  }
406 
407 
408  //inline void
409  //VectorSelector::add(const std::string& name,
410  // const unsigned int block,
411  // bool values, bool gradients, bool hessians)
412  //{
413  // if (values) value_selection.add(name, block);
414  // if (gradients) gradient_selection.add(name, block);
415  // if (hessians) hessian_selection.add(name, block);
416  //}
417 
418 
419  inline void
421  {
425  }
426 
427  inline bool
429  {
430  return (value_selection.size() == 0 &&
431  gradient_selection.size() == 0 &&
432  hessian_selection.size() == 0);
433  }
434 
435 
436  inline bool
438  {
439  return value_selection.size() != 0;
440  }
441 
442 
443  inline bool
445  {
446  return gradient_selection.size() != 0;
447  }
448 
449 
450  inline bool
452  {
453  return hessian_selection.size() != 0;
454  }
455 
456 
457  inline unsigned int
459  {
460  return value_selection.size();
461  }
462 
463 
464  inline unsigned int
466  {
467  return gradient_selection.size();
468  }
469 
470 
471  inline unsigned int
473  {
474  return hessian_selection.size();
475  }
476 
477 
478  inline unsigned int
479  VectorSelector::value_index(const unsigned int i) const
480  {
481  return value_selection(i);
482  }
483 
484 
485  inline unsigned int
486  VectorSelector::gradient_index(const unsigned int i) const
487  {
488  return gradient_selection(i);
489  }
490 
491 
492  inline unsigned int
493  VectorSelector::hessian_index(const unsigned int i) const
494  {
495  return hessian_selection(i);
496  }
497 
498 
499  template <class StreamType>
500  inline void
501  VectorSelector::print(StreamType &s) const
502  {
503  s << "values: " << n_values()
504  << " gradients: " << n_gradients()
505  << " hessians: " << n_hessians()
506  << std::endl;
507  }
508 
509 
510  template <class StreamType, typename DATA>
511  inline void
512  VectorSelector::print(StreamType &s, const AnyData &v) const
513  {
514  s << "values: ";
515  for (unsigned int i=0; i<n_values(); ++i)
516  s << " '" << v.name(value_selection(i)) << '\'';
517  s << std::endl << "gradients:";
518  for (unsigned int i=0; i<n_gradients(); ++i)
519  s << " '" << v.name(gradient_selection(i)) << '\'';
520  s << std::endl << "hessians: ";
521  for (unsigned int i=0; i<n_hessians(); ++i)
522  s << " '" << v.name(hessian_selection(i)) << '\'';
523  s << std::endl;
524  }
525 
526 
527  inline
528  std::size_t
530  {
531  return sizeof(*this);
532  }
533 }
534 
535 
536 DEAL_II_NAMESPACE_CLOSE
537 
538 #endif
void initialize(const AnyData &)
std::size_t memory_consumption() const
NamedSelection gradient_selection
void add(const std::string &name)
virtual void mg_fill(std::vector< std::vector< std::vector< typename VectorType::value_type > > > &values, std::vector< std::vector< std::vector< Tensor< 1, dim, typename VectorType::value_type > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, dim, typename VectorType::value_type > > > > &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
void add(const std::string &name, const bool values=true, const bool gradients=false, const bool hessians=false)
virtual void fill(std::vector< std::vector< std::vector< Number > > > &values, std::vector< std::vector< std::vector< Tensor< 1, dim, Number > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, dim, Number > > > > &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
unsigned int n_values() const
void initialize(const AnyData &data)
std::size_t memory_consumption() const
unsigned int hessian_index(const unsigned int i) const
std::size_t memory_consumption() const
void initialize(const AnyData &)
unsigned int gradient_index(const unsigned int i) const
NamedSelection hessian_selection
std::size_t memory_consumption() const
unsigned int n_gradients() const
virtual void fill(std::vector< std::vector< std::vector< typename VectorType::value_type > > > &values, std::vector< std::vector< std::vector< Tensor< 1, dim, typename VectorType::value_type > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, dim, typename VectorType::value_type > > > > &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
unsigned int size() const
unsigned int value_index(const unsigned int i) const
virtual void mg_fill(std::vector< std::vector< std::vector< Number > > > &values, std::vector< std::vector< std::vector< Tensor< 1, dim, Number > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, dim, Number > > > > &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
void initialize(const AnyData &)
unsigned int n_hessians() const
void initialize(const AnyData &)
void print(StreamType &s, const AnyData &v) const
const std::string & name(const unsigned int i) const
Name of object at index.
Definition: any_data.h:299