00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "Teko_EpetraOperatorWrapper.hpp"
00046 #include "Thyra_SpmdVectorBase.hpp"
00047 #include "Thyra_MultiVectorStdOps.hpp"
00048 #ifdef HAVE_MPI
00049 #include "Teuchos_DefaultMpiComm.hpp"
00050 #endif
00051 #include "Teuchos_DefaultSerialComm.hpp"
00052 #include "Thyra_EpetraLinearOp.hpp"
00053 #include "Epetra_SerialComm.h"
00054 #include "Epetra_Vector.h"
00055 #ifdef HAVE_MPI
00056 #include "Epetra_MpiComm.h"
00057 #endif
00058 #include "Thyra_EpetraThyraWrappers.hpp"
00059
00060
00061 #include "Thyra_BlockedLinearOpBase.hpp"
00062 #include "Thyra_ProductVectorSpaceBase.hpp"
00063 #include "Thyra_get_Epetra_Operator.hpp"
00064
00065 #include "Teko_EpetraThyraConverter.hpp"
00066 #include "Teuchos_Ptr.hpp"
00067
00068
00069 namespace Teko {
00070 namespace Epetra {
00071
00072
00073 using namespace Teuchos;
00074 using namespace Thyra;
00075
00076 DefaultMappingStrategy::DefaultMappingStrategy(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,const Epetra_Comm & comm)
00077 {
00078 RCP<Epetra_Comm> newComm = rcp(comm.Clone());
00079
00080
00081 domainSpace_ = thyraOp->domain();
00082 rangeSpace_ = thyraOp->range();
00083
00084 domainMap_ = Teko::Epetra::thyraVSToEpetraMap(*domainSpace_,newComm);
00085 rangeMap_ = Teko::Epetra::thyraVSToEpetraMap(*rangeSpace_,newComm);
00086 }
00087
00088 void DefaultMappingStrategy::copyEpetraIntoThyra(const Epetra_MultiVector& x, const Ptr<Thyra::MultiVectorBase<double> > & thyraVec) const
00089 {
00090 Teko::Epetra::blockEpetraToThyra(x,thyraVec);
00091 }
00092
00093 void DefaultMappingStrategy::copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraVec, Epetra_MultiVector& v) const
00094 {
00095 Teko::Epetra::blockThyraToEpetra(thyraVec,v);
00096 }
00097
00098 EpetraOperatorWrapper::EpetraOperatorWrapper()
00099 {
00100 useTranspose_ = false;
00101 mapStrategy_ = Teuchos::null;
00102 thyraOp_ = Teuchos::null;
00103 comm_ = Teuchos::null;
00104 label_ = Teuchos::null;
00105 }
00106
00107 EpetraOperatorWrapper::EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> > & thyraOp)
00108 {
00109 SetOperator(thyraOp);
00110 }
00111
00112 EpetraOperatorWrapper::EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,const RCP<const MappingStrategy> & mapStrategy)
00113 : mapStrategy_(mapStrategy)
00114 {
00115 SetOperator(thyraOp);
00116 }
00117
00118 EpetraOperatorWrapper::EpetraOperatorWrapper(const RCP<const MappingStrategy> & mapStrategy)
00119 : mapStrategy_(mapStrategy)
00120 {
00121 useTranspose_ = false;
00122 thyraOp_ = Teuchos::null;
00123 comm_ = Teuchos::null;
00124 label_ = Teuchos::null;
00125 }
00126
00127 void EpetraOperatorWrapper::SetOperator(const RCP<const LinearOpBase<double> > & thyraOp,bool buildMap)
00128 {
00129 useTranspose_ = false;
00130 thyraOp_ = thyraOp;
00131 comm_ = getEpetraComm(*thyraOp);
00132 label_ = thyraOp_->description();
00133 if(mapStrategy_==Teuchos::null && buildMap)
00134 mapStrategy_ = Teuchos::rcp(new DefaultMappingStrategy(thyraOp,*comm_));
00135 }
00136
00137 double EpetraOperatorWrapper::NormInf() const
00138 {
00139 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
00140 "EpetraOperatorWrapper::NormInf not implemated");
00141 return 1.0;
00142 }
00143
00144 int EpetraOperatorWrapper::Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
00145 {
00146 if (!useTranspose_)
00147 {
00148
00149 RCP<Thyra::MultiVectorBase<double> > tX;
00150 RCP<Thyra::MultiVectorBase<double> > tY;
00151
00152 tX = Thyra::createMembers(thyraOp_->domain(),X.NumVectors());
00153 tY = Thyra::createMembers(thyraOp_->range(),X.NumVectors());
00154
00155 Thyra::assign(tX.ptr(),0.0);
00156 Thyra::assign(tY.ptr(),0.0);
00157
00158
00159 mapStrategy_->copyEpetraIntoThyra(X, tX.ptr());
00160 mapStrategy_->copyEpetraIntoThyra(Y, tY.ptr());
00161
00162
00163 thyraOp_->apply(Thyra::NOTRANS,*tX,tY.ptr(),1.0,0.0);
00164
00165
00166 mapStrategy_->copyThyraIntoEpetra(tY, Y);
00167 }
00168 else
00169 {
00170 TEUCHOS_ASSERT(false);
00171 }
00172
00173 return 0;
00174 }
00175
00176
00177 int EpetraOperatorWrapper::ApplyInverse(const Epetra_MultiVector& X,
00178 Epetra_MultiVector& Y) const
00179 {
00180 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
00181 "EpetraOperatorWrapper::ApplyInverse not implemented");
00182 return 1;
00183 }
00184
00185
00186 RCP<const Epetra_Comm>
00187 EpetraOperatorWrapper::getEpetraComm(const Thyra::LinearOpBase<double>& inOp) const
00188 {
00189 RCP<const VectorSpaceBase<double> > vs = inOp.domain();
00190
00191 RCP<const SpmdVectorSpaceBase<double> > spmd;
00192 RCP<const VectorSpaceBase<double> > current = vs;
00193 while(current!=Teuchos::null) {
00194
00195 RCP<const ProductVectorSpaceBase<double> > prod
00196 = rcp_dynamic_cast<const ProductVectorSpaceBase<double> >(current);
00197
00198
00199 if(prod==Teuchos::null) {
00200
00201 spmd = rcp_dynamic_cast<const SpmdVectorSpaceBase<double> >(current);
00202
00203 break;
00204 }
00205 else
00206 current = prod->getBlock(0);
00207 }
00208
00209 TEUCHOS_TEST_FOR_EXCEPTION(spmd==Teuchos::null, std::runtime_error,
00210 "EpetraOperatorWrapper requires std::vector space "
00211 "blocks to be SPMD std::vector spaces");
00212
00213 return Thyra::get_Epetra_Comm(*spmd->getComm());
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 }
00277
00278 int EpetraOperatorWrapper::GetBlockRowCount()
00279 {
00280 const RCP<const Thyra::BlockedLinearOpBase<double> > blkOp
00281 = Teuchos::rcp_dynamic_cast<const Thyra::BlockedLinearOpBase<double> >(getThyraOp());
00282
00283 return blkOp->productRange()->numBlocks();
00284 }
00285
00286 int EpetraOperatorWrapper::GetBlockColCount()
00287 {
00288 const RCP<const Thyra::BlockedLinearOpBase<double> > blkOp
00289 = Teuchos::rcp_dynamic_cast<const Thyra::BlockedLinearOpBase<double> >(getThyraOp());
00290
00291 return blkOp->productDomain()->numBlocks();
00292 }
00293
00294 Teuchos::RCP<const Epetra_Operator> EpetraOperatorWrapper::GetBlock(int i,int j) const
00295 {
00296 const RCP<const Thyra::BlockedLinearOpBase<double> > blkOp
00297 = Teuchos::rcp_dynamic_cast<const Thyra::BlockedLinearOpBase<double> >(getThyraOp());
00298
00299 return Thyra::get_Epetra_Operator(*blkOp->getBlock(i,j));
00300 }
00301
00302 }
00303 }