TSFLAPACKGeneralMatrix.hpp
Go to the documentation of this file.
00001 #ifndef TSFLAPACKGENERALMATRIX_H
00002 #define TSFLAPACKGENERALMATRIX_H
00003 
00004 #include "SundanceDefs.hpp"
00005 #include "TSFDenseSerialVector.hpp"
00006 #include "Teuchos_Array.hpp"
00007 
00008 namespace TSFExtended
00009 {
00010   /**
00011    * Linear operator implemented as a LAPACK dense matrix.
00012    */
00013 
00014   class LAPACKGeneralMatrix
00015   {
00016   public:
00017     /** Construct with domain and range spaces, which should be
00018      * DenseSerialVectorSpace objects */
00019     LAPACKGeneralMatrix(int nRow, int nCol);
00020 
00021     /** Empty Ctor */
00022     LAPACKGeneralMatrix();
00023 
00024     /* added by ptb  */
00025     inline double& operator[](int i) {return data_[i];}
00026     inline const double& operator[](int i) const {return data_[i];}
00027 
00028     inline double& operator()(int i, int j)
00029       {return data_[i+nRows_*j];}
00030     inline const double& operator()(int i, int j) const
00031       {return data_[i+nRows_*j];}
00032 
00033     inline int getNumRows() const
00034     {
00035       return nRows_;
00036     }
00037 
00038     inline int getNumCols() const
00039     {
00040       return nCols_;
00041     }
00042 
00043 
00044     /** apply operator to dense serial vector.
00045      * in the range space */
00046     void apply(const DenseSerialVector& in,
00047                        DenseSerialVector& out) const ;
00048 
00049 
00050 
00051     /** apply inverse operator to a vector in the range space, returning
00052      * its preimage as a vector in the domain space. The solve is done
00053      * by factoring and backsolving. */
00054     void applyInverse(const DenseSerialVector& in,
00055                               DenseSerialVector& out) const ;
00056 
00057     /** apply adjoint operator to a vector in the domain space, returning
00058      * a vector in the range space. The default implementation throws an
00059      * exception */
00060     void applyAdjoint(const  DenseSerialVector& in,
00061                               DenseSerialVector& out) const ;
00062 
00063     /** apply inverse adjoint operator */
00064     void applyInverseAdjoint(const  DenseSerialVector& in,
00065                                      DenseSerialVector& out) const ;
00066 
00067 
00068 
00069 
00070     /** */
00071     void setElement(int i, int j, const double& aij) ;
00072 
00073     /** set all elements to zero */
00074     void zero() ;
00075 
00076     /** factor with a call to LAPACK's getrf() function */
00077     void factor() const ;
00078 
00079     /** write to a stream */
00080     void print(std::ostream& os) const ;
00081 
00082 
00083 
00084   protected:
00085 
00086     /** low-level matrix-vector multiply */
00087     void mvMult(bool transpose, const DenseSerialVector& in,
00088                 DenseSerialVector& out) const ;
00089 
00090     /** low-level solve */
00091     void solve(bool transpose, const DenseSerialVector& in,
00092                DenseSerialVector& out) const ;
00093 
00094 
00095     int nRows_;
00096 
00097     int nCols_;
00098 
00099     DenseSerialVector data_;
00100 
00101     mutable Teuchos::Array<int> iPiv_;
00102 
00103     mutable bool isFactored_;
00104 
00105     mutable DenseSerialVector factorData_;
00106 
00107   };
00108 
00109 }
00110 
00111 #endif

Site Contact