Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_TpetraHelpers.hpp
1 /*
2 // @HEADER
3 //
4 // ***********************************************************************
5 //
6 // Teko: A package for block and physics based preconditioning
7 // Copyright 2010 Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
40 //
41 // ***********************************************************************
42 //
43 // @HEADER
44 
45 */
46 
47 #ifndef __Teko_TpetraHelpers_hpp__
48 #define __Teko_TpetraHelpers_hpp__
49 
50 // stl includes
51 #include <string>
52 
53 #include "Teko_ConfigDefs.hpp"
54 
55 #ifdef TEKO_HAVE_EPETRA
56 // Epetra includes
57 #include "Epetra_Operator.h"
58 #include "Epetra_CrsMatrix.h"
59 #include "Epetra_MultiVector.h"
60 #endif
61 
62 // Teuchos includes
63 #include "Teuchos_RCP.hpp"
64 
65 // Thyra includes
66 #include "Thyra_VectorBase.hpp"
67 #include "Thyra_TpetraMultiVector.hpp"
68 #include "Thyra_DefaultSpmdMultiVector.hpp"
69 
70 // Tpetra
71 #include "Tpetra_Map.hpp"
72 #include "Tpetra_Vector.hpp"
73 #include "Tpetra_CrsMatrix.hpp"
74 
75 namespace Teko {
76 
77 typedef Teuchos::RCP<const Thyra::LinearOpBase<double> > LinearOp;
78 
79 namespace TpetraHelpers {
80 
90 void fillDefaultSpmdMultiVector(Teuchos::RCP<Thyra::TpetraMultiVector<ST, LO, GO, NT> >& spmdMV,
91  Teuchos::RCP<Tpetra::MultiVector<ST, LO, GO, NT> >& tpetraMV);
92 
103 const Teuchos::RCP<const Thyra::LinearOpBase<ST> > thyraDiagOp(
104  const Teuchos::RCP<const Tpetra::Vector<ST, LO, GO, NT> >& tv,
105  const Tpetra::Map<LO, GO, NT>& map, const std::string& lbl = "ANYM");
106 
117 const Teuchos::RCP<Thyra::LinearOpBase<ST> > thyraDiagOp(
118  const Teuchos::RCP<Tpetra::Vector<ST, LO, GO, NT> >& tv, const Tpetra::Map<LO, GO, NT>& map,
119  const std::string& lbl = "ANYM");
120 
130 void identityRowIndices(const Tpetra::Map<LO, GO, NT>& rowMap,
131  const Tpetra::CrsMatrix<ST, LO, GO, NT>& mat, std::vector<GO>& outIndices);
132 
143 void zeroMultiVectorRowIndices(Tpetra::MultiVector<ST, LO, GO, NT>& mv,
144  const std::vector<GO>& zeroIndices);
145 
148 bool isTpetraLinearOp(const Teko::LinearOp& op);
149 
159 Teuchos::RCP<const Tpetra::CrsMatrix<ST, LO, GO, NT> > getTpetraCrsMatrix(const Teko::LinearOp& op,
160  ST* scalar, bool* transp);
161 
162 #ifdef TEKO_HAVE_EPETRA
163 
171 Teuchos::RCP<const Tpetra::CrsMatrix<ST, LO, GO, NT> > epetraCrsMatrixToTpetra(
172  const Teuchos::RCP<const Epetra_CrsMatrix> A_e,
173  const Teuchos::RCP<const Teuchos::Comm<int> > comm);
174 
175 Teuchos::RCP<Tpetra::CrsMatrix<ST, LO, GO, NT> > nonConstEpetraCrsMatrixToTpetra(
176  const Teuchos::RCP<Epetra_CrsMatrix> A_e, const Teuchos::RCP<const Teuchos::Comm<int> > comm);
177 
178 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > epetraMapToTpetra(
179  const Epetra_Map eMap, const Teuchos::RCP<const Teuchos::Comm<int> > comm);
180 #endif // TEKO_HAVE_EPETRA
181 
185 class ZeroedOperator : public Tpetra::Operator<ST, LO, GO, NT> {
186  public:
196  ZeroedOperator(const std::vector<GO>& zeroIndices,
197  const Teuchos::RCP<const Tpetra::Operator<ST, LO, GO, NT> >& op);
198 
200 
201 
203  virtual ~ZeroedOperator() {}
204 
206  int SetUseTranspose(bool /* useTranspose */) { return -1; }
207 
209  void apply(const Tpetra::MultiVector<ST, LO, GO, NT>& X, Tpetra::MultiVector<ST, LO, GO, NT>& Y,
210  Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
211  ST beta = Teuchos::ScalarTraits<ST>::zero()) const;
212 
214  void applyInverse(const Tpetra::MultiVector<ST, LO, GO, NT>& /* X */,
215  Tpetra::MultiVector<ST, LO, GO, NT>& /* Y */,
216  Teuchos::ETransp /* mode */ = Teuchos::NO_TRANS,
217  ST /* alpha */ = Teuchos::ScalarTraits<ST>::one(),
218  ST /* beta */ = Teuchos::ScalarTraits<ST>::zero()) const {
219  TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
220  "Can't call applyInverse on a ZeroedOperator");
221  }
222 
224  double NormInf() const { return -1.0; }
225 
227  bool UseTranspose() const { return false; }
228 
230  bool HasNormInf() const { return false; }
231 
233  Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getDomainMap() const {
234  return tpetraOp_->getDomainMap();
235  }
236 
238  Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getRangeMap() const {
239  return tpetraOp_->getRangeMap();
240  }
241 
243 
244  protected:
245  std::vector<GO> zeroIndices_;
246  const Teuchos::RCP<const Tpetra::Operator<ST, LO, GO, NT> > tpetraOp_;
247 };
248 
249 } // end namespace TpetraHelpers
250 } // end namespace Teko
251 
252 #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.