LifeV
MapVector.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 MapVector.hpp
29  @brief The file contains the MapVector class
30 
31  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
32  @date 2011-04-31
33  */
34 
35 
36 #ifndef MAP_VECTOR_HPP
37 #define MAP_VECTOR_HPP
38 
39 #include <lifev/core/LifeV.hpp>
40 
41 namespace LifeV
42 {
43 
44 //! This class is used to store maps that will be used for block defined problems.
45 /*!
46  This class consists in a collection of maps (e.g. LifeV::MapEpetra) to represent a problem made of several blocks.
47 
48  When a system is made of several blocks (like a Stokes problem, with the velocity block and pressure block), one might want to use a block matrix and block vector. This class represents the "map" to construct block structures.
49 
50  There are two operators to work with the maps: the "+" and the "|" operators. The "+" can be used to fusion two maps to create a bigger map (see the documentation of the related maps). The "|" is used to separate two maps for two different blocks. Starting from two maps (or a map and a vector of maps), it creates a vector of maps.
51 
52  Between the operators "+" and "|", the "+" has a higher priority, meaning that all the "+" are evaluated before the "|" are. However, it is strongly recommanded to use brackets (some compilers might issue warnings if brackets are not used).
53 
54  <b> Example of valid template argument </b>
55 
56  LifeV::MapEpetra
57 
58 */
59 
60 template< typename MapType>
61 class MapVector
62 {
63 
64 public:
65 
66  //! @name Public Types
67  //@{
68 
69  //! Type of the map
70  typedef MapType map_Type;
71 
72  //@}
73 
74 
75  //! @name Constructors & Destructor
76  //@{
77 
78  //! Empty constructor
79  MapVector();
80 
81  //! Copy constructor
82  /*!
83  @param otherMapVector The vector of maps to copy
84  */
85  MapVector (const MapVector<map_Type>& otherMapVector);
86 
87  //! Constructor with one map
88  /*!
89  This constructor builds a MapVector with only
90  the map given in arguement.
91  @param map The map to be put in the vector
92  */
93  explicit MapVector (const map_Type& map);
94 
95  //! Constructor with two maps
96  /*!
97  The MapVector is filled with the two maps given in argument.
98  @param map1 The first map of the vector
99  @param map2 The second map of the vector
100  */
101  MapVector (const map_Type& map1, const map_Type& map2);
102 
103  //! Concatenation constructor
104  /*!
105  This constructor copies the maps in vector and adds the map to it.
106  @param vector The vector to copy
107  @param map The map to add to vector
108  */
109  MapVector (const MapVector<map_Type>& vector, const map_Type& map);
110 
111  //! Destructor
112  ~MapVector();
113 
114  //@}
115 
116 
117  //! @name Operators
118  //@{
119 
120  //! Assignement operator
121  /*
122  @param vector The MapVector to copy
123  @return This MapVector
124  */
125  MapVector<map_Type> operator= (const MapVector<map_Type>& vector);
126 
127  //! Access to the ith map (read only)
128  /*
129  @param i The index of the map
130  @return The ith map stored
131  */
132  const map_Type& operator[] (UInt i) const;
133 
134  //! Access to the ith map (read-write)
135  /*
136  @param i The index of the map
137  @return The ith map stored
138  */
139  map_Type& operator[] (UInt i);
140 
141  //! Juxtaposition operator for a vector of maps and a map
142  /*
143  @param map The map to be added
144  @return MapVector resulting of the concatenation of this MapVector and the map
145  given in argument
146  */
148  operator| (const map_Type& map) const;
149 
150  //@}
151 
152 
153  //! @name Methods
154  //@{
155 
156  //! Returns the number of maps stored
157  UInt nbMap() const;
158 
159  //! Returns the size of the ith map stored (global number of ids)
160  UInt mapSize (UInt i) const;
161 
162  //! Display internal state
163  void showMe ( std::ostream& output = std::cout) const;
164 
165  //! Return the map made by concatenating all the maps of the vector
166  map_Type totalMap() const;
167 
168  //! Add a map into this vector (at the end of the vector)
169  void addMap (const map_Type& newMap);
170 
171  //@}
172 
173 
174  //! @name Get Methods
175  //@{
176 
177  //! Getter for the ith map stored
178  const map_Type& map (const UInt& i) const;
179 
180  //@}
181 
182 
183 private:
184 
185  // The vector containing the maps
187 };
188 
189 
190 // ===================================================
191 // Constructors & Destructor
192 // ===================================================
193 
194 template< typename MapType>
195 MapVector<MapType>::
197  : M_vector()
198 {}
199 
200 template< typename MapType>
201 MapVector<MapType>::
202 MapVector (const MapVector<map_Type>& otherMapVector)
204 {}
205 
206 template< typename MapType>
207 MapVector<MapType>::
208 MapVector (const map_Type& map)
209  : M_vector (1, map)
210 {}
211 
212 template< typename MapType>
213 MapVector<MapType>::
214 MapVector (const map_Type& map1, const map_Type& map2)
215  : M_vector()
216 {
217  M_vector.push_back (map1);
218  M_vector.push_back (map2);
219 }
220 
221 template< typename MapType>
222 MapVector<MapType>::
223 MapVector (const MapVector<map_Type>& vector, const map_Type& map)
225 {
226  M_vector.push_back (map);
227 }
228 
229 template< typename MapType>
230 MapVector<MapType>::
232 {}
233 
234 // ===================================================
235 // Operators
236 // ===================================================
237 
238 template< typename MapType>
239 MapVector<MapType>
240 MapVector<MapType>::
241 operator= (const MapVector<map_Type>& vector)
242 {
243  M_vector = vector.M_vector;
244  return *this;
245 }
246 
247 template< typename MapType>
248 const MapType&
249 MapVector<MapType>::
250 operator[] (UInt i) const
251 {
252  ASSERT ( i < M_vector.size() , "Index out of bound, no map to access (Read only)");
253  return M_vector[i];
254 }
255 
256 template< typename MapType>
257 MapType&
258 MapVector<MapType>::
260 {
261  ASSERT ( i < M_vector.size() , "Index out of bound, no map to access (Read write)");
262  return M_vector[i];
263 }
264 
265 template< typename MapType>
266 MapVector<MapType>
267 MapVector<MapType>::
268 operator| (const map_Type& map) const
269 {
270  return MapVector<map_Type> (*this, map);
271 }
272 
273 // ===================================================
274 // Methods
275 // ===================================================
276 
277 template< typename MapType>
278 UInt
279 MapVector<MapType>::
280 nbMap() const
281 {
282  return M_vector.size();
283 }
284 
285 template< typename MapType>
286 UInt
287 MapVector<MapType>::
288 mapSize (UInt i) const
289 {
290  ASSERT ( i < M_vector.size() , "Index out of bound, no map to return");
291  return M_vector[i].mapSize();
292 }
293 
294 template< typename MapType>
295 void
296 MapVector<MapType>::
297 showMe ( std::ostream& output) const
298 {
299  output << " Number of map stored : " << M_vector.size() << std::endl;
300 }
301 
302 template< typename MapType>
303 MapType
304 MapVector<MapType>::
305 totalMap() const
306 {
307  ASSERT ( M_vector.size() != 0 , "No map to concatenate for the total map");
308  map_Type total (M_vector[0]);
309 
310  for (UInt i (1); i < M_vector.size(); ++i)
311  {
312  total += M_vector[i];
313  }
314  return total;
315 }
316 
317 template< typename MapType>
318 void
319 MapVector<MapType>::
320 addMap (const map_Type& newMap)
321 {
322  M_vector.push_back (newMap);
323 }
324 
325 // ===================================================
326 // Get Methods
327 // ===================================================
328 
329 template< typename MapType>
330 const MapType&
331 MapVector<MapType>::
332 map (const UInt& i) const
333 {
334  ASSERT ( i < M_vector.size() , "Index out of bound, no map to return");
335  return M_vector[i];
336 }
337 
338 
339 } // End of the namespace
340 
341 #endif
MapVector(const map_Type &map1, const map_Type &map2)
Constructor with two maps.
Definition: MapVector.hpp:214
UInt nbMap() const
Returns the number of maps stored.
Definition: MapVector.hpp:280
void addMap(const map_Type &newMap)
Add a map into this vector (at the end of the vector)
Definition: MapVector.hpp:320
std::vector< map_Type > M_vector
Definition: MapVector.hpp:186
MapVector(const map_Type &map)
Constructor with one map.
Definition: MapVector.hpp:208
const map_Type & operator[](UInt i) const
Access to the ith map (read only)
Definition: MapVector.hpp:250
MapVector< map_Type > operator|(const map_Type &map) const
Juxtaposition operator for a vector of maps and a map.
Definition: MapVector.hpp:268
MapVector< map_Type > operator=(const MapVector< map_Type > &vector)
Assignement operator.
Definition: MapVector.hpp:241
map_Type totalMap() const
Return the map made by concatenating all the maps of the vector.
Definition: MapVector.hpp:305
MapVector()
Empty constructor.
Definition: MapVector.hpp:196
void updateInverseJacobian(const UInt &iQuadPt)
MapType map_Type
Type of the map.
Definition: MapVector.hpp:70
void showMe(std::ostream &output=std::cout) const
Display internal state.
Definition: MapVector.hpp:297
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
MapVector(const MapVector< map_Type > &otherMapVector)
Copy constructor.
Definition: MapVector.hpp:202
MapVector(const MapVector< map_Type > &vector, const map_Type &map)
Concatenation constructor.
Definition: MapVector.hpp:223
const map_Type & map(const UInt &i) const
Getter for the ith map stored.
Definition: MapVector.hpp:332
This class is used to store maps that will be used for block defined problems.
Definition: MapVector.hpp:61
~MapVector()
Destructor.
Definition: MapVector.hpp:231
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
map_Type & operator[](UInt i)
Access to the ith map (read-write)
Definition: MapVector.hpp:259
UInt mapSize(UInt i) const
Returns the size of the ith map stored (global number of ids)
Definition: MapVector.hpp:288