36 #ifndef _MATRIX_BLOCK_MONOLITHIC_EPETRA_HPP_ 37 #define _MATRIX_BLOCK_MONOLITHIC_EPETRA_HPP_ 39 #include <boost/shared_ptr.hpp> 40 #include <lifev/core/array/MapEpetra.hpp> 41 #include <lifev/core/array/MapVector.hpp> 42 #include <lifev/core/array/MatrixEpetra.hpp> 43 #include <lifev/core/array/MatrixBlockMonolithicEpetraView.hpp> 69 template <
typename DataType>
70 class MatrixBlockMonolithicEpetra :
public MatrixEpetra<DataType>
74 typedef MatrixBlockMonolithicEpetraView<DataType> block_type;
75 typedef std::shared_ptr<block_type> block_ptrType;
81 MatrixBlockMonolithicEpetra (
const MapEpetra& map,
int numEntries = 50);
88 MatrixBlockMonolithicEpetra (
const MapVector<MapEpetra>& vector,
int numEntries = 50);
91 MatrixBlockMonolithicEpetra (
const MatrixEpetra<DataType>& matrix );
94 MatrixBlockMonolithicEpetra (
const MatrixBlockMonolithicEpetra& matrix );
97 ~MatrixBlockMonolithicEpetra();
109 void setBlockStructure (
const std::vector<UInt>& blockNumRows,
110 const std::vector<UInt>& blockNumColumns );
121 void setBlockStructure (
const MapVector<MapEpetra>& mapVector);
133 UInt blockNumRows (
const UInt& rowIndex)
const;
139 UInt blockNumColumns (
const UInt& columnIndex)
const;
147 void blockView (
const UInt& rowIndex,
148 const UInt& columnIndex,
158 block_ptrType block (
const UInt& rowIndex,
const UInt& columnIndex);
164 std::vector<UInt> M_blockNumRows;
165 std::vector<UInt> M_blockNumColumns;
166 std::vector<UInt> M_blockFirstRows;
167 std::vector<UInt> M_blockFirstColumns;
177 template <
typename DataType>
178 MatrixBlockMonolithicEpetra<DataType>::MatrixBlockMonolithicEpetra (
const MapEpetra& map,
int numEntries) :
179 MatrixEpetra<DataType> (map, numEntries),
180 M_blockNumRows (std::vector<UInt> (1, map.map (Unique)->NumGlobalElements() ) ),
181 M_blockNumColumns (std::vector<UInt> (1, map.map (Unique)->NumGlobalElements() ) ),
182 M_blockFirstRows (std::vector<UInt> (1, 0) ),
183 M_blockFirstColumns (std::vector<UInt> (1, 0) )
189 template <
typename DataType>
190 MatrixBlockMonolithicEpetra<DataType>::MatrixBlockMonolithicEpetra (
const MapVector<MapEpetra>& vector,
int numEntries)
192 MatrixEpetra<DataType> (vector.totalMap() )
195 ASSERT ( vector.nbMap() > 0 ,
"Map vector empty, impossible to construct a MatrixBlockMonolithicEpetra!");
197 MapEpetra myMap (vector.map (0) );
198 M_blockNumRows.push_back (vector.mapSize (0) );
199 M_blockNumColumns.push_back (vector.mapSize (0) );
200 M_blockFirstRows.push_back (0);
201 M_blockFirstColumns.push_back (0);
203 UInt totalRows (vector.mapSize (0) );
204 UInt totalColumns (vector.mapSize (0) );
206 for (UInt i (1); i < vector.nbMap(); ++i)
208 myMap += vector.map (i);
209 M_blockNumRows.push_back (vector.mapSize (i) );
210 M_blockNumColumns.push_back (vector.mapSize (i) );
211 M_blockFirstRows.push_back (totalRows);
212 M_blockFirstColumns.push_back (totalColumns);
214 totalRows += vector.mapSize (i);
215 totalColumns += vector.mapSize (i);
218 this->mapPtr().reset (
new MapEpetra (myMap) );
219 this->matrixPtr().reset (
new typename MatrixEpetra<DataType>::matrix_type ( Copy, *myMap.map ( Unique ), numEntries,
false) );
223 template <
typename DataType>
224 MatrixBlockMonolithicEpetra<DataType>::MatrixBlockMonolithicEpetra (
const MatrixEpetra<DataType>& matrix ) :
225 MatrixEpetra<DataType> (matrix),
229 M_blockFirstColumns()
232 template <
typename DataType>
233 MatrixBlockMonolithicEpetra<DataType>::MatrixBlockMonolithicEpetra (
const MatrixBlockMonolithicEpetra& matrix ) :
234 MatrixEpetra<DataType> (matrix),
235 M_blockNumRows (matrix.M_blockNumRows),
236 M_blockNumColumns (matrix.M_blockNumColumns),
237 M_blockFirstRows (matrix.M_blockFirstRows),
238 M_blockFirstColumns (matrix.M_blockFirstColumns)
241 template <
typename DataType>
242 MatrixBlockMonolithicEpetra<DataType>::~MatrixBlockMonolithicEpetra()
248 template <
typename DataType>
250 MatrixBlockMonolithicEpetra<DataType>::setBlockStructure (
const std::vector<UInt>& blockNumRows,
251 const std::vector<UInt>& blockNumColumns)
253 ASSERT ( blockNumRows.size() > 0,
"No way to build a matrix with 0 block rows");
254 ASSERT ( blockNumColumns.size() > 0,
"No way to build a matrix with 0 block columns")
257 M_blockNumRows = blockNumRows;
258 M_blockNumColumns = blockNumColumns;
260 M_blockFirstRows.resize (M_blockNumRows.size() );
261 M_blockFirstColumns.resize (M_blockNumColumns.size() );
263 UInt currentSize (0);
264 for (UInt i (0); i < blockNumRows.size(); ++i)
266 M_blockFirstRows[i] = currentSize;
267 currentSize += M_blockNumRows[i];
271 for (UInt i (0); i < blockNumColumns.size(); ++i)
273 M_blockFirstColumns[i] = currentSize;
274 currentSize += M_blockNumColumns[i];
278 template <
typename DataType>
280 MatrixBlockMonolithicEpetra<DataType>::setBlockStructure (
const MapVector<MapEpetra>& mapVector)
282 ASSERT ( mapVector.nbMap() > 0 ,
"Map vector empty, impossible to set the block structure");
284 M_blockNumRows.resize (mapVector.nbMap() );
285 M_blockNumColumns.resize (mapVector.nbMap() );
287 M_blockFirstRows.resize (mapVector.nbMap() );
288 M_blockFirstColumns.resize (mapVector.nbMap() );
292 for (UInt i (0); i < mapVector.nbMap(); ++i)
294 M_blockNumRows[i] = mapVector.mapSize (i);
295 M_blockNumColumns[i] = mapVector.mapSize (i);
297 M_blockFirstRows[i] = totalSize;
298 M_blockFirstColumns[i] = totalSize;
300 totalSize += mapVector.mapSize (i);
303 ASSERT (
this->matrixPtr()->NumGlobalCols() == totalSize,
" Incompatible block structure (global size does not match) ");
304 ASSERT (
this->matrixPtr()->NumGlobalRows() == totalSize,
" Incompatible block structure (global size does not match) ");
310 template <
typename DataType>
312 MatrixBlockMonolithicEpetra<DataType>::blockNumRows (
const UInt& rowIndex)
const 314 ASSERT (rowIndex < M_blockFirstRows.size(),
"Row index out of bound. No block to return");
316 return M_blockNumRows[rowIndex];
319 template <
typename DataType>
321 MatrixBlockMonolithicEpetra<DataType>::blockNumColumns (
const UInt& columnIndex)
const 323 ASSERT (columnIndex < M_blockFirstColumns.size(),
"Column index out of bound. No block to return");
325 return M_blockNumColumns[columnIndex];
328 template <
typename DataType>
330 MatrixBlockMonolithicEpetra<DataType>::blockView (
const UInt& rowIndex,
331 const UInt& columnIndex,
334 ASSERT (rowIndex < M_blockFirstRows.size(),
"Row index out of bound. No block to return");
335 ASSERT (columnIndex < M_blockFirstColumns.size(),
"Column index out of bound. No block to return");
337 mbv.setup (M_blockFirstRows[rowIndex],
338 M_blockFirstColumns[columnIndex],
339 M_blockNumRows[rowIndex],
340 M_blockNumColumns[columnIndex],
344 template <
typename DataType>
345 typename MatrixBlockMonolithicEpetra<DataType>::block_ptrType
346 MatrixBlockMonolithicEpetra<DataType>::block (
const UInt& rowIndex,
const UInt& columnIndex)
348 ASSERT (rowIndex < M_blockFirstRows.size(),
"Row index out of bound. No block to return");
349 ASSERT (columnIndex < M_blockFirstColumns.size(),
"Column index out of bound. No block to return");
351 block_ptrType mbv (
new block_type);
353 mbv->setup (M_blockFirstRows[rowIndex],
354 M_blockFirstColumns[columnIndex],
355 M_blockNumRows[rowIndex],
356 M_blockNumColumns[columnIndex],
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
uint32_type UInt
generic unsigned integer (used mainly for addressing)