44 #ifndef ROL_STDLINEAROPERATOR_H 45 #define ROL_STDLINEAROPERATOR_H 50 #include "Teuchos_BLAS.hpp" 51 #include "Teuchos_LAPACK.hpp" 68 template <
typename T>
using RCP = Teuchos::RCP<T>;
92 N_ = (std::round(std::sqrt(N2)));
93 bool isSquare = N_*N_ == N2;
94 TEUCHOS_TEST_FOR_EXCEPTION( !isSquare, std::invalid_argument,
95 "Error: vector representation of matrix must have a square " 96 "number of elements.");
108 virtual void update(
const std::vector<Real> &x,
bool flag =
true,
int iter = -1 ) {}
113 using Teuchos::dyn_cast;
119 virtual void apply( std::vector<Real> &Hv,
const std::vector<Real> &v, Real &tol )
const {
122 blas_.GEMV(Teuchos::NO_TRANS,N_,N_,1.0,&(*A_)[0],LDA,&(v)[0],1,0.0,&(Hv)[0],1);
128 using Teuchos::dyn_cast;
134 virtual void applyAdjoint( std::vector<Real> &Hv,
const std::vector<Real> &v, Real &tol )
const {
137 blas_.GEMV(Teuchos::TRANS,N_,N_,1.0,&(*A_)[0],LDA,&(v)[0],1,0.0,&(Hv)[0],1);
145 using Teuchos::dyn_cast;
151 virtual void applyInverse( std::vector<Real> &Hv,
const std::vector<Real> &v, Real &tol )
const {
162 lapack_.GETRF(N_,N_,&PLU_[0],LDA,&ipiv_[0],&INFO);
164 TEUCHOS_TEST_FOR_EXCEPTION(INFO>0,std::logic_error,
"Error in StdLinearOperator::applyInverse(): " 165 "Zero diagonal element encountered in matrix factor U(" << INFO <<
"," << INFO <<
").");
167 TEUCHOS_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyInverse(): " 168 "Illegal value encountered in element " << -INFO <<
" when performing LU factorization.");
171 lapack_.GETRS(
'N',N_,NRHS,&PLU_[0],LDA,&ipiv_[0],&Hv[0],LDB,&INFO);
173 TEUCHOS_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyInverse(): " 174 "Illegal value encountered in element " << -INFO <<
" when solving the factorized system. ");
182 using Teuchos::dyn_cast;
199 lapack_.GETRF(N_,N_,&PLU_[0],LDA,&ipiv_[0],&INFO);
201 TEUCHOS_TEST_FOR_EXCEPTION(INFO>0,std::logic_error,
"Error in StdLinearOperator::applyAdjointInverse(): " 202 "Zero diagonal element encountered in matrix factor U(" << INFO <<
"," << INFO <<
").");
204 TEUCHOS_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyAdjointInverse(): " 205 "Illegal value encountered in element " << -INFO <<
" when performing LU factorization.");
208 lapack_.GETRS(
'T',N_,NRHS,&PLU_[0],LDA,&ipiv_[0],&Hv[0],LDB,&INFO);
210 TEUCHOS_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyAdjointInverse(): " 211 "Illegal value encountered in element " << -INFO <<
" when solving the factorized system. ");
std::vector< Real > vector
Provides the std::vector implementation to apply a linear operator, which is a std::vector representa...
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
virtual void applyAdjoint(std::vector< Real > &Hv, const std::vector< Real > &v, Real &tol) const
StdLinearOperator(RCP< std::vector< Real > > &A)
Defines the linear algebra or vector space interface.
void applyAdjointInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply adjoint of the inverse linear operator.
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update linear operator.
Provides the interface to apply a linear operator.
virtual void applyInverse(std::vector< Real > &Hv, const std::vector< Real > &v, Real &tol) const
void applyAdjoint(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply adjoint of linear operator.
Teuchos::BLAS< int, Real > blas_
Teuchos::LAPACK< int, Real > lapack_
virtual void update(const std::vector< Real > &x, bool flag=true, int iter=-1)
virtual void applyAdjointInverse(std::vector< Real > &Hv, const std::vector< Real > &v, Real &tol) const
virtual void apply(std::vector< Real > &Hv, const std::vector< Real > &v, Real &tol) const
virtual ~StdLinearOperator()
RCP< std::vector< Real > > A_