Teko Version of the Day
Loading...
Searching...
No Matches
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
75namespace Teko {
76
77typedef Teuchos::RCP<const Thyra::LinearOpBase<double> > LinearOp;
78
79namespace TpetraHelpers {
80
90void fillDefaultSpmdMultiVector(Teuchos::RCP<Thyra::TpetraMultiVector<ST,LO,GO,NT> > & spmdMV,
91 Teuchos::RCP<Tpetra::MultiVector<ST,LO,GO,NT> > & tpetraMV);
92
103const Teuchos::RCP<const Thyra::LinearOpBase<ST> > thyraDiagOp(const Teuchos::RCP<const Tpetra::Vector<ST,LO,GO,NT> > & tv,
104 const Tpetra::Map<LO,GO,NT> & map,const std::string & lbl="ANYM");
105
116const Teuchos::RCP<Thyra::LinearOpBase<ST> > thyraDiagOp(const Teuchos::RCP<Tpetra::Vector<ST,LO,GO,NT> > & tv,
117 const Tpetra::Map<LO,GO,NT> & map,const std::string & lbl="ANYM");
118
128void identityRowIndices(const Tpetra::Map<LO,GO,NT> & rowMap, const Tpetra::CrsMatrix<ST,LO,GO,NT> & mat,std::vector<GO> & outIndices);
129
140void zeroMultiVectorRowIndices(Tpetra::MultiVector<ST,LO,GO,NT> & mv,const std::vector<GO> & zeroIndices);
141
144bool isTpetraLinearOp(const Teko::LinearOp & op);
145
154Teuchos::RCP<const Tpetra::CrsMatrix<ST,LO,GO,NT> > getTpetraCrsMatrix(const Teko::LinearOp & op, ST *scalar, bool *transp);
155
156#ifdef TEKO_HAVE_EPETRA
164Teuchos::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);
165
166Teuchos::RCP<Tpetra::CrsMatrix<ST,LO,GO,NT> > nonConstEpetraCrsMatrixToTpetra(const Teuchos::RCP<Epetra_CrsMatrix> A_e, const Teuchos::RCP<const Teuchos::Comm<int> > comm);
167
168Teuchos::RCP<const Tpetra::Map<LO,GO,NT> > epetraMapToTpetra(const Epetra_Map eMap, const Teuchos::RCP<const Teuchos::Comm<int> > comm);
169#endif // TEKO_HAVE_EPETRA
170
174class ZeroedOperator : public Tpetra::Operator<ST,LO,GO,NT> {
175public:
185 ZeroedOperator(const std::vector<GO> & zeroIndices,const Teuchos::RCP<const Tpetra::Operator<ST,LO,GO,NT> > & op);
186
188
189
191 virtual ~ZeroedOperator() {}
192
194 int SetUseTranspose(bool /* useTranspose */ ) { return -1;}
195
197 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;
198
200 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
201 { TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"Can't call applyInverse on a ZeroedOperator"); }
202
204 double NormInf() const { return -1.0; }
205
207 bool UseTranspose() const {return false;}
208
210 bool HasNormInf() const {return false;}
211
213 Teuchos::RCP<const Tpetra::Map<LO,GO,NT> > getDomainMap() const {return tpetraOp_->getDomainMap(); }
214
216 Teuchos::RCP<const Tpetra::Map<LO,GO,NT> > getRangeMap() const {return tpetraOp_->getRangeMap(); }
217
219
220protected:
221 std::vector<GO> zeroIndices_;
222 const Teuchos::RCP<const Tpetra::Operator<ST,LO,GO,NT> > tpetraOp_;
223};
224
225} // end namespace TpetraHelpers
226} // end namespace Teko
227
228#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.