10 #include "Epetra/Teko_BlockedMappingStrategy.hpp"
11 #include "Epetra/Teko_EpetraHelpers.hpp"
13 #include "Thyra_EpetraThyraWrappers.hpp"
14 #include "Thyra_EpetraLinearOp.hpp"
15 #include "Thyra_DefaultProductMultiVector.hpp"
16 #include "Thyra_DefaultProductVectorSpace.hpp"
17 #include "Thyra_DefaultSpmdMultiVector.hpp"
18 #include "Thyra_DefaultBlockedLinearOp.hpp"
19 #include "Thyra_get_Epetra_Operator.hpp"
23 using Teuchos::rcp_dynamic_cast;
38 BlockedMappingStrategy::BlockedMappingStrategy(
const std::vector<std::vector<int> >& vars,
39 const Teuchos::RCP<const Epetra_Map>& map,
40 const Epetra_Comm& comm) {
43 buildBlockTransferData(vars, rangeMap_, comm);
54 void BlockedMappingStrategy::copyEpetraIntoThyra(
55 const Epetra_MultiVector& X,
56 const Teuchos::Ptr<Thyra::MultiVectorBase<double> >& thyra_X)
const {
57 int count = X.NumVectors();
59 std::vector<RCP<Epetra_MultiVector> > subX;
62 Blocking::buildSubVectors(blockMaps_, subX, count);
65 Blocking::one2many(subX, X, blockImport_);
68 Teuchos::Array<RCP<Thyra::MultiVectorBase<double> > > thyra_subX;
69 Teuchos::Ptr<Thyra::ProductMultiVectorBase<double> > prod_X =
70 Teuchos::ptr_dynamic_cast<Thyra::ProductMultiVectorBase<double> >(thyra_X);
71 for (
unsigned int i = 0; i < blockMaps_.size(); i++) {
72 RCP<Thyra::DefaultSpmdMultiVector<double> > vec =
73 rcp_dynamic_cast<Thyra::DefaultSpmdMultiVector<double> >(
74 prod_X->getNonconstMultiVectorBlock(i));
75 fillDefaultSpmdMultiVector(vec, subX[i]);
87 void BlockedMappingStrategy::copyThyraIntoEpetra(
88 const RCP<
const Thyra::MultiVectorBase<double> >& thyra_Y, Epetra_MultiVector& Y)
const {
89 std::vector<RCP<const Epetra_MultiVector> > subY;
90 RCP<const Thyra::DefaultProductMultiVector<double> > prod_Y =
91 rcp_dynamic_cast<
const Thyra::DefaultProductMultiVector<double> >(thyra_Y);
94 for (
unsigned int i = 0; i < blockMaps_.size(); i++)
96 Thyra::get_Epetra_MultiVector(*blockMaps_[i].second, prod_Y->getMultiVectorBlock(i)));
102 Blocking::many2one(Y, subY, blockExport_);
117 void BlockedMappingStrategy::buildBlockTransferData(
const std::vector<std::vector<int> >& vars,
118 const Teuchos::RCP<const Epetra_Map>& baseMap,
119 const Epetra_Comm& comm) {
121 for (std::size_t i = 0; i < vars.size(); i++) {
123 Blocking::MapPair mapPair = Blocking::buildSubMap(vars[i], comm);
124 Blocking::ImExPair iePair = Blocking::buildExportImport(*baseMap, mapPair);
126 blockMaps_.push_back(mapPair);
127 blockImport_.push_back(iePair.first);
128 blockExport_.push_back(iePair.second);
142 const Teuchos::RCP<Thyra::BlockedLinearOpBase<double> > BlockedMappingStrategy::buildBlockedThyraOp(
143 const RCP<const Epetra_CrsMatrix>& crsContent,
const std::string& label)
const {
144 int dim = blockMaps_.size();
146 RCP<Thyra::DefaultBlockedLinearOp<double> > A = Thyra::defaultBlockedLinearOp<double>();
148 A->beginBlockFill(dim, dim);
149 for (
int i = 0; i < dim; i++) {
150 for (
int j = 0; j < dim; j++) {
152 std::stringstream ss;
153 ss << label <<
"_" << i <<
"," << j;
156 RCP<Epetra_CrsMatrix> blk = Blocking::buildSubBlock(i, j, *crsContent, blockMaps_);
157 A->setNonconstBlock(i, j, Thyra::nonconstEpetraLinearOp(blk, ss.str()));
175 void BlockedMappingStrategy::rebuildBlockedThyraOp(
176 const RCP<const Epetra_CrsMatrix>& crsContent,
177 const RCP<Thyra::BlockedLinearOpBase<double> >& A)
const {
178 int dim = blockMaps_.size();
180 for (
int i = 0; i < dim; i++) {
181 for (
int j = 0; j < dim; j++) {
183 RCP<Thyra::LinearOpBase<double> > Aij = A->getNonconstBlock(i, j);
184 RCP<Epetra_CrsMatrix> eAij =
185 rcp_dynamic_cast<Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*Aij),
true);
188 Blocking::rebuildSubBlock(i, j, *crsContent, blockMaps_, *eAij);