Teko Version of the Day
Loading...
Searching...
No Matches
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// Teuchos includes
19#include "Teuchos_RCP.hpp"
20
21// Thyra includes
22#include "Thyra_LinearOpBase.hpp"
23#include "Thyra_VectorBase.hpp"
24#include "Thyra_TpetraMultiVector.hpp"
25#include "Thyra_DefaultSpmdMultiVector.hpp"
26
27// Tpetra
28#include "Tpetra_Map.hpp"
29#include "Tpetra_Vector.hpp"
30#include "Tpetra_CrsMatrix.hpp"
31
32namespace Teko {
33
34typedef Teuchos::RCP<const Thyra::LinearOpBase<ST> > LinearOp;
35typedef Teuchos::RCP<Thyra::LinearOpBase<ST> > ModifiableLinearOp;
36
37namespace TpetraHelpers {
38
48void fillDefaultSpmdMultiVector(Teuchos::RCP<Thyra::TpetraMultiVector<ST, LO, GO, NT> >& spmdMV,
49 Teuchos::RCP<Tpetra::MultiVector<ST, LO, GO, NT> >& tpetraMV);
50
61const Teuchos::RCP<const Thyra::LinearOpBase<ST> > thyraDiagOp(
62 const Teuchos::RCP<const Tpetra::Vector<ST, LO, GO, NT> >& tv,
63 const Tpetra::Map<LO, GO, NT>& map, const std::string& lbl = "ANYM");
64
75const Teuchos::RCP<Thyra::LinearOpBase<ST> > thyraDiagOp(
76 const Teuchos::RCP<Tpetra::Vector<ST, LO, GO, NT> >& tv, const Tpetra::Map<LO, GO, NT>& map,
77 const std::string& lbl = "ANYM");
78
88void identityRowIndices(const Tpetra::Map<LO, GO, NT>& rowMap,
89 const Tpetra::CrsMatrix<ST, LO, GO, NT>& mat, std::vector<GO>& outIndices);
90
101void zeroMultiVectorRowIndices(Tpetra::MultiVector<ST, LO, GO, NT>& mv,
102 const std::vector<GO>& zeroIndices);
103
106bool isTpetraLinearOp(const Teko::LinearOp& op);
107
117Teuchos::RCP<const Tpetra::CrsMatrix<ST, LO, GO, NT> > getTpetraCrsMatrix(const Teko::LinearOp& op,
118 ST* scalar, bool* transp);
119
123Teuchos::RCP<Tpetra::CrsMatrix<ST, LO, GO, NT> > materializeTpetraCrsMatrix(
124 const Teko::LinearOp& op);
125
129Teko::ModifiableLinearOp materializeTpetraLinearOp(const Teko::LinearOp& op,
130 const Teko::ModifiableLinearOp& destOp);
131
135class ZeroedOperator : public Tpetra::Operator<ST, LO, GO, NT> {
136 public:
146 ZeroedOperator(const std::vector<GO>& zeroIndices,
147 const Teuchos::RCP<const Tpetra::Operator<ST, LO, GO, NT> >& op);
148
150
151
153 virtual ~ZeroedOperator() {}
154
156 int SetUseTranspose(bool /* useTranspose */) { return -1; }
157
159 void apply(const Tpetra::MultiVector<ST, LO, GO, NT>& X, Tpetra::MultiVector<ST, LO, GO, NT>& Y,
160 Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
161 ST beta = Teuchos::ScalarTraits<ST>::zero()) const;
162
164 void applyInverse(const Tpetra::MultiVector<ST, LO, GO, NT>& /* X */,
165 Tpetra::MultiVector<ST, LO, GO, NT>& /* Y */,
166 Teuchos::ETransp /* mode */ = Teuchos::NO_TRANS,
167 ST /* alpha */ = Teuchos::ScalarTraits<ST>::one(),
168 ST /* beta */ = Teuchos::ScalarTraits<ST>::zero()) const {
169 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
170 "Can't call applyInverse on a ZeroedOperator");
171 }
172
174 double NormInf() const { return -1.0; }
175
177 bool UseTranspose() const { return false; }
178
180 bool HasNormInf() const { return false; }
181
183 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getDomainMap() const {
184 return tpetraOp_->getDomainMap();
185 }
186
188 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getRangeMap() const {
189 return tpetraOp_->getRangeMap();
190 }
191
193
194 protected:
195 std::vector<GO> zeroIndices_;
196 const Teuchos::RCP<const Tpetra::Operator<ST, LO, GO, NT> > tpetraOp_;
197};
198
199} // end namespace TpetraHelpers
200} // end namespace Teko
201
202#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.
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.