10 #include "Teko_EpetraHelpers.hpp"
13 #include "Thyra_EpetraLinearOp.hpp"
14 #include "Thyra_BlockedLinearOpBase.hpp"
15 #include "Thyra_DefaultMultipliedLinearOp.hpp"
16 #include "Thyra_DefaultDiagonalLinearOp.hpp"
17 #include "Thyra_DefaultZeroLinearOp.hpp"
18 #include "Thyra_DefaultBlockedLinearOp.hpp"
19 #include "Thyra_EpetraThyraWrappers.hpp"
20 #include "Thyra_SpmdVectorBase.hpp"
21 #include "Thyra_SpmdVectorSpaceBase.hpp"
22 #include "Thyra_ScalarProdVectorSpaceBase.hpp"
25 #include "Epetra_Vector.h"
28 #include "EpetraExt_ProductOperator.h"
29 #include "EpetraExt_MatrixMatrix.h"
32 #include "Teko_EpetraOperatorWrapper.hpp"
38 using Teuchos::rcp_dynamic_cast;
39 using Teuchos::rcpFromRef;
54 const Teuchos::RCP<const Thyra::LinearOpBase<double> > thyraDiagOp(
55 const RCP<const Epetra_Vector>& ev,
const Epetra_Map& map,
const std::string& lbl) {
56 const RCP<const Thyra::VectorBase<double> > thyraVec
57 = Thyra::create_Vector(ev, Thyra::create_VectorSpace(rcpFromRef(map)));
58 Teuchos::RCP<Thyra::LinearOpBase<double> > op =
59 Teuchos::rcp(
new Thyra::DefaultDiagonalLinearOp<double>(thyraVec));
60 op->setObjectLabel(lbl);
74 const Teuchos::RCP<Thyra::LinearOpBase<double> > thyraDiagOp(
const RCP<Epetra_Vector>& ev,
75 const Epetra_Map& map,
76 const std::string& lbl) {
77 const RCP<Thyra::VectorBase<double> > thyraVec
78 = Thyra::create_Vector(ev, Thyra::create_VectorSpace(rcpFromRef(map)));
79 Teuchos::RCP<Thyra::LinearOpBase<double> > op =
80 Teuchos::rcp(
new Thyra::DefaultDiagonalLinearOp<double>(thyraVec));
81 op->setObjectLabel(lbl);
94 void fillDefaultSpmdMultiVector(Teuchos::RCP<Thyra::DefaultSpmdMultiVector<double> >& spmdMV,
95 Teuchos::RCP<Epetra_MultiVector>& epetraMV) {
97 const RCP<const Thyra::SpmdVectorSpaceBase<double> > range = spmdMV->spmdSpace();
98 const RCP<const Thyra::ScalarProdVectorSpaceBase<double> > domain =
99 rcp_dynamic_cast<
const Thyra::ScalarProdVectorSpaceBase<double> >(spmdMV->domain());
101 TEUCHOS_ASSERT(domain->dim() == epetraMV->NumVectors());
106 if (epetraMV->ConstantStride())
107 epetraMV->ExtractView(&localValues, &leadingDim);
109 TEUCHOS_TEST_FOR_EXCEPT(
true);
112 spmdMV->initialize(range, domain,
113 Teuchos::arcp(localValues, 0, leadingDim * epetraMV->NumVectors(),
false),
117 Teuchos::set_extra_data<RCP<Epetra_MultiVector> >(epetraMV,
"Epetra_MultiVector",
118 Teuchos::outArg(spmdMV));
130 void identityRowIndices(
const Epetra_Map& rowMap,
const Epetra_CrsMatrix& mat,
131 std::vector<int>& outIndices) {
132 int maxSz = mat.GlobalMaxNumEntries();
133 std::vector<double> values(maxSz);
134 std::vector<int> indices(maxSz);
137 for (
int i = 0; i < rowMap.NumMyElements(); i++) {
138 bool rowIsIdentity =
true;
140 int rowGID = rowMap.GID(i);
141 mat.ExtractGlobalRowCopy(rowGID, maxSz, sz, &values[0], &indices[0]);
144 for (
int j = 0; j < sz; j++) {
145 int colGID = indices[j];
148 if (colGID == rowGID)
149 rowIsIdentity &= values[j] == 1.0;
151 rowIsIdentity &= values[j] == 0.0;
154 if (not rowIsIdentity)
break;
158 if (rowIsIdentity) outIndices.push_back(rowGID);
172 void zeroMultiVectorRowIndices(Epetra_MultiVector& mv,
const std::vector<int>& zeroIndices) {
173 int colCnt = mv.NumVectors();
174 std::vector<int>::const_iterator itr;
177 for (itr = zeroIndices.begin(); itr != zeroIndices.end(); ++itr) {
179 for (
int j = 0; j < colCnt; j++) TEUCHOS_TEST_FOR_EXCEPT(mv.ReplaceGlobalValue(*itr, j, 0.0));
193 const Teuchos::RCP<const Epetra_Operator>& op)
194 : zeroIndices_(zeroIndices), epetraOp_(op) {
195 label_ =
"zeroed( " + std::string(epetraOp_->Label()) +
" )";
206 int result = epetraOp_->Apply(X, Y);
209 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.