LifeV
MatrixBlockMonolithicEpetraView.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 MatrixBlockMonolithicEpetraView.hpp
29  @brief The file contains the MatrixBlockMonolithicEpetraView class
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @contributor Samuel Quinodoz <samuel.quinodoz@epfl.ch>
33  @date 2010-10-09
34  */
35 
36 #ifndef _MATRIX_BLOCK_MONOLITHIC_EPETRA_VIEW_HPP_
37 #define _MATRIX_BLOCK_MONOLITHIC_EPETRA_VIEW_HPP_
38 
39 #include <boost/shared_ptr.hpp>
40 
41 #include <iostream>
42 
43 #include <lifev/core/array/MatrixEpetra.hpp>
44 
45 
46 namespace LifeV
47 {
48 
49 //! MatrixBlockMonolithicEpetraView - class representing a block in a MatrixBlockMonolithicEpetra
50 /*!
51  @author Gwenol Grandperrin
52  @author Samuel Quinodoz
53 
54  The MatrixBlockMonolithicEpetraView class contains data related
55  to block of a matrix. It is useful to setup a clean and easy-to-use blocks management.
56 
57  For more information about the block structures in LifeV, see \ref BlockAlgebraPage "this page".
58 
59  <b> Remark </b>
60 
61  Using the operator "=" is not valid for this class! Indeed, copying the view
62  would not copy the data stored in the matrix, which can be confusing. If the
63  copy of the block is the intended use, one should use a method from the BlockUtils.
64 
65  */
66 template<typename DataType>
67 class MatrixBlockMonolithicEpetraView
68 {
69 public:
70 
71  /** @name Typedefs
72  */
73  //@{
74 
75  // Not a block matrix to avoid circular dependancies
76  //typedef MatrixBlockMonolithicEpetra<DataType> matrix_Type;
77 
78  typedef MatrixEpetra<DataType> matrix_Type;
79 
80  //@}
81 
82 
83  /** @name Constructors, destructor
84  */
85  //@{
86  //! default constructor.
87  MatrixBlockMonolithicEpetraView();
88 
89  //! Copy constructor
90  MatrixBlockMonolithicEpetraView ( const MatrixBlockMonolithicEpetraView<DataType>& mbv );
91 
92  //! default virtual destructor
93  ~MatrixBlockMonolithicEpetraView();
94 
95  //@}
96 
97  //! @name Methods
98  //@{
99 
100  //! Print the informations about the MatrixBlockMonolithicEpetraView
101  void showMe (std::ostream& output = std::cout) const;
102 
103  //! Tells if the viewed matrix is already filled
104  bool filled() const;
105 
106  //! Function to assemble an elemental matrix in a block
107  void addToCoefficients ( UInt const numRows, UInt const numColumns,
108  std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
109  DataType* const* const localValues,
110  Int format = Epetra_FECrsMatrix::COLUMN_MAJOR ) const;
111 
112  //! Function to sum an elemental matrix in a block which is already closed
113  void sumIntoCoefficients ( UInt const numRows, UInt const numColumns,
114  std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
115  DataType* const* const localValues,
116  Int format = Epetra_FECrsMatrix::COLUMN_MAJOR ) const;
117 
118  //@}
119 
120  //! @name Set Methods
121  //@{
122  /*! Set all the informations relative to the block
123  * @param firstRow First row in the block
124  * @param firstColumn First column in the block
125  * @param numRows Number of rows in the block
126  * @param numColumns Number of columns in the block
127  * @param A Matrix which contains the block
128  */
129  void setup ( const UInt& firstRow,
130  const UInt& firstColumn,
131  const UInt& numRows,
132  const UInt& numColumns,
133  matrix_Type* A );
134 
135  //@}
136 
137  //! @name Get Methods
138  //@{
139  //! Returns the number of rows in the block
140  UInt numRows() const
141  {
142  return M_numRows;
143  }
144 
145  //! Returns the number of columns in the block
146  UInt numColumns() const
147  {
148  return M_numColumns;
149  }
150 
151  //! Returns the index of the first row in the block
152  UInt firstRowIndex() const
153  {
154  return M_firstRowIndex;
155  }
156 
157  //! Returns the index of the last row in the block
158  UInt lastRowIndex() const
159  {
160  return M_lastRowIndex;
161  }
162 
163  //! Returns the index of the first column in the block
164  UInt firstColumnIndex() const
165  {
166  return M_firstColumnIndex;
167  }
168 
169  //! Returns the index of the last column in the block
170  UInt lastColumnIndex() const
171  {
172  return M_lastColumnIndex;
173  }
174 
175  //! Return the pointer of the full matrix
176  matrix_Type* matrixPtr() const
177  {
178  return M_matrix;
179  }
180 
181  //@}
182 
183 private:
184 
185  //! @name Private Methods
186  //@{
187 
188  //! No assignement operator, it is missleading (would copy the views, not the blocks!)
189  MatrixBlockMonolithicEpetraView<DataType> operator= ( const MatrixBlockMonolithicEpetraView& otherView);
190 
191  //@}
192 
193 
194  UInt M_numRows;
195  UInt M_numColumns;
196  UInt M_firstRowIndex;
197  UInt M_lastRowIndex;
198  UInt M_firstColumnIndex;
199  UInt M_lastColumnIndex;
200  matrix_Type* M_matrix;
201 };
202 
203 // ===================================================
204 // Constructors & Destructor
205 // ===================================================
206 
207 template<typename DataType>
208 MatrixBlockMonolithicEpetraView<DataType>::MatrixBlockMonolithicEpetraView() :
209  M_numRows ( 0 ),
210  M_numColumns ( 0 ),
211  M_firstRowIndex ( 0 ),
212  M_lastRowIndex ( 0 ),
213  M_firstColumnIndex ( 0 ),
214  M_lastColumnIndex ( 0 ),
215  M_matrix()
216 {
217 
218 }
219 
220 template<typename DataType>
221 MatrixBlockMonolithicEpetraView<DataType>::MatrixBlockMonolithicEpetraView ( const MatrixBlockMonolithicEpetraView<DataType>& mbv ) :
222  M_numRows ( mbv.M_numRows ),
223  M_numColumns ( mbv.M_numColumns ),
224  M_firstRowIndex ( mbv.M_firstRowIndex ),
225  M_lastRowIndex ( mbv.M_lastRowIndex ),
226  M_firstColumnIndex ( mbv.M_firstColumnIndex ),
227  M_lastColumnIndex ( mbv.M_lastColumnIndex ),
228  M_matrix ( mbv.M_matrix )
229 {
230 
231 }
232 
233 template<typename DataType>
234 MatrixBlockMonolithicEpetraView<DataType>::~MatrixBlockMonolithicEpetraView()
235 {
236  //M_matrix.reset();
237 }
238 
239 // ===================================================
240 // Methods
241 // ===================================================
242 
243 template<typename DataType>
244 void
245 MatrixBlockMonolithicEpetraView<DataType>::showMe ( std::ostream& output ) const
246 {
247  output << "MatrixBlockMonolithicEpetraView informations:" << std::endl
248  << "Size = " << M_numRows << " x " << M_numColumns << std::endl
249  << "firstRow = " << M_firstRowIndex << std::endl
250  << "lastRow = " << M_lastRowIndex << std::endl
251  << "firstColumn = " << M_firstColumnIndex << std::endl
252  << "lastColumn = " << M_lastColumnIndex << std::endl;
253 }
254 
255 
256 template<typename DataType>
257 bool
258 MatrixBlockMonolithicEpetraView<DataType>::
259 filled() const
260 {
261  return M_matrix->filled();
262 }
263 
264 
265 template<typename DataType>
266 void
267 MatrixBlockMonolithicEpetraView<DataType>::
268 addToCoefficients ( UInt const numRows, UInt const numColumns,
269  std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
270  DataType* const* const localValues,
271  Int format) const
272 {
273  std::vector<Int> rowIndices (blockRowIndices);
274  std::vector<Int> columnIndices (blockColumnIndices);
275 
276  for (UInt i (0); i < numRows; ++i)
277  {
278  rowIndices[i] += M_firstRowIndex;
279  }
280  for (UInt i (0); i < numColumns; ++i)
281  {
282  columnIndices[i] += M_firstColumnIndex;
283  }
284 
285  M_matrix->addToCoefficients (numRows, numColumns,
286  rowIndices, columnIndices,
287  localValues, format);
288 }
289 
290 
291 template<typename DataType>
292 void
293 MatrixBlockMonolithicEpetraView<DataType>::
294 sumIntoCoefficients ( UInt const numRows, UInt const numColumns,
295  std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
296  DataType* const* const localValues,
297  Int format) const
298 {
299  std::vector<Int> rowIndices (blockRowIndices);
300  std::vector<Int> columnIndices (blockColumnIndices);
301 
302  for (UInt i (0); i < numRows; ++i)
303  {
304  rowIndices[i] += M_firstRowIndex;
305  }
306  for (UInt i (0); i < numColumns; ++i)
307  {
308  columnIndices[i] += M_firstColumnIndex;
309  }
310 
311  M_matrix->sumIntoCoefficients (numRows, numColumns,
312  rowIndices, columnIndices,
313  localValues, format);
314 }
315 
316 
317 
318 
319 
320 // ===================================================
321 // Set Methods
322 // ===================================================
323 
324 template<typename DataType>
325 void
326 MatrixBlockMonolithicEpetraView<DataType>::setup ( const UInt& firstRow,
327  const UInt& firstColumn,
328  const UInt& numRows,
329  const UInt& numColumns,
330  matrix_Type* A )
331 {
332  M_numRows = numRows;
333  M_numColumns = numColumns;
334  M_firstRowIndex = firstRow;
335  M_lastRowIndex = firstRow + numRows - 1;
336  M_firstColumnIndex = firstColumn;
337  M_lastColumnIndex = firstColumn + numColumns - 1;
338  M_matrix = A;
339 }
340 
341 // ===================================================
342 // Get Methods
343 // ===================================================
344 
345 } // namespace LifeV
346 
347 #endif /* MATRIXBLOCKVIEW_HPP */
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191