Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_TpetraHelpers.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Teko: A package for block and physics based preconditioning
4 //
5 // Copyright 2010 NTESS and the Teko contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef __Teko_TpetraHelpers_hpp__
11 #define __Teko_TpetraHelpers_hpp__
12 
13 // stl includes
14 #include <string>
15 
16 #include "Teko_ConfigDefs.hpp"
17 
18 #ifdef TEKO_HAVE_EPETRA
19 // Epetra includes
20 #include "Epetra_Operator.h"
21 #include "Epetra_CrsMatrix.h"
22 #include "Epetra_MultiVector.h"
23 #endif
24 
25 // Teuchos includes
26 #include "Teuchos_RCP.hpp"
27 
28 // Thyra includes
29 #include "Thyra_VectorBase.hpp"
30 #include "Thyra_TpetraMultiVector.hpp"
31 #include "Thyra_DefaultSpmdMultiVector.hpp"
32 
33 // Tpetra
34 #include "Tpetra_Map.hpp"
35 #include "Tpetra_Vector.hpp"
36 #include "Tpetra_CrsMatrix.hpp"
37 
38 namespace Teko {
39 
40 typedef Teuchos::RCP<const Thyra::LinearOpBase<double> > LinearOp;
41 
42 namespace TpetraHelpers {
43 
53 void fillDefaultSpmdMultiVector(Teuchos::RCP<Thyra::TpetraMultiVector<ST, LO, GO, NT> >& spmdMV,
54  Teuchos::RCP<Tpetra::MultiVector<ST, LO, GO, NT> >& tpetraMV);
55 
66 const Teuchos::RCP<const Thyra::LinearOpBase<ST> > thyraDiagOp(
67  const Teuchos::RCP<const Tpetra::Vector<ST, LO, GO, NT> >& tv,
68  const Tpetra::Map<LO, GO, NT>& map, const std::string& lbl = "ANYM");
69 
80 const Teuchos::RCP<Thyra::LinearOpBase<ST> > thyraDiagOp(
81  const Teuchos::RCP<Tpetra::Vector<ST, LO, GO, NT> >& tv, const Tpetra::Map<LO, GO, NT>& map,
82  const std::string& lbl = "ANYM");
83 
93 void identityRowIndices(const Tpetra::Map<LO, GO, NT>& rowMap,
94  const Tpetra::CrsMatrix<ST, LO, GO, NT>& mat, std::vector<GO>& outIndices);
95 
106 void zeroMultiVectorRowIndices(Tpetra::MultiVector<ST, LO, GO, NT>& mv,
107  const std::vector<GO>& zeroIndices);
108 
111 bool isTpetraLinearOp(const Teko::LinearOp& op);
112 
122 Teuchos::RCP<const Tpetra::CrsMatrix<ST, LO, GO, NT> > getTpetraCrsMatrix(const Teko::LinearOp& op,
123  ST* scalar, bool* transp);
124 
125 #ifdef TEKO_HAVE_EPETRA
126 
134 Teuchos::RCP<const Tpetra::CrsMatrix<ST, LO, GO, NT> > epetraCrsMatrixToTpetra(
135  const Teuchos::RCP<const Epetra_CrsMatrix> A_e,
136  const Teuchos::RCP<const Teuchos::Comm<int> > comm);
137 
138 Teuchos::RCP<Tpetra::CrsMatrix<ST, LO, GO, NT> > nonConstEpetraCrsMatrixToTpetra(
139  const Teuchos::RCP<Epetra_CrsMatrix> A_e, const Teuchos::RCP<const Teuchos::Comm<int> > comm);
140 
141 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > epetraMapToTpetra(
142  const Epetra_Map eMap, const Teuchos::RCP<const Teuchos::Comm<int> > comm);
143 #endif // TEKO_HAVE_EPETRA
144 
148 class ZeroedOperator : public Tpetra::Operator<ST, LO, GO, NT> {
149  public:
159  ZeroedOperator(const std::vector<GO>& zeroIndices,
160  const Teuchos::RCP<const Tpetra::Operator<ST, LO, GO, NT> >& op);
161 
163 
164 
166  virtual ~ZeroedOperator() {}
167 
169  int SetUseTranspose(bool /* useTranspose */) { return -1; }
170 
172  void apply(const Tpetra::MultiVector<ST, LO, GO, NT>& X, Tpetra::MultiVector<ST, LO, GO, NT>& Y,
173  Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
174  ST beta = Teuchos::ScalarTraits<ST>::zero()) const;
175 
177  void applyInverse(const Tpetra::MultiVector<ST, LO, GO, NT>& /* X */,
178  Tpetra::MultiVector<ST, LO, GO, NT>& /* Y */,
179  Teuchos::ETransp /* mode */ = Teuchos::NO_TRANS,
180  ST /* alpha */ = Teuchos::ScalarTraits<ST>::one(),
181  ST /* beta */ = Teuchos::ScalarTraits<ST>::zero()) const {
182  TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
183  "Can't call applyInverse on a ZeroedOperator");
184  }
185 
187  double NormInf() const { return -1.0; }
188 
190  bool UseTranspose() const { return false; }
191 
193  bool HasNormInf() const { return false; }
194 
196  Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getDomainMap() const {
197  return tpetraOp_->getDomainMap();
198  }
199 
201  Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getRangeMap() const {
202  return tpetraOp_->getRangeMap();
203  }
204 
206 
207  protected:
208  std::vector<GO> zeroIndices_;
209  const Teuchos::RCP<const Tpetra::Operator<ST, LO, GO, NT> > tpetraOp_;
210 };
211 
212 } // end namespace TpetraHelpers
213 } // end namespace Teko
214 
215 #endif
void apply(const Tpetra::MultiVector< ST, LO, GO, NT > &X, Tpetra::MultiVector< ST, LO, GO, NT > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, ST alpha=Teuchos::ScalarTraits< ST >::one(), ST beta=Teuchos::ScalarTraits< ST >::zero()) const
Perform a matrix-vector product with certain rows zeroed out.
int SetUseTranspose(bool)
Can&#39;t transpose a ZeroedOperator.
ZeroedOperator(const std::vector< GO > &zeroIndices, const Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > &op)
Constructor for a ZeroedOperator.
void applyInverse(const Tpetra::MultiVector< ST, LO, GO, NT > &, Tpetra::MultiVector< ST, LO, GO, NT > &, Teuchos::ETransp=Teuchos::NO_TRANS, ST=Teuchos::ScalarTraits< ST >::one(), ST=Teuchos::ScalarTraits< ST >::zero()) const
Can&#39;t call ApplyInverse on a zeroed operator.
virtual ~ZeroedOperator()
Do nothing destructor.