TSFDenseSerialMatrix.hpp
Go to the documentation of this file.
00001 #ifndef TSF_DENSE_SERIAL_MATRIX_H
00002 #define TSF_DENSE_SERIAL_MATRIX_H
00003 
00004 #include "SundanceDefs.hpp"
00005 #include "Teuchos_Array.hpp"
00006 #include "Teuchos_RCP.hpp"
00007 #include "SundancePrintable.hpp"
00008 #include "Teuchos_Describable.hpp"
00009 #include "TSFSimplifiedLinearOpBaseDecl.hpp"
00010 #include "TSFSerialVectorSpace.hpp"
00011 #include "TSFLoadableMatrix.hpp"
00012 #include "TSFSolverState.hpp"
00013 
00014 namespace TSFExtended
00015 {
00016 using namespace Teuchos;
00017 
00018 template <class T> class LinearOperator;
00019 
00020 /**
00021  * Linear operator implemented as a dense matrix.
00022  */
00023 
00024 class DenseSerialMatrix : public SimplifiedLinearOpBase<double>,
00025                           public LoadableMatrix<double>,
00026                           public Sundance::Printable
00027 {
00028 public:
00029   /** Construct with domain and range spaces, which should be
00030    * DenseSerialVectorSpace objects */
00031   DenseSerialMatrix(
00032     const RCP<const SerialVectorSpace>& domain,
00033     const RCP<const SerialVectorSpace>& range);
00034 
00035   /** Virtual dtor */
00036   ~DenseSerialMatrix(){;}
00037 
00038   /** 
00039    * Apply either the operator or its transpose
00040    */
00041   virtual void applyOp(const Thyra::EOpTransp M_trans,
00042     const Vector<double>& in,
00043     Vector<double> out) const ;
00044 
00045   /** Insert a set of elements in a row, adding to any previously
00046    * existing values.  The nonzero structure of the matrix must have
00047    * been determined at construction time. 
00048    *
00049    * @param globalRowIndex the global index of the row to which these
00050    * elements belong.
00051    * @param nElemsToInsert the number of elements being inserted in this
00052    * step
00053    * @param globalColumnIndices array of column indices. Must 
00054    * be nElemsToInsert in length. 
00055    * @param elements array of element values. Must be nElemsToInsert in
00056    * length
00057    */
00058   virtual void addToRow(int globalRowIndex,
00059     int nElemsToInsert,
00060     const int* globalColumnIndices,
00061     const double* elementValues) ;
00062 
00063   /** Set all elements to zero, preserving the existing structure */
00064   virtual void zero() ;
00065 
00066 
00067 
00068   /** write to a stream */
00069   void print(std::ostream& os) const ;
00070 
00071   /** 
00072    * \brief Return a smart pointer for the range space 
00073    * for <tt>this</tt> operator.
00074    */
00075   RCP< const VectorSpaceBase<double> > range() const 
00076     {return range_;}
00077 
00078   /** \brief Return a smart pointer for the domain space for <tt>this</tt> operator.
00079    */
00080   RCP< const VectorSpaceBase<double> > domain() const 
00081     {return domain_;}
00082 
00083   /** */
00084   const double * const dataPtr() const {return &(data_[0]);}
00085 
00086   /** */
00087   double* dataPtr() {return &(data_[0]);}
00088 
00089   /** */
00090   int numRows() const {return nRows_;}
00091 
00092   /** */
00093   int numCols() const {return nCols_;}
00094 
00095   /** */
00096   void setRow(int row, const Array<double>& rowVals);
00097 
00098 
00099 private:
00100 
00101   RCP<const SerialVectorSpace> domain_;
00102   RCP<const SerialVectorSpace> range_;
00103     
00104   int nRows_;
00105   int nCols_;
00106   Array<double> data_;
00107 };
00108 
00109 
00110 /** \relates DenseSerialMatrix */
00111 void denseSVD(const LinearOperator<double>& A,
00112   LinearOperator<double>& U,  
00113   Vector<double>& Sigma,
00114   LinearOperator<double>& Vt);
00115 
00116 /** \relates DenseSerialMatrix */
00117 SolverState<double> denseSolve(const LinearOperator<double>& A,
00118   const Vector<double>& b,
00119   Vector<double>& x);
00120 
00121 }
00122 
00123 #endif

Site Contact