Epetra Package Browser (Single Doxygen Collection) Development
Epetra_BasicRowMatrix.h
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright 2001 Sandia Corporation
00007 // 
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00044 #ifndef EPETRA_BASICROWMATRIX_H
00045 #define EPETRA_BASICROWMATRIX_H
00046 
00047 #include "Epetra_RowMatrix.h"
00048 #include "Epetra_Object.h"
00049 #include "Epetra_CompObject.h"
00050 #include "Epetra_Map.h"
00051 #include "Epetra_Comm.h"
00052 #include "Epetra_SerialDenseVector.h"
00053 #include "Epetra_IntSerialDenseVector.h"
00054 #include "Epetra_MultiVector.h"
00055 
00056 class Epetra_Vector;
00057 class Epetra_Import;
00058 class Epetra_Export;
00059 
00061 
00109 class EPETRA_LIB_DLL_EXPORT Epetra_BasicRowMatrix: public Epetra_CompObject, public Epetra_Object, public virtual Epetra_RowMatrix  {
00110       
00111  public:
00112 
00114 
00115 
00116   /* This constructor requires a valid Epetra_Comm object as its only argument.  The constructor will use Comm to build
00117      Epetra_Maps objects: RowMap, ColMap, DomainMap and RangeMap.  However, these will be zero-length (trivial) maps that
00118      \e must be reset by calling one of the two SetMap() methods listed below.
00119      \param Comm (In) An Epetra_Comm containing a valid Comm object.
00120   */
00121   Epetra_BasicRowMatrix(const Epetra_Comm & Comm);
00122 
00124   virtual ~Epetra_BasicRowMatrix();
00126   
00128 
00129 
00130   /* This method takes a row and column map.  On each processor these maps describe the global rows and columns, resp, 
00131      that the processor will care about.  Note that the ColMap does not have to be one-to-one.  In other words, a column ID can appear
00132      on more than one processor.  The RowMap \e must be 1-to-1.
00133      \param RowMap (In) An Epetra_Map containing on each processor a list of GIDs of rows that the processor cares about.
00134      \param ColMap (In) An Epetra_Map containing on each processor a list of GIDs of columns that the processor cares about.
00135 
00136      In this method, the domain and range maps are assumed to be the same as the row map.  Note that this requires that 
00137      the global matrix be square.  If the matrix is not square, or the domain vectors or range vectors do not have the same layout
00138      as the rows, then the second constructor should be called.
00139   */
00140   void SetMaps(const Epetra_Map & RowMap, const Epetra_Map & ColMap);
00141 
00143   /* This constructor takes a row, column, domain and range map.  On each processor these maps describe the global rows, columns, domain
00144      and range, resp, that the processor will care about.  The domain and range maps must be one-to-one, but note that the row and column
00145      maps do not have to be one-to-one.  In other words, a row ID can appear
00146      on more than one processor, as can a column ID.
00147      \param RowMap (In) An Epetra_Map containing on each processor a list of GIDs of rows that the processor cares about.
00148      \param ColMap (In) An Epetra_Map containing on each processor a list of GIDs of columns that the processor cares about.
00149      \param DomainMap (In) An Epetra_Map describing the distribution of domain vectors and multivectors.
00150      \param RangeMap (In) An Epetra_Map describing the distribution of range vectors and multivectors.
00151 
00152   */
00153   void SetMaps(const Epetra_Map & RowMap, const Epetra_Map & ColMap, 
00154          const Epetra_Map & DomainMap, const Epetra_Map & RangeMap);
00155 
00157 
00158   
00160 
00161 
00163 
00172   virtual int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const = 0;
00173 
00175 
00183     virtual int ExtractMyEntryView(int CurEntry, double * & Value, int & RowIndex, int & ColIndex) = 0;
00184 
00186 
00194     virtual int ExtractMyEntryView(int CurEntry, double const * & Value, int & RowIndex, int & ColIndex) const = 0;
00195 
00197 
00204     virtual int NumMyRowEntries(int MyRow, int & NumEntries) const = 0;
00206 
00208 
00209 
00211 
00218     virtual int Multiply(bool TransA, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00219 
00221 
00230     virtual int Solve(bool Upper, bool Trans, bool UnitDiagonal,
00231                       const Epetra_MultiVector& X,
00232                       Epetra_MultiVector& Y) const
00233     {
00234       (void)Upper;
00235       (void)Trans;
00236       (void)UnitDiagonal;
00237       (void)X;
00238       (void)Y;
00239       return(-1);
00240     }
00241 
00243 
00248     virtual int ExtractDiagonalCopy(Epetra_Vector & Diagonal) const;
00249 
00251 
00260     virtual int InvRowSums(Epetra_Vector& x) const;
00261 
00263 
00269     virtual int LeftScale(const Epetra_Vector& x);
00270 
00272 
00281     virtual int InvColSums(Epetra_Vector& x) const;
00282 
00284 
00290     virtual int RightScale(const Epetra_Vector& x);
00292 
00294 
00295 
00296 
00298     virtual bool Filled() const {return(true);}
00299 
00301     bool LowerTriangular() const {if (!HaveNumericConstants_) ComputeNumericConstants(); return(LowerTriangular_);}
00302 
00304     virtual bool UpperTriangular() const {if (!HaveNumericConstants_) ComputeNumericConstants(); return(UpperTriangular_);}
00305 
00307   
00309 
00310 
00312     /* Returns the quantity \f$ \| A \|_\infty\f$ such that
00313        \f[\| A \|_\infty = \max_{1\lei\lem} \sum_{j=1}^n |a_{ij}| \f].
00314 
00315      \warning This method is supported if and only if the Epetra_RowMatrix Object that was used to create this supports this method.
00316 
00317     */ 
00318     virtual double NormInf() const{if (!HaveNumericConstants_) ComputeNumericConstants(); return(NormInf_);}
00319 
00321     /* Returns the quantity \f$ \| A \|_1\f$ such that
00322        \f[\| A \|_1= \max_{1\lej\len} \sum_{i=1}^m |a_{ij}| \f].
00323 
00324      \warning This method is supported if and only if the Epetra_RowMatrix Object that was used to create this supports this method.
00325 
00326     */ 
00327     virtual double NormOne() const{if (!HaveNumericConstants_) ComputeNumericConstants(); return(NormOne_);}
00328 
00330     /* Note that if the data decomposition is defined such that some nonzeros
00331        appear on multiple processors, then those nonzeros will be counted
00332        multiple times.
00333     */
00334     virtual int NumGlobalNonzeros() const{if (!HaveStructureConstants_) ComputeStructureConstants(); return(NumGlobalNonzeros_);}
00335 
00337     virtual int NumGlobalRows() const {return(OperatorRangeMap().NumGlobalPoints());}
00338 
00340     virtual int NumGlobalCols() const {return(OperatorDomainMap().NumGlobalPoints());}
00341 
00343     virtual int NumGlobalDiagonals() const{return(OperatorDomainMap().NumGlobalPoints());}
00344     
00346     virtual int NumMyNonzeros() const{if (!HaveStructureConstants_) ComputeStructureConstants(); return(NumMyNonzeros_);}
00347 
00349     virtual int NumMyRows() const {return(OperatorRangeMap().NumMyPoints());}
00350 
00352     virtual int NumMyCols() const {return(RowMatrixColMap().NumMyPoints());}
00353 
00355     virtual int NumMyDiagonals() const {return(OperatorRangeMap().NumMyPoints());}
00356 
00358     virtual int MaxNumEntries() const{ if (!HaveStructureConstants_) ComputeStructureConstants(); return(MaxNumEntries_);}
00359 
00361     virtual const Epetra_Map & OperatorDomainMap() const {return(OperatorDomainMap_);}
00362 
00364     virtual const Epetra_Map & OperatorRangeMap() const  {return(OperatorRangeMap_);}
00365 
00367     virtual const Epetra_BlockMap& Map() const {return(RowMatrixRowMap());}
00368 
00370     virtual const Epetra_Map & RowMatrixRowMap() const {return(RowMatrixRowMap_);}
00371 
00373     virtual const Epetra_Map & RowMatrixColMap() const {return(RowMatrixColMap_);}
00374 
00376     virtual const Epetra_Import * RowMatrixImporter() const {return(Importer_);}
00377 
00379     virtual const Epetra_Comm & Comm() const {return(*Comm_);}
00381   
00382   
00384 
00385 
00387   virtual void Print(ostream & os) const;
00389 
00391 
00392     
00394 
00402   virtual int SetUseTranspose(bool use_transpose) {UseTranspose_ = use_transpose; return(0);}
00403 
00405   virtual const char* Label() const {return(Epetra_Object::Label());}
00406   
00408 
00414   virtual int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
00415     return(Multiply(Epetra_BasicRowMatrix::UseTranspose(), X, Y));}
00416 
00418 
00426   virtual int ApplyInverse(const Epetra_MultiVector& X,
00427                            Epetra_MultiVector& Y) const
00428    {
00429      (void)X;
00430      (void)Y;
00431      return(-1);
00432    }
00433 
00435   bool HasNormInf() const {return(true);}
00436   
00438   virtual bool UseTranspose() const {return(UseTranspose_);}
00439 
00441   
00443 
00444 
00446 
00454   virtual const Epetra_Import* Importer() const {return(Importer_);}
00455   
00457 
00466   virtual const Epetra_Export* Exporter() const {return(Exporter_);}
00467 
00469 
00470  protected:
00471 
00473 
00474 
00475   /* Several constants are pre-computed to save excess computations.  However, if the structure of the
00476      problem changes, specifically if the nonzero count in any given row changes, then this function should be called
00477      to update these constants.
00478   */ 
00479   virtual void ComputeStructureConstants() const;
00481   /* Several numeric constants are pre-computed to save excess computations.  However, if the values of the
00482      problem change, then this function should be called to update these constants.
00483   */ 
00484   virtual void ComputeNumericConstants() const;
00486 
00487   void Setup();
00488   void UpdateImportVector(int NumVectors) const;
00489   void UpdateExportVector(int NumVectors) const;
00490   void SetImportExport();
00491   Epetra_Comm * Comm_;
00492   Epetra_Map OperatorDomainMap_;
00493   Epetra_Map OperatorRangeMap_;
00494   Epetra_Map RowMatrixRowMap_;
00495   Epetra_Map RowMatrixColMap_;
00496   
00497   mutable int NumMyNonzeros_;
00498   mutable int NumGlobalNonzeros_;
00499   mutable int MaxNumEntries_;
00500   mutable double NormInf_;
00501   mutable double NormOne_;
00502   int NumMyRows_;
00503   int NumMyCols_;
00504 
00505   bool UseTranspose_;
00506   bool HasNormInf_;
00507   mutable bool LowerTriangular_;
00508   mutable bool UpperTriangular_;
00509   mutable bool HaveStructureConstants_;
00510   mutable bool HaveNumericConstants_;
00511   mutable bool HaveMaps_;
00512     
00513 
00514   mutable Epetra_MultiVector * ImportVector_;
00515   mutable Epetra_MultiVector * ExportVector_;
00516   Epetra_Import * Importer_;
00517   Epetra_Export * Exporter_;
00518 
00519 };
00520 #endif /* EPETRA_BASICROWMATRIX_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines