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);
46 template <
class EpetraGlobalOrdinalType,
class TpetraMapType>
47 TPETRA_DEPRECATED_MSG(
"epetra removal")
49 tpetraToEpetraMapTmpl(const TpetraMapType &tpetraMap) {
50 using Teuchos::ArrayView;
51 typedef typename TpetraMapType::global_ordinal_type TGO;
52 typedef typename TpetraMapType::local_ordinal_type LO;
53 typedef EpetraGlobalOrdinalType EGO;
55 const TGO gblNumInds =
static_cast<TGO
>(tpetraMap.getGlobalNumElements());
56 const LO lclNumInds =
static_cast<LO
>(tpetraMap.getLocalNumElements());
57 ArrayView<const TGO> global_index_list = tpetraMap.getLocalElementList();
59 std::vector<EGO> global_index_list_epetra;
60 const EGO *global_index_list_epetra_ptr = NULL;
61 if (std::is_same<TGO, EGO>::value) {
62 global_index_list_epetra_ptr =
63 reinterpret_cast<const EGO *
>(global_index_list.getRawPtr());
65 global_index_list_epetra.resize(lclNumInds);
66 for (LO k = 0; k < lclNumInds; ++k) {
68 global_index_list_epetra[k] =
static_cast<EGO
>(global_index_list[k]);
70 global_index_list_epetra_ptr = global_index_list_epetra.data();
72 const EGO indexBase = tpetraMap.getIndexBase();
73 std::shared_ptr<Epetra_Comm> epetraComm =
74 Tpetra::Details::makeEpetraCommFromTeuchosComm(*(tpetraMap.getComm()));
82 return Epetra_Map(static_cast<EGO>(gblNumInds),
83 static_cast<int>(lclNumInds),
84 global_index_list_epetra_ptr, indexBase, *epetraComm);
92 template <
class TpetraMatrixType>
94 TPETRA_DEPRECATED_MSG(
"epetra removal")
95 EpetraRowMatrix : public Epetra_BasicRowMatrix {
97 EpetraRowMatrix(
const Teuchos::RCP<TpetraMatrixType> &mat,
const Epetra_Comm &comm);
98 virtual ~EpetraRowMatrix(){};
100 int ExtractMyRowCopy(
int MyRow,
int Length,
int &NumEntries,
double *Values,
int *Indices)
const;
103 int ExtractMyEntryView(
int CurEntry,
double *&Value,
int &RowIndex,
int &ColIndex);
106 int ExtractMyEntryView(
int CurEntry,
double const *&Value,
int &RowIndex,
int &ColIndex)
const;
108 int NumMyRowEntries(
int MyRow,
int &NumEntries)
const;
111 Teuchos::RCP<TpetraMatrixType> tpetra_matrix_;
114 template <
class TpetraMatrixType>
115 EpetraRowMatrix<TpetraMatrixType>::EpetraRowMatrix(
116 const Teuchos::RCP<TpetraMatrixType> &mat,
const Epetra_Comm &comm)
117 : Epetra_BasicRowMatrix(comm)
118 , tpetra_matrix_(mat) {
120 typedef typename TpetraMatrixType::map_type tpetra_map_type;
121 #if !defined(EPETRA_NO_64BIT_GLOBAL_INDICES)
123 typedef long long EGO;
124 #elif !defined(EPETRA_NO_32BIT_GLOBAL_INDICES)
128 #error "Epetra was not configured correctly. Neither 64-bit nor 32-bit indices are enabled."
130 const char tfecfFuncName[] =
"EpetraRowMatrix: ";
132 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(mat.is_null(), std::invalid_argument,
133 "The input Tpetra matrix is null.");
134 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(mat->getRowMap().is_null(), std::invalid_argument,
135 "The input Tpetra matrix's row Map is null.");
136 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(mat->getColMap().is_null(), std::invalid_argument,
137 "The input Tpetra matrix's column Map is null.");
139 RCP<const tpetra_map_type> tpetraRowMap = mat->getRowMap();
140 Epetra_Map epetraRowMap =
141 tpetraToEpetraMapTmpl<EGO, tpetra_map_type>(*tpetraRowMap);
142 RCP<const tpetra_map_type> tpetraColMap = mat->getColMap();
143 Epetra_Map epetraColMap =
144 tpetraToEpetraMapTmpl<EGO, tpetra_map_type>(*tpetraColMap);
145 this->SetMaps(epetraRowMap, epetraColMap);
148 template <
class TpetraMatrixType>
149 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyRowCopy(
int MyRow,
int Length,
int &NumEntries,
double *Values,
int *Indices)
const {
150 using inds_view =
typename TpetraMatrixType::nonconst_local_inds_host_view_type;
151 using vals_view =
typename TpetraMatrixType::nonconst_values_host_view_type;
152 static_assert(std::is_same<typename TpetraMatrixType::scalar_type, double>::value,
153 "This code assumes that Tpetra::CrsMatrix's scalar_type is int.");
154 static_assert(std::is_same<typename TpetraMatrixType::local_ordinal_type, int>::value,
155 "This code assumes that Tpetra::CrsMatrix's local_ordinal_type is int.");
156 inds_view IndicesView(Indices, Length);
157 vals_view ValuesView(Values, Length);
158 size_t num_entries = NumEntries;
159 tpetra_matrix_->getLocalRowCopy(MyRow, IndicesView, ValuesView, num_entries);
160 NumEntries = num_entries;
164 template <
class TpetraMatrixType>
165 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(
int CurEntry,
double *&Value,
int &RowIndex,
int &ColIndex) {
170 template <
class TpetraMatrixType>
171 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(
int CurEntry,
double const *&Value,
int &RowIndex,
int &ColIndex)
const {
176 template <
class TpetraMatrixType>
177 int EpetraRowMatrix<TpetraMatrixType>::NumMyRowEntries(
int MyRow,
int &NumEntries)
const {
178 NumEntries = tpetra_matrix_->getNumEntriesInLocalRow(MyRow);
184 #endif // defined(TPETRA_ENABLE_DEPRECATED_CODE) && defined(HAVE_TPETRA_EPETRA)