Reference documentation for deal.II version Git 3e516b7449 2019-12-12 13:14:56 -0500
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
trilinos_parallel_block_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 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_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 
24 # include <deal.II/lac/block_indices.h>
25 # include <deal.II/lac/block_vector_base.h>
26 # include <deal.II/lac/exceptions.h>
27 # include <deal.II/lac/trilinos_vector.h>
28 
29 # include <functional>
30 
31 DEAL_II_NAMESPACE_OPEN
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 
91  using value_type = BaseClass::value_type;
92  using pointer = BaseClass::pointer;
93  using const_pointer = BaseClass::const_pointer;
94  using reference = BaseClass::reference;
95  using const_reference = BaseClass::const_reference;
96  using size_type = BaseClass::size_type;
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
263  import_nonlocal_data_for_fe(const TrilinosWrappers::BlockSparseMatrix &m,
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 
307  DeclException0(ExcIteratorRangeDoesNotMatchVectorSize);
308 
312  DeclException0(ExcNonMatchingBlockVectors);
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 
486 DEAL_II_NAMESPACE_CLOSE
487 
488 #endif // DEAL_II_WITH_TRILINOS
489 
490 #endif
void reinit(const std::vector< IndexSet > &parallel_partitioning, const MPI_Comm &communicator=MPI_COMM_WORLD, const bool omit_zeroing_entries=false)
void swap(BlockVector &u, BlockVector &v)
#define Assert(cond, exc)
Definition: exceptions.h:1411
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
#define DeclException0(Exception0)
Definition: exceptions.h:473
std::vector< MPI::Vector > components
void swap(Vector< Number > &u, Vector< Number > &v)
Definition: vector.h:1376
BlockVector & operator=(const value_type s)
unsigned int n_blocks() const
LinearAlgebra::distributed::BlockVector< Number > BlockVector
BlockType & block(const unsigned int i)
static ::ExceptionBase & ExcInternalError()