Reference documentation for deal.II version 8.4.2
trilinos_block_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2016 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__trilinos_block_vector_h
17 #define dealii__trilinos_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/trilinos_vector.h>
25 # include <deal.II/lac/trilinos_parallel_block_vector.h>
26 # include <deal.II/lac/block_indices.h>
27 # include <deal.II/lac/block_vector_base.h>
28 # include <deal.II/lac/exceptions.h>
29 
30 DEAL_II_NAMESPACE_OPEN
31 
32 // forward declaration
33 template <typename Number> class BlockVector;
34 
39 namespace TrilinosWrappers
40 {
41  // forward declaration
42  namespace MPI
43  {
44  class BlockVector;
45  }
46  class BlockVector;
47  class BlockSparseMatrix;
48 
49 
69  class BlockVector : public BlockVectorBase<Vector>
70  {
71  public:
76 
81 
85  typedef BaseClass::value_type value_type;
86  typedef BaseClass::pointer pointer;
87  typedef BaseClass::const_pointer const_pointer;
88  typedef BaseClass::reference reference;
89  typedef BaseClass::const_reference const_reference;
90  typedef BaseClass::size_type size_type;
93 
97  BlockVector ();
98 
104  explicit BlockVector (const std::vector<Epetra_Map> &partitioner) DEAL_II_DEPRECATED;
105 
111  explicit BlockVector (const std::vector<IndexSet> &partitioner,
112  const MPI_Comm &communicator = MPI_COMM_WORLD) DEAL_II_DEPRECATED;
113 
118  BlockVector (const MPI::BlockVector &V) DEAL_II_DEPRECATED;
119 
124  BlockVector (const BlockVector &V) DEAL_II_DEPRECATED;
125 
131  explicit BlockVector (const size_type num_blocks) DEAL_II_DEPRECATED;
132 
139  explicit BlockVector (const std::vector<size_type> &N) DEAL_II_DEPRECATED;
140 
149  template <typename InputIterator>
150  BlockVector (const std::vector<size_type> &n,
151  const InputIterator first,
152  const InputIterator end) DEAL_II_DEPRECATED;
153 
157  ~BlockVector ();
158 
163  BlockVector &
164  operator = (const value_type s);
165 
169  BlockVector &
170  operator = (const MPI::BlockVector &V);
171 
175  BlockVector &
176  operator = (const BlockVector &V);
177 
188  template <typename Number>
189  BlockVector &
190  operator = (const ::BlockVector<Number> &V);
191 
204  void reinit (const std::vector<Epetra_Map> &partitioning,
205  const bool omit_zeroing_entries = false);
206 
218  void reinit (const std::vector<IndexSet> &partitioning,
219  const MPI_Comm &communicator = MPI_COMM_WORLD,
220  const bool omit_zeroing_entries = false);
221 
230  void reinit (const std::vector<size_type> &N,
231  const bool omit_zeroing_entries=false);
232 
237  void reinit (const MPI::BlockVector &V);
238 
253  void reinit (const BlockVector &V,
254  const bool omit_zeroing_entries = false);
255 
262  void reinit (const size_type num_blocks);
263 
279  void swap (BlockVector &v);
280 
284  void print (std::ostream &out,
285  const unsigned int precision = 3,
286  const bool scientific = true,
287  const bool across = true) const;
288 
292  DeclException0 (ExcIteratorRangeDoesNotMatchVectorSize);
293 
297  DeclException0 (ExcNonMatchingBlockVectors);
298 
302  DeclException2 (ExcNonLocalizedMap,
303  int, int,
304  << "For the generation of a localized vector the map has "
305  << "to assign all elements to all vectors! "
306  << "local_size = global_size is a necessary condition, but"
307  << arg1 << " != " << arg2 << " was given!");
308 
309  };
310 
311 
312 
313  /*----------------------- Inline functions ----------------------------------*/
314 
315 
316 
317  inline
319  {}
320 
321 
322 
323  inline
324  BlockVector::BlockVector (const std::vector<Epetra_Map> &partitioning)
325  {
326  reinit (partitioning);
327  }
328 
329 
330 
331  inline
332  BlockVector::BlockVector (const std::vector<IndexSet> &partitioning,
333  const MPI_Comm &communicator)
334  {
335  reinit (partitioning, communicator);
336  }
337 
338 
339 
340  inline
341  BlockVector::BlockVector (const std::vector<size_type> &N)
342  {
343  reinit (N);
344  }
345 
346 
347 
348  template <typename InputIterator>
349  BlockVector::BlockVector (const std::vector<size_type> &n,
350  const InputIterator first,
351  const InputIterator end)
352  {
353  // first set sizes of blocks, but
354  // don't initialize them as we will
355  // copy elements soon
356  (void)end;
357  reinit (n, true);
358  InputIterator start = first;
359  for (size_type b=0; b<n.size(); ++b)
360  {
361  InputIterator end = start;
362  std::advance (end, static_cast<size_type>(n[b]));
363 
364  for (size_type i=0; i<n[b]; ++i, ++start)
365  this->block(b)(i) = *start;
366  }
367  Assert (start == end, ExcIteratorRangeDoesNotMatchVectorSize());
368  }
369 
370 
371 
372  inline
373  BlockVector::BlockVector (const size_type num_blocks)
374  {
375  reinit (num_blocks);
376  }
377 
378 
379 
380  inline
382  {}
383 
384 
385 
386  inline
388  {
389  reinit (v);
390  }
391 
392 
393 
394  inline
396  :
398  {
399  this->components.resize (v.n_blocks());
400  this->block_indices = v.block_indices;
401 
402  for (size_type i=0; i<this->n_blocks(); ++i)
403  this->components[i] = v.components[i];
404  }
405 
406 
407  inline
408  void
410  {
411  Assert (n_blocks() == v.n_blocks(),
412  ExcDimensionMismatch(n_blocks(),v.n_blocks()));
413 
414  for (unsigned int row=0; row<n_blocks(); ++row)
415  block(row).swap (v.block(row));
416  }
417 
418 
419  template <typename Number>
420  BlockVector &
421  BlockVector::operator = (const ::BlockVector<Number> &v)
422  {
423  if (n_blocks() != v.n_blocks())
424  {
425  std::vector<size_type> block_sizes (v.n_blocks(), 0);
426  block_indices.reinit (block_sizes);
427  if (components.size() != n_blocks())
428  components.resize(n_blocks());
429  }
430 
431  for (size_type i=0; i<this->n_blocks(); ++i)
432  this->components[i] = v.block(i);
433 
434  collect_sizes();
435 
436  return *this;
437  }
438 
439 
448  inline
449  void swap (BlockVector &u,
450  BlockVector &v)
451  {
452  u.swap (v);
453  }
454 
455 } /* namespace TrilinosWrappers */
456 
460 namespace internal
461 {
462  namespace LinearOperator
463  {
464  template <typename> class ReinitHelper;
465 
470  template<>
472  {
473  public:
474  template <typename Matrix>
475  static
476  void reinit_range_vector (const Matrix &matrix,
478  bool omit_zeroing_entries)
479  {
480  v.reinit(matrix.range_partitioner(), omit_zeroing_entries);
481  }
482 
483  template <typename Matrix>
484  static
485  void reinit_domain_vector(const Matrix &matrix,
487  bool omit_zeroing_entries)
488  {
489  v.reinit(matrix.domain_partitioner(), omit_zeroing_entries);
490  }
491  };
492 
493  } /* namespace LinearOperator */
494 } /* namespace internal */
495 
496 
497 DEAL_II_NAMESPACE_CLOSE
498 
499 #endif // DEAL_II_WITH_TRILINOS
500 
501 #endif
DeclException2(ExcNoSubscriber, char *, char *,<< "No subscriber with identifier <"<< arg2<< "> subscribes to this object of class "<< arg1<< ". Consequently, it cannot be unsubscribed.")
STL namespace.
void reinit(const std::vector< Epetra_Map > &parallel_partitioning, const bool omit_zeroing_entries=false) DEAL_II_DEPRECATED
#define DEAL_II_DEPRECATED
Definition: config.h:88
#define Assert(cond, exc)
Definition: exceptions.h:294
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
BlockVector & operator=(const value_type s)
std::vector< Vector > components
virtual void swap(Vector< Number > &v)
void swap(BlockVector &u, BlockVector &v)
unsigned int n_blocks() const
void reinit(const std::vector< Epetra_Map > &partitioning, const bool omit_zeroing_entries=false)
BlockVectorBase< Vector > BaseClass
BlockType & block(const unsigned int i)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
DeclException0(ExcIteratorRangeDoesNotMatchVectorSize)