//============================================================================== Epetra_CrsMatrix * Poisson2dOperator::GeneratePrecMatrix() const { // Generate a tridiagonal matrix as an Epetra_CrsMatrix // This method illustrates how to generate a matrix that is an approximation to the true // operator. Given this matrix, we can use any of the Aztec or IFPACK preconditioners. // Create a Epetra_Matrix Epetra_CrsMatrix * A = new Epetra_CrsMatrix(Copy, *map_, 3); int NumMyElements = map_->NumMyElements(); long long NumGlobalElements = map_->NumGlobalElements64(); // Add rows one-at-a-time double negOne = -1.0; double posTwo = 4.0; for (int i=0; i<NumMyElements; i++) { long long GlobalRow = A->GRID64(i); long long RowLess1 = GlobalRow - 1; long long RowPlus1 = GlobalRow + 1; if (RowLess1!=-1) A->InsertGlobalValues(GlobalRow, 1, &negOne, &RowLess1); if (RowPlus1!=NumGlobalElements) A->InsertGlobalValues(GlobalRow, 1, &negOne, &RowPlus1); A->InsertGlobalValues(GlobalRow, 1, &posTwo, &GlobalRow); } // Finish up A->FillComplete(); return(A); }