LifeV
ETVectorElemental.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 ETVectorElemental class
31 
32  @date 06/2011
33  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
34  */
35 
36 #ifndef ET_VECTOR_ELEMENTAL_HPP
37 #define ET_VECTOR_ELEMENTAL_HPP
38 
39 #include <vector>
40 
41 #include <boost/shared_ptr.hpp>
42 
43 #include <lifev/core/LifeV.hpp>
44 
45 namespace LifeV
46 {
47 
48 //! class ETVectorElemental A class for describing an elemental vector
49 /*!
50  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
51 
52  This class is meant to represent an ETVectorElemental. It contains mainly:
53 
54  <ol>
55  <li> Simple constructors
56  <li> Methods to access and modify the indexes
57  <li> Methods to store and access the entries
58  <li> Assembly methods to put the local entries in a global vector
59  </ol>
60 
61 */
63 {
64 
65 public:
66 
67  //! @name Constructors & Destructor
68  //@{
69 
70  //! Constructor with the minimal interface: number of rows has to be provided.
71  explicit ETVectorElemental (const UInt& nbRow)
72  : M_rowIndices (nbRow, 0),
73  M_nbRow (nbRow),
74  M_rawData (new Real[nbRow])
75  {
76  zero();
77  }
78 
79  //! Copy constructor (including deep copy of the data)
82  M_nbRow (vec.M_nbRow),
83  M_rawData ( new Real[M_nbRow])
84  {
85  for (UInt iRow (0); iRow < M_nbRow; ++iRow)
86  {
87  M_rawData[iRow] = vec.M_rawData[iRow];
88  }
89  }
90 
91  //! Destructor
93  {
94  delete [] M_rawData;
95  }
96 
97  //@}
98 
99 
100  //! @name Operators
101  //@{
102 
103  //! Operator to access (read-only) the iloc-th element
104  const Real& operator[] (const UInt& iloc) const
105  {
106  ASSERT (iloc < M_nbRow, "Access out of range");
107  return M_rawData[iloc];
108  }
109 
110  //! Operator to access (read-write) the iloc-th element
111  Real& operator[] (const UInt& iloc)
112  {
113  ASSERT (iloc < M_nbRow, "Access out of range");
114  return M_rawData[iloc];
115  }
116 
117  //@}
118 
119 
120  //! @name Methods
121  //@{
122 
123  //! Put zero all the data stored
124  void zero()
125  {
126  for (UInt i (0); i < M_nbRow; ++i)
127  {
128  M_rawData[i] = 0.0;
129  }
130  }
131 
132  //! Assembly procedure for a vector or a block of a vector
133  /*!
134  This method puts the values stored in this elemental vector into the global
135  vector passed as arguement, using the positions given in the global indices
136  stored in this elemental vector.
137  */
138  template <typename VectorType>
139  void pushToGlobal (VectorType& vec)
140  {
141  for (UInt iRow (0); iRow < M_nbRow; ++iRow)
142  {
143  vec.sumIntoGlobalValues ( M_rowIndices[iRow], M_rawData[iRow] );
144  }
145  }
146 
147  //! Assembly procedure for a vector or a block of a vector passed in a shared_ptr
148  /*!
149  This method puts the values stored in this elemental vector into the global
150  vector passed as argument, using the positions given in the global indices
151  stored in this elemental vector.
152 
153  This is a partial specialization of the other assembly procedure of this class.
154  */
155  template <typename VectorType>
156  void globalAssembly (std::shared_ptr<VectorType> vec)
157  {
158  for (UInt iRow (0); iRow < M_nbRow; ++iRow)
159  {
160  vec->sumIntoGlobalValues ( M_rowIndices[iRow], M_rawData[iRow] );
161  }
162  }
163 
164 
165  //! Ouput method for the sizes and the stored values
166  void showMe ( std::ostream& out = std::cout ) const
167  {
168  out << " Elemental vector : Size " << M_nbRow << std::endl;
169  for (UInt i (0); i < M_nbRow; ++i)
170  {
171  out << "[" << i << "] " << M_rawData[i] << " ";
172  }
173  out << std::endl;
174  }
175 
176  //@}
177 
178  //! @name Set Methods
179  //@{
180 
181  //! Setter for the value in the local position (iloc)
182  Real& element (const UInt& iloc)
183  {
184  ASSERT (iloc < M_nbRow, "Access out of range");
185  return M_rawData[iloc];
186  }
187 
188  //! Setter for the global index corresponding to the iloc row of the local vector
189  void setRowIndex (const UInt& iloc, const UInt& iglobal)
190  {
191  M_rowIndices[iloc] = iglobal;
192  }
193 
194  //! Setter for all the global indices using a std::vector
195  void setRowIndex (const std::vector<Int>& indicesVector)
196  {
197  M_rowIndices = indicesVector;
198  }
199 
200  //@}
201 
202 
203  //! @name Get Methods
204  //@{
205 
206  //! Getter for the data stored in the given elemental position
207  const Real& element (const UInt& iloc) const
208  {
209  ASSERT (iloc < M_nbRow, "Access out of range");
210  return M_rawData[iloc];
211  }
212 
213  //! Getter for the full set of data
214  Real* rawData() const
215  {
216  return M_rawData;
217  }
218 
219 
220  //! Getter for the global indices of the rows
221  const std::vector<Int>& rowIndices() const
222  {
223  return M_rowIndices;
224  }
225 
226  //@}
227 
228 private:
229 
230  //! @name Private Methods
231  //@{
232 
233  //! No empty constructor, as we want at least the sizes to be defined.
235 
236  //! No need for an assignement operator
238 
239  //@}
240 
241  // Vectors storing the global indices corresponding to the entries stored
242  // Here UInt would be more suitable, but it does not work with assembly functions.
244 
245  // Number of rows
247 
248  // Raw data
250 };
251 
252 }
253 #endif
void showMe(std::ostream &out=std::cout) const
Ouput method for the sizes and the stored values.
class ETVectorElemental A class for describing an elemental vector
const Real & element(const UInt &iloc) const
Getter for the data stored in the given elemental position.
ETVectorElemental(const UInt &nbRow)
Constructor with the minimal interface: number of rows has to be provided.
Real * rawData() const
Getter for the full set of data.
void globalAssembly(std::shared_ptr< VectorType > vec)
Assembly procedure for a vector or a block of a vector passed in a shared_ptr.
const Real & operator[](const UInt &iloc) const
Operator to access (read-only) the iloc-th element.
Real & element(const UInt &iloc)
Setter for the value in the local position (iloc)
void updateInverseJacobian(const UInt &iQuadPt)
void zero()
Put zero all the data stored.
Real & operator[](const UInt &iloc)
Operator to access (read-write) the iloc-th element.
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
ETVectorElemental()
No empty constructor, as we want at least the sizes to be defined.
void pushToGlobal(VectorType &vec)
Assembly procedure for a vector or a block of a vector.
void setRowIndex(const UInt &iloc, const UInt &iglobal)
Setter for the global index corresponding to the iloc row of the local vector.
double Real
Generic real data.
Definition: LifeV.hpp:175
ETVectorElemental(const ETVectorElemental &vec)
Copy constructor (including deep copy of the data)
const std::vector< Int > & rowIndices() const
Getter for the global indices of the rows.
ETVectorElemental operator=(const ETVectorElemental &)
No need for an assignement operator.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
void setRowIndex(const std::vector< Int > &indicesVector)
Setter for all the global indices using a std::vector.
std::vector< Int > M_rowIndices