19 #ifndef ROL_PARABOLOIDCIRCLE_HPP
20 #define ROL_PARABOLOIDCIRCLE_HPP
24 #include "Teuchos_SerialDenseVector.hpp"
25 #include "Teuchos_SerialDenseSolver.hpp"
33 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real> >
44 template<
class VectorType>
47 return dynamic_cast<const VectorType&
>(x).
getVector();
50 template<
class VectorType>
53 return dynamic_cast<VectorType&
>(x).
getVector();
62 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
65 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective value): "
66 "Primal vector x must be of length 2.");
71 Real val = x1*x1 + x2*x2;
79 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
80 ROL::Ptr<vector> gp = getVector<XDual>(g);
83 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective gradient): "
84 " Primal vector x must be of length 2.");
87 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective gradient): "
88 "Gradient vector g must be of length 2.");
102 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
103 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
104 ROL::Ptr<vector> hvp = getVector<XDual>(hv);
107 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): "
108 "Primal vector x must be of length 2.");
111 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): "
112 "Input vector v must be of length 2.");
115 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): "
116 "Output vector hv must be of length 2.");
132 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
141 template<
class VectorType>
144 return dynamic_cast<const VectorType&
>(x).
getVector();
147 template<
class VectorType>
150 return dynamic_cast<VectorType&
>(x).
getVector();
159 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
160 ROL::Ptr<vector> cp = getVector<CPrim>(c);
163 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint value): "
164 "Primal vector x must be of length 2.");
167 ROL_TEST_FOR_EXCEPTION( (m != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint value): "
168 "Constraint vector c must be of length 1.");
175 (*cp)[0] = (x1-two)*(x1-two) + x2*x2 - one;
181 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
182 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
183 ROL::Ptr<vector> jvp = getVector<CPrim>(jv);
186 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): "
187 "Primal vector x must be of length 2.");
190 ROL_TEST_FOR_EXCEPTION( (d != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): "
191 "Input vector v must be of length 2.");
193 ROL_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): "
194 "Output vector jv must be of length 1.");
204 (*jvp)[0] = two*(x1-two)*v1 + two*x2*v2;
210 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
211 ROL::Ptr<const vector> vp = getVector<CDual>(v);
212 ROL::Ptr<vector> ajvp = getVector<XDual>(ajv);
215 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): "
216 "Primal vector x must be of length 2.");
219 ROL_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): "
220 "Input vector v must be of length 1.");
223 ROL_TEST_FOR_EXCEPTION( (d != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): "
224 "Output vector ajv must be of length 2.");
233 (*ajvp)[0] = two*(x1-two)*v1;
234 (*ajvp)[1] = two*x2*v1;
247 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
248 ROL::Ptr<const vector> up = getVector<CDual>(u);
249 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
250 ROL::Ptr<vector> ahuvp = getVector<XDual>(ahuv);
253 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
254 "Primal vector x must be of length 2.");
257 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
258 "Direction vector v must be of length 2.");
261 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
262 "Output vector ahuv must be of length 2.");
264 ROL_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
265 "Dual constraint vector u must be of length 1.");
274 (*ahuvp)[0] = two*u1*v1;
275 (*ahuvp)[1] = two*u1*v2;
282 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
291 return ROL::makePtr<Objective_ParaboloidCircle<Real,XPrim,XDual>>();
297 ROL::Ptr<vector> x0p = makePtr<vector>(n,0.0);
298 (*x0p)[0] =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
299 (*x0p)[1] =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
300 return makePtr<XPrim>(x0p);
306 Real
zero(0), one(1);
307 ROL::Ptr<vector> solp = makePtr<vector>(n,0.0);
310 return makePtr<XPrim>(solp);
315 return ROL::makePtr<Constraint_ParaboloidCircle<Real,XPrim,XDual,CPrim,CDual>>();
319 ROL::Ptr<vector> lp = makePtr<vector>(1,0.0);
320 return makePtr<CDual>(lp);
Provides the interface to evaluate objective functions.
typename PV< Real >::size_type size_type
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
Ptr< Vector< Real > > getSolution(const int i=0) const
ROL::Ptr< vector > getVector(V &x)
constraint c(x,y) = (x-2)^2 + y^2 - 1.
ROL::Ptr< vector > getVector(V &x)
ROL::Ptr< const vector > getVector(const V &x)
Defines the linear algebra or vector space interface.
Ptr< Objective< Real > > getObjective(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
virtual void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
Objective_ParaboloidCircle()
Contains definitions of test objective functions.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
getParaboloidCircle(void)
Ptr< Vector< Real > > getInitialGuess(void) const
Objective function: f(x,y) = x^2 + y^2.
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
std::vector< Real > vector
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
std::vector< Real > vector
ROL::Ptr< const vector > getVector(const V &x)
Defines the general constraint operator interface.
std::vector< Real > vector
Constraint_ParaboloidCircle()