Reference documentation for deal.II version 9.0.0
vector_selector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2009 - 2017 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() = default;
184 
189 
197  void initialize(const AnyData &);
198 
202  virtual ~VectorDataBase() = default;
203 
242  virtual void fill(
243  std::vector<std::vector<std::vector<Number> > > &values,
244  std::vector<std::vector<std::vector<Tensor<1,spacedim,Number> > > > &gradients,
245  std::vector<std::vector<std::vector<Tensor<2,spacedim,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,spacedim,Number> > > > &gradients,
262  std::vector<std::vector<std::vector<Tensor<2,spacedim,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 
271  protected:
272  AnyData data;
273  };
274 
275 
284  template <typename VectorType, int dim, int spacedim = dim>
285  class VectorData :
286  public VectorDataBase<dim, spacedim,typename VectorType::value_type>
287  {
288  public:
292  VectorData() = default;
293 
297  VectorData(const VectorSelector &);
298 
302  void initialize(const AnyData &);
303 
311  void initialize(const VectorType *, const std::string &name);
312 
313  virtual void fill(
314  std::vector<std::vector<std::vector<typename VectorType::value_type> > > &values,
315  std::vector<std::vector<std::vector<Tensor<1,spacedim,typename VectorType::value_type> > > > &gradients,
316  std::vector<std::vector<std::vector<Tensor<2,spacedim,typename VectorType::value_type> > > > &hessians,
317  const FEValuesBase<dim,spacedim> &fe,
318  const std::vector<types::global_dof_index> &index,
319  const unsigned int component,
320  const unsigned int n_comp,
321  const unsigned int start,
322  const unsigned int size) const;
323 
324  virtual void mg_fill(
325  std::vector<std::vector<std::vector<typename VectorType::value_type> > > &values,
326  std::vector<std::vector<std::vector<Tensor<1,spacedim,typename VectorType::value_type> > > > &gradients,
327  std::vector<std::vector<std::vector<Tensor<2,spacedim,typename VectorType::value_type> > > > &hessians,
328  const FEValuesBase<dim,spacedim> &fe,
329  const unsigned int level,
330  const std::vector<types::global_dof_index> &index,
331  const unsigned int component,
332  const unsigned int n_comp,
333  const unsigned int start,
334  const unsigned int size) const;
335 
339  std::size_t memory_consumption () const;
340  };
341 
342 
351  template <typename VectorType, int dim, int spacedim = dim>
352  class MGVectorData :
353  public VectorData<VectorType, dim, spacedim>
354  {
355  public:
359  MGVectorData() = default;
360 
364  MGVectorData(const VectorSelector &);
365 
369  void initialize(const AnyData &);
370 
378  void initialize(const MGLevelObject<VectorType> *, const std::string &name);
379  };
380 
381 
382 //----------------------------------------------------------------------//
383 
384  inline void
385  VectorSelector::add(const std::string &name,
386  const bool values,
387  const bool gradients,
388  const bool hessians)
389  {
390  if (values)
391  value_selection.add(name);
392  if (gradients)
393  gradient_selection.add(name);
394  if (hessians)
395  hessian_selection.add(name);
396  }
397 
398 
399  //inline void
400  //VectorSelector::add(const std::string& name,
401  // const unsigned int block,
402  // bool values, bool gradients, bool hessians)
403  //{
404  // if (values) value_selection.add(name, block);
405  // if (gradients) gradient_selection.add(name, block);
406  // if (hessians) hessian_selection.add(name, block);
407  //}
408 
409 
410  inline void
412  {
416  }
417 
418  inline bool
420  {
421  return (value_selection.size() == 0 &&
422  gradient_selection.size() == 0 &&
423  hessian_selection.size() == 0);
424  }
425 
426 
427  inline bool
429  {
430  return value_selection.size() != 0;
431  }
432 
433 
434  inline bool
436  {
437  return gradient_selection.size() != 0;
438  }
439 
440 
441  inline bool
443  {
444  return hessian_selection.size() != 0;
445  }
446 
447 
448  inline unsigned int
450  {
451  return value_selection.size();
452  }
453 
454 
455  inline unsigned int
457  {
458  return gradient_selection.size();
459  }
460 
461 
462  inline unsigned int
464  {
465  return hessian_selection.size();
466  }
467 
468 
469  inline unsigned int
470  VectorSelector::value_index(const unsigned int i) const
471  {
472  return value_selection(i);
473  }
474 
475 
476  inline unsigned int
477  VectorSelector::gradient_index(const unsigned int i) const
478  {
479  return gradient_selection(i);
480  }
481 
482 
483  inline unsigned int
484  VectorSelector::hessian_index(const unsigned int i) const
485  {
486  return hessian_selection(i);
487  }
488 
489 
490  template <class StreamType>
491  inline void
492  VectorSelector::print(StreamType &s) const
493  {
494  s << "values: " << n_values()
495  << " gradients: " << n_gradients()
496  << " hessians: " << n_hessians()
497  << std::endl;
498  }
499 
500 
501  template <class StreamType, typename DATA>
502  inline void
503  VectorSelector::print(StreamType &s, const AnyData &v) const
504  {
505  s << "values: ";
506  for (unsigned int i=0; i<n_values(); ++i)
507  s << " '" << v.name(value_selection(i)) << '\'';
508  s << std::endl << "gradients:";
509  for (unsigned int i=0; i<n_gradients(); ++i)
510  s << " '" << v.name(gradient_selection(i)) << '\'';
511  s << std::endl << "hessians: ";
512  for (unsigned int i=0; i<n_hessians(); ++i)
513  s << " '" << v.name(hessian_selection(i)) << '\'';
514  s << std::endl;
515  }
516 
517 
518  inline
519  std::size_t
521  {
522  return sizeof(*this);
523  }
524 }
525 
526 
527 DEAL_II_NAMESPACE_CLOSE
528 
529 #endif
void initialize(const AnyData &)
std::size_t memory_consumption() const
NamedSelection gradient_selection
virtual void mg_fill(std::vector< std::vector< std::vector< typename VectorType::value_type > > > &values, std::vector< std::vector< std::vector< Tensor< 1, spacedim, typename VectorType::value_type > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, spacedim, 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)
virtual void mg_fill(std::vector< std::vector< std::vector< Number > > > &values, std::vector< std::vector< std::vector< Tensor< 1, spacedim, Number > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, spacedim, 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 add(const std::string &name, const bool values=true, const bool gradients=false, const bool hessians=false)
unsigned int n_values() const
virtual void fill(std::vector< std::vector< std::vector< typename VectorType::value_type > > > &values, std::vector< std::vector< std::vector< Tensor< 1, spacedim, typename VectorType::value_type > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, spacedim, 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
void initialize(const AnyData &data)
std::size_t memory_consumption() const
virtual ~VectorDataBase()=default
unsigned int hessian_index(const unsigned int i) const
void initialize(const AnyData &)
unsigned int gradient_index(const unsigned int i) const
NamedSelection hessian_selection
Definition: mpi.h:53
unsigned int n_gradients() const
unsigned int size() const
unsigned int value_index(const unsigned int i) const
virtual void fill(std::vector< std::vector< std::vector< Number > > > &values, std::vector< std::vector< std::vector< Tensor< 1, spacedim, Number > > > > &gradients, std::vector< std::vector< std::vector< Tensor< 2, spacedim, 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
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:294