deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+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: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2009 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_mesh_worker_vector_selector_h
14#define dealii_mesh_worker_vector_selector_h
15
16#include <deal.II/base/config.h>
17
20
24#include <deal.II/base/tensor.h>
25#include <deal.II/base/types.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>
383 : public VectorData<VectorType, dim, spacedim>
384 {
385 public:
389 MGVectorData() = default;
390
395
399 void
401
409 void
410 initialize(const MGLevelObject<VectorType> *, const std::string &name);
411 };
412
413
414 //----------------------------------------------------------------------//
415
416 inline void
417 VectorSelector::add(const std::string &name,
418 const bool values,
419 const bool gradients,
420 const bool hessians)
421 {
422 if (values)
423 value_selection.add(name);
424 if (gradients)
426 if (hessians)
428 }
429
430
431 // inline void
432 // VectorSelector::add(const std::string& name,
433 // const unsigned int block,
434 // bool values, bool gradients, bool hessians)
435 //{
436 // if (values) value_selection.add(name, block);
437 // if (gradients) gradient_selection.add(name, block);
438 // if (hessians) hessian_selection.add(name, block);
439 //}
440
441
442 inline void
449
450 inline bool
452 {
453 return (value_selection.size() == 0 && gradient_selection.size() == 0 &&
454 hessian_selection.size() == 0);
455 }
456
457
458 inline bool
460 {
461 return value_selection.size() != 0;
462 }
463
464
465 inline bool
467 {
468 return gradient_selection.size() != 0;
469 }
470
471
472 inline bool
474 {
475 return hessian_selection.size() != 0;
476 }
477
478
479 inline unsigned int
481 {
482 return value_selection.size();
483 }
484
485
486 inline unsigned int
488 {
489 return gradient_selection.size();
490 }
491
492
493 inline unsigned int
495 {
496 return hessian_selection.size();
497 }
498
499
500 inline unsigned int
501 VectorSelector::value_index(const unsigned int i) const
502 {
503 return value_selection(i);
504 }
505
506
507 inline unsigned int
508 VectorSelector::gradient_index(const unsigned int i) const
509 {
510 return gradient_selection(i);
511 }
512
513
514 inline unsigned int
515 VectorSelector::hessian_index(const unsigned int i) const
516 {
517 return hessian_selection(i);
518 }
519
520
521 template <typename StreamType>
522 inline void
523 VectorSelector::print(StreamType &s) const
524 {
525 s << "values: " << n_values() << " gradients: " << n_gradients()
526 << " hessians: " << n_hessians() << std::endl;
527 }
528
529
530 template <typename StreamType, typename DATA>
531 inline void
532 VectorSelector::print(StreamType &s, const AnyData &v) const
533 {
534 s << "values: ";
535 for (unsigned int i = 0; i < n_values(); ++i)
536 s << " '" << v.name(value_selection(i)) << '\'';
537 s << std::endl << "gradients:";
538 for (unsigned int i = 0; i < n_gradients(); ++i)
539 s << " '" << v.name(gradient_selection(i)) << '\'';
540 s << std::endl << "hessians: ";
541 for (unsigned int i = 0; i < n_hessians(); ++i)
542 s << " '" << v.name(hessian_selection(i)) << '\'';
543 s << std::endl;
544 }
545
546
547 inline std::size_t
549 {
550 return sizeof(*this);
551 }
552} // namespace MeshWorker
553
554
556
557#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_DEPRECATED
Definition config.h:294
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
unsigned int level
Definition grid_out.cc:4642
std::size_t size
Definition mpi.cc:733