44 #ifndef ROL_STDLINEAROPERATOR_H
45 #define ROL_STDLINEAROPERATOR_H
49 #include "ROL_LAPACK.hpp"
73 ROL::Ptr<std::vector<Real> >
A_;
88 N_ = (std::round(std::sqrt(N2)));
89 bool isSquare =
N_*
N_ == N2;
90 ROL_TEST_FOR_EXCEPTION( !isSquare, std::invalid_argument,
91 "Error: vector representation of matrix must have a square "
92 "number of elements.");
100 ROL::Ptr<const vector> xp =
dynamic_cast<const SV&
>(x).getVector();
104 virtual void update(
const std::vector<Real> &x,
bool flag =
true,
int iter = -1 ) {}
110 ROL::Ptr<vector> Hvp =
dynamic_cast<SV&
>(Hv).getVector();
111 ROL::Ptr<const vector> vp =
dynamic_cast<const SV&
>(v).getVector();
115 virtual void apply( std::vector<Real> &Hv,
const std::vector<Real> &v, Real &tol )
const {
116 for(
int i=0; i<
N_; ++i ) {
118 for(
int j=0; j<
N_; ++j ) {
119 Hv.at(i) +=
A_->at(N_*j+i)*v.at(j);
128 ROL::Ptr<vector> Hvp =
dynamic_cast<SV&
>(Hv).getVector();
129 ROL::Ptr<const vector> vp =
dynamic_cast<const SV&
>(v).getVector();
133 virtual void applyAdjoint( std::vector<Real> &Hv,
const std::vector<Real> &v, Real &tol )
const {
134 for(
int i=0; i<
N_; ++i ) {
136 for(
int j=0; j<
N_; ++j ) {
137 Hv.at(i) +=
A_->at(N_*i+j)*v.at(j);
148 ROL::Ptr<vector> Hvp =
dynamic_cast<SV&
>(Hv).getVector();
149 ROL::Ptr<const vector> vp =
dynamic_cast<const SV&
>(v).getVector();
153 virtual void applyInverse( std::vector<Real> &Hv,
const std::vector<Real> &v, Real &tol )
const {
166 ROL_TEST_FOR_EXCEPTION(INFO>0,std::logic_error,
"Error in StdLinearOperator::applyInverse(): "
167 "Zero diagonal element encountered in matrix factor U(" << INFO <<
"," << INFO <<
").");
169 ROL_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyInverse(): "
170 "Illegal value encountered in element " << -INFO <<
" when performing LU factorization.");
175 ROL_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyInverse(): "
176 "Illegal value encountered in element " << -INFO <<
" when solving the factorized system. ");
185 ROL::Ptr<vector> Hvp =
dynamic_cast<SV&
>(Hv).getVector();
186 ROL::Ptr<const vector> vp =
dynamic_cast<const SV&
>(v).getVector();
203 ROL_TEST_FOR_EXCEPTION(INFO>0,std::logic_error,
"Error in StdLinearOperator::applyAdjointInverse(): "
204 "Zero diagonal element encountered in matrix factor U(" << INFO <<
"," << INFO <<
").");
206 ROL_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyAdjointInverse(): "
207 "Illegal value encountered in element " << -INFO <<
" when performing LU factorization.");
212 ROL_TEST_FOR_EXCEPTION(INFO<0,std::logic_error,
"Error in StdLinearOperator::applyAdjointInverse(): "
213 "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_