Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DelayedLinearOpWithSolve_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 
43 #ifndef THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
44 #define THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
45 
46 
47 #include "Thyra_DelayedLinearOpWithSolve_decl.hpp"
48 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
49 #include "Thyra_LinearOpWithSolveBase.hpp"
50 #include "Thyra_SolveSupportTypes.hpp"
51 #include "Teuchos_VerboseObject.hpp"
52 
53 
54 namespace Thyra {
55 
56 
57 // Constructor/Initializers
58 
59 
60 template <class Scalar>
62  :supportSolveUse_(SUPPORT_SOLVE_UNSPECIFIED), lows_is_valid_(false)
63 {}
64 
65 
66 template <class Scalar>
68  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
69  const RCP<const PreconditionerBase<Scalar> > &prec,
70  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
71  const ESupportSolveUse supportSolveUse,
73  )
74 {
75 #ifdef TEUCHOS_DEBUG
77  TEUCHOS_TEST_FOR_EXCEPT(!is_null(prec) && !is_null(approxFwdOpSrc));
79 #endif
80  fwdOpSrc_ = fwdOpSrc;
81  prec_ = prec;
82  approxFwdOpSrc_ = approxFwdOpSrc;
83  lowsf_ = lowsf;
84  supportSolveUse_ = supportSolveUse;
85  fwdOp_ = fwdOpSrc_->getOp().assert_not_null();
86  lows_is_valid_ = false;
87 }
88 
89 
90 template <class Scalar>
93 {
94  return fwdOpSrc_;
95 }
96 
97 
98 template <class Scalar>
101 {
102  return prec_;
103 }
104 
105 
106 template <class Scalar>
109 {
110  return approxFwdOpSrc_;
111 }
112 
113 
114 template <class Scalar>
117 {
118  return supportSolveUse_;
119 }
120 
121 
122 // Overridden from Teuchos::Describable
123 
124 
125 template<class Scalar>
127 {
128  std::ostringstream oss;
129  oss << this->Teuchos::Describable::description()
130  << "{";
131  oss << "fwdOp_=";
132  if (!is_null(fwdOp_))
133  oss << fwdOp_->description();
134  else
135  oss << "NULL,";
136  oss << "lows=";
137  if (!is_null(lows_))
138  oss << lows_->description();
139  else
140  oss << "NULL";
141  oss << "}";
142  return oss.str();
143 }
144 
145 
146 // Overridden from LinearOpBase
147 
148 
149 template <class Scalar>
152 {
153  if (!is_null(fwdOp_))
154  return fwdOp_->range();
155  return Teuchos::null;
156 }
157 
158 
159 template <class Scalar>
162 {
163  if (!is_null(fwdOp_))
164  return fwdOp_->domain();
165  return Teuchos::null;
166 }
167 
168 
169 template <class Scalar>
172 {
173  return Teuchos::null; // ToDo: Implement if needed!
174 }
175 
176 
177 // protected
178 
179 
180 template<class Scalar>
182 {
183  if (!is_null(lowsf_)) {
184  lowsf_->setVerbLevel(this->getVerbLevel());
185  lowsf_->setOStream(this->getOStream());
186  }
187  if (!is_null(lows_)) {
188  lows_->setVerbLevel(this->getVerbLevel());
189  lows_->setOStream(this->getOStream());
190  }
191 }
192 
193 
194 // Overridden from LinearOpBase
195 
196 
197 template <class Scalar>
199 {
200  return Thyra::opSupported(*fwdOp_,M_trans);
201 }
202 
203 
204 template <class Scalar>
206  const EOpTransp M_trans,
207  const MultiVectorBase<Scalar> &X,
208  const Ptr<MultiVectorBase<Scalar> > &Y,
209  const Scalar alpha,
210  const Scalar beta
211  ) const
212 {
213  Thyra::apply(*fwdOp_, M_trans, X, Y, alpha, beta);
214 }
215 
216 
217 // Overridden from LinearOpWithSolveBase
218 
219 
220 template <class Scalar>
222 {
223  updateSolver();
224  return Thyra::solveSupports(*lows_, M_trans);
225 }
226 
227 
228 template <class Scalar>
230  EOpTransp M_trans, const SolveMeasureType& solveMeasureType
231  ) const
232 {
233  updateSolver();
234  return Thyra::solveSupportsSolveMeasureType(*lows_, M_trans, solveMeasureType);
235 }
236 
237 
238 template <class Scalar>
241  const EOpTransp transp,
242  const MultiVectorBase<Scalar> &B,
243  const Ptr<MultiVectorBase<Scalar> > &X,
244  const Ptr<const SolveCriteria<Scalar> > solveCriteria
245  ) const
246 {
247  updateSolver();
248  return Thyra::solve(*lows_, transp, B, X, solveCriteria);
249 }
250 
251 
252 // private
253 
254 
255 template <class Scalar>
257 {
258  if (is_null(lows_))
259  lows_ = lowsf_->createOp();
260  if (!lows_is_valid_) {
261  if (!is_null(prec_))
262  lowsf_->initializePreconditionedOp(
263  fwdOpSrc_,prec_,&*lows_,supportSolveUse_);
264  else if (!is_null(approxFwdOpSrc_))
265  lowsf_->initializeApproxPreconditionedOp(
266  fwdOpSrc_,approxFwdOpSrc_,&*lows_,supportSolveUse_);
267  else
268  lowsf_->initializeOp(
269  fwdOpSrc_,&*lows_,supportSolveUse_);
270  lows_is_valid_ = true;
271  }
272 }
273 
274 
275 } // namespace Thyra
276 
277 
278 #endif // THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
279 
280 
281 
282 
283 
How the output LOWSB object will be useded for solves in unspecified.
RCP< const PreconditionerBase< Scalar > > getPrec() const
bool is_null(const boost::shared_ptr< T > &p)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
SolveStatus< Scalar > solveImpl(const EOpTransp transp, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > > solveCriteria) const
Simple interface class to access a precreated preconditioner as one or more linear operators objects ...
RCP< const VectorSpaceBase< Scalar > > domain() const
RCP< const LinearOpSourceBase< Scalar > > getFwdOpSrc() const
Interface for a collection of column vectors called a multi-vector.
Factory interface for creating LinearOpWithSolveBase objects from compatible LinearOpBase objects...
void informUpdatedVerbosityState() const
Overridden from Teuchos::VerboseObjectBase.
virtual std::string description() const
void initialize(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const PreconditionerBase< Scalar > > &prec, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, const ESupportSolveUse supportSolveUse, const RCP< LinearOpWithSolveFactoryBase< Scalar > > &lowsf)
Simple struct for the return status from a solve.
Base interface for objects that can return a linear operator.
RCP< const LinearOpSourceBase< Scalar > > getApproxFwdOpSrc() const
RCP< const VectorSpaceBase< Scalar > > range() const
ESupportSolveUse
Enum that specifies how a LinearOpWithSolveBase object will be used for solves after it is constructe...
virtual void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
virtual bool solveSupportsSolveMeasureTypeImpl(EOpTransp M_trans, const SolveMeasureType &solveMeasureType) const
virtual bool opSupportedImpl(EOpTransp M_trans) const
virtual bool solveSupportsImpl(EOpTransp M_trans) const
Simple struct that defines the requested solution criteria for a solve.
Delayed linear solver construction LinearOpWithSolveBase decorator class.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
RCP< const LinearOpBase< Scalar > > clone() const