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 2011 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_ConfigDefs.h"
00048 #include "Epetra_RowMatrix.h"
00049 #include "Epetra_Object.h"
00050 #include "Epetra_CompObject.h"
00051 #include "Epetra_Map.h"
00052 #include "Epetra_Comm.h"
00053 #include "Epetra_SerialDenseVector.h"
00054 #include "Epetra_IntSerialDenseVector.h"
00055 #include "Epetra_MultiVector.h"
00056 
00057 class Epetra_Vector;
00058 class Epetra_Import;
00059 class Epetra_Export;
00060 
00062 
00110 class EPETRA_LIB_DLL_EXPORT Epetra_BasicRowMatrix: public Epetra_CompObject, public Epetra_Object, public virtual Epetra_RowMatrix  {
00111 
00112  public:
00113 
00115 
00116 
00123   Epetra_BasicRowMatrix(const Epetra_Comm & Comm);
00124 
00126   virtual ~Epetra_BasicRowMatrix();
00128 
00130 
00131 
00143   void SetMaps(const Epetra_Map & RowMap, const Epetra_Map & ColMap);
00144 
00157   void SetMaps(const Epetra_Map & RowMap, const Epetra_Map & ColMap,
00158          const Epetra_Map & DomainMap, const Epetra_Map & RangeMap);
00159 
00161 
00162 
00164 
00165 
00167 
00176   virtual int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const = 0;
00177 
00179 
00187     virtual int ExtractMyEntryView(int CurEntry, double * & Value, int & RowIndex, int & ColIndex) = 0;
00188 
00190 
00198     virtual int ExtractMyEntryView(int CurEntry, double const * & Value, int & RowIndex, int & ColIndex) const = 0;
00199 
00201 
00208     virtual int NumMyRowEntries(int MyRow, int & NumEntries) const = 0;
00210 
00212 
00213 
00215 
00222     virtual int Multiply(bool TransA, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00223 
00225 
00234     virtual int Solve(bool Upper, bool Trans, bool UnitDiagonal,
00235                       const Epetra_MultiVector& X,
00236                       Epetra_MultiVector& Y) const
00237     {
00238       (void)Upper;
00239       (void)Trans;
00240       (void)UnitDiagonal;
00241       (void)X;
00242       (void)Y;
00243       return(-1);
00244     }
00245 
00247 
00252     virtual int ExtractDiagonalCopy(Epetra_Vector & Diagonal) const;
00253 
00255 
00264     virtual int InvRowSums(Epetra_Vector& x) const;
00265 
00267 
00273     virtual int LeftScale(const Epetra_Vector& x);
00274 
00276 
00285     virtual int InvColSums(Epetra_Vector& x) const;
00286 
00288 
00294     virtual int RightScale(const Epetra_Vector& x);
00296 
00298 
00299 
00300 
00302     virtual bool Filled() const {return(true);}
00303 
00305     bool LowerTriangular() const {if (!HaveNumericConstants_) ComputeNumericConstants(); return(LowerTriangular_);}
00306 
00308     virtual bool UpperTriangular() const {if (!HaveNumericConstants_) ComputeNumericConstants(); return(UpperTriangular_);}
00309 
00311 
00313 
00314 
00323     virtual double NormInf() const{if (!HaveNumericConstants_) ComputeNumericConstants(); return(NormInf_);}
00324 
00333     virtual double NormOne() const{if (!HaveNumericConstants_) ComputeNumericConstants(); return(NormOne_);}
00334 
00341 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00342     virtual int NumGlobalNonzeros() const {
00343       if(OperatorRangeMap().GlobalIndicesInt() && OperatorDomainMap().GlobalIndicesInt()) {
00344         if (!HaveStructureConstants_)
00345           ComputeStructureConstants();
00346         return (int) NumGlobalNonzeros_;
00347       }
00348 
00349       throw "Epetra_BasicRowMatrix::NumGlobalNonzeros: GlobalIndices not int.";
00350     }
00351 #endif
00352     virtual long long NumGlobalNonzeros64() const{if (!HaveStructureConstants_) ComputeStructureConstants(); return(NumGlobalNonzeros_);}
00353 
00355 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00356   virtual int NumGlobalRows() const {
00357       if(OperatorRangeMap().GlobalIndicesInt()) {
00358         return (int) NumGlobalRows64();
00359       }
00360 
00361       throw "Epetra_BasicRowMatrix::NumGlobalRows: GlobalIndices not int.";
00362     }
00363 #endif
00364     virtual long long NumGlobalRows64() const {return(OperatorRangeMap().NumGlobalPoints64());}
00365 
00367 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00368     virtual int NumGlobalCols() const {
00369       if(OperatorDomainMap().GlobalIndicesInt()) {
00370         return (int) NumGlobalCols64();
00371       }
00372 
00373       throw "Epetra_BasicRowMatrix::NumGlobalCols: GlobalIndices not int.";
00374     }
00375 #endif
00376     virtual long long NumGlobalCols64() const {return(OperatorDomainMap().NumGlobalPoints64());}
00377 
00379 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00380     virtual int NumGlobalDiagonals() const {
00381       if(OperatorDomainMap().GlobalIndicesInt()) {
00382         return (int) NumGlobalDiagonals64();
00383       }
00384 
00385       throw "Epetra_BasicRowMatrix::NumGlobalDiagonals: GlobalIndices not int.";
00386     }
00387 #endif
00388     virtual long long NumGlobalDiagonals64() const{return(OperatorDomainMap().NumGlobalPoints64());}
00389 
00391     virtual int NumMyNonzeros() const{if (!HaveStructureConstants_) ComputeStructureConstants(); return(NumMyNonzeros_);}
00392 
00394     virtual int NumMyRows() const {return(OperatorRangeMap().NumMyPoints());}
00395 
00397     virtual int NumMyCols() const {return(RowMatrixColMap().NumMyPoints());}
00398 
00400     virtual int NumMyDiagonals() const {return(OperatorRangeMap().NumMyPoints());}
00401 
00403     virtual int MaxNumEntries() const{ if (!HaveStructureConstants_) ComputeStructureConstants(); return(MaxNumEntries_);}
00404 
00406     virtual const Epetra_Map & OperatorDomainMap() const {return(OperatorDomainMap_);}
00407 
00409     virtual const Epetra_Map & OperatorRangeMap() const  {return(OperatorRangeMap_);}
00410 
00412     virtual const Epetra_BlockMap& Map() const {return(RowMatrixRowMap());}
00413 
00415     virtual const Epetra_Map & RowMatrixRowMap() const {return(RowMatrixRowMap_);}
00416 
00418     virtual const Epetra_Map & RowMatrixColMap() const {return(RowMatrixColMap_);}
00419 
00421     virtual const Epetra_Import * RowMatrixImporter() const {return(Importer_);}
00422 
00424     virtual const Epetra_Comm & Comm() const {return(*Comm_);}
00426 
00427 
00429 
00430 
00432   virtual void Print(std::ostream & os) const;
00434 
00436 
00437 
00439 
00447   virtual int SetUseTranspose(bool use_transpose) {UseTranspose_ = use_transpose; return(0);}
00448 
00450   virtual const char* Label() const {return(Epetra_Object::Label());}
00451 
00453 
00459   virtual int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
00460     return(Multiply(Epetra_BasicRowMatrix::UseTranspose(), X, Y));}
00461 
00463 
00471   virtual int ApplyInverse(const Epetra_MultiVector& X,
00472                            Epetra_MultiVector& Y) const
00473    {
00474      (void)X;
00475      (void)Y;
00476      return(-1);
00477    }
00478 
00480   bool HasNormInf() const {return(true);}
00481 
00483   virtual bool UseTranspose() const {return(UseTranspose_);}
00484 
00486 
00488 
00489 
00491 
00499   virtual const Epetra_Import* Importer() const {return(Importer_);}
00500 
00502 
00511   virtual const Epetra_Export* Exporter() const {return(Exporter_);}
00512 
00514 
00515  protected:
00516 
00518 
00519 
00520   /* Several constants are pre-computed to save excess computations.  However, if the structure of the
00521      problem changes, specifically if the nonzero count in any given row changes, then this function should be called
00522      to update these constants.
00523   */
00524   virtual void ComputeStructureConstants() const;
00526   /* Several numeric constants are pre-computed to save excess computations.  However, if the values of the
00527      problem change, then this function should be called to update these constants.
00528   */
00529   virtual void ComputeNumericConstants() const;
00531 
00532   void Setup();
00533   void UpdateImportVector(int NumVectors) const;
00534   void UpdateExportVector(int NumVectors) const;
00535   void SetImportExport();
00536   Epetra_Comm * Comm_;
00537   Epetra_Map OperatorDomainMap_;
00538   Epetra_Map OperatorRangeMap_;
00539   Epetra_Map RowMatrixRowMap_;
00540   Epetra_Map RowMatrixColMap_;
00541 
00542   mutable int NumMyNonzeros_;
00543   mutable long long NumGlobalNonzeros_;
00544   mutable int MaxNumEntries_;
00545   mutable double NormInf_;
00546   mutable double NormOne_;
00547   int NumMyRows_;
00548   int NumMyCols_;
00549 
00550   bool UseTranspose_;
00551   bool HasNormInf_;
00552   mutable bool LowerTriangular_;
00553   mutable bool UpperTriangular_;
00554   mutable bool HaveStructureConstants_;
00555   mutable bool HaveNumericConstants_;
00556   mutable bool HaveMaps_;
00557 
00558 
00559   mutable Epetra_MultiVector * ImportVector_;
00560   mutable Epetra_MultiVector * ExportVector_;
00561   Epetra_Import * Importer_;
00562   Epetra_Export * Exporter_;
00563 
00564 };
00565 #endif /* EPETRA_BASICROWMATRIX_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines