Teko Version of the Day
Loading...
Searching...
No Matches
Teko_PreconditionerLinearOp.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_PreconditionerLinearOp_hpp__
11#define __Teko_PreconditionerLinearOp_hpp__
12
13#include "Teko_PreconditionerLinearOpDecl.hpp"
14
15#include "Thyra_LinearOpBase.hpp"
16#include "Thyra_PreconditionerBase.hpp"
17
18namespace Teko {
19
20template <typename ScalarT>
21PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp() {}
22
23template <typename ScalarT>
24PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(
25 const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> >& prec) {
26 preconditioner_.initialize(prec);
27}
28
29template <typename ScalarT>
30PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(
31 const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> >& prec) {
32 preconditioner_.initialize(prec);
33}
34
36template <typename ScalarT>
38 const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> >& prec) {
40 preconditioner_.initialize(prec);
41}
42
44template <typename ScalarT>
46 const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> >& prec) {
48 preconditioner_.initialize(prec);
49}
50
52template <typename ScalarT>
54 preconditioner_.uninitialize();
55}
56
58template <typename ScalarT>
59Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::range()
60 const {
61 return getOperator_cnoc()->range();
62}
63
65template <typename ScalarT>
66Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::domain()
67 const {
68 return getOperator_cnoc()->domain();
69}
70
71template <typename ScalarT>
72bool PreconditionerLinearOp<ScalarT>::opSupportedImpl(const Thyra::EOpTransp M_trans) const {
73 return getOperator_cnoc()->opSupported(M_trans);
74}
75
76template <typename ScalarT>
78 const Thyra::EOpTransp M_trans, const Thyra::MultiVectorBase<ScalarT>& x,
79 const Teuchos::Ptr<Thyra::MultiVectorBase<ScalarT> >& y, const ScalarT alpha,
80 const ScalarT beta) const {
81 getOperator_cnoc()->apply(M_trans, x, y, alpha, beta);
82}
83
85template <typename ScalarT>
86Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> >
88 return preconditioner_.getNonconstObj();
89}
90
92template <typename ScalarT>
93Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> >
95 return preconditioner_.getConstObj();
96}
97
99template <typename ScalarT>
100Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> >
102 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
103 oper.initialize(preconditioner_.getConstObj()->getUnspecifiedPrecOp());
104
105 return oper;
106}
107
109template <typename ScalarT>
110Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> >
112 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
113 oper.initialize(preconditioner_.getNonconstObj()->getNonconstUnspecifiedPrecOp());
114
115 return oper;
116}
117
118template <typename ScalarT>
119void PreconditionerLinearOp<ScalarT>::describe(Teuchos::FancyOStream& out_arg,
120 const Teuchos::EVerbosityLevel verbLevel) const {
121 using Teuchos::OSTab;
122
123 Teuchos::RCP<Teuchos::FancyOStream> out = rcp(&out_arg, false);
124 OSTab tab0(out);
125 switch (verbLevel) {
126 case Teuchos::VERB_DEFAULT:
127 case Teuchos::VERB_LOW:
128 *out << this->description() << " ( [Operator] = " << getOperator_cnoc()->description() << " )"
129 << std::endl;
130 break;
131 case Teuchos::VERB_MEDIUM:
132 case Teuchos::VERB_HIGH:
133 case Teuchos::VERB_EXTREME: {
134 *out << Teuchos::Describable::description() << "{"
135 << "rangeDim=" << this->range()->dim() << ",domainDim=" << this->domain()->dim()
136 << "}\n";
137 {
138 OSTab tab1(out);
139 *out << "[Operator] = ";
140 *out << Teuchos::describe(*getOperator_cnoc(), verbLevel);
141 }
142 break;
143 }
144 default: TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
145 }
146}
147
148inline Teko::LinearOp extractOperatorFromPrecOp(const Teko::LinearOp& lo) {
149 Teuchos::RCP<const Teko::PreconditionerLinearOp<double> > plo =
150 Teuchos::rcp_dynamic_cast<const Teko::PreconditionerLinearOp<double> >(lo);
151 if (plo != Teuchos::null)
152 return plo->getOperator();
153 else
154 return lo;
155}
156
157} // end namespace Teko
158
159#endif
virtual Teuchos::RCP< const Thyra::PreconditionerBase< ScalarT > > getPreconditioner() const
Get a constant PreconditionerBase object.
virtual Teuchos::RCP< Thyra::PreconditionerBase< ScalarT > > getNonconstPreconditioner()
Get a nonconstant PreconditionerBase object.
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > range() const
Range space of this operator.
void initialize(const Teuchos::RCP< Thyra::PreconditionerBase< ScalarT > > &prec)
build a linear operator using this preconditioner, this initialization permits changes
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > domain() const
Domain space of this operator.
virtual void applyImpl(const Thyra::EOpTransp M_trans, const Thyra::MultiVectorBase< ScalarT > &x, const Teuchos::Ptr< Thyra::MultiVectorBase< ScalarT > > &y, const ScalarT alpha, const ScalarT beta) const
Apply operation.
void uninitialize()
Disassociate this object with the currently owned preconditioner.
Teuchos::ConstNonconstObjectContainer< Thyra::LinearOpBase< ScalarT > > getOperator_cnoc() const
get operator associated with the preconditioner