EpetraExt Development
EpetraExt_PETScAIJMatrix.h
Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00005 //                 Copyright (2011) Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 
00042 /*#############################################################################
00043 # CVS File Information
00044 #    Current revision: $Revision$
00045 #    Last modified:    $Date$
00046 #    Modified by:      $Author$
00047 #############################################################################*/
00048 
00049 #ifndef _EPETRAEXT_PETSCAIJMATRIX_H_
00050 #define _EPETRAEXT_PETSCAIJMATRIX_H_
00051 
00052 #include "Epetra_Object.h"
00053 #include "Epetra_CompObject.h"
00054 #include "Epetra_RowMatrix.h"
00055 #include "Epetra_Map.h"
00056 #ifdef HAVE_MPI
00057 #include "Epetra_MpiComm.h"
00058 #else
00059 #include "Epetra_SerialComm.h"
00060 #endif
00061 extern "C" {
00062 //Petsc headers.
00063 //Note: Petsc internally hard-codes paths to headers, relative to the PETSC home
00064 //      directory.  This means that --with-incdirs must contain the full path(s)
00065 //      to the header below plus the PETSc home directory.
00066 #include "src/mat/impls/aij/mpi/mpiaij.h"
00067 }
00068 
00069 class Epetra_Import;
00070 class Epetra_Export;
00071 class Epetra_Vector;
00072 class Epetra_MultiVector;
00073 
00075 
00083 class Epetra_PETScAIJMatrix: public Epetra_Object, public Epetra_CompObject, public virtual Epetra_RowMatrix  {
00084       
00085  public:
00086 
00088 
00089 
00090 
00095   Epetra_PETScAIJMatrix(Mat Amat);
00096 
00098   virtual ~Epetra_PETScAIJMatrix();
00100   
00102 
00103 
00105 
00119     int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const;
00120 
00122 
00128     int ExtractDiagonalCopy(Epetra_Vector & Diagonal) const;
00130 
00132 
00133 
00135 
00145     int Multiply(bool TransA, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00146 
00148 
00162     int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00163 
00165 
00175     int InvRowSums(Epetra_Vector& x) const;
00176 
00178 
00185     int LeftScale(const Epetra_Vector& x);
00186 
00188 
00198     int InvColSums(Epetra_Vector& x) const;
00199 
00201 
00208     int RightScale(const Epetra_Vector& x);
00210 
00212 
00213 
00214 
00216     bool Filled() const {return(true);};
00217 
00219     bool LowerTriangular() const {return(false);};
00220 
00222     bool UpperTriangular() const {return(false);};
00223 
00225   
00227 
00228 
00230     Mat Amat() const {return(Amat_);};
00231 
00233     /* Returns the quantity \f$ \| A \|_\infty\f$ such that
00234        \f[\| A \|_\infty = \max_{1\lei\lem} \sum_{j=1}^n |a_{ij}| \f].
00235     */ 
00236     double NormInf() const;
00237 
00239     /* Returns the quantity \f$ \| A \|_1\f$ such that
00240        \f[\| A \|_1= \max_{1\lej\len} \sum_{i=1}^m |a_{ij}| \f].
00241     */ 
00242     double NormOne() const;
00243 
00245     int NumGlobalNonzeros() const {return(NumGlobalNonzeros_);};
00246 
00248     int NumGlobalRows() const {return(OperatorRangeMap().NumGlobalPoints());};
00249 
00251     int NumGlobalCols() const {return(OperatorDomainMap().NumGlobalPoints());};
00252 
00254     int NumGlobalDiagonals() const{return(OperatorDomainMap().NumGlobalPoints());};
00255     
00257     int NumMyNonzeros() const {return(NumMyNonzeros_);};
00258 
00260     int NumMyRows() const {return(OperatorRangeMap().NumMyPoints());};
00261 
00263     int NumMyCols() const {return(RowMatrixColMap().NumMyPoints());};
00264 
00266     int NumMyDiagonals() const {return(OperatorRangeMap().NumMyPoints());};
00267 
00269     const Epetra_Map & OperatorDomainMap() const {return(*DomainMap_);};
00270 
00272     const Epetra_Map & OperatorRangeMap() const  {return(*DomainMap_);};
00273 
00275     const Epetra_BlockMap& Map() const {return(RowMatrixRowMap());}
00276 
00278     const Epetra_Map & RowMatrixRowMap() const {return(OperatorRangeMap());};
00279 
00281     const Epetra_Map & RowMatrixColMap() const {return(*ColMap_);};
00282 
00284     virtual const Epetra_Import * RowMatrixImporter() const {return(Importer_);};
00285 
00287     const Epetra_Comm & Comm() const {return(*Comm_);};
00289   
00290   
00292 
00293 
00295   virtual void Print(ostream & os) const;
00297 
00299 
00300 
00302     const char * Label() const {return(Epetra_Object::Label());};
00303     
00305 
00314   int SetUseTranspose(bool UseTranspose)
00315     {(void)UseTranspose; return(-1);}
00316 
00318 
00326   int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
00327     return(Epetra_PETScAIJMatrix::Multiply(Epetra_PETScAIJMatrix::UseTranspose(), X, Y));};
00328 
00330 
00343   int ApplyInverse(const Epetra_MultiVector& X,
00344                    Epetra_MultiVector& Y) const
00345     {(void)X; (void)Y; return(-1);}
00346 
00348     virtual bool HasNormInf() const {return(true);}
00349 
00351     virtual bool UseTranspose() const {return(false);}
00352 
00354 
00355 
00356 
00358 
00367     int NumMyRowEntries(int MyRow, int & NumEntries) const;
00368 
00370     int MaxNumEntries() const;
00372 
00373  private:
00374 
00375     int GetRow(int Row) const;
00376     Mat Amat_;                //general PETSc matrix type
00377     mutable double * Values_;
00378     mutable int * Indices_;
00379     mutable int MaxNumEntries_;
00380     
00381 #ifdef HAVE_MPI
00382     Epetra_MpiComm * Comm_;
00383 #else
00384     Epetra_SerialComm * Comm_;
00385 #endif  
00386     Epetra_Map * DomainMap_;
00387     Epetra_Map * ColMap_;
00388     Epetra_Import * Importer_;
00389     mutable Epetra_MultiVector * ImportVector_;
00390  
00391     double NumGlobalNonzeros_;
00392     int NumMyNonzeros_;
00393     int NumMyRows_;
00394     int NumGlobalRows_;
00395     int NumMyCols_;
00396     int PetscRowStart_;
00397     int PetscRowEnd_;
00398     enum petscMatrixType {PETSC_SEQ_AIJ, PETSC_MPI_AIJ};
00399     const MatType MatType_;         //really const char*
00400     mutable double NormInf_;
00401     mutable double NormOne_;
00402 
00403     
00405   //FIXME we need a copy ctor
00406   //Epetra_PETScAIJMatrix(const Epetra_PETScAIJMatrix & Matrix) {(void)Matrix;}
00407 };
00408 #endif /* _EPETRAEXT_PETSCAIJMATRIX_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines