Reference documentation for deal.II version 8.1.0
trilinos_block_vector.h
1 // ---------------------------------------------------------------------
2 // @f$Id: trilinos_block_vector.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2008 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__trilinos_block_vector_h
18 #define __deal2__trilinos_block_vector_h
19 
20 
21 #include <deal.II/base/config.h>
22 
23 #ifdef DEAL_II_WITH_TRILINOS
24 
25 # include <deal.II/lac/trilinos_vector.h>
26 # include <deal.II/lac/trilinos_parallel_block_vector.h>
27 # include <deal.II/lac/block_indices.h>
28 # include <deal.II/lac/block_vector_base.h>
29 # include <deal.II/lac/exceptions.h>
30 
32 
33 // forward declaration
34 template <typename Number> class BlockVector;
35 
40 namespace TrilinosWrappers
41 {
42  // forward declaration
43  namespace MPI
44  {
45  class BlockVector;
46  }
47  class BlockVector;
48  class BlockSparseMatrix;
49 
50 
70  class BlockVector : public BlockVectorBase<Vector>
71  {
72  public:
78 
84 
89  typedef BaseClass::value_type value_type;
90  typedef BaseClass::pointer pointer;
91  typedef BaseClass::const_pointer const_pointer;
92  typedef BaseClass::reference reference;
93  typedef BaseClass::const_reference const_reference;
94  typedef BaseClass::size_type size_type;
97 
102  BlockVector ();
103 
113  explicit BlockVector (const std::vector<Epetra_Map> &partitioner);
114 
124  explicit BlockVector (const std::vector<IndexSet> &partitioner,
125  const MPI_Comm &communicator = MPI_COMM_WORLD);
126 
134  BlockVector (const MPI::BlockVector &V);
135 
142  BlockVector (const BlockVector &V);
143 
154  explicit BlockVector (const size_type num_blocks);
155 
164  explicit BlockVector (const std::vector<size_type> &N);
165 
184  template <typename InputIterator>
185  BlockVector (const std::vector<size_type> &n,
186  const InputIterator first,
187  const InputIterator end);
188 
192  ~BlockVector ();
193 
203  void compress (const Epetra_CombineMode last_action) DEAL_II_DEPRECATED;
204 
209 
216  BlockVector &
217  operator = (const value_type s);
218 
224  BlockVector &
225  operator = (const MPI::BlockVector &V);
226 
231  BlockVector &
232  operator = (const BlockVector &V);
233 
254  template <typename Number>
255  BlockVector &
256  operator = (const ::BlockVector<Number> &V);
257 
278  void reinit (const std::vector<Epetra_Map> &partitioning,
279  const bool fast = false);
280 
300  void reinit (const std::vector<IndexSet> &partitioning,
301  const MPI_Comm &communicator = MPI_COMM_WORLD,
302  const bool fast = false);
303 
316  void reinit (const std::vector<size_type> &N,
317  const bool fast=false);
318 
324  void reinit (const MPI::BlockVector &V);
325 
352  void reinit (const BlockVector &V,
353  const bool fast = false);
354 
366  void reinit (const size_type num_blocks);
367 
398  void swap (BlockVector &v);
399 
403  void print (std::ostream &out,
404  const unsigned int precision = 3,
405  const bool scientific = true,
406  const bool across = true) const;
407 
411  DeclException0 (ExcIteratorRangeDoesNotMatchVectorSize);
412 
416  DeclException0 (ExcNonMatchingBlockVectors);
417 
421  DeclException2 (ExcNonLocalizedMap,
422  int, int,
423  << "For the generation of a localized vector the map has "
424  << "to assign all elements to all vectors! "
425  << "local_size = global_size is a necessary condition, but"
426  << arg1 << " != " << arg2 << " was given!");
427 
428  };
429 
430 
431 
432  /*----------------------- Inline functions ----------------------------------*/
433 
434 
435 
436  inline
438  {}
439 
440 
441 
442  inline
443  BlockVector::BlockVector (const std::vector<Epetra_Map> &partitioning)
444  {
445  reinit (partitioning);
446  }
447 
448 
449 
450  inline
451  BlockVector::BlockVector (const std::vector<IndexSet> &partitioning,
452  const MPI_Comm &communicator)
453  {
454  reinit (partitioning, communicator);
455  }
456 
457 
458 
459  inline
460  BlockVector::BlockVector (const std::vector<size_type> &N)
461  {
462  reinit (N);
463  }
464 
465 
466 
467  template <typename InputIterator>
468  BlockVector::BlockVector (const std::vector<size_type> &n,
469  const InputIterator first,
470  const InputIterator end)
471  {
472  // first set sizes of blocks, but
473  // don't initialize them as we will
474  // copy elements soon
475  reinit (n, true);
476  InputIterator start = first;
477  for (size_type b=0; b<n.size(); ++b)
478  {
479  InputIterator end = start;
480  std::advance (end, static_cast<size_type>(n[b]));
481 
482  for (size_type i=0; i<n[b]; ++i, ++start)
483  this->block(b)(i) = *start;
484  }
485  Assert (start == end, ExcIteratorRangeDoesNotMatchVectorSize());
486  }
487 
488 
489 
490  inline
491  BlockVector::BlockVector (const size_type num_blocks)
492  {
493  reinit (num_blocks);
494  }
495 
496 
497 
498  inline
500  {}
501 
502 
503 
504  inline
506  {
507  reinit (v);
508  }
509 
510 
511 
512  inline
514  :
516  {
517  this->components.resize (v.n_blocks());
518  this->block_indices = v.block_indices;
519 
520  for (size_type i=0; i<this->n_blocks(); ++i)
521  this->components[i] = v.components[i];
522  }
523 
524 
525  inline
526  void
527  BlockVector::compress (const Epetra_CombineMode last_action)
528  {
529  if (last_action == Add)
530  this->compress(::VectorOperation::add);
531  else if (last_action == Insert)
532  this->compress(::VectorOperation::insert);
533  else
534  AssertThrow(false, ExcNotImplemented());
535  }
536 
537 
538  inline
539  void
541  {
542  Assert (n_blocks() == v.n_blocks(),
544 
545  for (unsigned int row=0; row<n_blocks(); ++row)
546  block(row).swap (v.block(row));
547  }
548 
549 
550  template <typename Number>
551  BlockVector &
552  BlockVector::operator = (const ::BlockVector<Number> &v)
553  {
554  if (n_blocks() != v.n_blocks())
555  {
556  std::vector<size_type> block_sizes (v.n_blocks(), 0);
557  block_indices.reinit (block_sizes);
558  if (components.size() != n_blocks())
559  components.resize(n_blocks());
560  }
561 
562  for (size_type i=0; i<this->n_blocks(); ++i)
563  this->components[i] = v.block(i);
564 
565  collect_sizes();
566 
567  return *this;
568  }
569 
570 
579  inline
580  void swap (BlockVector &u,
581  BlockVector &v)
582  {
583  u.swap (v);
584  }
585 
586 }
587 
590 DEAL_II_NAMESPACE_CLOSE
591 
592 #endif // DEAL_II_WITH_TRILINOS
593 
594 #endif
unsigned int n_blocks() const
#define AssertThrow(cond, exc)
Definition: exceptions.h:362
BlockVector & operator=(const value_type s)
void reinit(const std::vector< Epetra_Map > &partitioning, const bool fast=false)
DeclException0(ExcIteratorRangeDoesNotMatchVectorSize)
#define Assert(cond, exc)
Definition: exceptions.h:299
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
BlockCompressedSparsityPattern CompressedBlockSparsityPattern DEAL_II_DEPRECATED
std::vector< Vector > components
DeclException2(ExcNonLocalizedMap, int, int,<< "For the generation of a localized vector the map has "<< "to assign all elements to all vectors! "<< "local_size = global_size is a necessary condition, but"<< arg1<< " != "<< arg2<< " was given!")
virtual void swap(Vector< Number > &v)
void swap(BlockVector &u, BlockVector &v)
void compress() DEAL_II_DEPRECATED
::ExceptionBase & ExcNotImplemented()
::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
BlockVectorBase< Vector > BaseClass
BlockType & block(const unsigned int i)