Reference documentation for deal.II version 8.1.0
trilinos_block_sparse_matrix.h
1 // ---------------------------------------------------------------------
2 // @f$Id: trilinos_block_sparse_matrix.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_sparse_matrix_h
18 #define __deal2__trilinos_block_sparse_matrix_h
19 
20 
21 #include <deal.II/base/config.h>
22 
23 #ifdef DEAL_II_WITH_TRILINOS
24 
25 # include <deal.II/base/table.h>
26 # include <deal.II/base/template_constraints.h>
27 # include <deal.II/lac/block_matrix_base.h>
28 # include <deal.II/lac/trilinos_sparse_matrix.h>
29 # include <deal.II/lac/trilinos_block_vector.h>
30 # include <deal.II/lac/full_matrix.h>
31 # include <deal.II/lac/exceptions.h>
32 
33 # include <cmath>
34 
35 # define TrilinosScalar double
36 
38 
39 // forward declarations
44 template <typename number> class BlockSparseMatrix;
45 
46 
47 namespace TrilinosWrappers
48 {
49 
76  class BlockSparseMatrix : public BlockMatrixBase<SparseMatrix>
77  {
78  public:
84 
90 
96  typedef BaseClass::pointer pointer;
97  typedef BaseClass::const_pointer const_pointer;
98  typedef BaseClass::reference reference;
99  typedef BaseClass::const_reference const_reference;
100  typedef BaseClass::size_type size_type;
103 
126 
131 
139 
156  operator = (const double d);
157 
184  void reinit (const size_type n_block_rows,
185  const size_type n_block_columns);
186 
195  template <typename BlockSparsityType>
196  void reinit (const std::vector<Epetra_Map> &input_maps,
197  const BlockSparsityType &block_sparsity_pattern);
198 
207  template <typename BlockSparsityType>
208  void reinit (const std::vector<IndexSet> &input_maps,
209  const BlockSparsityType &block_sparsity_pattern,
210  const MPI_Comm &communicator = MPI_COMM_WORLD);
211 
219  template <typename BlockSparsityType>
220  void reinit (const BlockSparsityType &block_sparsity_pattern);
221 
233  void reinit (const std::vector<Epetra_Map> &input_maps,
234  const ::BlockSparseMatrix<double> &deal_ii_sparse_matrix,
235  const double drop_tolerance=1e-13);
236 
252  void reinit (const ::BlockSparseMatrix<double> &deal_ii_sparse_matrix,
253  const double drop_tolerance=1e-13);
254 
268  bool is_compressed () const;
269 
291  void collect_sizes ();
292 
298  size_type n_nonzero_elements () const;
299 
306  template <typename VectorType1, typename VectorType2>
307  void vmult (VectorType1 &dst,
308  const VectorType2 &src) const;
309 
315  template <typename VectorType1, typename VectorType2>
316  void Tvmult (VectorType1 &dst,
317  const VectorType2 &src) const;
318 
344  TrilinosScalar residual (MPI::BlockVector &dst,
345  const MPI::BlockVector &x,
346  const MPI::BlockVector &b) const;
347 
378  TrilinosScalar residual (BlockVector &dst,
379  const BlockVector &x,
380  const BlockVector &b) const;
381 
395  TrilinosScalar residual (MPI::BlockVector &dst,
396  const MPI::Vector &x,
397  const MPI::BlockVector &b) const;
398 
412  TrilinosScalar residual (BlockVector &dst,
413  const Vector &x,
414  const BlockVector &b) const;
415 
429  TrilinosScalar residual (MPI::Vector &dst,
430  const MPI::BlockVector &x,
431  const MPI::Vector &b) const;
432 
446  TrilinosScalar residual (Vector &dst,
447  const BlockVector &x,
448  const Vector &b) const;
449 
463  TrilinosScalar residual (VectorBase &dst,
464  const VectorBase &x,
465  const VectorBase &b) const;
466 
473 
481  DeclException4 (ExcIncompatibleRowNumbers,
482  int, int, int, int,
483  << "The blocks [" << arg1 << ',' << arg2 << "] and ["
484  << arg3 << ',' << arg4 << "] have differing row numbers.");
485 
489  DeclException4 (ExcIncompatibleColNumbers,
490  int, int, int, int,
491  << "The blocks [" << arg1 << ',' << arg2 << "] and ["
492  << arg3 << ',' << arg4 << "] have differing column numbers.");
494 
495  private:
499  template <typename VectorType1, typename VectorType2>
500  void vmult (VectorType1 &dst,
501  const VectorType2 &src,
502  const bool transpose,
503  const ::internal::bool2type<true>,
504  const ::internal::bool2type<true>) const;
505 
510  template <typename VectorType1, typename VectorType2>
511  void vmult (VectorType1 &dst,
512  const VectorType2 &src,
513  const bool transpose,
514  const ::internal::bool2type<false>,
515  const ::internal::bool2type<true>) const;
516 
521  template <typename VectorType1, typename VectorType2>
522  void vmult (VectorType1 &dst,
523  const VectorType2 &src,
524  const bool transpose,
525  const ::internal::bool2type<true>,
526  const ::internal::bool2type<false>) const;
527 
533  template <typename VectorType1, typename VectorType2>
534  void vmult (VectorType1 &dst,
535  const VectorType2 &src,
536  const bool transpose,
537  const ::internal::bool2type<false>,
538  const ::internal::bool2type<false>) const;
539  };
540 
541 
542 
545 // ------------- inline and template functions -----------------
546 
547 
548 
549  inline
552  {
554 
555  for (size_type r=0; r<this->n_block_rows(); ++r)
556  for (size_type c=0; c<this->n_block_cols(); ++c)
557  this->block(r,c) = d;
558 
559  return *this;
560  }
561 
562 
563 
564  inline
565  bool
567  {
568  bool compressed = true;
569  for (size_type row=0; row<n_block_rows(); ++row)
570  for (size_type col=0; col<n_block_cols(); ++col)
571  if (block(row, col).is_compressed() == false)
572  {
573  compressed = false;
574  break;
575  }
576 
577  return compressed;
578  }
579 
580 
581 
582  template <typename VectorType1, typename VectorType2>
583  inline
584  void
585  BlockSparseMatrix::vmult (VectorType1 &dst,
586  const VectorType2 &src) const
587  {
588  vmult(dst, src, false,
591  }
592 
593 
594 
595  template <typename VectorType1, typename VectorType2>
596  inline
597  void
598  BlockSparseMatrix::Tvmult (VectorType1 &dst,
599  const VectorType2 &src) const
600  {
601  vmult(dst, src, true,
604  }
605 
606 
607 
608  template <typename VectorType1, typename VectorType2>
609  inline
610  void
611  BlockSparseMatrix::vmult (VectorType1 &dst,
612  const VectorType2 &src,
613  const bool transpose,
616  {
617  if (transpose == true)
619  else
620  BaseClass::vmult_block_block (dst, src);
621  }
622 
623 
624 
625 
626  template <typename VectorType1, typename VectorType2>
627  inline
628  void
629  BlockSparseMatrix::vmult (VectorType1 &dst,
630  const VectorType2 &src,
631  const bool transpose,
634  {
635  if (transpose == true)
637  else
639  }
640 
641 
642 
643  template <typename VectorType1, typename VectorType2>
644  inline
645  void
646  BlockSparseMatrix::vmult (VectorType1 &dst,
647  const VectorType2 &src,
648  const bool transpose,
651  {
652  if (transpose == true)
654  else
656  }
657 
658 
659 
660  template <typename VectorType1, typename VectorType2>
661  inline
662  void
663  BlockSparseMatrix::vmult (VectorType1 &dst,
664  const VectorType2 &src,
665  const bool transpose,
668  {
669  if (transpose == true)
671  else
673  }
674 
675 }
676 
677 DEAL_II_NAMESPACE_CLOSE
678 
679 #endif // DEAL_II_WITH_TRILINOS
680 
681 #endif // __deal2__trilinos_block_sparse_matrix_h
void Tvmult_nonblock_nonblock(VectorType &dst, const VectorType &src) const
void vmult_block_block(BlockVectorType &dst, const BlockVectorType &src) const
void vmult_nonblock_nonblock(VectorType &dst, const VectorType &src) const
BlockMatrixBase< SparseMatrix > BaseClass
void Tvmult_block_nonblock(BlockVectorType &dst, const VectorType &src) const
unsigned int n_block_cols() const
void vmult_block_nonblock(BlockVectorType &dst, const VectorType &src) const
void vmult(VectorType1 &dst, const VectorType2 &src) const
size_type n_nonzero_elements() const
void vmult_nonblock_block(VectorType &dst, const BlockVectorType &src) const
TrilinosScalar residual(MPI::BlockVector &dst, const MPI::BlockVector &x, const MPI::BlockVector &b) const
#define Assert(cond, exc)
Definition: exceptions.h:299
void reinit(const size_type n_block_rows, const size_type n_block_columns)
BlockType::value_type value_type
BlockSparseMatrix & operator=(const BlockSparseMatrix &)
DeclException4(ExcIncompatibleRowNumbers, int, int, int, int,<< "The blocks ["<< arg1<< ','<< arg2<< "] and ["<< arg3<< ','<< arg4<< "] have differing row numbers.")
void Tvmult_nonblock_block(VectorType &dst, const BlockVectorType &src) const
void Tvmult_block_block(BlockVectorType &dst, const BlockVectorType &src) const
BlockType & block(const unsigned int row, const unsigned int column)
::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
void Tvmult(VectorType1 &dst, const VectorType2 &src) const
unsigned int n_block_rows() const