Reference documentation for deal.II version Git 31af17f30d 2020-12-04 11:18:37 -0500
\(\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
38 namespace TrilinosWrappers
39 {
40  namespace MPI
41  {
42  class BlockVector;
43  }
44 } // namespace TrilinosWrappers
45 # endif
46 #endif
47 
48 
69 template <typename Number>
70 class BlockVector : public BlockVectorBase<Vector<Number>>
71 {
72 public:
77 
81  using BlockType = typename BaseClass::BlockType;
82 
87  using real_type = typename BaseClass::real_type;
88  using pointer = typename BaseClass::pointer;
90  using reference = typename BaseClass::reference;
92  using size_type = typename BaseClass::size_type;
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
138 
143 
144 #endif
145 
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
187  compress(::VectorOperation::values operation =
189 
196  bool
197  has_ghost_elements() const;
198 
203  BlockVector &
204  operator=(const value_type s);
205 
211  operator=(const BlockVector<Number> &v);
212 
218  operator=(BlockVector<Number> && /*v*/) = default; // NOLINT
219 
224  template <class Number2>
227 
232  operator=(const Vector<Number> &V);
233 
234 #ifdef DEAL_II_WITH_TRILINOS
235 
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 
383 template <typename Number>
384 template <typename InputIterator>
385 BlockVector<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  };
403 }
404 
405 
406 
407 template <typename Number>
408 inline BlockVector<Number> &
410 {
411  AssertIsFinite(s);
412 
414  return *this;
415 }
416 
417 
418 
419 template <typename Number>
420 inline BlockVector<Number> &
422 {
423  reinit(v, true);
425  return *this;
426 }
427 
428 
429 
430 template <typename Number>
431 inline BlockVector<Number> &
432 BlockVector<Number>::operator=(const Vector<Number> &v)
433 {
435  return *this;
436 }
437 
438 
439 
440 template <typename Number>
441 template <typename Number2>
442 inline BlockVector<Number> &
444 {
445  reinit(v, true);
447  return *this;
448 }
449 
450 template <typename Number>
451 inline void
453 {
454  for (size_type i = 0; i < this->n_blocks(); ++i)
455  this->components[i].compress(operation);
456 }
457 
458 
459 
460 template <typename Number>
461 inline bool
463 {
464  return false;
465 }
466 
467 
468 
469 template <typename Number>
470 template <class BlockVector2>
471 void
472 BlockVector<Number>::scale(const BlockVector2 &v)
473 {
474  BaseClass::scale(v);
475 }
476 
477 #endif // DOXYGEN
478 
479 
487 template <typename Number>
488 inline void
490 {
491  u.swap(v);
492 }
493 
494 
495 namespace internal
496 {
497  namespace LinearOperatorImplementation
498  {
499  template <typename>
501 
506  template <typename number>
507  class ReinitHelper<BlockVector<number>>
508  {
509  public:
510  template <typename Matrix>
511  static void
512  reinit_range_vector(const Matrix & matrix,
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
521  reinit_domain_vector(const Matrix & matrix,
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 
536 template <typename Number>
537 struct is_serial_vector<BlockVector<Number>> : std::true_type
538 {};
539 
541 
542 #endif
typename BaseClass::real_type real_type
Definition: block_vector.h:87
Contents is actually a matrix.
void compress(::VectorOperation::values operation)
typename BaseClass::BlockType BlockType
Definition: block_vector.h:81
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
types::global_dof_index size_type
constexpr int block_size
Definition: cuda_size.h:29
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
static const char V
void reinit(const std::vector< IndexSet > &parallel_partitioning, const MPI_Comm &communicator=MPI_COMM_WORLD, const bool omit_zeroing_entries=false)
typename BaseClass::const_pointer const_pointer
Definition: block_vector.h:89
void scale(const BlockVector2 &v)
static void reinit_domain_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:521
typename BaseClass::iterator iterator
Definition: block_vector.h:93
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
#define Assert(cond, exc)
Definition: exceptions.h:1466
typename BaseClass::const_reference const_reference
Definition: block_vector.h:91
#define DeclException0(Exception0)
Definition: exceptions.h:470
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:372
void reinit(const unsigned int n_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
std::vector< MPI::Vector > components
typename BaseClass::reference reference
Definition: block_vector.h:90
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
Point< 2 > first
Definition: grid_out.cc:4340
void swap(BlockVector< Number > &v)
BlockVector & operator=(const value_type s)
static void reinit_range_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:512
unsigned int n_blocks() const
void advance(std::tuple< I1, I2 > &t, const unsigned int n)
typename BaseClass::pointer pointer
Definition: block_vector.h:88
typename BlockType::value_type value_type
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:371
typename BlockType::real_type real_type
typename BlockType::const_reference const_reference
typename BaseClass::const_iterator const_iterator
Definition: block_vector.h:94
BlockType & block(const unsigned int i)
BlockVectorBase & operator=(const value_type s)
void copy(const T *begin, const T *end, U *dest)
#define AssertIsFinite(number)
Definition: exceptions.h:1722
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
typename BaseClass::size_type size_type
Definition: block_vector.h:92
typename BlockType::reference reference
typename BaseClass::value_type value_type
Definition: block_vector.h:86