LifeV
ETMatrixElemental.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory UNiversity
7 
8  This file is part of the LifeV library
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, see <http://www.gnu.org/licenses/>
22 
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 /*!
29  * @file
30  @brief This file contains the definition of the ETMatrixElemental class
31 
32  @date 06/2011
33  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
34  */
35 
36 #ifndef ET_MATRIX_ELEMENTAL_HPP
37 #define ET_MATRIX_ELEMENTAL_HPP
38 
39 #include <vector>
40 
41 #include <boost/shared_ptr.hpp>
42 
43 #include <lifev/core/LifeV.hpp>
44 
45 // next needed for ROW_MAJOR ...
46 #include <lifev/core/array/MatrixEpetra.hpp>
47 
48 namespace LifeV
49 {
50 
51 //! class ETMatrixElemental A class for describing an elemental matrix
52 /*!
53  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
54 
55  This class is meant to represent an ETMatrixElemental. It contains mainly:
56 
57  <ol>
58  <li> Simple constructors
59  <li> Methods to access and modify the indexes
60  <li> Methods to store and access the entries
61  <li> Assembly methods to put the local entries in a global matrix
62  </ol>
63 
64 */
66 {
67 
68 public:
69 
70  //! @name Constructors & Destructor
71  //@{
72 
73  //! Constructor with the minimal interface: number of columns and of rows are provided.
74  ETMatrixElemental (const UInt& nbRow, const UInt& nbCol );
75 
76  //! Copy constructor (including deep copy of the data)
78 
79  //! Destructor
80  virtual ~ETMatrixElemental();
81 
82  //@}
83 
84  //! @name Operators
85  //@{
86 
87  //@}
88 
89 
90  //! @name Methods
91  //@{
92 
93  //! Put zero all the data stored
94  // This method is defined in class to allow the compiler
95  // to optimize it easily (used repeatedly during the assembly)
96  void zero()
97  {
98  for (UInt i (0); i < M_nbRow; ++i)
99  {
100  for (UInt j (0); j < M_nbColumn; ++j)
101  {
102  M_rawData[i][j] = 0.0;
103  }
104  }
105  }
106 
107  //! Assembly procedure for a matrix or a block of a matrix
108  /*!
109  This method puts the values stored in this elemental matrix into the global
110  matrix passed as argument, using the positions given in the global indices
111  stored.
112  */
113  // Method defined in class to allow compiler optimization
114  // as this class is used repeatedly during the assembly
115  template <typename MatrixType>
116  void pushToGlobal (MatrixType& mat)
117  {
118  mat.addToCoefficients ( M_nbRow, M_nbColumn,
119  rowIndices(), columnIndices(),
120  M_rawData, Epetra_FECrsMatrix::ROW_MAJOR);
121  }
122 
123  //! Assembly procedure for a matrix or a block of a matrix
124  /*!
125  This method puts the values stored in this elemental matrix into the global
126  matrix passed as argument, using the positions given in the global indices
127  stored.
128  The method is used when the global matrix is closed
129  */
130  // Method defined in class to allow compiler optimization
131  // as this class is used repeatedly during the assembly
132  template <typename MatrixType>
133  void pushToClosedGlobal (MatrixType& mat)
134  {
135  mat.sumIntoCoefficients ( M_nbRow, M_nbColumn,
136  rowIndices(), columnIndices(),
137  M_rawData, Epetra_FECrsMatrix::ROW_MAJOR);
138  }
139 
140  //! Assembly procedure for a matrix or a block of a matrix passed in a shared_ptr
141  /*!
142  This method puts the values stored in this elemental matrix into the global
143  matrix passed as argument, using the positions given in the global indices
144  stored.
145 
146  This is a partial specialization of the other assembly procedure of this class.
147  */
148  // Method defined in class to allow compiler optimization
149  // as this class is used repeatedly during the assembly
150  template <typename MatrixType>
151  void pushToGlobal (std::shared_ptr<MatrixType> mat)
152  {
153  mat->addToCoefficients ( M_nbRow, M_nbColumn,
154  rowIndices(), columnIndices(),
155  M_rawData, Epetra_FECrsMatrix::ROW_MAJOR);
156  }
157 
158  //! Assembly procedure for a matrix or a block of a matrix passed in a shared_ptr
159  /*!
160  This method puts the values stored in this elemental matrix into the global
161  matrix passed as argument, using the positions given in the global indices
162  stored.
163  The method is used when the global matrix is closed
164 
165  This is a partial specialization of the other assembly procedure of this class.
166  */
167  // Method defined in class to allow compiler optimization
168  // as this class is used repeatedly during the assembly
169  template <typename MatrixType>
170  void pushToClosedGlobal (std::shared_ptr<MatrixType> mat)
171  {
172  mat->sumIntoCoefficients ( M_nbRow, M_nbColumn,
173  rowIndices(), columnIndices(),
174  M_rawData, Epetra_FECrsMatrix::ROW_MAJOR);
175  }
176 
177  //! Ouput method for the sizes and the stored values
178  void showMe ( std::ostream& out = std::cout ) const;
179 
180  //@}
181 
182  //! @name Set Methods
183  //@{
184 
185  //! Setter for the value in the local position (iloc,jloc)
186  Real& element (const UInt& iloc, const UInt& jloc)
187  {
188  ASSERT (iloc < M_nbRow, "Try to access an element out of the elemental matrix (row)");
189  ASSERT (jloc < M_nbColumn, "Try to access an element out of the elemental matrix (column)");
190  return M_rawData[iloc][jloc];
191  }
192 
193  //! Setter for the global index corresponding to the iloc row of the local matrix
194  void setRowIndex (const UInt& iloc, const UInt& iglobal)
195  {
196  ASSERT (iloc < M_nbRow, "Try to set an index out of the elemental matrix (row)");
197  M_rowIndices[iloc] = iglobal;
198  }
199 
200  //! Setter for the global index of the rows of the local matrix
201  void setRowIndex (const std::vector<Int>& indicesVector)
202  {
203  M_rowIndices = indicesVector;
204  }
205 
206  //! Setter for the global index corresponding to the jloc column of the local matrix
207  void setColumnIndex (const UInt& jloc, const UInt& jglobal)
208  {
209  ASSERT (jloc < M_nbColumn, "Try to set an index out of the elemental matrix (row)");
210  M_columnIndices[jloc] = jglobal;
211  }
212 
213  //! Setter for the global index of the columns of the local matrix
214  void setColumnIndex (const std::vector<Int>& indicesVector)
215  {
216  M_columnIndices = indicesVector;
217  }
218 
219 
220  //@}
221 
222 
223  //! @name Get Methods
224  //@{
225 
226  //! Getter for the data stored in the given elemental position
227  const Real& element (const UInt& iloc, const UInt& jloc) const
228  {
229  ASSERT (iloc < M_nbRow, "Try to get an element out of the elemental matrix (row)");
230  ASSERT (jloc < M_nbColumn, "Try to get an element out of the elemental matrix (column)");
231  return M_rawData[iloc][jloc];
232  }
233 
234  //! Getter for the full set of data
235  Real* const* rawData() const
236  {
237  return M_rawData;
238  }
239 
240  //! Getter for the global indices of the rows
241  const std::vector<Int>& rowIndices() const
242  {
243  return M_rowIndices;
244  }
245 
246  //! Getter for the global indices of the columns
247  const std::vector<Int>& columnIndices() const
248  {
249  return M_columnIndices;
250  }
251 
252  //@}
253 
254 private:
255 
256  //! @name Private Methods
257  //@{
258 
259  //! No empty constructor, as we want at least the sizes to be defined.
261 
262  //! No need for an assignement operator
264 
265  //@}
266 
267  // Vectors storing the global indices corresponding to the entries stored.
268  // Here UInt would be more suitable, but it does not work with assembly functions.
271 
272  // Number of rows
274  // Number of columns
276 
277  // Raw data (stored as double pointer to avoid unnecessary conversions)
279 };
280 
281 }
282 #endif
Real *const * rawData() const
Getter for the full set of data.
const std::vector< Int > & columnIndices() const
Getter for the global indices of the columns.
const std::vector< Int > & rowIndices() const
Getter for the global indices of the rows.
void pushToClosedGlobal(MatrixType &mat)
Assembly procedure for a matrix or a block of a matrix.
void setRowIndex(const std::vector< Int > &indicesVector)
Setter for the global index of the rows of the local matrix.
std::vector< Int > M_columnIndices
void updateInverseJacobian(const UInt &iQuadPt)
void setRowIndex(const UInt &iloc, const UInt &iglobal)
Setter for the global index corresponding to the iloc row of the local matrix.
void showMe(std::ostream &out=std::cout) const
Ouput method for the sizes and the stored values.
ETMatrixElemental()
No empty constructor, as we want at least the sizes to be defined.
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
void zero()
Put zero all the data stored.
virtual ~ETMatrixElemental()
Destructor.
std::vector< Int > M_rowIndices
const Real & element(const UInt &iloc, const UInt &jloc) const
Getter for the data stored in the given elemental position.
void pushToGlobal(std::shared_ptr< MatrixType > mat)
Assembly procedure for a matrix or a block of a matrix passed in a shared_ptr.
ETMatrixElemental(const UInt &nbRow, const UInt &nbCol)
Constructor with the minimal interface: number of columns and of rows are provided.
void setColumnIndex(const UInt &jloc, const UInt &jglobal)
Setter for the global index corresponding to the jloc column of the local matrix. ...
ETMatrixElemental operator=(const ETMatrixElemental &)
No need for an assignement operator.
double Real
Generic real data.
Definition: LifeV.hpp:175
ETMatrixElemental(const ETMatrixElemental &mat)
Copy constructor (including deep copy of the data)
void setColumnIndex(const std::vector< Int > &indicesVector)
Setter for the global index of the columns of the local matrix.
void pushToClosedGlobal(std::shared_ptr< MatrixType > mat)
Assembly procedure for a matrix or a block of a matrix passed in a shared_ptr.
Real & element(const UInt &iloc, const UInt &jloc)
Setter for the value in the local position (iloc,jloc)
void pushToGlobal(MatrixType &mat)
Assembly procedure for a matrix or a block of a matrix.
class ETMatrixElemental A class for describing an elemental matrix
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191