MatrixEpetraStructuredView.hpp 9.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//@HEADER
/*
************************************************************************

 This file is part of the LifeV Applications.
 Copyright (C) 2001-2010 EPFL, Politecnico di Milano, INRIA

 This library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1 of the
 License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA

************************************************************************
*/
//@HEADER

/*!
28
29
   @file MatrixEpetraStructuredView.hpp
   @brief The file contains the MatrixEpetraStructuredView class
30
31
32
33
34
35

   @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
   @contributor Samuel Quinodoz <samuel.quinodoz@epfl.ch>
   @date 2010-10-09
 */

36
37
#ifndef _MATRIXEPETRASTRUCTUREDVIEW_HPP_
#define _MATRIXEPETRASTRUCTUREDVIEW_HPP_
38
39


40
#include <lifev/core/LifeV.hpp>
41

42
#include <lifev/core/array/MatrixEpetra.hpp>
43
44


Alessio Fumagalli's avatar
Alessio Fumagalli committed
45
46
namespace LifeV
{
47

48
//! MatrixEpetraStructuredView - class representing a block in a MatrixEpetraStructured
49
/*!
quinodoz's avatar
quinodoz committed
50
51
52
  @author Gwenol Grandperrin
  @author Samuel Quinodoz

53
  The MatrixEpetraStructuredView class contains data related
quinodoz's avatar
quinodoz committed
54
55
56
  to block of a matrix. It is useful to setup a clean and easy-to-use blocks management.

  For more information about the block structures in LifeV, see \ref BlockAlgebraPage "this page".
Gwenol Grandperrin's avatar
Gwenol Grandperrin committed
57
58
59
60
61
62
63

  <b> Remark </b>

  Using the operator "=" is not valid for this class! Indeed, copying the view
  would not copy the data stored in the matrix, which can be confusing. If the
  copy of the block is the intended use, one should use a method from the BlockUtils.

64
65
 */
template<typename DataType>
66
class MatrixEpetraStructuredView
67
68
69
70
71
72
{
public:

    /** @name Typedefs
     */
    //@{
73

74
    // Not a block matrix to avoid circular dependancies
75
    //typedef MatrixEpetraStructured<DataType> matrix_Type;
76
77
78
79

    typedef MatrixEpetra<DataType> matrix_Type;

    //@}
80
81
82
83
84
85


    /** @name Constructors, destructor
     */
    //@{
    //! default constructor.
86
    MatrixEpetraStructuredView();
87
88

    //! Copy constructor
Alessio Fumagalli's avatar
Alessio Fumagalli committed
89
    MatrixEpetraStructuredView ( const MatrixEpetraStructuredView<DataType>& matrixEpetraStructured );
90
91

    //! default virtual destructor
92
    ~MatrixEpetraStructuredView();
93
94
95
96
97
98

    //@}

    //! @name Methods
    //@{

99
    //! Print the informations about the MatrixEpetraStructuredView
Alessio Fumagalli's avatar
Alessio Fumagalli committed
100
    void showMe (std::ostream& output = std::cout) const;
101

Alessio Fumagalli's avatar
Alessio Fumagalli committed
102
103
104
105
106
    //! Function to assemble an elemental matrix in a block
    void addToCoefficients ( UInt const numRows, UInt const numColumns,
                             std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
                             DataType* const* const localValues,
                             Int format = Epetra_FECrsMatrix::COLUMN_MAJOR ) const;
107
108
109
110
111
    //! Function to assemble an elemental matrix in a block (for closed matrices)
    void sumIntoCoefficients ( UInt const numRows, UInt const numColumns,
                               std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
                               DataType* const* const localValues,
                               Int format = Epetra_FECrsMatrix::COLUMN_MAJOR ) const;
112
113
114
115
116
117
118
119
120
121
122
    //@}

    //! @name  Set Methods
    //@{
    /*! Set all the informations relative to the block
     *  @param firstRow First row in the block
     *  @param firstColumn First column in the block
     *  @param numRows Number of rows in the block
     *  @param numColumns Number of columns in the block
     *  @param A Matrix which contains the block
     */
Alessio Fumagalli's avatar
Alessio Fumagalli committed
123
124
125
126
127
    void setup ( const UInt& firstRow,
                 const UInt& firstColumn,
                 const UInt& numRows,
                 const UInt& numColumns,
                 matrix_Type* A );
128
129
130
131
132
133

    //@}

    //! @name  Get Methods
    //@{
    //! Returns the number of rows in the block
Alessio Fumagalli's avatar
Alessio Fumagalli committed
134
135
136
137
    UInt numRows() const
    {
        return M_numRows;
    }
138
139

    //! Returns the number of columns in the block
Alessio Fumagalli's avatar
Alessio Fumagalli committed
140
141
142
143
    UInt numColumns() const
    {
        return M_numColumns;
    }
144
145

    //! Returns the index of the first row in the block
Alessio Fumagalli's avatar
Alessio Fumagalli committed
146
147
148
149
    UInt firstRowIndex() const
    {
        return M_firstRowIndex;
    }
150
151

    //! Returns the index of the last row in the block
Alessio Fumagalli's avatar
Alessio Fumagalli committed
152
153
154
155
    UInt lastRowIndex() const
    {
        return M_lastRowIndex;
    }
156
157

    //! Returns the index of the first column in the block
Alessio Fumagalli's avatar
Alessio Fumagalli committed
158
159
160
161
    UInt firstColumnIndex() const
    {
        return M_firstColumnIndex;
    }
162
163

    //! Returns the index of the last column in the block
Alessio Fumagalli's avatar
Alessio Fumagalli committed
164
165
166
167
    UInt lastColumnIndex() const
    {
        return M_lastColumnIndex;
    }
168

169
170
171
    //! Return the fill-complete status of the inner Epetra_FECrsMatrix
    bool filled() const
    {
172
        return M_matrix->matrixPtr()->Filled();
173
174
    }

175
    //! Return the pointer of the full matrix
Alessio Fumagalli's avatar
Alessio Fumagalli committed
176
177
178
179
    matrix_Type* matrixPtr() const
    {
        return M_matrix;
    }
180
181
182
183

    //@}

private:
184
185
186
187
188

    //! @name Private Methods
    //@{

    //! No assignement operator, it is missleading (would copy the views, not the blocks!)
Alessio Fumagalli's avatar
Alessio Fumagalli committed
189
    MatrixEpetraStructuredView<DataType> operator= ( const MatrixEpetraStructuredView& otherView);
190
191
192
193

    //@}


194
195
196
197
198
199
    UInt M_numRows;
    UInt M_numColumns;
    UInt M_firstRowIndex;
    UInt M_lastRowIndex;
    UInt M_firstColumnIndex;
    UInt M_lastColumnIndex;
200
    matrix_Type* M_matrix;
201
202
203
204
205
206
207
};

// ===================================================
// Constructors & Destructor
// ===================================================

template<typename DataType>
208
MatrixEpetraStructuredView<DataType>::MatrixEpetraStructuredView() :
Alessio Fumagalli's avatar
Alessio Fumagalli committed
209
210
211
212
213
214
    M_numRows ( 0 ),
    M_numColumns ( 0 ),
    M_firstRowIndex ( 0 ),
    M_lastRowIndex ( 0 ),
    M_firstColumnIndex ( 0 ),
    M_lastColumnIndex ( 0 ),
215
216
217
218
219
220
    M_matrix()
{

}

template<typename DataType>
Alessio Fumagalli's avatar
Alessio Fumagalli committed
221
222
223
224
225
226
227
228
MatrixEpetraStructuredView<DataType>::MatrixEpetraStructuredView ( const MatrixEpetraStructuredView<DataType>& matrixEpetraStructured ) :
    M_numRows ( matrixEpetraStructured.M_numRows ),
    M_numColumns ( matrixEpetraStructured.M_numColumns ),
    M_firstRowIndex ( matrixEpetraStructured.M_firstRowIndex ),
    M_lastRowIndex ( matrixEpetraStructured.M_lastRowIndex ),
    M_firstColumnIndex ( matrixEpetraStructured.M_firstColumnIndex ),
    M_lastColumnIndex ( matrixEpetraStructured.M_lastColumnIndex ),
    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
241
242
243
244
}

