Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultPreconditioner_def.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_DEFUALT_PRECONDITIONER_DEF_HPP
43 #define THYRA_DEFUALT_PRECONDITIONER_DEF_HPP
44 
45 #include "Thyra_DefaultPreconditioner_decl.hpp"
46 #include "Thyra_LinearOpBase.hpp"
47 
48 
49 namespace Thyra {
50 
51 
52 // Constructors/initializers/accessors
53 
54 
55 template <class Scalar>
57 {}
58 
59 
60 template <class Scalar>
62  const Teuchos::RCP<LinearOpBase<Scalar> > &leftPrecOp,
63  const Teuchos::RCP<LinearOpBase<Scalar> > &rightPrecOp
64  )
65 {
66 #ifdef TEUCHOS_DEBUG
67  TEUCHOS_TEST_FOR_EXCEPT( is_null(leftPrecOp) && is_null(rightPrecOp) );
68 #endif
69  if (!is_null(leftPrecOp))
70  leftPrecOp_.initialize(leftPrecOp);
71  if (!is_null(rightPrecOp))
72  rightPrecOp_.initialize(rightPrecOp);
73 }
74 
75 
76 template <class Scalar>
78  const Teuchos::RCP<const LinearOpBase<Scalar> > &leftPrecOp,
79  const Teuchos::RCP<const LinearOpBase<Scalar> > &rightPrecOp
80  )
81 {
82 #ifdef TEUCHOS_DEBUG
83  TEUCHOS_TEST_FOR_EXCEPT( is_null(leftPrecOp) && is_null(rightPrecOp) );
84 #endif
85  if (!is_null(leftPrecOp))
86  leftPrecOp_.initialize(leftPrecOp);
87  if (!is_null(rightPrecOp))
88  rightPrecOp_.initialize(rightPrecOp);
89 }
90 
91 
92 template <class Scalar>
94  const Teuchos::RCP<LinearOpBase<Scalar> > &unspecifiedPrecOp
95  )
96 {
97  unspecifiedPrecOp_.initialize(unspecifiedPrecOp);
98 }
99 
100 
101 template <class Scalar>
103  const Teuchos::RCP<const LinearOpBase<Scalar> > &unspecifiedPrecOp
104  )
105 {
106  unspecifiedPrecOp_.initialize(unspecifiedPrecOp);
107 }
108 
109 
110 template <class Scalar>
112  const Teuchos::RCP<LinearOpBase<Scalar> > &leftPrecOp
113  )
114 {
115  uninitialize();
116  leftPrecOp_.initialize(leftPrecOp);
117 }
118 
119 
120 template <class Scalar>
122  const Teuchos::RCP<const LinearOpBase<Scalar> > &leftPrecOp
123  )
124 {
125  uninitialize();
126  leftPrecOp_.initialize(leftPrecOp);
127 }
128 
129 
130 template <class Scalar>
132  const Teuchos::RCP<LinearOpBase<Scalar> > &rightPrecOp
133  )
134 {
135  uninitialize();
136  rightPrecOp_.initialize(rightPrecOp);
137 }
138 
139 
140 template <class Scalar>
142  const Teuchos::RCP<const LinearOpBase<Scalar> > &rightPrecOp
143  )
144 {
145  uninitialize();
146  rightPrecOp_.initialize(rightPrecOp);
147 }
148 
149 
150 template <class Scalar>
152  const Teuchos::RCP<LinearOpBase<Scalar> > &leftPrecOp,
153  const Teuchos::RCP<LinearOpBase<Scalar> > &rightPrecOp
154  )
155 {
156  uninitialize();
157  rightPrecOp_.initialize(rightPrecOp);
158  leftPrecOp_.initialize(leftPrecOp);
159 }
160 
161 
162 template <class Scalar>
164  const Teuchos::RCP<const LinearOpBase<Scalar> > &leftPrecOp,
165  const Teuchos::RCP<const LinearOpBase<Scalar> > &rightPrecOp
166  )
167 {
168  uninitialize();
169  rightPrecOp_.initialize(rightPrecOp);
170  leftPrecOp_.initialize(leftPrecOp);
171 }
172 
173 
174 template <class Scalar>
176  const Teuchos::RCP<LinearOpBase<Scalar> > &unspecifiedPrecOp
177  )
178 {
179  uninitialize();
180  unspecifiedPrecOp_.initialize(unspecifiedPrecOp);
181 }
182 
183 
184 template <class Scalar>
186  const Teuchos::RCP<const LinearOpBase<Scalar> > &unspecifiedPrecOp
187  )
188 {
189  uninitialize();
190  unspecifiedPrecOp_.initialize(unspecifiedPrecOp);
191 }
192 
193 
194 template <class Scalar>
196 {
197  leftPrecOp_.uninitialize();
198  rightPrecOp_.uninitialize();
199  unspecifiedPrecOp_.uninitialize();
200 }
201 
202 
203 // Overridden from PreconditionerBase
204 
205 
206 template <class Scalar>
208 {
209  return leftPrecOp_.isConst();
210 }
211 
212 
213 template <class Scalar>
216 {
217  return leftPrecOp_.getNonconstObj();
218 }
219 
220 
221 template <class Scalar>
224 {
225  return leftPrecOp_.getConstObj();
226 }
227 
228 
229 template <class Scalar>
231 {
232  return rightPrecOp_.isConst();
233 }
234 
235 
236 template <class Scalar>
239 {
240  return rightPrecOp_.getNonconstObj();
241 }
242 
243 
244 template <class Scalar>
247 {
248  return rightPrecOp_.getConstObj();
249 }
250 
251 
252 template <class Scalar>
254 {
255  return unspecifiedPrecOp_.isConst();
256 }
257 
258 
259 template <class Scalar>
262 {
263  return unspecifiedPrecOp_.getNonconstObj();
264 }
265 
266 
267 template <class Scalar>
270 {
271  return unspecifiedPrecOp_.getConstObj();
272 }
273 
274 
275 // Overridden from Teuchos::Describable
276 
277 
278 template <class Scalar>
280 {
281  std::ostringstream oss;
282  oss << Teuchos::Describable::description() << "{";
283  bool wroteOne = false;
284  if(!is_null(leftPrecOp_.getConstObj())) {
285  if(wroteOne) oss << ",";
286  oss << "leftPrecOp=" << leftPrecOp_.getConstObj()->description();
287  wroteOne = true;
288  }
289  if(!is_null(rightPrecOp_.getConstObj())) {
290  if(wroteOne) oss << ",";
291  oss << "rightPrecOp=" << rightPrecOp_.getConstObj()->description();
292  wroteOne = true;
293  }
294  if(!is_null(unspecifiedPrecOp_.getConstObj())) {
295  if(wroteOne) oss << ",";
296  oss << "unspecifiedPrecOp=" << unspecifiedPrecOp_.getConstObj()->description();
297  wroteOne = true;
298  }
299  oss << "}";
300  return oss.str();
301 }
302 
303 
304 template <class Scalar>
307  const Teuchos::EVerbosityLevel verbLevel
308  ) const
309 {
310  using Teuchos::FancyOStream;
311  using Teuchos::OSTab;
312  using Teuchos::describe;
313  OSTab tab(out);
314  switch(verbLevel) {
316  case Teuchos::VERB_LOW:
317  out << Teuchos::Describable::description() << std::endl;
318  break;
320  case Teuchos::VERB_HIGH:
322  {
323  out
324  << Teuchos::typeName(*this) << "\n";
325  OSTab tab2(out);
326  if(!is_null(leftPrecOp_.getConstObj()))
327  out << "leftPrecOp=" << describe(*leftPrecOp_.getConstObj(),verbLevel);
328  if(!is_null(rightPrecOp_.getConstObj()))
329  out << "rig htPrecOp=" << describe(*rightPrecOp_.getConstObj(),verbLevel);
330  if(!is_null(unspecifiedPrecOp_.getConstObj()))
331  out << "unspecifiedPrecOp=" << describe(*unspecifiedPrecOp_.getConstObj(),verbLevel);
332  break;
333  }
334  default:
335  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
336  }
337 }
338 
339 
340 } // namespace Thyra
341 
342 
343 #endif // THYRA_DEFUALT_PRECONDITIONER_DEF_HPP
bool is_null(const boost::shared_ptr< T > &p)
void initializeUnspecified(const Teuchos::RCP< LinearOpBase< Scalar > > &unspecifiedPrecOp)
Initialize a single unspecified preconditioner operator.
basic_OSTab< char > OSTab
basic_FancyOStream< char > FancyOStream
void initializeRight(const Teuchos::RCP< LinearOpBase< Scalar > > &rightPrecOp)
Initialize a right preconditioner.
Teuchos::RCP< LinearOpBase< Scalar > > getNonconstUnspecifiedPrecOp()
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual std::string description() const
Teuchos::RCP< const LinearOpBase< Scalar > > getRightPrecOp() const
Base class for all linear operators.
Teuchos::RCP< const LinearOpBase< Scalar > > getLeftPrecOp() const
Teuchos::RCP< LinearOpBase< Scalar > > getNonconstLeftPrecOp()
Teuchos::RCP< LinearOpBase< Scalar > > getNonconstRightPrecOp()
Teuchos::RCP< const LinearOpBase< Scalar > > getUnspecifiedPrecOp() const
void initializeLeftRight(const Teuchos::RCP< LinearOpBase< Scalar > > &leftPrecOp, const Teuchos::RCP< LinearOpBase< Scalar > > &rightPrecOp)
Initialize a split left/right preconditioner.
DefaultPreconditioner()
Construct to uninitialized.
void initializeLeft(const Teuchos::RCP< LinearOpBase< Scalar > > &leftPrecOp)
Initialize a left preconditioner.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
std::string typeName(const T &t)