Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_PreconditionerLinearOp.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_PreconditionerLinearOp_hpp__
48 #define __Teko_PreconditionerLinearOp_hpp__
49 
50 #include "Teko_PreconditionerLinearOpDecl.hpp"
51 
52 #include "Thyra_LinearOpBase.hpp"
53 #include "Thyra_PreconditionerBase.hpp"
54 
55 namespace Teko {
56 
57 template <typename ScalarT>
58 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp() {}
59 
60 template <typename ScalarT>
61 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(
62  const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> >& prec) {
63  preconditioner_.initialize(prec);
64 }
65 
66 template <typename ScalarT>
67 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(
68  const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> >& prec) {
69  preconditioner_.initialize(prec);
70 }
71 
73 template <typename ScalarT>
75  const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> >& prec) {
76  uninitialize();
77  preconditioner_.initialize(prec);
78 }
79 
81 template <typename ScalarT>
83  const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> >& prec) {
84  uninitialize();
85  preconditioner_.initialize(prec);
86 }
87 
89 template <typename ScalarT>
91  preconditioner_.uninitialize();
92 }
93 
95 template <typename ScalarT>
96 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::range()
97  const {
98  return getOperator_cnoc()->range();
99 }
100 
102 template <typename ScalarT>
103 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::domain()
104  const {
105  return getOperator_cnoc()->domain();
106 }
107 
108 template <typename ScalarT>
109 bool PreconditionerLinearOp<ScalarT>::opSupportedImpl(const Thyra::EOpTransp M_trans) const {
110  return getOperator_cnoc()->opSupported(M_trans);
111 }
112 
113 template <typename ScalarT>
115  const Thyra::EOpTransp M_trans, const Thyra::MultiVectorBase<ScalarT>& x,
116  const Teuchos::Ptr<Thyra::MultiVectorBase<ScalarT> >& y, const ScalarT alpha,
117  const ScalarT beta) const {
118  getOperator_cnoc()->apply(M_trans, x, y, alpha, beta);
119 }
120 
122 template <typename ScalarT>
123 Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> >
125  return preconditioner_.getNonconstObj();
126 }
127 
129 template <typename ScalarT>
130 Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> >
132  return preconditioner_.getConstObj();
133 }
134 
136 template <typename ScalarT>
137 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> >
139  Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
140  oper.initialize(preconditioner_.getConstObj()->getUnspecifiedPrecOp());
141 
142  return oper;
143 }
144 
146 template <typename ScalarT>
147 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> >
149  Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
150  oper.initialize(preconditioner_.getNonconstObj()->getNonconstUnspecifiedPrecOp());
151 
152  return oper;
153 }
154 
155 template <typename ScalarT>
156 void PreconditionerLinearOp<ScalarT>::describe(Teuchos::FancyOStream& out_arg,
157  const Teuchos::EVerbosityLevel verbLevel) const {
158  using Teuchos::OSTab;
159 
160  Teuchos::RCP<Teuchos::FancyOStream> out = rcp(&out_arg, false);
161  OSTab tab0(out);
162  switch (verbLevel) {
163  case Teuchos::VERB_DEFAULT:
164  case Teuchos::VERB_LOW:
165  *out << this->description() << " ( [Operator] = " << getOperator_cnoc()->description() << " )"
166  << std::endl;
167  break;
168  case Teuchos::VERB_MEDIUM:
169  case Teuchos::VERB_HIGH:
170  case Teuchos::VERB_EXTREME: {
171  *out << Teuchos::Describable::description() << "{"
172  << "rangeDim=" << this->range()->dim() << ",domainDim=" << this->domain()->dim()
173  << "}\n";
174  {
175  OSTab tab1(out);
176  *out << "[Operator] = ";
177  *out << Teuchos::describe(*getOperator_cnoc(), verbLevel);
178  }
179  break;
180  }
181  default: TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
182  }
183 }
184 
185 inline Teko::LinearOp extractOperatorFromPrecOp(const Teko::LinearOp& lo) {
186  Teuchos::RCP<const Teko::PreconditionerLinearOp<double> > plo =
187  Teuchos::rcp_dynamic_cast<const Teko::PreconditionerLinearOp<double> >(lo);
188  if (plo != Teuchos::null)
189  return plo->getOperator();
190  else
191  return lo;
192 }
193 
194 } // end namespace Teko
195 
196 #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.