53 #ifndef AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
54 #define AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
56 #include <Epetra_RowMatrix.h>
57 #include <Epetra_Map.h>
58 #include <Epetra_Comm.h>
66 using Teuchos::ArrayView;
68 template <
class DerivedMat>
69 AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::AbstractConcreteMatrixAdapter(RCP<DerivedMat> m)
70 : MatrixAdapter<DerivedMat>(m)
76 template <
class DerivedMat>
78 AbstractConcreteMatrixAdapter<
80 DerivedMat>::getGlobalRowCopy_impl(global_ordinal_t row,
81 const ArrayView<global_ordinal_t>& indices,
82 const ArrayView<scalar_t>& vals,
86 const int local_row = this->row_map_->getLocalElement(row);
89 Teuchos::Array<local_ordinal_t> epetra_lcl_inds_buf;
90 Teuchos::ArrayView<local_ordinal_t> epetra_lcl_inds;
91 if (! std::is_same<global_ordinal_t, local_ordinal_t>::value) {
95 err = this->mat_->NumMyRowEntries (local_row, num_ent);
97 catch (
int integer_exception) {
99 err = integer_exception;
101 TEUCHOS_TEST_FOR_EXCEPTION
102 (threw && err != 0, std::runtime_error,
"Epetra_RowMatrix::"
103 "NumMyRowEntries, called on local row " << local_row <<
", threw "
104 "an integer exception " << err <<
".");
105 TEUCHOS_TEST_FOR_EXCEPTION
106 (! threw && err != 0, std::runtime_error,
"Epetra_RowMatrix returned "
107 "error code " << err <<
" from NumMyRowEntries for local row "
108 << local_row <<
".");
109 epetra_lcl_inds_buf.resize (num_ent);
110 epetra_lcl_inds = epetra_lcl_inds_buf ();
113 using Teuchos::av_reinterpret_cast;
114 epetra_lcl_inds = av_reinterpret_cast<
int> (indices);
118 int rowmatrix_return_val = 0;
120 rowmatrix_return_val =
121 this->mat_->ExtractMyRowCopy(local_row,
122 as<int>(std::min(epetra_lcl_inds.size(), vals.size())),
125 epetra_lcl_inds.getRawPtr());
127 catch (
int integer_exception) {
129 rowmatrix_return_val = integer_exception;
131 TEUCHOS_TEST_FOR_EXCEPTION
132 (threw && rowmatrix_return_val != 0, std::runtime_error,
133 "Epetra_RowMatrix::ExtractMyRowCopy, called on local row " << local_row
134 <<
", threw an integer exception " << rowmatrix_return_val <<
".");
135 TEUCHOS_TEST_FOR_EXCEPTION
136 (! threw && rowmatrix_return_val != 0, std::runtime_error,
137 "Epetra_RowMatrix object returned error code "
138 << rowmatrix_return_val <<
" from ExtractMyRowCopy." );
139 nnz = as<size_t>(nnz_ret);
143 for(
size_t i = 0; i < nnz; ++i ){
144 indices[i] = this->col_map_->getGlobalElement(epetra_lcl_inds[i]);
148 template <
class DerivedMat>
150 AbstractConcreteMatrixAdapter<
152 DerivedMat>::getGlobalColCopy_impl(global_ordinal_t col,
153 const ArrayView<global_ordinal_t>& indices,
154 const ArrayView<scalar_t>& vals,
157 TEUCHOS_TEST_FOR_EXCEPTION(
true,
159 "Column access to row-based object not yet supported. "
160 "Please contact the Amesos2 developers." );
164 template <
class DerivedMat>
165 typename AbstractConcreteMatrixAdapter<
167 DerivedMat>::global_size_t
168 AbstractConcreteMatrixAdapter<
170 DerivedMat>::getGlobalNNZ_impl()
const
172 return Teuchos::as<global_size_t>(this->mat_->NumGlobalNonzeros());
175 template <
class DerivedMat>
177 AbstractConcreteMatrixAdapter<
179 DerivedMat>::getLocalNNZ_impl()
const
181 return Teuchos::as<size_t>(this->mat_->NumMyNonzeros());
184 template <
class DerivedMat>
185 typename AbstractConcreteMatrixAdapter<
187 DerivedMat>::global_size_t
188 AbstractConcreteMatrixAdapter<
190 DerivedMat>::getGlobalNumRows_impl()
const
192 return Teuchos::as<global_size_t>(this->mat_->NumGlobalRows());
195 template <
class DerivedMat>
196 typename AbstractConcreteMatrixAdapter<
198 DerivedMat>::global_size_t
199 AbstractConcreteMatrixAdapter<
201 DerivedMat>::getGlobalNumCols_impl()
const
203 return Teuchos::as<global_size_t>(this->mat_->NumGlobalCols());
206 template <
class DerivedMat>
208 AbstractConcreteMatrixAdapter<
210 DerivedMat>::getMaxRowNNZ_impl()
const
212 return Teuchos::as<size_t>(this->mat_->MaxNumEntries());
215 template <
class DerivedMat>
217 AbstractConcreteMatrixAdapter<
219 DerivedMat>::getMaxColNNZ_impl()
const
221 TEUCHOS_TEST_FOR_EXCEPTION(
true,
223 "Column access to row-based object not yet supported. "
224 "Please contact the Amesos2 developers." );
227 template <
class DerivedMat>
229 AbstractConcreteMatrixAdapter<
231 DerivedMat>::getGlobalRowNNZ_impl(global_ordinal_t row)
const
234 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
235 int gid = Teuchos::as<int>(row);
236 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyGID(gid),
237 std::invalid_argument,
238 "The specified global row id does not belong to me" );
239 int lid = rowmap.LID(gid);
241 this->mat_->NumMyRowEntries(lid, nnz);
245 template <
class DerivedMat>
247 AbstractConcreteMatrixAdapter<
249 DerivedMat>::getLocalRowNNZ_impl(local_ordinal_t row)
const
251 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
252 int lid = Teuchos::as<int>(row);
253 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyLID(lid),
254 std::invalid_argument,
255 "The specified local row id does not beloing to me" );
257 this->mat_->NumMyRowEntries(row, num_entries);
261 template <
class DerivedMat>
263 AbstractConcreteMatrixAdapter<
265 DerivedMat>::getGlobalColNNZ_impl(global_ordinal_t col)
const
267 TEUCHOS_TEST_FOR_EXCEPTION(
true,
269 "Column access to row-based object not yet supported. "
270 "Please contact the Amesos2 developers." );
273 template <
class DerivedMat>
275 AbstractConcreteMatrixAdapter<
277 DerivedMat>::getLocalColNNZ_impl(local_ordinal_t col)
const
279 TEUCHOS_TEST_FOR_EXCEPTION(
true,
281 "Column access to row-based object not yet supported. "
282 "Please contact the Amesos2 developers." );
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>::getMap_impl()
const
296 return( Teuchos::null );
299 template <
class DerivedMat>
300 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
301 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
302 MatrixTraits<Epetra_RowMatrix>::node_t> >
303 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getRowMap_impl()
const
306 const Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
307 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(rowmap) );
310 template <
class DerivedMat>
311 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
312 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
313 MatrixTraits<Epetra_RowMatrix>::node_t> >
314 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getColMap_impl()
const
317 const Epetra_Map colmap = this->mat_->RowMatrixColMap();
318 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(colmap) );
321 template <
class DerivedMat>
322 const RCP<const Teuchos::Comm<int> >
323 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getComm_impl()
const
328 template <
class DerivedMat>
330 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isLocallyIndexed_impl()
const
332 return this->mat_->IndicesAreLocal();
335 template <
class DerivedMat>
337 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isGloballyIndexed_impl()
const
339 return this->mat_->IndicesAreGlobal();
343 template <
class DerivedMat>
344 RCP<const MatrixAdapter<DerivedMat> >
345 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::get_impl(
const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map,
EDistribution distribution)
const
350 return dynamic_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map, distribution);
352 return static_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map, distribution);
356 template <
class DerivedMat>
357 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
358 ::super_t::spmtx_ptr_t
359 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseRowPtr()
const
361 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_ptr_t sp_rowptr =
nullptr;
362 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_idx_t sp_colind =
nullptr;
363 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_vals_t sp_values =
nullptr;
365 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
370 template <
class DerivedMat>
371 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
372 ::super_t::spmtx_idx_t
373 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseColInd()
const
375 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_ptr_t sp_rowptr =
nullptr;
376 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_idx_t sp_colind =
nullptr;
377 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_vals_t sp_values =
nullptr;
379 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
384 template <
class DerivedMat>
385 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
386 ::super_t::spmtx_vals_t
387 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseValues()
const
389 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_ptr_t sp_rowptr =
nullptr;
390 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_idx_t sp_colind =
nullptr;
391 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_vals_t sp_values =
nullptr;
393 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
400 #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:123