47 #include "Teko_TpetraStridedMappingStrategy.hpp"
48 #include "Teko_InterlacedTpetra.hpp"
49 #include "Teko_TpetraHelpers.hpp"
51 #include "Thyra_TpetraThyraWrappers.hpp"
52 #include "Thyra_TpetraLinearOp.hpp"
53 #include "Thyra_DefaultProductMultiVector.hpp"
54 #include "Thyra_DefaultProductVectorSpace.hpp"
55 #include "Thyra_DefaultSpmdMultiVector.hpp"
56 #include "Thyra_DefaultBlockedLinearOp.hpp"
60 using Teuchos::rcp_dynamic_cast;
63 namespace TpetraHelpers {
75 TpetraStridedMappingStrategy::TpetraStridedMappingStrategy(
const std::vector<int> & vars,
const RCP<
const Tpetra::Map<LO,GO,NT> > & map,
76 const Teuchos::Comm<int> & comm)
80 buildBlockTransferData(vars, rangeMap_,comm);
91 void TpetraStridedMappingStrategy::copyTpetraIntoThyra(
const Tpetra::MultiVector<ST,LO,GO,NT>& X,
92 const Teuchos::Ptr<Thyra::MultiVectorBase<ST> > & thyra_X)
const
94 int count = X.getNumVectors();
96 std::vector<RCP<Tpetra::MultiVector<ST,LO,GO,NT> > > subX;
99 Strided::buildSubVectors(blockMaps_,subX,count);
102 Strided::one2many(subX,X,blockImport_);
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 TpetraStridedMappingStrategy::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());
136 Strided::associateSubVectors(blockMaps_,subY);
139 Strided::many2one(Y,subY,blockExport_);
154 void TpetraStridedMappingStrategy::buildBlockTransferData(
const std::vector<int> & vars,
const Teuchos::RCP<
const Tpetra::Map<LO,GO,NT> > & baseMap,
const Teuchos::Comm<int> & comm)
157 Strided::buildSubMaps(*baseMap,vars,comm,blockMaps_);
158 Strided::buildExportImport(*baseMap, blockMaps_, blockExport_,blockImport_);
171 const Teuchos::RCP<Thyra::BlockedLinearOpBase<ST> >
172 TpetraStridedMappingStrategy::buildBlockedThyraOp(
const RCP<
const Tpetra::CrsMatrix<ST,LO,GO,NT> > & crsContent,
const std::string & label)
const
174 int dim = blockMaps_.size();
176 RCP<Thyra::DefaultBlockedLinearOp<ST> > A = Thyra::defaultBlockedLinearOp<ST>();
178 A->beginBlockFill(dim,dim);
179 for(
int i=0;i<dim;i++) {
180 for(
int j=0;j<dim;j++) {
182 std::stringstream ss;
183 ss << label <<
"_" << i <<
"," << j;
186 RCP<Tpetra::CrsMatrix<ST,LO,GO,NT> > Aij = Strided::buildSubBlock(i,j,crsContent,blockMaps_);
187 A->setNonconstBlock(i,j,Thyra::tpetraLinearOp<ST,LO,GO,NT>(Thyra::tpetraVectorSpace<ST,LO,GO,NT>(Aij->getRangeMap()),Thyra::tpetraVectorSpace<ST,LO,GO,NT>(Aij->getDomainMap()),Aij));
205 void TpetraStridedMappingStrategy::rebuildBlockedThyraOp(
const RCP<
const Tpetra::CrsMatrix<ST,LO,GO,NT> > & crsContent,
206 const RCP<Thyra::BlockedLinearOpBase<ST> > & A)
const
208 int dim = blockMaps_.size();
210 for(
int i=0;i<dim;i++) {
211 for(
int j=0;j<dim;j++) {
213 RCP<Thyra::LinearOpBase<ST> > Aij = A->getNonconstBlock(i,j);
214 RCP<Thyra::TpetraLinearOp<ST,LO,GO,NT> > tAij = rcp_dynamic_cast<Thyra::TpetraLinearOp<ST,LO,GO,NT> >(Aij,
true);
215 RCP<Tpetra::CrsMatrix<ST,LO,GO,NT> > eAij = rcp_dynamic_cast<Tpetra::CrsMatrix<ST,LO,GO,NT> >(tAij->getTpetraOperator(),
true);
218 Strided::rebuildSubBlock(i,j,crsContent,blockMaps_,*eAij);