EpetraExt Package Browser (Single Doxygen Collection) Development
EpetraExt_BlockCrsMatrix.h
Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00005 //                 Copyright (2011) 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 Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 
00042 #ifndef EPETRAEXT_BLOCKCRSMATRIX_H
00043 #define EPETRAEXT_BLOCKCRSMATRIX_H
00044 
00045 #include <vector>
00046 
00047 #include "Epetra_ConfigDefs.h" 
00048 #include "Epetra_CrsMatrix.h" 
00049 
00051 
00058 namespace EpetraExt {
00059 
00060 class BlockCrsMatrix: public Epetra_CrsMatrix {
00061  public:
00062 
00064 
00065 
00074 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00075   BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector<int> & RowStencil, int RowIndex, const Epetra_Comm & GlobalComm );
00076 #endif
00077 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00078   BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector<long long> & RowStencil, long long RowIndex, const Epetra_Comm & GlobalComm );
00079 #endif
00080 
00082 
00091 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00092   BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector< std::vector<int> > & RowStencil, const std::vector<int> & RowIndices, const Epetra_Comm & GlobalComm );
00093 #endif
00094 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00095   BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector< std::vector<long long> > & RowStencil, const std::vector<long long> & RowIndices, const Epetra_Comm & GlobalComm );
00096 #endif
00097 
00099   BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const Epetra_CrsGraph& LocalBlockGraph, const Epetra_Comm & GlobalComm );
00100 
00101 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00102   BlockCrsMatrix( const Epetra_RowMatrix & BaseMatrix, const std::vector< std::vector<int> > & RowStencil, const std::vector<int> & RowIndices, const Epetra_Comm & GlobalComm );
00103 #endif
00104 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00105   BlockCrsMatrix( const Epetra_RowMatrix & BaseMatrix, const std::vector< std::vector<long long> > & RowStencil, const std::vector<long long> & RowIndices, const Epetra_Comm & GlobalComm );
00106 #endif
00107   
00109   BlockCrsMatrix( const BlockCrsMatrix & Matrix );
00110 
00112   virtual ~BlockCrsMatrix();
00114   
00115 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00116 
00117   const std::vector<int> & Stencil( int i = 0 ) {
00118     if(BaseGraph_.RowMap().GlobalIndicesInt())
00119       return RowStencil_int_[i];
00120     else
00121       throw "EpetraExt::BlockCrsMatrix::Stencil: Global Indices not int";
00122   }
00123 
00125   int RowIndex( int i = 0 ) {
00126     if(BaseGraph_.RowMap().GlobalIndicesInt())
00127       return RowIndices_int_[i];
00128     else
00129       throw "EpetraExt::BlockCrsMatrix::RowIndex: Global Indices not int";
00130   }
00131 #endif
00132 
00133 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00134 
00135   const std::vector<long long> & Stencil64( int i = 0 ) {
00136     if(BaseGraph_.RowMap().GlobalIndicesLongLong())
00137       return RowStencil_LL_[i];
00138     else
00139       throw "EpetraExt::BlockCrsMatrix::Stencil: Global Indices not long long";
00140   }
00141 
00143   long long RowIndex64( int i = 0 ) {
00144     if(BaseGraph_.RowMap().GlobalIndicesLongLong())
00145       return RowIndices_LL_[i];
00146     else
00147       throw "EpetraExt::BlockCrsMatrix::RowIndex: Global Indices not long long";
00148   }
00149 #endif
00150 
00153 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00154   void LoadBlock(const Epetra_RowMatrix & BaseMatrix, const int Row, const int Col);
00155 #endif
00156 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00157   void LoadBlock(const Epetra_RowMatrix & BaseMatrix, const long long Row, const long long Col);
00158 #endif
00159 
00162 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00163   void SumIntoBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int Row, const int Col);
00164 #endif
00165 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00166   void SumIntoBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const long long Row, const long long Col);
00167 #endif
00168 
00171 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00172   void SumIntoGlobalBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int Row, const int Col);
00173 #endif
00174 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00175   void SumIntoGlobalBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const long long Row, const long long Col);
00176 #endif
00177 
00180 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00181   void BlockSumIntoGlobalValues(const int BaseRow, int NumIndices,
00182      double* Values, const int* Indices, const int Row, const int Col);
00183 #endif
00184 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00185   void BlockSumIntoGlobalValues(const long long BaseRow, int NumIndices,
00186      double* Values, const long long* Indices, const long long Row, const long long Col);
00187 #endif
00188 
00189 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00190   void BlockReplaceGlobalValues(const int BaseRow, int NumIndices,
00191      double* Values, const int* Indices, const int Row, const int Col);
00192 #endif
00193 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00194   void BlockReplaceGlobalValues(const long long BaseRow, int NumIndices,
00195      double* Values, const long long* Indices, const long long Row, const long long Col);
00196 #endif
00197 
00198 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00199   void BlockExtractGlobalRowView(const int BaseRow, int& NumEntries, 
00200      double*& Values, const int Row, const int Col);
00201 #endif
00202 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00203   void BlockExtractGlobalRowView(const long long BaseRow, int& NumEntries, 
00204      double*& Values, const long long Row, const long long Col);
00205 #endif
00206 
00207 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00208   void ExtractBlock(Epetra_CrsMatrix & BaseMatrix, const int Row, const int Col);
00209 #endif
00210 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00211   void ExtractBlock(Epetra_CrsMatrix & BaseMatrix, const long long Row, const long long Col);
00212 #endif
00213 
00214  protected:
00215 
00216   Epetra_CrsGraph BaseGraph_;
00217 
00218 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00219   std::vector< std::vector<int> > RowStencil_int_;
00220 
00221   std::vector<int> RowIndices_int_; 
00222 #endif
00223 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00224   std::vector< std::vector<long long> > RowStencil_LL_;
00225 
00226   std::vector<long long> RowIndices_LL_; 
00227 #endif
00228 
00229   long long ROffset_;
00230   long long COffset_;
00231 
00232 private:
00233   template<typename int_type>
00234   void TLoadBlock(const Epetra_RowMatrix & BaseMatrix, const int_type Row, const int_type Col);
00235 
00236   template<typename int_type>
00237   void TSumIntoBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int_type Row, const int_type Col);
00238 
00239   template<typename int_type>
00240   void TSumIntoGlobalBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int_type Row, const int_type Col);
00241 
00242   template<typename int_type>
00243   void TBlockSumIntoGlobalValues(const int_type BaseRow, int NumIndices,
00244      double* Values, const int_type* Indices, const int_type Row, const int_type Col);
00245 
00246   template<typename int_type>
00247   void TBlockReplaceGlobalValues(const int_type BaseRow, int NumIndices,
00248      double* Values, const int_type* Indices, const int_type Row, const int_type Col);
00249 
00250   template<typename int_type>
00251   void TBlockExtractGlobalRowView(const int_type BaseRow, int& NumEntries, 
00252      double*& Values, const int_type Row, const int_type Col);
00253 
00254   template<typename int_type>
00255   void TExtractBlock(Epetra_CrsMatrix & BaseMatrix, const int_type Row, const int_type Col);
00256 
00257   template<typename int_type>
00258   std::vector< std::vector<int_type> >& TRowStencil();
00259 
00260   template<typename int_type>
00261   std::vector<int_type>& TRowIndices();
00262 };
00263 
00264 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00265 template<> inline std::vector<int>& BlockCrsMatrix::TRowIndices() { return RowIndices_int_; }
00266 template<> inline std::vector< std::vector<int> >& BlockCrsMatrix::TRowStencil() { return RowStencil_int_; }
00267 #endif
00268 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00269 template<> inline std::vector<long long>& BlockCrsMatrix::TRowIndices() { return RowIndices_LL_; }
00270 template<> inline std::vector< std::vector<long long> >& BlockCrsMatrix::TRowStencil() { return RowStencil_LL_; }
00271 #endif
00272 
00273 } //namespace EpetraExt
00274 
00275 #endif /* EPETRA_CRSMATRIX_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines