IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
Ifpack_SerialTriDiMatrix.h
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 IFPACK_SERIALTRIDIMATRIX_H
00045 #define IFPACK_SERIALTRIDIMATRIX_H
00046 
00047 #include "Epetra_ConfigDefs.h"
00048 #include "Epetra_Object.h"
00049 #include "Epetra_CompObject.h"
00050 #include "Epetra_BLAS.h"
00051 
00052 class Epetra_VbrMatrix;
00053 
00055 
00105 //=========================================================================
00106 class EPETRA_LIB_DLL_EXPORT Ifpack_SerialTriDiMatrix : public Epetra_CompObject, public Epetra_Object, public Epetra_BLAS {
00107 
00108   public:
00109 
00111 
00112 
00113 
00118   Ifpack_SerialTriDiMatrix(bool set_object_label=true);
00119 
00121 
00130   Ifpack_SerialTriDiMatrix(int NumRowCol, bool set_object_label=true);
00131 
00133 
00144   Ifpack_SerialTriDiMatrix(Epetra_DataAccess CV, double* A_in, int NumRowCol,
00145                            bool set_object_label=true);
00146 
00148 
00149   Ifpack_SerialTriDiMatrix(const Ifpack_SerialTriDiMatrix& Source);
00150 
00152   virtual ~Ifpack_SerialTriDiMatrix ();
00154 
00156 
00157 
00158 
00168   int Shape(int NumRowCol);
00169 
00170   int Reshape(int, int);
00171 
00173 
00174 
00176 
00195   int Multiply(char TransA, char TransB, double ScalarAB,
00196            const Ifpack_SerialTriDiMatrix& A,
00197            const Ifpack_SerialTriDiMatrix& B,
00198            double ScalarThis);
00199 
00201   /* This method is intended to imitate the semantics of the matrix-vector
00202     multiplication provided by Epetra's sparse matrices. The 'vector' arguments
00203     are actually matrices; this method will return an error if the
00204     dimensions of 'x' are not compatible. 'y' will be reshaped if necessary.
00205   */
00206   /* int Multiply(bool transA, */
00207   /*              const Ifpack_SerialTriDiMatrix& x, */
00208   /*              Ifpack_SerialTriDiMatrix& y); */
00209 
00211 
00238   int Scale(double ScalarA);
00239 
00241 
00244   virtual double NormOne() const;
00245 
00247   virtual double NormInf() const;
00248 
00250 
00252 
00253 
00255 
00261     Ifpack_SerialTriDiMatrix & operator = (const Ifpack_SerialTriDiMatrix& Source);
00262 
00264 
00267     bool operator==(const Ifpack_SerialTriDiMatrix& rhs) const;
00268 
00270 
00272     bool operator!=(const Ifpack_SerialTriDiMatrix& rhs) const
00273     { return !(*this == rhs); }
00274 
00276 
00283     Ifpack_SerialTriDiMatrix & operator += (const Ifpack_SerialTriDiMatrix& Source);
00284 
00286 
00294         double& operator () (int RowIndex, int ColIndex);
00295 
00297 
00306     const double& operator () (int RowIndex, int ColIndex) const;
00307 
00309 
00319     //    double* operator [] (int ColIndex);
00320 
00322 
00332     //    const double* operator [] (int ColIndex) const;
00333 
00335 
00341   int Random();
00342 
00344   int N() const {return(N_);};
00345 
00346   int LDA() const {return(LDA_);};
00347 
00349   double* A() const {return(A_);};
00350 
00352   //  double* A() {return(A_);};
00353 
00354   double* DL() { return DL_;};
00355   double* DL() const { return DL_;};
00356   double* D() { return D_;};
00357   double* D() const { return D_;};
00358   double* DU() { return DU_;};
00359   double* DU() const { return DU_;};
00360   double* DU2() { return DU2_;};
00361   double* DU2() const { return DU2_;};
00362 
00364   Epetra_DataAccess CV() const {return(CV_);};
00366 
00368 
00369 
00370   virtual void Print(std::ostream& os) const;
00372 
00374 
00375 
00377 
00380   virtual double OneNorm() const {return(NormOne());};
00381 
00383   virtual double InfNorm() const {return(NormInf());};
00385 
00387 
00388 
00390 
00399     virtual int SetUseTranspose(bool UseTranspose_in) { UseTranspose_ = UseTranspose_in; return (0); }
00400 
00402 
00411     virtual int ApplyInverse(const Ifpack_SerialTriDiMatrix & X, Ifpack_SerialTriDiMatrix & Y)
00412     {
00413       (void)X;//prevents unused variable compiler warning
00414       (void)Y;
00415       return (-1);
00416     }
00417 
00419     virtual const char * Label() const { return Epetra_Object::Label(); }
00420 
00422     virtual bool UseTranspose() const { return UseTranspose_; }
00423 
00425     virtual bool HasNormInf() const { return true; }
00426 
00428     virtual int RowColDim() const { return N(); }
00430 
00431  protected:
00432 
00433   void CopyMat(const double* Source, int NumRowCol,
00434                double* Target, int NRC2, bool add=false);
00435   void CleanupData();
00436 
00437   int N_;
00438   int LDA_;
00439   bool A_Copied_;
00440   Epetra_DataAccess CV_;
00441 
00442   //For performance reasons, it's better if Epetra_VbrMatrix can access the
00443   //A_ members of this class directly without going through an
00444   //accessor method. Rather than making them public members, we'll make
00445   //Epetra_VbrMatrix a friend class.
00446 
00447   friend class Epetra_VbrMatrix;
00448 
00449   double* A_;
00450   double* DL_;
00451   double* D_;
00452   double* DU_;
00453   double* DU2_;
00454 
00455   bool UseTranspose_;
00456 };
00457 
00458 // inlined definitions of op() and op[]
00459 //=========================================================================
00460 inline double& Ifpack_SerialTriDiMatrix::operator () (int RowIndex, int ColIndex) {
00461 
00462  int diff = ColIndex - RowIndex;
00463 
00464 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00465  if (ColIndex >= N_ || ColIndex < 0)
00466         throw ReportError("Column index = " +toString(ColIndex) +
00467                   " Out of Range 0 - " + toString(N_-1),-2);
00468  if (RowIndex >= N_ || RowIndex < 0)
00469         throw ReportError("Row index = " +toString(RowIndex) +
00470                   " Out of Range 0 - " + toString(N_-1),-2);
00471 
00472  if ( diff > 1 || diff < -1 )
00473    throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) +
00474              " Out of Range -1 to 1",-2);
00475 #endif
00476 
00477  switch (diff) {
00478  case -1:
00479    // DL
00480    return DL_[ColIndex];
00481    break;
00482  case 0:
00483    return D_[ColIndex];
00484    break;
00485  case 1:
00486    return DU_[RowIndex];
00487    break;
00488  default:
00489    throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) +" Out of Range -1 to 1",1);
00490    return D_[0]; // ultimate badness, should never get here
00491  }
00492  throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) + " Out of Range -1 to 1",1);
00493  return D_[0]; // ultimat badness, should never get here
00494 }
00495 //=========================================================================
00496 inline const double& Ifpack_SerialTriDiMatrix::operator () (int RowIndex, int ColIndex) const {
00497  int diff = ColIndex - RowIndex;
00498 
00499 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00500  if (ColIndex >= N_ || ColIndex < 0)
00501         throw ReportError("Column index = " +toString(ColIndex) +
00502                   " Out of Range 0 - " + toString(N_-1),-2);
00503  if (RowIndex >= N_ || RowIndex < 0)
00504         throw ReportError("Row index = " +toString(RowIndex) +
00505                   " Out of Range 0 - " + toString(N_-1),-2);
00506  if ( diff > 1 || diff < -1 )
00507    throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) + " Out of Range -1 to 1",-2);
00508 #endif
00509  switch (diff) {
00510  case -1:
00511    // DL
00512    return DL_[ColIndex];
00513    break;
00514  case 0:
00515    return D_[ColIndex];
00516    break;
00517  case 1:
00518    return DU_[RowIndex];
00519    break;
00520  default:
00521    throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) + " Out of Range -1 to 1",-2);
00522   return D_[0]; // Ultimate badness, should never get here.
00523  }
00524  return D_[0]; // Crime against humanity, should never get here. 
00525 }
00526 
00527 
00528 #endif /* EPETRA_SERIALTRIDIMATRIX_H */
 All Classes Files Functions Variables Enumerations Friends