47 #include "Epetra/Teko_BlockedMappingStrategy.hpp"
48 #include "Epetra/Teko_EpetraHelpers.hpp"
50 #include "Thyra_EpetraThyraWrappers.hpp"
51 #include "Thyra_EpetraLinearOp.hpp"
52 #include "Thyra_DefaultProductMultiVector.hpp"
53 #include "Thyra_DefaultProductVectorSpace.hpp"
54 #include "Thyra_DefaultSpmdMultiVector.hpp"
55 #include "Thyra_DefaultBlockedLinearOp.hpp"
56 #include "Thyra_get_Epetra_Operator.hpp"
60 using Teuchos::rcp_dynamic_cast;
75 BlockedMappingStrategy::BlockedMappingStrategy(
const std::vector<std::vector<int> > & vars,
76 const Teuchos::RCP<const Epetra_Map> & map,
const Epetra_Comm & comm)
80 buildBlockTransferData(vars, rangeMap_,comm);
91 void BlockedMappingStrategy::copyEpetraIntoThyra(
const Epetra_MultiVector& X,
92 const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyra_X)
const
94 int count = X.NumVectors();
96 std::vector<RCP<Epetra_MultiVector> > subX;
99 Blocking::buildSubVectors(blockMaps_,subX,count);
102 Blocking::one2many(subX,X,blockImport_);
105 Teuchos::Array<RCP<Thyra::MultiVectorBase<double> > > thyra_subX;
106 Teuchos::Ptr<Thyra::ProductMultiVectorBase<double> > prod_X
107 = Teuchos::ptr_dynamic_cast<Thyra::ProductMultiVectorBase<double> >(thyra_X);
108 for(
unsigned int i=0;i<blockMaps_.size();i++) {
109 RCP<Thyra::DefaultSpmdMultiVector<double> > vec
110 = rcp_dynamic_cast<Thyra::DefaultSpmdMultiVector<double> >(prod_X->getNonconstMultiVectorBlock(i));
111 fillDefaultSpmdMultiVector(vec,subX[i]);
123 void BlockedMappingStrategy::copyThyraIntoEpetra(
const RCP<
const Thyra::MultiVectorBase<double> > & thyra_Y,
124 Epetra_MultiVector& Y)
const
126 std::vector<RCP<const Epetra_MultiVector> > subY;
127 RCP<const Thyra::DefaultProductMultiVector<double> > prod_Y
128 = rcp_dynamic_cast<
const Thyra::DefaultProductMultiVector<double> >(thyra_Y);
131 for(
unsigned int i=0;i<blockMaps_.size();i++)
132 subY.push_back(Thyra::get_Epetra_MultiVector(*blockMaps_[i].second,prod_Y->getMultiVectorBlock(i)));
138 Blocking::many2one(Y,subY,blockExport_);
153 void BlockedMappingStrategy::buildBlockTransferData(
const std::vector<std::vector<int> > & vars,
154 const Teuchos::RCP<const Epetra_Map> & baseMap,
const Epetra_Comm & comm)
157 for(std::size_t i=0;i<vars.size();i++) {
159 Blocking::MapPair mapPair = Blocking::buildSubMap(vars[i],comm);
160 Blocking::ImExPair iePair = Blocking::buildExportImport(*baseMap, mapPair);
162 blockMaps_.push_back(mapPair);
163 blockImport_.push_back(iePair.first);
164 blockExport_.push_back(iePair.second);
178 const Teuchos::RCP<Thyra::BlockedLinearOpBase<double> >
179 BlockedMappingStrategy::buildBlockedThyraOp(
const RCP<const Epetra_CrsMatrix> & crsContent,
const std::string & label)
const
181 int dim = blockMaps_.size();
183 RCP<Thyra::DefaultBlockedLinearOp<double> > A = Thyra::defaultBlockedLinearOp<double>();
185 A->beginBlockFill(dim,dim);
186 for(
int i=0;i<dim;i++) {
187 for(
int j=0;j<dim;j++) {
189 std::stringstream ss;
190 ss << label <<
"_" << i <<
"," << j;
193 RCP<Epetra_CrsMatrix> blk = Blocking::buildSubBlock(i,j,*crsContent,blockMaps_);
194 A->setNonconstBlock(i,j,Thyra::nonconstEpetraLinearOp(blk,ss.str()));
212 void BlockedMappingStrategy::rebuildBlockedThyraOp(
const RCP<const Epetra_CrsMatrix> & crsContent,
213 const RCP<Thyra::BlockedLinearOpBase<double> > & A)
const
215 int dim = blockMaps_.size();
217 for(
int i=0;i<dim;i++) {
218 for(
int j=0;j<dim;j++) {
220 RCP<Thyra::LinearOpBase<double> > Aij = A->getNonconstBlock(i,j);
221 RCP<Epetra_CrsMatrix> eAij = rcp_dynamic_cast<Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*Aij),
true);
224 Blocking::rebuildSubBlock(i,j,*crsContent,blockMaps_,*eAij);