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 value(Vector<Real> &c, const Vector<Real> &x, Real &tol) {
37  // Downcast c to PartitionedVector
38  PV& cpv = Teuchos::dyn_cast<PV>(c);
39 
40  // Iterate over constraints
41  for( uint k=0; k<dim_; ++k ) {
42  // Evaluate constraint for each c contribution
43  con_[k]->value(*(cpv.get(k)),x,tol);
44  }
45 
46  }
47 
48  virtual void applyJacobian(Vector<Real> &jv, const Vector<Real> &v,
49  const Vector<Real> &x, Real &tol) {
50 
51  // Downcast jv to PartitionedVector
52  PV& jvpv = Teuchos::dyn_cast<PV>(jv);
53 
54  // Iterate over constraints
55  for( uint k=0; k<dim_; ++k ) {
56  // Evaluate jacobian contributions
57  con_[k]->applyJacobian( *(jvpv.get(k)), v, x, tol);
58  }
59 
60  }
61 
62  virtual void applyAdjointJacobian(Vector<Real> &ajv, const Vector<Real> &v,
63  const Vector<Real> &x, Real &tol) {
64 
65  const PV& vpv = Teuchos::dyn_cast<const PV>(v);
66 
67  Teuchos::RCP<V> temp = ajv.clone();
68  ajv.zero();
69 
70  for( uint k=0; k<dim_; ++k ) {
71  con_[k]->applyAdjointJacobian( *temp, *(vpv.get(k)), x, tol);
72  ajv.plus(*temp);
73  }
74  }
75 
76  virtual void applyAdjointHessian(Vector<Real> &ahuv, const Vector<Real> &u,
77  const Vector<Real> &v, const Vector<Real> &x,
78  Real &tol) {
79 
80  const PV& upv = Teuchos::dyn_cast<const PV>(u);
81 
82  Teuchos::RCP<V> temp = ahuv.clone();
83  ahuv.zero();
84 
85  for( uint k=0; k<dim_; ++k ) {
86  con_[k]->applyAdjointHessian( *temp, *(upv.get(k)), v, x, tol );
87  ahuv.plus( *temp );
88  }
89  }
90 
91  virtual void applyPreconditioner(Vector<Real> &pv, const Vector<Real> &v,
92  const Vector<Real> &x, const Vector<Real> &g,
93  Real &tol) {
94 
95  const PV& vpv = Teuchos::dyn_cast<const PV>(v);
96  PV& pvpv = Teuchos::dyn_cast<PV>(pv);
97 
98  for( uint k=0; k<dim_; ++k ) {
99  con_[k]->applyPreconditioner( *(pvpv.get(k)), *(vpv.get(k)), x, g, tol );
100  }
101 
102  }
103 
104 // Definitions for parametrized (stochastic) equality constraints
105 public:
106  void setParameter(const std::vector<Real> &param) {
108  for( uint k=0; k<dim_; ++k ) {
109  con_[k]->setParameter(param);
110  }
111  }
112 }; // class EqualityConstraint_Partitioned
113 
114 // Helper methods
115 template<class Real>
116 Teuchos::RCP<EqualityConstraint<Real> >
118  const Teuchos::RCP<EqualityConstraint<Real> > &con2 ) {
119  using Teuchos::RCP; using Teuchos::rcp;
120 
122  typedef RCP<EqualityConstraint<Real> > RCPEC;
123  RCPEC con[] = { con1, con2 };
124 
125  return rcp( new ECP( std::vector<RCPEC>( con, con+2 ) ) );
126 }
127 
128 template<class Real>
129 Teuchos::RCP<EqualityConstraint<Real> >
131  const Teuchos::RCP<EqualityConstraint<Real> > &con2,
132  const Teuchos::RCP<EqualityConstraint<Real> > &con3 ) {
133  using Teuchos::RCP; using Teuchos::rcp;
134 
136  typedef RCP<EqualityConstraint<Real> > RCPEC;
137  RCPEC con[] = { con1, con2, con3 };
138 
139  return rcp( new ECP( std::vector<RCPEC>( con, con+3 ) ) );
140 }
141 
142 
143 } // namespace ROL
144 
145 
146 #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.
Teuchos::RCP< const Vector< Real > > get(size_type i) const
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:157
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
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)
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)