Teko  Version of the Day
 All Classes Files Functions Variables Pages
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 
18 namespace Teko {
19 
20 template <typename ScalarT>
21 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp() {}
22 
23 template <typename ScalarT>
24 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(
25  const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> >& prec) {
26  preconditioner_.initialize(prec);
27 }
28 
29 template <typename ScalarT>
30 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(
31  const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> >& prec) {
32  preconditioner_.initialize(prec);
33 }
34 
36 template <typename ScalarT>
38  const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> >& prec) {
39  uninitialize();
40  preconditioner_.initialize(prec);
41 }
42 
44 template <typename ScalarT>
46  const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> >& prec) {
47  uninitialize();
48  preconditioner_.initialize(prec);
49 }
50 
52 template <typename ScalarT>
54  preconditioner_.uninitialize();
55 }
56 
58 template <typename ScalarT>
59 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::range()
60  const {
61  return getOperator_cnoc()->range();
62 }
63 
65 template <typename ScalarT>
66 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::domain()
67  const {
68  return getOperator_cnoc()->domain();
69 }
70 
71 template <typename ScalarT>
72 bool PreconditionerLinearOp<ScalarT>::opSupportedImpl(const Thyra::EOpTransp M_trans) const {
73  return getOperator_cnoc()->opSupported(M_trans);
74 }
75 
76 template <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 
85 template <typename ScalarT>
86 Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> >
88  return preconditioner_.getNonconstObj();
89 }
90 
92 template <typename ScalarT>
93 Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> >
95  return preconditioner_.getConstObj();
96 }
97 
99 template <typename ScalarT>
100 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> >
102  Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
103  oper.initialize(preconditioner_.getConstObj()->getUnspecifiedPrecOp());
104 
105  return oper;
106 }
107 
109 template <typename ScalarT>
110 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> >
112  Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
113  oper.initialize(preconditioner_.getNonconstObj()->getNonconstUnspecifiedPrecOp());
114 
115  return oper;
116 }
117 
118 template <typename ScalarT>
119 void 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 
148 inline 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
void initialize(const Teuchos::RCP< Thyra::PreconditionerBase< ScalarT > > &prec)
build a linear operator using this preconditioner, this initialization permits changes ...
virtual Teuchos::RCP< Thyra::PreconditionerBase< ScalarT > > getNonconstPreconditioner()
Get a nonconstant PreconditionerBase object.
void uninitialize()
Disassociate this object with the currently owned preconditioner.
Teko::LinearOp getOperator() const
Get teko linear 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.
virtual Teuchos::RCP< const Thyra::PreconditionerBase< ScalarT > > getPreconditioner() const
Get a constant PreconditionerBase object.
Teuchos::ConstNonconstObjectContainer< Thyra::LinearOpBase< ScalarT > > getOperator_cnoc() const
get operator associated with the preconditioner
Class that wraps a PreconditionerBase object it makes it behave like a linear operator.
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > range() const
Range space of this operator.
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > domain() const
Domain space of this operator.