Debian Codegraph @

packages/rol/example/l1-penalty/l1_penalty_constraint.hpp

raw
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 #pragma once
11 #ifndef L1_PENALTY_CONSTRAINT_HPP
12 #define L1_PENALTY_CONSTRAINT_HPP
13
14 #include "ROL_Constraint.hpp"
15 #include "l1_utilities.hpp"
16
17 namespace ROL {
18
19 template<typename Real>
20 class L1PenaltyConstraint : public Constraint<Real> {
21 public:
22
23 L1PenaltyConstraint( const Ptr<Constraint<Real>>& con )
24 : con_(con) {}
25
26 void update( const Vector<Real>& x,
27 UpdateType type,
28 int iter = -1 ) override {
29 auto [xp] = pv_cast(x);
30 con_->update(xp[X],type,iter);
31 }
32
33 void value( Vector<Real>& c,
34 const Vector<Real>& x,
35 Real& tol ) override {
36 auto [xp] = pv_cast(x);
37 con_->value(c,xp[X],tol);
38 c.plus(xp[S]);
39 c.axpy(-1.0,xp[R]);
40 }
41
42 void applyJacobian( Vector<Real>& jv,
43 const Vector<Real>& v,
44 const Vector<Real>& x,
45 Real& tol ) override {
46 auto [vp,xp] = pv_cast(v,x);
47 con_->applyJacobian(jv,vp[X],xp[X],tol);
48 jv.plus(vp[S]);
49 jv.axpy(-1.0,vp[R]);
50 }
51
52 void applyAdjointJacobian( Vector<Real>& ajv,
53 const Vector<Real>& v,
54 const Vector<Real>& x,
55 Real& tol ) override {
56 auto [ajvp,xp] = pv_cast(ajv,x);
57 con_->applyAdjointJacobian(ajvp[X],v,xp[X],tol);
58 ajvp[R].set(v);
59 ajvp[R].scale(-1);
60 ajvp[S].set(v);
61 }
62
63 void applyAdjointHessian( Vector<Real>& ahuv,
64 const Vector<Real>& u,
65 const Vector<Real>& v,
66 const Vector<Real>& x,
67 Real& tol ) override {
68 auto [ahuvp,vp,xp] = pv_cast(ahuv,v,x);
69 con_->applyAdjointHessian(ahuvp[X],u,vp[X],xp[X],tol);
70 ahuvp[R].zero();
71 ahuvp[S].zero();
72 }
73
74 // PartitionedVector block indices
75 static constexpr int X{0}, R{1}, S{2};
76
77 private:
78
79 Ptr<Constraint<Real>> con_;
80
81 };
82
83
84 } // namespace ROL
85
86 #endif //L1_PENALTY_CONSTRAINT_HPP
87