Tpetra_EpetraRowMatrix.hpp

00001 #ifndef TPETRA_EPETRAROWMATRIX_HPP
00002 #define TPETRA_EPETRAROWMATRIX_HPP
00003 
00004 #include <Tpetra_ConfigDefs.hpp>
00005 
00006 #if defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_MPI)
00007 
00008 #include <mpi.h>
00009 
00010 #include <Epetra_MpiComm.h>
00011 #include <Epetra_BasicRowMatrix.h>
00012 #include <Tpetra_CrsMatrix.hpp>
00013 
00014 namespace Tpetra
00015 {
00016 
00018 template<class TpetraMatrixType>
00019 class EpetraRowMatrix : public Epetra_BasicRowMatrix {
00020 public:
00021   EpetraRowMatrix(Teuchos::RCP<TpetraMatrixType> mat, MPI_Comm mpicomm);
00022   virtual ~EpetraRowMatrix();
00023 
00024   int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const;
00025 
00026   //not implemented
00027   int ExtractMyEntryView(int CurEntry, double * & Value, int & RowIndex, int & ColIndex);
00028 
00029   //not implemented
00030   int ExtractMyEntryView(int CurEntry, double const * & Value, int & RowIndex, int & ColIndex) const;
00031 
00032   int NumMyRowEntries(int MyRow, int & NumEntries) const;
00033 
00034 private:
00035   Teuchos::RCP<TpetraMatrixType> tpetra_matrix_;
00036 };//class EpetraRowMatrix
00037 
00038 template<class TpetraMatrixType>
00039 EpetraRowMatrix<TpetraMatrixType>::EpetraRowMatrix(Teuchos::RCP<TpetraMatrixType> mat, MPI_Comm mpicomm)
00040  : Epetra_BasicRowMatrix(Epetra_MpiComm(mpicomm)),
00041    tpetra_matrix_(mat)
00042 {
00043   Epetra_MpiComm ecomm(mpicomm);
00044   int globalNumRows = tpetra_matrix_->getRowMap()->getGlobalNumElements();
00045   int globalNumCols = tpetra_matrix_->getColMap()->getGlobalNumElements();
00046   Teuchos::ArrayView<const int> row_elem_list = tpetra_matrix_->getRowMap()->getNodeElementList();
00047   Teuchos::ArrayView<const int> col_elem_list = tpetra_matrix_->getColMap()->getNodeElementList();
00048   Epetra_Map rowmap(globalNumRows, row_elem_list.size(), row_elem_list.getRawPtr(), 0, ecomm);
00049   Epetra_Map colmap(globalNumCols, col_elem_list.size(), col_elem_list.getRawPtr(), 0, ecomm);
00050   SetMaps(rowmap, colmap);
00051 }
00052 
00053 template<class TpetraMatrixType>
00054 EpetraRowMatrix<TpetraMatrixType>::~EpetraRowMatrix()
00055 {
00056 }
00057 
00058 template<class TpetraMatrixType>
00059 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const
00060 {
00061   Teuchos::ArrayView<int> inds(Indices, Length);
00062   Teuchos::ArrayView<double> vals(Values, Length);
00063   size_t num_entries = NumEntries;
00064   tpetra_matrix_->getLocalRowCopy(MyRow, inds, vals, num_entries);
00065   NumEntries = num_entries;
00066   return 0;
00067 }
00068 
00069 template<class TpetraMatrixType>
00070 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(int CurEntry, double * & Value, int & RowIndex, int & ColIndex)
00071 {
00072   //not implemented
00073   return -1;
00074 }
00075 
00076 template<class TpetraMatrixType>
00077 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(int CurEntry, double const * & Value, int & RowIndex, int & ColIndex) const
00078 {
00079   //not implemented
00080   return -1;
00081 }
00082 
00083 template<class TpetraMatrixType>
00084 int EpetraRowMatrix<TpetraMatrixType>::NumMyRowEntries(int MyRow, int & NumEntries) const
00085 {
00086   NumEntries = tpetra_matrix_->getNumEntriesInLocalRow(MyRow);
00087   return 0;
00088 }
00089 
00090 }//namespace Tpetra
00091 
00092 //here is the #endif for defined(HAVE_TPETRA_EPETRA)&&defined(HAVE_TPETRA_MPI):
00093 #endif
00094 
00095 //here is the include-guard #endif:
00096 #endif
00097 

Generated on Tue Jul 13 09:39:06 2010 for Tpetra Matrix/Vector Services by  doxygen 1.4.7