EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_PETScAIJMatrix.h
Go to the documentation of this file.
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 # CVS File Information
44 # Current revision: $Revision$
45 # Last modified: $Date$
46 # Modified by: $Author$
47 #############################################################################*/
48 
49 #ifndef _EPETRAEXT_PETSCAIJMATRIX_H_
50 #define _EPETRAEXT_PETSCAIJMATRIX_H_
51 
52 #include "Epetra_Object.h"
53 #include "Epetra_CompObject.h"
54 #include "Epetra_RowMatrix.h"
55 #include "Epetra_Map.h"
56 #ifdef HAVE_MPI
57 #include "Epetra_MpiComm.h"
58 #else
59 #include "Epetra_SerialComm.h"
60 #endif
61 extern "C" {
62 //Petsc headers.
63 //Note: Petsc internally hard-codes paths to headers, relative to the PETSC home
64 // directory. This means that --with-incdirs must contain the full path(s)
65 // to the header below plus the PETSc home directory.
66 #include "src/mat/impls/aij/mpi/mpiaij.h"
67 }
68 
69 class Epetra_Import;
70 class Epetra_Export;
71 class Epetra_Vector;
72 class Epetra_MultiVector;
73 
75 
83 class Epetra_PETScAIJMatrix: public Epetra_Object, public Epetra_CompObject, public virtual Epetra_RowMatrix {
84 
85  public:
86 
88 
89 
96 
98  virtual ~Epetra_PETScAIJMatrix();
100 
102 
103 
105 
119  int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const;
120 
122 
128  int ExtractDiagonalCopy(Epetra_Vector & Diagonal) const;
130 
132 
133 
135 
145  int Multiply(bool TransA, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
146 
148 
162  int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
163 
165 
175  int InvRowSums(Epetra_Vector& x) const;
176 
178 
185  int LeftScale(const Epetra_Vector& x);
186 
188 
198  int InvColSums(Epetra_Vector& x) const;
199 
201 
208  int RightScale(const Epetra_Vector& x);
210 
212 
213 
214 
216  bool Filled() const {return(true);};
217 
219  bool LowerTriangular() const {return(false);};
220 
222  bool UpperTriangular() const {return(false);};
223 
225 
227 
228 
230  Mat Amat() const {return(Amat_);};
231 
233  /* Returns the quantity \f$ \| A \|_\infty\f$ such that
234  \f[\| A \|_\infty = \max_{1\lei\lem} \sum_{j=1}^n |a_{ij}| \f].
235  */
236  double NormInf() const;
237 
239  /* Returns the quantity \f$ \| A \|_1\f$ such that
240  \f[\| A \|_1= \max_{1\lej\len} \sum_{i=1}^m |a_{ij}| \f].
241  */
242  double NormOne() const;
243 
245  int NumGlobalNonzeros() const {return(NumGlobalNonzeros_);};
246 
248  int NumGlobalRows() const {return(OperatorRangeMap().NumGlobalPoints());};
249 
251  int NumGlobalCols() const {return(OperatorDomainMap().NumGlobalPoints());};
252 
254  int NumGlobalDiagonals() const{return(OperatorDomainMap().NumGlobalPoints());};
255 
257  int NumMyNonzeros() const {return(NumMyNonzeros_);};
258 
260  int NumMyRows() const {return(OperatorRangeMap().NumMyPoints());};
261 
263  int NumMyCols() const {return(RowMatrixColMap().NumMyPoints());};
264 
266  int NumMyDiagonals() const {return(OperatorRangeMap().NumMyPoints());};
267 
269  const Epetra_Map & OperatorDomainMap() const {return(*DomainMap_);};
270 
272  const Epetra_Map & OperatorRangeMap() const {return(*DomainMap_);};
273 
275  const Epetra_BlockMap& Map() const {return(RowMatrixRowMap());}
276 
278  const Epetra_Map & RowMatrixRowMap() const {return(OperatorRangeMap());};
279 
281  const Epetra_Map & RowMatrixColMap() const {return(*ColMap_);};
282 
284  virtual const Epetra_Import * RowMatrixImporter() const {return(Importer_);};
285 
287  const Epetra_Comm & Comm() const {return(*Comm_);};
289 
290 
292 
293 
295  virtual void Print(ostream & os) const;
297 
299 
300 
302  const char * Label() const {return(Epetra_Object::Label());};
303 
305 
315  {(void)UseTranspose; return(-1);}
316 
318 
326  int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
328 
330 
343  int ApplyInverse(const Epetra_MultiVector& X,
344  Epetra_MultiVector& Y) const
345  {(void)X; (void)Y; return(-1);}
346 
348  virtual bool HasNormInf() const {return(true);}
349 
351  virtual bool UseTranspose() const {return(false);}
352 
354 
356 
358 
367  int NumMyRowEntries(int MyRow, int & NumEntries) const;
368 
370  int MaxNumEntries() const;
372 
373  private:
374 
375  int GetRow(int Row) const;
376  Mat Amat_; //general PETSc matrix type
377  mutable double * Values_;
378  mutable int * Indices_;
379  mutable int MaxNumEntries_;
380 
381 #ifdef HAVE_MPI
382  Epetra_MpiComm * Comm_;
383 #else
384  Epetra_SerialComm * Comm_;
385 #endif
386  Epetra_Map * DomainMap_;
387  Epetra_Map * ColMap_;
388  Epetra_Import * Importer_;
389  mutable Epetra_MultiVector * ImportVector_;
390 
391  double NumGlobalNonzeros_;
392  int NumMyNonzeros_;
393  int NumMyRows_;
394  int NumGlobalRows_;
395  int NumMyCols_;
396  int PetscRowStart_;
397  int PetscRowEnd_;
398  enum petscMatrixType {PETSC_SEQ_AIJ, PETSC_MPI_AIJ};
399  const MatType MatType_; //really const char*
400  mutable double NormInf_;
401  mutable double NormOne_;
402 
403 
405  //FIXME we need a copy ctor
406  //Epetra_PETScAIJMatrix(const Epetra_PETScAIJMatrix & Matrix) {(void)Matrix;}
407 };
408 #endif /* _EPETRAEXT_PETSCAIJMATRIX_H_ */
int ExtractDiagonalCopy(Epetra_Vector &Diagonal) const
Returns a copy of the main diagonal in a user-provided vector.
int NumMyRowEntries(int MyRow, int &NumEntries) const
Return the current number of values stored for the specified local row.
int NumMyNonzeros() const
Returns the number of nonzero entries in the calling processor's portion of the matrix.
Epetra_PETScAIJMatrix(Mat Amat)
Epetra_PETScAIJMatrix constructor.
virtual const Epetra_Import * RowMatrixImporter() const
Returns the Epetra_Import object that contains the import operations for distributed operations...
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
const Epetra_BlockMap & Map() const
Implement the Epetra_SrcDistObjec::Map() function.
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.
int InvRowSums(Epetra_Vector &x) const
Computes the sum of absolute values of the rows of the Epetra_PETScAIJMatrix, results returned in x...
int RightScale(const Epetra_Vector &x)
Scales the Epetra_PETScAIJMatrix on the right with a Epetra_Vector x.
virtual ~Epetra_PETScAIJMatrix()
Epetra_PETScAIJMatrix Destructor.
double NormOne() const
Returns the one norm of the global matrix.
const char * Label() const
Returns a character string describing the operator.
int SetUseTranspose(bool UseTranspose)
If set true, transpose of this operator will be applied.
int NumGlobalRows() const
Returns the number of global matrix rows.
int LeftScale(const Epetra_Vector &x)
Scales the Epetra_PETScAIJMatrix on the left with a Epetra_Vector x.
int NumGlobalDiagonals() const
Returns the number of global nonzero diagonal entries.
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
bool Filled() const
If FillComplete() has been called, this query returns true, otherwise it returns false.
int NumGlobalCols() const
Returns the number of global matrix columns.
int NumMyCols() const
Returns the number of matrix columns owned by the calling processor.
int NumMyDiagonals() const
Returns the number of local nonzero diagonal entries.
int InvColSums(Epetra_Vector &x) const
Computes the sum of absolute values of the columns of the Epetra_PETScAIJMatrix, results returned in ...
int NumGlobalNonzeros() const
Returns the number of nonzero entries in the global matrix.
const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this matrix.
int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_PETScAIJMatrix multiplied by a Epetra_MultiVector X in Y...
Mat Amat() const
Returns a pointer to the PETSc matrix used to create this object.
const Epetra_Map & RowMatrixRowMap() const
Returns the Row Map object needed for implementing Epetra_RowMatrix.
bool LowerTriangular() const
If matrix is lower triangular, this query returns true, otherwise it returns false.
const Epetra_Map & RowMatrixColMap() const
Returns the Column Map object needed for implementing Epetra_RowMatrix.
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator (same as domain)...
int MaxNumEntries() const
Returns the maximum of NumMyRowEntries() over all rows.
Epetra_PETScAIJMatrix: A class for constructing and using real-valued sparse compressed row matrices...
virtual void Print(ostream &os) const
Print method.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_PETScAIJMatrix multiplied by a Epetra_MultiVector X in Y...
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.
virtual bool HasNormInf() const
Returns true because this class can compute an Inf-norm.
double NormInf() const
Returns the infinity norm of the global matrix.
bool UpperTriangular() const
If matrix is upper triangular, this query returns true, otherwise it returns false.
int NumMyRows() const
Returns the number of matrix rows owned by the calling processor.