10 #include "Teko_TpetraStridedMappingStrategy.hpp"
11 #include "Teko_InterlacedTpetra.hpp"
12 #include "Teko_TpetraHelpers.hpp"
14 #include "Thyra_TpetraThyraWrappers.hpp"
15 #include "Thyra_TpetraLinearOp.hpp"
16 #include "Thyra_DefaultProductMultiVector.hpp"
17 #include "Thyra_DefaultProductVectorSpace.hpp"
18 #include "Thyra_DefaultSpmdMultiVector.hpp"
19 #include "Thyra_DefaultBlockedLinearOp.hpp"
23 using Teuchos::rcp_dynamic_cast;
26 namespace TpetraHelpers {
38 TpetraStridedMappingStrategy::TpetraStridedMappingStrategy(
39 const std::vector<int>& vars,
const RCP<
const Tpetra::Map<LO, GO, NT> >& map,
40 const Teuchos::Comm<int>& comm) {
43 buildBlockTransferData(vars, rangeMap_, comm);
54 void TpetraStridedMappingStrategy::copyTpetraIntoThyra(
55 const Tpetra::MultiVector<ST, LO, GO, NT>& X,
56 const Teuchos::Ptr<Thyra::MultiVectorBase<ST> >& thyra_X)
const {
57 int count = X.getNumVectors();
59 std::vector<RCP<Tpetra::MultiVector<ST, LO, GO, NT> > > subX;
62 Strided::buildSubVectors(blockMaps_, subX, count);
65 Strided::one2many(subX, X, blockImport_);
68 Teuchos::Ptr<Thyra::ProductMultiVectorBase<ST> > prod_X =
69 Teuchos::ptr_dynamic_cast<Thyra::ProductMultiVectorBase<ST> >(thyra_X);
70 for (
unsigned int i = 0; i < blockMaps_.size(); i++) {
71 RCP<Thyra::TpetraMultiVector<ST, LO, GO, NT> > vec =
72 rcp_dynamic_cast<Thyra::TpetraMultiVector<ST, LO, GO, NT> >(
73 prod_X->getNonconstMultiVectorBlock(i),
true);
75 fillDefaultSpmdMultiVector(vec, subX[i]);
87 void TpetraStridedMappingStrategy::copyThyraIntoTpetra(
88 const RCP<
const Thyra::MultiVectorBase<ST> >& thyra_Y,
89 Tpetra::MultiVector<ST, LO, GO, NT>& Y)
const {
90 std::vector<RCP<const Tpetra::MultiVector<ST, LO, GO, NT> > > subY;
91 RCP<const Thyra::DefaultProductMultiVector<ST> > prod_Y =
92 rcp_dynamic_cast<
const Thyra::DefaultProductMultiVector<ST> >(thyra_Y);
95 for (
unsigned int i = 0; i < blockMaps_.size(); i++) {
96 RCP<const Thyra::TpetraMultiVector<ST, LO, GO, NT> > tmv =
97 rcp_dynamic_cast<
const Thyra::TpetraMultiVector<ST, LO, GO, NT> >(
98 prod_Y->getMultiVectorBlock(i),
true);
99 subY.push_back(tmv->getConstTpetraMultiVector());
103 Strided::associateSubVectors(blockMaps_, subY);
106 Strided::many2one(Y, subY, blockExport_);
121 void TpetraStridedMappingStrategy::buildBlockTransferData(
122 const std::vector<int>& vars,
const Teuchos::RCP<
const Tpetra::Map<LO, GO, NT> >& baseMap,
123 const Teuchos::Comm<int>& comm) {
125 Strided::buildSubMaps(*baseMap, vars, comm, blockMaps_);
126 Strided::buildExportImport(*baseMap, blockMaps_, blockExport_, blockImport_);
139 const Teuchos::RCP<Thyra::BlockedLinearOpBase<ST> >
140 TpetraStridedMappingStrategy::buildBlockedThyraOp(
141 const RCP<
const Tpetra::CrsMatrix<ST, LO, GO, NT> >& crsContent,
142 const std::string& label)
const {
143 int dim = blockMaps_.size();
145 RCP<Thyra::DefaultBlockedLinearOp<ST> > A = Thyra::defaultBlockedLinearOp<ST>();
147 A->beginBlockFill(dim, dim);
148 for (
int i = 0; i < dim; i++) {
149 for (
int j = 0; j < dim; j++) {
151 std::stringstream ss;
152 ss << label <<
"_" << i <<
"," << j;
155 RCP<Tpetra::CrsMatrix<ST, LO, GO, NT> > Aij =
156 Strided::buildSubBlock(i, j, crsContent, blockMaps_);
157 A->setNonconstBlock(i, j,
158 Thyra::tpetraLinearOp<ST, LO, GO, NT>(
159 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(Aij->getRangeMap()),
160 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(Aij->getDomainMap()), Aij));
178 void TpetraStridedMappingStrategy::rebuildBlockedThyraOp(
179 const RCP<
const Tpetra::CrsMatrix<ST, LO, GO, NT> >& crsContent,
180 const RCP<Thyra::BlockedLinearOpBase<ST> >& A)
const {
181 int dim = blockMaps_.size();
183 for (
int i = 0; i < dim; i++) {
184 for (
int j = 0; j < dim; j++) {
186 RCP<Thyra::LinearOpBase<ST> > Aij = A->getNonconstBlock(i, j);
187 RCP<Thyra::TpetraLinearOp<ST, LO, GO, NT> > tAij =
188 rcp_dynamic_cast<Thyra::TpetraLinearOp<ST, LO, GO, NT> >(Aij,
true);
189 RCP<Tpetra::CrsMatrix<ST, LO, GO, NT> > eAij =
190 rcp_dynamic_cast<Tpetra::CrsMatrix<ST, LO, GO, NT> >(tAij->getTpetraOperator(),
true);
193 Strided::rebuildSubBlock(i, j, crsContent, blockMaps_, *eAij);