49 #ifndef XPETRA_MATRIXFACTORY_HPP 50 #define XPETRA_MATRIXFACTORY_HPP 61 template <class Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = Kokkos::DefaultNode::DefaultNodeType, class LocalMatOps = typename Kokkos::DefaultKernels<Scalar,LocalOrdinal,Node>::SparseOps>
63 #undef XPETRA_MATRIXFACTORY_SHORT 76 return rcp(
new CrsMatrixWrap(rowMap, maxNumEntriesPerRow, pftype) );
89 return rcp(
new CrsMatrixWrap(rowMap, colMap, maxNumEntriesPerRow, pftype));
94 return rcp(
new CrsMatrixWrap(rowMap, colMap, NumEntriesPerRowToAlloc, pftype));
99 return rcp(
new CrsMatrixWrap(rowMap, NumEntriesPerRowToAlloc, pftype) );
103 static RCP<Matrix>
Build(
const RCP<const Vector> & diagonal) {
104 Teuchos::ArrayRCP<const Scalar> vals = diagonal->getData(0);
106 LocalOrdinal NumMyElements = diagonal->getMap()->getNodeNumElements();
107 Teuchos::ArrayView<const GlobalOrdinal> MyGlobalElements = diagonal->getMap()->getNodeElementList();
108 for (LocalOrdinal i = 0; i < NumMyElements; ++i) {
109 mtx->insertGlobalValues(MyGlobalElements[i],
110 Teuchos::tuple<GlobalOrdinal>(MyGlobalElements[i]),
111 Teuchos::tuple<Scalar>(vals[i]) );
119 static RCP<Matrix>
Build(
const RCP<const Matrix> & sourceMatrix,
const Import &importer,
const RCP<const Map> & domainMap = Teuchos::null,
const RCP<const Map> & rangeMap = Teuchos::null,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
121 RCP<const CrsMatrixWrap> crsOp = Teuchos::rcp_dynamic_cast<
const CrsMatrixWrap>(sourceMatrix);
122 if (crsOp == Teuchos::null)
126 if(newCrs->hasMatrix())
129 return Teuchos::null;
133 static RCP<Matrix>
Build(
const RCP<const Matrix> & sourceMatrix,
const Export &exporter,
const RCP<const Map> & domainMap = Teuchos::null,
const RCP<const Map> & rangeMap = Teuchos::null,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
135 RCP<const CrsMatrixWrap> crsOp = Teuchos::rcp_dynamic_cast<
const CrsMatrixWrap>(sourceMatrix);
136 if (crsOp == Teuchos::null)
143 #ifdef HAVE_XPETRA_EXPERIMENTAL 144 static RCP<Matrix> BuildCopy(
const RCP<const Matrix> A) {
145 RCP<const CrsMatrixWrap> oldOp = Teuchos::rcp_dynamic_cast<
const CrsMatrixWrap>(A);
146 if (oldOp == Teuchos::null)
149 RCP<const CrsMatrix> oldCrsOp = oldOp->getCrsMatrix();
151 #ifdef HAVE_XPETRA_EPETRA 152 RCP<const EpetraCrsMatrix> oldECrsOp = Teuchos::rcp_dynamic_cast<
const EpetraCrsMatrix>(oldCrsOp);
153 if (oldECrsOp != Teuchos::null) {
163 #ifdef HAVE_XPETRA_TPETRA 165 RCP<const TpetraCrsMatrix> oldTCrsOp = Teuchos::rcp_dynamic_cast<
const TpetraCrsMatrix>(oldCrsOp);
171 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::EpetraCrsMatrix or Xpetra::TpetraCrsMatrix failed");
172 return Teuchos::null;
175 #endif // ifdef HAVE_XPETRA_EXPERIMENTAL 181 #define XPETRA_MATRIXFACTORY_SHORT
static RCP< Matrix > Build(const RCP< const Map > &rowMap, const RCP< const Map > &colMap, size_t maxNumEntriesPerRow, Xpetra::ProfileType pftype=Xpetra::DynamicProfile)
Constructor specifying the max number of non-zeros per row and providing column map.
Exception indicating invalid cast attempted.
RCP< CrsMatrix > getCrsMatrix() const
static RCP< Matrix > Build(const RCP< const Matrix > &sourceMatrix, const Export &exporter, const RCP< const Map > &domainMap=Teuchos::null, const RCP< const Map > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Constructor to create a Matrix using a fusedExport-style construction. The originalMatrix must be a X...
static RCP< Matrix > Build(const RCP< const Map > &rowMap, size_t maxNumEntriesPerRow, Xpetra::ProfileType pftype=Xpetra::DynamicProfile)
Constructor specifying the number of non-zeros for all rows.
MatrixFactory()
Private constructor. This is a static class.
static RCP< Matrix > Build(const RCP< const Matrix > &sourceMatrix, const Import &importer, const RCP< const Map > &domainMap=Teuchos::null, const RCP< const Map > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Constructor to create a Matrix using a fusedImport-style construction. The originalMatrix must be a X...
static RCP< Matrix > Build(const RCP< const Vector > &diagonal)
Constructor for creating a diagonal Xpetra::Matrix using the entries of a given vector for the diagon...
static RCP< Matrix > Build(const RCP< const Map > &rowMap, const RCP< const Map > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, Xpetra::ProfileType pftype=Xpetra::DynamicProfile)
Constructor specifying the (possibly different) number of entries per row and providing column map...
Concrete implementation of Xpetra::Matrix.
static RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, Xpetra::ProfileType pftype=Xpetra::DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying fixed number of entries for each row.
static RCP< Matrix > Build(const RCP< const Map > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=Xpetra::DynamicProfile)
Constructor specifying (possibly different) number of entries in each row.