ROL
ROL_ElasticLinearConstraint_Def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_ELASTICLINEARCONSTRAINT_DEF_H
11 #define ROL_ELASTICLINEARCONSTRAINT_DEF_H
12 
13 namespace ROL {
14 
15 template<typename Real>
17  const Ptr<Constraint<Real>> &con,
18  const Ptr<const Vector<Real>> &c)
19  : con_(con), x_(x->clone()), c_(c->clone()), tmp_(x->clone()) {
20  setAnchor(x);
21 }
22 
23 template<typename Real>
25 
26 template<typename Real>
27 void ElasticLinearConstraint<Real>::update( const Vector<Real> &x, bool flag, int iter ) {}
28 
29 template<typename Real>
31  Ptr<const Vector<Real>> xs = dynamic_cast<const PartitionedVector<Real>&>(x).get(0);
32  Ptr<const Vector<Real>> xu = dynamic_cast<const PartitionedVector<Real>&>(x).get(1);
33  Ptr<const Vector<Real>> xv = dynamic_cast<const PartitionedVector<Real>&>(x).get(2);
34  tmp_->set(*xs); tmp_->axpy(static_cast<Real>(-1),*x_);
35  con_->applyJacobian(c,*tmp_,*x_,tol);
36  c.plus(*c_);
37  c.plus(*xu);
38  c.axpy(static_cast<Real>(-1),*xv);
39 }
40 
41 template<typename Real>
43  Ptr<const Vector<Real>> vs = dynamic_cast<const PartitionedVector<Real>&>(v).get(0);
44  Ptr<const Vector<Real>> vu = dynamic_cast<const PartitionedVector<Real>&>(v).get(1);
45  Ptr<const Vector<Real>> vv = dynamic_cast<const PartitionedVector<Real>&>(v).get(2);
46  con_->applyJacobian(jv,*vs,*x_,tol);
47  jv.plus(*vu);
48  jv.axpy(static_cast<Real>(-1),*vv);
49 }
50 
51 template<typename Real>
53  Ptr<Vector<Real>> as = dynamic_cast<PartitionedVector<Real>&>(ajv).get(0);
54  Ptr<Vector<Real>> au = dynamic_cast<PartitionedVector<Real>&>(ajv).get(1);
55  Ptr<Vector<Real>> av = dynamic_cast<PartitionedVector<Real>&>(ajv).get(2);
56  con_->applyAdjointJacobian(*as,v,*x_,tol);
57  au->set(v.dual());
58  av->set(v.dual()); av->scale(static_cast<Real>(-1));
59 }
60 
61 template<typename Real>
63  Ptr<Vector<Real>> as = dynamic_cast<PartitionedVector<Real>&>(ajv).get(0);
64  Ptr<Vector<Real>> au = dynamic_cast<PartitionedVector<Real>&>(ajv).get(1);
65  Ptr<Vector<Real>> av = dynamic_cast<PartitionedVector<Real>&>(ajv).get(2);
66  con_->applyAdjointJacobian(*as,v,*x_,tol);
67  au->set(dualv);
68  av->set(dualv); av->scale(static_cast<Real>(-1));
69 }
70 
71 template<typename Real>
73  ahuv.zero();
74 }
75 
76 template<typename Real>
78  x_->set(*x);
79  Real tol = std::sqrt(ROL_EPSILON<Real>());
80  con_->value(*c_,*x_,tol);
81 }
82 
83 } // namespace ROL
84 
85 #endif
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Definition: ROL_Vector.hpp:192
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:119
Defines the linear algebra of vector space on a generic partitioned vector.
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update constraint function.
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:133
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol) override
Evaluate the constraint operator at .
ElasticLinearConstraint(const Ptr< const Vector< Real >> &x, const Ptr< Constraint< Real >> &con, const Ptr< const Vector< Real >> &c)
void setAnchor(const Ptr< const Vector< Real >> &x)
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply the adjoint of the the constraint Jacobian at , , to vector .
Defines the general constraint operator interface.
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply the constraint Jacobian at , , to vector .