Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultMultiVectorLinearOpWithSolve_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_MULTI_VECTOR_LINEAR_OP_WITH_SOLVE_HPP
11 #define THYRA_MULTI_VECTOR_LINEAR_OP_WITH_SOLVE_HPP
12 
13 #include "Thyra_DefaultMultiVectorLinearOpWithSolve_decl.hpp"
14 #include "Thyra_DefaultDiagonalLinearOp.hpp"
15 #include "Thyra_LinearOpWithSolveBase.hpp"
16 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
17 #include "Thyra_DefaultMultiVectorProductVector.hpp"
18 #include "Thyra_AssertOp.hpp"
19 #include "Teuchos_dyn_cast.hpp"
20 
21 
22 namespace Thyra {
23 
24 
25 // Constructors/initializers/accessors
26 
27 
28 template<class Scalar>
30 {}
31 
32 
33 template<class Scalar>
35  const RCP<LinearOpWithSolveBase<Scalar> > &lows,
36  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
37  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
38  )
39 {
40  validateInitialize(lows,multiVecRange,multiVecDomain);
41  lows_ = lows;
42  multiVecRange_ = multiVecRange;
43  multiVecDomain_ = multiVecDomain;
44 }
45 
46 
47 template<class Scalar>
49  const RCP<const LinearOpWithSolveBase<Scalar> > &lows,
50  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
51  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
52  )
53 {
54  validateInitialize(lows,multiVecRange,multiVecDomain);
55  lows_ = lows;
56  multiVecRange_ = multiVecRange;
57  multiVecDomain_ = multiVecDomain;
58 }
59 
60 
61 template<class Scalar>
64 {
65  return lows_.getNonconstObj();
66 }
67 
68 
69 template<class Scalar>
72 {
73  return lows_.getConstObj();
74 }
75 
76 
77 template<class Scalar>
79 {
80  lows_.uninitialize();
81  multiVecRange_ = Teuchos::null;
82  multiVecDomain_ = Teuchos::null;
83 }
84 
85 
86 // Overridden from LinearOpBase
87 
88 
89 template<class Scalar>
92 {
93  return multiVecRange_;
94 }
95 
96 
97 template<class Scalar>
100 {
101  return multiVecDomain_;
102 }
103 
104 
105 template<class Scalar>
108 {
109  return Teuchos::null; // ToDo: Implement if needed ???
110 }
111 
112 
113 // protected
114 
115 
116 // Overridden from LinearOpBase
117 
118 
119 template<class Scalar>
121  EOpTransp M_trans
122  ) const
123 {
124  return Thyra::opSupported(*lows_.getConstObj(),M_trans);
125 }
126 
127 
128 template<class Scalar>
130  const EOpTransp M_trans,
131  const MultiVectorBase<Scalar> &XX,
132  const Ptr<MultiVectorBase<Scalar> > &YY,
133  const Scalar alpha,
134  const Scalar beta
135  ) const
136 {
137 
138  using Teuchos::dyn_cast;
140 
141  const Ordinal numCols = XX.domain()->dim();
142 
143  for (Ordinal col_j = 0; col_j < numCols; ++col_j) {
144 
145  const RCP<const VectorBase<Scalar> > x = XX.col(col_j);
146  const RCP<VectorBase<Scalar> > y = YY->col(col_j);
147 
149  X = dyn_cast<const MVPV>(*x).getMultiVector().assert_not_null();
151  Y = dyn_cast<MVPV>(*y).getNonconstMultiVector().assert_not_null();
152 
153  Thyra::apply( *lows_.getConstObj(), M_trans, *X, Y.ptr(), alpha, beta );
154 
155  }
156 
157 }
158 
159 
160 // Overridden from LinearOpWithSolveBase
161 
162 
163 template<class Scalar>
164 bool
166  EOpTransp M_trans
167  ) const
168 {
169  return Thyra::solveSupports(*lows_.getConstObj(),M_trans);
170 }
171 
172 
173 template<class Scalar>
174 bool
176  EOpTransp M_trans, const SolveMeasureType& solveMeasureType
177  ) const
178 {
179  return Thyra::solveSupportsSolveMeasureType(
180  *lows_.getConstObj(),M_trans,solveMeasureType);
181 }
182 
183 
184 template<class Scalar>
187  const EOpTransp transp,
188  const MultiVectorBase<Scalar> &BB,
189  const Ptr<MultiVectorBase<Scalar> > &XX,
190  const Ptr<const SolveCriteria<Scalar> > solveCriteria
191  ) const
192 {
193 
194  using Teuchos::dyn_cast;
195  using Teuchos::outArg;
196  using Teuchos::inOutArg;
198 
199  const Ordinal numCols = BB.domain()->dim();
200 
201  SolveStatus<Scalar> overallSolveStatus;
202  accumulateSolveStatusInit(outArg(overallSolveStatus));
203 
204  for (Ordinal col_j = 0; col_j < numCols; ++col_j) {
205 
206  const RCP<const VectorBase<Scalar> > b = BB.col(col_j);
207  const RCP<VectorBase<Scalar> > x = XX->col(col_j);
208 
210  B = dyn_cast<const MVPV>(*b).getMultiVector().assert_not_null();
212  X = dyn_cast<MVPV>(*x).getNonconstMultiVector().assert_not_null();
213 
214  const SolveStatus<Scalar> solveStatus =
215  Thyra::solve(*lows_.getConstObj(), transp, *B, X.ptr(), solveCriteria);
216 
217  accumulateSolveStatus(
218  SolveCriteria<Scalar>(), // Never used
219  solveStatus, inOutArg(overallSolveStatus) );
220 
221  }
222 
223  return overallSolveStatus;
224 
225 }
226 
227 
228 // private
229 
230 
231 template<class Scalar>
233  const RCP<const LinearOpWithSolveBase<Scalar> > &lows,
234  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecRange,
235  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &multiVecDomain
236  )
237 {
238 #ifdef TEUCHOS_DEBUG
240  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecRange));
241  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVecDomain));
242  TEUCHOS_TEST_FOR_EXCEPT( multiVecRange->numBlocks() != multiVecDomain->numBlocks() );
243  if (lows->range() != Teuchos::null)
245  "DefaultMultiVectorLinearOpWithSolve<Scalar>::initialize(lows,multiVecRange,multiVecDomain)",
246  *lows->range(), *multiVecRange->getBlock(0) );
247  if (lows->domain() != Teuchos::null)
249  "DefaultMultiVectorLinearOpWithSolve<Scalar>::initialize(lows,multiVecRange,multiVecDomain)",
250  *lows->domain(), *multiVecDomain->getBlock(0) );
251 #else
252  (void)lows;
253  (void)multiVecRange;
254  (void)multiVecDomain;
255 #endif
256 }
257 
258 
259 } // end namespace Thyra
260 
261 
262 #endif // THYRA_MULTI_VECTOR_LINEAR_OP_WITH_SOLVE_HPP
#define THYRA_ASSERT_VEC_SPACES(FUNC_NAME, VS1, VS2)
This is a very useful macro that should be used to validate that two vector spaces are compatible...
Implicit concrete LinearOpWithSolveBase subclass that takes a flattended out multi-vector and perform...
Base class for all linear operators that can support a high-level solve operation.
bool is_null(const boost::shared_ptr< T > &p)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
T_To & dyn_cast(T_From &from)
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Concrete implementation of a product vector which is really composed out of the columns of a multi-ve...
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
RCP< const LinearOpWithSolveBase< Scalar > > getLinearOpWithSolve() const
Interface for a collection of column vectors called a multi-vector.
Ptr< T > ptr() const
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
void nonconstInitialize(const RCP< LinearOpWithSolveBase< Scalar > > &lows, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)
Simple struct for the return status from a solve.
Standard concrete implementation of a product vector space that creates product vectors fromed implic...
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
SolveStatus< Scalar > solveImpl(const EOpTransp transp, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > > solveCriteria) const
Simple struct that defines the requested solution criteria for a solve.
bool solveSupportsSolveMeasureTypeImpl(EOpTransp M_trans, const SolveMeasureType &solveMeasureType) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void initialize(const RCP< const LinearOpWithSolveBase< Scalar > > &lows, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecRange, const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &multiVecDomain)