ROL
ROL_EqualityConstraint_Partitioned.hpp
Go to the documentation of this file.
1 #ifndef ROL_EQUALITYCONSTRAINT_PARTITIONED_H
2 #define ROL_EQUALITYCONSTRAINT_PARTITIONED_H
3 
6 
7 namespace ROL {
8 
14 template<class Real>
16 
18  typedef Vector<Real> V;
20  typedef typename std::vector<Real>::size_type uint;
21 
22 private:
23 
24  const std::vector<Teuchos::RCP<EC> > con_;
26 
27 public:
28 
29  EqualityConstraint_Partitioned( const std::vector<Teuchos::RCP<EqualityConstraint<Real> > > &con ) :
30  con_(con), dim_(con.size()) {
31 
32  }
33 
35 
36  virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
37  for ( uint k=0; k<dim_; ++k ) {
38  con_[k]->update(x,flag,iter);
39  }
40  }
41 
42  virtual void value(Vector<Real> &c, const Vector<Real> &x, Real &tol) {
43  // Downcast c to PartitionedVector
44  PV& cpv = Teuchos::dyn_cast<PV>(c);
45 
46  // Iterate over constraints
47  for( uint k=0; k<dim_; ++k ) {
48  // Evaluate constraint for each c contribution
49  con_[k]->value(*(cpv.get(k)),x,tol);
50  }
51 
52  }
53 
54  virtual void applyJacobian(Vector<Real> &jv, const Vector<Real> &v,
55  const Vector<Real> &x, Real &tol) {
56 
57  // Downcast jv to PartitionedVector
58  PV& jvpv = Teuchos::dyn_cast<PV>(jv);
59 
60  // Iterate over constraints
61  for( uint k=0; k<dim_; ++k ) {
62  // Evaluate jacobian contributions
63  con_[k]->applyJacobian( *(jvpv.get(k)), v, x, tol);
64  }
65 
66  }
67 
68  virtual void applyAdjointJacobian(Vector<Real> &ajv, const Vector<Real> &v,
69  const Vector<Real> &x, Real &tol) {
70 
71  const PV& vpv = Teuchos::dyn_cast<const PV>(v);
72 
73  Teuchos::RCP<V> temp = ajv.clone();
74  ajv.zero();
75 
76  for( uint k=0; k<dim_; ++k ) {
77  con_[k]->applyAdjointJacobian( *temp, *(vpv.get(k)), x, tol);
78  ajv.plus(*temp);
79  }
80  }
81 
82  virtual void applyAdjointHessian(Vector<Real> &ahuv, const Vector<Real> &u,
83  const Vector<Real> &v, const Vector<Real> &x,
84  Real &tol) {
85 
86  const PV& upv = Teuchos::dyn_cast<const PV>(u);
87 
88  Teuchos::RCP<V> temp = ahuv.clone();
89  ahuv.zero();
90 
91  for( uint k=0; k<dim_; ++k ) {
92  con_[k]->applyAdjointHessian( *temp, *(upv.get(k)), v, x, tol );
93  ahuv.plus( *temp );
94  }
95  }
96 
97  virtual void applyPreconditioner(Vector<Real> &pv, const Vector<Real> &v,
98  const Vector<Real> &x, const Vector<Real> &g,
99  Real &tol) {
100 
101  const PV& vpv = Teuchos::dyn_cast<const PV>(v);
102  PV& pvpv = Teuchos::dyn_cast<PV>(pv);
103 
104  for( uint k=0; k<dim_; ++k ) {
105  con_[k]->applyPreconditioner( *(pvpv.get(k)), *(vpv.get(k)), x, g, tol );
106  }
107 
108  }
109 
110 // Definitions for parametrized (stochastic) equality constraints
111 public:
112  void setParameter(const std::vector<Real> &param) {
114  for( uint k=0; k<dim_; ++k ) {
115  con_[k]->setParameter(param);
116  }
117  }
118 }; // class EqualityConstraint_Partitioned
119 
120 // Helper methods
121 template<class Real>
122 Teuchos::RCP<EqualityConstraint<Real> >
124  const Teuchos::RCP<EqualityConstraint<Real> > &con2 ) {
125  using Teuchos::RCP; using Teuchos::rcp;
126 
128  typedef RCP<EqualityConstraint<Real> > RCPEC;
129  RCPEC con[] = { con1, con2 };
130 
131  return rcp( new ECP( std::vector<RCPEC>( con, con+2 ) ) );
132 }
133 
134 template<class Real>
135 Teuchos::RCP<EqualityConstraint<Real> >
137  const Teuchos::RCP<EqualityConstraint<Real> > &con2,
138  const Teuchos::RCP<EqualityConstraint<Real> > &con3 ) {
139  using Teuchos::RCP; using Teuchos::rcp;
140 
142  typedef RCP<EqualityConstraint<Real> > RCPEC;
143  RCPEC con[] = { con1, con2, con3 };
144 
145  return rcp( new ECP( std::vector<RCPEC>( con, con+3 ) ) );
146 }
147 
148 
149 } // namespace ROL
150 
151 
152 #endif // ROL_PARTITIONEQUALITYCONSTRAINT_H
virtual void applyPreconditioner(Vector< Real > &pv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g, Real &tol)
Apply a constraint preconditioner at , , to vector . Ideally, this preconditioner satisfies the follo...
virtual void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
virtual void plus(const Vector &x)=0
Compute , where .
Defines the linear algebra of vector space on a generic partitioned vector.
Allows composition of equality constraints.
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update constraint functions. x is the optimization variable, flag = true if optimization variable is ...
virtual void setParameter(const std::vector< Real > &param)
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 ...
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:159
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:76
Teuchos::RCP< EqualityConstraint< Real > > CreateEqualityConstraintPartitioned(const Teuchos::RCP< EqualityConstraint< Real > > &con1, const Teuchos::RCP< EqualityConstraint< Real > > &con2)
Defines the equality constraint operator interface.
void setParameter(const std::vector< Real > &param)
Teuchos::RCP< const Vector< Real > > get(size_type i) const
const std::vector< Teuchos::RCP< EC > > con_
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
virtual 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 .
EqualityConstraint_Partitioned(const std::vector< Teuchos::RCP< EqualityConstraint< Real > > > &con)