47 #include "Epetra/Teko_StridedMappingStrategy.hpp"
48 #include "Epetra/Teko_InterlacedEpetra.hpp"
49 #include "Epetra/Teko_EpetraHelpers.hpp"
51 #include "Thyra_EpetraThyraWrappers.hpp"
52 #include "Thyra_EpetraLinearOp.hpp"
53 #include "Thyra_DefaultProductMultiVector.hpp"
54 #include "Thyra_DefaultProductVectorSpace.hpp"
55 #include "Thyra_DefaultSpmdMultiVector.hpp"
56 #include "Thyra_DefaultBlockedLinearOp.hpp"
57 #include "Thyra_get_Epetra_Operator.hpp"
61 using Teuchos::rcp_dynamic_cast;
76 StridedMappingStrategy::StridedMappingStrategy(
const std::vector<int> & vars,
const RCP<const Epetra_Map> & map,
77 const Epetra_Comm & comm)
81 buildBlockTransferData(vars, rangeMap_,comm);
92 void StridedMappingStrategy::copyEpetraIntoThyra(
const Epetra_MultiVector& X,
93 const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyra_X)
const
95 int count = X.NumVectors();
97 std::vector<RCP<Epetra_MultiVector> > subX;
100 Strided::buildSubVectors(blockMaps_,subX,count);
103 Strided::one2many(subX,X,blockImport_);
106 Teuchos::Array<RCP<Thyra::MultiVectorBase<double> > > thyra_subX;
107 Teuchos::Ptr<Thyra::ProductMultiVectorBase<double> > prod_X
108 = Teuchos::ptr_dynamic_cast<Thyra::ProductMultiVectorBase<double> >(thyra_X);
109 for(
unsigned int i=0;i<blockMaps_.size();i++) {
110 RCP<Thyra::DefaultSpmdMultiVector<double> > vec
111 = rcp_dynamic_cast<Thyra::DefaultSpmdMultiVector<double> >(prod_X->getNonconstMultiVectorBlock(i));
112 fillDefaultSpmdMultiVector(vec,subX[i]);
124 void StridedMappingStrategy::copyThyraIntoEpetra(
const RCP<
const Thyra::MultiVectorBase<double> > & thyra_Y,
125 Epetra_MultiVector& Y)
const
127 std::vector<RCP<const Epetra_MultiVector> > subY;
128 RCP<const Thyra::DefaultProductMultiVector<double> > prod_Y
129 = rcp_dynamic_cast<
const Thyra::DefaultProductMultiVector<double> >(thyra_Y);
132 for(
unsigned int i=0;i<blockMaps_.size();i++)
133 subY.push_back(Thyra::get_Epetra_MultiVector(*blockMaps_[i].second,prod_Y->getMultiVectorBlock(i)));
136 Strided::associateSubVectors(blockMaps_,subY);
139 Strided::many2one(Y,subY,blockExport_);
154 void StridedMappingStrategy::buildBlockTransferData(
const std::vector<int> & vars,
const Teuchos::RCP<const Epetra_Map> & baseMap,
const Epetra_Comm & comm)
157 Strided::buildSubMaps(*baseMap,vars,comm,blockMaps_);
158 Strided::buildExportImport(*baseMap, blockMaps_, blockExport_,blockImport_);
171 const Teuchos::RCP<Thyra::BlockedLinearOpBase<double> >
172 StridedMappingStrategy::buildBlockedThyraOp(
const RCP<const Epetra_CrsMatrix> & crsContent,
const std::string & label)
const
174 int dim = blockMaps_.size();
176 RCP<Thyra::DefaultBlockedLinearOp<double> > A = Thyra::defaultBlockedLinearOp<double>();
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 A->setNonconstBlock(i,j,Thyra::nonconstEpetraLinearOp(Strided::buildSubBlock(i,j,*crsContent,blockMaps_),ss.str()));
204 void StridedMappingStrategy::rebuildBlockedThyraOp(
const RCP<const Epetra_CrsMatrix> & crsContent,
205 const RCP<Thyra::BlockedLinearOpBase<double> > & A)
const
207 int dim = blockMaps_.size();
209 for(
int i=0;i<dim;i++) {
210 for(
int j=0;j<dim;j++) {
212 RCP<Thyra::LinearOpBase<double> > Aij = A->getNonconstBlock(i,j);
213 RCP<Epetra_CrsMatrix> eAij = rcp_dynamic_cast<Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*Aij),
true);
216 Strided::rebuildSubBlock(i,j,*crsContent,blockMaps_,*eAij);