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,
87 local_ordinal_t local_row = this->row_map_->getLocalElement(row);
89 int rowmatrix_return_val
90 = this->mat_->ExtractMyRowCopy(as<int>(local_row),
91 as<int>(std::min(indices.size(), vals.size())),
95 TEUCHOS_TEST_FOR_EXCEPTION( rowmatrix_return_val != 0,
97 "Epetra_RowMatrix object returned error code " 98 << rowmatrix_return_val <<
" from ExtractMyRowCopy." );
99 nnz = as<size_t>(nnz_ret);
103 for(
size_t i = 0; i < nnz; ++i ){
104 indices[i] = this->col_map_->getGlobalElement(indices[i]);
108 template <
class DerivedMat>
110 AbstractConcreteMatrixAdapter<
112 DerivedMat>::getGlobalColCopy_impl(global_ordinal_t col,
113 const ArrayView<global_ordinal_t>& indices,
114 const ArrayView<scalar_t>& vals,
117 TEUCHOS_TEST_FOR_EXCEPTION(
true,
119 "Column access to row-based object not yet supported. " 120 "Please contact the Amesos2 developers." );
124 template <
class DerivedMat>
125 typename AbstractConcreteMatrixAdapter<
127 DerivedMat>::global_size_t
128 AbstractConcreteMatrixAdapter<
130 DerivedMat>::getGlobalNNZ_impl()
const 132 return Teuchos::as<global_size_t>(this->mat_->NumGlobalNonzeros());
135 template <
class DerivedMat>
137 AbstractConcreteMatrixAdapter<
139 DerivedMat>::getLocalNNZ_impl()
const 141 return Teuchos::as<size_t>(this->mat_->NumMyNonzeros());
144 template <
class DerivedMat>
145 typename AbstractConcreteMatrixAdapter<
147 DerivedMat>::global_size_t
148 AbstractConcreteMatrixAdapter<
150 DerivedMat>::getGlobalNumRows_impl()
const 152 return Teuchos::as<global_size_t>(this->mat_->NumGlobalRows());
155 template <
class DerivedMat>
156 typename AbstractConcreteMatrixAdapter<
158 DerivedMat>::global_size_t
159 AbstractConcreteMatrixAdapter<
161 DerivedMat>::getGlobalNumCols_impl()
const 163 return Teuchos::as<global_size_t>(this->mat_->NumGlobalCols());
166 template <
class DerivedMat>
168 AbstractConcreteMatrixAdapter<
170 DerivedMat>::getMaxRowNNZ_impl()
const 172 return Teuchos::as<size_t>(this->mat_->MaxNumEntries());
175 template <
class DerivedMat>
177 AbstractConcreteMatrixAdapter<
179 DerivedMat>::getMaxColNNZ_impl()
const 181 TEUCHOS_TEST_FOR_EXCEPTION(
true,
183 "Column access to row-based object not yet supported. " 184 "Please contact the Amesos2 developers." );
187 template <
class DerivedMat>
189 AbstractConcreteMatrixAdapter<
191 DerivedMat>::getGlobalRowNNZ_impl(global_ordinal_t row)
const 194 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
195 int gid = Teuchos::as<int>(row);
196 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyGID(gid),
197 std::invalid_argument,
198 "The specified global row id does not belong to me" );
199 int lid = rowmap.LID(gid);
201 this->mat_->NumMyRowEntries(lid, nnz);
205 template <
class DerivedMat>
207 AbstractConcreteMatrixAdapter<
209 DerivedMat>::getLocalRowNNZ_impl(local_ordinal_t row)
const 211 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
212 int lid = Teuchos::as<int>(row);
213 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyLID(lid),
214 std::invalid_argument,
215 "The specified local row id does not beloing to me" );
217 this->mat_->NumMyRowEntries(row, num_entries);
221 template <
class DerivedMat>
223 AbstractConcreteMatrixAdapter<
225 DerivedMat>::getGlobalColNNZ_impl(global_ordinal_t col)
const 227 TEUCHOS_TEST_FOR_EXCEPTION(
true,
229 "Column access to row-based object not yet supported. " 230 "Please contact the Amesos2 developers." );
233 template <
class DerivedMat>
235 AbstractConcreteMatrixAdapter<
237 DerivedMat>::getLocalColNNZ_impl(local_ordinal_t col)
const 239 TEUCHOS_TEST_FOR_EXCEPTION(
true,
241 "Column access to row-based object not yet supported. " 242 "Please contact the Amesos2 developers." );
245 template <
class DerivedMat>
246 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
247 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
248 MatrixTraits<Epetra_RowMatrix>::node_t> >
249 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getMap_impl()
const 256 return( Teuchos::null );
259 template <
class DerivedMat>
260 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
261 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
262 MatrixTraits<Epetra_RowMatrix>::node_t> >
263 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getRowMap_impl()
const 266 const Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
267 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(rowmap) );
270 template <
class DerivedMat>
271 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
272 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
273 MatrixTraits<Epetra_RowMatrix>::node_t> >
274 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getColMap_impl()
const 277 const Epetra_Map colmap = this->mat_->RowMatrixColMap();
278 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(colmap) );
281 template <
class DerivedMat>
282 const RCP<const Teuchos::Comm<int> >
283 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getComm_impl()
const 285 return Util::to_teuchos_comm(Teuchos::rcpFromRef(this->mat_->Comm()));
288 template <
class DerivedMat>
290 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isLocallyIndexed_impl()
const 292 return this->mat_->IndicesAreLocal();
295 template <
class DerivedMat>
297 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isGloballyIndexed_impl()
const 299 return this->mat_->IndicesAreGlobal();
303 template <
class DerivedMat>
304 RCP<const MatrixAdapter<DerivedMat> >
305 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::get_impl(
const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map,
EDistribution distribution)
const 310 return dynamic_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map, distribution);
312 return static_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map, distribution);
316 template <
class DerivedMat>
317 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
318 ::super_t::spmtx_ptr_t
319 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseRowPtr()
const 321 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_ptr_t sp_rowptr =
nullptr;
322 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_idx_t sp_colind =
nullptr;
323 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_vals_t sp_values =
nullptr;
325 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
330 template <
class DerivedMat>
331 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
332 ::super_t::spmtx_idx_t
333 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseColInd()
const 335 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_ptr_t sp_rowptr =
nullptr;
336 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_idx_t sp_colind =
nullptr;
337 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_vals_t sp_values =
nullptr;
339 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
344 template <
class DerivedMat>
345 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
346 ::super_t::spmtx_vals_t
347 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseValues()
const 349 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_ptr_t sp_rowptr =
nullptr;
350 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_idx_t sp_colind =
nullptr;
351 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::super_t::spmtx_vals_t sp_values =
nullptr;
353 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
360 #endif // AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
Provides the Epetra_RowMatrix abstraction for the concrete Epetra row matric adapters.
EDistribution
Definition: Amesos2_TypeDecl.hpp:123