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>
64 class MatrixFactory2 {
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 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
105 return Teuchos::null;
108 #define XPETRA_MATRIXFACTORY2_SHORT
118 #undef XPETRA_MATRIXFACTORY2_SHORT
123 if (oldOp == Teuchos::null)
128 #ifdef HAVE_XPETRA_EPETRA
129 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
131 if (oldECrsOp != Teuchos::null) {
135 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
141 #ifdef HAVE_XPETRA_TPETRA
144 if (oldTCrsOp != Teuchos::null) {
147 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
150 return Teuchos::null;
152 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::EpetraCrsMatrix or Xpetra::TpetraCrsMatrix failed");
159 #define XPETRA_MATRIXFACTORY2_SHORT
161 #ifdef HAVE_XPETRA_INT_LONG_LONG
165 class MatrixFactory2<double, int, long long, Node> {
166 typedef double Scalar;
167 typedef int LocalOrdinal;
168 typedef long long GlobalOrdinal;
170 #undef XPETRA_MATRIXFACTORY2_SHORT
174 RCP<const CrsMatrixWrap> oldOp = Teuchos::rcp_dynamic_cast<
const CrsMatrixWrap>(A);
175 if (oldOp == Teuchos::null)
176 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
178 RCP<const CrsMatrix> oldCrsOp = oldOp->getCrsMatrix();
180 #ifdef HAVE_XPETRA_EPETRA
181 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
182 RCP<const EpetraCrsMatrixT<GlobalOrdinal,Node> > oldECrsOp = Teuchos::rcp_dynamic_cast<
const EpetraCrsMatrixT<GlobalOrdinal,Node> >(oldCrsOp);
183 if (oldECrsOp != Teuchos::null) {
185 RCP<CrsMatrix> newECrsOp(
new EpetraCrsMatrixT<GlobalOrdinal,Node>(*oldECrsOp));
186 RCP<CrsMatrixWrap> newOp (
new CrsMatrixWrap (newECrsOp));
187 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
193 #ifdef HAVE_XPETRA_TPETRA
195 RCP<const TpetraCrsMatrix> oldTCrsOp = Teuchos::rcp_dynamic_cast<
const TpetraCrsMatrix>(oldCrsOp);
196 if (oldTCrsOp != Teuchos::null) {
197 RCP<CrsMatrix> newTCrsOp(
new TpetraCrsMatrix(*oldTCrsOp));
198 RCP<CrsMatrixWrap> newOp (
new CrsMatrixWrap(newTCrsOp));
199 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
203 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::EpetraCrsMatrix or Xpetra::TpetraCrsMatrix failed");
206 return Teuchos::null;
209 #endif // HAVE_XPETRA_INT_LONG_LONG
211 #define XPETRA_MATRIXFACTORY2_SHORT
214 template <
class Scalar,
218 class MatrixFactory {
219 #undef XPETRA_MATRIXFACTORY_SHORT
240 return rcp(
new CrsMatrixWrap(rowMap, colMap, NumEntriesPerRowToAlloc, pftype));
243 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
254 static RCP<Matrix>
Build (
262 return rcp(
new CrsMatrixWrap(lclMatrix, rowMap, colMap, domainMap, rangeMap, params));
279 LocalOrdinal NumMyElements = diagonal->getMap()->getNodeNumElements();
284 for (LocalOrdinal i = 0; i < NumMyElements; ++i) {
285 mtx->insertGlobalValues(MyGlobalElements[i],
286 Teuchos::tuple<GlobalOrdinal>(MyGlobalElements[i]),
287 Teuchos::tuple<Scalar>(vals[i]) );
296 if (crsOp == Teuchos::null)
301 if (newCrs->hasMatrix())
304 return Teuchos::null;
310 if (crsOp == Teuchos::null)
320 if (crsOp == Teuchos::null)
325 if (newCrs->hasMatrix())
328 return Teuchos::null;
334 if (crsOp == Teuchos::null)
339 if (newCrs->hasMatrix())
342 return Teuchos::null;
350 if(input == Teuchos::null)
360 for (
size_t r = 0; r < input->Rows(); ++r) {
361 for (
size_t c = 0; c < input->Cols(); ++c)
362 if(input->getMatrix(r,c) != Teuchos::null) {
367 bop->setMatrix(r,c,mat);
371 if(input->isFillComplete())
376 #define XPETRA_MATRIXFACTORY_SHORT
380 #define XPETRA_MATRIXFACTORY_SHORT
381 #define XPETRA_MATRIXFACTORY2_SHORT
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 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 CrsGraph > &graph, const RCP< ParameterList > ¶mList=Teuchos::null)
Constructor specifying graph.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > 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.
Exception throws to report errors in the internal logical of the program.
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...
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.
Exception indicating invalid cast attempted.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A)
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.
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A)
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A)
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...
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
TypeTo as(const TypeFrom &t)
Concrete implementation of Xpetra::Matrix.
#define XPETRA_MONITOR(funcName)
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, Xpetra::ProfileType pftype=Xpetra::DynamicProfile)
Constructor specifying the number of non-zeros for all rows.
Xpetra-specific matrix class.
MatrixFactory()
Private constructor. This is a static class.
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...