Reference documentation for deal.II version 9.2.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\}}\)
trilinos_parallel_block_vector.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2019 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_trilinos_parallel_block_vector_h
17 #define dealii_trilinos_parallel_block_vector_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #ifdef DEAL_II_WITH_TRILINOS
23 
26 # include <deal.II/lac/exceptions.h>
28 
29 # include <functional>
30 
32 
33 // forward declaration
34 # ifndef DOXYGEN
35 template <typename Number>
36 class BlockVectorBase;
37 
38 namespace TrilinosWrappers
39 {
40  // forward declaration
41  namespace MPI
42  {
43  class BlockVector;
44  }
45  class BlockSparseMatrix;
46 } // namespace TrilinosWrappers
47 # endif
48 
53 namespace TrilinosWrappers
54 {
55  namespace MPI
56  {
75  class BlockVector : public ::BlockVectorBase<MPI::Vector>
76  {
77  public:
82 
87 
99 
103  BlockVector() = default;
104 
111  explicit BlockVector(const std::vector<IndexSet> &parallel_partitioning,
112  const MPI_Comm &communicator = MPI_COMM_WORLD);
113 
119  BlockVector(const std::vector<IndexSet> &parallel_partitioning,
120  const std::vector<IndexSet> &ghost_values,
121  const MPI_Comm & communicator,
122  const bool vector_writable = false);
123 
128  BlockVector(const BlockVector &v);
129 
134  BlockVector(BlockVector &&v) noexcept;
135 
141  explicit BlockVector(const size_type num_blocks);
142 
146  ~BlockVector() override = default;
147 
152  BlockVector &
153  operator=(const value_type s);
154 
158  BlockVector &
159  operator=(const BlockVector &v);
160 
165  BlockVector &
166  operator=(BlockVector &&v) noexcept;
167 
178  template <typename Number>
179  BlockVector &
180  operator=(const ::BlockVector<Number> &v);
181 
190  void
191  reinit(const std::vector<IndexSet> &parallel_partitioning,
192  const MPI_Comm & communicator = MPI_COMM_WORLD,
193  const bool omit_zeroing_entries = false);
194 
212  void
213  reinit(const std::vector<IndexSet> &partitioning,
214  const std::vector<IndexSet> &ghost_values,
215  const MPI_Comm & communicator = MPI_COMM_WORLD,
216  const bool vector_writable = false);
217 
218 
233  void
234  reinit(const BlockVector &V, const bool omit_zeroing_entries = false);
235 
242  void
243  reinit(const size_type num_blocks);
244 
262  void
264  const BlockVector & v);
265 
272  bool
273  has_ghost_elements() const;
274 
292  void
293  swap(BlockVector &v);
294 
298  void
299  print(std::ostream & out,
300  const unsigned int precision = 3,
301  const bool scientific = true,
302  const bool across = true) const;
303 
308 
313  };
314 
315 
316 
317  /*-------------------------- Inline functions ---------------------------*/
319  const std::vector<IndexSet> &parallel_partitioning,
320  const MPI_Comm & communicator)
321  {
322  reinit(parallel_partitioning, communicator, false);
323  }
324 
325 
326 
328  const std::vector<IndexSet> &parallel_partitioning,
329  const std::vector<IndexSet> &ghost_values,
330  const MPI_Comm & communicator,
331  const bool vector_writable)
332  {
333  reinit(parallel_partitioning,
334  ghost_values,
335  communicator,
336  vector_writable);
337  }
338 
339 
340 
341  inline BlockVector::BlockVector(const size_type num_blocks)
342  {
343  reinit(num_blocks);
344  }
345 
346 
347 
349  : ::BlockVectorBase<MPI::Vector>()
350  {
351  this->components.resize(v.n_blocks());
352  this->block_indices = v.block_indices;
353 
354  for (size_type i = 0; i < this->n_blocks(); ++i)
355  this->components[i] = v.components[i];
356  }
357 
358 
359 
361  {
362  // initialize a minimal, valid object and swap
363  reinit(0);
364  swap(v);
365  }
366 
367 
368 
369  template <typename Number>
370  BlockVector &
371  BlockVector::operator=(const ::BlockVector<Number> &v)
372  {
373  if (n_blocks() != v.n_blocks())
374  {
375  std::vector<size_type> block_sizes(v.n_blocks(), 0);
376  block_indices.reinit(block_sizes);
377  if (components.size() != n_blocks())
378  components.resize(n_blocks());
379  }
380 
381  for (size_type i = 0; i < this->n_blocks(); ++i)
382  this->components[i] = v.block(i);
383 
384  collect_sizes();
385 
386  return *this;
387  }
388 
389 
390 
391  inline bool
393  {
394  bool ghosted = block(0).has_ghost_elements();
395 # ifdef DEBUG
396  for (unsigned int i = 0; i < this->n_blocks(); ++i)
397  Assert(block(i).has_ghost_elements() == ghosted, ExcInternalError());
398 # endif
399  return ghosted;
400  }
401 
402 
403 
404  inline void
406  {
407  std::swap(this->components, v.components);
408 
410  }
411 
412 
413 
422  inline void
424  {
425  u.swap(v);
426  }
427 
428  } /* namespace MPI */
429 
430 } /* namespace TrilinosWrappers */
431 
435 namespace internal
436 {
437  namespace LinearOperatorImplementation
438  {
439  template <typename>
440  class ReinitHelper;
441 
446  template <>
448  {
449  public:
450  template <typename Matrix>
451  static void
452  reinit_range_vector(const Matrix & matrix,
454  bool omit_zeroing_entries)
455  {
456  v.reinit(matrix.locally_owned_range_indices(),
457  matrix.get_mpi_communicator(),
458  omit_zeroing_entries);
459  }
460 
461  template <typename Matrix>
462  static void
463  reinit_domain_vector(const Matrix & matrix,
465  bool omit_zeroing_entries)
466  {
467  v.reinit(matrix.locally_owned_domain_indices(),
468  matrix.get_mpi_communicator(),
469  omit_zeroing_entries);
470  }
471  };
472 
473  } // namespace LinearOperatorImplementation
474 } /* namespace internal */
475 
476 
482 template <>
484 {};
485 
487 
488 #endif // DEAL_II_WITH_TRILINOS
489 
490 #endif
BlockVectorBase< MPI::Vector >::value_type
typename BlockType::value_type value_type
Definition: block_vector_base.h:468
TrilinosWrappers::MPI::BlockVector::swap
void swap(BlockVector &v)
Definition: trilinos_parallel_block_vector.h:405
TrilinosWrappers::MPI::Vector
Definition: trilinos_vector.h:400
BlockVector
Definition: block_vector.h:71
TrilinosWrappers::MPI::BlockVector::reference
BaseClass::reference reference
Definition: trilinos_parallel_block_vector.h:94
block_vector_base.h
TrilinosWrappers::MPI::BlockVector::has_ghost_elements
bool has_ghost_elements() const
Definition: trilinos_parallel_block_vector.h:392
TrilinosWrappers::MPI::BlockVector::pointer
BaseClass::pointer pointer
Definition: trilinos_parallel_block_vector.h:92
TrilinosWrappers::MPI::BlockVector::const_pointer
BaseClass::const_pointer const_pointer
Definition: trilinos_parallel_block_vector.h:93
LAPACKSupport::V
static const char V
Definition: lapack_support.h:175
TrilinosWrappers
Definition: types.h:161
TrilinosWrappers::MPI::BlockVector::ExcIteratorRangeDoesNotMatchVectorSize
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
block_indices.h
TrilinosWrappers::MPI::BlockVector
Definition: trilinos_parallel_block_vector.h:75
MPI_Comm
exceptions.h
TrilinosWrappers::MPI::BlockVector::value_type
BaseClass::value_type value_type
Definition: trilinos_parallel_block_vector.h:91
BlockVectorBase< MPI::Vector >::reference
typename BlockType::reference reference
Definition: block_vector_base.h:475
BlockVectorBase< MPI::Vector >::const_reference
typename BlockType::const_reference const_reference
Definition: block_vector_base.h:476
TrilinosWrappers::MPI::swap
void swap(BlockVector &u, BlockVector &v)
Definition: trilinos_parallel_block_vector.h:423
BlockVectorBase< MPI::Vector >::collect_sizes
void collect_sizes()
internal::LinearOperatorImplementation::ReinitHelper< TrilinosWrappers::MPI::BlockVector >::reinit_range_vector
static void reinit_range_vector(const Matrix &matrix, TrilinosWrappers::MPI::BlockVector &v, bool omit_zeroing_entries)
Definition: trilinos_parallel_block_vector.h:452
LinearAlgebraDealII::BlockVector
BlockVector< double > BlockVector
Definition: generic_linear_algebra.h:48
is_serial_vector
Definition: vector_type_traits.h:49
TrilinosWrappers::MPI::BlockVector::import_nonlocal_data_for_fe
void import_nonlocal_data_for_fe(const TrilinosWrappers::BlockSparseMatrix &m, const BlockVector &v)
Definition: trilinos_block_vector.cc:154
BlockVectorBase< MPI::Vector >::components
std::vector< MPI::Vector > components
Definition: block_vector_base.h:956
internal::reinit
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:621
internal::LinearOperatorImplementation::ReinitHelper< TrilinosWrappers::MPI::BlockVector >::reinit_domain_vector
static void reinit_domain_vector(const Matrix &matrix, TrilinosWrappers::MPI::BlockVector &v, bool omit_zeroing_entries)
Definition: trilinos_parallel_block_vector.h:463
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
BlockVectorBase::n_blocks
unsigned int n_blocks() const
BlockVectorBase
Definition: block_vector_base.h:450
LAPACKSupport::matrix
@ matrix
Contents is actually a matrix.
Definition: lapack_support.h:60
BlockVectorBase< MPI::Vector >::BlockType
MPI::Vector BlockType
Definition: block_vector_base.h:456
internal::BlockVectorIterators::Iterator
Definition: block_vector_base.h:139
TrilinosWrappers::MPI::BlockVector::ExcNonMatchingBlockVectors
static ::ExceptionBase & ExcNonMatchingBlockVectors()
BlockVectorBase< MPI::Vector >::const_pointer
const value_type * const_pointer
Definition: block_vector_base.h:470
BlockVectorBase< MPI::Vector >::size_type
types::global_dof_index size_type
Definition: block_vector_base.h:477
TrilinosWrappers::MPI::BlockVector::print
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
Definition: trilinos_block_vector.cc:178
BlockVectorBase< MPI::Vector >::pointer
value_type * pointer
Definition: block_vector_base.h:469
BlockVectorBase< MPI::Vector >::const_iterator
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
Definition: block_vector_base.h:474
BlockVectorBase< MPI::Vector >::block_indices
BlockIndices block_indices
Definition: block_vector_base.h:962
TrilinosWrappers::MPI::BlockVector::size_type
BaseClass::size_type size_type
Definition: trilinos_parallel_block_vector.h:96
StandardExceptions::ExcInternalError
static ::ExceptionBase & ExcInternalError()
TrilinosWrappers::MPI::BlockVector::BlockVector
BlockVector()=default
BlockVectorBase< MPI::Vector >::iterator
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
Definition: block_vector_base.h:472
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
BlockIndices::reinit
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
Definition: block_indices.h:260
TrilinosWrappers::MPI::BlockVector::reinit
void reinit(const std::vector< IndexSet > &parallel_partitioning, const MPI_Comm &communicator=MPI_COMM_WORLD, const bool omit_zeroing_entries=false)
Definition: trilinos_block_vector.cc:70
DeclException0
#define DeclException0(Exception0)
Definition: exceptions.h:473
TrilinosWrappers::BlockSparseMatrix
Definition: trilinos_block_sparse_matrix.h:72
TrilinosWrappers::MPI::BlockVector::BlockType
BaseClass::BlockType BlockType
Definition: trilinos_parallel_block_vector.h:86
config.h
TrilinosWrappers::MPI::BlockVector::~BlockVector
~BlockVector() override=default
internal
Definition: aligned_vector.h:369
TrilinosWrappers::MPI::BlockVector::const_reference
BaseClass::const_reference const_reference
Definition: trilinos_parallel_block_vector.h:95
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
BlockVectorBase< MPI::Vector >::block
BlockType & block(const unsigned int i)
trilinos_vector.h
TrilinosWrappers::MPI::BlockVector::operator=
BlockVector & operator=(const value_type s)
Definition: trilinos_block_vector.cc:31
internal::LinearOperatorImplementation::ReinitHelper
Definition: block_vector.h:502
BlockSparseMatrix
Definition: block_sparse_matrix.h:50