Epetra Package Browser (Single Doxygen Collection) Development
Epetra_SerialDenseMatrix.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_SERIALDENSEMATRIX_H
00045 #define EPETRA_SERIALDENSEMATRIX_H
00046 
00047 #include "Epetra_ConfigDefs.h"
00048 #include "Epetra_Object.h" 
00049 #include "Epetra_CompObject.h"
00050 #include "Epetra_BLAS.h"
00051 #include "Epetra_SerialDenseOperator.h"
00052 class Epetra_SerialSymDenseMatrix;
00053 class Epetra_VbrMatrix;
00054 
00056 
00106 //=========================================================================
00107 class EPETRA_LIB_DLL_EXPORT Epetra_SerialDenseMatrix : public Epetra_CompObject, public Epetra_Object, public Epetra_SerialDenseOperator, public Epetra_BLAS {
00108 
00109   public:
00110   
00112 
00113 
00114 
00119   Epetra_SerialDenseMatrix(bool set_object_label=true);
00120 
00122 
00133   Epetra_SerialDenseMatrix(int NumRows, int NumCols, bool set_object_label=true);
00134   
00136 
00151   Epetra_SerialDenseMatrix(Epetra_DataAccess CV, double* A_in, int LDA_in, int NumRows, int NumCols,
00152                            bool set_object_label=true);
00153   
00155   
00156   Epetra_SerialDenseMatrix(const Epetra_SerialDenseMatrix& Source);
00157 
00159   virtual ~Epetra_SerialDenseMatrix ();
00161 
00163 
00164 
00165 
00177   int Shape(int NumRows, int NumCols);
00178   
00180 
00193   int Reshape(int NumRows, int NumCols);
00195 
00197 
00198 
00200 
00219   int Multiply(char TransA, char TransB, double ScalarAB, 
00220          const Epetra_SerialDenseMatrix& A, 
00221          const Epetra_SerialDenseMatrix& B,
00222          double ScalarThis);
00223 
00225   /* This method is intended to imitate the semantics of the matrix-vector
00226     multiplication provided by Epetra's sparse matrices. The 'vector' arguments
00227     are actually matrices; this method will return an error if the
00228     dimensions of 'x' are not compatible. 'y' will be reshaped if necessary.
00229   */
00230   int Multiply(bool transA,
00231                const Epetra_SerialDenseMatrix& x,
00232                Epetra_SerialDenseMatrix& y);
00233 
00235 
00256   int Multiply(char SideA, double ScalarAB, 
00257          const Epetra_SerialSymDenseMatrix& A, 
00258          const Epetra_SerialDenseMatrix& B,
00259          double ScalarThis);
00260 
00262 
00270   int Scale(double ScalarA);
00271 
00273 
00276   virtual double NormOne() const;
00277 
00279   virtual double NormInf() const;
00280 
00282 
00284 
00285 
00287 
00293     Epetra_SerialDenseMatrix & operator = (const Epetra_SerialDenseMatrix& Source);
00294 
00296 
00299     bool operator==(const Epetra_SerialDenseMatrix& rhs) const;
00300 
00302 
00304     bool operator!=(const Epetra_SerialDenseMatrix& rhs) const
00305     { return !(*this == rhs); }
00306 
00308 
00315     Epetra_SerialDenseMatrix & operator += (const Epetra_SerialDenseMatrix& Source);
00316 
00318 
00327       double& operator () (int RowIndex, int ColIndex);
00328 
00330 
00339     const double& operator () (int RowIndex, int ColIndex) const;
00340 
00342 
00352     double* operator [] (int ColIndex);
00353 
00355 
00365     const double* operator [] (int ColIndex) const;
00366     
00368 
00374   int Random();
00375 
00377   int M() const {return(M_);};
00378 
00380   int N() const {return(N_);};
00381 
00383   double* A() const {return(A_);};
00384 
00386   double* A() {return(A_);};
00387 
00389   int LDA() const {return(LDA_);};
00390 
00392   Epetra_DataAccess CV() const {return(CV_);};
00394   
00396 
00397 
00398   virtual void Print(ostream& os) const;
00400 
00402 
00403 
00405 
00408   virtual double OneNorm() const {return(NormOne());};
00409 
00411   virtual double InfNorm() const {return(NormInf());};
00413 
00415 
00416  
00418 
00427     virtual int SetUseTranspose(bool UseTranspose_in) { UseTranspose_ = UseTranspose_in; return (0); }
00428  
00430 
00438   virtual int Apply(const Epetra_SerialDenseMatrix& X, Epetra_SerialDenseMatrix& Y);
00439  
00441 
00450     virtual int ApplyInverse(const Epetra_SerialDenseMatrix & X, Epetra_SerialDenseMatrix & Y)
00451     {
00452       (void)X;//prevents unused variable compiler warning
00453       (void)Y;
00454       return (-1);
00455     }
00456  
00458     virtual const char * Label() const { return Epetra_Object::Label(); }
00459  
00461     virtual bool UseTranspose() const { return UseTranspose_; }
00462  
00464     virtual bool HasNormInf() const { return true; }
00465 
00467     virtual int RowDim() const { return M(); } 
00468  
00470     virtual int ColDim() const { return N(); } 
00472 
00473  protected:
00474 
00475   void CopyMat(double* Source, int Source_LDA, int NumRows, int NumCols,
00476                double* Target, int Target_LDA, bool add=false);
00477   void CleanupData();
00478 
00479   int M_;
00480   int N_;
00481   bool A_Copied_;
00482   Epetra_DataAccess CV_;
00483 
00484   //For performance reasons, it's better if Epetra_VbrMatrix can access the
00485   //LDA_ and A_ members of this class directly without going through an
00486   //accessor method. Rather than making them public members, we'll make
00487   //Epetra_VbrMatrix a friend class.
00488 
00489   friend class Epetra_VbrMatrix;
00490 
00491   int LDA_;
00492   double* A_;
00493 
00494   bool UseTranspose_;
00495 };
00496 
00497 // inlined definitions of op() and op[]
00498 //=========================================================================
00499 inline double& Epetra_SerialDenseMatrix::operator () (int RowIndex, int ColIndex) {
00500 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00501   if (RowIndex >= M_ || RowIndex < 0)
00502     throw ReportError("Row index = " +toString(RowIndex) + 
00503                       " Out of Range 0 - " + toString(M_-1),-1);
00504   if (ColIndex >= N_ || ColIndex < 0) 
00505     throw ReportError("Column index = " +toString(ColIndex) + 
00506                       " Out of Range 0 - " + toString(N_-1),-2);
00507 #endif
00508    return(A_[ColIndex*LDA_ + RowIndex]);
00509 }
00510 //=========================================================================
00511 inline const double& Epetra_SerialDenseMatrix::operator () (int RowIndex, int ColIndex) const {
00512 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00513   if (RowIndex >= M_ || RowIndex < 0) 
00514     throw ReportError("Row index = " +toString(RowIndex) + 
00515                       " Out of Range 0 - " + toString(M_-1),-1);
00516   if (ColIndex >= N_ || ColIndex < 0) 
00517     throw ReportError("Column index = " +toString(ColIndex) + 
00518                       " Out of Range 0 - " + toString(N_-1),-2);
00519 #endif
00520   return(A_[ColIndex*LDA_ + RowIndex]);
00521 }
00522 //=========================================================================
00523 inline double* Epetra_SerialDenseMatrix::operator [] (int ColIndex) {
00524 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00525   if (ColIndex >= N_ || ColIndex < 0) 
00526     throw ReportError("Column index = " +toString(ColIndex) + 
00527                       " Out of Range 0 - " + toString(N_-1),-2);
00528 #endif
00529   return(A_ + ColIndex*LDA_);
00530 }
00531 //=========================================================================
00532 inline const double* Epetra_SerialDenseMatrix::operator [] (int ColIndex) const {
00533 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00534   if (ColIndex >= N_ || ColIndex < 0) 
00535     throw ReportError("Column index = " +toString(ColIndex) + 
00536                       " Out of Range 0 - " + toString(N_-1),-2);
00537 #endif
00538   return(A_+ ColIndex*LDA_);
00539 }
00540 //=========================================================================
00541 
00542 #endif /* EPETRA_SERIALDENSEMATRIX_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines