44 #ifndef _fei_MatrixTraits_Epetra_h_ 45 #define _fei_MatrixTraits_Epetra_h_ 47 #include <fei_trilinos_macros.hpp> 49 #ifdef HAVE_FEI_EPETRA 55 #include <fei_MatrixTraits.hpp> 56 #include <snl_fei_BlockMatrixTraits.hpp> 57 #include <fei_VectorTraits_Epetra.hpp> 58 #include <fei_Include_Trilinos.hpp> 59 #include <fei_Vector_Impl.hpp> 69 struct MatrixTraits<Epetra_CrsMatrix> {
71 {
return(
"Epetra_CrsMatrix"); }
73 static double* getBeginPointer(Epetra_CrsMatrix* mat)
78 static int getOffset(Epetra_CrsMatrix* A,
int row,
int col)
80 const Epetra_Map& erowmap = A->RowMap();
81 const Epetra_Map& ecolmap = A->ColMap();
82 int local_row = erowmap.LID(row);
83 int local_col = ecolmap.LID(col);
88 A->ExtractCrsDataPointers(rowOffsets, colIndices, coefs);
90 int* row_ptr = &colIndices[rowOffsets[local_row]];
91 int* end_row = &colIndices[rowOffsets[local_row+1]];
94 for(; row_ptr != end_row; ++row_ptr) {
95 if (*row_ptr == local_col)
break;
99 return rowOffsets[local_row] + col_offset;
102 static int setValues(Epetra_CrsMatrix* mat,
double scalar)
104 return( mat->PutScalar(scalar) );
109 numRows = mat->NumMyRows();
113 static int getRowLength(Epetra_CrsMatrix* mat,
int row,
int& length)
115 length = mat->NumGlobalEntries(row);
116 if (length < 0)
return(-1);
121 int row,
int len,
double* coefs,
int* indices)
124 return(mat->ExtractGlobalRowCopy(row, len, dummy, coefs, indices));
128 int numRows,
const int* rows,
129 int numCols,
const int* cols,
130 const double*
const* values,
134 static std::vector<int> idx;
135 idx.resize(numRows+numCols);
136 int* idx_row = &idx[0];
137 int* idx_col = idx_row+numRows;
138 for(
int i=0; i<numRows; ++i) {
139 idx_row[i] = mat->RowMap().LID(rows[i]);
141 for(
int i=0; i<numCols; ++i) {
142 idx_col[i] = mat->ColMap().LID(cols[i]);
145 for(
int i=0; i<numRows; ++i) {
146 int err = mat->SumIntoMyValues(idx_row[i], numCols,
155 for(
int i=0; i<numRows; ++i) {
156 int err = mat->ReplaceMyValues(idx_row[i], numCols,
169 if (!mat->Filled()) {
170 int err = mat->FillComplete();
173 <<
" ERROR in mat->FillComplete" << FEI_ENDL;
178 if (!mat->StorageOptimized()) {
179 mat->OptimizeStorage();
185 static int matvec(Epetra_CrsMatrix* mat,
194 if (evx == NULL || evy == NULL) {
201 return( mat->Multiply(
false, *ex, *ey) );
215 struct BlockMatrixTraits<Epetra_VbrMatrix> {
217 {
return(
"Epetra_VbrMatrix"); }
219 static int putScalar(Epetra_VbrMatrix* mat,
double scalar)
221 return( mat->PutScalar(scalar) );
224 static int getRowLength(Epetra_VbrMatrix* mat,
int row,
int& length)
226 length = mat->NumGlobalBlockEntries(row);
232 const Epetra_Map& map = mat->RowMatrixRowMap();
233 int minLocalRow = map.MinMyGID();
234 int localRow = row - minLocalRow;
235 int error = mat->NumMyRowEntries(localRow, length);
240 int row,
int numBlkCols,
249 int error = mat->BeginExtractGlobalBlockRowCopy(row, numBlkCols,
253 if (error != 0 || checkRowDim != rowDim || blkRowLength != numBlkCols) {
258 for(
int i=0; i<numBlkCols; ++i) {
259 if (offset >= coefsLen) {
260 std::cerr <<
"BlockMatrixTraits::copyOutRow ran off end of coefs array." 264 int numValues = rowDim*colDims[i];
265 error = mat->ExtractEntryCopy(numValues, &(coefs[offset]),
277 int firstLocalOffset,
284 int error = mat->ExtractMyRowCopy(row-firstLocalOffset,
288 const Epetra_Map& colmap = mat->RowMatrixColMap();
289 for(
int i=0; i<len; ++i) {
290 indices[i] = colmap.GID(indices[i]);
296 static int sumIn(Epetra_VbrMatrix* mat,
300 const int* blockCols,
303 const double* values)
305 int err, voffset = 0;
306 for(
int j=0; j<numBlockCols; ++j) {
307 err = mat->DirectSubmitBlockEntry(blockRow, blockCols[j],
308 &(values[voffset]), LDA,
309 rowDim, colDims[j],
true);
310 if (err != 0)
return(err);
312 voffset += colDims[j]*LDA;
318 static int copyIn(Epetra_VbrMatrix* mat,
322 const int* blockCols,
325 const double* values)
327 int err, voffset = 0;
328 for(
int j=0; j<numBlockCols; ++j) {
329 err = mat->DirectSubmitBlockEntry(blockRow, blockCols[j],
330 &(values[voffset]), LDA,
331 rowDim, colDims[j],
false);
332 if (err != 0)
return(err);
334 voffset += colDims[j]*LDA;
340 static int sumIn(Epetra_VbrMatrix* mat,
347 const double*
const* values)
350 for(
int i=0; i<numCols; ++i) {
351 err = mat->DirectSubmitBlockEntry(row, cols[i], values[i],
352 LDAs[i], rowDim, colDims[i],
true);
353 if (err != 0)
return(err);
359 static int copyIn(Epetra_VbrMatrix* mat,
366 const double*
const* values)
369 for(
int i=0; i<numCols; ++i) {
370 err = mat->DirectSubmitBlockEntry(row, cols[i], values[i],
371 LDAs[i], rowDim, colDims[i],
false);
372 if (err != 0)
return(err);
380 return( mat->FillComplete() );
384 #endif //HAVE_FEI_EPETRA 385 #endif // _fei_MatrixTraits_Epetra_hpp_ static int getPointRowLength(T *, int, int &)
static int copyIn(T *, int, int, int, const int *, const int *, int, const double *)
static const char * typeName()
static int matvec(T *A, fei::Vector *x, fei::Vector *y)
static int getRowLength(T *mat, int row, int &length)
static int copyOutPointRow(T *, int, int, int, double *, int *, int &)
static int getNumLocalRows(T *mat, int &numRows)
static const char * typeName()
static int getRowLength(T *, int, int &)
static int putScalar(T *, double)
std::ostream & console_out()
static int copyOutRow(T *, int, int, int, int *, int *, double *, int, int &)
T * getUnderlyingVector()
static int setValues(T *mat, double scalar)
static int sumIn(T *, int, int, int, const int *, const int *, int, const double *)
static int copyOutRow(T *mat, int row, int len, double *coefs, int *indices)
static int putValuesIn(T *mat, int numRows, const int *rows, int numCols, const int *cols, const double *const *values, bool sum_into)
static int globalAssemble(T *A)
static int globalAssemble(T *)