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." );
188 template <
class DerivedMat>
190 AbstractConcreteMatrixAdapter<
192 DerivedMat>::getGlobalRowNNZ_impl(global_ordinal_t row)
const 195 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
196 int gid = Teuchos::as<int>(row);
197 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyGID(gid),
198 std::invalid_argument,
199 "The specified global row id does not belong to me" );
200 int lid = rowmap.LID(gid);
202 this->mat_->NumMyRowEntries(lid, nnz);
206 template <
class DerivedMat>
208 AbstractConcreteMatrixAdapter<
210 DerivedMat>::getLocalRowNNZ_impl(local_ordinal_t row)
const 212 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
213 int lid = Teuchos::as<int>(row);
214 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyLID(lid),
215 std::invalid_argument,
216 "The specified local row id does not beloing to me" );
218 this->mat_->NumMyRowEntries(row, num_entries);
222 template <
class DerivedMat>
224 AbstractConcreteMatrixAdapter<
226 DerivedMat>::getGlobalColNNZ_impl(global_ordinal_t col)
const 228 TEUCHOS_TEST_FOR_EXCEPTION(
true,
230 "Column access to row-based object not yet supported. " 231 "Please contact the Amesos2 developers." );
235 template <
class DerivedMat>
237 AbstractConcreteMatrixAdapter<
239 DerivedMat>::getLocalColNNZ_impl(local_ordinal_t col)
const 241 TEUCHOS_TEST_FOR_EXCEPTION(
true,
243 "Column access to row-based object not yet supported. " 244 "Please contact the Amesos2 developers." );
248 template <
class DerivedMat>
249 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
250 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
251 MatrixTraits<Epetra_RowMatrix>::node_t> >
252 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getRowMap_impl()
const 255 const Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
256 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(rowmap) );
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>::getColMap_impl()
const 266 const Epetra_Map colmap = this->mat_->RowMatrixColMap();
267 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(colmap) );
270 template <
class DerivedMat>
271 const RCP<const Teuchos::Comm<int> >
272 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getComm_impl()
const 274 return Util::to_teuchos_comm(Teuchos::rcpFromRef(this->mat_->Comm()));
277 template <
class DerivedMat>
279 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isLocallyIndexed_impl()
const 281 return this->mat_->IndicesAreLocal();
284 template <
class DerivedMat>
286 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isGloballyIndexed_impl()
const 288 return this->mat_->IndicesAreGlobal();
291 template <
class DerivedMat>
292 RCP<const MatrixAdapter<DerivedMat> >
293 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::get_impl(
const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map)
const 298 return dynamic_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map);
300 return static_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map);
306 #endif // AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
Provides the Epetra_RowMatrix abstraction for the concrete Epetra row matric adapters.