DOLFIN
DOLFIN C++ interface
BlockMatrix.h
1 // Copyright (C) 2008 Kent-Andre Mardal
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Modified by Anders Logg, 2008.
19 // Modified by Garth N. Wells, 2011.
20 //
21 // First added: 2008-08-25
22 // Last changed: 2011-01-22
23 
24 #ifndef __BLOCKMATRIX_H
25 #define __BLOCKMATRIX_H
26 
27 #include <boost/multi_array.hpp>
28 #include <memory>
29 
30 #include "BlockVector.h"
31 
32 namespace dolfin
33 {
34 
35  // Forward declarations
36  class GenericMatrix;
37 
39 
41  {
42  public:
43 
45  BlockMatrix(std::size_t m=0, std::size_t n=0);
46 
48  ~BlockMatrix();
49 
51  void set_block(std::size_t i, std::size_t j,
52  std::shared_ptr<GenericMatrix> m);
53 
55  std::shared_ptr<const GenericMatrix>
56  get_block(std::size_t i, std::size_t j) const;
57 
59  std::shared_ptr<GenericMatrix> get_block(std::size_t i, std::size_t j);
60 
62  std::size_t size(std::size_t dim) const;
63 
65  void zero();
66 
68  void apply(std::string mode);
69 
71  std::string str(bool verbose) const;
72 
74  void mult(const BlockVector& x, BlockVector& y,
75  bool transposed=false) const;
76 
80  std::shared_ptr<GenericMatrix>
81  schur_approximation(bool symmetry=true) const;
82 
83  private:
84 
85  boost::multi_array<std::shared_ptr<GenericMatrix>, 2> matrices;
86 
87  };
88 
89 }
90 
91 #endif
BlockMatrix(std::size_t m=0, std::size_t n=0)
Constructor.
Definition: BlockMatrix.cpp:38
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: BlockMatrix.cpp:96
std::size_t size(std::size_t dim) const
Return size of given dimension.
Definition: BlockMatrix.cpp:75
Definition: adapt.h:29
Block Matrix.
Definition: BlockMatrix.h:40
std::shared_ptr< const GenericMatrix > get_block(std::size_t i, std::size_t j) const
Get block (const version)
Definition: BlockMatrix.cpp:60
void zero()
Set all entries to zero and keep any sparse structure.
Definition: BlockMatrix.cpp:81
void apply(std::string mode)
Finalize assembly of tensor.
Definition: BlockMatrix.cpp:88
~BlockMatrix()
Destructor.
Definition: BlockMatrix.cpp:46
std::shared_ptr< GenericMatrix > schur_approximation(bool symmetry=true) const
Definition: BlockMatrix.cpp:161
void set_block(std::size_t i, std::size_t j, std::shared_ptr< GenericMatrix > m)
Set block.
Definition: BlockMatrix.cpp:51
Block vector.
Definition: BlockVector.h:41
void mult(const BlockVector &x, BlockVector &y, bool transposed=false) const
Matrix-vector product, y = Ax.
Definition: BlockMatrix.cpp:122