LifeV
MatrixEpetraStructured.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 ************************************************************************
4 
5  This file is part of the LifeV Applications.
6  Copyright (C) 2001-2010 EPFL, Politecnico di Milano, INRIA
7 
8  This library is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as
10  published by the Free Software Foundation; either version 2.1 of the
11  License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  USA
22 
23 ************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file MatrixEpetraStructured.hpp
29  @brief The file contains the MatrixEpetraStructured class
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
33  @date 2010-10-09
34  */
35 
36 #ifndef _MATRIXEPETRASTRUCTURED_HPP_
37 #define _MATRIXEPETRASTRUCTURED_HPP_
38 
39 #include <lifev/core/LifeV.hpp>
40 
41 #include <lifev/core/array/MapEpetra.hpp>
42 #include <lifev/core/array/MapVector.hpp>
43 #include <lifev/core/array/MatrixEpetra.hpp>
44 #include <lifev/core/array/MatrixBlockStructure.hpp>
45 #include <lifev/core/array/MatrixEpetraStructuredView.hpp>
46 
47 namespace LifeV
48 {
49 
50 //! MatrixEpetraStructured - class of block matrix
51 /*!
52  @author Gwenol Grandperrin
53  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
54 
55  The MatrixEpetraStructured class contains data related
56  to block matrix. It is an extension to MatrixEpetra where data about blocks have
57  been set. For an introduction to the block structures in LifeV, see
58  \ref BlockAlgebraPage "this page".
59 
60  There are mainly two ways to define a MatrixEpetraStructured:
61  <ul>
62  <li> Construct it using the same syntax as for LifeV::MatrixEpetra and the use
63  a setter for the structure.
64  <li> Construct it directly with the maps of the blocks.
65  </ul>
66  Both ways are equivalent.
67 
68  To access the blocks, one uses then the blockView or block methods.
69 
70  */
71 template <typename DataType>
72 class MatrixEpetraStructured : public MatrixEpetra<DataType>
73 {
74 public:
75 
76  typedef MatrixEpetraStructuredView<DataType> block_type;
77  typedef std::shared_ptr<block_type> block_ptrType;
78 
79  /** @name Constructors, destructor
80  */
81  //@{
82  //! default constructor.
83  MatrixEpetraStructured ( const MapEpetra& map, int numEntries = 50, bool ignoreNonLocalValues = false );
84 
85  //! Block constructor
86  /*!
87  This is the most complete constructor, as it builds the whole block
88  structure of the matrix, using the maps stored in the vector.
89  */
90  MatrixEpetraStructured ( const MapVector<MapEpetra>& vector, int numEntries = 50, bool ignoreNonLocalValues = false );
91 
92  //! Casting constructor
93  MatrixEpetraStructured ( const MatrixEpetra<DataType>& matrix );
94 
95  //! Copy constructor
96  MatrixEpetraStructured ( const MatrixEpetraStructured& matrix );
97 
98  //! Destructor
99  ~MatrixEpetraStructured();
100 
101  //@}
102 
103 
104  //! @name Set Methods
105  //@{
106 
107  /*! Set the size of the blocks of the matrix
108  * @param blockNumRows Number of rows in the blocks
109  * @param blockNumColumns Number of columns in the blocks
110  */
111  void setBlockStructure ( const std::vector<UInt>& blockNumRows,
112  const std::vector<UInt>& blockNumColumns );
113 
114  /*! Set the size of the blocks of the matrix using the maps stored in the vector
115  of map. The resulting block structure in symmetric (same blocks in the rows
116  and in the columns).
117 
118  This method does not involve large computations. The global size and the map
119  of the matrix cannot be changed with this method (and the block structure has
120  to be compatible with the global size).
121 
122  */
123  void setBlockStructure ( const MapVector<MapEpetra>& mapVector );
124 
125  //! Set the block structure from a matrix structure object
126  void setBlockStructure ( const MatrixBlockStructure& blockStructure );
127 
128  //! Set the block structure from row and column structures
129  void setBlockStructure ( const VectorBlockStructure& rowsBlockStructure,
130  const VectorBlockStructure& columnsBlockStructure );
131 
132  //! Set the block structure from row and column structures
133  void setBlockStructure ( const VectorBlockStructure& vectorBlockStructure );
134 
135  //@}
136 
137 
138  //! @name Get Methods
139  //@{
140 
141  //! Returns the number of rows of the block
142  /*!
143  * @param rowIndex Row index of the block
144  */
145  UInt blockNumRows ( const UInt& rowIndex ) const;
146 
147  //! Returns the number of columns of the block
148  /*!
149  * @param columnIndex Column index of the block
150  */
151  UInt blockNumColumns ( const UInt& columnIndex ) const;
152 
153  //! Returns the MatrixEpetraStructuredView at the (rowIndex,colIndex) location
154  /*!
155  * @param rowIndex Row position of the block in the matrix
156  * @param columnIndex Column position of the block in the matrix
157  * @param mbv MatrixEpetraStructuredView to be filled
158  */
159  void blockView ( const UInt& rowIndex,
160  const UInt& columnIndex,
161  block_type& mbv );
162 
163  //! Returns the block (rowIndex,columnIndex) of the matrix
164  /*!
165  Remark that the returned block is a shared pointer. This is
166  a limitation due to the non-copiability of the blocks.
167  @param rowIndex The index of the block w.r. to the block structure
168  @param columnIndex The index of the block w.r. to the block structure
169  */
170  block_ptrType block ( const UInt& rowIndex, const UInt& columnIndex );
171 
172  //! Get the rows block structure
173  VectorBlockStructure rowsBlockStructure() const;
174 
175  //! Get the columns block structure
176  VectorBlockStructure columnsBlockStructure() const;
177 
178  //! Get the matrix block structure
179  MatrixBlockStructure blockStructure() const;
180 
181  //@}
182 
183 
184  //! @name Linear Algebra Methods
185  //@{
186 
187  //! Returns a pointer to a new matrix which contains the transpose of the current matrix
188  std::shared_ptr<MatrixEpetraStructured<DataType> > transpose()
189  {
190  return std::static_pointer_cast<MatrixEpetraStructured<DataType> > ( this->MatrixEpetra<DataType>::transpose() );
191  }
192 
193  //@}
194 
195 private:
196 
197  MatrixBlockStructure M_blockStructure;
198 };
199 
200 // ===================================================
201 // IMPLEMENTATION
202 // ===================================================
203 
204 // ===================================================
205 // Constructors & Destructor
206 // ===================================================
207 template <typename DataType>
208 MatrixEpetraStructured<DataType>::MatrixEpetraStructured ( const MapEpetra& map, int numEntries, bool ignoreNonLocalValues ) :
209  MatrixEpetra<DataType> ( map, numEntries, ignoreNonLocalValues ),
210  M_blockStructure ( map )
211 {
212 
213 }
214 
215 
216 
217 template <typename DataType>
218 MatrixEpetraStructured<DataType>::MatrixEpetraStructured ( const MapVector<MapEpetra>& vector, int numEntries, bool ignoreNonLocalValues ) :
219  MatrixEpetra<DataType> ( typename MatrixEpetra<DataType>::matrix_ptrtype() ), M_blockStructure ( vector )
220 {
221  ASSERT ( vector.nbMap() > 0 , "Map vector empty, impossible to construct a MatrixBlockMonolithicEpetra!" );
222 
223  MapEpetra myMap ( vector.totalMap() );
224 
225  this->mapPtr().reset ( new MapEpetra ( myMap ) );
226  this->matrixPtr().reset ( new typename MatrixEpetra<DataType>::matrix_type ( Copy, *myMap.map ( Unique ), numEntries, ignoreNonLocalValues ) );
227 }
228 
229 
230 template <typename DataType>
231 MatrixEpetraStructured<DataType>::MatrixEpetraStructured ( const MatrixEpetra<DataType>& matrix ) :
232  MatrixEpetra<DataType> ( matrix ),
233  M_blockStructure ( matrix.map() )
234 {}
235 
236 template <typename DataType>
237 MatrixEpetraStructured<DataType>::MatrixEpetraStructured ( const MatrixEpetraStructured& matrix ) :
238  MatrixEpetra<DataType> ( matrix ),
239  M_blockStructure ( matrix.M_blockStructure )
240 {}
241 
242 template <typename DataType>
243 MatrixEpetraStructured<DataType>::~MatrixEpetraStructured()
244 {}
245 
246 // ===================================================
247 // Set Methods
248 // ===================================================
249 template <typename DataType>
250 void
251 MatrixEpetraStructured<DataType>::setBlockStructure ( const std::vector<UInt>& blockNumRows,
252  const std::vector<UInt>& blockNumColumns )
253 {
254  ASSERT ( blockNumRows.size() > 0, "No way to build a matrix with 0 block rows" );
255  ASSERT ( blockNumColumns.size() > 0, "No way to build a matrix with 0 block columns" );
256 
257 
258  M_blockStructure.setBlockStructure ( blockNumRows, blockNumColumns );
259 }
260 
261 template <typename DataType>
262 void
263 MatrixEpetraStructured<DataType>::setBlockStructure ( const MapVector<MapEpetra>& mapVector )
264 {
265  ASSERT ( mapVector.nbMap() > 0 , "Map vector empty, impossible to set the block structure" );
266 
267  M_blockStructure.setBlockStructure ( mapVector );
268 
269  ASSERT ( this->matrixPtr()->NumGlobalCols() == M_blockStructure.numRows(), " Incompatible block structure (global size does not match) " );
270  ASSERT ( this->matrixPtr()->NumGlobalRows() == M_blockStructure.numColumns(), " Incompatible block structure (global size does not match) " );
271 }
272 
273 template <typename DataType>
274 void
275 MatrixEpetraStructured<DataType>::setBlockStructure ( const MatrixBlockStructure& blockStructure )
276 {
277  M_blockStructure.setBlockStructure ( blockStructure );
278 }
279 
280 template <typename DataType>
281 void
282 MatrixEpetraStructured<DataType>::setBlockStructure ( const VectorBlockStructure& rowsBlockStructure,
283  const VectorBlockStructure& columnsBlockStructure )
284 {
285  M_blockStructure.setBlockStructure ( rowsBlockStructure, columnsBlockStructure );
286 }
287 
288 template <typename DataType>
289 void
290 MatrixEpetraStructured<DataType>::setBlockStructure ( const VectorBlockStructure& vectorBlockStructure )
291 {
292  M_blockStructure.setBlockStructure ( vectorBlockStructure, vectorBlockStructure );
293 }
294 
295 // ===================================================
296 // Get Methods
297 // ===================================================
298 template <typename DataType>
299 UInt
300 MatrixEpetraStructured<DataType>::blockNumRows ( const UInt& rowIndex ) const
301 {
302  return M_blockStructure.blockNumRows ( rowIndex );
303 }
304 
305 template <typename DataType>
306 UInt
307 MatrixEpetraStructured<DataType>::blockNumColumns ( const UInt& columnIndex ) const
308 {
309  return M_blockStructure.blockNumColumns ( columnIndex );
310 }
311 
312 template <typename DataType>
313 void
314 MatrixEpetraStructured<DataType>::blockView ( const UInt& rowIndex,
315  const UInt& columnIndex,
316  block_type& mbv )
317 {
318  mbv.setup ( M_blockStructure.rowBlockFirstIndex ( rowIndex ),
319  M_blockStructure.columnBlockFirstIndex ( columnIndex ),
320  M_blockStructure.blockNumRows ( rowIndex ),
321  M_blockStructure.blockNumColumns ( columnIndex ),
322  this );
323 }
324 
325 template <typename DataType>
326 typename MatrixEpetraStructured<DataType>::block_ptrType
327 MatrixEpetraStructured<DataType>::block ( const UInt& rowIndex, const UInt& columnIndex )
328 {
329  block_ptrType matrixBlockView ( new block_type );
330 
331  matrixBlockView->setup ( M_blockStructure.rowBlockFirstIndex ( rowIndex ),
332  M_blockStructure.columnBlockFirstIndex ( columnIndex ),
333  M_blockStructure.blockNumRows ( rowIndex ),
334  M_blockStructure.blockNumColumns ( columnIndex ),
335  this );
336 
337  return matrixBlockView;
338 }
339 
340 template <typename DataType>
341 VectorBlockStructure
342 MatrixEpetraStructured<DataType>::rowsBlockStructure() const
343 {
344  return M_blockStructure.rowsBlockStructure();
345 }
346 
347 template <typename DataType>
348 VectorBlockStructure
349 MatrixEpetraStructured<DataType>::columnsBlockStructure() const
350 {
351  return M_blockStructure.columnsBlockStructure();
352 }
353 
354 template <typename DataType>
355 MatrixBlockStructure
356 MatrixEpetraStructured<DataType>::blockStructure() const
357 {
358  return M_blockStructure;
359 }
360 
361 
362 } // namespace LifeV
363 
364 #endif /* _MATRIXEPETRASTRUCTURED_HPP_ */
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191