10 #ifndef TPETRA_EPETRAROWMATRIX_HPP
11 #define TPETRA_EPETRAROWMATRIX_HPP
13 #include "TpetraCore_config.h"
15 #if !defined(TPETRA_ENABLE_DEPRECATED_CODE)
16 #error This file is deprecated due to Epetra removal and will be removed
19 #if defined(TPETRA_ENABLE_DEPRECATED_CODE) && defined(HAVE_TPETRA_EPETRA)
21 #include <Epetra_Comm.h>
22 #include <Epetra_BasicRowMatrix.h>
23 #include <Tpetra_CrsMatrix.hpp>
24 #include <Teuchos_TestForException.hpp>
27 #include <type_traits>
37 TPETRA_DEPRECATED_MSG(
"epetra removal")
38 std::shared_ptr<Epetra_Comm>
39 makeEpetraCommFromTeuchosComm (const Teuchos::Comm<
int>& teuchosComm);
47 template<
class EpetraGlobalOrdinalType,
class TpetraMapType>
48 TPETRA_DEPRECATED_MSG(
"epetra removal")
50 tpetraToEpetraMapTmpl (const TpetraMapType& tpetraMap)
52 using Teuchos::ArrayView;
53 typedef typename TpetraMapType::global_ordinal_type TGO;
54 typedef typename TpetraMapType::local_ordinal_type LO;
55 typedef EpetraGlobalOrdinalType EGO;
57 const TGO gblNumInds =
static_cast<TGO
> (tpetraMap.getGlobalNumElements ());
58 const LO lclNumInds =
static_cast<LO
> (tpetraMap.getLocalNumElements ());
59 ArrayView<const TGO> global_index_list = tpetraMap.getLocalElementList ();
61 std::vector<EGO> global_index_list_epetra;
62 const EGO* global_index_list_epetra_ptr = NULL;
63 if (std::is_same<TGO, EGO>::value) {
64 global_index_list_epetra_ptr =
65 reinterpret_cast<const EGO*
> (global_index_list.getRawPtr ());
68 global_index_list_epetra.resize (lclNumInds);
69 for (LO k = 0; k < lclNumInds; ++k) {
71 global_index_list_epetra[k] =
static_cast<EGO
> (global_index_list[k]);
73 global_index_list_epetra_ptr = global_index_list_epetra.data ();
75 const EGO indexBase = tpetraMap.getIndexBase ();
76 std::shared_ptr<Epetra_Comm> epetraComm =
77 Tpetra::Details::makeEpetraCommFromTeuchosComm (* (tpetraMap.getComm ()));
85 return Epetra_Map (static_cast<EGO> (gblNumInds),
86 static_cast<int> (lclNumInds),
87 global_index_list_epetra_ptr, indexBase, *epetraComm);
95 template<
class TpetraMatrixType>
class
96 TPETRA_DEPRECATED_MSG("epetra removal")
97 EpetraRowMatrix :
public Epetra_BasicRowMatrix {
100 EpetraRowMatrix(
const Teuchos::RCP<TpetraMatrixType> &mat,
const Epetra_Comm &comm);
101 virtual ~EpetraRowMatrix() {};
103 int ExtractMyRowCopy(
int MyRow,
int Length,
int & NumEntries,
double *Values,
int * Indices)
const;
106 int ExtractMyEntryView(
int CurEntry,
double * & Value,
int & RowIndex,
int & ColIndex);
109 int ExtractMyEntryView(
int CurEntry,
double const * & Value,
int & RowIndex,
int & ColIndex)
const;
111 int NumMyRowEntries(
int MyRow,
int & NumEntries)
const;
114 Teuchos::RCP<TpetraMatrixType> tpetra_matrix_;
117 template<
class TpetraMatrixType>
118 EpetraRowMatrix<TpetraMatrixType>::EpetraRowMatrix(
119 const Teuchos::RCP<TpetraMatrixType> &mat,
const Epetra_Comm &comm
121 : Epetra_BasicRowMatrix(comm),
125 typedef typename TpetraMatrixType::map_type tpetra_map_type;
126 #if ! defined(EPETRA_NO_64BIT_GLOBAL_INDICES)
128 typedef long long EGO;
129 #elif ! defined(EPETRA_NO_32BIT_GLOBAL_INDICES)
133 # error "Epetra was not configured correctly. Neither 64-bit nor 32-bit indices are enabled."
135 const char tfecfFuncName[] =
"EpetraRowMatrix: ";
137 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
138 (mat.is_null (), std::invalid_argument,
139 "The input Tpetra matrix is null.");
140 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
141 (mat->getRowMap ().is_null (), std::invalid_argument,
142 "The input Tpetra matrix's row Map is null.");
143 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
144 (mat->getColMap ().is_null (), std::invalid_argument,
145 "The input Tpetra matrix's column Map is null.");
147 RCP<const tpetra_map_type> tpetraRowMap = mat->getRowMap ();
148 Epetra_Map epetraRowMap =
149 tpetraToEpetraMapTmpl<EGO, tpetra_map_type> (*tpetraRowMap);
150 RCP<const tpetra_map_type> tpetraColMap = mat->getColMap ();
151 Epetra_Map epetraColMap =
152 tpetraToEpetraMapTmpl<EGO, tpetra_map_type> (*tpetraColMap);
153 this->SetMaps (epetraRowMap, epetraColMap);
156 template<
class TpetraMatrixType>
157 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyRowCopy(
int MyRow,
int Length,
int & NumEntries,
double *Values,
int * Indices)
const
159 using inds_view =
typename TpetraMatrixType::nonconst_local_inds_host_view_type;
160 using vals_view =
typename TpetraMatrixType::nonconst_values_host_view_type;
161 static_assert (std::is_same<typename TpetraMatrixType::scalar_type, double>::value,
162 "This code assumes that Tpetra::CrsMatrix's scalar_type is int.");
163 static_assert (std::is_same<typename TpetraMatrixType::local_ordinal_type, int>::value,
164 "This code assumes that Tpetra::CrsMatrix's local_ordinal_type is int.");
165 inds_view IndicesView(Indices, Length);
166 vals_view ValuesView(Values, Length);
167 size_t num_entries = NumEntries;
168 tpetra_matrix_->getLocalRowCopy(MyRow, IndicesView, ValuesView, num_entries);
169 NumEntries = num_entries;
173 template<
class TpetraMatrixType>
174 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(
int CurEntry,
double * & Value,
int & RowIndex,
int & ColIndex)
180 template<
class TpetraMatrixType>
181 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(
int CurEntry,
double const * & Value,
int & RowIndex,
int & ColIndex)
const
187 template<
class TpetraMatrixType>
188 int EpetraRowMatrix<TpetraMatrixType>::NumMyRowEntries(
int MyRow,
int & NumEntries)
const
190 NumEntries = tpetra_matrix_->getNumEntriesInLocalRow(MyRow);
196 #endif // defined(TPETRA_ENABLE_DEPRECATED_CODE) && defined(HAVE_TPETRA_EPETRA)