Reference documentation for deal.II version GIT relicensing-249-g48dc7357c7 2024-03-29 12:30: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{
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 <typename StreamType, typename DATA>
153 void
154 print(StreamType &s, const AnyData &v) const;
155
159 template <typename StreamType>
160 void
161 print(StreamType &s) const;
162
166 std::size_t
167 memory_consumption() const;
168
169 protected:
174
179
184 };
185
192 template <int dim, int spacedim = dim, typename Number = double>
194 {
195 public:
199 VectorDataBase() = default;
200
205
213 void
215
219 virtual ~VectorDataBase() override = default;
220
259 virtual void
260 fill(std::vector<std::vector<std::vector<Number>>> &values,
261 std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
262 &gradients,
263 std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
264 &hessians,
266 const std::vector<types::global_dof_index> &index,
267 const unsigned int component,
268 const unsigned int n_comp,
269 const unsigned int start,
270 const unsigned int size) const;
271
278 virtual void
279 mg_fill(std::vector<std::vector<std::vector<Number>>> &values,
280 std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>>
281 &gradients,
282 std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>>
283 &hessians,
285 const unsigned int level,
286 const std::vector<types::global_dof_index> &index,
287 const unsigned int component,
288 const unsigned int n_comp,
289 const unsigned int start,
290 const unsigned int size) const;
291
292 protected:
294 };
295
296
304 template <typename VectorType, int dim, int spacedim = dim>
306 : public VectorDataBase<dim, spacedim, typename VectorType::value_type>
307 {
308 public:
312 VectorData() = default;
313
318
322 void
324
332 void
333 initialize(const VectorType *, const std::string &name);
334
335 virtual void
336 fill(std::vector<std::vector<std::vector<typename VectorType::value_type>>>
337 &values,
338 std::vector<std::vector<
340 &gradients,
341 std::vector<std::vector<
343 &hessians,
345 const std::vector<types::global_dof_index> &index,
346 const unsigned int component,
347 const unsigned int n_comp,
348 const unsigned int start,
349 const unsigned int size) const override;
350
351 virtual void
353 std::vector<std::vector<std::vector<typename VectorType::value_type>>>
354 &values,
355 std::vector<std::vector<
357 &gradients,
358 std::vector<std::vector<
360 &hessians,
362 const unsigned int level,
363 const std::vector<types::global_dof_index> &index,
364 const unsigned int component,
365 const unsigned int n_comp,
366 const unsigned int start,
367 const unsigned int size) const override;
368
372 std::size_t
374 };
375
376
384 template <typename VectorType, int dim, int spacedim = dim>
385 class MGVectorData : public VectorData<VectorType, dim, spacedim>
386 {
387 public:
391 MGVectorData() = default;
392
397
401 void
403
411 void
412 initialize(const MGLevelObject<VectorType> *, const std::string &name);
413 };
414
415
416 //----------------------------------------------------------------------//
417
418 inline void
419 VectorSelector::add(const std::string &name,
420 const bool values,
421 const bool gradients,
422 const bool hessians)
423 {
424 if (values)
425 value_selection.add(name);
426 if (gradients)
428 if (hessians)
430 }
431
432
433 // inline void
434 // VectorSelector::add(const std::string& name,
435 // const unsigned int block,
436 // bool values, bool gradients, bool hessians)
437 //{
438 // if (values) value_selection.add(name, block);
439 // if (gradients) gradient_selection.add(name, block);
440 // if (hessians) hessian_selection.add(name, block);
441 //}
442
443
444 inline void
451
452 inline bool
454 {
455 return (value_selection.size() == 0 && gradient_selection.size() == 0 &&
456 hessian_selection.size() == 0);
457 }
458
459
460 inline bool
462 {
463 return value_selection.size() != 0;
464 }
465
466
467 inline bool
469 {
470 return gradient_selection.size() != 0;
471 }
472
473
474 inline bool
476 {
477 return hessian_selection.size() != 0;
478 }
479
480
481 inline unsigned int
483 {
484 return value_selection.size();
485 }
486
487
488 inline unsigned int
490 {
491 return gradient_selection.size();
492 }
493
494
495 inline unsigned int
497 {
498 return hessian_selection.size();
499 }
500
501
502 inline unsigned int
503 VectorSelector::value_index(const unsigned int i) const
504 {
505 return value_selection(i);
506 }
507
508
509 inline unsigned int
510 VectorSelector::gradient_index(const unsigned int i) const
511 {
512 return gradient_selection(i);
513 }
514
515
516 inline unsigned int
517 VectorSelector::hessian_index(const unsigned int i) const
518 {
519 return hessian_selection(i);
520 }
521
522
523 template <typename StreamType>
524 inline void
525 VectorSelector::print(StreamType &s) const
526 {
527 s << "values: " << n_values() << " gradients: " << n_gradients()
528 << " hessians: " << n_hessians() << std::endl;
529 }
530
531
532 template <typename StreamType, typename DATA>
533 inline void
534 VectorSelector::print(StreamType &s, const AnyData &v) const
535 {
536 s << "values: ";
537 for (unsigned int i = 0; i < n_values(); ++i)
538 s << " '" << v.name(value_selection(i)) << '\'';
539 s << std::endl << "gradients:";
540 for (unsigned int i = 0; i < n_gradients(); ++i)
541 s << " '" << v.name(gradient_selection(i)) << '\'';
542 s << std::endl << "hessians: ";
543 for (unsigned int i = 0; i < n_hessians(); ++i)
544 s << " '" << v.name(hessian_selection(i)) << '\'';
545 s << std::endl;
546 }
547
548
549 inline std::size_t
551 {
552 return sizeof(*this);
553 }
554} // namespace MeshWorker
555
556
558
559#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:4616