Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultBlockedTriangularLinearOpWithSolveFactory_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_DEFAULT_BLOCKED_TRIANGULAR_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
11 #define THYRA_DEFAULT_BLOCKED_TRIANGULAR_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
12 
13 
14 #include "Thyra_DefaultBlockedTriangularLinearOpWithSolveFactory_decl.hpp"
15 #include "Thyra_LinearOpWithSolveBase.hpp"
16 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
17 #include "Thyra_PhysicallyBlockedLinearOpBase.hpp"
18 #include "Thyra_PhysicallyBlockedLinearOpWithSolveBase.hpp" // Interface
19 #include "Thyra_DefaultBlockedTriangularLinearOpWithSolve.hpp" // Implementation
20 #include "Thyra_DefaultLinearOpSource.hpp"
21 
22 
23 namespace Thyra {
24 
25 
26 // Overridden from Constructors/Initializers/Accessors
27 
28 
29 template<class Scalar>
32  )
33 {
34 #ifdef TEUCHOS_DEBUG
36 #endif
37  lowsf_.initialize(lowsf);
38 }
39 
40 
41 template<class Scalar>
43  const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf
44  )
45 {
46 #ifdef TEUCHOS_DEBUG
48 #endif
49  lowsf_.initialize(lowsf);
50 }
51 
52 
53 template<class Scalar>
56 {
57  return lowsf_.getNonconstObj();
58 }
59 
60 
61 template<class Scalar>
64 {
65  return lowsf_.getConstObj();
66 }
67 
68 
69 // Overridden from Teuchos::Describable
70 
71 
72 template<class Scalar>
73 std::string
75 {
76  std::ostringstream oss;
78  << "{"
79  << "lowsf=";
80  if (!is_null(lowsf_.getConstObj()))
81  oss << lowsf_.getConstObj()->description();
82  else
83  oss << "NULL";
84  oss << "}";
85  return oss.str();
86 }
87 
88 
89 // Overridden from ParameterListAcceptor
90 
91 
92 template<class Scalar>
93 void
95  RCP<ParameterList> const& paramList
96  )
97 {
98  lowsf_.getNonconstObj()->setParameterList(paramList);
99 }
100 
101 
102 template<class Scalar>
105 {
106  return lowsf_.getNonconstObj()->getNonconstParameterList();
107 }
108 
109 
110 template<class Scalar>
113 {
114  return lowsf_.getNonconstObj()->unsetParameterList();
115 }
116 
117 
118 template<class Scalar>
121 {
122  return lowsf_.getConstObj()->getParameterList();
123 }
124 
125 
126 template<class Scalar>
129 {
130  return lowsf_.getConstObj()->getValidParameters();
131 }
132 
133 
134 // Overridden from LinearOpWithSolveFactoyBase
135 
136 
137 template<class Scalar>
138 bool
140 {
141  return false;
142 }
143 
144 
145 template<class Scalar>
146 void
148  const RCP<PreconditionerFactoryBase<Scalar> > &/* precFactory */,
149  const std::string &/* precFactoryName */
150  )
151 {
152  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
153  "Error, we don't support a preconditioner factory!");
154 }
155 
156 
157 template<class Scalar>
160 {
161  return Teuchos::null;
162 }
163 
164 
165 template<class Scalar>
167  RCP<PreconditionerFactoryBase<Scalar> > * /* precFactory */,
168  std::string * /* precFactoryName */
169  )
170 {
171  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
172  "Error, we don't support a preconditioner factory!");
173 }
174 
175 
176 template<class Scalar>
177 bool
179  const LinearOpSourceBase<Scalar> &/* fwdOpSrc */
180  ) const
181 {
184 }
185 
186 
187 template<class Scalar>
190 {
191  return defaultBlockedTriangularLinearOpWithSolve<Scalar>();
192 }
193 
194 
195 template<class Scalar>
196 void
198  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
200  const ESupportSolveUse /* supportSolveUse */
201  ) const
202 {
203 
204  using Teuchos::dyn_cast;
205  using Teuchos::rcp_dynamic_cast;
206 
207 #ifdef TEUCHOS_DEBUG
209 #endif
210 
211  // Set the verbosity settings for the wrapped LOWSF object!
212  lowsf_.getConstObj()->setOStream(this->getOStream());
213  lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
214 
215  // Get the block interface to get at the blocks
217  const RCP<const PBLOB> blo =
218  rcp_dynamic_cast<const PBLOB>(fwdOpSrc->getOp().assert_not_null());
219 
220  // Dynamic cast to get the DefaultBlockedTriangularLinearOpWithSolveBase
221  // interface that we will fill.
222 
224  DBTLOWS &btlows = dyn_cast<DBTLOWS>(*Op);
225 
226  // Determine if this is the first time through or if we have already
227  // initialized before. This will be needed to allow efficient reuse of the
228  // LOWSB objects for the diagonal blocks.
229  const bool firstTime = is_null(btlows.range());
230 
231  // If this is the first time through, we need to fill and create the block
232  // structure
233  if (firstTime)
234  btlows.beginBlockFill(blo->productRange(),blo->productDomain());
235 
236  const int N = blo->productRange()->numBlocks();
237  for ( int k = 0; k < N; ++k ) {
238  const RCP<const LinearOpBase<Scalar> > fwdOp_k =
239  blo->getBlock(k,k).assert_not_null();
240  if (firstTime) {
241  // This is the first time through so reate and initialize a new LOWSB
242  // object for each block
243  btlows.setNonconstLOWSBlock( k, k,
244  linearOpWithSolve<Scalar>(*lowsf_.getConstObj(),fwdOp_k)
245  );
246  }
247  else {
248  // This is not the first time through so we need to just reinitiallize
249  // the object that is already created. This allows us to efficiently
250  // reuse precreated structure and storage.
252  invOp_k = btlows.getNonconstLOWSBlock(k,k).assert_not_null();
253  Thyra::initializeOp<Scalar>(*lowsf_.getConstObj(), fwdOp_k, invOp_k.ptr());
254  }
255  }
256 
257  // If this is the first time through, then we need to finalize the block
258  // structure.
259  if (firstTime)
260  btlows.endBlockFill();
261 
262  // After the block structure has been setup, set the off-diagonal blocks.
263  // Note that this also sets the diagonal blocks but these are ignored since
264  // the LOWSB blocks created above override these.
265  btlows.setBlocks(blo);
266 
267  // Set the verbosity settings
268  btlows.setOStream(this->getOStream());
269  btlows.setVerbLevel(this->getVerbLevel());
270 
271 }
272 
273 
274 template<class Scalar>
275 void
277  const RCP<const LinearOpSourceBase<Scalar> > &/* fwdOpSrc */,
279  ) const
280 {
282 }
283 
284 
285 template<class Scalar>
286 void
289  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
290  RCP<const PreconditionerBase<Scalar> > *prec,
291  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
292  ESupportSolveUse * /* supportSolveUse */
293  ) const
294 {
295  using Teuchos::dyn_cast;
296  using Teuchos::rcp_implicit_cast;
297  using Teuchos::rcp_dynamic_cast;
300  DBTLOWS &btlowsOp = dyn_cast<DBTLOWS>(*Op);
301  if (fwdOpSrc) {
302  const RCP<const LinearOpBase<Scalar> > fwdOp = btlowsOp.getBlocks();
303  if (!is_null(fwdOp))
304  *fwdOpSrc = defaultLinearOpSource<Scalar>(fwdOp);
305  else
306  *fwdOpSrc = Teuchos::null;
307  }
308  if (prec) *prec = Teuchos::null;
309  if (approxFwdOpSrc) *approxFwdOpSrc = Teuchos::null;
310 }
311 
312 
313 template<class Scalar>
314 bool
316  const EPreconditionerInputType /* precOpType */
317  ) const
318 {
319  // We don't support any external preconditioners!
320  return false;
321  // 20071006: rabartl: Note: We could support external preconditioners but it
322  // will take some work. We would have to extract out the individual
323  // preconditioners from each block. This would be pretty easy to do but I
324  // am not going to do this until we have to.
325 }
326 
327 
328 template<class Scalar>
329 void
331  const RCP<const LinearOpSourceBase<Scalar> > &/* fwdOpSrc */,
332  const RCP<const PreconditionerBase<Scalar> > &/* prec */,
334  const ESupportSolveUse /* supportSolveUse */
335  ) const
336 {
337  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
338  "Error, we don't support an external preconditioner!");
339 }
340 
341 
342 template<class Scalar>
343 void
345  const RCP<const LinearOpSourceBase<Scalar> > &/* fwdOpSrc */,
346  const RCP<const LinearOpSourceBase<Scalar> > &/* approxFwdOpSrc */,
348  const ESupportSolveUse /* supportSolveUse */
349  ) const
350 {
351  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
352  "Error, we don't support an external preconditioner!");
353 }
354 
355 
356 // protected
357 
358 
359 template<class Scalar>
360 void
362 {
363  lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
364  lowsf_.getConstObj()->setOStream(this->getOStream());
365 }
366 
367 
368 } // namespace Thyra
369 
370 
371 #endif // THYRA_DEFAULT_BLOCKED_TRIANGULAR_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
Base class for all linear operators that can support a high-level solve operation.
bool is_null(const boost::shared_ptr< T > &p)
virtual void initializePreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const PreconditionerBase< Scalar > > &prec, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
Concrete composite LinearOpWithSolveBase subclass that creates single upper or lower block triangular...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T_To & dyn_cast(T_From &from)
virtual void unsetPreconditionerFactory(RCP< PreconditionerFactoryBase< Scalar > > *precFactory, std::string *precFactoryName)
Throws exception.
Simple interface class to access a precreated preconditioner as one or more linear operators objects ...
virtual bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const
Implicit subclass that takes a blocked triangular LOWB object and turns it into a LOWSB object...
Factory interface for creating LinearOpWithSolveBase objects from compatible LinearOpBase objects...
Ptr< T > ptr() const
Base interface for physically blocked linear operators.
virtual void initializeApproxPreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
virtual void initializeOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
virtual std::string description() const
Factory interface for creating preconditioner objects from LinearOpBase objects.
Base interface for objects that can return a linear operator.
virtual RCP< PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
Returns null .
virtual void uninitializeOp(LinearOpWithSolveBase< Scalar > *Op, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc, RCP< const PreconditionerBase< Scalar > > *prec, RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
const RCP< T > & assert_not_null() const
ESupportSolveUse
Enum that specifies how a LinearOpWithSolveBase object will be used for solves after it is constructe...
virtual void setPreconditionerFactory(const RCP< PreconditionerFactoryBase< Scalar > > &precFactory, const std::string &precFactoryName)
Throws exception.
virtual void initializeAndReuseOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op) const
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
virtual bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
EPreconditionerInputType
Enum defining the status of a preconditioner object.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)