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
00046
00047 #include "Teko_EpetraHelpers.hpp"
00048
00049
00050 #include "Thyra_EpetraLinearOp.hpp"
00051 #include "Thyra_BlockedLinearOpBase.hpp"
00052 #include "Thyra_DefaultMultipliedLinearOp.hpp"
00053 #include "Thyra_DefaultDiagonalLinearOp.hpp"
00054 #include "Thyra_DefaultZeroLinearOp.hpp"
00055 #include "Thyra_DefaultBlockedLinearOp.hpp"
00056 #include "Thyra_EpetraThyraWrappers.hpp"
00057 #include "Thyra_SpmdVectorBase.hpp"
00058 #include "Thyra_SpmdVectorSpaceBase.hpp"
00059
00060
00061 #include "Epetra_Vector.h"
00062
00063
00064 #include "EpetraExt_ProductOperator.h"
00065 #include "EpetraExt_MatrixMatrix.h"
00066
00067
00068 #include "Teko_EpetraOperatorWrapper.hpp"
00069 #include "Teko_Utilities.hpp"
00070
00071 using Teuchos::RCP;
00072 using Teuchos::rcp;
00073 using Teuchos::rcpFromRef;
00074 using Teuchos::rcp_dynamic_cast;
00075 using Teuchos::null;
00076
00077 namespace Teko {
00078 namespace Epetra {
00079
00090 const Teuchos::RCP<const Thyra::LinearOpBase<double> > thyraDiagOp(const RCP<const Epetra_Vector> & ev,const Epetra_Map & map,
00091 const std::string & lbl)
00092 {
00093 const RCP<const Thyra::VectorBase<double> > thyraVec
00094 = Thyra::create_Vector(ev,Thyra::create_VectorSpace(rcpFromRef(map)));
00095 Teuchos::RCP<Thyra::LinearOpBase<double> > op
00096 = Teuchos::rcp(new Thyra::DefaultDiagonalLinearOp<double>(thyraVec));
00097 op->setObjectLabel(lbl);
00098 return op;
00099 }
00100
00111 const Teuchos::RCP<Thyra::LinearOpBase<double> > thyraDiagOp(const RCP<Epetra_Vector> & ev,const Epetra_Map & map,
00112 const std::string & lbl)
00113 {
00114 const RCP<Thyra::VectorBase<double> > thyraVec
00115 = Thyra::create_Vector(ev,Thyra::create_VectorSpace(rcpFromRef(map)));
00116 Teuchos::RCP<Thyra::LinearOpBase<double> > op
00117 = Teuchos::rcp(new Thyra::DefaultDiagonalLinearOp<double>(thyraVec));
00118 op->setObjectLabel(lbl);
00119 return op;
00120 }
00121
00131 void fillDefaultSpmdMultiVector(Teuchos::RCP<Thyra::DefaultSpmdMultiVector<double> > & spmdMV,
00132 Teuchos::RCP<Epetra_MultiVector> & epetraMV)
00133 {
00134
00135 const RCP<const Thyra::SpmdVectorSpaceBase<double> > range = spmdMV->spmdSpace();
00136 const RCP<const Thyra::ScalarProdVectorSpaceBase<double> > domain
00137 = rcp_dynamic_cast<const Thyra::ScalarProdVectorSpaceBase<double> >(spmdMV->domain());
00138
00139 TEUCHOS_ASSERT(domain->dim()==epetraMV->NumVectors());
00140
00141
00142 double *localValues; int leadingDim;
00143 if(epetraMV->ConstantStride() )
00144 epetraMV->ExtractView( &localValues, &leadingDim );
00145 else
00146 TEUCHOS_TEST_FOR_EXCEPT(true);
00147
00148
00149 spmdMV->initialize(range, domain,
00150 Teuchos::arcp(localValues,0,leadingDim*epetraMV->NumVectors(),false),
00151 leadingDim);
00152
00153
00154 Teuchos::set_extra_data<RCP<Epetra_MultiVector> >(epetraMV,"Epetra_MultiVector",Teuchos::outArg(spmdMV));
00155 }
00156
00166 void identityRowIndices(const Epetra_Map & rowMap, const Epetra_CrsMatrix & mat,std::vector<int> & outIndices)
00167 {
00168 int maxSz = mat.GlobalMaxNumEntries();
00169 std::vector<double> values(maxSz);
00170 std::vector<int> indices(maxSz);
00171
00172
00173 for(int i=0;i<rowMap.NumMyElements();i++) {
00174 bool rowIsIdentity = true;
00175 int sz = 0;
00176 int rowGID = rowMap.GID(i);
00177 mat.ExtractGlobalRowCopy(rowGID,maxSz,sz,&values[0],&indices[0]);
00178
00179
00180 for(int j=0;j<sz;j++) {
00181 int colGID = indices[j];
00182
00183
00184 if(colGID==rowGID) rowIsIdentity &= values[j]==1.0;
00185 else rowIsIdentity &= values[j]==0.0;
00186
00187
00188 if(not rowIsIdentity)
00189 break;
00190 }
00191
00192
00193 if(rowIsIdentity)
00194 outIndices.push_back(rowGID);
00195 }
00196 }
00197
00208 void zeroMultiVectorRowIndices(Epetra_MultiVector & mv,const std::vector<int> & zeroIndices)
00209 {
00210 int colCnt = mv.NumVectors();
00211 std::vector<int>::const_iterator itr;
00212
00213
00214 for(itr=zeroIndices.begin();itr!=zeroIndices.end();++itr) {
00215
00216
00217 for(int j=0;j<colCnt;j++)
00218 TEUCHOS_TEST_FOR_EXCEPT(mv.ReplaceGlobalValue(*itr,j,0.0));
00219 }
00220 }
00221
00231 ZeroedOperator::ZeroedOperator(const std::vector<int> & zeroIndices,
00232 const Teuchos::RCP<const Epetra_Operator> & op)
00233 : zeroIndices_(zeroIndices), epetraOp_(op)
00234 { }
00235
00237 int ZeroedOperator::Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
00238 {
00239
00240
00241
00242
00243
00244
00245 int result = epetraOp_->Apply(X,Y);
00246
00247
00248 zeroMultiVectorRowIndices(Y,zeroIndices_);
00249
00250 return result;
00251 }
00252
00253 }
00254 }