IFPACK  Development
Ifpack_LocalFilter.h
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK_LOCALFILTER_H
44 #define IFPACK_LOCALFILTER_H
45 
46 #include "Ifpack_ConfigDefs.h"
47 #ifdef HAVE_MPI
48 #include "Epetra_MpiComm.h"
49 #else
50 #include "Epetra_SerialComm.h"
51 #endif
52 #include "Epetra_RowMatrix.h"
53 #include "Teuchos_RefCountPtr.hpp"
54 
55 class Epetra_Map;
56 class Epetra_MultiVector;
57 class Epetra_Vector;
58 class Epetra_Import;
59 class Epetra_BlockMap;
60 
62 
98 class Ifpack_LocalFilter : public virtual Epetra_RowMatrix {
99 
100 public:
102  Ifpack_LocalFilter(const Teuchos::RefCountPtr<const Epetra_RowMatrix>& Matrix);
104 
106 
107  virtual ~Ifpack_LocalFilter() {};
109 
111 
113 
115 
123  virtual int NumMyRowEntries(int MyRow, int & NumEntries) const
124  {
125  NumEntries = NumEntries_[MyRow];
126  return(0);
127  }
128 
130  virtual int MaxNumEntries() const
131  {
132  return(MaxNumEntries_);
133  }
134 
136 
150  virtual int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const;
151 
153 
159  virtual int ExtractDiagonalCopy(Epetra_Vector & Diagonal) const;
161 
163 
165 
175  virtual int Multiply(bool TransA, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
176  {
177  if (TransA == true) {
178  IFPACK_CHK_ERR(-1);
179  }
180 
181  IFPACK_CHK_ERR(Apply(X,Y));
182  return(0);
183  }
184 
186  virtual int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector& X,
187  Epetra_MultiVector& Y) const
188  {
189  IFPACK_RETURN(-1); // not implemented
190  }
191 
192  virtual int Apply(const Epetra_MultiVector& X,
193  Epetra_MultiVector& Y) const;
194 
195  virtual int ApplyInverse(const Epetra_MultiVector& X,
196  Epetra_MultiVector& Y) const;
198  virtual int InvRowSums(Epetra_Vector& x) const
199  {
200  IFPACK_RETURN(-1); // not implemented
201  }
202 
204  virtual int LeftScale(const Epetra_Vector& x)
205  {
206  IFPACK_RETURN(-1); // not implemented
207  }
208 
210  virtual int InvColSums(Epetra_Vector& x) const
211  {
212  IFPACK_RETURN(-1); // not implemented
213  }
214 
215 
217  virtual int RightScale(const Epetra_Vector& x)
218  {
219  IFPACK_RETURN(-1); // not implemented
220  }
221 
223 
225 
227  virtual bool Filled() const
228  {
229  return true;
230  }
231 
233  /* Returns the quantity \f$ \| A \|_\infty\f$ such that
234  \f[\| A \|_\infty = \max_{1\lei\len} \sum_{i=1}^m |a_{ij}| \f].
235  */
236  virtual double NormInf() const
237  {
238  return(-1.0);
239  }
240 
242  /* Returns the quantity \f$ \| A \|_1\f$ such that
243  \f[\| A \|_1= \max_{1\lej\len} \sum_{j=1}^n |a_{ij}| \f].
244  */
245  virtual double NormOne() const
246  {
247  IFPACK_RETURN(-1.0);
248  }
249 
250 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
251  virtual int NumGlobalNonzeros() const
253  {
254  return(NumNonzeros_);
255  }
256 
258  virtual int NumGlobalRows() const
259  {
260  return(NumRows_);
261  }
262 
264  virtual int NumGlobalCols() const
265  {
266  return(NumRows_);
267  }
268 
270  virtual int NumGlobalDiagonals() const
271  {
272  return(NumRows_);
273  }
274 #endif
275 
277  virtual long long NumGlobalNonzeros64() const
278  {
279  return(NumNonzeros_);
280  }
281 
283  virtual long long NumGlobalRows64() const
284  {
285  return(NumRows_);
286  }
287 
289  virtual long long NumGlobalCols64() const
290  {
291  return(NumRows_);
292  }
293 
295  virtual long long NumGlobalDiagonals64() const
296  {
297  return(NumRows_);
298  }
299 
301  virtual int NumMyNonzeros() const
302  {
303  return(NumNonzeros_);
304  }
305 
307  virtual int NumMyRows() const
308  {
309  return(NumRows_);
310  }
311 
313  virtual int NumMyCols() const
314  {
315  return(NumRows_);
316  }
317 
319  virtual int NumMyDiagonals() const
320  {
321  return(NumRows_);
322  }
323 
325  virtual bool LowerTriangular() const
326  {
327  return(Matrix_->LowerTriangular());
328  }
329 
331  virtual bool UpperTriangular() const
332  {
333  return(Matrix_->UpperTriangular());
334  }
335 
337  virtual const Epetra_Map & RowMatrixRowMap() const
338  {
339  return(*Map_);
340  }
341 
343  virtual const Epetra_Map & RowMatrixColMap() const
344  {
345  return(*Map_);
346  }
347 
349  virtual const Epetra_Import * RowMatrixImporter() const
350  {
351  return(0);
352  }
354 
355  // following functions are required to derive Epetra_RowMatrix objects.
356 
358  int SetOwnership(bool ownership)
359  {
360  IFPACK_RETURN(-1);
361  }
362 
364  int SetUseTranspose(bool UseTranspose_in)
365  {
366  UseTranspose_ = UseTranspose_in;
367  return(0);
368  }
369 
371  bool UseTranspose() const
372  {
373  return(UseTranspose_);
374  }
375 
377  bool HasNormInf() const
378  {
379  return(false);
380  }
381 
383  const Epetra_Comm & Comm() const
384  {
385  return(*SerialComm_);
386  }
387 
390  {
391  return(*Map_);
392  }
393 
395  const Epetra_Map & OperatorRangeMap() const
396  {
397  return(*Map_);
398  }
400 
401 const Epetra_BlockMap& Map() const;
402 
403 const char* Label() const{
404  return(Label_);
405 };
406 
407 private:
408 
410  Teuchos::RefCountPtr<const Epetra_RowMatrix> Matrix_;
411 #ifdef HAVE_MPI
412  Teuchos::RefCountPtr<Epetra_MpiComm> SerialComm_;
414 #else
415  Teuchos::RefCountPtr<Epetra_SerialComm> SerialComm_;
417 #endif
418  Teuchos::RefCountPtr<Epetra_Map> Map_;
421  int NumRows_;
423  int NumNonzeros_;
425  int MaxNumEntries_;
427  int MaxNumEntriesA_;
429  std::vector<int> NumEntries_;
431  mutable std::vector<int> Indices_;
433  mutable std::vector<double> Values_;
435  bool UseTranspose_;
437  char Label_[80];
438  Teuchos::RefCountPtr<Epetra_Vector> Diagonal_;
439  /* unused (comment out to avoid build warnings)
440  double NormOne_;
441  double NormInf_;
442  */
443 };
444 
445 #endif /* IFPACK_LOCALFILTER_H */
Ifpack_LocalFilter::ExtractMyRowCopy
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.
Definition: Ifpack_LocalFilter.cpp:131
Ifpack_LocalFilter::NumGlobalCols64
virtual long long NumGlobalCols64() const
Returns the number of global matrix columns.
Definition: Ifpack_LocalFilter.h:289
Ifpack_LocalFilter::NumGlobalCols
virtual int NumGlobalCols() const
Returns the number of global matrix columns.
Definition: Ifpack_LocalFilter.h:264
Ifpack_LocalFilter::OperatorDomainMap
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
Definition: Ifpack_LocalFilter.h:389
Ifpack_LocalFilter::NumGlobalDiagonals64
virtual long long NumGlobalDiagonals64() const
Returns the number of global nonzero diagonal entries, based on global row/column index comparisons.
Definition: Ifpack_LocalFilter.h:295
Ifpack_LocalFilter::RowMatrixRowMap
virtual const Epetra_Map & RowMatrixRowMap() const
Returns the Epetra_Map object associated with the rows of this matrix.
Definition: Ifpack_LocalFilter.h:337
Ifpack_LocalFilter::RowMatrixImporter
virtual const Epetra_Import * RowMatrixImporter() const
Returns the Epetra_Import object that contains the import operations for distributed operations.
Definition: Ifpack_LocalFilter.h:349
Ifpack_LocalFilter::NumGlobalRows64
virtual long long NumGlobalRows64() const
Returns the number of global matrix rows.
Definition: Ifpack_LocalFilter.h:283
Ifpack_LocalFilter::NumGlobalNonzeros
virtual int NumGlobalNonzeros() const
Returns the number of nonzero entries in the global matrix.
Definition: Ifpack_LocalFilter.h:252
Ifpack_LocalFilter::NumMyRows
virtual int NumMyRows() const
Returns the number of matrix rows owned by the calling processor.
Definition: Ifpack_LocalFilter.h:307
Ifpack_LocalFilter::NumMyDiagonals
virtual int NumMyDiagonals() const
Returns the number of local nonzero diagonal entries, based on global row/column index comparisons.
Definition: Ifpack_LocalFilter.h:319
Ifpack_LocalFilter::OperatorRangeMap
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
Definition: Ifpack_LocalFilter.h:395
Ifpack_LocalFilter
Ifpack_LocalFilter a class for light-weight extraction of the submatrix corresponding to local rows a...
Definition: Ifpack_LocalFilter.h:98
Ifpack_LocalFilter::RowMatrixColMap
virtual const Epetra_Map & RowMatrixColMap() const
Returns the Epetra_Map object associated with the columns of this matrix.
Definition: Ifpack_LocalFilter.h:343
Ifpack_LocalFilter::Ifpack_LocalFilter
Ifpack_LocalFilter(const Teuchos::RefCountPtr< const Epetra_RowMatrix > &Matrix)
Constructor.
Definition: Ifpack_LocalFilter.cpp:53
Epetra_Comm
Ifpack_LocalFilter::Comm
const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
Definition: Ifpack_LocalFilter.h:383
Ifpack_LocalFilter::ExtractDiagonalCopy
virtual int ExtractDiagonalCopy(Epetra_Vector &Diagonal) const
Returns a copy of the main diagonal in a user-provided vector.
Definition: Ifpack_LocalFilter.cpp:167
Ifpack_LocalFilter::NumMyCols
virtual int NumMyCols() const
Returns the number of matrix columns owned by the calling processor.
Definition: Ifpack_LocalFilter.h:313
Ifpack_LocalFilter::HasNormInf
bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
Definition: Ifpack_LocalFilter.h:377
Ifpack_LocalFilter::UpperTriangular
virtual bool UpperTriangular() const
If matrix is upper triangular in local index space, this query returns true, otherwise it returns fal...
Definition: Ifpack_LocalFilter.h:331
Ifpack_LocalFilter::NumGlobalDiagonals
virtual int NumGlobalDiagonals() const
Returns the number of global nonzero diagonal entries, based on global row/column index comparisons.
Definition: Ifpack_LocalFilter.h:270
Ifpack_LocalFilter::MaxNumEntries
virtual int MaxNumEntries() const
Returns the maximum of NumMyRowEntries() over all rows.
Definition: Ifpack_LocalFilter.h:130
Ifpack_LocalFilter::Multiply
virtual int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_RowMatrix multiplied by a Epetra_MultiVector X in Y.
Definition: Ifpack_LocalFilter.h:175
Ifpack_LocalFilter::RightScale
virtual int RightScale(const Epetra_Vector &x)
Scales the Epetra_RowMatrix on the right with a Epetra_Vector x (NOT IMPLEMENTED).
Definition: Ifpack_LocalFilter.h:217
Ifpack_LocalFilter::NormInf
virtual double NormInf() const
Returns the infinity norm of the global matrix.
Definition: Ifpack_LocalFilter.h:236
Ifpack_LocalFilter::Solve
virtual int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns result of a local-only solve using a triangular Epetra_RowMatrix with Epetra_MultiVectors X a...
Definition: Ifpack_LocalFilter.h:186
Ifpack_LocalFilter::NumMyNonzeros
virtual int NumMyNonzeros() const
Returns the number of nonzero entries in the calling processor's portion of the matrix.
Definition: Ifpack_LocalFilter.h:301
Epetra_RowMatrix
Ifpack_LocalFilter::SetOwnership
int SetOwnership(bool ownership)
Sets ownership.
Definition: Ifpack_LocalFilter.h:358
Ifpack_LocalFilter::LowerTriangular
virtual bool LowerTriangular() const
If matrix is lower triangular in local index space, this query returns true, otherwise it returns fal...
Definition: Ifpack_LocalFilter.h:325
Ifpack_LocalFilter::NumGlobalNonzeros64
virtual long long NumGlobalNonzeros64() const
Returns the number of nonzero entries in the global matrix.
Definition: Ifpack_LocalFilter.h:277
Ifpack_LocalFilter::NormOne
virtual double NormOne() const
Returns the one norm of the global matrix.
Definition: Ifpack_LocalFilter.h:245
Epetra_BlockMap
Epetra_Vector
Ifpack_LocalFilter::LeftScale
virtual int LeftScale(const Epetra_Vector &x)
Scales the Epetra_RowMatrix on the left with a Epetra_Vector x (NOT IMPLEMENTED).
Definition: Ifpack_LocalFilter.h:204
Epetra_MultiVector
Ifpack_LocalFilter::Filled
virtual bool Filled() const
If FillComplete() has been called, this query returns true, otherwise it returns false.
Definition: Ifpack_LocalFilter.h:227
Ifpack_LocalFilter::~Ifpack_LocalFilter
virtual ~Ifpack_LocalFilter()
Destructor.
Definition: Ifpack_LocalFilter.h:108
Ifpack_LocalFilter::UseTranspose
bool UseTranspose() const
Returns the current UseTranspose setting.
Definition: Ifpack_LocalFilter.h:371
Ifpack_LocalFilter::NumMyRowEntries
virtual int NumMyRowEntries(int MyRow, int &NumEntries) const
Returns the number of nonzero entries in MyRow.
Definition: Ifpack_LocalFilter.h:123
Ifpack_LocalFilter::InvColSums
virtual int InvColSums(Epetra_Vector &x) const
Computes the sum of absolute values of the columns of the Epetra_RowMatrix, results returned in x (NO...
Definition: Ifpack_LocalFilter.h:210
Ifpack_LocalFilter::InvRowSums
virtual int InvRowSums(Epetra_Vector &x) const
Computes the sum of absolute values of the rows of the Epetra_RowMatrix, results returned in x (NOT I...
Definition: Ifpack_LocalFilter.h:198
Ifpack_LocalFilter::SetUseTranspose
int SetUseTranspose(bool UseTranspose_in)
Sets use transpose (not implemented).
Definition: Ifpack_LocalFilter.h:364
Ifpack_LocalFilter::NumGlobalRows
virtual int NumGlobalRows() const
Returns the number of global matrix rows.
Definition: Ifpack_LocalFilter.h:258
Epetra_Map
Epetra_Import