49 #ifndef ROL_HELPERFUNCTIONS_HPP
50 #define ROL_HELPERFUNCTIONS_HPP
56 #include "Teuchos_SerialDenseMatrix.hpp"
57 #include "Teuchos_SerialDenseVector.hpp"
58 #include "Teuchos_LAPACK.hpp"
65 Real tol = std::sqrt(ROL_EPSILON<Real>());
68 Teuchos::SerialDenseMatrix<int, Real> H(dim, dim);
70 ROL::Ptr<Vector<Real> > e = x.
clone();
71 ROL::Ptr<Vector<Real> > h = x.
dual().
clone();
73 for (
int i=0; i<dim; i++) {
76 for (
int j=0; j<dim; j++) {
78 H(j,i) = e->dot(h->dual());
90 Real tol = std::sqrt(ROL_EPSILON<Real>());
93 Teuchos::SerialDenseMatrix<int, Real> H(dim, dim);
95 ROL::Ptr<Vector<Real> > ei = x.
clone();
96 ROL::Ptr<Vector<Real> > ej = x.
dual().
clone();
97 ROL::Ptr<Vector<Real> > h = x.
dual().
clone();
99 for (
int i=0; i<dim; i++) {
102 for (
int j=0; j<dim; j++) {
104 H(j,i) = ej->dot(*h);
117 Teuchos::SerialDenseMatrix<int, Real> M(dim, dim);
119 ROL::Ptr<Vector<Real> > ei = x.
clone();
120 ROL::Ptr<Vector<Real> > ej = x.
clone();
122 for (
int i=0; i<dim; i++) {
124 for (
int j=0; j<dim; j++) {
126 M(j,i) = ej->dot(*ei);
135 std::vector<std::vector<Real> >
computeEigenvalues(
const Teuchos::SerialDenseMatrix<int, Real> & mat) {
137 Teuchos::LAPACK<int, Real> lapack;
139 Teuchos::SerialDenseMatrix<int, Real> mymat(Teuchos::Copy, mat);
144 int n = mat.numRows();
146 std::vector<Real> real(n, 0);
147 std::vector<Real> imag(n, 0);
148 std::vector<std::vector<Real> > eigenvals;
158 std::vector<Real> work(lwork, 0);
162 lapack.GEEV(jobvl, jobvr, n, &mymat(0,0), n, &real[0], &imag[0], vl, ldvl, vr, ldvr, &work[0], lwork, &info);
164 eigenvals.push_back(real);
165 eigenvals.push_back(imag);
174 const Teuchos::SerialDenseMatrix<int, Real> & B) {
176 Teuchos::LAPACK<int, Real> lapack;
178 Teuchos::SerialDenseMatrix<int, Real> myA(Teuchos::Copy, A);
179 Teuchos::SerialDenseMatrix<int, Real> myB(Teuchos::Copy, B);
186 std::vector<Real> real(n, 0);
187 std::vector<Real> imag(n, 0);
188 std::vector<Real> beta(n, 0);
189 std::vector<std::vector<Real> > eigenvals;
199 std::vector<Real> work(lwork, 0);
203 lapack.GGEV(jobvl, jobvr, n, &myA(0,0), n, &myB(0,0), n, &real[0], &imag[0], &beta[0],
204 vl, ldvl, vr, ldvr, &work[0], lwork, &info);
206 for (
int i=0; i<n; i++) {
211 eigenvals.push_back(real);
212 eigenvals.push_back(imag);
220 Teuchos::SerialDenseMatrix<int, Real>
computeInverse(
const Teuchos::SerialDenseMatrix<int, Real> & mat) {
222 Teuchos::LAPACK<int, Real> lapack;
224 Teuchos::SerialDenseMatrix<int, Real> mymat(Teuchos::Copy, mat);
226 int n = mat.numRows();
228 std::vector<int> ipiv(n, 0);
232 std::vector<Real> work(lwork, 0);
236 lapack.GETRF(n, n, &mymat(0,0), n, &ipiv[0], &info);
237 lapack.GETRI(n, &mymat(0,0), n, &ipiv[0], &work[0], lwork, &info);
248 ROL::Ptr<Objective<Real> >
obj_;
249 ROL::Ptr<BoundConstraint<Real> >
con_;
263 bool useSecantPrecond =
false,
264 bool useSecantHessVec =
false,
268 obj_ = ROL::makePtrFromRef(obj);
269 con_ = ROL::makePtrFromRef(con);
274 obj_->update(x,flag,iter);
275 con_->update(x,flag,iter);
279 return obj_->value(x,tol);
283 obj_->gradient(g,x,tol);
287 return obj_->dirDeriv(x,d,tol);
295 obj_->hessVec( Hv, v, x, tol );
304 obj_->invHessVec(Hv,v,x,tol);
313 obj_->precond( Mv, v, x, tol );
330 if (
con_->isActivated() ) {
370 if (
con_->isActivated() ) {
411 if (
con_->isActivated() ) {
451 if (
con_->isActivated() ) {
492 if (
con_->isActivated() ) {
532 if (
con_->isActivated() ) {
581 return con_->isFeasible(v);
585 return con_->isActivated();
589 con_->computeProjectedStep(v,x);