12 #ifndef XPETRA_MATRIXFACTORY_DEF_HPP
13 #define XPETRA_MATRIXFACTORY_DEF_HPP
17 #include "Xpetra_BlockedCrsMatrix.hpp"
21 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
26 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
31 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
33 return rcp(
new CrsMatrixWrap(rowMap, colMap, maxNumEntriesPerRow));
36 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
38 return rcp(
new CrsMatrixWrap(rowMap, colMap, NumEntriesPerRowToAlloc));
41 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
43 const Teuchos::RCP<const Map>& rowMap,
44 const Teuchos::RCP<const Map>& colMap,
46 const Teuchos::RCP<Teuchos::ParameterList>& params) {
48 return rcp(
new CrsMatrixWrap(rowMap, colMap, lclMatrix, params));
51 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
54 const Teuchos::RCP<const Map>& rowMap,
55 const Teuchos::RCP<const Map>& colMap,
56 const Teuchos::RCP<const Map>& domainMap,
57 const Teuchos::RCP<const Map>& rangeMap,
58 const Teuchos::RCP<Teuchos::ParameterList>& params) {
60 return rcp(
new CrsMatrixWrap(lclMatrix, rowMap, colMap, domainMap, rangeMap, params));
63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 return rcp(
new CrsMatrixWrap(rowMap, NumEntriesPerRowToAlloc));
68 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 const RCP<ParameterList>& paramList) {
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82 RCP<const BlockedVector> bdiagonal = Teuchos::rcp_dynamic_cast<
const BlockedVector>(diagonal);
83 Teuchos::RCP<Matrix> mtx = Teuchos::null;
85 if (bdiagonal == Teuchos::null) {
86 Teuchos::ArrayRCP<const Scalar> vals = diagonal->
getData(0);
87 LocalOrdinal numMyElements = diagonal->getMap()->getLocalNumElements();
88 Teuchos::ArrayView<const GlobalOrdinal> myGlobalElements = diagonal->getMap()->getLocalElementList();
92 for (LocalOrdinal i = 0; i < numMyElements; ++i) {
93 mtx->insertGlobalValues(myGlobalElements[i],
94 Teuchos::tuple<GlobalOrdinal>(myGlobalElements[i]),
95 Teuchos::tuple<Scalar>(vals[i]));
99 RCP<BlockedCrsMatrix> bop = Teuchos::rcp(
new BlockedCrsMatrix(bdiagonal->getBlockedMap(), bdiagonal->getBlockedMap(), 1));
101 for (
size_t r = 0; r < bdiagonal->getBlockedMap()->getNumMaps(); ++r) {
102 if (!bdiagonal->getMultiVector(r).is_null()) {
103 const RCP<MultiVector> subvec = bdiagonal->getMultiVector(r);
104 bop->setMatrix(r, r, Build(subvec->getVector(0)));
108 mtx = BuildCopy(bop);
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
115 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
MatrixFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(
const RCP<const Matrix>& sourceMatrix,
const Import& importer,
const RCP<const Map>& domainMap,
const RCP<const Map>& rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) {
116 RCP<const CrsMatrixWrap> crsOp = Teuchos::rcp_dynamic_cast<
const CrsMatrixWrap>(sourceMatrix);
117 if (crsOp == Teuchos::null)
120 RCP<CrsMatrix> originalCrs = crsOp->getCrsMatrix();
122 if (newCrs->hasMatrix())
125 return Teuchos::null;
128 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
129 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
MatrixFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(
const RCP<const Matrix>& sourceMatrix,
const Export& exporter,
const RCP<const Map>& domainMap,
const RCP<const Map>& rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) {
130 RCP<const CrsMatrixWrap> crsOp = Teuchos::rcp_dynamic_cast<
const CrsMatrixWrap>(sourceMatrix);
131 if (crsOp == Teuchos::null)
134 RCP<CrsMatrix> originalCrs = crsOp->getCrsMatrix();
138 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
MatrixFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::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>& params) {
140 RCP<const CrsMatrixWrap> crsOp = Teuchos::rcp_dynamic_cast<
const CrsMatrixWrap>(sourceMatrix);
141 if (crsOp == Teuchos::null)
144 RCP<CrsMatrix> originalCrs = crsOp->getCrsMatrix();
145 RCP<CrsMatrix> newCrs =
CrsMatrixFactory::Build(originalCrs, RowImporter, Teuchos::rcpFromRef(DomainImporter), domainMap, rangeMap, params);
146 if (newCrs->hasMatrix())
149 return Teuchos::null;
152 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
153 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
MatrixFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(
const RCP<
const Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& sourceMatrix,
const Xpetra::Export<LocalOrdinal, GlobalOrdinal, Node>& RowExporter,
const Xpetra::Export<LocalOrdinal, GlobalOrdinal, Node>& DomainExporter,
const RCP<
const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& domainMap,
const RCP<
const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) {
154 RCP<const CrsMatrixWrap> crsOp = Teuchos::rcp_dynamic_cast<
const CrsMatrixWrap>(sourceMatrix);
155 if (crsOp == Teuchos::null)
158 RCP<CrsMatrix> originalCrs = crsOp->getCrsMatrix();
159 RCP<CrsMatrix> newCrs =
CrsMatrixFactory::Build(originalCrs, RowExporter, Teuchos::rcpFromRef(DomainExporter), domainMap, rangeMap, params);
160 if (newCrs->hasMatrix())
163 return Teuchos::null;
166 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
167 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
MatrixFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::BuildCopy(
const RCP<
const Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> A,
bool setFixedBlockSize) {
168 RCP<const BlockedCrsMatrix> input = Teuchos::rcp_dynamic_cast<
const BlockedCrsMatrix>(A);
169 if (input == Teuchos::null)
173 RCP<const MapExtractor> rgMapExt = Teuchos::rcp(
new MapExtractor(*(input->getRangeMapExtractor())));
174 RCP<const MapExtractor> doMapExt = Teuchos::rcp(
new MapExtractor(*(input->getDomainMapExtractor())));
177 RCP<BlockedCrsMatrix> bop = Teuchos::rcp(
new BlockedCrsMatrix(rgMapExt, doMapExt, input->getLocalMaxNumRowEntries()));
179 for (
size_t r = 0; r < input->Rows(); ++r) {
180 for (
size_t c = 0; c < input->Cols(); ++c)
181 if (input->getMatrix(r, c) != Teuchos::null) {
186 bop->setMatrix(r, c, mat);
190 if (input->isFillComplete())
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...
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A, bool setFixedBlockSize=true)
Exception indicating invalid cast attempted.
static RCP< Matrix > Build(const RCP< const Map > &rowMap)
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this vector.
Concrete implementation of Xpetra::Matrix.
#define XPETRA_MONITOR(funcName)
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A, bool setFixedBlockSize=true)
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...
Xpetra-specific matrix class.