Reference documentation for deal.II version Git 840703ecf3 2019-10-14 17:15:20 -0400
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
block_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2018 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 
22 #include <deal.II/base/exceptions.h>
23 
24 #include <deal.II/lac/block_indices.h>
25 #include <deal.II/lac/block_vector_base.h>
26 #include <deal.II/lac/vector_operation.h>
27 #include <deal.II/lac/vector_type_traits.h>
28 
29 #include <cstdio>
30 #include <vector>
31 
32 DEAL_II_NAMESPACE_OPEN
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 
70 template <typename Number>
71 class BlockVector : public BlockVectorBase<Vector<Number>>
72 {
73 public:
78 
82  using BlockType = typename BaseClass::BlockType;
83 
87  using value_type = typename BaseClass::value_type;
88  using real_type = typename BaseClass::real_type;
89  using pointer = typename BaseClass::pointer;
90  using const_pointer = typename BaseClass::const_pointer;
91  using reference = typename BaseClass::reference;
92  using const_reference = typename BaseClass::const_reference;
93  using size_type = typename BaseClass::size_type;
94  using iterator = typename BaseClass::iterator;
95  using const_iterator = typename BaseClass::const_iterator;
96 
107  explicit BlockVector(const unsigned int n_blocks = 0,
108  const size_type block_size = 0);
109 
115 
116 
121  BlockVector(BlockVector<Number> && /*v*/) noexcept = default;
122 
135  template <typename OtherNumber>
136  explicit BlockVector(const BlockVector<OtherNumber> &v);
137 
138 #ifdef DEAL_II_WITH_TRILINOS
139 
144 
145 #endif
146 
150  BlockVector(const std::vector<size_type> &block_sizes);
151 
157 
167  template <typename InputIterator>
168  BlockVector(const std::vector<size_type> &block_sizes,
169  const InputIterator first,
170  const InputIterator end);
171 
175  ~BlockVector() override = default;
176 
187  void
188  compress(::VectorOperation::values operation =
190 
197  bool
198  has_ghost_elements() const;
199 
204  BlockVector &
205  operator=(const value_type s);
206 
212  operator=(const BlockVector<Number> &v);
213 
219  operator=(BlockVector<Number> && /*v*/) = default; // NOLINT
220 
225  template <class Number2>
228 
233  operator=(const Vector<Number> &V);
234 
235 #ifdef DEAL_II_WITH_TRILINOS
236 
242 #endif
243 
256  void
257  reinit(const unsigned int n_blocks,
258  const size_type block_size = 0,
259  const bool omit_zeroing_entries = false);
260 
277  void
278  reinit(const std::vector<size_type> &block_sizes,
279  const bool omit_zeroing_entries = false);
280 
290  void
292  const bool omit_zeroing_entries = false);
293 
307  template <typename Number2>
308  void
309  reinit(const BlockVector<Number2> &V,
310  const bool omit_zeroing_entries = false);
311 
316  template <class BlockVector2>
317  void
318  scale(const BlockVector2 &v);
319 
331  void
333 
337  void
338  print(std::ostream & out,
339  const unsigned int precision = 3,
340  const bool scientific = true,
341  const bool across = true) const;
342 
348  void
349  block_write(std::ostream &out) const;
350 
362  void
363  block_read(std::istream &in);
364 
375 };
376 
379 #ifndef DOXYGEN
380 /*----------------------- Inline functions ----------------------------------*/
381 
382 
383 
384 template <typename Number>
385 template <typename InputIterator>
386 BlockVector<Number>::BlockVector(const std::vector<size_type> &block_sizes,
387  const InputIterator first,
388  const InputIterator end)
389 {
390  // first set sizes of blocks, but
391  // don't initialize them as we will
392  // copy elements soon
393  (void)end;
394  reinit(block_sizes, true);
395  InputIterator start = first;
396  for (size_type b = 0; b < block_sizes.size(); ++b)
397  {
398  InputIterator end = start;
399  std::advance(end, static_cast<signed int>(block_sizes[b]));
400  std::copy(start, end, this->block(b).begin());
401  start = end;
402  };
404 }
405 
406 
407 
408 template <typename Number>
409 inline BlockVector<Number> &
411 {
412  AssertIsFinite(s);
413 
415  return *this;
416 }
417 
418 
419 
420 template <typename Number>
421 inline BlockVector<Number> &
423 {
424  reinit(v, true);
426  return *this;
427 }
428 
429 
430 
431 template <typename Number>
432 inline BlockVector<Number> &
433 BlockVector<Number>::operator=(const Vector<Number> &v)
434 {
436  return *this;
437 }
438 
439 
440 
441 template <typename Number>
442 template <typename Number2>
443 inline BlockVector<Number> &
445 {
446  reinit(v, true);
448  return *this;
449 }
450 
451 template <typename Number>
452 inline void
454 {
455  for (size_type i = 0; i < this->n_blocks(); ++i)
456  this->components[i].compress(operation);
457 }
458 
459 
460 
461 template <typename Number>
462 inline bool
464 {
465  return false;
466 }
467 
468 
469 
470 template <typename Number>
471 template <class BlockVector2>
472 void
473 BlockVector<Number>::scale(const BlockVector2 &v)
474 {
475  BaseClass::scale(v);
476 }
477 
478 #endif // DOXYGEN
479 
480 
489 template <typename Number>
490 inline void
492 {
493  u.swap(v);
494 }
495 
496 
497 namespace internal
498 {
499  namespace LinearOperatorImplementation
500  {
501  template <typename>
503 
508  template <typename number>
509  class ReinitHelper<BlockVector<number>>
510  {
511  public:
512  template <typename Matrix>
513  static void
514  reinit_range_vector(const Matrix & matrix,
516  bool omit_zeroing_entries)
517  {
518  v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
519  }
520 
521  template <typename Matrix>
522  static void
523  reinit_domain_vector(const Matrix & matrix,
525  bool omit_zeroing_entries)
526  {
527  v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
528  }
529  };
530 
531  } // namespace LinearOperatorImplementation
532 } /* namespace internal */
533 
534 
540 template <typename Number>
541 struct is_serial_vector<BlockVector<Number>> : std::true_type
542 {};
543 
544 DEAL_II_NAMESPACE_CLOSE
545 
546 #endif
void compress(::VectorOperation::values operation)
typename BaseClass::BlockType BlockType
Definition: block_vector.h:82
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
void reinit(const std::vector< IndexSet > &parallel_partitioning, const MPI_Comm &communicator=MPI_COMM_WORLD, const bool omit_zeroing_entries=false)
void swap(BlockVector< Number > &u, BlockVector< Number > &v)
Definition: block_vector.h:491
void scale(const BlockVector2 &v)
#define Assert(cond, exc)
Definition: exceptions.h:1407
#define DeclException0(Exception0)
Definition: exceptions.h:473
void reinit(const unsigned int n_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
std::vector< MPI::Vector > components
void swap(BlockVector< Number > &v)
BlockVector & operator=(const value_type s)
unsigned int n_blocks() const
typename BlockType::real_type real_type
BlockType & block(const unsigned int i)
BlockVectorBase & operator=(const value_type s)
#define AssertIsFinite(number)
Definition: exceptions.h:1669
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
typename BaseClass::value_type value_type
Definition: block_vector.h:87