LifeV
MatrixEpetraStructuredView.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 MatrixEpetraStructuredView.hpp
29  @brief The file contains the MatrixEpetraStructuredView 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 _MATRIXEPETRASTRUCTUREDVIEW_HPP_
37 #define _MATRIXEPETRASTRUCTUREDVIEW_HPP_
38 
39 
40 #include <lifev/core/LifeV.hpp>
41 
42 #include <lifev/core/array/MatrixEpetra.hpp>
43 
44 
45 namespace LifeV
46 {
47 
48 //! MatrixEpetraStructuredView - class representing a block in a MatrixEpetraStructured
49 /*!
50  @author Gwenol Grandperrin
51  @author Samuel Quinodoz
52 
53  The MatrixEpetraStructuredView class contains data related
54  to block of a matrix. It is useful to setup a clean and easy-to-use blocks management.
55 
56  For more information about the block structures in LifeV, see \ref BlockAlgebraPage "this page".
57 
58  <b> Remark </b>
59 
60  Using the operator "=" is not valid for this class! Indeed, copying the view
61  would not copy the data stored in the matrix, which can be confusing. If the
62  copy of the block is the intended use, one should use a method from the BlockUtils.
63 
64  */
65 template<typename DataType>
66 class MatrixEpetraStructuredView
67 {
68 public:
69 
70  /** @name Typedefs
71  */
72  //@{
73 
74  // Not a block matrix to avoid circular dependancies
75  //typedef MatrixEpetraStructured<DataType> matrix_Type;
76 
77  typedef MatrixEpetra<DataType> matrix_Type;
78 
79  //@}
80 
81 
82  /** @name Constructors, destructor
83  */
84  //@{
85  //! default constructor.
86  MatrixEpetraStructuredView();
87 
88  //! Copy constructor
89  MatrixEpetraStructuredView ( const MatrixEpetraStructuredView<DataType>& matrixEpetraStructured );
90 
91  //! default virtual destructor
92  ~MatrixEpetraStructuredView();
93 
94  //@}
95 
96  //! @name Methods
97  //@{
98 
99  //! Print the informations about the MatrixEpetraStructuredView
100  void showMe (std::ostream& output = std::cout) const;
101 
102  //! Function to assemble an elemental matrix in a block
103  void addToCoefficients ( UInt const numRows, UInt const numColumns,
104  std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
105  DataType* const* const localValues,
106  Int format = Epetra_FECrsMatrix::COLUMN_MAJOR ) const;
107  //! Function to assemble an elemental matrix in a block (for closed matrices)
108  void sumIntoCoefficients ( UInt const numRows, UInt const numColumns,
109  std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
110  DataType* const* const localValues,
111  Int format = Epetra_FECrsMatrix::COLUMN_MAJOR ) const;
112  //@}
113 
114  //! @name Set Methods
115  //@{
116  /*! Set all the informations relative to the block
117  * @param firstRow First row in the block
118  * @param firstColumn First column in the block
119  * @param numRows Number of rows in the block
120  * @param numColumns Number of columns in the block
121  * @param A Matrix which contains the block
122  */
123  void setup ( const UInt& firstRow,
124  const UInt& firstColumn,
125  const UInt& numRows,
126  const UInt& numColumns,
127  matrix_Type* A );
128 
129  //@}
130 
131  //! @name Get Methods
132  //@{
133  //! Returns the number of rows in the block
134  UInt numRows() const
135  {
136  return M_numRows;
137  }
138 
139  //! Returns the number of columns in the block
140  UInt numColumns() const
141  {
142  return M_numColumns;
143  }
144 
145  //! Returns the index of the first row in the block
146  UInt firstRowIndex() const
147  {
148  return M_firstRowIndex;
149  }
150 
151  //! Returns the index of the last row in the block
152  UInt lastRowIndex() const
153  {
154  return M_lastRowIndex;
155  }
156 
157  //! Returns the index of the first column in the block
158  UInt firstColumnIndex() const
159  {
160  return M_firstColumnIndex;
161  }
162 
163  //! Returns the index of the last column in the block
164  UInt lastColumnIndex() const
165  {
166  return M_lastColumnIndex;
167  }
168 
169  //! Return the fill-complete status of the inner Epetra_FECrsMatrix
170  bool filled() const
171  {
172  return M_matrix->matrixPtr()->Filled();
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  MatrixEpetraStructuredView<DataType> operator= ( const MatrixEpetraStructuredView& 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 MatrixEpetraStructuredView<DataType>::MatrixEpetraStructuredView() :
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 MatrixEpetraStructuredView<DataType>::MatrixEpetraStructuredView ( const MatrixEpetraStructuredView<DataType>& matrixEpetraStructured ) :
222  M_numRows ( matrixEpetraStructured.M_numRows ),
223  M_numColumns ( matrixEpetraStructured.M_numColumns ),
224  M_firstRowIndex ( matrixEpetraStructured.M_firstRowIndex ),
225  M_lastRowIndex ( matrixEpetraStructured.M_lastRowIndex ),
226  M_firstColumnIndex ( matrixEpetraStructured.M_firstColumnIndex ),
227  M_lastColumnIndex ( matrixEpetraStructured.M_lastColumnIndex ),
228  M_matrix ( matrixEpetraStructured.M_matrix )
229 {
230 
231 }
232 
233 template<typename DataType>
234 MatrixEpetraStructuredView<DataType>::~MatrixEpetraStructuredView()
235 {
236  //M_matrix.reset();
237 }
238 
239 // ===================================================
240 // Methods
241 // ===================================================
242 
243 template<typename DataType>
244 void
245 MatrixEpetraStructuredView<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 template<typename DataType>
256 void
257 MatrixEpetraStructuredView<DataType>::
258 addToCoefficients ( UInt const numRows, UInt const numColumns,
259  std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
260  DataType* const* const localValues,
261  Int format) const
262 {
263  std::vector<Int> rowIndices (blockRowIndices);
264  std::vector<Int> columnIndices (blockColumnIndices);
265 
266  for (UInt i (0); i < numRows; ++i)
267  {
268  rowIndices[i] += M_firstRowIndex;
269  }
270  for (UInt i (0); i < numColumns; ++i)
271  {
272  columnIndices[i] += M_firstColumnIndex;
273  }
274 
275  M_matrix->addToCoefficients (numRows, numColumns,
276  rowIndices, columnIndices,
277  localValues, format);
278 }
279 
280 template<typename DataType>
281 void
282 MatrixEpetraStructuredView<DataType>::
283 sumIntoCoefficients ( UInt const numRows, UInt const numColumns,
284  std::vector<Int> const& blockRowIndices,
285  std::vector<Int> const& blockColumnIndices,
286  DataType* const* const localValues,
287  Int format) const
288 {
289  std::vector<Int> rowIndices (blockRowIndices);
290  std::vector<Int> columnIndices (blockColumnIndices);
291 
292  for (UInt i (0); i < numRows; ++i)
293  {
294  rowIndices[i] += M_firstRowIndex;
295  }
296  for (UInt i (0); i < numColumns; ++i)
297  {
298  columnIndices[i] += M_firstColumnIndex;
299  }
300 
301  M_matrix->sumIntoCoefficients (numRows, numColumns,
302  rowIndices, columnIndices,
303  localValues, format);
304 }
305 
306 // ===================================================
307 // Set Methods
308 // ===================================================
309 
310 template<typename DataType>
311 void
312 MatrixEpetraStructuredView<DataType>::setup ( const UInt& firstRow,
313  const UInt& firstColumn,
314  const UInt& numRows,
315  const UInt& numColumns,
316  matrix_Type* A )
317 {
318  M_numRows = numRows;
319  M_numColumns = numColumns;
320  M_firstRowIndex = firstRow;
321  M_lastRowIndex = firstRow + numRows - 1;
322  M_firstColumnIndex = firstColumn;
323  M_lastColumnIndex = firstColumn + numColumns - 1;
324  M_matrix = A;
325 }
326 
327 // ===================================================
328 // Get Methods
329 // ===================================================
330 
331 } // namespace LifeV
332 
333 #endif /* _MATRIXEPETRASTRUCTUREDVIEW_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