Reference documentation for deal.II version 8.5.1
block_matrix.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2000 - 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__block_matrix_h
17 #define dealii__block_matrix_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/lac/block_vector.h>
24 
25 DEAL_II_NAMESPACE_OPEN
26 
50 template <typename MatrixType>
52 {
53 public:
58  BlockDiagonalMatrix (const MatrixType &M,
59  const unsigned int n_blocks);
60 
64  template <typename number1, typename number2>
65  void vmult (BlockVector<number1> &dst,
66  const BlockVector<number2> &src) const;
67 
71  template <typename number1, typename number2>
72  void Tvmult (BlockVector<number1> &dst,
73  const BlockVector<number2> &src) const;
74 private:
78  unsigned int num_blocks;
79 
84 };
85 
87 //---------------------------------------------------------------------------
88 
89 template <typename MatrixType>
91  const unsigned int num_blocks)
92  :
93  num_blocks (num_blocks),
94  matrix(&M)
95 {}
96 
97 
98 template <typename MatrixType>
99 template <typename number1, typename number2>
100 void
102  const BlockVector<number2> &src) const
103 {
104  Assert (dst.n_blocks()==num_blocks,
105  ExcDimensionMismatch(dst.n_blocks(),num_blocks));
106  Assert (src.n_blocks()==num_blocks,
107  ExcDimensionMismatch(src.n_blocks(),num_blocks));
108 
109  for (unsigned int i=0; i<num_blocks; ++i)
110  matrix->vmult (dst.block(i), src.block(i));
111 }
112 
113 
114 template <typename MatrixType>
115 template <typename number1, typename number2>
116 void
118  const BlockVector<number2> &src) const
119 {
120  Assert (dst.n_blocks()==num_blocks,
121  ExcDimensionMismatch(dst.n_blocks(),num_blocks));
122  Assert (src.n_blocks()==num_blocks,
123  ExcDimensionMismatch(src.n_blocks(),num_blocks));
124 
125  for (unsigned int i=0; i<num_blocks; ++i)
126  matrix->Tvmult (dst.block(i), src.block(i));
127 }
128 
129 
130 DEAL_II_NAMESPACE_CLOSE
131 
132 #endif
unsigned int num_blocks
Definition: block_matrix.h:78
void vmult(BlockVector< number1 > &dst, const BlockVector< number2 > &src) const
Definition: block_matrix.h:101
BlockDiagonalMatrix(const MatrixType &M, const unsigned int n_blocks)
Definition: block_matrix.h:90
SmartPointer< const MatrixType, BlockDiagonalMatrix< MatrixType > > matrix
Definition: block_matrix.h:83
#define Assert(cond, exc)
Definition: exceptions.h:313
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void Tvmult(BlockVector< number1 > &dst, const BlockVector< number2 > &src) const
Definition: block_matrix.h:117
BlockType & block(const unsigned int i)