// ===================================================
// Methods
// ===================================================

template<typename DataType>
void
Alessio Fumagalli's avatar
Alessio Fumagalli committed
245
MatrixEpetraStructuredView<DataType>::showMe ( std::ostream& output ) const
246
{
247
    output << "MatrixBlockMonolithicEpetraView informations:" << std::endl
248
249
250
251
252
253
254
           << "Size = " << M_numRows << " x " << M_numColumns << std::endl
           << "firstRow = " << M_firstRowIndex << std::endl
           << "lastRow = " << M_lastRowIndex << std::endl
           << "firstColumn = " << M_firstColumnIndex << std::endl
           << "lastColumn = " << M_lastColumnIndex << std::endl;
}

255
256
template<typename DataType>
void
257
MatrixEpetraStructuredView<DataType>::
Alessio Fumagalli's avatar
Alessio Fumagalli committed
258
259
260
261
addToCoefficients ( UInt const numRows, UInt const numColumns,
                    std::vector<Int> const& blockRowIndices, std::vector<Int> const& blockColumnIndices,
                    DataType* const* const localValues,
                    Int format) const
262
{
Alessio Fumagalli's avatar
Alessio Fumagalli committed
263
264
    std::vector<Int> rowIndices (blockRowIndices);
    std::vector<Int> columnIndices (blockColumnIndices);
265

Alessio Fumagalli's avatar
Alessio Fumagalli committed
266
    for (UInt i (0); i < numRows; ++i)
267
    {
Alessio Fumagalli's avatar
Alessio Fumagalli committed
268
        rowIndices[i] += M_firstRowIndex;
269
    }
Alessio Fumagalli's avatar
Alessio Fumagalli committed
270
    for (UInt i (0); i < numColumns; ++i)
271
    {
Alessio Fumagalli's avatar
Alessio Fumagalli committed
272
        columnIndices[i] += M_firstColumnIndex;
273
274
    }

Alessio Fumagalli's avatar
Alessio Fumagalli committed
275
276
277
    M_matrix->addToCoefficients (numRows, numColumns,
                                 rowIndices, columnIndices,
                                 localValues, format);
278
279
}

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
template<typename DataType>
void
MatrixEpetraStructuredView<DataType>::
sumIntoCoefficients ( UInt const numRows, UInt const numColumns,
                      std::vector<Int> const& blockRowIndices,
                      std::vector<Int> const& blockColumnIndices,
                      DataType* const* const localValues,
                      Int format) const
{
    std::vector<Int> rowIndices (blockRowIndices);
    std::vector<Int> columnIndices (blockColumnIndices);

    for (UInt i (0); i < numRows; ++i)
    {
        rowIndices[i] += M_firstRowIndex;
    }
    for (UInt i (0); i < numColumns; ++i)
    {
        columnIndices[i] += M_firstColumnIndex;
    }

    M_matrix->sumIntoCoefficients (numRows, numColumns,
                                   rowIndices, columnIndices,
                                   localValues, format);
}
305

306
307
308
309
310
311
// ===================================================
// Set Methods
// ===================================================

template<typename DataType>
void
Alessio Fumagalli's avatar
Alessio Fumagalli committed
312
313
314
315
316
MatrixEpetraStructuredView<DataType>::setup ( const UInt& firstRow,
                                              const UInt& firstColumn,
                                              const UInt& numRows,
                                              const UInt& numColumns,
                                              matrix_Type* A )
317
318
319
320
{
    M_numRows          = numRows;
    M_numColumns       = numColumns;
    M_firstRowIndex    = firstRow;
Alessio Fumagalli's avatar
Alessio Fumagalli committed
321
    M_lastRowIndex     = firstRow + numRows - 1;
322
    M_firstColumnIndex = firstColumn;
Alessio Fumagalli's avatar
Alessio Fumagalli committed
323
    M_lastColumnIndex  = firstColumn + numColumns - 1;
324
    M_matrix           = A;
325
326
327
328
329
330
331
332
}

// ===================================================
// Get Methods
// ===================================================

} // namespace LifeV

333
#endif /* _MATRIXEPETRASTRUCTUREDVIEW_HPP_ */
334