Reference documentation for deal.II version 9.3.3
\(\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\}}\)
block_vector.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 1999 - 2020 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
134 template <typename OtherNumber>
135 explicit BlockVector(const BlockVector<OtherNumber> &v);
136
137#ifdef DEAL_II_WITH_TRILINOS
143
144#endif
149 BlockVector(const std::vector<size_type> &block_sizes);
150
156
166 template <typename InputIterator>
167 BlockVector(const std::vector<size_type> &block_sizes,
168 const InputIterator first,
169 const InputIterator end);
170
174 ~BlockVector() override = default;
175
186 void
189
196 bool
198
205
212
218 operator=(BlockVector<Number> && /*v*/) = default; // NOLINT
219
224 template <class Number2>
227
233
234#ifdef DEAL_II_WITH_TRILINOS
241#endif
242
255 void
256 reinit(const unsigned int n_blocks,
257 const size_type block_size = 0,
258 const bool omit_zeroing_entries = false);
259
276 void
277 reinit(const std::vector<size_type> &block_sizes,
278 const bool omit_zeroing_entries = false);
279
289 void
291 const bool omit_zeroing_entries = false);
292
306 template <typename Number2>
307 void
309 const bool omit_zeroing_entries = false);
310
315 template <class BlockVector2>
316 void
317 scale(const BlockVector2 &v);
318
330 void
332
336 void
337 print(std::ostream & out,
338 const unsigned int precision = 3,
339 const bool scientific = true,
340 const bool across = true) const;
341
347 void
348 block_write(std::ostream &out) const;
349
361 void
362 block_read(std::istream &in);
363
374};
375
378#ifndef DOXYGEN
379/*----------------------- Inline functions ----------------------------------*/
380
381
382
383template <typename Number>
384template <typename InputIterator>
385BlockVector<Number>::BlockVector(const std::vector<size_type> &block_sizes,
386 const InputIterator first,
387 const InputIterator end)
388{
389 // first set sizes of blocks, but
390 // don't initialize them as we will
391 // copy elements soon
392 (void)end;
393 reinit(block_sizes, true);
394 InputIterator start = first;
395 for (size_type b = 0; b < block_sizes.size(); ++b)
396 {
397 InputIterator end = start;
398 std::advance(end, static_cast<signed int>(block_sizes[b]));
399 std::copy(start, end, this->block(b).begin());
400 start = end;
401 };
402 Assert(start == end, ExcIteratorRangeDoesNotMatchVectorSize());
403}
404
405
406
407template <typename Number>
408inline BlockVector<Number> &
409BlockVector<Number>::operator=(const value_type s)
410{
412
413 BaseClass::operator=(s);
414 return *this;
415}
416
417
418
419template <typename Number>
420inline BlockVector<Number> &
422{
423 reinit(v, true);
424 BaseClass::operator=(v);
425 return *this;
426}
427
428
429
430template <typename Number>
431inline BlockVector<Number> &
433{
434 BaseClass::operator=(v);
435 return *this;
436}
437
438
439
440template <typename Number>
441template <typename Number2>
442inline BlockVector<Number> &
444{
445 reinit(v, true);
446 BaseClass::operator=(v);
447 return *this;
448}
449
450template <typename Number>
451inline void
453{
454 for (size_type i = 0; i < this->n_blocks(); ++i)
455 this->components[i].compress(operation);
456}
457
458
459
460template <typename Number>
461inline bool
463{
464 return false;
465}
466
467
468
469template <typename Number>
470template <class BlockVector2>
471void
472BlockVector<Number>::scale(const BlockVector2 &v)
473{
475}
476
477#endif // DOXYGEN
478
479
487template <typename Number>
488inline void
490{
491 u.swap(v);
492}
493
494
495namespace internal
496{
497 namespace LinearOperatorImplementation
498 {
499 template <typename>
500 class ReinitHelper;
501
506 template <typename number>
508 {
509 public:
510 template <typename Matrix>
511 static void
514 bool omit_zeroing_entries)
515 {
516 v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
517 }
518
519 template <typename Matrix>
520 static void
523 bool omit_zeroing_entries)
524 {
525 v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
526 }
527 };
528
529 } // namespace LinearOperatorImplementation
530} /* namespace internal */
531
532
536template <typename Number>
537struct is_serial_vector<BlockVector<Number>> : std::true_type
538{};
539
541
542#endif
Definition: vector.h:110
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
Point< 2 > first
Definition: grid_out.cc:4587
#define DeclException0(Exception0)
Definition: exceptions.h:470
::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:1465
#define AssertIsFinite(number)
Definition: exceptions.h:1721
::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:512
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:521
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:489
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
constexpr int block_size
Definition: cuda_size.h:29
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:2042
@ matrix
Contents is actually a matrix.
static const char V
types::global_dof_index size_type
Definition: cuda_kernels.h:45
std::enable_if< IsBlockVector< VectorType >::value, unsignedint >::type n_blocks(const VectorType &vector)
Definition: operators.h:49
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
std::string compress(const std::string &input)
Definition: utilities.cc:392
void copy(const T *begin, const T *end, U *dest)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:618
void advance(std::tuple< I1, I2 > &t, const unsigned int n)