00001 /* @HEADER@ */ 00002 // ************************************************************************ 00003 // 00004 // Playa: Programmable Linear Algebra 00005 // Copyright 2012 Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu) 00038 // 00039 00040 /* @HEADER@ */ 00041 00042 #ifndef PLAYA_EPETRAMATRIX_HPP 00043 #define PLAYA_EPETRAMATRIX_HPP 00044 00045 #include "PlayaLoadableMatrix.hpp" 00046 #include "PlayaLinearOperatorDecl.hpp" 00047 #include "PlayaLinearOpWithSpacesDecl.hpp" 00048 #include "PlayaRowAccessibleOp.hpp" 00049 #include "PlayaPrintable.hpp" 00050 #include "PlayaILUFactorizableOp.hpp" 00051 #include "PlayaICCFactorizableOp.hpp" 00052 #include "Epetra_CrsMatrix.h" 00053 #include "PlayaLinearOpWithSpacesDecl.hpp" 00054 00055 namespace Playa 00056 { 00057 using namespace Teuchos; 00058 00059 00060 00061 /** Playa wrapper for epetra matrix */ 00062 class EpetraMatrix : public LinearOpWithSpaces<double>, 00063 public LoadableMatrix<double>, 00064 public RowAccessibleOp<double>, 00065 public Printable, 00066 public ILUFactorizableOp<double>, 00067 public ICCFactorizableOp<double> 00068 { 00069 public: 00070 00071 /** Construct an empty EpetraMatrix structured according to the graph 00072 * argument */ 00073 EpetraMatrix(const Epetra_CrsGraph& graph, 00074 const VectorSpace<double>& domain, 00075 const VectorSpace<double>& range); 00076 00077 /** Wrap an existing Epetra CRS Matrix */ 00078 EpetraMatrix(const RCP<Epetra_CrsMatrix>& mat, 00079 const VectorSpace<double>& domain, 00080 const VectorSpace<double>& range); 00081 00082 /** Apply the operator */ 00083 virtual void apply( 00084 Teuchos::ETransp applyType, 00085 const Vector<double>& in, 00086 Vector<double> out) const ; 00087 00088 00089 00090 /** \name LoadableMatrix interface functions */ 00091 //@{ 00092 /** Insert a set of elements in a row, adding to any previously 00093 * existing values. 00094 * @param globalRowIndex the global index of the row to which these 00095 * elements belong. 00096 * @param nElemsToInsert the number of elements being inserted in this 00097 * step 00098 * @param globalColumnIndices array of column indices. Must 00099 * be nElemsToInsert in length. 00100 * @param elements array of element values. Must be nElemsToInsert in 00101 * length 00102 */ 00103 virtual void addToRow(int globalRowIndex, 00104 int nElemsToInsert, 00105 const int* globalColumnIndices, 00106 const double* elementValues) ; 00107 00108 00109 /** 00110 * Add to a batch of elements 00111 */ 00112 virtual void addToElementBatch(int numRows, 00113 int rowBlockSize, 00114 const int* globalRowIndices, 00115 int numColumnsPerRow, 00116 const int* globalColumnIndices, 00117 const double* values, 00118 const int* skipRow); 00119 00120 /** Set all elements to zero, preserving the existing structure */ 00121 virtual void zero() ; 00122 00123 //@} 00124 00125 /** \name incomplete factorization preconditioning interface */ 00126 //@{ 00127 /** create an incomplete factorization. 00128 * @param fillLevels number of levels of fill on the local processor 00129 * @param overlapFill number of levels of fill on remote processors 00130 * @param relaxationValue fraction of dropped values to be added to the 00131 * diagonal 00132 * @param relativeThreshold relative diagonal perutrbation 00133 * @param absoluteThreshold absolute diagonal perturbation 00134 * @param leftOrRight whether this preconditioner is to be applied 00135 * from the left or right 00136 * @param rtn newly created preconditioner, returned 00137 * by reference argument. 00138 */ 00139 virtual void getILUKPreconditioner(int fillLevels, 00140 int overlapFill, 00141 double relaxationValue, 00142 double relativeThreshold, 00143 double absoluteThreshold, 00144 LeftOrRight leftOrRight, 00145 Preconditioner<double>& rtn) const ; 00146 //@} 00147 00148 00149 /** \name incomplete factorization preconditioning interface */ 00150 //@{ 00151 /** create an incomplete factorization. 00152 * @param fillLevels number of levels of fill on the local processor 00153 * @param overlapFill number of levels of fill on remote processors 00154 * @param relaxationValue fraction of dropped values to be added to the 00155 * diagonal 00156 * @param relativeThreshold relative diagonal perutrbation 00157 * @param absoluteThreshold absolute diagonal perturbation 00158 * @param rtn newly created preconditioner, returned 00159 * by reference argument. 00160 */ 00161 virtual void getICCPreconditioner(int fillLevels, 00162 int overlapFill, 00163 double dropTolerance, 00164 double relaxationValue, 00165 double relativeThreshold, 00166 double absoluteThreshold, 00167 Preconditioner<double>& rtn) const ; 00168 00169 00170 /** \name Row access interface */ 00171 //@{ 00172 /** Get the specified row as defined by RowAccessible */ 00173 void getRow(const int& row, 00174 Teuchos::Array<int>& indices, 00175 Teuchos::Array<double>& values) const; 00176 //@} 00177 00178 00179 /** \name Diagnostic output */ 00180 //@{ 00181 /** Print the matrix */ 00182 virtual void print(std::ostream& os) const ; 00183 //@} 00184 00185 /** */ 00186 std::ostream& describe( 00187 std::ostream &out 00188 ,const Teuchos::EVerbosityLevel verbLevel 00189 ,const std::string leadingIndent 00190 , const std::string indentSpacer 00191 ) const 00192 { 00193 out << leadingIndent << indentSpacer << this->description() << std::endl; 00194 return out; 00195 } 00196 /** */ 00197 std::string description() const ; 00198 //@} 00199 00200 /** */ 00201 static Epetra_CrsMatrix& getConcrete(const LinearOperator<double>& A); 00202 00203 /** */ 00204 static RCP<const Epetra_CrsMatrix> getConcretePtr(const LinearOperator<double>& A); 00205 00206 /** 00207 * Read-only access to the underlying crs matrix. Needed by Ifpack and ML. 00208 */ 00209 const Epetra_CrsMatrix* crsMatrix() const ; 00210 00211 private: 00212 00213 Epetra_CrsMatrix* crsMatrix(); 00214 00215 RCP<Epetra_CrsMatrix> matrix_; 00216 00217 const Epetra_Map& getRangeMap() const; 00218 const Epetra_Map& getDomainMap() const; 00219 }; 00220 00221 00222 00223 } 00224 00225 #endif