Tpetra parallel linear algebra  Version of the Day
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  typedef typename TpetraMatrixType::global_ordinal_type GO;
87  GO globalNumRows = tpetra_matrix_->getRowMap()->getGlobalNumElements();
88  GO globalNumCols = tpetra_matrix_->getColMap()->getGlobalNumElements();
89  Teuchos::ArrayView<const GO> row_elem_list = tpetra_matrix_->getRowMap()->getNodeElementList();
90  Teuchos::ArrayView<const GO> col_elem_list = tpetra_matrix_->getColMap()->getNodeElementList();
91  Epetra_Map rowmap(globalNumRows, row_elem_list.size(), row_elem_list.getRawPtr(), 0, comm);
92  Epetra_Map colmap(globalNumCols, col_elem_list.size(), col_elem_list.getRawPtr(), 0, comm);
93  SetMaps(rowmap, colmap);
94 }
95 
96 template<class TpetraMatrixType>
97 EpetraRowMatrix<TpetraMatrixType>::~EpetraRowMatrix()
98 {
99 }
100 
101 template<class TpetraMatrixType>
102 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const
103 {
104  Teuchos::ArrayView<int> inds(Indices, Length);
105  Teuchos::ArrayView<double> vals(Values, Length);
106  size_t num_entries = NumEntries;
107  tpetra_matrix_->getLocalRowCopy(MyRow, inds, vals, num_entries);
108  NumEntries = num_entries;
109  return 0;
110 }
111 
112 template<class TpetraMatrixType>
113 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(int CurEntry, double * & Value, int & RowIndex, int & ColIndex)
114 {
115  //not implemented
116  return -1;
117 }
118 
119 template<class TpetraMatrixType>
120 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(int CurEntry, double const * & Value, int & RowIndex, int & ColIndex) const
121 {
122  //not implemented
123  return -1;
124 }
125 
126 template<class TpetraMatrixType>
127 int EpetraRowMatrix<TpetraMatrixType>::NumMyRowEntries(int MyRow, int & NumEntries) const
128 {
129  NumEntries = tpetra_matrix_->getNumEntriesInLocalRow(MyRow);
130  return 0;
131 }
132 
133 }//namespace Tpetra
134 
135 #endif // defined(HAVE_TPETRA_EPETRA)
136 
137 //here is the include-guard #endif:
138 
139 #endif
Namespace Tpetra contains the class and methods constituting the Tpetra library.