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(
const std::vector<std::vector<GO> > & vars,
75 const Teuchos::RCP<
const Tpetra::Map<LO,GO,NT> > & map,
const Teuchos::Comm<int> & comm)
79 buildBlockTransferData(vars, rangeMap_,comm);
90 void TpetraBlockedMappingStrategy::copyTpetraIntoThyra(
const Tpetra::MultiVector<ST,LO,GO,NT>& X,
91 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 = rcp_dynamic_cast<Thyra::TpetraMultiVector<ST,LO,GO,NT> >(prod_X->getNonconstMultiVectorBlock(i),
true);
110 fillDefaultSpmdMultiVector(vec,subX[i]);
122 void TpetraBlockedMappingStrategy::copyThyraIntoTpetra(
const RCP<
const Thyra::MultiVectorBase<ST> > & thyra_Y,
123 Tpetra::MultiVector<ST,LO,GO,NT>& Y)
const
125 std::vector<RCP<const Tpetra::MultiVector<ST,LO,GO,NT> > > subY;
126 RCP<const Thyra::DefaultProductMultiVector<ST> > prod_Y
127 = rcp_dynamic_cast<
const Thyra::DefaultProductMultiVector<ST> >(thyra_Y);
130 for(
unsigned int i=0;i<blockMaps_.size();i++){
131 RCP<const Thyra::TpetraMultiVector<ST,LO,GO,NT> > tmv = rcp_dynamic_cast<
const Thyra::TpetraMultiVector<ST,LO,GO,NT> >(prod_Y->getMultiVectorBlock(i),
true);
132 subY.push_back(tmv->getConstTpetraMultiVector());
139 Blocking::many2one(Y,subY,blockExport_);
154 void TpetraBlockedMappingStrategy::buildBlockTransferData(
const std::vector<std::vector<GO> > & vars,
155 const Teuchos::RCP<
const Tpetra::Map<LO,GO,NT> > & baseMap,
const Teuchos::Comm<int> & comm)
158 for(std::size_t i=0;i<vars.size();i++) {
160 Blocking::MapPair mapPair = Blocking::buildSubMap(vars[i],comm);
161 Blocking::ImExPair iePair = Blocking::buildExportImport(*baseMap, mapPair);
163 blockMaps_.push_back(mapPair);
164 blockImport_.push_back(iePair.first);
165 blockExport_.push_back(iePair.second);
179 const Teuchos::RCP<Thyra::BlockedLinearOpBase<ST> >
180 TpetraBlockedMappingStrategy::buildBlockedThyraOp(
const RCP<
const Tpetra::CrsMatrix<ST,LO,GO,NT> > & crsContent,
const std::string & label)
const
182 int dim = blockMaps_.size();
184 RCP<Thyra::DefaultBlockedLinearOp<ST> > A = Thyra::defaultBlockedLinearOp<ST>();
186 A->beginBlockFill(dim,dim);
187 for(
int i=0;i<dim;i++) {
188 for(
int j=0;j<dim;j++) {
190 std::stringstream ss;
191 ss << label <<
"_" << i <<
"," << j;
194 RCP<Tpetra::CrsMatrix<ST,LO,GO,NT> > blk = Blocking::buildSubBlock(i,j,crsContent,blockMaps_);
195 A->setNonconstBlock(i,j,Thyra::tpetraLinearOp<ST,LO,GO,NT>(Thyra::tpetraVectorSpace<ST,LO,GO,NT>(blk->getRangeMap()),Thyra::tpetraVectorSpace<ST,LO,GO,NT>(blk->getDomainMap()),blk));
213 void TpetraBlockedMappingStrategy::rebuildBlockedThyraOp(
const RCP<
const Tpetra::CrsMatrix<ST,LO,GO,NT> > & crsContent,
214 const RCP<Thyra::BlockedLinearOpBase<ST> > & A)
const
216 int dim = blockMaps_.size();
218 for(
int i=0;i<dim;i++) {
219 for(
int j=0;j<dim;j++) {
221 RCP<Thyra::LinearOpBase<ST> > Aij = A->getNonconstBlock(i,j);
222 RCP<Thyra::TpetraLinearOp<ST,LO,GO,NT> > tAij = rcp_dynamic_cast<Thyra::TpetraLinearOp<ST,LO,GO,NT> >(Aij,
true);
223 RCP<Tpetra::CrsMatrix<ST,LO,GO,NT> > eAij = rcp_dynamic_cast<Tpetra::CrsMatrix<ST,LO,GO,NT> >(tAij->getTpetraOperator(),
true);
226 Blocking::rebuildSubBlock(i,j,crsContent,blockMaps_,*eAij);