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 
61 template <typename ScalarT>
62 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> > & prec)
63 {
64  preconditioner_.initialize(prec);
65 }
66 
67 template <typename ScalarT>
68 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> > & prec)
69 {
70  preconditioner_.initialize(prec);
71 }
72 
74 template <typename ScalarT>
75 void PreconditionerLinearOp<ScalarT>::initialize(const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> > & prec)
76 {
77  uninitialize();
78  preconditioner_.initialize(prec);
79 }
80 
82 template <typename ScalarT>
83 void PreconditionerLinearOp<ScalarT>::initialize(const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> > & prec)
84 {
85  uninitialize();
86  preconditioner_.initialize(prec);
87 }
88 
90 template <typename ScalarT>
92 {
93  preconditioner_.uninitialize();
94 }
95 
97 template <typename ScalarT>
98 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::range() const
99 {
100  return getOperator_cnoc()->range();
101 }
102 
104 template <typename ScalarT>
105 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::domain() const
106 {
107  return getOperator_cnoc()->domain();
108 }
109 
110 template <typename ScalarT>
112  const Thyra::EOpTransp M_trans) const
113 {
114  return getOperator_cnoc()->opSupported(M_trans);
115 }
116 
117 template <typename ScalarT>
119  const Thyra::EOpTransp M_trans,
120  const Thyra::MultiVectorBase<ScalarT> & x,
121  const Teuchos::Ptr<Thyra::MultiVectorBase<ScalarT> > & y,
122  const ScalarT alpha,
123  const ScalarT beta
124  ) const
125 {
126  getOperator_cnoc()->apply(M_trans, x, y, alpha, beta);
127 }
128 
129 
131 template <typename ScalarT>
132 Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> > PreconditionerLinearOp<ScalarT>::getNonconstPreconditioner()
133 {
134  return preconditioner_.getNonconstObj();
135 }
136 
138 template <typename ScalarT>
139 Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> > PreconditionerLinearOp<ScalarT>::getPreconditioner() const
140 {
141  return preconditioner_.getConstObj();
142 }
143 
145 template <typename ScalarT>
146 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > PreconditionerLinearOp<ScalarT>::getOperator_cnoc() const
147 {
148  Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
149  oper.initialize(preconditioner_.getConstObj()->getUnspecifiedPrecOp());
150 
151  return oper;
152 }
153 
155 template <typename ScalarT>
156 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > PreconditionerLinearOp<ScalarT>::getOperator_cnoc()
157 {
158  Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
159  oper.initialize(preconditioner_.getNonconstObj()->getNonconstUnspecifiedPrecOp());
160 
161  return oper;
162 }
163 
164 template <typename ScalarT>
165 void PreconditionerLinearOp<ScalarT>::describe(Teuchos::FancyOStream & out_arg,
166  const Teuchos::EVerbosityLevel verbLevel) const
167 {
168  using Teuchos::OSTab;
169 
170  Teuchos::RCP<Teuchos::FancyOStream> out = rcp(&out_arg,false);
171  OSTab tab0(out);
172  switch(verbLevel) {
173  case Teuchos::VERB_DEFAULT:
174  case Teuchos::VERB_LOW:
175  *out << this->description() << " ( [Operator] = " << getOperator_cnoc()->description() << " )" << std::endl;
176  break;
177  case Teuchos::VERB_MEDIUM:
178  case Teuchos::VERB_HIGH:
179  case Teuchos::VERB_EXTREME:
180  {
181  *out << Teuchos::Describable::description() << "{"
182  << "rangeDim=" << this->range()->dim()
183  << ",domainDim=" << this->domain()->dim()
184  << "}\n";
185  {
186  OSTab tab1(out);
187  *out << "[Operator] = ";
188  *out << Teuchos::describe(*getOperator_cnoc(),verbLevel);
189  }
190  break;
191  }
192  default:
193  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
194  }
195 }
196 
197 inline Teko::LinearOp extractOperatorFromPrecOp(const Teko::LinearOp & lo)
198 {
199  Teuchos::RCP<const Teko::PreconditionerLinearOp<double> > plo =
200  Teuchos::rcp_dynamic_cast<const Teko::PreconditionerLinearOp<double> >(lo);
201  if(plo!=Teuchos::null)
202  return plo->getOperator();
203  else
204  return lo;
205 }
206 
207 } // end namespace Teko
208 
209 #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.