49 #ifndef XPETRA_MATRIXFACTORY_HPP
50 #define XPETRA_MATRIXFACTORY_HPP
55 #include "Xpetra_CrsMatrixWrap.hpp"
57 #include "Xpetra_Map.hpp"
63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node = KokkosClassic::DefaultNode::DefaultNodeType>
65 #undef XPETRA_MATRIXFACTORY2_SHORT
71 if (oldOp == Teuchos::null)
79 "Not Epetra or Tpetra matrix");
81 #ifdef HAVE_XPETRA_EPETRA
88 #ifdef HAVE_XPETRA_TPETRA
93 if (oldTCrsOp != Teuchos::null) {
96 if (setFixedBlockSize)
97 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
106 return Teuchos::null;
109 #define XPETRA_MATRIXFACTORY2_SHORT
119 #undef XPETRA_MATRIXFACTORY2_SHORT
124 if (oldOp == Teuchos::null)
129 #ifdef HAVE_XPETRA_EPETRA
130 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
132 if (oldECrsOp != Teuchos::null) {
136 if (setFixedBlockSize)
137 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
143 #ifdef HAVE_XPETRA_TPETRA
146 if (oldTCrsOp != Teuchos::null) {
149 if (setFixedBlockSize)
150 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
153 return Teuchos::null;
155 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::EpetraCrsMatrix or Xpetra::TpetraCrsMatrix failed");
162 #define XPETRA_MATRIXFACTORY2_SHORT
164 #ifdef HAVE_XPETRA_INT_LONG_LONG
168 class MatrixFactory2<double, int, long long, Node> {
169 typedef double Scalar;
170 typedef int LocalOrdinal;
171 typedef long long GlobalOrdinal;
173 #undef XPETRA_MATRIXFACTORY2_SHORT
177 RCP<const CrsMatrixWrap> oldOp = Teuchos::rcp_dynamic_cast<const CrsMatrixWrap>(A);
178 if (oldOp == Teuchos::null)
179 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
181 RCP<const CrsMatrix> oldCrsOp = oldOp->getCrsMatrix();
183 #ifdef HAVE_XPETRA_EPETRA
184 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
185 RCP<const EpetraCrsMatrixT<GlobalOrdinal,Node> > oldECrsOp = Teuchos::rcp_dynamic_cast<const EpetraCrsMatrixT<GlobalOrdinal,Node> >(oldCrsOp);
186 if (oldECrsOp != Teuchos::null) {
188 RCP<CrsMatrix> newECrsOp(
new EpetraCrsMatrixT<GlobalOrdinal,Node>(*oldECrsOp));
189 RCP<CrsMatrixWrap> newOp (
new CrsMatrixWrap (newECrsOp));
190 if (setFixedBlockSize)
191 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
197 #ifdef HAVE_XPETRA_TPETRA
199 RCP<const TpetraCrsMatrix> oldTCrsOp = Teuchos::rcp_dynamic_cast<const TpetraCrsMatrix>(oldCrsOp);
200 if (oldTCrsOp != Teuchos::null) {
201 RCP<CrsMatrix> newTCrsOp(
new TpetraCrsMatrix(*oldTCrsOp));
202 RCP<CrsMatrixWrap> newOp (
new CrsMatrixWrap(newTCrsOp));
203 if (setFixedBlockSize)
204 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
208 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::EpetraCrsMatrix or Xpetra::TpetraCrsMatrix failed");
211 return Teuchos::null;
216 #define XPETRA_MATRIXFACTORY2_SHORT
219 template <
class Scalar,
224 #undef XPETRA_MATRIXFACTORY_SHORT
253 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
264 static RCP<Matrix>
Build (
272 return rcp(
new CrsMatrixWrap(lclMatrix, rowMap, colMap, domainMap, rangeMap, params));
289 LocalOrdinal NumMyElements = diagonal->getMap()->getNodeNumElements();
294 for (LocalOrdinal i = 0; i < NumMyElements; ++i) {
295 mtx->insertGlobalValues(MyGlobalElements[i],
296 Teuchos::tuple<GlobalOrdinal>(MyGlobalElements[i]),
297 Teuchos::tuple<Scalar>(vals[i]) );
306 if (crsOp == Teuchos::null)
311 if (newCrs->hasMatrix())
314 return Teuchos::null;
320 if (crsOp == Teuchos::null)
330 if (crsOp == Teuchos::null)
335 if (newCrs->hasMatrix())
338 return Teuchos::null;
344 if (crsOp == Teuchos::null)
349 if (newCrs->hasMatrix())
352 return Teuchos::null;
360 if(input == Teuchos::null)
370 for (
size_t r = 0; r < input->Rows(); ++r) {
371 for (
size_t c = 0; c < input->Cols(); ++c)
372 if(input->getMatrix(r,c) != Teuchos::null) {
377 bop->setMatrix(r,c,mat);
381 if(input->isFillComplete())
386 #define XPETRA_MATRIXFACTORY_SHORT
390 #define XPETRA_MATRIXFACTORY_SHORT
391 #define XPETRA_MATRIXFACTORY2_SHORT
#define XPETRA_MONITOR(funcName)
static RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap)
Constructor for empty matrix (intended use is an import/export target - can't insert entries directly...
Concrete implementation of Xpetra::Matrix.
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A, bool setFixedBlockSize=true)
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A, bool setFixedBlockSize=true)
static RCP< Matrix > Build(const RCP< const Matrix > &sourceMatrix, const Export &exporter, const RCP< const Map > &domainMap, const RCP< const Map > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
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)
static RCP< Matrix > Build(const RCP< const Map > &rowMap, const RCP< const Map > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc)
Constructor specifying the (possibly different) number of entries per row and providing column map.
static RCP< Matrix > Build(const RCP< const CrsGraph > &graph, const RCP< ParameterList > ¶mList=Teuchos::null)
Constructor specifying graph.
static RCP< Matrix > Build(const RCP< const Matrix > &sourceMatrix, const Export &RowExporter, const Export &DomainExporter, 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)
Constructor specifying the number of non-zeros for all rows.
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A, bool setFixedBlockSize=true)
static RCP< Matrix > Build(const RCP< const Matrix > &sourceMatrix, const Import &RowImporter, const Import &DomainImporter, const RCP< const Map > &domainMap, const RCP< const Map > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Constructor to create a Matrix using a fusedImport-style construction. The originalMatrix must be a X...
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...
MatrixFactory()
Private constructor. This is a static class.
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, size_t maxNumEntriesPerRow)
Constructor specifying the max number of non-zeros per row and providing column map.
static RCP< Matrix > Build(const RCP< const Map > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc)
Constructor specifying (possibly different) number of entries in each row.
Xpetra-specific matrix class.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TypeTo as(const TypeFrom &t)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)