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 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
11 #define THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
12 
13 
14 #include "Thyra_DelayedLinearOpWithSolve_decl.hpp"
15 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
16 #include "Thyra_LinearOpWithSolveBase.hpp"
17 #include "Thyra_SolveSupportTypes.hpp"
18 #include "Teuchos_VerboseObject.hpp"
19 
20 
21 namespace Thyra {
22 
23 
24 // Constructor/Initializers
25 
26 
27 template <class Scalar>
29  :supportSolveUse_(SUPPORT_SOLVE_UNSPECIFIED), lows_is_valid_(false)
30 {}
31 
32 
33 template <class Scalar>
35  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
36  const RCP<const PreconditionerBase<Scalar> > &prec,
37  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
38  const ESupportSolveUse supportSolveUse,
40  )
41 {
42 #ifdef TEUCHOS_DEBUG
44  TEUCHOS_TEST_FOR_EXCEPT(!is_null(prec) && !is_null(approxFwdOpSrc));
46 #endif
47  fwdOpSrc_ = fwdOpSrc;
48  prec_ = prec;
49  approxFwdOpSrc_ = approxFwdOpSrc;
50  lowsf_ = lowsf;
51  supportSolveUse_ = supportSolveUse;
52  fwdOp_ = fwdOpSrc_->getOp().assert_not_null();
53  lows_is_valid_ = false;
54 }
55 
56 
57 template <class Scalar>
60 {
61  return fwdOpSrc_;
62 }
63 
64 
65 template <class Scalar>
68 {
69  return prec_;
70 }
71 
72 
73 template <class Scalar>
76 {
77  return approxFwdOpSrc_;
78 }
79 
80 
81 template <class Scalar>
84 {
85  return supportSolveUse_;
86 }
87 
88 
89 // Overridden from Teuchos::Describable
90 
91 
92 template<class Scalar>
94 {
95  std::ostringstream oss;
97  << "{";
98  oss << "fwdOp_=";
99  if (!is_null(fwdOp_))
100  oss << fwdOp_->description();
101  else
102  oss << "NULL,";
103  oss << "lows=";
104  if (!is_null(lows_))
105  oss << lows_->description();
106  else
107  oss << "NULL";
108  oss << "}";
109  return oss.str();
110 }
111 
112 
113 // Overridden from LinearOpBase
114 
115 
116 template <class Scalar>
119 {
120  if (!is_null(fwdOp_))
121  return fwdOp_->range();
122  return Teuchos::null;
123 }
124 
125 
126 template <class Scalar>
129 {
130  if (!is_null(fwdOp_))
131  return fwdOp_->domain();
132  return Teuchos::null;
133 }
134 
135 
136 template <class Scalar>
139 {
140  return Teuchos::null; // ToDo: Implement if needed!
141 }
142 
143 
144 // protected
145 
146 
147 template<class Scalar>
149 {
150  if (!is_null(lowsf_)) {
151  lowsf_->setVerbLevel(this->getVerbLevel());
152  lowsf_->setOStream(this->getOStream());
153  }
154  if (!is_null(lows_)) {
155  lows_->setVerbLevel(this->getVerbLevel());
156  lows_->setOStream(this->getOStream());
157  }
158 }
159 
160 
161 // Overridden from LinearOpBase
162 
163 
164 template <class Scalar>
166 {
167  return Thyra::opSupported(*fwdOp_,M_trans);
168 }
169 
170 
171 template <class Scalar>
173  const EOpTransp M_trans,
174  const MultiVectorBase<Scalar> &X,
175  const Ptr<MultiVectorBase<Scalar> > &Y,
176  const Scalar alpha,
177  const Scalar beta
178  ) const
179 {
180  Thyra::apply(*fwdOp_, M_trans, X, Y, alpha, beta);
181 }
182 
183 
184 // Overridden from LinearOpWithSolveBase
185 
186 
187 template <class Scalar>
189 {
190  updateSolver();
191  return Thyra::solveSupports(*lows_, M_trans);
192 }
193 
194 
195 template <class Scalar>
197  EOpTransp M_trans, const SolveMeasureType& solveMeasureType
198  ) const
199 {
200  updateSolver();
201  return Thyra::solveSupportsSolveMeasureType(*lows_, M_trans, solveMeasureType);
202 }
203 
204 
205 template <class Scalar>
208  const EOpTransp transp,
209  const MultiVectorBase<Scalar> &B,
210  const Ptr<MultiVectorBase<Scalar> > &X,
211  const Ptr<const SolveCriteria<Scalar> > solveCriteria
212  ) const
213 {
214  updateSolver();
215  return Thyra::solve(*lows_, transp, B, X, solveCriteria);
216 }
217 
218 
219 // private
220 
221 
222 template <class Scalar>
224 {
225  if (is_null(lows_))
226  lows_ = lowsf_->createOp();
227  if (!lows_is_valid_) {
228  if (!is_null(prec_))
229  lowsf_->initializePreconditionedOp(
230  fwdOpSrc_,prec_,&*lows_,supportSolveUse_);
231  else if (!is_null(approxFwdOpSrc_))
232  lowsf_->initializeApproxPreconditionedOp(
233  fwdOpSrc_,approxFwdOpSrc_,&*lows_,supportSolveUse_);
234  else
235  lowsf_->initializeOp(
236  fwdOpSrc_,&*lows_,supportSolveUse_);
237  lows_is_valid_ = true;
238  }
239 }
240 
241 
242 } // namespace Thyra
243 
244 
245 #endif // THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
246 
247 
248 
249 
250 
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