51 #include "Teuchos_GlobalMPISession.hpp"
53 #include "ROL_ParameterList.hpp"
66 template <
class Real,
class Element=Real>
69 template <
class Real,
class Element=Real>
72 template <
class Real,
class Element=Real>
75 template <
class Real,
class Element=Real>
82 template <
class Real,
class Element>
89 ROL::Ptr<std::vector<Element> > std_vec_;
90 mutable ROL::Ptr<OptDualStdVector<Real> > dual_vec_;
92 ROL::Ptr<FiniteDifference<Real> >
fd_;
98 std_vec_(std_vec), dual_vec_(ROL::nullPtr), fd_(fd) {}
102 ROL::Ptr<const vector> xvalptr = ex.
getVector();
103 uint dimension = std_vec_->size();
104 for (
uint i=0; i<dimension; i++) {
105 (*std_vec_)[i] += (*xvalptr)[i];
110 uint dimension = std_vec_->size();
111 for (
uint i=0; i<dimension; i++) {
112 (*std_vec_)[i] *= alpha;
121 ROL::Ptr<const vector> xvalptr = ex.
getVector();
123 ROL::Ptr<vector> kxvalptr = ROL::makePtr<vector>(std_vec_->size(), 0.0);
125 fd_->apply(xvalptr,kxvalptr);
127 uint dimension = std_vec_->size();
128 for (
uint i=0; i<dimension; i++) {
129 val += (*std_vec_)[i]*(*kxvalptr)[i];
136 val = std::sqrt( dot(*
this) );
140 ROL::Ptr<Vector<Real> >
clone()
const {
141 return ROL::makePtr<OptStdVector>( ROL::makePtr<vector>(std_vec_->size()), fd_ );
152 ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
153 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(std_vec_->size(),0.0);
154 ROL::Ptr<OptStdVector> e = ROL::makePtr<OptStdVector>( e_ptr, fd_ );
159 int dimension()
const {
return static_cast<int>(std_vec_->size());}
164 ROL::Ptr<vector> dual_vecp = ROL::makePtr<vector>(*std_vec_);
165 dual_vec_ = ROL::makePtr<OptDualStdVector<Real>>( dual_vecp, fd_ );
166 fd_->apply(dual_vecp);
174 template <
class Real,
class Element>
181 ROL::Ptr<std::vector<Element> > std_vec_;
182 mutable ROL::Ptr<OptStdVector<Real> > dual_vec_;
183 ROL::Ptr<FiniteDifference<Real> >
fd_;
188 std_vec_(std_vec), dual_vec_(ROL::nullPtr), fd_(fd) {}
192 ROL::Ptr<const vector> xvalptr = ex.
getVector();
193 uint dimension = std_vec_->size();
194 for (
uint i=0; i<dimension; i++) {
195 (*std_vec_)[i] += (*xvalptr)[i];
200 uint dimension = std_vec_->size();
201 for (
uint i=0; i<dimension; i++) {
202 (*std_vec_)[i] *= alpha;
209 ROL::Ptr<const vector> kxvalptr = ex.
getVector();
210 ROL::Ptr<vector> xvalptr = ROL::makePtr<vector>(std_vec_->size(), 0.0);
211 fd_->solve(kxvalptr,xvalptr);
213 uint dimension = std_vec_->size();
214 for (
unsigned i=0; i<dimension; i++) {
215 val += (*std_vec_)[i]*(*xvalptr)[i];
222 val = std::sqrt( dot(*
this) );
226 ROL::Ptr<Vector<Real> >
clone()
const {
227 return ROL::makePtr<OptDualStdVector>( ROL::makePtr<std::vector<Element>>(std_vec_->size()), fd_ );
230 ROL::Ptr<const std::vector<Element> >
getVector()
const {
238 ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
239 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(std_vec_->size(), 0.0 );
240 ROL::Ptr<OptDualStdVector> e = ROL::makePtr<OptDualStdVector>( e_ptr,fd_ );
245 int dimension()
const {
return static_cast<int>(std_vec_->size());}
248 ROL::Ptr<vector> dual_vecp = ROL::makePtr<vector>(*std_vec_);
249 dual_vec_ = ROL::makePtr<OptStdVector<Real>>( dual_vecp, fd_ );
251 fd_->solve(dual_vecp);
261 template <
class Real,
class Element>
268 ROL::Ptr<std::vector<Element> > std_vec_;
269 mutable ROL::Ptr<ConDualStdVector<Real> > dual_vec_;
273 ConStdVector(
const ROL::Ptr<std::vector<Element> > & std_vec) : std_vec_(std_vec), dual_vec_(ROL::nullPtr) {}
277 ROL::Ptr<const vector> xvalptr = ex.
getVector();
278 uint dimension = std_vec_->size();
279 for (
uint i=0; i<dimension; i++) {
280 (*std_vec_)[i] += (*xvalptr)[i];
285 uint dimension = std_vec_->size();
286 for (
uint i=0; i<dimension; i++) {
287 (*std_vec_)[i] *= alpha;
294 ROL::Ptr<const vector> xvalptr = ex.
getVector();
296 uint dimension = std_vec_->size();
297 for (
uint i=0; i<dimension; i++) {
298 val += (*std_vec_)[i]*(*xvalptr)[i];
305 val = std::sqrt( dot(*
this) );
309 ROL::Ptr<Vector<Real> >
clone()
const {
310 return ROL::makePtr<ConStdVector>( ROL::makePtr<vector>(std_vec_->size()));
313 ROL::Ptr<const std::vector<Element> >
getVector()
const {
321 ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
322 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(std_vec_->size(),0.0);
323 ROL::Ptr<ConStdVector> e = ROL::makePtr<ConStdVector>( e_ptr);
328 int dimension()
const {
return static_cast<int>(std_vec_->size());}
331 dual_vec_ = ROL::makePtr<ConDualStdVector<Real>>( ROL::makePtr<std::vector<Element>>(*std_vec_) );
339 template <
class Real,
class Element>
347 ROL::Ptr<std::vector<Element> > std_vec_;
348 mutable ROL::Ptr<ConStdVector<Real> > dual_vec_;
352 ConDualStdVector(
const ROL::Ptr<std::vector<Element> > & std_vec) : std_vec_(std_vec), dual_vec_(ROL::nullPtr) {}
356 ROL::Ptr<const vector> xvalptr = ex.
getVector();
357 uint dimension = std_vec_->size();
358 for (
uint i=0; i<dimension; i++) {
359 (*std_vec_)[i] += (*xvalptr)[i];
364 uint dimension = std_vec_->size();
365 for (
uint i=0; i<dimension; i++) {
366 (*std_vec_)[i] *= alpha;
373 ROL::Ptr<const vector> xvalptr = ex.
getVector();
374 uint dimension = std_vec_->size();
375 for (
uint i=0; i<dimension; i++) {
376 val += (*std_vec_)[i]*(*xvalptr)[i];
383 val = std::sqrt( dot(*
this) );
387 ROL::Ptr<Vector<Real> >
clone()
const {
388 return ROL::makePtr<ConDualStdVector>( ROL::makePtr<std::vector<Element>>(std_vec_->size()));
391 ROL::Ptr<const std::vector<Element> >
getVector()
const {
399 ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
400 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(std_vec_->size(),0.0);
401 ROL::Ptr<ConDualStdVector> e = ROL::makePtr<ConDualStdVector>( e_ptr );
406 int dimension()
const {
return static_cast<int>(std_vec_->size());}
409 dual_vec_ = ROL::makePtr<ConStdVector<Real>>( ROL::makePtr<std::vector<Element>>(*std_vec_) );
420 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real> >
438 ROL::Ptr<const std::vector<Real> >
Vp_;
440 ROL::Ptr<FiniteDifference<Real> >
fd_;
450 ROL::Ptr<const vector> vp =
dynamic_cast<const XPrim&
>(v).getVector();
453 ROL::Ptr<vector> kvp =
dynamic_cast<XDual&
>(kv).getVector();
457 (*kvp)[0] = (2.0*(*vp)[0]-(*vp)[1])/dx2;
459 for(
uint i=1;i<nx_-1;++i) {
460 (*kvp)[i] = (2.0*(*vp)[i]-(*vp)[i-1]-(*vp)[i+1])/dx2;
463 (*kvp)[nx_-1] = (2.0*(*vp)[nx_-1]-(*vp)[nx_-2])/dx2;
470 Vp_((dynamic_cast<const
StdVector<Real>&>(V)).getVector()), fd_(fd) {
473 dx_ = (1.0/(1.0+nx_));
486 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).getVector();
489 ROL::Ptr<vector> kpsip = ROL::makePtr<vector>(nx_, 0.0);
490 XDual kpsi(kpsip,fd_);
496 for(
uint i=0;i<nx_;++i) {
497 J += (*psip)[i]*(*kpsip)[i] + (*Vp_)[i]*pow((*psip)[i],2) + g_*pow((*psip)[i],4);
513 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).getVector();
516 ROL::Ptr<vector> gp =
dynamic_cast<XDual&
>(g).getVector();
519 ROL::Ptr<vector> kpsip = ROL::makePtr<vector>(nx_, 0.0);
520 XDual kpsi(kpsip,fd_);
524 for(
uint i=0;i<nx_;++i) {
525 (*gp)[i] = ((*kpsip)[i] + (*Vp_)[i]*(*psip)[i] + 2.0*g_*pow((*psip)[i],3))*dx_;
539 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).getVector();
542 ROL::Ptr<const vector> vp =
dynamic_cast<const XPrim&
>(v).getVector();
545 ROL::Ptr<vector> hvp =
dynamic_cast<XDual&
>(hv).getVector();
549 for(
uint i=0;i<nx_;++i) {
551 (*hvp)[i] += ( (*Vp_)[i] + 6.0*g_*pow((*psip)[i],2) )*(*vp)[i]*dx_;
560 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
569 ROL::Ptr<FiniteDifference<Real> >
fd_;
574 nx_(n), dx_(dx), fd_(fd), exactsolve_(exactsolve) {}
586 ROL::Ptr<vector> cp =
dynamic_cast<CPrim&
>(c).getVector();
589 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).getVector();
592 for(
uint i=0;i<nx_;++i) {
593 (*cp)[0] += dx_*pow((*psip)[i],2);
605 ROL::Ptr<vector> jvp =
dynamic_cast<CPrim&
>(jv).getVector();
608 ROL::Ptr<const vector> vp =
dynamic_cast<const XPrim&
>(v).getVector();
611 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).getVector();
614 for(
uint i=0;i<nx_;++i) {
615 (*jvp)[0] += 2.0*dx_*(*psip)[i]*(*vp)[i];
627 ROL::Ptr<vector> ajvp =
dynamic_cast<XDual&
>(ajv).getVector();
630 ROL::Ptr<const vector> vp =
dynamic_cast<const CDual&
>(v).getVector();
633 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).getVector();
635 for(
uint i=0;i<nx_;++i) {
636 (*ajvp)[i] = 2.0*dx_*(*psip)[i]*(*vp)[0];
651 ROL::Ptr<vector> ahuvp =
dynamic_cast<XDual&
>(ahuv).getVector();
654 ROL::Ptr<const vector> up =
dynamic_cast<const CDual&
>(u).getVector();
657 ROL::Ptr<const vector> vp =
dynamic_cast<const XPrim&
>(v).getVector();
660 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).getVector();
662 for(
uint i=0;i<nx_;++i) {
663 (*ahuvp)[i] = 2.0*dx_*(*vp)[i]*(*up)[0];
678 ROL::Ptr<vector> v1p =
dynamic_cast<XPrim&
>(v1).getVector();
679 ROL::Ptr<vector> v2p =
dynamic_cast<CDual&
>(v2).getVector();
680 ROL::Ptr<const vector> b1p =
dynamic_cast<const XDual&
>(b1).getVector();
681 ROL::Ptr<const vector> b2p =
dynamic_cast<const CPrim&
>(b2).getVector();
682 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).getVector();
684 ROL::Ptr<vector> jacp = ROL::makePtr<vector>(nx_, 0.0);
685 ROL::Ptr<vector> b1dp = ROL::makePtr<vector>(nx_, 0.0);
687 for(
uint i=0;i<nx_;++i) {
688 (*jacp)[i] = (*psip)[i];
689 (*b1dp)[i] = (*b1p)[i];
700 Real d = 1.0/jac.dot(jac);
701 Real p = jac.dot(b1d);
703 (*v2p)[0] = d*(p-(*b2p)[0]);
706 v1.
scale(-(*v2p)[0]);
709 return std::vector<Real>(0);
std::vector< Element > vector
Provides the interface to evaluate objective functions.
typename PV< Real >::size_type size_type
Real value(const Vector< Real > &psi, Real &tol)
Evaluate .
virtual void scale(const Real alpha)=0
Compute where .
void scale(const Real alpha)
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Evaluate .
std::vector< Element > vector
ROL::Ptr< const std::vector< Element > > getVector() const
std::vector< Real > vector
Real norm() const
Returns where .
void value(Vector< Real > &c, const Vector< Real > &psi, Real &tol)
Evaluate .
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Evaluate .
ROL::Ptr< vector > getVector()
ROL::Ptr< FiniteDifference< Real > > fd_
Real dot(const Vector< Real > &x) const
Compute where .
ROL::Ptr< const vector > getVector() const
ROL::Ptr< std::vector< Element > > getVector()
int dimension() const
Return dimension of the vector space.
std::vector< Element > vector
Defines the linear algebra or vector space interface.
std::vector< Real > vector
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
ROL::Ptr< std::vector< Element > > getVector()
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Evaluate .
ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
std::vector< Element > vector
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
std::vector< Real > solveAugmentedSystem(Vector< Real > &v1, Vector< Real > &v2, const Vector< Real > &b1, const Vector< Real > &b2, const Vector< Real > &psi, Real &tol)
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
void scale(const Real alpha)
Compute where .
ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
Real dot(const Vector< Real > &x) const
Compute where .
ConDualStdVector(const ROL::Ptr< std::vector< Element > > &std_vec)
void scale(const Real alpha)
Compute where .
ROL::Ptr< const std::vector< Element > > getVector() const
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
int dimension() const
Return dimension of the vector space.
int dimension() const
Return dimension of the vector space.
ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
ConStdVector(const ROL::Ptr< std::vector< Element > > &std_vec)
void applyK(const Vector< Real > &v, Vector< Real > &kv)
Apply finite difference operator.
Real norm() const
Returns where .
Objective_GrossPitaevskii(const Real &g, const Vector< Real > &V, ROL::Ptr< FiniteDifference< Real > > fd)
void plus(const Vector< Real > &x)
Compute , where .
int dimension() const
Return dimension of the vector space.
Real dot(const Vector< Real > &x) const
Compute where .
ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
void plus(const Vector< Real > &x)
Compute , where .
const Vector< Real > & dual() const
Modify the dual of vector u to be .
ROL::Ptr< FiniteDifference< Real > > fd_
ROL::Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
virtual std::vector< Real > solveAugmentedSystem(Vector< Real > &v1, Vector< Real > &v2, const Vector< Real > &b1, const Vector< Real > &b2, const Vector< Real > &x, Real &tol)
Approximately solves the augmented system where , , , , is an identity or Riesz operator...
Real norm() const
Returns where .
Real dot(const Vector< Real > &x) const
Modify the dot product between primal variables to be .
Normalization_Constraint(int n, Real dx, ROL::Ptr< FiniteDifference< Real > > fd, bool exactsolve)
ROL::Ptr< const std::vector< Element > > getVector() const
void gradient(Vector< Real > &g, const Vector< Real > &psi, Real &tol)
Evaluate .
virtual void set(const Vector &x)
Set where .
ROL::Ptr< const std::vector< Element > > getVector() const
void plus(const Vector< Real > &x)
Compute , where .
OptDualStdVector(const ROL::Ptr< std::vector< Element > > &std_vec, ROL::Ptr< FiniteDifference< Real > >fd)
ROL::Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ROL::Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ROL::Ptr< std::vector< Element > > getVector()
ROL::Ptr< FiniteDifference< Real > > fd_
void plus(const Vector< Real > &x)
Compute , where .
ROL::Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ROL::Ptr< FiniteDifference< Real > > fd_
Defines the general constraint operator interface.
Real norm() const
Returns where .
ROL::Ptr< const std::vector< Real > > Vp_
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Evaluate .
void scale(const Real alpha)
Compute where .
OptStdVector(const ROL::Ptr< std::vector< Element > > &std_vec, ROL::Ptr< FiniteDifference< Real > >fd)