44 #ifndef TPETRA_EPETRAROWMATRIX_HPP
45 #define TPETRA_EPETRAROWMATRIX_HPP
47 #include "TpetraCore_config.h"
49 #if !defined(TPETRA_ENABLE_DEPRECATED_CODE)
50 #error This file is deprecated due to Epetra removal and will be removed
53 #if defined(TPETRA_ENABLE_DEPRECATED_CODE) && defined(HAVE_TPETRA_EPETRA)
55 #include <Epetra_Comm.h>
56 #include <Epetra_BasicRowMatrix.h>
57 #include <Tpetra_CrsMatrix.hpp>
58 #include <Teuchos_TestForException.hpp>
61 #include <type_traits>
71 TPETRA_DEPRECATED_MSG(
"epetra removal")
72 std::shared_ptr<Epetra_Comm>
73 makeEpetraCommFromTeuchosComm (const Teuchos::Comm<
int>& teuchosComm);
81 template<
class EpetraGlobalOrdinalType,
class TpetraMapType>
82 TPETRA_DEPRECATED_MSG(
"epetra removal")
84 tpetraToEpetraMapTmpl (const TpetraMapType& tpetraMap)
86 using Teuchos::ArrayView;
87 typedef typename TpetraMapType::global_ordinal_type TGO;
88 typedef typename TpetraMapType::local_ordinal_type LO;
89 typedef EpetraGlobalOrdinalType EGO;
91 const TGO gblNumInds =
static_cast<TGO
> (tpetraMap.getGlobalNumElements ());
92 const LO lclNumInds =
static_cast<LO
> (tpetraMap.getLocalNumElements ());
93 ArrayView<const TGO> global_index_list = tpetraMap.getLocalElementList ();
95 std::vector<EGO> global_index_list_epetra;
96 const EGO* global_index_list_epetra_ptr = NULL;
97 if (std::is_same<TGO, EGO>::value) {
98 global_index_list_epetra_ptr =
99 reinterpret_cast<const EGO*
> (global_index_list.getRawPtr ());
102 global_index_list_epetra.resize (lclNumInds);
103 for (LO k = 0; k < lclNumInds; ++k) {
105 global_index_list_epetra[k] =
static_cast<EGO
> (global_index_list[k]);
107 global_index_list_epetra_ptr = global_index_list_epetra.data ();
109 const EGO indexBase = tpetraMap.getIndexBase ();
110 std::shared_ptr<Epetra_Comm> epetraComm =
111 Tpetra::Details::makeEpetraCommFromTeuchosComm (* (tpetraMap.getComm ()));
119 return Epetra_Map (static_cast<EGO> (gblNumInds),
120 static_cast<int> (lclNumInds),
121 global_index_list_epetra_ptr, indexBase, *epetraComm);
129 template<
class TpetraMatrixType>
class
130 TPETRA_DEPRECATED_MSG("epetra removal")
131 EpetraRowMatrix :
public Epetra_BasicRowMatrix {
134 EpetraRowMatrix(
const Teuchos::RCP<TpetraMatrixType> &mat,
const Epetra_Comm &comm);
135 virtual ~EpetraRowMatrix() {};
137 int ExtractMyRowCopy(
int MyRow,
int Length,
int & NumEntries,
double *Values,
int * Indices)
const;
140 int ExtractMyEntryView(
int CurEntry,
double * & Value,
int & RowIndex,
int & ColIndex);
143 int ExtractMyEntryView(
int CurEntry,
double const * & Value,
int & RowIndex,
int & ColIndex)
const;
145 int NumMyRowEntries(
int MyRow,
int & NumEntries)
const;
148 Teuchos::RCP<TpetraMatrixType> tpetra_matrix_;
151 template<
class TpetraMatrixType>
152 EpetraRowMatrix<TpetraMatrixType>::EpetraRowMatrix(
153 const Teuchos::RCP<TpetraMatrixType> &mat,
const Epetra_Comm &comm
155 : Epetra_BasicRowMatrix(comm),
159 typedef typename TpetraMatrixType::map_type tpetra_map_type;
160 #if ! defined(EPETRA_NO_64BIT_GLOBAL_INDICES)
162 typedef long long EGO;
163 #elif ! defined(EPETRA_NO_32BIT_GLOBAL_INDICES)
167 # error "Epetra was not configured correctly. Neither 64-bit nor 32-bit indices are enabled."
169 const char tfecfFuncName[] =
"EpetraRowMatrix: ";
171 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
172 (mat.is_null (), std::invalid_argument,
173 "The input Tpetra matrix is null.");
174 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
175 (mat->getRowMap ().is_null (), std::invalid_argument,
176 "The input Tpetra matrix's row Map is null.");
177 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
178 (mat->getColMap ().is_null (), std::invalid_argument,
179 "The input Tpetra matrix's column Map is null.");
181 RCP<const tpetra_map_type> tpetraRowMap = mat->getRowMap ();
182 Epetra_Map epetraRowMap =
183 tpetraToEpetraMapTmpl<EGO, tpetra_map_type> (*tpetraRowMap);
184 RCP<const tpetra_map_type> tpetraColMap = mat->getColMap ();
185 Epetra_Map epetraColMap =
186 tpetraToEpetraMapTmpl<EGO, tpetra_map_type> (*tpetraColMap);
187 this->SetMaps (epetraRowMap, epetraColMap);
190 template<
class TpetraMatrixType>
191 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyRowCopy(
int MyRow,
int Length,
int & NumEntries,
double *Values,
int * Indices)
const
193 using inds_view =
typename TpetraMatrixType::nonconst_local_inds_host_view_type;
194 using vals_view =
typename TpetraMatrixType::nonconst_values_host_view_type;
195 static_assert (std::is_same<typename TpetraMatrixType::scalar_type, double>::value,
196 "This code assumes that Tpetra::CrsMatrix's scalar_type is int.");
197 static_assert (std::is_same<typename TpetraMatrixType::local_ordinal_type, int>::value,
198 "This code assumes that Tpetra::CrsMatrix's local_ordinal_type is int.");
199 inds_view IndicesView(Indices, Length);
200 vals_view ValuesView(Values, Length);
201 size_t num_entries = NumEntries;
202 tpetra_matrix_->getLocalRowCopy(MyRow, IndicesView, ValuesView, num_entries);
203 NumEntries = num_entries;
207 template<
class TpetraMatrixType>
208 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(
int CurEntry,
double * & Value,
int & RowIndex,
int & ColIndex)
214 template<
class TpetraMatrixType>
215 int EpetraRowMatrix<TpetraMatrixType>::ExtractMyEntryView(
int CurEntry,
double const * & Value,
int & RowIndex,
int & ColIndex)
const
221 template<
class TpetraMatrixType>
222 int EpetraRowMatrix<TpetraMatrixType>::NumMyRowEntries(
int MyRow,
int & NumEntries)
const
224 NumEntries = tpetra_matrix_->getNumEntriesInLocalRow(MyRow);
230 #endif // defined(TPETRA_ENABLE_DEPRECATED_CODE) && defined(HAVE_TPETRA_EPETRA)