Reference documentation for deal.II version 9.1.0-pre
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.md at
12 // the top level directory of deal.II.
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 
22 #include <deal.II/base/mg_level_object.h>
23 #include <deal.II/base/smartpointer.h>
24 #include <deal.II/base/tensor.h>
25 
26 DEAL_II_NAMESPACE_OPEN
27 
28 template <int, int>
29 class FEValuesBase;
30 
31 namespace MeshWorker
32 {
47  class VectorSelector : public Subscriptor
48  {
49  public:
58  void
59  add(const std::string &name,
60  const bool values = true,
61  const bool gradients = false,
62  const bool hessians = false);
63 
68  // void add(const std::string& name,
69  // const unsigned int selected_block,
70  // bool values = true,
71  // bool gradients = false,
72  // bool hessians = false);
73 
83  void
84  initialize(const AnyData &);
85 
89  bool
90  empty() const;
91 
95  bool
96  has_values() const;
97 
101  bool
102  has_gradients() const;
103 
107  bool
108  has_hessians() const;
109 
113  unsigned int
114  n_values() const;
115 
119  unsigned int
120  n_gradients() const;
121 
125  unsigned int
126  n_hessians() const;
127 
131  unsigned int
132  value_index(const unsigned int i) const;
133 
137  unsigned int
138  gradient_index(const unsigned int i) const;
139 
143  unsigned int
144  hessian_index(const unsigned int i) const;
145 
149  template <class StreamType, typename DATA>
150  void
151  print(StreamType &s, const AnyData &v) const;
152 
156  template <class StreamType>
157  void
158  print(StreamType &s) const;
159 
163  std::size_t
164  memory_consumption() const;
165 
166  protected:
171 
176 
181  };
182 
190  template <int dim, int spacedim = dim, typename Number = double>
192  {
193  public:
197  VectorDataBase() = default;
198 
203 
211  void
212  initialize(const AnyData &);
213 
217  virtual ~VectorDataBase() override = default;
218 
257  virtual void
258  fill(std::vector<std::vector<std::vector<Number>>> &values,
259  std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
260  &gradients,
261  std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
262  & hessians,
263  const FEValuesBase<dim, spacedim> & fe,
264  const std::vector<types::global_dof_index> &index,
265  const unsigned int component,
266  const unsigned int n_comp,
267  const unsigned int start,
268  const unsigned int size) const;
269 
276  virtual void
277  mg_fill(std::vector<std::vector<std::vector<Number>>> &values,
278  std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
279  &gradients,
280  std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
281  & hessians,
282  const FEValuesBase<dim, spacedim> & fe,
283  const unsigned int level,
284  const std::vector<types::global_dof_index> &index,
285  const unsigned int component,
286  const unsigned int n_comp,
287  const unsigned int start,
288  const unsigned int size) const;
289 
290  protected:
291  AnyData data;
292  };
293 
294 
303  template <typename VectorType, int dim, int spacedim = dim>
305  : public VectorDataBase<dim, spacedim, typename VectorType::value_type>
306  {
307  public:
311  VectorData() = default;
312 
316  VectorData(const VectorSelector &);
317 
321  void
322  initialize(const AnyData &);
323 
331  void
332  initialize(const VectorType *, const std::string &name);
333 
334  virtual void
335  fill(std::vector<std::vector<std::vector<typename VectorType::value_type>>>
336  &values,
337  std::vector<std::vector<
339  &gradients,
340  std::vector<std::vector<
342  & hessians,
343  const FEValuesBase<dim, spacedim> & fe,
344  const std::vector<types::global_dof_index> &index,
345  const unsigned int component,
346  const unsigned int n_comp,
347  const unsigned int start,
348  const unsigned int size) const override;
349 
350  virtual void
351  mg_fill(
352  std::vector<std::vector<std::vector<typename VectorType::value_type>>>
353  &values,
354  std::vector<std::vector<
356  &gradients,
357  std::vector<std::vector<
359  & hessians,
360  const FEValuesBase<dim, spacedim> & fe,
361  const unsigned int level,
362  const std::vector<types::global_dof_index> &index,
363  const unsigned int component,
364  const unsigned int n_comp,
365  const unsigned int start,
366  const unsigned int size) const override;
367 
371  std::size_t
372  memory_consumption() const;
373  };
374 
375 
384  template <typename VectorType, int dim, int spacedim = dim>
385  class MGVectorData : public VectorData<VectorType, dim, spacedim>
386  {
387  public:
391  MGVectorData() = default;
392 
396  MGVectorData(const VectorSelector &);
397 
401  void
402  initialize(const AnyData &);
403 
411  void
412  initialize(const MGLevelObject<VectorType> *, const std::string &name);
413  };
414 
415 
416  //----------------------------------------------------------------------//
417 
418  inline void
419  VectorSelector::add(const std::string &name,
420  const bool values,
421  const bool gradients,
422  const bool hessians)
423  {
424  if (values)
425  value_selection.add(name);
426  if (gradients)
427  gradient_selection.add(name);
428  if (hessians)
429  hessian_selection.add(name);
430  }
431 
432 
433  // inline void
434  // VectorSelector::add(const std::string& name,
435  // const unsigned int block,
436  // bool values, bool gradients, bool hessians)
437  //{
438  // if (values) value_selection.add(name, block);
439  // if (gradients) gradient_selection.add(name, block);
440  // if (hessians) hessian_selection.add(name, block);
441  //}
442 
443 
444  inline void
446  {
450  }
451 
452  inline bool
454  {
455  return (value_selection.size() == 0 && gradient_selection.size() == 0 &&
456  hessian_selection.size() == 0);
457  }
458 
459 
460  inline bool
462  {
463  return value_selection.size() != 0;
464  }
465 
466 
467  inline bool
469  {
470  return gradient_selection.size() != 0;
471  }
472 
473 
474  inline bool
476  {
477  return hessian_selection.size() != 0;
478  }
479 
480 
481  inline unsigned int
483  {
484  return value_selection.size();
485  }
486 
487 
488  inline unsigned int
490  {
491  return gradient_selection.size();
492  }
493 
494 
495  inline unsigned int
497  {
498  return hessian_selection.size();
499  }
500 
501 
502  inline unsigned int
503  VectorSelector::value_index(const unsigned int i) const
504  {
505  return value_selection(i);
506  }
507 
508 
509  inline unsigned int
510  VectorSelector::gradient_index(const unsigned int i) const
511  {
512  return gradient_selection(i);
513  }
514 
515 
516  inline unsigned int
517  VectorSelector::hessian_index(const unsigned int i) const
518  {
519  return hessian_selection(i);
520  }
521 
522 
523  template <class StreamType>
524  inline void
525  VectorSelector::print(StreamType &s) const
526  {
527  s << "values: " << n_values() << " gradients: " << n_gradients()
528  << " hessians: " << n_hessians() << std::endl;
529  }
530 
531 
532  template <class StreamType, typename DATA>
533  inline void
534  VectorSelector::print(StreamType &s, const AnyData &v) const
535  {
536  s << "values: ";
537  for (unsigned int i = 0; i < n_values(); ++i)
538  s << " '" << v.name(value_selection(i)) << '\'';
539  s << std::endl << "gradients:";
540  for (unsigned int i = 0; i < n_gradients(); ++i)
541  s << " '" << v.name(gradient_selection(i)) << '\'';
542  s << std::endl << "hessians: ";
543  for (unsigned int i = 0; i < n_hessians(); ++i)
544  s << " '" << v.name(hessian_selection(i)) << '\'';
545  s << std::endl;
546  }
547 
548 
549  inline std::size_t
551  {
552  return sizeof(*this);
553  }
554 } // namespace MeshWorker
555 
556 
557 DEAL_II_NAMESPACE_CLOSE
558 
559 #endif
NamedSelection gradient_selection
void add(const std::string &name)
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
unsigned int size() const
const std::string & name(const unsigned int i) const
Name of object at index.
Definition: any_data.h:311
void print(StreamType &s, const AnyData &v) const
unsigned int n_hessians() const
void initialize(const AnyData &data)
unsigned int value_index(const unsigned int i) const
std::size_t memory_consumption() const
NamedSelection hessian_selection
Definition: mpi.h:55
unsigned int n_gradients() const
void initialize(const AnyData &)