Reference documentation for deal.II version 9.4.1
\(\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// Copyright (C) 1999 - 2021 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_block_vector_h
17#define dealii_block_vector_h
18
19
20#include <deal.II/base/config.h>
21
23
28
29#include <cstdio>
30#include <vector>
31
33
34
35// Forward declaration
36#ifndef DOXYGEN
37# ifdef DEAL_II_WITH_TRILINOS
38namespace TrilinosWrappers
39{
40 namespace MPI
41 {
42 class BlockVector;
43 }
44} // namespace TrilinosWrappers
45# endif
46#endif
47
48
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
183
190 bool
192
199
206
212 operator=(BlockVector<Number> && /*v*/) = default; // NOLINT
213
218 template <class Number2>
221
227
228#ifdef DEAL_II_WITH_TRILINOS
235#endif
236
249 void
250 reinit(const unsigned int n_blocks,
251 const size_type block_size = 0,
252 const bool omit_zeroing_entries = false);
253
270 void
271 reinit(const std::vector<size_type> &block_sizes,
272 const bool omit_zeroing_entries = false);
273
283 void
285 const bool omit_zeroing_entries = false);
286
300 template <typename Number2>
301 void
303 const bool omit_zeroing_entries = false);
304
309 template <class BlockVector2>
310 void
311 scale(const BlockVector2 &v);
312
324 void
326
330 void
331 print(std::ostream & out,
332 const unsigned int precision = 3,
333 const bool scientific = true,
334 const bool across = true) const;
335
341 void
342 block_write(std::ostream &out) const;
343
355 void
356 block_read(std::istream &in);
357
368};
369
372#ifndef DOXYGEN
373/*----------------------- Inline functions ----------------------------------*/
374
375
376
377template <typename Number>
378template <typename InputIterator>
379BlockVector<Number>::BlockVector(const std::vector<size_type> &block_sizes,
380 const InputIterator first,
381 const InputIterator end)
382{
383 // first set sizes of blocks, but
384 // don't initialize them as we will
385 // copy elements soon
386 (void)end;
387 reinit(block_sizes, true);
388 InputIterator start = first;
389 for (size_type b = 0; b < block_sizes.size(); ++b)
390 {
391 InputIterator end = start;
392 std::advance(end, static_cast<signed int>(block_sizes[b]));
393 std::copy(start, end, this->block(b).begin());
394 start = end;
395 };
396 Assert(start == end, ExcIteratorRangeDoesNotMatchVectorSize());
397}
398
399
400
401template <typename Number>
402inline BlockVector<Number> &
403BlockVector<Number>::operator=(const value_type s)
404{
406
407 BaseClass::operator=(s);
408 return *this;
409}
410
411
412
413template <typename Number>
414inline BlockVector<Number> &
416{
417 reinit(v, true);
418 BaseClass::operator=(v);
419 return *this;
420}
421
422
423
424template <typename Number>
425inline BlockVector<Number> &
427{
428 BaseClass::operator=(v);
429 return *this;
430}
431
432
433
434template <typename Number>
435template <typename Number2>
436inline BlockVector<Number> &
438{
439 reinit(v, true);
440 BaseClass::operator=(v);
441 return *this;
442}
443
444template <typename Number>
445inline void
447{
448 for (size_type i = 0; i < this->n_blocks(); ++i)
449 this->components[i].compress(operation);
450}
451
452
453
454template <typename Number>
455inline bool
457{
458 return false;
459}
460
461
462
463template <typename Number>
464template <class BlockVector2>
465void
466BlockVector<Number>::scale(const BlockVector2 &v)
467{
468 BaseClass::scale(v);
469}
470
471#endif // DOXYGEN
472
473
481template <typename Number>
482inline void
484{
485 u.swap(v);
486}
487
488
489namespace internal
490{
491 namespace LinearOperatorImplementation
492 {
493 template <typename>
494 class ReinitHelper;
495
500 template <typename number>
502 {
503 public:
504 template <typename Matrix>
505 static void
506 reinit_range_vector(const Matrix & matrix,
508 bool omit_zeroing_entries)
509 {
510 v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
511 }
512
513 template <typename Matrix>
514 static void
515 reinit_domain_vector(const Matrix & matrix,
517 bool omit_zeroing_entries)
518 {
519 v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
520 }
521 };
522
523 } // namespace LinearOperatorImplementation
524} /* namespace internal */
525
526
530template <typename Number>
531struct is_serial_vector<BlockVector<Number>> : std::true_type
532{};
533
535
536#endif
Definition: vector.h:109
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
Point< 2 > first
Definition: grid_out.cc:4603
#define DeclException0(Exception0)
Definition: exceptions.h:464
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
typename BlockType::const_reference const_reference
typename BlockType::value_type value_type
#define Assert(cond, exc)
Definition: exceptions.h:1473
#define AssertIsFinite(number)
Definition: exceptions.h:1758
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
static void reinit_range_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:506
typename BlockType::reference reference
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
static void reinit_domain_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:515
typename BlockType::real_type real_type
BlockVector(const std::vector< size_type > &block_sizes)
typename BaseClass::const_reference const_reference
Definition: block_vector.h:91
void reinit(const BlockIndices &block_indices, const bool omit_zeroing_entries=false)
void swap(BlockVector< Number > &v)
typename BaseClass::reference reference
Definition: block_vector.h:90
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
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
Definition: block_vector.h:86
typename BaseClass::const_pointer const_pointer
Definition: block_vector.h:89
BlockVector(const BlockVector< Number > &V)
void block_write(std::ostream &out) const
typename BaseClass::pointer pointer
Definition: block_vector.h:88
~BlockVector() override=default
typename BaseClass::BlockType BlockType
Definition: block_vector.h:81
BlockVector(const unsigned int n_blocks=0, const size_type block_size=0)
void scale(const BlockVector2 &v)
BlockVector(BlockVector< Number > &&) noexcept=default
void reinit(const std::vector< size_type > &block_sizes, const bool omit_zeroing_entries=false)
typename BaseClass::iterator iterator
Definition: block_vector.h:93
void block_read(std::istream &in)
BlockVector & operator=(const value_type s)
typename BaseClass::size_type size_type
Definition: block_vector.h:92
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 compress(::VectorOperation::values operation=::VectorOperation::unknown)
void reinit(const unsigned int n_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
void swap(BlockVector< Number > &u, BlockVector< Number > &v)
Definition: block_vector.h:483
typename BaseClass::const_iterator const_iterator
Definition: block_vector.h:94
void reinit(const BlockVector< Number2 > &V, const bool omit_zeroing_entries=false)
typename BaseClass::real_type real_type
Definition: block_vector.h:87
std::enable_if< IsBlockVector< VectorType >::value, unsignedint >::type n_blocks(const VectorType &vector)
Definition: operators.h:50
std::string compress(const std::string &input)
Definition: utilities.cc:392
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:618