10 #include "Teko_EpetraOperatorWrapper.hpp"
11 #include "Thyra_SpmdVectorBase.hpp"
12 #include "Thyra_MultiVectorStdOps.hpp"
14 #include "Teuchos_DefaultMpiComm.hpp"
16 #include "Teuchos_DefaultSerialComm.hpp"
17 #include "Thyra_EpetraLinearOp.hpp"
18 #include "Epetra_SerialComm.h"
19 #include "Epetra_Vector.h"
21 #include "Epetra_MpiComm.h"
23 #include "Thyra_EpetraThyraWrappers.hpp"
26 #include "Thyra_BlockedLinearOpBase.hpp"
27 #include "Thyra_ProductVectorSpaceBase.hpp"
28 #include "Thyra_get_Epetra_Operator.hpp"
30 #include "Teko_EpetraThyraConverter.hpp"
31 #include "Teuchos_Ptr.hpp"
36 using namespace Teuchos;
37 using namespace Thyra;
39 DefaultMappingStrategy::DefaultMappingStrategy(
40 const RCP<
const Thyra::LinearOpBase<double> >& thyraOp,
const Epetra_Comm& comm) {
41 RCP<Epetra_Comm> newComm = rcp(comm.Clone());
44 domainSpace_ = thyraOp->domain();
45 rangeSpace_ = thyraOp->range();
47 domainMap_ = Teko::Epetra::thyraVSToEpetraMap(*domainSpace_, newComm);
48 rangeMap_ = Teko::Epetra::thyraVSToEpetraMap(*rangeSpace_, newComm);
52 const Epetra_MultiVector& x,
const Ptr<Thyra::MultiVectorBase<double> >& thyraVec)
const {
53 Teko::Epetra::blockEpetraToThyra(x, thyraVec);
57 const RCP<
const Thyra::MultiVectorBase<double> >& thyraVec, Epetra_MultiVector& v)
const {
58 Teko::Epetra::blockThyraToEpetra(thyraVec, v);
61 EpetraOperatorWrapper::EpetraOperatorWrapper() {
62 useTranspose_ =
false;
63 mapStrategy_ = Teuchos::null;
64 thyraOp_ = Teuchos::null;
65 comm_ = Teuchos::null;
66 label_ = Teuchos::null;
69 EpetraOperatorWrapper::EpetraOperatorWrapper(
70 const RCP<
const Thyra::LinearOpBase<double> >& thyraOp) {
74 EpetraOperatorWrapper::EpetraOperatorWrapper(
const RCP<
const Thyra::LinearOpBase<double> >& thyraOp,
75 const RCP<const MappingStrategy>& mapStrategy)
76 : mapStrategy_(mapStrategy) {
80 EpetraOperatorWrapper::EpetraOperatorWrapper(
const RCP<const MappingStrategy>& mapStrategy)
81 : mapStrategy_(mapStrategy) {
82 useTranspose_ =
false;
83 thyraOp_ = Teuchos::null;
84 comm_ = Teuchos::null;
85 label_ = Teuchos::null;
88 void EpetraOperatorWrapper::SetOperator(
const RCP<
const LinearOpBase<double> >& thyraOp,
90 useTranspose_ =
false;
92 comm_ = getEpetraComm(*thyraOp);
93 label_ = thyraOp_->description();
94 if (mapStrategy_ == Teuchos::null && buildMap)
95 mapStrategy_ = Teuchos::rcp(
new DefaultMappingStrategy(thyraOp, *comm_));
98 double EpetraOperatorWrapper::NormInf()
const {
99 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
100 "EpetraOperatorWrapper::NormInf not implemated");
104 int EpetraOperatorWrapper::Apply(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const {
105 if (!useTranspose_) {
107 RCP<Thyra::MultiVectorBase<double> > tX;
108 RCP<Thyra::MultiVectorBase<double> > tY;
110 tX = Thyra::createMembers(thyraOp_->domain(), X.NumVectors());
111 tY = Thyra::createMembers(thyraOp_->range(), X.NumVectors());
113 Thyra::assign(tX.ptr(), 0.0);
114 Thyra::assign(tY.ptr(), 0.0);
117 mapStrategy_->copyEpetraIntoThyra(X, tX.ptr());
118 mapStrategy_->copyEpetraIntoThyra(
122 thyraOp_->apply(Thyra::NOTRANS, *tX, tY.ptr(), 1.0, 0.0);
125 mapStrategy_->copyThyraIntoEpetra(tY, Y);
127 TEUCHOS_ASSERT(
false);
133 int EpetraOperatorWrapper::ApplyInverse(
const Epetra_MultiVector& ,
134 Epetra_MultiVector& )
const {
135 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
136 "EpetraOperatorWrapper::ApplyInverse not implemented");
140 RCP<const Epetra_Comm> EpetraOperatorWrapper::getEpetraComm(
141 const Thyra::LinearOpBase<double>& inOp)
const {
142 RCP<const VectorSpaceBase<double> > vs = inOp.domain();
144 RCP<const SpmdVectorSpaceBase<double> > spmd;
145 RCP<const VectorSpaceBase<double> > current = vs;
146 while (current != Teuchos::null) {
148 RCP<const ProductVectorSpaceBase<double> > prod =
149 rcp_dynamic_cast<
const ProductVectorSpaceBase<double> >(current);
152 if (prod == Teuchos::null) {
154 spmd = rcp_dynamic_cast<
const SpmdVectorSpaceBase<double> >(current);
158 current = prod->getBlock(0);
161 TEUCHOS_TEST_FOR_EXCEPTION(spmd == Teuchos::null, std::runtime_error,
162 "EpetraOperatorWrapper requires std::vector space "
163 "blocks to be SPMD std::vector spaces");
165 return Thyra::get_Epetra_Comm(*spmd->getComm());
231 const RCP<const Thyra::BlockedLinearOpBase<double> > blkOp =
232 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<double> >(
getThyraOp());
234 return blkOp->productRange()->numBlocks();
238 const RCP<const Thyra::BlockedLinearOpBase<double> > blkOp =
239 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<double> >(
getThyraOp());
241 return blkOp->productDomain()->numBlocks();
245 const RCP<const Thyra::BlockedLinearOpBase<double> > blkOp =
246 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<double> >(
getThyraOp());
248 return Thyra::get_Epetra_Operator(*blkOp->getBlock(i, j));
virtual int GetBlockColCount()
Get the number of block columns in this operator.
virtual void copyEpetraIntoThyra(const Epetra_MultiVector &epetraX, const Teuchos::Ptr< Thyra::MultiVectorBase< double > > &thyraX) const
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
Teuchos::RCP< const Epetra_Operator > GetBlock(int i, int j) const
Grab the i,j block.
virtual int GetBlockRowCount()
Get the number of block rows in this operator.
virtual void copyThyraIntoEpetra(const RCP< const Thyra::MultiVectorBase< double > > &thyraX, Epetra_MultiVector &epetraX) const
Copy an Thyra::MultiVectorBase into a Epetra_MultiVector.
const RCP< const Thyra::LinearOpBase< double > > getThyraOp() const
Return the thyra operator associated with this wrapper.