49#ifndef XPETRA_MATRIXFACTORY_HPP
50#define XPETRA_MATRIXFACTORY_HPP
55#include "Xpetra_CrsMatrixWrap.hpp"
57#include "Xpetra_Map.hpp"
58#include "Xpetra_BlockedMap.hpp"
60#include "Xpetra_BlockedVector.hpp"
65 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node = KokkosClassic::DefaultNode::DefaultNodeType>
67#undef XPETRA_MATRIXFACTORY2_SHORT
73 if (oldOp == Teuchos::null)
81 "Not Epetra or Tpetra matrix");
83#ifdef HAVE_XPETRA_EPETRA
90#ifdef HAVE_XPETRA_TPETRA
95 if (oldTCrsOp != Teuchos::null) {
98 if (setFixedBlockSize)
99 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
108 return Teuchos::null;
111#define XPETRA_MATRIXFACTORY2_SHORT
121#undef XPETRA_MATRIXFACTORY2_SHORT
126 if (oldOp == Teuchos::null)
131#ifdef HAVE_XPETRA_EPETRA
132#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
134 if (oldECrsOp != Teuchos::null) {
138 if (setFixedBlockSize)
139 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
145#ifdef HAVE_XPETRA_TPETRA
148 if (oldTCrsOp != Teuchos::null) {
151 if (setFixedBlockSize)
152 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
155 return Teuchos::null;
157 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::EpetraCrsMatrix or Xpetra::TpetraCrsMatrix failed");
164#define XPETRA_MATRIXFACTORY2_SHORT
166#ifdef HAVE_XPETRA_INT_LONG_LONG
170 class MatrixFactory2<double, int, long long, Node> {
171 typedef double Scalar;
172 typedef int LocalOrdinal;
173 typedef long long GlobalOrdinal;
175#undef XPETRA_MATRIXFACTORY2_SHORT
179 RCP<const CrsMatrixWrap> oldOp = Teuchos::rcp_dynamic_cast<const CrsMatrixWrap>(A);
180 if (oldOp == Teuchos::null)
181 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
183 RCP<const CrsMatrix> oldCrsOp = oldOp->getCrsMatrix();
185#ifdef HAVE_XPETRA_EPETRA
186#ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
187 RCP<const EpetraCrsMatrixT<GlobalOrdinal,Node> > oldECrsOp = Teuchos::rcp_dynamic_cast<const EpetraCrsMatrixT<GlobalOrdinal,Node> >(oldCrsOp);
188 if (oldECrsOp != Teuchos::null) {
190 RCP<CrsMatrix> newECrsOp(
new EpetraCrsMatrixT<GlobalOrdinal,Node>(*oldECrsOp));
191 RCP<CrsMatrixWrap> newOp (
new CrsMatrixWrap (newECrsOp));
192 if (setFixedBlockSize)
193 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
199#ifdef HAVE_XPETRA_TPETRA
201 RCP<const TpetraCrsMatrix> oldTCrsOp = Teuchos::rcp_dynamic_cast<const TpetraCrsMatrix>(oldCrsOp);
202 if (oldTCrsOp != Teuchos::null) {
203 RCP<CrsMatrix> newTCrsOp(
new TpetraCrsMatrix(*oldTCrsOp));
204 RCP<CrsMatrixWrap> newOp (
new CrsMatrixWrap(newTCrsOp));
205 if (setFixedBlockSize)
206 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
210 throw Exceptions::BadCast(
"Cast from Xpetra::Matrix to Xpetra::EpetraCrsMatrix or Xpetra::TpetraCrsMatrix failed");
213 return Teuchos::null;
218#define XPETRA_MATRIXFACTORY2_SHORT
221 template <
class Scalar,
226#undef XPETRA_MATRIXFACTORY_SHORT
247 return rcp(
new CrsMatrixWrap(rowMap, colMap, maxNumEntriesPerRow));
252 return rcp(
new CrsMatrixWrap(rowMap, colMap, NumEntriesPerRowToAlloc));
262 return rcp(
new CrsMatrixWrap(rowMap, colMap, lclMatrix, params));
273 return rcp(
new CrsMatrixWrap(lclMatrix, rowMap, colMap, domainMap, rangeMap, params));
278 return rcp(
new CrsMatrixWrap(rowMap, NumEntriesPerRowToAlloc) );
292 if(bdiagonal == Teuchos::null)
295 LocalOrdinal numMyElements = diagonal->getMap()->getLocalNumElements();
300 for (LocalOrdinal i = 0; i < numMyElements; ++i) {
301 mtx->insertGlobalValues(myGlobalElements[i],
302 Teuchos::tuple<GlobalOrdinal>(myGlobalElements[i]),
303 Teuchos::tuple<Scalar>(vals[i]));
311 for (
size_t r = 0; r < bdiagonal->getBlockedMap()->getNumMaps(); ++r) {
312 if (!bdiagonal->getMultiVector(r).
is_null()) {
314 bop->setMatrix(r, r,
Build(subvec->getVector(0)));
327 if (crsOp == Teuchos::null)
332 if (newCrs->hasMatrix())
335 return Teuchos::null;
341 if (crsOp == Teuchos::null)
351 if (crsOp == Teuchos::null)
356 if (newCrs->hasMatrix())
359 return Teuchos::null;
365 if (crsOp == Teuchos::null)
370 if (newCrs->hasMatrix())
373 return Teuchos::null;
381 if(input == Teuchos::null)
391 for (
size_t r = 0; r < input->Rows(); ++r) {
392 for (
size_t c = 0; c < input->Cols(); ++c)
393 if(input->getMatrix(r,c) != Teuchos::null) {
398 bop->setMatrix(r,c,mat);
402 if(input->isFillComplete())
407#define XPETRA_MATRIXFACTORY_SHORT
411#define XPETRA_MATRIXFACTORY_SHORT
412#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.
KokkosSparse::CrsMatrix< impl_scalar_type, LocalOrdinal, execution_space, void, typename local_graph_type::size_type > local_matrix_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
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 &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 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 typename Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_type &lclMatrix, const Teuchos::RCP< const Map > &rowMap, const Teuchos::RCP< const Map > &colMap, const Teuchos::RCP< const Map > &domainMap=Teuchos::null, const Teuchos::RCP< const Map > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=null)
Constructor providing a local Kokkos::CrsMatrix together with all maps.
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 Map > &rowMap)
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 Map > &rowMap, size_t maxNumEntriesPerRow)
Constructor specifying the number of non-zeros for all rows.
static RCP< Matrix > Build(const Teuchos::RCP< const Map > &rowMap, const Teuchos::RCP< const Map > &colMap, const typename Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_type &lclMatrix, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=null)
Constructor providing a local Kokkos::CrsMatrix together with a row and column map.
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.
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...
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 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, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc)
Constructor specifying (possibly different) number of entries in each row.
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...
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)