include/deal.II/lac/trilinos_block_sparse_matrix.h

00001 //---------------------------------------------------------------------------
00002 //    @f$Id: trilinos_block_sparse_matrix.h 25345 2012-03-31 08:37:04Z bangerth @f$
00003 //
00004 //    Copyright (C) 2008, 2010, 2012 by the deal.II authors
00005 //
00006 //    This file is subject to QPL and may not be  distributed
00007 //    without copyright and license information. Please refer
00008 //    to the file deal.II/doc/license.html for the  text  and
00009 //    further information on this license.
00010 //
00011 //---------------------------------------------------------------------------
00012 #ifndef __deal2__trilinos_block_sparse_matrix_h
00013 #define __deal2__trilinos_block_sparse_matrix_h
00014 
00015 
00016 #include <deal.II/base/config.h>
00017 
00018 #ifdef DEAL_II_USE_TRILINOS
00019 
00020 #  include <deal.II/base/table.h>
00021 #  include <deal.II/lac/block_matrix_base.h>
00022 #  include <deal.II/lac/trilinos_sparse_matrix.h>
00023 #  include <deal.II/lac/trilinos_block_vector.h>
00024 #  include <deal.II/lac/full_matrix.h>
00025 #  include <deal.II/lac/exceptions.h>
00026 
00027 #  include <cmath>
00028 
00029 #  define TrilinosScalar double
00030 
00031 DEAL_II_NAMESPACE_OPEN
00032 
00033                                    // forward declarations
00034 class BlockSparsityPattern;
00035 class BlockCompressedSparsityPattern;
00036 class BlockCompressedSetSparsityPattern;
00037 class BlockCompressedSimpleSparsityPattern;
00038 template <typename number> class BlockSparseMatrix;
00039 
00040 
00041 namespace TrilinosWrappers
00042 {
00043 
00070   class BlockSparseMatrix : public BlockMatrixBase<SparseMatrix>
00071   {
00072     public:
00077       typedef BlockMatrixBase<SparseMatrix> BaseClass;
00078 
00083       typedef BaseClass::BlockType  BlockType;
00084 
00089       typedef BaseClass::value_type      value_type;
00090       typedef BaseClass::pointer         pointer;
00091       typedef BaseClass::const_pointer   const_pointer;
00092       typedef BaseClass::reference       reference;
00093       typedef BaseClass::const_reference const_reference;
00094       typedef BaseClass::size_type       size_type;
00095       typedef BaseClass::iterator        iterator;
00096       typedef BaseClass::const_iterator  const_iterator;
00097 
00119       BlockSparseMatrix ();
00120 
00124       ~BlockSparseMatrix ();
00125 
00131       BlockSparseMatrix &
00132       operator = (const BlockSparseMatrix &);
00133 
00149       BlockSparseMatrix &
00150       operator = (const double d);
00151 
00178       void reinit (const unsigned int n_block_rows,
00179                    const unsigned int n_block_columns);
00180 
00189       template <typename BlockSparsityType>
00190       void reinit (const std::vector<Epetra_Map> &input_maps,
00191                    const BlockSparsityType       &block_sparsity_pattern);
00192 
00201       template <typename BlockSparsityType>
00202       void reinit (const std::vector<IndexSet> &input_maps,
00203                    const BlockSparsityType     &block_sparsity_pattern,
00204                    const MPI_Comm              &communicator = MPI_COMM_WORLD);
00205 
00213       template <typename BlockSparsityType>
00214       void reinit (const BlockSparsityType &block_sparsity_pattern);
00215 
00227       void reinit (const std::vector<Epetra_Map>             &input_maps,
00228                    const ::BlockSparseMatrix<double> &deal_ii_sparse_matrix,
00229                    const double                               drop_tolerance=1e-13);
00230 
00246       void reinit (const ::BlockSparseMatrix<double> &deal_ii_sparse_matrix,
00247                    const double                               drop_tolerance=1e-13);
00248 
00261       void compress ();
00262 
00276       bool is_compressed () const;
00277 
00299       void collect_sizes ();
00300 
00306       unsigned int n_nonzero_elements () const;
00307 
00313       void vmult (MPI::BlockVector       &dst,
00314                   const MPI::BlockVector &src) const;
00315 
00316 
00325       void vmult (BlockVector       &dst,
00326                   const BlockVector &src) const;
00327 
00335       void vmult (MPI::BlockVector  &dst,
00336                   const MPI::Vector &src) const;
00337 
00348       void vmult (BlockVector  &dst,
00349                   const Vector &src) const;
00350 
00358       void vmult (MPI::Vector            &dst,
00359                   const MPI::BlockVector &src) const;
00360 
00371       void vmult (Vector            &dst,
00372                   const BlockVector &src) const;
00373 
00381       void vmult (VectorBase       &dst,
00382                   const VectorBase &src) const;
00383 
00392       void Tvmult (MPI::BlockVector       &dst,
00393                    const MPI::BlockVector &src) const;
00394 
00406       void Tvmult (BlockVector       &dst,
00407                    const BlockVector &src) const;
00408 
00416       void Tvmult (MPI::BlockVector  &dst,
00417                    const MPI::Vector &src) const;
00418 
00429       void Tvmult (BlockVector  &dst,
00430                    const Vector &src) const;
00431 
00439       void Tvmult (MPI::Vector    &dst,
00440                    const MPI::BlockVector &src) const;
00441 
00452       void Tvmult (Vector    &dst,
00453                    const BlockVector &src) const;
00454 
00462       void Tvmult (VectorBase       &dst,
00463                    const VectorBase &src) const;
00464 
00490       TrilinosScalar residual (MPI::BlockVector       &dst,
00491                                const MPI::BlockVector &x,
00492                                const MPI::BlockVector &b) const;
00493 
00524       TrilinosScalar residual (BlockVector       &dst,
00525                                const BlockVector &x,
00526                                const BlockVector &b) const;
00527 
00541       TrilinosScalar residual (MPI::BlockVector       &dst,
00542                                const MPI::Vector      &x,
00543                                const MPI::BlockVector &b) const;
00544 
00558       TrilinosScalar residual (BlockVector       &dst,
00559                                const Vector      &x,
00560                                const BlockVector &b) const;
00561 
00575       TrilinosScalar residual (MPI::Vector            &dst,
00576                                const MPI::BlockVector &x,
00577                                const MPI::Vector      &b) const;
00578 
00592       TrilinosScalar residual (Vector            &dst,
00593                                const BlockVector &x,
00594                                const Vector      &b) const;
00595 
00609       TrilinosScalar residual (VectorBase       &dst,
00610                                const VectorBase &x,
00611                                const VectorBase &b) const;
00612 
00618       using BlockMatrixBase<SparseMatrix>::clear;
00619 
00627       DeclException4 (ExcIncompatibleRowNumbers,
00628                       int, int, int, int,
00629                       << "The blocks [" << arg1 << ',' << arg2 << "] and ["
00630                       << arg3 << ',' << arg4 << "] have differing row numbers.");
00631 
00635       DeclException4 (ExcIncompatibleColNumbers,
00636                       int, int, int, int,
00637                       << "The blocks [" << arg1 << ',' << arg2 << "] and ["
00638                       << arg3 << ',' << arg4 << "] have differing column numbers.");
00640   };
00641 
00642 
00643 
00646 // ------------- inline and template functions -----------------
00647 
00648 
00649 
00650   inline
00651   BlockSparseMatrix &
00652   BlockSparseMatrix::operator = (const double d)
00653   {
00654     Assert (d==0, ExcScalarAssignmentOnlyForZeroValue());
00655 
00656     for (unsigned int r=0; r<this->n_block_rows(); ++r)
00657       for (unsigned int c=0; c<this->n_block_cols(); ++c)
00658         this->block(r,c) = d;
00659 
00660     return *this;
00661   }
00662 
00663 
00664 
00665   inline
00666   bool
00667   BlockSparseMatrix::is_compressed () const
00668   {
00669     bool compressed = true;
00670     for (unsigned int row=0; row<n_block_rows(); ++row)
00671       for (unsigned int col=0; col<n_block_cols(); ++col)
00672         if (block(row, col).is_compressed() == false)
00673           {
00674             compressed = false;
00675             break;
00676           }
00677 
00678     return compressed;
00679   }
00680 
00681 
00682 
00683   inline
00684   void
00685   BlockSparseMatrix::vmult (MPI::BlockVector       &dst,
00686                             const MPI::BlockVector &src) const
00687   {
00688     BaseClass::vmult_block_block (dst, src);
00689   }
00690 
00691 
00692 
00693   inline
00694   void
00695   BlockSparseMatrix::vmult (BlockVector       &dst,
00696                             const BlockVector &src) const
00697   {
00698     BaseClass::vmult_block_block (dst, src);
00699   }
00700 
00701 
00702 
00703   inline
00704   void
00705   BlockSparseMatrix::vmult (MPI::BlockVector  &dst,
00706                             const MPI::Vector &src) const
00707   {
00708     BaseClass::vmult_block_nonblock (dst, src);
00709   }
00710 
00711 
00712 
00713   inline
00714   void
00715   BlockSparseMatrix::vmult (BlockVector  &dst,
00716                             const Vector &src) const
00717   {
00718     BaseClass::vmult_block_nonblock (dst, src);
00719   }
00720 
00721 
00722 
00723   inline
00724   void
00725   BlockSparseMatrix::vmult (MPI::Vector            &dst,
00726                             const MPI::BlockVector &src) const
00727   {
00728     BaseClass::vmult_nonblock_block (dst, src);
00729   }
00730 
00731 
00732 
00733   inline
00734   void
00735   BlockSparseMatrix::vmult (Vector            &dst,
00736                             const BlockVector &src) const
00737   {
00738     BaseClass::vmult_nonblock_block (dst, src);
00739   }
00740 
00741 
00742 
00743   inline
00744   void
00745   BlockSparseMatrix::vmult (VectorBase       &dst,
00746                             const VectorBase &src) const
00747   {
00748     BaseClass::vmult_nonblock_nonblock (dst, src);
00749   }
00750 
00751 
00752 
00753   inline
00754   void
00755   BlockSparseMatrix::Tvmult (MPI::BlockVector       &dst,
00756                              const MPI::BlockVector &src) const
00757   {
00758     BaseClass::Tvmult_block_block (dst, src);
00759   }
00760 
00761 
00762 
00763   inline
00764   void
00765   BlockSparseMatrix::Tvmult (BlockVector       &dst,
00766                              const BlockVector &src) const
00767   {
00768     BaseClass::Tvmult_block_block (dst, src);
00769   }
00770 
00771 
00772 
00773   inline
00774   void
00775   BlockSparseMatrix::Tvmult (MPI::BlockVector  &dst,
00776                              const MPI::Vector &src) const
00777   {
00778     BaseClass::Tvmult_block_nonblock (dst, src);
00779   }
00780 
00781 
00782 
00783   inline
00784   void
00785   BlockSparseMatrix::Tvmult (BlockVector  &dst,
00786                              const Vector &src) const
00787   {
00788     BaseClass::Tvmult_block_nonblock (dst, src);
00789   }
00790 
00791 
00792 
00793   inline
00794   void
00795   BlockSparseMatrix::Tvmult (MPI::Vector            &dst,
00796                              const MPI::BlockVector &src) const
00797   {
00798     BaseClass::Tvmult_nonblock_block (dst, src);
00799   }
00800 
00801 
00802 
00803   inline
00804   void
00805   BlockSparseMatrix::Tvmult (Vector            &dst,
00806                              const BlockVector &src) const
00807   {
00808     BaseClass::Tvmult_nonblock_block (dst, src);
00809   }
00810 
00811 
00812 
00813   inline
00814   void
00815   BlockSparseMatrix::Tvmult (VectorBase       &dst,
00816                              const VectorBase &src) const
00817   {
00818     BaseClass::Tvmult_nonblock_nonblock (dst, src);
00819   }
00820 
00821 }
00822 
00823 DEAL_II_NAMESPACE_CLOSE
00824 
00825 #endif    // DEAL_II_USE_TRILINOS
00826 
00827 #endif    // __deal2__trilinos_block_sparse_matrix_h
00828 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Wed May 23 2012 12:03:30 by doxygen 1.7.3