Reference documentation for deal.II version 8.4.2
trilinos_block_sparse_matrix.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2015 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_sparse_matrix_h
17 #define dealii__trilinos_block_sparse_matrix_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #ifdef DEAL_II_WITH_TRILINOS
23 
24 # include <deal.II/base/table.h>
25 # include <deal.II/base/template_constraints.h>
26 # include <deal.II/lac/block_matrix_base.h>
27 # include <deal.II/lac/trilinos_sparse_matrix.h>
28 # include <deal.II/lac/trilinos_block_vector.h>
29 # include <deal.II/lac/full_matrix.h>
30 # include <deal.II/lac/exceptions.h>
31 
32 # include <cmath>
33 
34 # define TrilinosScalar double
35 
36 DEAL_II_NAMESPACE_OPEN
37 
38 // forward declarations
40 template <typename number> class BlockSparseMatrix;
41 
42 
43 namespace TrilinosWrappers
44 {
45 
73  class BlockSparseMatrix : public BlockMatrixBase<SparseMatrix>
74  {
75  public:
80 
85 
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 
110 
115 
122 
133  operator = (const double d);
134 
148  void reinit (const size_type n_block_rows,
149  const size_type n_block_columns);
150 
156  template <typename BlockSparsityPatternType>
157  void reinit (const std::vector<Epetra_Map> &input_maps,
158  const BlockSparsityPatternType &block_sparsity_pattern,
159  const bool exchange_data = false);
160 
166  template <typename BlockSparsityPatternType>
167  void reinit (const std::vector<IndexSet> &input_maps,
168  const BlockSparsityPatternType &block_sparsity_pattern,
169  const MPI_Comm &communicator = MPI_COMM_WORLD,
170  const bool exchange_data = false);
171 
177  template <typename BlockSparsityPatternType>
178  void reinit (const BlockSparsityPatternType &block_sparsity_pattern);
179 
188  void reinit (const std::vector<Epetra_Map> &input_maps,
189  const ::BlockSparseMatrix<double> &deal_ii_sparse_matrix,
190  const double drop_tolerance=1e-13) DEAL_II_DEPRECATED;
191 
199  void reinit (const ::BlockSparseMatrix<double> &deal_ii_sparse_matrix,
200  const double drop_tolerance=1e-13);
201 
209  bool is_compressed () const;
210 
221  void collect_sizes ();
222 
226  size_type n_nonzero_elements () const;
227 
237  std::vector<Epetra_Map> domain_partitioner () const DEAL_II_DEPRECATED;
238 
248  std::vector<Epetra_Map> range_partitioner () const DEAL_II_DEPRECATED;
249 
250 
257  template <typename VectorType1, typename VectorType2>
258  void vmult (VectorType1 &dst,
259  const VectorType2 &src) const;
260 
266  template <typename VectorType1, typename VectorType2>
267  void Tvmult (VectorType1 &dst,
268  const VectorType2 &src) const;
269 
282  TrilinosScalar residual (MPI::BlockVector &dst,
283  const MPI::BlockVector &x,
284  const MPI::BlockVector &b) const;
285 
300  TrilinosScalar residual (BlockVector &dst,
301  const BlockVector &x,
302  const BlockVector &b) const;
303 
311  TrilinosScalar residual (MPI::BlockVector &dst,
312  const MPI::Vector &x,
313  const MPI::BlockVector &b) const;
314 
322  TrilinosScalar residual (BlockVector &dst,
323  const Vector &x,
324  const BlockVector &b) const;
325 
333  TrilinosScalar residual (MPI::Vector &dst,
334  const MPI::BlockVector &x,
335  const MPI::Vector &b) const;
336 
344  TrilinosScalar residual (Vector &dst,
345  const BlockVector &x,
346  const Vector &b) const;
347 
355  TrilinosScalar residual (VectorBase &dst,
356  const VectorBase &x,
357  const VectorBase &b) const;
358 
364 
373  DeclException4 (ExcIncompatibleRowNumbers,
374  int, int, int, int,
375  << "The blocks [" << arg1 << ',' << arg2 << "] and ["
376  << arg3 << ',' << arg4 << "] have differing row numbers.");
377 
381  DeclException4 (ExcIncompatibleColNumbers,
382  int, int, int, int,
383  << "The blocks [" << arg1 << ',' << arg2 << "] and ["
384  << arg3 << ',' << arg4 << "] have differing column numbers.");
386 
387  private:
391  template <typename VectorType1, typename VectorType2>
392  void vmult (VectorType1 &dst,
393  const VectorType2 &src,
394  const bool transpose,
395  const ::internal::bool2type<true>,
396  const ::internal::bool2type<true>) const;
397 
402  template <typename VectorType1, typename VectorType2>
403  void vmult (VectorType1 &dst,
404  const VectorType2 &src,
405  const bool transpose,
406  const ::internal::bool2type<false>,
407  const ::internal::bool2type<true>) const;
408 
413  template <typename VectorType1, typename VectorType2>
414  void vmult (VectorType1 &dst,
415  const VectorType2 &src,
416  const bool transpose,
417  const ::internal::bool2type<true>,
418  const ::internal::bool2type<false>) const;
419 
425  template <typename VectorType1, typename VectorType2>
426  void vmult (VectorType1 &dst,
427  const VectorType2 &src,
428  const bool transpose,
429  const ::internal::bool2type<false>,
430  const ::internal::bool2type<false>) const;
431  };
432 
433 
434 
437 // ------------- inline and template functions -----------------
438 
439 
440 
441  inline
443  BlockSparseMatrix::operator = (const double d)
444  {
445  Assert (d==0, ExcScalarAssignmentOnlyForZeroValue());
446 
447  for (size_type r=0; r<this->n_block_rows(); ++r)
448  for (size_type c=0; c<this->n_block_cols(); ++c)
449  this->block(r,c) = d;
450 
451  return *this;
452  }
453 
454 
455 
456  inline
457  bool
459  {
460  bool compressed = true;
461  for (size_type row=0; row<n_block_rows(); ++row)
462  for (size_type col=0; col<n_block_cols(); ++col)
463  if (block(row, col).is_compressed() == false)
464  {
465  compressed = false;
466  break;
467  }
468 
469  return compressed;
470  }
471 
472 
473 
474  template <typename VectorType1, typename VectorType2>
475  inline
476  void
477  BlockSparseMatrix::vmult (VectorType1 &dst,
478  const VectorType2 &src) const
479  {
480  vmult(dst, src, false,
483  }
484 
485 
486 
487  template <typename VectorType1, typename VectorType2>
488  inline
489  void
490  BlockSparseMatrix::Tvmult (VectorType1 &dst,
491  const VectorType2 &src) const
492  {
493  vmult(dst, src, true,
496  }
497 
498 
499 
500  template <typename VectorType1, typename VectorType2>
501  inline
502  void
503  BlockSparseMatrix::vmult (VectorType1 &dst,
504  const VectorType2 &src,
505  const bool transpose,
508  {
509  if (transpose == true)
511  else
512  BaseClass::vmult_block_block (dst, src);
513  }
514 
515 
516 
517 
518  template <typename VectorType1, typename VectorType2>
519  inline
520  void
521  BlockSparseMatrix::vmult (VectorType1 &dst,
522  const VectorType2 &src,
523  const bool transpose,
526  {
527  if (transpose == true)
529  else
531  }
532 
533 
534 
535  template <typename VectorType1, typename VectorType2>
536  inline
537  void
538  BlockSparseMatrix::vmult (VectorType1 &dst,
539  const VectorType2 &src,
540  const bool transpose,
543  {
544  if (transpose == true)
546  else
548  }
549 
550 
551 
552  template <typename VectorType1, typename VectorType2>
553  inline
554  void
555  BlockSparseMatrix::vmult (VectorType1 &dst,
556  const VectorType2 &src,
557  const bool transpose,
560  {
561  if (transpose == true)
563  else
565  }
566 
567 }
568 
569 DEAL_II_NAMESPACE_CLOSE
570 
571 #endif // DEAL_II_WITH_TRILINOS
572 
573 #endif // dealii__trilinos_block_sparse_matrix_h
void vmult_block_nonblock(BlockVectorType &dst, const VectorType &src) const
BlockMatrixBase< SparseMatrix > BaseClass
void vmult_nonblock_block(VectorType &dst, const BlockVectorType &src) const
STL namespace.
void Tvmult_block_nonblock(BlockVectorType &dst, const VectorType &src) const
void Tvmult_block_block(BlockVectorType &dst, const BlockVectorType &src) const
void Tvmult_nonblock_block(VectorType &dst, const BlockVectorType &src) const
void vmult_block_block(BlockVectorType &dst, const BlockVectorType &src) const
void Tvmult_nonblock_nonblock(VectorType &dst, const VectorType &src) const
BlockSparseMatrix & operator=(const BlockSparseMatrix &)
BlockDynamicSparsityPattern BlockCompressedSparsityPattern DEAL_II_DEPRECATED
unsigned int n_block_cols() const
void vmult(VectorType1 &dst, const VectorType2 &src) const
#define Assert(cond, exc)
Definition: exceptions.h:294
void reinit(const size_type n_block_rows, const size_type n_block_columns)
BlockType::value_type value_type
void Tvmult(VectorType1 &dst, const VectorType2 &src) const
DeclException4(ExcIncompatibleRowNumbers, int, int, int, int,<< "The blocks ["<< arg1<< ','<< arg2<< "] and ["<< arg3<< ','<< arg4<< "] have differing row numbers.")
std::vector< Epetra_Map > range_partitioner() const DEAL_II_DEPRECATED
void vmult_nonblock_nonblock(VectorType &dst, const VectorType &src) const
std::vector< Epetra_Map > domain_partitioner() const DEAL_II_DEPRECATED
BlockType & block(const unsigned int row, const unsigned int column)
unsigned int n_block_rows() const
TrilinosScalar residual(MPI::BlockVector &dst, const MPI::BlockVector &x, const MPI::BlockVector &b) const