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 = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
66 class MatrixFactory2 {
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
116 class MatrixFactory2<double,int,int,Node> {
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
180 if (oldOp == Teuchos::null)
185#ifdef HAVE_XPETRA_EPETRA
186#ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
188 if (oldECrsOp != Teuchos::null) {
192 if (setFixedBlockSize)
193 newOp->SetFixedBlockSize(A->GetFixedBlockSize());
199#ifdef HAVE_XPETRA_TPETRA
202 if (oldTCrsOp != Teuchos::null) {
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
273 return rcp(
new CrsMatrixWrap(lclMatrix, rowMap, colMap, domainMap, rangeMap, params));
299 if(bdiagonal == Teuchos::null)
302 LocalOrdinal numMyElements = diagonal->getMap()->getLocalNumElements();
307 for (LocalOrdinal i = 0; i < numMyElements; ++i) {
308 mtx->insertGlobalValues(myGlobalElements[i],
309 Teuchos::tuple<GlobalOrdinal>(myGlobalElements[i]),
310 Teuchos::tuple<Scalar>(vals[i]));
318 for (
size_t r = 0; r < bdiagonal->getBlockedMap()->getNumMaps(); ++r) {
319 if (!bdiagonal->getMultiVector(r).
is_null()) {
321 bop->setMatrix(r, r,
Build(subvec->getVector(0)));
334 if (crsOp == Teuchos::null)
339 if (newCrs->hasMatrix())
342 return Teuchos::null;
348 if (crsOp == Teuchos::null)
358 if (crsOp == Teuchos::null)
363 if (newCrs->hasMatrix())
366 return Teuchos::null;
372 if (crsOp == Teuchos::null)
377 if (newCrs->hasMatrix())
380 return Teuchos::null;
388 if(input == Teuchos::null)
389 return Xpetra::MatrixFactory2<Scalar,LocalOrdinal,GlobalOrdinal,Node>::BuildCopy(A,setFixedBlockSize);
398 for (
size_t r = 0; r < input->Rows(); ++r) {
399 for (
size_t c = 0; c < input->Cols(); ++c)
400 if(input->getMatrix(r,c) != Teuchos::null) {
405 bop->setMatrix(r,c,mat);
409 if(input->isFillComplete())
414#define XPETRA_MATRIXFACTORY_SHORT
418#define XPETRA_MATRIXFACTORY_SHORT
419#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 CrsGraph > &graph, typename Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_type::values_type &values, const RCP< ParameterList > ¶mList=Teuchos::null)
Constructor specifying graph and values array.
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)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)