47 #include "Teko_EpetraHelpers.hpp"
50 #include "Thyra_EpetraLinearOp.hpp"
51 #include "Thyra_BlockedLinearOpBase.hpp"
52 #include "Thyra_DefaultMultipliedLinearOp.hpp"
53 #include "Thyra_DefaultDiagonalLinearOp.hpp"
54 #include "Thyra_DefaultZeroLinearOp.hpp"
55 #include "Thyra_DefaultBlockedLinearOp.hpp"
56 #include "Thyra_EpetraThyraWrappers.hpp"
57 #include "Thyra_SpmdVectorBase.hpp"
58 #include "Thyra_SpmdVectorSpaceBase.hpp"
59 #include "Thyra_ScalarProdVectorSpaceBase.hpp"
62 #include "Epetra_Vector.h"
65 #include "EpetraExt_ProductOperator.h"
66 #include "EpetraExt_MatrixMatrix.h"
69 #include "Teko_EpetraOperatorWrapper.hpp"
74 using Teuchos::rcpFromRef;
75 using Teuchos::rcp_dynamic_cast;
91 const Teuchos::RCP<const Thyra::LinearOpBase<double> > thyraDiagOp(
const RCP<const Epetra_Vector> & ev,
const Epetra_Map & map,
92 const std::string & lbl)
94 const RCP<const Thyra::VectorBase<double> > thyraVec
95 = Thyra::create_Vector(ev,Thyra::create_VectorSpace(rcpFromRef(map)));
96 Teuchos::RCP<Thyra::LinearOpBase<double> > op
97 = Teuchos::rcp(
new Thyra::DefaultDiagonalLinearOp<double>(thyraVec));
98 op->setObjectLabel(lbl);
112 const Teuchos::RCP<Thyra::LinearOpBase<double> > thyraDiagOp(
const RCP<Epetra_Vector> & ev,
const Epetra_Map & map,
113 const std::string & lbl)
115 const RCP<Thyra::VectorBase<double> > thyraVec
116 = Thyra::create_Vector(ev,Thyra::create_VectorSpace(rcpFromRef(map)));
117 Teuchos::RCP<Thyra::LinearOpBase<double> > op
118 = Teuchos::rcp(
new Thyra::DefaultDiagonalLinearOp<double>(thyraVec));
119 op->setObjectLabel(lbl);
132 void fillDefaultSpmdMultiVector(Teuchos::RCP<Thyra::DefaultSpmdMultiVector<double> > & spmdMV,
133 Teuchos::RCP<Epetra_MultiVector> & epetraMV)
136 const RCP<const Thyra::SpmdVectorSpaceBase<double> > range = spmdMV->spmdSpace();
137 const RCP<const Thyra::ScalarProdVectorSpaceBase<double> > domain
138 = rcp_dynamic_cast<
const Thyra::ScalarProdVectorSpaceBase<double> >(spmdMV->domain());
140 TEUCHOS_ASSERT(domain->dim()==epetraMV->NumVectors());
143 double *localValues;
int leadingDim;
144 if(epetraMV->ConstantStride() )
145 epetraMV->ExtractView( &localValues, &leadingDim );
147 TEUCHOS_TEST_FOR_EXCEPT(
true);
150 spmdMV->initialize(range, domain,
151 Teuchos::arcp(localValues,0,leadingDim*epetraMV->NumVectors(),
false),
155 Teuchos::set_extra_data<RCP<Epetra_MultiVector> >(epetraMV,
"Epetra_MultiVector",Teuchos::outArg(spmdMV));
167 void identityRowIndices(
const Epetra_Map & rowMap,
const Epetra_CrsMatrix & mat,std::vector<int> & outIndices)
169 int maxSz = mat.GlobalMaxNumEntries();
170 std::vector<double> values(maxSz);
171 std::vector<int> indices(maxSz);
174 for(
int i=0;i<rowMap.NumMyElements();i++) {
175 bool rowIsIdentity =
true;
177 int rowGID = rowMap.GID(i);
178 mat.ExtractGlobalRowCopy(rowGID,maxSz,sz,&values[0],&indices[0]);
181 for(
int j=0;j<sz;j++) {
182 int colGID = indices[j];
185 if(colGID==rowGID) rowIsIdentity &= values[j]==1.0;
186 else rowIsIdentity &= values[j]==0.0;
189 if(not rowIsIdentity)
195 outIndices.push_back(rowGID);
209 void zeroMultiVectorRowIndices(Epetra_MultiVector & mv,
const std::vector<int> & zeroIndices)
211 int colCnt = mv.NumVectors();
212 std::vector<int>::const_iterator itr;
215 for(itr=zeroIndices.begin();itr!=zeroIndices.end();++itr) {
218 for(
int j=0;j<colCnt;j++)
219 TEUCHOS_TEST_FOR_EXCEPT(mv.ReplaceGlobalValue(*itr,j,0.0));
233 const Teuchos::RCP<const Epetra_Operator> & op)
234 : zeroIndices_(zeroIndices), epetraOp_(op)
246 int result = epetraOp_->Apply(X,Y);
249 zeroMultiVectorRowIndices(Y,zeroIndices_);
ZeroedOperator(const std::vector< int > &zeroIndices, const Teuchos::RCP< const Epetra_Operator > &op)
Constructor for a ZeroedOperator.
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Perform a matrix-vector product with certain rows zeroed out.