Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_MultiVectorPreconditioner.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_MultiVectorPreconditioner_hpp
11 #define Thyra_MultiVectorPreconditioner_hpp
12 
13 #include "Thyra_PreconditionerBase.hpp"
14 #include "Teuchos_ConstNonconstObjectContainer.hpp"
16 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
17 
18 namespace Thyra {
19 
23 template <class Scalar>
24 class MultiVectorPreconditioner : virtual public PreconditionerBase<Scalar> {
25  public:
28 
31 
33  const RCP<PreconditionerBase<Scalar> > &prec,
35  &multiVecRange,
37  &multiVecDomain)
38  {
39  validateInitialize(prec, multiVecRange, multiVecDomain);
40  prec_ = prec;
41  multiVecRange_ = multiVecRange;
42  multiVecDomain_ = multiVecDomain;
43  }
44 
45  void initialize(const RCP<const PreconditionerBase<Scalar> > &prec,
47  &multiVecRange,
49  &multiVecDomain)
50  {
51  validateInitialize(prec, multiVecRange, multiVecDomain);
52  prec_ = prec;
53  multiVecRange_ = multiVecRange;
54  multiVecDomain_ = multiVecDomain;
55  }
56 
57  RCP<PreconditionerBase<Scalar> > getNonconstPreconditioner()
58  {
59  return prec_.getNonconstObj();
60  }
61 
62  RCP<const PreconditionerBase<Scalar> > getPreconditioner() const
63  {
64  return prec_.getConstObj();
65  }
66 
67  void uninitialize()
68  {
70  multiVecRange_ = Teuchos::null;
71  multiVecDomain_ = Teuchos::null;
72  }
73 
75 
78 
79  bool isLeftPrecOpConst() const
80  {
81  return prec_.getConstObj()->isLeftPrecOpConst();
82  }
83 
85  {
86  return nonconstMultiVectorLinearOp(
87  prec_.getNonconstObj()->getNonconstLeftPrecOp(), multiVecRange_,
89  }
90 
92  {
93  return multiVectorLinearOp(prec_.getConstObj()->getLeftPrecOp(),
95  }
96 
97  bool isRightPrecOpConst() const
98  {
99  return prec_.getConstObj()->isRightPrecOpConst();
100  }
101 
103  {
104  return nonconstMultiVectorLinearOp(
105  prec_.getNonconstObj()->getNonconstRightPrecOp(), multiVecRange_,
107  }
108 
110  {
111  return multiVectorLinearOp(prec_.getConstObj()->getRightPrecOp(),
113  }
114 
116  {
117  return prec_.getConstObj()->isUnspecifiedPrecOpConst();
118  }
119 
121  {
122  return nonconstMultiVectorLinearOp(
123  prec_.getNonconstObj()->getNonconstUnspecifiedPrecOp(), multiVecRange_,
125  }
126 
128  {
129  return multiVectorLinearOp(prec_.getNonconstObj()->getUnspecifiedPrecOp(),
131  }
132 
134 
135  private:
136  // //////////////////////////////
137  // Private types
138 
141 
142  // //////////////////////////////
143  // Private data members
144 
146  RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > multiVecRange_;
147  RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > multiVecDomain_;
148 
149  // //////////////////////////////
150  // Private member functions
151 
152  static void validateInitialize(
153  const RCP<const PreconditionerBase<Scalar> > &prec,
155  &multiVecRange,
157  &multiVecDomain)
158  {
159 #ifdef TEUCHOS_DEBUG
161  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecRange));
162  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecDomain));
163  TEUCHOS_TEST_FOR_EXCEPT(multiVecRange->numBlocks() !=
164  multiVecDomain->numBlocks());
165 #else
166  (void)prec;
167  (void)multiVecRange;
168  (void)multiVecDomain;
169 #endif
170  }
171 };
172 
177 template <class Scalar>
178 RCP<MultiVectorPreconditioner<Scalar> > multiVectorPreconditioner()
179 {
181 }
182 
187 template <class Scalar>
188 RCP<MultiVectorPreconditioner<Scalar> > nonconstMultiVectorPreconditioner(
189  const RCP<PreconditionerBase<Scalar> > &prec,
191  &multiVecRange,
193  &multiVecDomain)
194 {
195  RCP<MultiVectorPreconditioner<Scalar> > mvprec =
197  mvprec->nonconstInitialize(prec, multiVecRange, multiVecDomain);
198  return mvprec;
199 }
200 
205 template <class Scalar>
206 RCP<MultiVectorPreconditioner<Scalar> > multiVectorPreconditioner(
207  const RCP<const PreconditionerBase<Scalar> > &prec,
209  &multiVecRange,
211  &multiVecDomain)
212 {
213  RCP<MultiVectorPreconditioner<Scalar> > mvprec =
215  mvprec->initialize(prec, multiVecRange, multiVecDomain);
216  return mvprec;
217 }
218 
219 } // end namespace Thyra
220 
221 #endif
Teuchos::RCP< LinearOpBase< Scalar > > getNonconstLeftPrecOp()
bool is_null(const boost::shared_ptr< T > &p)
RCP< PreconditionerBase< Scalar > > getNonconstPreconditioner()
void nonconstInitialize(const RCP< PreconditionerBase< Scalar > > &prec, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
Teuchos::RCP< const LinearOpBase< Scalar > > getLeftPrecOp() const
RCP< MultiVectorPreconditioner< Scalar > > multiVectorPreconditioner()
Nonmember constructor function.
RCP< const PreconditionerBase< Scalar > > getPreconditioner() const
Teuchos::ConstNonconstObjectContainer< PreconditionerBase< Scalar > > CNPB
RCP< MultiVectorPreconditioner< Scalar > > nonconstMultiVectorPreconditioner(const RCP< PreconditionerBase< Scalar > > &prec, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
Nonmember constructor function.
Teuchos::RCP< const LinearOpBase< Scalar > > getRightPrecOp() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static void validateInitialize(const RCP< const PreconditionerBase< Scalar > > &prec, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
RCP< const ObjType > getConstObj() const
RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > multiVecRange_
Teuchos::RCP< LinearOpBase< Scalar > > getNonconstRightPrecOp()
RCP< MultiVectorPreconditioner< Scalar > > multiVectorPreconditioner(const RCP< const PreconditionerBase< Scalar > > &prec, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
Nonmember constructor function.
RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > multiVecDomain_
Teuchos::RCP< const LinearOpBase< Scalar > > getUnspecifiedPrecOp() const
Teuchos::RCP< LinearOpBase< Scalar > > getNonconstUnspecifiedPrecOp()
Concrete PreconditionerBase subclass that wraps a preconditioner operator in MultiVectorLinearOp.
MultiVectorPreconditioner()
Construct to uninitialized.
RCP< ObjType > getNonconstObj() const
void initialize(const RCP< const PreconditionerBase< Scalar > > &prec, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)