10 #ifndef ROL_STDLINEAROPERATOR_H
11 #define ROL_STDLINEAROPERATOR_H
15 #include "ROL_LAPACK.hpp"
39 ROL::Ptr<std::vector<Real> >
A_;
54 N_ = (std::round(std::sqrt(N2)));
55 bool isSquare =
N_*
N_ == N2;
56 ROL_TEST_FOR_EXCEPTION( !isSquare, std::invalid_argument,
57 "Error: vector representation of matrix must have a square "
58 "number of elements.");
66 ROL::Ptr<const vector> xp =
dynamic_cast<const SV&
>(x).getVector();
70 virtual void update(
const std::vector<Real> &x,
bool flag =
true,
int iter = -1 ) {}
76 ROL::Ptr<vector> Hvp =
dynamic_cast<SV&
>(Hv).getVector();
77 ROL::Ptr<const vector> vp =
dynamic_cast<const SV&
>(v).getVector();
81 virtual void apply( std::vector<Real> &Hv,
const std::vector<Real> &v, Real &tol )
const {
82 for(
int i=0; i<
N_; ++i ) {
84 for(
int j=0; j<
N_; ++j ) {
85 Hv.at(i) +=
A_->at(N_*j+i)*v.at(j);
94 ROL::Ptr<vector> Hvp =
dynamic_cast<SV&
>(Hv).getVector();
95 ROL::Ptr<const vector> vp =
dynamic_cast<const SV&
>(v).getVector();
99 virtual void applyAdjoint( std::vector<Real> &Hv,
const std::vector<Real> &v, Real &tol )
const {
100 for(
int i=0; i<
N_; ++i ) {
102 for(
int j=0; j<
N_; ++j ) {
103 Hv.at(i) +=
A_->at(N_*i+j)*v.at(j);
114 ROL::Ptr<vector> Hvp =
dynamic_cast<SV&
>(Hv).getVector();
115 ROL::Ptr<const vector> vp =
dynamic_cast<const SV&
>(v).getVector();
119 virtual void applyInverse( std::vector<Real> &Hv,
const std::vector<Real> &v, Real &tol )
const {
132 ROL_TEST_FOR_EXCEPTION(INFO>0,std::logic_error,
"Error in StdLinearOperator::applyInverse(): "
133 "Zero diagonal element encountered in matrix factor U(" << INFO <<
"," << INFO <<
").");
135 ROL_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyInverse(): "
136 "Illegal value encountered in element " << -INFO <<
" when performing LU factorization.");
141 ROL_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyInverse(): "
142 "Illegal value encountered in element " << -INFO <<
" when solving the factorized system. ");
151 ROL::Ptr<vector> Hvp =
dynamic_cast<SV&
>(Hv).getVector();
152 ROL::Ptr<const vector> vp =
dynamic_cast<const SV&
>(v).getVector();
169 ROL_TEST_FOR_EXCEPTION(INFO>0,std::logic_error,
"Error in StdLinearOperator::applyAdjointInverse(): "
170 "Zero diagonal element encountered in matrix factor U(" << INFO <<
"," << INFO <<
").");
172 ROL_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyAdjointInverse(): "
173 "Illegal value encountered in element " << -INFO <<
" when performing LU factorization.");
178 ROL_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyAdjointInverse(): "
179 "Illegal value encountered in element " << -INFO <<
" when solving the factorized system. ");
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
std::vector< Real > vector
virtual void apply(std::vector< Real > &Hv, const std::vector< Real > &v, Real &tol) const
Provides the std::vector implementation to apply a linear operator, which is a std::vector representa...
virtual void applyAdjointInverse(std::vector< Real > &Hv, const std::vector< Real > &v, Real &tol) const
virtual void applyAdjoint(std::vector< Real > &Hv, const std::vector< Real > &v, Real &tol) const
ROL::LAPACK< int, Real > lapack_
Defines the linear algebra or vector space interface.
virtual void applyInverse(std::vector< Real > &Hv, const std::vector< Real > &v, Real &tol) const
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update linear operator.
Provides the interface to apply a linear operator.
void applyAdjointInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply adjoint of the inverse linear operator.
virtual void update(const std::vector< Real > &x, bool flag=true, int iter=-1)
void applyAdjoint(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply adjoint of linear operator.
StdLinearOperator(ROL::Ptr< std::vector< Real > > &A)
virtual ~StdLinearOperator()
ROL::Ptr< std::vector< Real > > A_