47 #include "Teko_TpetraBlockedMappingStrategy.hpp"
48 #include "Teko_TpetraHelpers.hpp"
50 #include "Thyra_TpetraThyraWrappers.hpp"
51 #include "Thyra_TpetraLinearOp.hpp"
52 #include "Thyra_DefaultProductMultiVector.hpp"
53 #include "Thyra_DefaultProductVectorSpace.hpp"
54 #include "Thyra_DefaultSpmdMultiVector.hpp"
55 #include "Thyra_DefaultBlockedLinearOp.hpp"
59 using Teuchos::rcp_dynamic_cast;
62 namespace TpetraHelpers {
74 TpetraBlockedMappingStrategy::TpetraBlockedMappingStrategy(
75 const std::vector<std::vector<GO> >& vars,
76 const Teuchos::RCP<
const Tpetra::Map<LO, GO, NT> >& map,
const Teuchos::Comm<int>& comm) {
79 buildBlockTransferData(vars, rangeMap_, comm);
90 void TpetraBlockedMappingStrategy::copyTpetraIntoThyra(
91 const Tpetra::MultiVector<ST, LO, GO, NT>& X,
92 const Teuchos::Ptr<Thyra::MultiVectorBase<ST> >& thyra_X)
const {
93 int count = X.getNumVectors();
95 std::vector<RCP<Tpetra::MultiVector<ST, LO, GO, NT> > > subX;
98 Blocking::buildSubVectors(blockMaps_, subX, count);
101 Blocking::one2many(subX, X, blockImport_);
104 Teuchos::Array<RCP<Thyra::MultiVectorBase<ST> > > thyra_subX;
105 Teuchos::Ptr<Thyra::ProductMultiVectorBase<ST> > prod_X =
106 Teuchos::ptr_dynamic_cast<Thyra::ProductMultiVectorBase<ST> >(thyra_X);
107 for (
unsigned int i = 0; i < blockMaps_.size(); i++) {
108 RCP<Thyra::TpetraMultiVector<ST, LO, GO, NT> > vec =
109 rcp_dynamic_cast<Thyra::TpetraMultiVector<ST, LO, GO, NT> >(
110 prod_X->getNonconstMultiVectorBlock(i),
true);
112 fillDefaultSpmdMultiVector(vec, subX[i]);
124 void TpetraBlockedMappingStrategy::copyThyraIntoTpetra(
125 const RCP<
const Thyra::MultiVectorBase<ST> >& thyra_Y,
126 Tpetra::MultiVector<ST, LO, GO, NT>& Y)
const {
127 std::vector<RCP<const Tpetra::MultiVector<ST, LO, GO, NT> > > subY;
128 RCP<const Thyra::DefaultProductMultiVector<ST> > prod_Y =
129 rcp_dynamic_cast<
const Thyra::DefaultProductMultiVector<ST> >(thyra_Y);
132 for (
unsigned int i = 0; i < blockMaps_.size(); i++) {
133 RCP<const Thyra::TpetraMultiVector<ST, LO, GO, NT> > tmv =
134 rcp_dynamic_cast<
const Thyra::TpetraMultiVector<ST, LO, GO, NT> >(
135 prod_Y->getMultiVectorBlock(i),
true);
136 subY.push_back(tmv->getConstTpetraMultiVector());
143 Blocking::many2one(Y, subY, blockExport_);
158 void TpetraBlockedMappingStrategy::buildBlockTransferData(
159 const std::vector<std::vector<GO> >& vars,
160 const Teuchos::RCP<
const Tpetra::Map<LO, GO, NT> >& baseMap,
const Teuchos::Comm<int>& comm) {
162 for (std::size_t i = 0; i < vars.size(); i++) {
164 Blocking::MapPair mapPair = Blocking::buildSubMap(vars[i], comm);
165 Blocking::ImExPair iePair = Blocking::buildExportImport(*baseMap, mapPair);
167 blockMaps_.push_back(mapPair);
168 blockImport_.push_back(iePair.first);
169 blockExport_.push_back(iePair.second);
183 const Teuchos::RCP<Thyra::BlockedLinearOpBase<ST> >
184 TpetraBlockedMappingStrategy::buildBlockedThyraOp(
185 const RCP<
const Tpetra::CrsMatrix<ST, LO, GO, NT> >& crsContent,
186 const std::string& label)
const {
187 int dim = blockMaps_.size();
189 RCP<Thyra::DefaultBlockedLinearOp<ST> > A = Thyra::defaultBlockedLinearOp<ST>();
191 A->beginBlockFill(dim, dim);
192 for (
int i = 0; i < dim; i++) {
193 for (
int j = 0; j < dim; j++) {
195 std::stringstream ss;
196 ss << label <<
"_" << i <<
"," << j;
199 RCP<Tpetra::CrsMatrix<ST, LO, GO, NT> > blk =
200 Blocking::buildSubBlock(i, j, crsContent, blockMaps_);
201 A->setNonconstBlock(i, j,
202 Thyra::tpetraLinearOp<ST, LO, GO, NT>(
203 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(blk->getRangeMap()),
204 Thyra::tpetraVectorSpace<ST, LO, GO, NT>(blk->getDomainMap()), blk));
222 void TpetraBlockedMappingStrategy::rebuildBlockedThyraOp(
223 const RCP<
const Tpetra::CrsMatrix<ST, LO, GO, NT> >& crsContent,
224 const RCP<Thyra::BlockedLinearOpBase<ST> >& A)
const {
225 int dim = blockMaps_.size();
227 for (
int i = 0; i < dim; i++) {
228 for (
int j = 0; j < dim; j++) {
230 RCP<Thyra::LinearOpBase<ST> > Aij = A->getNonconstBlock(i, j);
231 RCP<Thyra::TpetraLinearOp<ST, LO, GO, NT> > tAij =
232 rcp_dynamic_cast<Thyra::TpetraLinearOp<ST, LO, GO, NT> >(Aij,
true);
233 RCP<Tpetra::CrsMatrix<ST, LO, GO, NT> > eAij =
234 rcp_dynamic_cast<Tpetra::CrsMatrix<ST, LO, GO, NT> >(tAij->getTpetraOperator(),
true);
237 Blocking::rebuildSubBlock(i, j, crsContent, blockMaps_, *eAij);