53 #ifndef ROL_PARABOLOIDCIRCLE_HPP
54 #define ROL_PARABOLOIDCIRCLE_HPP
58 #include "Teuchos_SerialDenseVector.hpp"
59 #include "Teuchos_SerialDenseSolver.hpp"
67 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real> >
78 template<
class VectorType>
81 return dynamic_cast<const VectorType&>(x).getVector();
84 template<
class VectorType>
87 return dynamic_cast<VectorType&>(x).getVector();
96 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
99 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective value): "
100 "Primal vector x must be of length 2.");
105 Real val = x1*x1 + x2*x2;
113 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
114 ROL::Ptr<vector> gp = getVector<XDual>(g);
117 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective gradient): "
118 " Primal vector x must be of length 2.");
121 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective gradient): "
122 "Gradient vector g must be of length 2.");
136 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
137 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
138 ROL::Ptr<vector> hvp = getVector<XDual>(hv);
141 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): "
142 "Primal vector x must be of length 2.");
145 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): "
146 "Input vector v must be of length 2.");
149 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): "
150 "Output vector hv must be of length 2.");
166 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
175 template<
class VectorType>
178 return dynamic_cast<const VectorType&>(x).getVector();
181 template<
class VectorType>
184 return dynamic_cast<VectorType&>(x).getVector();
193 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
194 ROL::Ptr<vector> cp = getVector<CPrim>(c);
197 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint value): "
198 "Primal vector x must be of length 2.");
201 ROL_TEST_FOR_EXCEPTION( (m != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint value): "
202 "Constraint vector c must be of length 1.");
209 (*cp)[0] = (x1-two)*(x1-two) + x2*x2 - one;
215 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
216 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
217 ROL::Ptr<vector> jvp = getVector<CPrim>(jv);
220 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): "
221 "Primal vector x must be of length 2.");
224 ROL_TEST_FOR_EXCEPTION( (d != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): "
225 "Input vector v must be of length 2.");
227 ROL_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): "
228 "Output vector jv must be of length 1.");
238 (*jvp)[0] = two*(x1-two)*v1 + two*x2*v2;
244 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
245 ROL::Ptr<const vector> vp = getVector<CDual>(v);
246 ROL::Ptr<vector> ajvp = getVector<XDual>(ajv);
249 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): "
250 "Primal vector x must be of length 2.");
253 ROL_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): "
254 "Input vector v must be of length 1.");
257 ROL_TEST_FOR_EXCEPTION( (d != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): "
258 "Output vector ajv must be of length 2.");
267 (*ajvp)[0] = two*(x1-two)*v1;
268 (*ajvp)[1] = two*x2*v1;
281 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
282 ROL::Ptr<const vector> up = getVector<CDual>(u);
283 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
284 ROL::Ptr<vector> ahuvp = getVector<XDual>(ahuv);
287 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
288 "Primal vector x must be of length 2.");
291 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
292 "Direction vector v must be of length 2.");
295 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
296 "Output vector ahuv must be of length 2.");
298 ROL_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
299 "Dual constraint vector u must be of length 1.");
308 (*ahuvp)[0] = two*u1*v1;
309 (*ahuvp)[1] = two*u1*v2;
316 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
325 return ROL::makePtr<Objective_ParaboloidCircle<Real,XPrim,XDual>>();
331 ROL::Ptr<vector> x0p = makePtr<vector>(n,0.0);
332 (*x0p)[0] = static_cast<Real>(rand())/static_cast<Real>(RAND_MAX);
333 (*x0p)[1] = static_cast<Real>(rand())/static_cast<Real>(RAND_MAX);
334 return makePtr<XPrim>(x0p);
340 Real
zero(0), one(1);
341 ROL::Ptr<vector> solp = makePtr<vector>(n,0.0);
344 return makePtr<XPrim>(solp);
349 return ROL::makePtr<Constraint_ParaboloidCircle<Real,XPrim,XDual,CPrim,CDual>>();
353 ROL::Ptr<vector> lp = makePtr<vector>(1,0.0);
354 return makePtr<CDual>(lp);