Reference documentation for deal.II version 9.6.0
\(\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
block_vector.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 1999 - 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_block_vector_h
16#define dealii_block_vector_h
17
18
19#include <deal.II/base/config.h>
20
22
27
28#include <cstdio>
29#include <vector>
30
32
33
34// Forward declaration
35#ifndef DOXYGEN
36# ifdef DEAL_II_WITH_TRILINOS
37namespace TrilinosWrappers
38{
39 namespace MPI
40 {
41 class BlockVector;
42 }
43} // namespace TrilinosWrappers
44# endif
45#endif
46
47
69template <typename Number>
70class BlockVector : public BlockVectorBase<Vector<Number>>
71{
72public:
77
82
88 using pointer = typename BaseClass::pointer;
93 using iterator = typename BaseClass::iterator;
95
106 explicit BlockVector(const unsigned int n_blocks = 0,
107 const size_type block_size = 0);
108
114
115
120 BlockVector(BlockVector<Number> && /*v*/) noexcept = default;
121
128 template <typename OtherNumber>
129 explicit BlockVector(const BlockVector<OtherNumber> &v);
130
131#ifdef DEAL_II_WITH_TRILINOS
137
138#endif
143 BlockVector(const std::vector<size_type> &block_sizes);
144
150
160 template <typename InputIterator>
161 BlockVector(const std::vector<size_type> &block_sizes,
162 const InputIterator first,
163 const InputIterator end);
164
168 ~BlockVector() override = default;
169
180 void
182
189 bool
191
198
207
213 operator=(BlockVector<Number> && /*v*/) = default; // NOLINT
214
219 template <class Number2>
222
228
229#ifdef DEAL_II_WITH_TRILINOS
236#endif
237
250 void
251 reinit(const unsigned int n_blocks,
252 const size_type block_size = 0,
253 const bool omit_zeroing_entries = false);
254
271 void
272 reinit(const std::vector<size_type> &block_sizes,
273 const bool omit_zeroing_entries = false);
274
284 void
286 const bool omit_zeroing_entries = false);
287
301 template <typename Number2>
302 void
304 const bool omit_zeroing_entries = false);
305
310 template <class BlockVector2>
311 void
312 scale(const BlockVector2 &v);
313
325 void
327
331 void
332 print(std::ostream &out,
333 const unsigned int precision = 3,
334 const bool scientific = true,
335 const bool across = true) const;
336
342 void
343 block_write(std::ostream &out) const;
344
356 void
357 block_read(std::istream &in);
358
369};
370
373#ifndef DOXYGEN
374/*----------------------- Inline functions ----------------------------------*/
375
376
377
378template <typename Number>
379template <typename InputIterator>
380BlockVector<Number>::BlockVector(const std::vector<size_type> &block_sizes,
381 const InputIterator first,
382 const InputIterator end)
383{
384 // first set sizes of blocks, but
385 // don't initialize them as we will
386 // copy elements soon
387 (void)end;
388 reinit(block_sizes, true);
389 InputIterator start = first;
390 for (size_type b = 0; b < block_sizes.size(); ++b)
391 {
392 InputIterator end = start;
393 std::advance(end, static_cast<signed int>(block_sizes[b]));
394 std::copy(start, end, this->block(b).begin());
395 start = end;
396 };
397 Assert(start == end, ExcIteratorRangeDoesNotMatchVectorSize());
398}
399
400
401
402template <typename Number>
403inline BlockVector<Number> &
404BlockVector<Number>::operator=(const value_type s)
405{
407
408 BaseClass::operator=(s);
409 return *this;
410}
411
412
413
414template <typename Number>
415inline BlockVector<Number> &
417{
418 reinit(v, true);
419 BaseClass::operator=(v);
420 return *this;
421}
422
423
424
425template <typename Number>
426inline BlockVector<Number> &
428{
429 BaseClass::operator=(v);
430 return *this;
431}
432
433
434
435template <typename Number>
436template <typename Number2>
437inline BlockVector<Number> &
439{
440 reinit(v, true);
441 BaseClass::operator=(v);
442 return *this;
443}
444
445template <typename Number>
446inline void
448{
449 for (size_type i = 0; i < this->n_blocks(); ++i)
450 this->components[i].compress(operation);
451}
452
453
454
455template <typename Number>
456inline bool
458{
459 return false;
460}
461
462
463
464template <typename Number>
465template <class BlockVector2>
466void
467BlockVector<Number>::scale(const BlockVector2 &v)
468{
469 BaseClass::scale(v);
470}
471
472#endif // DOXYGEN
473
474
482template <typename Number>
483inline void
485{
486 u.swap(v);
487}
488
489
490namespace internal
491{
492 namespace LinearOperatorImplementation
493 {
494 template <typename>
495 class ReinitHelper;
496
501 template <typename number>
503 {
504 public:
505 template <typename Matrix>
506 static void
507 reinit_range_vector(const Matrix &matrix,
509 bool omit_zeroing_entries)
510 {
511 v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
512 }
513
514 template <typename Matrix>
515 static void
516 reinit_domain_vector(const Matrix &matrix,
518 bool omit_zeroing_entries)
519 {
520 v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
521 }
522 };
523
524 } // namespace LinearOperatorImplementation
525} /* namespace internal */
526
527
531template <typename Number>
532struct is_serial_vector<BlockVector<Number>> : std::true_type
533{};
534
536
537#endif
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
typename BlockType::const_reference const_reference
typename BlockType::value_type value_type
typename BlockType::reference reference
typename BlockType::real_type real_type
BlockVector(const std::vector< size_type > &block_sizes)
typename BaseClass::const_reference const_reference
void reinit(const BlockIndices &block_indices, const bool omit_zeroing_entries=false)
typename BaseClass::reference reference
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
void swap(BlockVector< Number > &u, BlockVector< Number > &v) noexcept
void compress(VectorOperation::values operation=VectorOperation::unknown)
bool has_ghost_elements() const
BlockVector(const TrilinosWrappers::MPI::BlockVector &v)
BlockVector< Number > & operator=(const TrilinosWrappers::MPI::BlockVector &V)
BlockVector< Number > & operator=(const BlockVector< Number2 > &V)
BlockVector(const BlockIndices &block_indices)
BlockVector< Number > & operator=(BlockVector< Number > &&)=default
typename BaseClass::value_type value_type
typename BaseClass::const_pointer const_pointer
BlockVector(const BlockVector< Number > &V)
void block_write(std::ostream &out) const
typename BaseClass::pointer pointer
~BlockVector() override=default
typename BaseClass::BlockType BlockType
BlockVector(const unsigned int n_blocks=0, const size_type block_size=0)
void scale(const BlockVector2 &v)
void swap(BlockVector< Number > &v) noexcept
BlockVector(BlockVector< Number > &&) noexcept=default
void reinit(const std::vector< size_type > &block_sizes, const bool omit_zeroing_entries=false)
typename BaseClass::iterator iterator
void block_read(std::istream &in)
BlockVector & operator=(const value_type s)
typename BaseClass::size_type size_type
BlockVector< Number > & operator=(const Vector< Number > &V)
BlockVector< Number > & operator=(const BlockVector< Number > &v)
BlockVector(const std::vector< size_type > &block_sizes, const InputIterator first, const InputIterator end)
void reinit(const unsigned int n_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
typename BaseClass::const_iterator const_iterator
void reinit(const BlockVector< Number2 > &V, const bool omit_zeroing_entries=false)
typename BaseClass::real_type real_type
static void reinit_range_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
static void reinit_domain_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
Point< 2 > first
Definition grid_out.cc:4623
#define DeclException0(Exception0)
Definition exceptions.h:471
#define Assert(cond, exc)
#define AssertIsFinite(number)
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
std::enable_if_t< IsBlockVector< VectorType >::value, unsigned int > n_blocks(const VectorType &vector)
Definition operators.h:49
std::string compress(const std::string &input)
Definition utilities.cc:389
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)