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"
36using namespace Teuchos;
39DefaultMappingStrategy::DefaultMappingStrategy(
40 const RCP<
const Thyra::LinearOpBase<double> >& thyraOp,
const Epetra_Comm& comm) {
41 RCP<Epetra_Comm> newComm = rcp(comm.Clone());
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);
61EpetraOperatorWrapper::EpetraOperatorWrapper() {
62 useTranspose_ =
false;
63 mapStrategy_ = Teuchos::null;
64 thyraOp_ = Teuchos::null;
65 comm_ = Teuchos::null;
66 label_ = Teuchos::null;
69EpetraOperatorWrapper::EpetraOperatorWrapper(
70 const RCP<
const Thyra::LinearOpBase<double> >& thyraOp) {
74EpetraOperatorWrapper::EpetraOperatorWrapper(
const RCP<
const Thyra::LinearOpBase<double> >& thyraOp,
75 const RCP<const MappingStrategy>& mapStrategy)
76 : mapStrategy_(mapStrategy) {
80EpetraOperatorWrapper::EpetraOperatorWrapper(
const RCP<const MappingStrategy>& mapStrategy)
81 : mapStrategy_(mapStrategy) {
82 useTranspose_ =
false;
83 thyraOp_ = Teuchos::null;
84 comm_ = Teuchos::null;
85 label_ = Teuchos::null;
88void 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_));
98double EpetraOperatorWrapper::NormInf()
const {
99 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
100 "EpetraOperatorWrapper::NormInf not implemated");
104int 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);
133int EpetraOperatorWrapper::ApplyInverse(
const Epetra_MultiVector& ,
134 Epetra_MultiVector& )
const {
135 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
136 "EpetraOperatorWrapper::ApplyInverse not implemented");
140RCP<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));
RCP< const Thyra::VectorSpaceBase< double > > rangeSpace_
Range space object.
RCP< const Epetra_Map > domainMap_
Pointer to the constructed domain map.
RCP< const Thyra::VectorSpaceBase< double > > domainSpace_
Domain space object.
RCP< const Epetra_Map > rangeMap_
Pointer to the constructed range map.
virtual void copyEpetraIntoThyra(const Epetra_MultiVector &epetraX, const Teuchos::Ptr< Thyra::MultiVectorBase< double > > &thyraX) const
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
virtual void copyThyraIntoEpetra(const RCP< const Thyra::MultiVectorBase< double > > &thyraX, Epetra_MultiVector &epetraX) const
Copy an Thyra::MultiVectorBase into a Epetra_MultiVector.
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 int GetBlockColCount()
Get the number of block columns in this operator.
const RCP< const Thyra::LinearOpBase< double > > getThyraOp() const
Return the thyra operator associated with this wrapper.