10 #include "Epetra/Teko_StridedMappingStrategy.hpp"
11 #include "Epetra/Teko_InterlacedEpetra.hpp"
12 #include "Epetra/Teko_EpetraHelpers.hpp"
14 #include "Thyra_EpetraThyraWrappers.hpp"
15 #include "Thyra_EpetraLinearOp.hpp"
16 #include "Thyra_DefaultProductMultiVector.hpp"
17 #include "Thyra_DefaultProductVectorSpace.hpp"
18 #include "Thyra_DefaultSpmdMultiVector.hpp"
19 #include "Thyra_DefaultBlockedLinearOp.hpp"
20 #include "Thyra_get_Epetra_Operator.hpp"
24 using Teuchos::rcp_dynamic_cast;
39 StridedMappingStrategy::StridedMappingStrategy(
const std::vector<int>& vars,
40 const RCP<const Epetra_Map>& map,
41 const Epetra_Comm& comm) {
44 buildBlockTransferData(vars, rangeMap_, comm);
55 void StridedMappingStrategy::copyEpetraIntoThyra(
56 const Epetra_MultiVector& X,
57 const Teuchos::Ptr<Thyra::MultiVectorBase<double> >& thyra_X)
const {
58 int count = X.NumVectors();
60 std::vector<RCP<Epetra_MultiVector> > subX;
63 Strided::buildSubVectors(blockMaps_, subX, count);
66 Strided::one2many(subX, X, blockImport_);
69 Teuchos::Array<RCP<Thyra::MultiVectorBase<double> > > thyra_subX;
70 Teuchos::Ptr<Thyra::ProductMultiVectorBase<double> > prod_X =
71 Teuchos::ptr_dynamic_cast<Thyra::ProductMultiVectorBase<double> >(thyra_X);
72 for (
unsigned int i = 0; i < blockMaps_.size(); i++) {
73 RCP<Thyra::DefaultSpmdMultiVector<double> > vec =
74 rcp_dynamic_cast<Thyra::DefaultSpmdMultiVector<double> >(
75 prod_X->getNonconstMultiVectorBlock(i));
76 fillDefaultSpmdMultiVector(vec, subX[i]);
88 void StridedMappingStrategy::copyThyraIntoEpetra(
89 const RCP<
const Thyra::MultiVectorBase<double> >& thyra_Y, Epetra_MultiVector& Y)
const {
90 std::vector<RCP<const Epetra_MultiVector> > subY;
91 RCP<const Thyra::DefaultProductMultiVector<double> > prod_Y =
92 rcp_dynamic_cast<
const Thyra::DefaultProductMultiVector<double> >(thyra_Y);
95 for (
unsigned int i = 0; i < blockMaps_.size(); i++)
97 Thyra::get_Epetra_MultiVector(*blockMaps_[i].second, prod_Y->getMultiVectorBlock(i)));
100 Strided::associateSubVectors(blockMaps_, subY);
103 Strided::many2one(Y, subY, blockExport_);
118 void StridedMappingStrategy::buildBlockTransferData(
const std::vector<int>& vars,
119 const Teuchos::RCP<const Epetra_Map>& baseMap,
120 const Epetra_Comm& comm) {
122 Strided::buildSubMaps(*baseMap, vars, comm, blockMaps_);
123 Strided::buildExportImport(*baseMap, blockMaps_, blockExport_, blockImport_);
136 const Teuchos::RCP<Thyra::BlockedLinearOpBase<double> > StridedMappingStrategy::buildBlockedThyraOp(
137 const RCP<const Epetra_CrsMatrix>& crsContent,
const std::string& label)
const {
138 int dim = blockMaps_.size();
140 RCP<Thyra::DefaultBlockedLinearOp<double> > A = Thyra::defaultBlockedLinearOp<double>();
142 A->beginBlockFill(dim, dim);
143 for (
int i = 0; i < dim; i++) {
144 for (
int j = 0; j < dim; j++) {
146 std::stringstream ss;
147 ss << label <<
"_" << i <<
"," << j;
150 A->setNonconstBlock(i, j,
151 Thyra::nonconstEpetraLinearOp(
152 Strided::buildSubBlock(i, j, *crsContent, blockMaps_), ss.str()));
170 void StridedMappingStrategy::rebuildBlockedThyraOp(
171 const RCP<const Epetra_CrsMatrix>& crsContent,
172 const RCP<Thyra::BlockedLinearOpBase<double> >& A)
const {
173 int dim = blockMaps_.size();
175 for (
int i = 0; i < dim; i++) {
176 for (
int j = 0; j < dim; j++) {
178 RCP<Thyra::LinearOpBase<double> > Aij = A->getNonconstBlock(i, j);
179 RCP<Epetra_CrsMatrix> eAij =
180 rcp_dynamic_cast<Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*Aij),
true);
183 Strided::rebuildSubBlock(i, j, *crsContent, blockMaps_, *eAij);