43 #include "Ifpack_ConfigDefs.h" 45 #include "Epetra_MultiVector.h" 46 #include "Epetra_Vector.h" 47 #include "Epetra_RowMatrix.h" 48 #include "Epetra_Map.h" 49 #include "Epetra_BlockMap.h" 50 #include "Ifpack_LocalFilter.h" 60 sprintf(Label_,
"%s",
"Ifpack_LocalFilter");
63 SerialComm_ = Teuchos::rcp(
new Epetra_MpiComm(MPI_COMM_SELF) );
65 SerialComm_ = Teuchos::rcp(
new Epetra_SerialComm );
69 NumRows_ = Matrix->NumMyRows();
72 Map_ = Teuchos::rcp(
new Epetra_Map(NumRows_,0,*SerialComm_) );
77 NumEntries_.resize(NumRows_);
80 Diagonal_ = Teuchos::rcp(
new Epetra_Vector(*Map_) );
81 if (Diagonal_ == Teuchos::null) IFPACK_CHK_ERRV(-5);
85 MaxNumEntriesA_ = Matrix->MaxNumEntries();
88 MaxNumEntries_ = Matrix->MaxNumEntries();
91 Indices_.resize(MaxNumEntries_);
92 Values_.resize(MaxNumEntries_);
101 int ActualMaxNumEntries = 0;
103 for (
int i = 0 ; i < NumRows_ ; ++i) {
107 IFPACK_CHK_ERRV(
ExtractMyRowCopy(i,MaxNumEntries_,Nnz,&Values_[0],&Indices_[0]));
109 for (
int j = 0 ; j < Nnz ; ++j) {
110 if (Indices_[j] < NumRows_ ) ++NewNnz;
112 if (Indices_[j] == i)
113 (*Diagonal_)[i] = Values_[j];
116 if (NewNnz > ActualMaxNumEntries)
117 ActualMaxNumEntries = NewNnz;
119 NumNonzeros_ += NewNnz;
120 NumEntries_[i] = NewNnz;
124 MaxNumEntries_ = ActualMaxNumEntries;
130 double *Values,
int * Indices)
const 132 if ((MyRow < 0) || (MyRow >= NumRows_)) {
136 if (Length < NumEntries_[MyRow])
143 int ierr = Matrix_->ExtractMyRowCopy(MyRow,MaxNumEntriesA_,Nnz,
144 &Values_[0],&Indices_[0]);
146 IFPACK_CHK_ERR(ierr);
151 for (
int j = 0 ; j < Nnz ; ++j) {
153 if (Indices_[j] < NumRows_ ) {
154 Indices[NumEntries] = Indices_[j];
155 Values[NumEntries] = Values_[j];
167 if (!Diagonal.Map().SameAs(*Map_))
169 Diagonal = *Diagonal_;
174 int Ifpack_LocalFilter::Apply(
const Epetra_MultiVector& X,
175 Epetra_MultiVector& Y)
const 181 int NumVectors = Y.NumVectors();
185 X.ExtractView(&X_ptr);
186 Y.ExtractView(&Y_ptr);
188 for (
int i = 0 ; i < NumRows_ ; ++i) {
191 int ierr = Matrix_->ExtractMyRowCopy(i,MaxNumEntriesA_,Nnz,&Values_[0],
193 IFPACK_CHK_ERR(ierr);
195 for (
int j = 0 ; j < Nnz ; ++j) {
196 if (Indices_[j] < NumRows_ ) {
197 for (
int k = 0 ; k < NumVectors ; ++k)
198 Y_ptr[k][i] += Values_[j] * X_ptr[k][Indices_[j]];
207 int Ifpack_LocalFilter::ApplyInverse(
const Epetra_MultiVector& X,
208 Epetra_MultiVector& Y)
const 214 const Epetra_BlockMap& Ifpack_LocalFilter::Map()
const virtual int ExtractDiagonalCopy(Epetra_Vector &Diagonal) const
Returns a copy of the main diagonal in a user-provided vector.
Ifpack_LocalFilter(const Teuchos::RefCountPtr< const Epetra_RowMatrix > &Matrix)
Constructor.
virtual int ExtractMyRowCopy(int MyRow, int Length, int &NumEntries, double *Values, int *Indices) const
Returns a copy of the specified local row in user-provided arrays.