Reference documentation for deal.II version Git 92c1895bf8 2020-06-04 17:48:28 -0400
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
vector_selector.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2009 - 2019 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/base/config.h>
20 
23 
26 #include <deal.II/base/tensor.h>
27 
29 
30 // Forward declaration
31 #ifndef DOXYGEN
32 template <int, int>
33 class FEValuesBase;
34 #endif
35 
36 namespace MeshWorker
37 {
52  class VectorSelector : public Subscriptor
53  {
54  public:
63  void
64  add(const std::string &name,
65  const bool values = true,
66  const bool gradients = false,
67  const bool hessians = false);
68 
73  // void add(const std::string& name,
74  // const unsigned int selected_block,
75  // bool values = true,
76  // bool gradients = false,
77  // bool hessians = false);
78 
88  void
89  initialize(const AnyData &);
90 
94  bool
95  empty() const;
96 
100  bool
101  has_values() const;
102 
106  bool
107  has_gradients() const;
108 
112  bool
113  has_hessians() const;
114 
118  unsigned int
119  n_values() const;
120 
124  unsigned int
125  n_gradients() const;
126 
130  unsigned int
131  n_hessians() const;
132 
136  unsigned int
137  value_index(const unsigned int i) const;
138 
142  unsigned int
143  gradient_index(const unsigned int i) const;
144 
148  unsigned int
149  hessian_index(const unsigned int i) const;
150 
154  template <class StreamType, typename DATA>
155  void
156  print(StreamType &s, const AnyData &v) const;
157 
161  template <class StreamType>
162  void
163  print(StreamType &s) const;
164 
168  std::size_t
169  memory_consumption() const;
170 
171  protected:
176 
181 
186  };
187 
195  template <int dim, int spacedim = dim, typename Number = double>
197  {
198  public:
202  VectorDataBase() = default;
203 
208 
216  void
217  initialize(const AnyData &);
218 
222  virtual ~VectorDataBase() override = default;
223 
262  virtual void
263  fill(std::vector<std::vector<std::vector<Number>>> &values,
264  std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
265  &gradients,
266  std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
267  & hessians,
268  const FEValuesBase<dim, spacedim> & fe,
269  const std::vector<types::global_dof_index> &index,
270  const unsigned int component,
271  const unsigned int n_comp,
272  const unsigned int start,
273  const unsigned int size) const;
274 
281  virtual void
282  mg_fill(std::vector<std::vector<std::vector<Number>>> &values,
283  std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
284  &gradients,
285  std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
286  & hessians,
287  const FEValuesBase<dim, spacedim> & fe,
288  const unsigned int level,
289  const std::vector<types::global_dof_index> &index,
290  const unsigned int component,
291  const unsigned int n_comp,
292  const unsigned int start,
293  const unsigned int size) const;
294 
295  protected:
297  };
298 
299 
308  template <typename VectorType, int dim, int spacedim = dim>
310  : public VectorDataBase<dim, spacedim, typename VectorType::value_type>
311  {
312  public:
316  VectorData() = default;
317 
321  VectorData(const VectorSelector &);
322 
326  void
327  initialize(const AnyData &);
328 
336  void
337  initialize(const VectorType *, const std::string &name);
338 
339  virtual void
340  fill(std::vector<std::vector<std::vector<typename VectorType::value_type>>>
341  &values,
342  std::vector<std::vector<
344  &gradients,
345  std::vector<std::vector<
347  & hessians,
348  const FEValuesBase<dim, spacedim> & fe,
349  const std::vector<types::global_dof_index> &index,
350  const unsigned int component,
351  const unsigned int n_comp,
352  const unsigned int start,
353  const unsigned int size) const override;
354 
355  virtual void
356  mg_fill(
357  std::vector<std::vector<std::vector<typename VectorType::value_type>>>
358  &values,
359  std::vector<std::vector<
361  &gradients,
362  std::vector<std::vector<
364  & hessians,
365  const FEValuesBase<dim, spacedim> & fe,
366  const unsigned int level,
367  const std::vector<types::global_dof_index> &index,
368  const unsigned int component,
369  const unsigned int n_comp,
370  const unsigned int start,
371  const unsigned int size) const override;
372 
376  std::size_t
377  memory_consumption() const;
378  };
379 
380 
389  template <typename VectorType, int dim, int spacedim = dim>
390  class MGVectorData : public VectorData<VectorType, dim, spacedim>
391  {
392  public:
396  MGVectorData() = default;
397 
401  MGVectorData(const VectorSelector &);
402 
406  void
407  initialize(const AnyData &);
408 
416  void
417  initialize(const MGLevelObject<VectorType> *, const std::string &name);
418  };
419 
420 
421  //----------------------------------------------------------------------//
422 
423  inline void
424  VectorSelector::add(const std::string &name,
425  const bool values,
426  const bool gradients,
427  const bool hessians)
428  {
429  if (values)
430  value_selection.add(name);
431  if (gradients)
432  gradient_selection.add(name);
433  if (hessians)
434  hessian_selection.add(name);
435  }
436 
437 
438  // inline void
439  // VectorSelector::add(const std::string& name,
440  // const unsigned int block,
441  // bool values, bool gradients, bool hessians)
442  //{
443  // if (values) value_selection.add(name, block);
444  // if (gradients) gradient_selection.add(name, block);
445  // if (hessians) hessian_selection.add(name, block);
446  //}
447 
448 
449  inline void
451  {
455  }
456 
457  inline bool
459  {
460  return (value_selection.size() == 0 && gradient_selection.size() == 0 &&
461  hessian_selection.size() == 0);
462  }
463 
464 
465  inline bool
467  {
468  return value_selection.size() != 0;
469  }
470 
471 
472  inline bool
474  {
475  return gradient_selection.size() != 0;
476  }
477 
478 
479  inline bool
481  {
482  return hessian_selection.size() != 0;
483  }
484 
485 
486  inline unsigned int
488  {
489  return value_selection.size();
490  }
491 
492 
493  inline unsigned int
495  {
496  return gradient_selection.size();
497  }
498 
499 
500  inline unsigned int
502  {
503  return hessian_selection.size();
504  }
505 
506 
507  inline unsigned int
508  VectorSelector::value_index(const unsigned int i) const
509  {
510  return value_selection(i);
511  }
512 
513 
514  inline unsigned int
515  VectorSelector::gradient_index(const unsigned int i) const
516  {
517  return gradient_selection(i);
518  }
519 
520 
521  inline unsigned int
522  VectorSelector::hessian_index(const unsigned int i) const
523  {
524  return hessian_selection(i);
525  }
526 
527 
528  template <class StreamType>
529  inline void
530  VectorSelector::print(StreamType &s) const
531  {
532  s << "values: " << n_values() << " gradients: " << n_gradients()
533  << " hessians: " << n_hessians() << std::endl;
534  }
535 
536 
537  template <class StreamType, typename DATA>
538  inline void
539  VectorSelector::print(StreamType &s, const AnyData &v) const
540  {
541  s << "values: ";
542  for (unsigned int i = 0; i < n_values(); ++i)
543  s << " '" << v.name(value_selection(i)) << '\'';
544  s << std::endl << "gradients:";
545  for (unsigned int i = 0; i < n_gradients(); ++i)
546  s << " '" << v.name(gradient_selection(i)) << '\'';
547  s << std::endl << "hessians: ";
548  for (unsigned int i = 0; i < n_hessians(); ++i)
549  s << " '" << v.name(hessian_selection(i)) << '\'';
550  s << std::endl;
551  }
552 
553 
554  inline std::size_t
556  {
557  return sizeof(*this);
558  }
559 } // namespace MeshWorker
560 
561 
563 
564 #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)
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:361
unsigned int level
Definition: grid_out.cc:4355
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:450
unsigned int n_gradients() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:360
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