TSFEpetraMatrix.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 /* ***********************************************************************
00003 // 
00004 //           TSFExtended: Trilinos Solver Framework Extended
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // **********************************************************************/
00027  /* @HEADER@ */
00028 
00029 #ifndef TSFEPETRAMATRIX_HPP
00030 #define TSFEPETRAMATRIX_HPP
00031 
00032 #include "TSFEpetraVectorSpace.hpp"
00033 #include "TSFEpetraMatrixFactory.hpp"
00034 #include "TSFLoadableMatrix.hpp"
00035 #include "TSFLinearOperatorDecl.hpp"
00036 #include "TSFRowAccessibleOp.hpp"
00037 #include "SundanceHandleable.hpp"
00038 #include "SundancePrintable.hpp"
00039 #include "TSFILUFactorizableOp.hpp"
00040 #include "Epetra_CrsMatrix.h"
00041 #include "Thyra_LinearOpDefaultBase.hpp"
00042 #include "Thyra_EpetraLinearOpBase.hpp"
00043 
00044 namespace TSFExtended
00045 {
00046 using namespace Teuchos;
00047 using namespace Thyra;
00048 
00049 class EpetraMatrix : virtual public LinearOpDefaultBase<double>,
00050                      public LoadableMatrix<double>,
00051                      public RowAccessibleOp<double>,
00052                      public Printable,
00053                      public NamedObject,
00054                      public ILUFactorizableOp<double>,
00055                      virtual public EpetraLinearOpBase
00056 {
00057 public:
00058 
00059   /** Construct an empty EpetraMatrix structured according to the graph 
00060    * argument */
00061   EpetraMatrix(const Epetra_CrsGraph& graph,
00062     const RCP<const EpetraVectorSpace>& domain,
00063     const RCP<const EpetraVectorSpace>& range);
00064 
00065   /** Wrap an existing Epetra CRS Matrix */
00066   EpetraMatrix(const RCP<Epetra_CrsMatrix>& mat,
00067     const RCP<const EpetraVectorSpace>& domain,
00068     const RCP<const EpetraVectorSpace>& range);
00069 
00070   /** */
00071   RCP< const VectorSpaceBase<double> > domain() const {return domain_;}
00072 
00073   /** */
00074   RCP< const VectorSpaceBase<double> > range() const {return range_;}
00075 
00076   /** \brief . */
00077   bool opSupportedImpl(Thyra::EOpTransp M_trans) const;
00078 
00079   /** */
00080   void applyImpl(
00081     const Thyra::EOpTransp M_trans,
00082     const Thyra::MultiVectorBase<double> &x,
00083     const Teuchos::Ptr<Thyra::MultiVectorBase<double> > &y,
00084     const double alpha,
00085     const double beta
00086     ) const ;
00087 
00088   /** \name Epetra-Thyra adapter interface */
00089   //@{
00090 
00091   /** \brief . */
00092   void getNonconstEpetraOpView(
00093     const Teuchos::Ptr<Teuchos::RCP<Epetra_Operator> > &epetraOp,
00094     const Teuchos::Ptr<Thyra::EOpTransp> &epetraOpTransp,
00095     const Teuchos::Ptr<Thyra::EApplyEpetraOpAs> &epetraOpApplyAs,
00096     const Teuchos::Ptr<Thyra::EAdjointEpetraOp> &epetraOpAdjointSupport
00097     );
00098   /** \brief . */
00099   void getEpetraOpView(
00100     const Teuchos::Ptr<Teuchos::RCP<const Epetra_Operator> > &epetraOp,
00101     const Teuchos::Ptr<Thyra::EOpTransp> &epetraOpTransp,
00102     const Teuchos::Ptr<Thyra::EApplyEpetraOpAs> &epetraOpApplyAs,
00103     const Teuchos::Ptr<Thyra::EAdjointEpetraOp> &epetraOpAdjointSupport
00104     ) const;
00105   /// Returns <tt>this->mpiRange()</tt>
00106   Teuchos::RCP< const ScalarProdVectorSpaceBase<double> > rangeScalarProdVecSpc() const;
00107   /// Returns <tt>this->mpiDomain()</tt>
00108   Teuchos::RCP< const ScalarProdVectorSpaceBase<double> > domainScalarProdVecSpc() const;
00109 
00110   //@}
00111 
00112   /** Insert a set of elements in a row, adding to any previously
00113    * existing values. 
00114    * @param globalRowIndex the global index of the row to which these
00115    * elements belong.
00116    * @param nElemsToInsert the number of elements being inserted in this
00117    * step
00118    * @param globalColumnIndices array of column indices. Must 
00119    * be nElemsToInsert in length. 
00120    * @param elements array of element values. Must be nElemsToInsert in
00121    * length
00122    */
00123   virtual void addToRow(int globalRowIndex,
00124     int nElemsToInsert,
00125     const int* globalColumnIndices,
00126     const double* elementValues) ;
00127 
00128 
00129   /** 
00130    * Add to a batch of elements
00131    */
00132   virtual void addToElementBatch(int numRows, 
00133     int rowBlockSize,
00134     const int* globalRowIndices,
00135     int numColumnsPerRow,
00136     const int* globalColumnIndices,
00137     const double* values,
00138     const int* skipRow);
00139 
00140   /** Set all elements to zero, preserving the existing structure */
00141   virtual void zero() ;
00142 
00143 
00144   /** \name incomplete factorization preconditioning interface */
00145   //@{
00146   /** create an incomplete factorization. 
00147    * @param fillLevels number of levels of fill on the local processor
00148    * @param overlapFill number of levels of fill on remote processors
00149    * @param relaxationValue fraction of dropped values to be added to the
00150    * diagonal
00151    * @param relativeThreshold relative diagonal perutrbation
00152    * @param absoluteThreshold absolute diagonal perturbation
00153    * @param leftOrRight whether this preconditioner is to be applied
00154    * from the left or right 
00155    * @param rtn newly created preconditioner, returned 
00156    * by reference argument.
00157    */
00158   virtual void getILUKPreconditioner(int fillLevels,
00159     int overlapFill,
00160     double relaxationValue,
00161     double relativeThreshold,
00162     double absoluteThreshold,
00163     LeftOrRight leftOrRight,
00164     Preconditioner<double>& rtn) const ;
00165 
00166   /** Printable interface */
00167   virtual void print(std::ostream& os) const ;
00168 
00169 
00170   /** */
00171   std::ostream& describe(
00172     std::ostream                         &out
00173     ,const Teuchos::EVerbosityLevel      verbLevel
00174     ,const std::string                   leadingIndent
00175     , const std::string                   indentSpacer
00176     ) const 
00177     {
00178       out << leadingIndent << indentSpacer << this->description() << std::endl;
00179       return out;
00180     }
00181     
00182 
00183   /** */
00184   std::string description() const ;
00185 
00186   /** */
00187   static Epetra_CrsMatrix& getConcrete(const LinearOperator<double>& A);
00188 
00189   /** */
00190   static RCP<const Epetra_CrsMatrix> getConcretePtr(const LinearOperator<double>& A);
00191 
00192   /** 
00193    * Read-only access to the underlying crs matrix. Needed for Ifpack.
00194    */
00195   const Epetra_CrsMatrix* crsMatrix() const ;
00196 
00197 protected:
00198 
00199   /** Get the specified row as defined by RowAccessible  */
00200   void getRow(const int& row, 
00201     Teuchos::Array<int>& indices, 
00202     Teuchos::Array<double>& values) const;
00203 
00204 private:
00205 
00206   Epetra_CrsMatrix* crsMatrix();
00207 
00208   RCP<Epetra_CrsMatrix> matrix_;
00209 
00210   RCP<const VectorSpaceBase<double> > range_;
00211 
00212   RCP<const VectorSpaceBase<double> > domain_;
00213 
00214   const Epetra_Map& getRangeMap() const;
00215   const Epetra_Map& getDomainMap() const;
00216 };
00217 
00218   
00219 
00220 }
00221 
00222 #endif

Site Contact