IFPACK  Development
Ifpack_SerialTriDiMatrix.h
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef IFPACK_SERIALTRIDIMATRIX_H
45 #define IFPACK_SERIALTRIDIMATRIX_H
46 
47 #include "Epetra_ConfigDefs.h"
48 #include "Epetra_Object.h"
49 #include "Epetra_CompObject.h"
50 #include "Epetra_BLAS.h"
51 
52 class Epetra_VbrMatrix;
53 
55 
105 //=========================================================================
106 class EPETRA_LIB_DLL_EXPORT Ifpack_SerialTriDiMatrix : public Epetra_CompObject, public Epetra_Object, public Epetra_BLAS {
107 
108  public:
109 
111 
112 
118  Ifpack_SerialTriDiMatrix(bool set_object_label=true);
119 
121 
130  Ifpack_SerialTriDiMatrix(int NumRowCol, bool set_object_label=true);
131 
133 
144  Ifpack_SerialTriDiMatrix(Epetra_DataAccess CV, double* A_in, int NumRowCol,
145  bool set_object_label=true);
146 
148 
150 
152  virtual ~Ifpack_SerialTriDiMatrix ();
154 
156 
157 
168  int Shape(int NumRowCol);
169 
170  int Reshape(int, int);
171 
173 
174 
176 
195  int Multiply(char TransA, char TransB, double ScalarAB,
196  const Ifpack_SerialTriDiMatrix& A,
197  const Ifpack_SerialTriDiMatrix& B,
198  double ScalarThis);
199 
201  /* This method is intended to imitate the semantics of the matrix-vector
202  multiplication provided by Epetra's sparse matrices. The 'vector' arguments
203  are actually matrices; this method will return an error if the
204  dimensions of 'x' are not compatible. 'y' will be reshaped if necessary.
205  */
206  /* int Multiply(bool transA, */
207  /* const Ifpack_SerialTriDiMatrix& x, */
208  /* Ifpack_SerialTriDiMatrix& y); */
209 
211 
238  int Scale(double ScalarA);
239 
241 
244  virtual double NormOne() const;
245 
247  virtual double NormInf() const;
248 
250 
252 
253 
255 
261  Ifpack_SerialTriDiMatrix & operator = (const Ifpack_SerialTriDiMatrix& Source);
262 
264 
267  bool operator==(const Ifpack_SerialTriDiMatrix& rhs) const;
268 
270 
272  bool operator!=(const Ifpack_SerialTriDiMatrix& rhs) const
273  { return !(*this == rhs); }
274 
276 
283  Ifpack_SerialTriDiMatrix & operator += (const Ifpack_SerialTriDiMatrix& Source);
284 
286 
294  double& operator () (int RowIndex, int ColIndex);
295 
297 
306  const double& operator () (int RowIndex, int ColIndex) const;
307 
309 
319  // double* operator [] (int ColIndex);
320 
322 
332  // const double* operator [] (int ColIndex) const;
333 
335 
341  int Random();
342 
344  int N() const {return(N_);};
345 
346  int LDA() const {return(LDA_);};
347 
349  double* A() const {return(A_);};
350 
352  // double* A() {return(A_);};
353 
354  double* DL() { return DL_;};
355  double* DL() const { return DL_;};
356  double* D() { return D_;};
357  double* D() const { return D_;};
358  double* DU() { return DU_;};
359  double* DU() const { return DU_;};
360  double* DU2() { return DU2_;};
361  double* DU2() const { return DU2_;};
362 
364  Epetra_DataAccess CV() const {return(CV_);};
366 
368 
369  virtual void Print(std::ostream& os) const;
372 
374 
375 
377 
380  virtual double OneNorm() const {return(NormOne());};
381 
383  virtual double InfNorm() const {return(NormInf());};
385 
387 
388 
390 
399  virtual int SetUseTranspose(bool UseTranspose_in) { UseTranspose_ = UseTranspose_in; return (0); }
400 
402 
412  {
413  (void)X;//prevents unused variable compiler warning
414  (void)Y;
415  return (-1);
416  }
417 
419  virtual const char * Label() const { return Epetra_Object::Label(); }
420 
422  virtual bool UseTranspose() const { return UseTranspose_; }
423 
425  virtual bool HasNormInf() const { return true; }
426 
428  virtual int RowColDim() const { return N(); }
430 
431  protected:
432 
433  void CopyMat(const double* Source, int NumRowCol,
434  double* Target, int NRC2, bool add=false);
435  void CleanupData();
436 
437  int N_;
438  int LDA_;
439  bool A_Copied_;
440  Epetra_DataAccess CV_;
441 
442  //For performance reasons, it's better if Epetra_VbrMatrix can access the
443  //A_ members of this class directly without going through an
444  //accessor method. Rather than making them public members, we'll make
445  //Epetra_VbrMatrix a friend class.
446 
447  friend class Epetra_VbrMatrix;
448 
449  double* A_;
450  double* DL_;
451  double* D_;
452  double* DU_;
453  double* DU2_;
454 
455  bool UseTranspose_;
456 };
457 
458 // inlined definitions of op() and op[]
459 //=========================================================================
460 inline double& Ifpack_SerialTriDiMatrix::operator () (int RowIndex, int ColIndex) {
461 
462  int diff = ColIndex - RowIndex;
463 
464 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
465  if (ColIndex >= N_ || ColIndex < 0)
466  throw ReportError("Column index = " +toString(ColIndex) +
467  " Out of Range 0 - " + toString(N_-1),-2);
468  if (RowIndex >= N_ || RowIndex < 0)
469  throw ReportError("Row index = " +toString(RowIndex) +
470  " Out of Range 0 - " + toString(N_-1),-2);
471 
472  if ( diff > 1 || diff < -1 )
473  throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) +
474  " Out of Range -1 to 1",-2);
475 #endif
476 
477  switch (diff) {
478  case -1:
479  // DL
480  return DL_[ColIndex];
481  break;
482  case 0:
483  return D_[ColIndex];
484  break;
485  case 1:
486  return DU_[RowIndex];
487  break;
488  default:
489  throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) +" Out of Range -1 to 1",1);
490  return D_[0]; // ultimate badness, should never get here
491  }
492  throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) + " Out of Range -1 to 1",1);
493  return D_[0]; // ultimat badness, should never get here
494 }
495 //=========================================================================
496 inline const double& Ifpack_SerialTriDiMatrix::operator () (int RowIndex, int ColIndex) const {
497  int diff = ColIndex - RowIndex;
498 
499 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
500  if (ColIndex >= N_ || ColIndex < 0)
501  throw ReportError("Column index = " +toString(ColIndex) +
502  " Out of Range 0 - " + toString(N_-1),-2);
503  if (RowIndex >= N_ || RowIndex < 0)
504  throw ReportError("Row index = " +toString(RowIndex) +
505  " Out of Range 0 - " + toString(N_-1),-2);
506  if ( diff > 1 || diff < -1 )
507  throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) + " Out of Range -1 to 1",-2);
508 #endif
509  switch (diff) {
510  case -1:
511  // DL
512  return DL_[ColIndex];
513  break;
514  case 0:
515  return D_[ColIndex];
516  break;
517  case 1:
518  return DU_[RowIndex];
519  break;
520  default:
521  throw ReportError("Row index = " +toString(RowIndex) + " differs from Col_Index " + toString(ColIndex) + " Out of Range -1 to 1",-2);
522  return D_[0]; // Ultimate badness, should never get here.
523  }
524  return D_[0]; // Crime against humanity, should never get here.
525 }
526 
527 
528 #endif /* EPETRA_SERIALTRIDIMATRIX_H */
Epetra_DataAccess CV() const
Returns the data access mode of the this matrix.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
int N() const
Returns column dimension of system.
virtual void Print(std::ostream &os) const
virtual int SetUseTranspose(bool UseTranspose_in)
If set true, transpose of this operator will be applied.
double * A() const
Returns pointer to the this matrix.
double * DL()
Returns pointer to the this matrix.
virtual double InfNorm() const
Computes the Infinity-Norm of the this matrix (identical to NormInf() method).
virtual int ApplyInverse(const Ifpack_SerialTriDiMatrix &X, Ifpack_SerialTriDiMatrix &Y)
Returns the result of a Ifpack_SerialTriDiOperator inverse applied to an Ifpack_SerialTriDiMatrix X i...
virtual const char * Label() const
double & operator()(int RowIndex, int ColIndex)
Element access function.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual int RowColDim() const
Returns the column dimension of operator.
virtual double OneNorm() const
Computes the 1-Norm of the this matrix (identical to NormOne() method).
Ifpack_SerialTriDiMatrix: A class for constructing and using real double precision general TriDi matr...
virtual int ReportError(const std::string Message, int ErrorCode) const
virtual const char * Label() const
Returns a character string describing the operator.
Epetra_DataAccess
bool operator!=(const Ifpack_SerialTriDiMatrix &rhs) const
Inequality operator.