Reference documentation for deal.II version GIT relicensing-769-g16d39143b0 2024-05-28 17:50:02+00:00
\(\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\}}\)
Loading...
Searching...
No Matches
vector_selector.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2009 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_mesh_worker_vector_selector_h
16#define dealii_mesh_worker_vector_selector_h
17
18#include <deal.II/base/config.h>
19
22
25#include <deal.II/base/tensor.h>
26
28
29// Forward declaration
30#ifndef DOXYGEN
31template <int, int>
32class FEValuesBase;
33#endif
34
35namespace MeshWorker
36{
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 <typename StreamType, typename DATA>
150 void
151 print(StreamType &s, const AnyData &v) const;
152
156 template <typename StreamType>
157 void
158 print(StreamType &s) const;
159
163 std::size_t
164 memory_consumption() const;
165
166 protected:
171
176
181 };
182
189 template <int dim, int spacedim = dim, typename Number = double>
191 {
192 public:
196 VectorDataBase() = default;
197
202
210 void
212
216 virtual ~VectorDataBase() override = default;
217
256 virtual void
257 fill(std::vector<std::vector<std::vector<Number>>> &values,
258 std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
259 &gradients,
260 std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
261 &hessians,
263 const std::vector<types::global_dof_index> &index,
264 const unsigned int component,
265 const unsigned int n_comp,
266 const unsigned int start,
267 const unsigned int size) const;
268
275 virtual void
276 mg_fill(std::vector<std::vector<std::vector<Number>>> &values,
277 std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
278 &gradients,
279 std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
280 &hessians,
282 const unsigned int level,
283 const std::vector<types::global_dof_index> &index,
284 const unsigned int component,
285 const unsigned int n_comp,
286 const unsigned int start,
287 const unsigned int size) const;
288
289 protected:
291 };
292
293
301 template <typename VectorType, int dim, int spacedim = dim>
303 : public VectorDataBase<dim, spacedim, typename VectorType::value_type>
304 {
305 public:
309 VectorData() = default;
310
315
319 void
321
329 void
330 initialize(const VectorType *, const std::string &name);
331
332 virtual void
333 fill(std::vector<std::vector<std::vector<typename VectorType::value_type>>>
334 &values,
335 std::vector<std::vector<
337 &gradients,
338 std::vector<std::vector<
340 &hessians,
342 const std::vector<types::global_dof_index> &index,
343 const unsigned int component,
344 const unsigned int n_comp,
345 const unsigned int start,
346 const unsigned int size) const override;
347
348 virtual void
350 std::vector<std::vector<std::vector<typename VectorType::value_type>>>
351 &values,
352 std::vector<std::vector<
354 &gradients,
355 std::vector<std::vector<
357 &hessians,
359 const unsigned int level,
360 const std::vector<types::global_dof_index> &index,
361 const unsigned int component,
362 const unsigned int n_comp,
363 const unsigned int start,
364 const unsigned int size) const override;
365
369 std::size_t
371 };
372
373
381 template <typename VectorType, int dim, int spacedim = dim>
382 class MGVectorData : public VectorData<VectorType, dim, spacedim>
383 {
384 public:
388 MGVectorData() = default;
389
394
398 void
400
408 void
409 initialize(const MGLevelObject<VectorType> *, const std::string &name);
410 };
411
412
413 //----------------------------------------------------------------------//
414
415 inline void
416 VectorSelector::add(const std::string &name,
417 const bool values,
418 const bool gradients,
419 const bool hessians)
420 {
421 if (values)
422 value_selection.add(name);
423 if (gradients)
425 if (hessians)
427 }
428
429
430 // inline void
431 // VectorSelector::add(const std::string& name,
432 // const unsigned int block,
433 // bool values, bool gradients, bool hessians)
434 //{
435 // if (values) value_selection.add(name, block);
436 // if (gradients) gradient_selection.add(name, block);
437 // if (hessians) hessian_selection.add(name, block);
438 //}
439
440
441 inline void
448
449 inline bool
451 {
452 return (value_selection.size() == 0 && gradient_selection.size() == 0 &&
453 hessian_selection.size() == 0);
454 }
455
456
457 inline bool
459 {
460 return value_selection.size() != 0;
461 }
462
463
464 inline bool
466 {
467 return gradient_selection.size() != 0;
468 }
469
470
471 inline bool
473 {
474 return hessian_selection.size() != 0;
475 }
476
477
478 inline unsigned int
480 {
481 return value_selection.size();
482 }
483
484
485 inline unsigned int
487 {
488 return gradient_selection.size();
489 }
490
491
492 inline unsigned int
494 {
495 return hessian_selection.size();
496 }
497
498
499 inline unsigned int
500 VectorSelector::value_index(const unsigned int i) const
501 {
502 return value_selection(i);
503 }
504
505
506 inline unsigned int
507 VectorSelector::gradient_index(const unsigned int i) const
508 {
509 return gradient_selection(i);
510 }
511
512
513 inline unsigned int
514 VectorSelector::hessian_index(const unsigned int i) const
515 {
516 return hessian_selection(i);
517 }
518
519
520 template <typename StreamType>
521 inline void
522 VectorSelector::print(StreamType &s) const
523 {
524 s << "values: " << n_values() << " gradients: " << n_gradients()
525 << " hessians: " << n_hessians() << std::endl;
526 }
527
528
529 template <typename StreamType, typename DATA>
530 inline void
531 VectorSelector::print(StreamType &s, const AnyData &v) const
532 {
533 s << "values: ";
534 for (unsigned int i = 0; i < n_values(); ++i)
535 s << " '" << v.name(value_selection(i)) << '\'';
536 s << std::endl << "gradients:";
537 for (unsigned int i = 0; i < n_gradients(); ++i)
538 s << " '" << v.name(gradient_selection(i)) << '\'';
539 s << std::endl << "hessians: ";
540 for (unsigned int i = 0; i < n_hessians(); ++i)
541 s << " '" << v.name(hessian_selection(i)) << '\'';
542 s << std::endl;
543 }
544
545
546 inline std::size_t
548 {
549 return sizeof(*this);
550 }
551} // namespace MeshWorker
552
553
555
556#endif
const std::string & name(const unsigned int i) const
Name of object at index.
Definition any_data.h:309
void initialize(const AnyData &)
MGVectorData(const VectorSelector &)
void initialize(const MGLevelObject< VectorType > *, 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 initialize(const AnyData &)
virtual ~VectorDataBase() override=default
VectorDataBase(const VectorSelector &)
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 VectorType *, const std::string &name)
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 override
VectorData(const VectorSelector &)
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 override
std::size_t memory_consumption() const
void initialize(const AnyData &)
std::size_t memory_consumption() const
unsigned int n_values() const
unsigned int n_gradients() const
unsigned int value_index(const unsigned int i) const
void print(StreamType &s, const AnyData &v) const
void initialize(const AnyData &)
unsigned int n_hessians() const
unsigned int hessian_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 gradient_index(const unsigned int i) const
void initialize(const AnyData &data)
void add(const std::string &name)
unsigned int size() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
unsigned int level
Definition grid_out.cc:4626