Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultSerialDenseLinearOpWithSolve_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_SERIAL_DENSE_LINEAR_OP_WITH_SOLVE_HPP
11 #define THYRA_DEFAULT_SERIAL_DENSE_LINEAR_OP_WITH_SOLVE_HPP
12 
13 
14 #include "Thyra_DefaultSerialDenseLinearOpWithSolve_decl.hpp"
15 #include "Thyra_LinearOpWithSolveBase.hpp"
16 #include "Thyra_DetachedMultiVectorView.hpp"
17 #include "Thyra_MultiVectorStdOps.hpp"
18 #include "Thyra_AssertOp.hpp"
19 #include "Teuchos_Assert.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<const MultiVectorBase<Scalar> > &M )
36 {
37  using Teuchos::outArg;
38 #ifdef TEUCHOS_DEBUG
40  TEUCHOS_ASSERT(isFullyInitialized(*M));
41  TEUCHOS_ASSERT(M->range()->hasInCoreView());
42  TEUCHOS_ASSERT(M->domain()->hasInCoreView());
43  THYRA_ASSERT_VEC_SPACES("", *M->range(), *M->domain());
44 #endif
45  factorize(*M, outArg(LU_), outArg(ipiv_));
46  M_ = M;
47 }
48 
49 template<class Scalar>
51 {
52  return M_;
53 }
54 
55 // Overridden from LinearOpBase
56 
57 
58 template<class Scalar>
61 {
62  if (!is_null(M_))
63  return M_->range();
64  return Teuchos::null;
65 }
66 
67 
68 template<class Scalar>
71 {
72  if (!is_null(M_))
73  return M_->domain();
74  return Teuchos::null;
75 }
76 
77 
78 // protected
79 
80 
81 // Overridden from LinearOpBase
82 
83 
84 template<class Scalar>
86  EOpTransp M_trans) const
87 {
88  return Thyra::opSupported(*M_, M_trans);
89 }
90 
91 
92 template<class Scalar>
94  const EOpTransp M_trans,
95  const MultiVectorBase<Scalar> &X,
96  const Ptr<MultiVectorBase<Scalar> > &Y,
97  const Scalar alpha,
98  const Scalar beta
99  ) const
100 {
101  Thyra::apply( *M_, M_trans, X, Y, alpha, beta );
102 }
103 
104 
105 // Overridden from LinearOpWithSolveBase
106 
107 
108 template<class Scalar>
110  EOpTransp M_trans) const
111 {
113  return ( ST::isComplex ? ( M_trans!=CONJ ) : true );
114 }
115 
116 
117 template<class Scalar>
119  EOpTransp M_trans, const SolveMeasureType& /* solveMeasureType */) const
120 {
121  // We support all solve measures since we are a direct solver
122  return this->solveSupportsImpl(M_trans);
123 }
124 
125 
126 template<class Scalar>
129  const EOpTransp M_trans,
130  const MultiVectorBase<Scalar> &B,
131  const Ptr<MultiVectorBase<Scalar> > &X,
132  const Ptr<const SolveCriteria<Scalar> > /* solveCriteria */
133  ) const
134 {
135 #ifdef TEUCHOS_DEBUG
137  "DefaultSerialDenseLinearOpWithSolve<Scalar>::solve(...)",
138  *this, M_trans, *X, &B );
139 #endif
140  backsolve( LU_, ipiv_, M_trans, B, X );
141  SolveStatus<Scalar> solveStatus;
142  solveStatus.solveStatus = SOLVE_STATUS_CONVERGED;\
143  return solveStatus;
144 }
145 
146 
147 // private
148 
149 
150 template<class Scalar>
152  const MultiVectorBase<Scalar> &M,
154  const Ptr<Array<int> > &ipiv
155  )
156 {
157  using Teuchos::outArg;
159  const int dim = dM.subDim();
160  ipiv->resize(dim);
161  RTOpPack::SubMultiVectorView<Scalar> LU_tmp(dim, dim);
162  RTOpPack::assign_entries<Scalar>( outArg(LU_tmp), dM.smv() );
163  int rank = -1;
164  RTOpPack::getrf<Scalar>( LU_tmp, (*ipiv)(), outArg(rank) );
165  TEUCHOS_ASSERT_EQUALITY( dim, rank );
166  *LU = LU_tmp; // Weak copy
167 }
168 
169 
170 template<class Scalar>
171 void DefaultSerialDenseLinearOpWithSolve<Scalar>::backsolve(
173  const ArrayView<const int> ipiv,
174  const EOpTransp transp,
175  const MultiVectorBase<Scalar> &B,
176  const Ptr<MultiVectorBase<Scalar> > &X
177  )
178 {
179  using Teuchos::outArg;
180  assign( X, B );
181  DetachedMultiVectorView<Scalar> dX(*X);
182  RTOpPack::getrs<Scalar>( LU, ipiv, convertToRTOpPackETransp(transp),
183  outArg(dX.smv()) );
184 }
185 
186 
187 } // end namespace Thyra
188 
189 
190 #endif // THYRA_DEFAULT_SERIAL_DENSE_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...
Create an explicit non-mutable (const) view of a MultiVectorBase object.
SolveStatus< Scalar > solveImpl(const EOpTransp transp, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > > solveCriteria) const
bool is_null(const boost::shared_ptr< T > &p)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
#define THYRA_ASSERT_LINEAR_OP_MULTIVEC_APPLY_SPACES(FUNC_NAME, M, M_T, X, Y)
This is a very useful macro that should be used to validate that the spaces for the multi-vector vers...
Simple concreate subclass of LinearOpWithSolveBase for serial dense matrices implemented using LAPACK...
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
bool solveSupportsSolveMeasureTypeImpl(EOpTransp M_trans, const SolveMeasureType &solveMeasureType) const
void initialize(const RCP< const MultiVectorBase< Scalar > > &M)
Interface for a collection of column vectors called a multi-vector.
Simple struct for the return status from a solve.
ESolveStatus solveStatus
The return status of the solve.
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
The requested solution criteria has likely been achieved.
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
Simple struct that defines the requested solution criteria for a solve.