deal.II version GIT relicensing-2647-gce4370862c 2025-02-15 16:00:00+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 - 2024 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
26#include <deal.II/base/tensor.h>
27#include <deal.II/base/types.h>
28
30
31// Forward declaration
32#ifndef DOXYGEN
33template <int, int>
34class FEValuesBase;
35#endif
36
37namespace MeshWorker
38{
50 {
51 public:
60 void
61 add(const std::string &name,
62 const bool values = true,
63 const bool gradients = false,
64 const bool hessians = false);
65
70 // void add(const std::string& name,
71 // const unsigned int selected_block,
72 // bool values = true,
73 // bool gradients = false,
74 // bool hessians = false);
75
85 void
86 initialize(const AnyData &);
87
91 bool
92 empty() const;
93
97 bool
98 has_values() const;
99
103 bool
104 has_gradients() const;
105
109 bool
110 has_hessians() const;
111
115 unsigned int
116 n_values() const;
117
121 unsigned int
122 n_gradients() const;
123
127 unsigned int
128 n_hessians() const;
129
133 unsigned int
134 value_index(const unsigned int i) const;
135
139 unsigned int
140 gradient_index(const unsigned int i) const;
141
145 unsigned int
146 hessian_index(const unsigned int i) const;
147
151 template <typename StreamType, typename DATA>
152 void
153 print(StreamType &s, const AnyData &v) const;
154
158 template <typename StreamType>
159 void
160 print(StreamType &s) const;
161
165 std::size_t
166 memory_consumption() const;
167
168 protected:
173
178
183 };
184
191 template <int dim, int spacedim = dim, typename Number = double>
193 {
194 public:
198 VectorDataBase() = default;
199
204
212 void
214
218 virtual ~VectorDataBase() override = default;
219
258 virtual void
259 fill(std::vector<std::vector<std::vector<Number>>> &values,
260 std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
261 &gradients,
262 std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
263 &hessians,
265 const std::vector<types::global_dof_index> &index,
266 const unsigned int component,
267 const unsigned int n_comp,
268 const unsigned int start,
269 const unsigned int size) const;
270
277 virtual void
278 mg_fill(std::vector<std::vector<std::vector<Number>>> &values,
279 std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
280 &gradients,
281 std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
282 &hessians,
284 const unsigned int level,
285 const std::vector<types::global_dof_index> &index,
286 const unsigned int component,
287 const unsigned int n_comp,
288 const unsigned int start,
289 const unsigned int size) const;
290
291 protected:
293 };
294
295
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
317
321 void
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,
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
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,
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
373 };
374
375
383 template <typename VectorType, int dim, int spacedim = dim>
384 class MGVectorData : public VectorData<VectorType, dim, spacedim>
385 {
386 public:
390 MGVectorData() = default;
391
396
400 void
402
410 void
411 initialize(const MGLevelObject<VectorType> *, const std::string &name);
412 };
413
414
415 //----------------------------------------------------------------------//
416
417 inline void
418 VectorSelector::add(const std::string &name,
419 const bool values,
420 const bool gradients,
421 const bool hessians)
422 {
423 if (values)
424 value_selection.add(name);
425 if (gradients)
427 if (hessians)
429 }
430
431
432 // inline void
433 // VectorSelector::add(const std::string& name,
434 // const unsigned int block,
435 // bool values, bool gradients, bool hessians)
436 //{
437 // if (values) value_selection.add(name, block);
438 // if (gradients) gradient_selection.add(name, block);
439 // if (hessians) hessian_selection.add(name, block);
440 //}
441
442
443 inline void
450
451 inline bool
453 {
454 return (value_selection.size() == 0 && gradient_selection.size() == 0 &&
455 hessian_selection.size() == 0);
456 }
457
458
459 inline bool
461 {
462 return value_selection.size() != 0;
463 }
464
465
466 inline bool
468 {
469 return gradient_selection.size() != 0;
470 }
471
472
473 inline bool
475 {
476 return hessian_selection.size() != 0;
477 }
478
479
480 inline unsigned int
482 {
483 return value_selection.size();
484 }
485
486
487 inline unsigned int
489 {
490 return gradient_selection.size();
491 }
492
493
494 inline unsigned int
496 {
497 return hessian_selection.size();
498 }
499
500
501 inline unsigned int
502 VectorSelector::value_index(const unsigned int i) const
503 {
504 return value_selection(i);
505 }
506
507
508 inline unsigned int
509 VectorSelector::gradient_index(const unsigned int i) const
510 {
511 return gradient_selection(i);
512 }
513
514
515 inline unsigned int
516 VectorSelector::hessian_index(const unsigned int i) const
517 {
518 return hessian_selection(i);
519 }
520
521
522 template <typename StreamType>
523 inline void
524 VectorSelector::print(StreamType &s) const
525 {
526 s << "values: " << n_values() << " gradients: " << n_gradients()
527 << " hessians: " << n_hessians() << std::endl;
528 }
529
530
531 template <typename StreamType, typename DATA>
532 inline void
533 VectorSelector::print(StreamType &s, const AnyData &v) const
534 {
535 s << "values: ";
536 for (unsigned int i = 0; i < n_values(); ++i)
537 s << " '" << v.name(value_selection(i)) << '\'';
538 s << std::endl << "gradients:";
539 for (unsigned int i = 0; i < n_gradients(); ++i)
540 s << " '" << v.name(gradient_selection(i)) << '\'';
541 s << std::endl << "hessians: ";
542 for (unsigned int i = 0; i < n_hessians(); ++i)
543 s << " '" << v.name(hessian_selection(i)) << '\'';
544 s << std::endl;
545 }
546
547
548 inline std::size_t
550 {
551 return sizeof(*this);
552 }
553} // namespace MeshWorker
554
555
557
558#endif
const std::string & name(const unsigned int i) const
Name of object at index.
Definition any_data.h:310
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:518
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:519
unsigned int level
Definition grid_out.cc:4632
std::size_t size
Definition mpi.cc:739