19 #ifndef AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
20 #define AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
22 #include <Epetra_RowMatrix.h>
23 #include <Epetra_Map.h>
24 #include <Epetra_Comm.h>
32 using Teuchos::ArrayView;
34 template <
class DerivedMat>
35 AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::AbstractConcreteMatrixAdapter(RCP<DerivedMat> m)
36 : MatrixAdapter<DerivedMat>(m)
42 template <
class DerivedMat>
44 AbstractConcreteMatrixAdapter<
46 DerivedMat>::getGlobalRowCopy_impl(global_ordinal_t row,
47 const ArrayView<global_ordinal_t>& indices,
48 const ArrayView<scalar_t>& vals,
52 const int local_row = this->row_map_->getLocalElement(row);
55 Teuchos::Array<local_ordinal_t> epetra_lcl_inds_buf;
56 Teuchos::ArrayView<local_ordinal_t> epetra_lcl_inds;
57 if (! std::is_same<global_ordinal_t, local_ordinal_t>::value) {
61 err = this->mat_->NumMyRowEntries (local_row, num_ent);
63 catch (
int integer_exception) {
65 err = integer_exception;
67 TEUCHOS_TEST_FOR_EXCEPTION
68 (threw && err != 0, std::runtime_error,
"Epetra_RowMatrix::"
69 "NumMyRowEntries, called on local row " << local_row <<
", threw "
70 "an integer exception " << err <<
".");
71 TEUCHOS_TEST_FOR_EXCEPTION
72 (! threw && err != 0, std::runtime_error,
"Epetra_RowMatrix returned "
73 "error code " << err <<
" from NumMyRowEntries for local row "
75 epetra_lcl_inds_buf.resize (num_ent);
76 epetra_lcl_inds = epetra_lcl_inds_buf ();
79 using Teuchos::av_reinterpret_cast;
80 epetra_lcl_inds = av_reinterpret_cast<
int> (indices);
84 int rowmatrix_return_val = 0;
86 rowmatrix_return_val =
87 this->mat_->ExtractMyRowCopy(local_row,
88 as<int>(std::min(epetra_lcl_inds.size(), vals.size())),
91 epetra_lcl_inds.getRawPtr());
93 catch (
int integer_exception) {
95 rowmatrix_return_val = integer_exception;
97 TEUCHOS_TEST_FOR_EXCEPTION
98 (threw && rowmatrix_return_val != 0, std::runtime_error,
99 "Epetra_RowMatrix::ExtractMyRowCopy, called on local row " << local_row
100 <<
", threw an integer exception " << rowmatrix_return_val <<
".");
101 TEUCHOS_TEST_FOR_EXCEPTION
102 (! threw && rowmatrix_return_val != 0, std::runtime_error,
103 "Epetra_RowMatrix object returned error code "
104 << rowmatrix_return_val <<
" from ExtractMyRowCopy." );
105 nnz = as<size_t>(nnz_ret);
109 for(
size_t i = 0; i < nnz; ++i ){
110 indices[i] = this->col_map_->getGlobalElement(epetra_lcl_inds[i]);
114 template <
class DerivedMat>
116 AbstractConcreteMatrixAdapter<
118 DerivedMat>::getGlobalColCopy_impl(global_ordinal_t col,
119 const ArrayView<global_ordinal_t>& indices,
120 const ArrayView<scalar_t>& vals,
123 TEUCHOS_TEST_FOR_EXCEPTION(
true,
125 "Column access to row-based object not yet supported. "
126 "Please contact the Amesos2 developers." );
130 template <
class DerivedMat>
131 template<
typename KV_GO,
typename KV_S>
133 AbstractConcreteMatrixAdapter<
135 DerivedMat>::getGlobalRowCopy_kokkos_view_impl(global_ordinal_t row,
140 using index_t =
typename KV_GO::value_type;
141 using value_t =
typename KV_S::value_type;
142 ArrayView<value_t> vals_array (vals.data(), vals.extent(0));
143 ArrayView<index_t> indices_array (indices.data(), indices.extent(0));
145 this->getGlobalRowCopy_impl(row, indices_array, vals_array, nnz);
150 template <
class DerivedMat>
151 typename AbstractConcreteMatrixAdapter<
153 DerivedMat>::global_size_t
154 AbstractConcreteMatrixAdapter<
156 DerivedMat>::getGlobalNNZ_impl()
const
158 return Teuchos::as<global_size_t>(this->mat_->NumGlobalNonzeros());
161 template <
class DerivedMat>
163 AbstractConcreteMatrixAdapter<
165 DerivedMat>::getLocalNNZ_impl()
const
167 return Teuchos::as<size_t>(this->mat_->NumMyNonzeros());
170 template <
class DerivedMat>
171 typename AbstractConcreteMatrixAdapter<
173 DerivedMat>::global_size_t
174 AbstractConcreteMatrixAdapter<
176 DerivedMat>::getGlobalNumRows_impl()
const
178 return Teuchos::as<global_size_t>(this->mat_->NumGlobalRows());
181 template <
class DerivedMat>
182 typename AbstractConcreteMatrixAdapter<
184 DerivedMat>::global_size_t
185 AbstractConcreteMatrixAdapter<
187 DerivedMat>::getGlobalNumCols_impl()
const
189 return Teuchos::as<global_size_t>(this->mat_->NumGlobalCols());
192 template <
class DerivedMat>
194 AbstractConcreteMatrixAdapter<
196 DerivedMat>::getMaxRowNNZ_impl()
const
198 return Teuchos::as<size_t>(this->mat_->MaxNumEntries());
201 template <
class DerivedMat>
203 AbstractConcreteMatrixAdapter<
205 DerivedMat>::getMaxColNNZ_impl()
const
207 TEUCHOS_TEST_FOR_EXCEPTION(
true,
209 "Column access to row-based object not yet supported. "
210 "Please contact the Amesos2 developers." );
213 template <
class DerivedMat>
215 AbstractConcreteMatrixAdapter<
217 DerivedMat>::getGlobalRowNNZ_impl(global_ordinal_t row)
const
220 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
221 int gid = Teuchos::as<int>(row);
222 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyGID(gid),
223 std::invalid_argument,
224 "The specified global row id does not belong to me" );
225 int lid = rowmap.LID(gid);
227 this->mat_->NumMyRowEntries(lid, nnz);
231 template <
class DerivedMat>
233 AbstractConcreteMatrixAdapter<
235 DerivedMat>::getLocalRowNNZ_impl(local_ordinal_t row)
const
237 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
238 int lid = Teuchos::as<int>(row);
239 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyLID(lid),
240 std::invalid_argument,
241 "The specified local row id does not beloing to me" );
243 this->mat_->NumMyRowEntries(row, num_entries);
247 template <
class DerivedMat>
249 AbstractConcreteMatrixAdapter<
251 DerivedMat>::getGlobalColNNZ_impl(global_ordinal_t col)
const
253 TEUCHOS_TEST_FOR_EXCEPTION(
true,
255 "Column access to row-based object not yet supported. "
256 "Please contact the Amesos2 developers." );
259 template <
class DerivedMat>
261 AbstractConcreteMatrixAdapter<
263 DerivedMat>::getLocalColNNZ_impl(local_ordinal_t col)
const
265 TEUCHOS_TEST_FOR_EXCEPTION(
true,
267 "Column access to row-based object not yet supported. "
268 "Please contact the Amesos2 developers." );
271 template <
class DerivedMat>
272 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
273 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
274 MatrixTraits<Epetra_RowMatrix>::node_t> >
275 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getMap_impl()
const
282 return( Teuchos::null );
285 template <
class DerivedMat>
286 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
287 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
288 MatrixTraits<Epetra_RowMatrix>::node_t> >
289 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getRowMap_impl()
const
292 const Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
293 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(rowmap) );
296 template <
class DerivedMat>
297 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
298 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
299 MatrixTraits<Epetra_RowMatrix>::node_t> >
300 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getColMap_impl()
const
303 const Epetra_Map colmap = this->mat_->RowMatrixColMap();
304 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(colmap) );
307 template <
class DerivedMat>
308 const RCP<const Teuchos::Comm<int> >
309 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getComm_impl()
const
314 template <
class DerivedMat>
316 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isLocallyIndexed_impl()
const
318 return this->mat_->IndicesAreLocal();
321 template <
class DerivedMat>
323 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isGloballyIndexed_impl()
const
325 return this->mat_->IndicesAreGlobal();
329 template <
class DerivedMat>
330 RCP<const MatrixAdapter<DerivedMat> >
331 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::get_impl(
const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map,
EDistribution distribution)
const
336 return dynamic_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map, distribution);
338 return static_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map, distribution);
342 template <
class DerivedMat>
343 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
345 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseRowPtr()
const
347 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_ptr_t sp_rowptr =
nullptr;
348 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_idx_t sp_colind =
nullptr;
349 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_val_t sp_values =
nullptr;
351 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
356 template <
class DerivedMat>
357 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
359 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseColInd()
const
361 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_ptr_t sp_rowptr =
nullptr;
362 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_idx_t sp_colind =
nullptr;
363 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_val_t sp_values =
nullptr;
365 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
370 template <
class DerivedMat>
371 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
373 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseValues()
const
375 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_ptr_t sp_rowptr =
nullptr;
376 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_idx_t sp_colind =
nullptr;
377 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_val_t sp_values =
nullptr;
379 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
386 #endif // AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
const RCP< const Teuchos::Comm< int > > to_teuchos_comm(RCP< const Epetra_Comm > c)
Transform an Epetra_Comm object into a Teuchos::Comm object.
Provides the Epetra_RowMatrix abstraction for the concrete Epetra row matric adapters.
EDistribution
Definition: Amesos2_TypeDecl.hpp:89