Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Tpetra_EpetraRowMatrix.hpp
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Tpetra: Templated Linear Algebra Services Package
6 // Copyright (2008) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 // @HEADER
42 */
43 
44 #ifndef TPETRA_EPETRAROWMATRIX_HPP
45 #define TPETRA_EPETRAROWMATRIX_HPP
46 
47 #include <Tpetra_ConfigDefs.hpp>
48 
49 #if defined(HAVE_TPETRA_EPETRA)
50 
51 #include <Epetra_Comm.h>
52 #include <Epetra_BasicRowMatrix.h>
53 #include <Tpetra_CrsMatrix.hpp>
54 
55 namespace Tpetra
56 {
57 
59 template<class TpetraMatrixType>
60 class EpetraRowMatrix : public Epetra_BasicRowMatrix {
61 public:
62  EpetraRowMatrix(const Teuchos::RCP<TpetraMatrixType> &mat, const Epetra_Comm &comm);
63  virtual ~EpetraRowMatrix();
64 
65  int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const;
66 
67  //not implemented
68  int ExtractMyEntryView(int CurEntry, double * & Value, int & RowIndex, int & ColIndex);
69 
70  //not implemented
71  int ExtractMyEntryView(int CurEntry, double const * & Value, int & RowIndex, int & ColIndex) const;
72 
73  int NumMyRowEntries(int MyRow, int & NumEntries) const;
74 
75 private:
76  Teuchos::RCP<TpetraMatrixType> tpetra_matrix_;
77 };//class EpetraRowMatrix
78 
79 template<class TpetraMatrixType>
80 EpetraRowMatrix<TpetraMatrixType>::EpetraRowMatrix(
81  const Teuchos::RCP<TpetraMatrixType> &mat, const Epetra_Comm &comm
82  )
83  : Epetra_BasicRowMatrix(comm),
84  tpetra_matrix_(mat)
85 {
86  int globalNumRows = tpetra_matrix_->getRowMap()->getGlobalNumElements();
87  int globalNumCols = tpetra_matrix_->getColMap()->getGlobalNumElements();
88  Teuchos::ArrayView<const int> row_elem_list = tpetra_matrix_->getRowMap()->getNodeElementList();
89  Teuchos::ArrayView<const int> col_elem_list = tpetra_matrix_->getColMap()->getNodeElementList();
90  Epetra_Map rowmap(globalNumRows, row_elem_list.size(), row_elem_list.getRawPtr(), 0, comm);
91  Epetra_Map colmap(globalNumCols, col_elem_list.size(), col_elem_list.getRawPtr(), 0, comm);
92  SetMaps(rowmap, colmap);
93 }
94 
95 template<class TpetraMatrixType>
96 EpetraRowMatrix<TpetraMatrixType>::~EpetraRowMatrix()
97 {
98 }
99 
100 template<class TpetraMatrixType>
101 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const
102 {
103  Teuchos::ArrayView<int> inds(Indices, Length);
104  Teuchos::ArrayView<double> vals(Values, Length);
105  size_t num_entries = NumEntries;
106  tpetra_matrix_->getLocalRowCopy(MyRow, inds, vals, num_entries);
107  NumEntries = num_entries;
108  return 0;
109 }
110 
111 template<class TpetraMatrixType>
112 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(int CurEntry, double * & Value, int & RowIndex, int & ColIndex)
113 {
114  //not implemented
115  return -1;
116 }
117 
118 template<class TpetraMatrixType>
119 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(int CurEntry, double const * & Value, int & RowIndex, int & ColIndex) const
120 {
121  //not implemented
122  return -1;
123 }
124 
125 template<class TpetraMatrixType>
126 int EpetraRowMatrix<TpetraMatrixType>::NumMyRowEntries(int MyRow, int & NumEntries) const
127 {
128  NumEntries = tpetra_matrix_->getNumEntriesInLocalRow(MyRow);
129  return 0;
130 }
131 
132 }//namespace Tpetra
133 
134 #endif // defined(HAVE_TPETRA_EPETRA)
135 
136 //here is the include-guard #endif:
137 
138 #endif