Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Thyra_MultiVectorPreconditioner.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Thyra_MultiVectorPreconditioner_hpp
10 #define Thyra_MultiVectorPreconditioner_hpp
11 
12 #include "Thyra_PreconditionerBase.hpp"
13 #include "Teuchos_ConstNonconstObjectContainer.hpp"
15 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
16 
17 namespace Thyra {
18 
19 /** \brief Concrete <tt>PreconditionerBase</tt> subclass that
20  * wraps a preconditioner operator in MultiVectorLinearOp.
21  */
22 template<class Scalar>
23 class MultiVectorPreconditioner : virtual public PreconditionerBase<Scalar>
24 {
25 public:
26 
27  /** @name Constructors/initializers/accessors */
28  //@{
29 
30  /** \brief Construct to uninitialized. */
32 
34  const RCP<PreconditionerBase<Scalar> > &prec,
35  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
36  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
37  ) {
38  validateInitialize(prec,multiVecRange,multiVecDomain);
39  prec_ = prec;
40  multiVecRange_ = multiVecRange;
41  multiVecDomain_ = multiVecDomain;
42  }
43 
44  void initialize(
45  const RCP<const PreconditionerBase<Scalar> > &prec,
46  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
47  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain) {
48  validateInitialize(prec,multiVecRange,multiVecDomain);
49  prec_ = prec;
50  multiVecRange_ = multiVecRange;
51  multiVecDomain_ = multiVecDomain;
52  }
53 
54  RCP<PreconditionerBase<Scalar> >
55  getNonconstPreconditioner() { return prec_.getNonconstObj(); }
56 
57  RCP<const PreconditionerBase<Scalar> >
58  getPreconditioner() const { return prec_.getConstObj(); }
59 
60  void uninitialize() {
61  prec_.uninitialize();
62  multiVecRange_ = Teuchos::null;
63  multiVecDomain_ = Teuchos::null;
64  }
65 
66  //@}
67 
68  /** @name Overridden from PreconditionerBase */
69  //@{
70 
71  bool isLeftPrecOpConst() const
72  { return prec_.getConstObj()->isLeftPrecOpConst(); }
73 
74  Teuchos::RCP<LinearOpBase<Scalar> > getNonconstLeftPrecOp()
75  { return nonconstMultiVectorLinearOp(
76  prec_.getNonconstObj()->getNonconstLeftPrecOp(),
78  multiVecDomain_); }
79 
80  Teuchos::RCP<const LinearOpBase<Scalar> > getLeftPrecOp() const
81  { return multiVectorLinearOp(
82  prec_.getConstObj()->getLeftPrecOp(),
84  multiVecDomain_); }
85 
86  bool isRightPrecOpConst() const
87  { return prec_.getConstObj()->isRightPrecOpConst(); }
88 
89  Teuchos::RCP<LinearOpBase<Scalar> > getNonconstRightPrecOp()
90  { return nonconstMultiVectorLinearOp(
91  prec_.getNonconstObj()->getNonconstRightPrecOp(),
93  multiVecDomain_); }
94 
95  Teuchos::RCP<const LinearOpBase<Scalar> > getRightPrecOp() const
96  { return multiVectorLinearOp(
97  prec_.getConstObj()->getRightPrecOp(),
99  multiVecDomain_); }
100 
102  { return prec_.getConstObj()->isUnspecifiedPrecOpConst(); }
103 
104  Teuchos::RCP<LinearOpBase<Scalar> > getNonconstUnspecifiedPrecOp()
105  { return nonconstMultiVectorLinearOp(
106  prec_.getNonconstObj()->getNonconstUnspecifiedPrecOp(),
108  multiVecDomain_); }
109 
110  Teuchos::RCP<const LinearOpBase<Scalar> > getUnspecifiedPrecOp() const
111  { return multiVectorLinearOp(
112  prec_.getNonconstObj()->getUnspecifiedPrecOp(),
114  multiVecDomain_); }
115 
116  //@}
117 
118 private:
119 
120  // //////////////////////////////
121  // Private types
122 
123  typedef Teuchos::ConstNonconstObjectContainer<PreconditionerBase<Scalar> > CNPB;
124 
125  // //////////////////////////////
126  // Private data members
127 
129  RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > multiVecRange_;
130  RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > multiVecDomain_;
131 
132  // //////////////////////////////
133  // Private member functions
134 
135  static void validateInitialize(
136  const RCP<const PreconditionerBase<Scalar> > &prec,
137  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
138  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
139  ) {
140 #ifdef TEUCHOS_DEBUG
141  TEUCHOS_TEST_FOR_EXCEPT(is_null(prec));
142  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecRange));
143  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecDomain));
144  TEUCHOS_TEST_FOR_EXCEPT( multiVecRange->numBlocks() != multiVecDomain->numBlocks() );
145 #else
146  (void)prec;
147  (void)multiVecRange;
148  (void)multiVecDomain;
149 #endif
150  }
151 
152 };
153 
154 /** \brief Nonmember constructor function.
155  *
156  * \relates MultiVectorPreconditioner
157  */
158 template<class Scalar>
159 RCP<MultiVectorPreconditioner<Scalar> >
161 {
162  return Teuchos::rcp(new MultiVectorPreconditioner<Scalar>());
163 }
164 
165 /** \brief Nonmember constructor function.
166  *
167  * \relates MultiVectorPreconditioner
168  */
169 template<class Scalar>
170 RCP<MultiVectorPreconditioner<Scalar> >
172  const RCP<PreconditionerBase<Scalar> > &prec,
173  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
174  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
175  )
176 {
177  RCP<MultiVectorPreconditioner<Scalar> >
178  mvprec = Teuchos::rcp(new MultiVectorPreconditioner<Scalar>());
179  mvprec->nonconstInitialize(prec,multiVecRange,multiVecDomain);
180  return mvprec;
181 }
182 
183 /** \brief Nonmember constructor function.
184  *
185  * \relates MultiVectorPreconditioner
186  */
187 template<class Scalar>
188 RCP<MultiVectorPreconditioner<Scalar> >
190  const RCP<const PreconditionerBase<Scalar> > &prec,
191  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
192  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
193  )
194 {
195  RCP<MultiVectorPreconditioner<Scalar> >
196  mvprec = Teuchos::rcp(new MultiVectorPreconditioner<Scalar>());
197  mvprec->initialize(prec,multiVecRange,multiVecDomain);
198  return mvprec;
199 }
200 
201 } // end namespace Thyra
202 
203 #endif
Teuchos::RCP< LinearOpBase< Scalar > > getNonconstLeftPrecOp()
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
static void validateInitialize(const RCP< const PreconditionerBase< Scalar > > &prec, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
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.
void initialize(const RCP< const PreconditionerBase< Scalar > > &prec, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)