Teko Version of the Day
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// Epetra includes
54#include "Epetra_Operator.h"
55#include "Epetra_CrsMatrix.h"
56#include "Epetra_MultiVector.h"
57
58// Teuchos includes
59#include "Teuchos_RCP.hpp"
60
61// Thyra includes
62#include "Thyra_VectorBase.hpp"
63#include "Thyra_TpetraMultiVector.hpp"
64#include "Thyra_DefaultSpmdMultiVector.hpp"
65
66// Tpetra
67#include "Teko_ConfigDefs.hpp"
68#include "Tpetra_Map.hpp"
69#include "Tpetra_Vector.hpp"
70#include "Tpetra_CrsMatrix.hpp"
71
72namespace Teko {
73
74typedef Teuchos::RCP<const Thyra::LinearOpBase<double> > LinearOp;
75
76namespace TpetraHelpers {
77
87void fillDefaultSpmdMultiVector(Teuchos::RCP<Thyra::TpetraMultiVector<ST,LO,GO,NT> > & spmdMV,
88 Teuchos::RCP<Tpetra::MultiVector<ST,LO,GO,NT> > & tpetraMV);
89
100const Teuchos::RCP<const Thyra::LinearOpBase<ST> > thyraDiagOp(const Teuchos::RCP<const Tpetra::Vector<ST,LO,GO,NT> > & tv,
101 const Tpetra::Map<LO,GO,NT> & map,const std::string & lbl="ANYM");
102
113const Teuchos::RCP<Thyra::LinearOpBase<ST> > thyraDiagOp(const Teuchos::RCP<Tpetra::Vector<ST,LO,GO,NT> > & tv,
114 const Tpetra::Map<LO,GO,NT> & map,const std::string & lbl="ANYM");
115
125void identityRowIndices(const Tpetra::Map<LO,GO,NT> & rowMap, const Tpetra::CrsMatrix<ST,LO,GO,NT> & mat,std::vector<GO> & outIndices);
126
137void zeroMultiVectorRowIndices(Tpetra::MultiVector<ST,LO,GO,NT> & mv,const std::vector<GO> & zeroIndices);
138
141bool isTpetraLinearOp(const Teko::LinearOp & op);
142
151Teuchos::RCP<const Tpetra::CrsMatrix<ST,LO,GO,NT> > getTpetraCrsMatrix(const Teko::LinearOp & op, ST *scalar, bool *transp);
152
160Teuchos::RCP<const Tpetra::CrsMatrix<ST,LO,GO,NT> > epetraCrsMatrixToTpetra(const Teuchos::RCP<const Epetra_CrsMatrix> A_e, const Teuchos::RCP<const Teuchos::Comm<int> > comm);
161
162Teuchos::RCP<Tpetra::CrsMatrix<ST,LO,GO,NT> > nonConstEpetraCrsMatrixToTpetra(const Teuchos::RCP<Epetra_CrsMatrix> A_e, const Teuchos::RCP<const Teuchos::Comm<int> > comm);
163
164Teuchos::RCP<const Tpetra::Map<LO,GO,NT> > epetraMapToTpetra(const Epetra_Map eMap, const Teuchos::RCP<const Teuchos::Comm<int> > comm);
165
169class ZeroedOperator : public Tpetra::Operator<ST,LO,GO,NT> {
170public:
180 ZeroedOperator(const std::vector<GO> & zeroIndices,const Teuchos::RCP<const Tpetra::Operator<ST,LO,GO,NT> > & op);
181
183
184
186 virtual ~ZeroedOperator() {}
187
189 int SetUseTranspose(bool /* useTranspose */ ) { return -1;}
190
192 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;
193
195 void applyInverse(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
196 { TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"Can't call applyInverse on a ZeroedOperator"); }
197
199 double NormInf() const { return -1.0; }
200
202 bool UseTranspose() const {return false;}
203
205 bool HasNormInf() const {return false;}
206
208 Teuchos::RCP<const Tpetra::Map<LO,GO,NT> > getDomainMap() const {return tpetraOp_->getDomainMap(); }
209
211 Teuchos::RCP<const Tpetra::Map<LO,GO,NT> > getRangeMap() const {return tpetraOp_->getRangeMap(); }
212
214
215protected:
216 std::vector<GO> zeroIndices_;
217 const Teuchos::RCP<const Tpetra::Operator<ST,LO,GO,NT> > tpetraOp_;
218};
219
220} // end namespace TpetraHelpers
221} // end namespace Teko
222
223#endif
int SetUseTranspose(bool)
Can't transpose a ZeroedOperator.
virtual ~ZeroedOperator()
Do nothing destructor.
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.
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't call ApplyInverse on a zeroed operator.