Tempus Version of the Day
Time Integration
Loading...
Searching...
No Matches
Thyra_BlockedTriangularLinearOpWithSolveFactory.hpp
Go to the documentation of this file.
1//@HEADER
2// *****************************************************************************
3// Tempus: Time Integration and Sensitivity Analysis Package
4//
5// Copyright 2017 NTESS and the Tempus contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8//@HEADER
9
10#ifndef Thyra_BlockedTriangularLinearOpWithSolveFactory_hpp
11#define Thyra_BlockedTriangularLinearOpWithSolveFactory_hpp
12
13#include "Thyra_LinearOpWithSolveBase.hpp"
14#include "Thyra_DefaultBlockedLinearOp.hpp"
15#include "Thyra_DefaultBlockedTriangularLinearOpWithSolve.hpp"
16#include "Thyra_LinearOpSourceBase.hpp"
17#include "Teuchos_Array.hpp"
18
19namespace Thyra {
20
61template <class Scalar>
63 : virtual public LinearOpWithSolveFactoryBase<Scalar> {
64 public:
67
79 const Array<RCP<LinearOpWithSolveFactoryBase<Scalar> > > &lowsf);
80
92 const Array<RCP<const LinearOpWithSolveFactoryBase<Scalar> > > &lowsf);
93
94 Array<RCP<LinearOpWithSolveFactoryBase<Scalar> > > getUnderlyingLOWSF();
95
96 Array<RCP<const LinearOpWithSolveFactoryBase<Scalar> > > getUnderlyingLOWSF()
97 const;
98
100
103
104 std::string description() const;
105
107
111
112 void setParameterList(RCP<ParameterList> const &paramList);
113 RCP<ParameterList> getNonconstParameterList();
114 RCP<ParameterList> unsetParameterList();
115 RCP<const ParameterList> getParameterList() const;
116 RCP<const ParameterList> getValidParameters() const;
117
119
122
124 virtual bool acceptsPreconditionerFactory() const;
125
127 virtual void setPreconditionerFactory(
128 const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
129 const std::string &precFactoryName);
130
132 virtual RCP<PreconditionerFactoryBase<Scalar> > getPreconditionerFactory()
133 const;
134
136 virtual void unsetPreconditionerFactory(
137 RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
138 std::string *precFactoryName);
139
140 virtual bool isCompatible(const LinearOpSourceBase<Scalar> &fwdOpSrc) const;
141
142 virtual RCP<LinearOpWithSolveBase<Scalar> > createOp() const;
143
144 virtual void initializeOp(
145 const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
147 const ESupportSolveUse supportSolveUse) const;
148
149 virtual void initializeAndReuseOp(
150 const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
152
153 virtual void uninitializeOp(
155 RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
156 RCP<const PreconditionerBase<Scalar> > *prec,
157 RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
158 ESupportSolveUse *supportSolveUse) const;
159
161 const EPreconditionerInputType precOpType) const;
162
163 virtual void initializePreconditionedOp(
164 const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
165 const RCP<const PreconditionerBase<Scalar> > &prec,
167 const ESupportSolveUse supportSolveUse) const;
168
170 const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
171 const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
173 const ESupportSolveUse supportSolveUse) const;
174
176
177 protected:
180
181 void informUpdatedVerbosityState() const;
182
184
185 private:
186 typedef Teuchos::ConstNonconstObjectContainer<
189
190 Array<LOWSF_t> lowsf_;
191
192 // Not defined and not to be called
194};
195
200template <class Scalar>
201RCP<BlockedTriangularLinearOpWithSolveFactory<Scalar> >
203 const Array<RCP<LinearOpWithSolveFactoryBase<Scalar> > > &lowsf)
204{
205 return Teuchos::rcp(
207}
208
213template <class Scalar>
214RCP<BlockedTriangularLinearOpWithSolveFactory<Scalar> >
216 const Array<RCP<const LinearOpWithSolveFactoryBase<Scalar> > > &lowsf)
217{
218 return Teuchos::rcp(
220}
221
222// Overridden from Constructors/Initializers/Accessors
223
224template <class Scalar>
227 const Array<RCP<LinearOpWithSolveFactoryBase<Scalar> > > &lowsf)
228 : lowsf_(lowsf.size())
229{
230 for (Ordinal i = 0; i < lowsf.size(); ++i) {
231#ifdef TEUCHOS_DEBUG
232 TEUCHOS_TEST_FOR_EXCEPT(is_null(lowsf[i]));
233#endif
234 lowsf_[i].initialize(lowsf[i]);
235 }
236}
237
238template <class Scalar>
241 const Array<RCP<const LinearOpWithSolveFactoryBase<Scalar> > > &lowsf)
242 : lowsf_(lowsf.size())
243{
244 for (Ordinal i = 0; i < lowsf.size(); ++i) {
245#ifdef TEUCHOS_DEBUG
246 TEUCHOS_TEST_FOR_EXCEPT(is_null(lowsf[i]));
247#endif
248 lowsf_[i].initialize(lowsf[i]);
249 }
250}
251
252template <class Scalar>
253Array<RCP<LinearOpWithSolveFactoryBase<Scalar> > >
255{
256 Array<RCP<LinearOpWithSolveFactoryBase<Scalar> > > lowsf(lowsf_.size());
257 for (Ordinal i = 0; i < lowsf_.size(); ++i) {
258 lowsf[i] = lowsf_[i].getNonconstObj();
259 }
260 return lowsf;
261}
262
263template <class Scalar>
264Array<RCP<const LinearOpWithSolveFactoryBase<Scalar> > >
266{
267 Array<RCP<const LinearOpWithSolveFactoryBase<Scalar> > > lowsf(lowsf_.size());
268 for (Ordinal i = 0; i < lowsf_.size(); ++i) {
269 lowsf[i] = lowsf_[i].getConstObj();
270 }
271 return lowsf;
272}
273
274// Overridden from Teuchos::Describable
275
276template <class Scalar>
278 const
279{
280 std::ostringstream oss;
281 oss << this->Teuchos::Describable::description() << "{";
282 for (Ordinal i = 0; i < lowsf_.size(); ++i) {
283 oss << "lowsf=";
284 if (!is_null(lowsf_[i].getConstObj()))
285 oss << lowsf_[i].getConstObj()->description();
286 else
287 oss << "NULL";
288 }
289 oss << "}";
290 return oss.str();
291}
292
293// Overridden from ParameterListAcceptor
294
295// Note, we should probably do something smarter with the parameter lists
296
297template <class Scalar>
299 RCP<ParameterList> const &paramList)
300{
301 for (Ordinal i = 0; i < lowsf_.size(); ++i) {
302 lowsf_[i].getNonconstObj()->setParameterList(paramList);
303 }
304}
305
306template <class Scalar>
307RCP<ParameterList>
309{
310 return lowsf_[0].getNonconstObj()->getNonconstParameterList();
311}
312
313template <class Scalar>
314RCP<ParameterList>
316{
317 RCP<ParameterList> pl;
318 for (Ordinal i = 0; i < lowsf_.size(); ++i) {
319 pl = lowsf_[i].getNonconstObj()->unsetParameterList();
320 }
321 return pl;
322}
323
324template <class Scalar>
325RCP<const ParameterList>
327{
328 return lowsf_[0].getConstObj()->getParameterList();
329}
330
331template <class Scalar>
332RCP<const ParameterList>
334{
335 return lowsf_[0].getConstObj()->getValidParameters();
336}
337
338// Overridden from LinearOpWithSolveFactoyBase
339
340template <class Scalar>
342 Scalar>::acceptsPreconditionerFactory() const
343{
344 return false;
345}
346
347template <class Scalar>
350 const RCP<PreconditionerFactoryBase<Scalar> > & /* precFactory */,
351 const std::string & /* precFactoryName */
352 )
353{
354 TEUCHOS_TEST_FOR_EXCEPTION(
355 true, std::logic_error,
356 "Error, we don't support a preconditioner factory!");
357}
358
359template <class Scalar>
360RCP<PreconditionerFactoryBase<Scalar> >
366
367template <class Scalar>
369 Scalar>::unsetPreconditionerFactory(RCP<PreconditionerFactoryBase<Scalar> >
370 * /* precFactory */,
371 std::string * /* precFactoryName */
372)
373{
374 TEUCHOS_TEST_FOR_EXCEPTION(
375 true, std::logic_error,
376 "Error, we don't support a preconditioner factory!");
377}
378
379template <class Scalar>
381 const LinearOpSourceBase<Scalar> & /* fwdOpSrc */
382) const
383{
384 TEUCHOS_TEST_FOR_EXCEPT(true);
385 TEUCHOS_UNREACHABLE_RETURN(false);
386}
387
388template <class Scalar>
389RCP<LinearOpWithSolveBase<Scalar> >
391{
392 return defaultBlockedTriangularLinearOpWithSolve<Scalar>();
393}
394
395template <class Scalar>
397 const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
399 const ESupportSolveUse /* supportSolveUse */
400) const
401{
402 using Teuchos::dyn_cast;
403 using Teuchos::rcp_dynamic_cast;
404
405#ifdef TEUCHOS_DEBUG
406 TEUCHOS_TEST_FOR_EXCEPT(0 == Op);
407#endif
408
409 // Set the verbosity settings for the wrapped LOWSF object!
410 for (Ordinal i = 0; i < lowsf_.size(); ++i) {
411 lowsf_[i].getConstObj()->setOStream(this->getOStream());
412 lowsf_[i].getConstObj()->setVerbLevel(this->getVerbLevel());
413 }
414
415 // Get the block interface to get at the blocks
416 typedef PhysicallyBlockedLinearOpBase<Scalar> PBLOB;
417 const RCP<const PBLOB> blo =
418 rcp_dynamic_cast<const PBLOB>(fwdOpSrc->getOp().assert_not_null());
419
420 // Dynamic cast to get the DefaultBlockedTriangularLinearOpWithSolveBase
421 // interface that we will fill.
422
423 typedef DefaultBlockedTriangularLinearOpWithSolve<Scalar> DBTLOWS;
424 DBTLOWS &btlows = dyn_cast<DBTLOWS>(*Op);
425
426 // Determine if this is the first time through or if we have already
427 // initialized before. This will be needed to allow efficient reuse of the
428 // LOWSB objects for the diagonal blocks.
429 const bool firstTime = is_null(btlows.range());
430
431 // If this is the first time through, we need to fill and create the block
432 // structure
433 if (firstTime)
434 btlows.beginBlockFill(blo->productRange(), blo->productDomain());
435
436 const int N = blo->productRange()->numBlocks();
437 for (int k = 0; k < N; ++k) {
438 const RCP<const LinearOpBase<Scalar> > fwdOp_k =
439 blo->getBlock(k, k).assert_not_null();
440 if (firstTime) {
441 // This is the first time through so reate and initialize a new LOWSB
442 // object for each block
443 btlows.setNonconstLOWSBlock(
444 k, k, linearOpWithSolve<Scalar>(*lowsf_[k].getConstObj(), fwdOp_k));
445 }
446 else {
447 // This is not the first time through so we need to just reinitiallize
448 // the object that is already created. This allows us to efficiently
449 // reuse precreated structure and storage.
450 RCP<LinearOpWithSolveBase<Scalar> > invOp_k =
451 btlows.getNonconstLOWSBlock(k, k).assert_not_null();
452 Thyra::initializeOp<Scalar>(*lowsf_[k].getConstObj(), fwdOp_k,
453 invOp_k.ptr());
454 }
455 }
456
457 // If this is the first time through, then we need to finalize the block
458 // structure.
459 if (firstTime) btlows.endBlockFill();
460
461 // After the block structure has been setup, set the off-diagonal blocks.
462 // Note that this also sets the diagonal blocks but these are ignored since
463 // the LOWSB blocks created above override these.
464 btlows.setBlocks(blo);
465
466 // Set the verbosity settings
467 btlows.setOStream(this->getOStream());
468 btlows.setVerbLevel(this->getVerbLevel());
469}
470
471template <class Scalar>
473 const RCP<const LinearOpSourceBase<Scalar> > & /* fwdOpSrc */,
475) const
476{
477 TEUCHOS_TEST_FOR_EXCEPT(true);
478}
479
480template <class Scalar>
483 RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
484 RCP<const PreconditionerBase<Scalar> > *prec,
485 RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
486 ESupportSolveUse * /* supportSolveUse */
487) const
488{
489 using Teuchos::dyn_cast;
490 using Teuchos::rcp_dynamic_cast;
491 using Teuchos::rcp_implicit_cast;
492 typedef DefaultBlockedTriangularLinearOpWithSolve<Scalar> DBTLOWS;
493 TEUCHOS_TEST_FOR_EXCEPT(0 == Op);
494 DBTLOWS &btlowsOp = dyn_cast<DBTLOWS>(*Op);
495 if (fwdOpSrc) {
496 const RCP<const LinearOpBase<Scalar> > fwdOp = btlowsOp.getBlocks();
497 if (!is_null(fwdOp))
498 *fwdOpSrc = defaultLinearOpSource<Scalar>(fwdOp);
499 else
500 *fwdOpSrc = Teuchos::null;
501 }
502 if (prec) *prec = Teuchos::null;
503 if (approxFwdOpSrc) *approxFwdOpSrc = Teuchos::null;
504}
505
506template <class Scalar>
509 const EPreconditionerInputType /* precOpType */
510 ) const
511{
512 // We don't support any external preconditioners!
513 return false;
514 // 20071006: rabartl: Note: We could support external preconditioners but it
515 // will take some work. We would have to extract out the individual
516 // preconditioners from each block. This would be pretty easy to do but I
517 // am not going to do this until we have to.
518}
519
520template <class Scalar>
523 const RCP<const LinearOpSourceBase<Scalar> > & /* fwdOpSrc */,
524 const RCP<const PreconditionerBase<Scalar> > & /* prec */,
526 const ESupportSolveUse /* supportSolveUse */
527 ) const
528{
529 TEUCHOS_TEST_FOR_EXCEPTION(
530 true, std::logic_error,
531 "Error, we don't support an external preconditioner!");
532}
533
534template <class Scalar>
537 const RCP<const LinearOpSourceBase<Scalar> > & /* fwdOpSrc */,
538 const RCP<const LinearOpSourceBase<Scalar> > & /* approxFwdOpSrc */,
540 const ESupportSolveUse /* supportSolveUse */
541 ) const
542{
543 TEUCHOS_TEST_FOR_EXCEPTION(
544 true, std::logic_error,
545 "Error, we don't support an external preconditioner!");
546}
547
548// protected
549
550template <class Scalar>
552 Scalar>::informUpdatedVerbosityState() const
553{
554 for (Ordinal i = 0; i < lowsf_.size(); ++i) {
555 lowsf_[i].getConstObj()->setVerbLevel(this->getVerbLevel());
556 lowsf_[i].getConstObj()->setOStream(this->getOStream());
557 }
558}
559
560} // namespace Thyra
561
562#endif // Thyra_BlockedTriangularLinearOpWithSolveFactory_hpp
Implicit subclass that takes a blocked triangular LOWB object and turns it into a LOWSB object.
RCP< BlockedTriangularLinearOpWithSolveFactory< Scalar > > blockedTriangularLinearOpWithSolveFactory(const Array< RCP< const LinearOpWithSolveFactoryBase< Scalar > > > &lowsf)
Nonmember constructor.
virtual bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
virtual void initializePreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const PreconditionerBase< Scalar > > &prec, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
RCP< BlockedTriangularLinearOpWithSolveFactory< Scalar > > blockedTriangularLinearOpWithSolveFactory(const Array< RCP< LinearOpWithSolveFactoryBase< Scalar > > > &lowsf)
Nonmember constructor.
virtual RCP< PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
Returns null .
Teuchos::ConstNonconstObjectContainer< LinearOpWithSolveFactoryBase< Scalar > > LOWSF_t
virtual void unsetPreconditionerFactory(RCP< PreconditionerFactoryBase< Scalar > > *precFactory, std::string *precFactoryName)
Throws exception.
virtual void initializeOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
virtual void initializeAndReuseOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op) const
virtual bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const
Array< RCP< LinearOpWithSolveFactoryBase< Scalar > > > getUnderlyingLOWSF()
virtual void uninitializeOp(LinearOpWithSolveBase< Scalar > *Op, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc, RCP< const PreconditionerBase< Scalar > > *prec, RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
void informUpdatedVerbosityState() const
Overridden from Teuchos::VerboseObjectBase.
virtual void initializeApproxPreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
virtual void setPreconditionerFactory(const RCP< PreconditionerFactoryBase< Scalar > > &precFactory, const std::string &precFactoryName)
Throws exception.