Reference documentation for deal.II version Git 7026f387cc 2019-10-15 14:19:01 -0400
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
vector_selector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2009 - 2018 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 // Forward declaration
29 #ifndef DOXYGEN
30 template <int, int>
31 class FEValuesBase;
32 #endif
33 
34 namespace MeshWorker
35 {
50  class VectorSelector : public Subscriptor
51  {
52  public:
61  void
62  add(const std::string &name,
63  const bool values = true,
64  const bool gradients = false,
65  const bool hessians = false);
66 
71  // void add(const std::string& name,
72  // const unsigned int selected_block,
73  // bool values = true,
74  // bool gradients = false,
75  // bool hessians = false);
76 
86  void
87  initialize(const AnyData &);
88 
92  bool
93  empty() const;
94 
98  bool
99  has_values() const;
100 
104  bool
105  has_gradients() const;
106 
110  bool
111  has_hessians() const;
112 
116  unsigned int
117  n_values() const;
118 
122  unsigned int
123  n_gradients() const;
124 
128  unsigned int
129  n_hessians() const;
130 
134  unsigned int
135  value_index(const unsigned int i) const;
136 
140  unsigned int
141  gradient_index(const unsigned int i) const;
142 
146  unsigned int
147  hessian_index(const unsigned int i) const;
148 
152  template <class StreamType, typename DATA>
153  void
154  print(StreamType &s, const AnyData &v) const;
155 
159  template <class StreamType>
160  void
161  print(StreamType &s) const;
162 
166  std::size_t
167  memory_consumption() const;
168 
169  protected:
174 
179 
184  };
185 
193  template <int dim, int spacedim = dim, typename Number = double>
195  {
196  public:
200  VectorDataBase() = default;
201 
206 
214  void
215  initialize(const AnyData &);
216 
220  virtual ~VectorDataBase() override = default;
221 
260  virtual void
261  fill(std::vector<std::vector<std::vector<Number>>> &values,
262  std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
263  &gradients,
264  std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
265  & hessians,
266  const FEValuesBase<dim, spacedim> & fe,
267  const std::vector<types::global_dof_index> &index,
268  const unsigned int component,
269  const unsigned int n_comp,
270  const unsigned int start,
271  const unsigned int size) const;
272 
279  virtual void
280  mg_fill(std::vector<std::vector<std::vector<Number>>> &values,
281  std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
282  &gradients,
283  std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
284  & hessians,
285  const FEValuesBase<dim, spacedim> & fe,
286  const unsigned int level,
287  const std::vector<types::global_dof_index> &index,
288  const unsigned int component,
289  const unsigned int n_comp,
290  const unsigned int start,
291  const unsigned int size) const;
292 
293  protected:
294  AnyData data;
295  };
296 
297 
306  template <typename VectorType, int dim, int spacedim = dim>
308  : public VectorDataBase<dim, spacedim, typename VectorType::value_type>
309  {
310  public:
314  VectorData() = default;
315 
319  VectorData(const VectorSelector &);
320 
324  void
325  initialize(const AnyData &);
326 
334  void
335  initialize(const VectorType *, const std::string &name);
336 
337  virtual void
338  fill(std::vector<std::vector<std::vector<typename VectorType::value_type>>>
339  &values,
340  std::vector<std::vector<
342  &gradients,
343  std::vector<std::vector<
345  & hessians,
346  const FEValuesBase<dim, spacedim> & fe,
347  const std::vector<types::global_dof_index> &index,
348  const unsigned int component,
349  const unsigned int n_comp,
350  const unsigned int start,
351  const unsigned int size) const override;
352 
353  virtual void
354  mg_fill(
355  std::vector<std::vector<std::vector<typename VectorType::value_type>>>
356  &values,
357  std::vector<std::vector<
359  &gradients,
360  std::vector<std::vector<
362  & hessians,
363  const FEValuesBase<dim, spacedim> & fe,
364  const unsigned int level,
365  const std::vector<types::global_dof_index> &index,
366  const unsigned int component,
367  const unsigned int n_comp,
368  const unsigned int start,
369  const unsigned int size) const override;
370 
374  std::size_t
375  memory_consumption() const;
376  };
377 
378 
387  template <typename VectorType, int dim, int spacedim = dim>
388  class MGVectorData : public VectorData<VectorType, dim, spacedim>
389  {
390  public:
394  MGVectorData() = default;
395 
399  MGVectorData(const VectorSelector &);
400 
404  void
405  initialize(const AnyData &);
406 
414  void
415  initialize(const MGLevelObject<VectorType> *, const std::string &name);
416  };
417 
418 
419  //----------------------------------------------------------------------//
420 
421  inline void
422  VectorSelector::add(const std::string &name,
423  const bool values,
424  const bool gradients,
425  const bool hessians)
426  {
427  if (values)
428  value_selection.add(name);
429  if (gradients)
430  gradient_selection.add(name);
431  if (hessians)
432  hessian_selection.add(name);
433  }
434 
435 
436  // inline void
437  // VectorSelector::add(const std::string& name,
438  // const unsigned int block,
439  // bool values, bool gradients, bool hessians)
440  //{
441  // if (values) value_selection.add(name, block);
442  // if (gradients) gradient_selection.add(name, block);
443  // if (hessians) hessian_selection.add(name, block);
444  //}
445 
446 
447  inline void
449  {
453  }
454 
455  inline bool
457  {
458  return (value_selection.size() == 0 && gradient_selection.size() == 0 &&
459  hessian_selection.size() == 0);
460  }
461 
462 
463  inline bool
465  {
466  return value_selection.size() != 0;
467  }
468 
469 
470  inline bool
472  {
473  return gradient_selection.size() != 0;
474  }
475 
476 
477  inline bool
479  {
480  return hessian_selection.size() != 0;
481  }
482 
483 
484  inline unsigned int
486  {
487  return value_selection.size();
488  }
489 
490 
491  inline unsigned int
493  {
494  return gradient_selection.size();
495  }
496 
497 
498  inline unsigned int
500  {
501  return hessian_selection.size();
502  }
503 
504 
505  inline unsigned int
506  VectorSelector::value_index(const unsigned int i) const
507  {
508  return value_selection(i);
509  }
510 
511 
512  inline unsigned int
513  VectorSelector::gradient_index(const unsigned int i) const
514  {
515  return gradient_selection(i);
516  }
517 
518 
519  inline unsigned int
520  VectorSelector::hessian_index(const unsigned int i) const
521  {
522  return hessian_selection(i);
523  }
524 
525 
526  template <class StreamType>
527  inline void
528  VectorSelector::print(StreamType &s) const
529  {
530  s << "values: " << n_values() << " gradients: " << n_gradients()
531  << " hessians: " << n_hessians() << std::endl;
532  }
533 
534 
535  template <class StreamType, typename DATA>
536  inline void
537  VectorSelector::print(StreamType &s, const AnyData &v) const
538  {
539  s << "values: ";
540  for (unsigned int i = 0; i < n_values(); ++i)
541  s << " '" << v.name(value_selection(i)) << '\'';
542  s << std::endl << "gradients:";
543  for (unsigned int i = 0; i < n_gradients(); ++i)
544  s << " '" << v.name(gradient_selection(i)) << '\'';
545  s << std::endl << "hessians: ";
546  for (unsigned int i = 0; i < n_hessians(); ++i)
547  s << " '" << v.name(hessian_selection(i)) << '\'';
548  s << std::endl;
549  }
550 
551 
552  inline std::size_t
554  {
555  return sizeof(*this);
556  }
557 } // namespace MeshWorker
558 
559 
560 DEAL_II_NAMESPACE_CLOSE
561 
562 #endif
NamedSelection gradient_selection
void add(const std::string &name)
void add(const std::string &name, const bool values=true, const bool gradients=false, const bool hessians=false)
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
unsigned int gradient_index(const unsigned int i) const
NamedSelection hessian_selection
Definition: tensor.h:422
unsigned int n_gradients() const
unsigned int size() const
unsigned int value_index(const unsigned int i) const
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:311