85#include "Teuchos_GlobalMPISession.hpp"
87#include "ROL_ParameterList.hpp"
100template <
class Real,
class Element=Real>
103template <
class Real,
class Element=Real>
106template <
class Real,
class Element=Real>
109template <
class Real,
class Element=Real>
116template <
class Real,
class Element>
120 typedef typename vector::size_type
uint;
123ROL::Ptr<std::vector<Element> >
std_vec_;
124mutable ROL::Ptr<OptDualStdVector<Real> >
dual_vec_;
126ROL::Ptr<FiniteDifference<Real> >
fd_;
136 ROL::Ptr<const vector> xvalptr = ex.
getVector();
139 (*std_vec_)[i] += (*xvalptr)[i];
146 (*std_vec_)[i] *= alpha;
155 ROL::Ptr<const vector> xvalptr = ex.
getVector();
157 ROL::Ptr<vector> kxvalptr = ROL::makePtr<vector>(
std_vec_->size(), 0.0);
159 fd_->apply(xvalptr,kxvalptr);
163 val += (*std_vec_)[i]*(*kxvalptr)[i];
170 val = std::sqrt(
dot(*
this) );
174ROL::Ptr<Vector<Real> >
clone()
const {
175 return ROL::makePtr<OptStdVector>( ROL::makePtr<vector>(
std_vec_->size()),
fd_ );
186ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
187 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(
std_vec_->size(),0.0);
188 ROL::Ptr<OptStdVector> e = ROL::makePtr<OptStdVector>( e_ptr,
fd_ );
198 ROL::Ptr<vector> dual_vecp = ROL::makePtr<vector>(*
std_vec_);
199 dual_vec_ = ROL::makePtr<OptDualStdVector<Real>>( dual_vecp,
fd_ );
200 fd_->apply(dual_vecp);
208template <
class Real,
class Element>
212 typedef typename vector::size_type
uint;
215ROL::Ptr<std::vector<Element> >
std_vec_;
216mutable ROL::Ptr<OptStdVector<Real> >
dual_vec_;
217ROL::Ptr<FiniteDifference<Real> >
fd_;
226 ROL::Ptr<const vector> xvalptr = ex.
getVector();
229 (*std_vec_)[i] += (*xvalptr)[i];
236 (*std_vec_)[i] *= alpha;
243 ROL::Ptr<const vector> kxvalptr = ex.
getVector();
244 ROL::Ptr<vector> xvalptr = ROL::makePtr<vector>(
std_vec_->size(), 0.0);
245 fd_->solve(kxvalptr,xvalptr);
249 val += (*std_vec_)[i]*(*xvalptr)[i];
256 val = std::sqrt(
dot(*
this) );
260ROL::Ptr<Vector<Real> >
clone()
const {
261 return ROL::makePtr<OptDualStdVector>( ROL::makePtr<std::vector<Element>>(
std_vec_->size()),
fd_ );
264ROL::Ptr<const std::vector<Element> >
getVector()
const {
272ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
273 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(
std_vec_->size(), 0.0 );
274 ROL::Ptr<OptDualStdVector> e = ROL::makePtr<OptDualStdVector>( e_ptr,
fd_ );
282 ROL::Ptr<vector> dual_vecp = ROL::makePtr<vector>(*
std_vec_);
283 dual_vec_ = ROL::makePtr<OptStdVector<Real>>( dual_vecp,
fd_ );
285 fd_->solve(dual_vecp);
295template <
class Real,
class Element>
299 typedef typename vector::size_type
uint;
302ROL::Ptr<std::vector<Element> >
std_vec_;
303mutable ROL::Ptr<ConDualStdVector<Real> >
dual_vec_;
311 ROL::Ptr<const vector> xvalptr = ex.
getVector();
314 (*std_vec_)[i] += (*xvalptr)[i];
321 (*std_vec_)[i] *= alpha;
328 ROL::Ptr<const vector> xvalptr = ex.
getVector();
332 val += (*std_vec_)[i]*(*xvalptr)[i];
339 val = std::sqrt(
dot(*
this) );
343ROL::Ptr<Vector<Real> >
clone()
const {
344 return ROL::makePtr<ConStdVector>( ROL::makePtr<vector>(
std_vec_->size()));
347ROL::Ptr<const std::vector<Element> >
getVector()
const {
355ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
356 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(
std_vec_->size(),0.0);
357 ROL::Ptr<ConStdVector> e = ROL::makePtr<ConStdVector>( e_ptr);
365 dual_vec_ = ROL::makePtr<ConDualStdVector<Real>>( ROL::makePtr<std::vector<Element>>(*std_vec_) );
373template <
class Real,
class Element>
377 typedef typename vector::size_type
uint;
381ROL::Ptr<std::vector<Element> >
std_vec_;
382mutable ROL::Ptr<ConStdVector<Real> >
dual_vec_;
390 ROL::Ptr<const vector> xvalptr = ex.
getVector();
393 (*std_vec_)[i] += (*xvalptr)[i];
400 (*std_vec_)[i] *= alpha;
407 ROL::Ptr<const vector> xvalptr = ex.
getVector();
410 val += (*std_vec_)[i]*(*xvalptr)[i];
417 val = std::sqrt(
dot(*
this) );
421ROL::Ptr<Vector<Real> >
clone()
const {
422 return ROL::makePtr<ConDualStdVector>( ROL::makePtr<std::vector<Element>>(
std_vec_->size()));
425ROL::Ptr<const std::vector<Element> >
getVector()
const {
433ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
434 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(
std_vec_->size(),0.0);
435 ROL::Ptr<ConDualStdVector> e = ROL::makePtr<ConDualStdVector>( e_ptr );
443 dual_vec_ = ROL::makePtr<ConStdVector<Real>>( ROL::makePtr<std::vector<Element>>(*std_vec_) );
454template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real> >
458 typedef typename vector::size_type
uint;
472 ROL::Ptr<const std::vector<Real> >
Vp_;
474 ROL::Ptr<FiniteDifference<Real> >
fd_;
484 ROL::Ptr<const vector> vp =
dynamic_cast<const XPrim&
>(v).
getVector();
487 ROL::Ptr<vector> kvp =
dynamic_cast<XDual&
>(kv).
getVector();
491 (*kvp)[0] = (2.0*(*vp)[0]-(*vp)[1])/dx2;
494 (*kvp)[i] = (2.0*(*vp)[i]-(*vp)[i-1]-(*vp)[i+1])/dx2;
497 (*kvp)[
nx_-1] = (2.0*(*vp)[
nx_-1]-(*vp)[
nx_-2])/dx2;
520 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).
getVector();
523 ROL::Ptr<vector> kpsip = ROL::makePtr<vector>(
nx_, 0.0);
524 XDual kpsi(kpsip,
fd_);
531 J += (*psip)[i]*(*kpsip)[i] + (*Vp_)[i]*pow((*psip)[i],2) +
g_*pow((*psip)[i],4);
547 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).
getVector();
550 ROL::Ptr<vector> gp =
dynamic_cast<XDual&
>(g).
getVector();
553 ROL::Ptr<vector> kpsip = ROL::makePtr<vector>(
nx_, 0.0);
554 XDual kpsi(kpsip,
fd_);
559 (*gp)[i] = ((*kpsip)[i] + (*Vp_)[i]*(*psip)[i] + 2.0*
g_*pow((*psip)[i],3))*
dx_;
573 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).
getVector();
576 ROL::Ptr<const vector> vp =
dynamic_cast<const XPrim&
>(v).
getVector();
579 ROL::Ptr<vector> hvp =
dynamic_cast<XDual&
>(hv).
getVector();
585 (*hvp)[i] += ( (*Vp_)[i] + 6.0*
g_*pow((*psip)[i],2) )*(*vp)[i]*
dx_;
594template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
598 typedef typename vector::size_type
uint;
603 ROL::Ptr<FiniteDifference<Real> >
fd_;
620 ROL::Ptr<vector> cp =
dynamic_cast<CPrim&
>(c).
getVector();
623 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).
getVector();
627 (*cp)[0] +=
dx_*pow((*psip)[i],2);
639 ROL::Ptr<vector> jvp =
dynamic_cast<CPrim&
>(jv).
getVector();
642 ROL::Ptr<const vector> vp =
dynamic_cast<const XPrim&
>(v).
getVector();
645 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).
getVector();
649 (*jvp)[0] += 2.0*
dx_*(*psip)[i]*(*vp)[i];
661 ROL::Ptr<vector> ajvp =
dynamic_cast<XDual&
>(ajv).
getVector();
664 ROL::Ptr<const vector> vp =
dynamic_cast<const CDual&
>(v).
getVector();
667 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).
getVector();
670 (*ajvp)[i] = 2.0*
dx_*(*psip)[i]*(*vp)[0];
685 ROL::Ptr<vector> ahuvp =
dynamic_cast<XDual&
>(ahuv).
getVector();
688 ROL::Ptr<const vector> up =
dynamic_cast<const CDual&
>(u).
getVector();
691 ROL::Ptr<const vector> vp =
dynamic_cast<const XPrim&
>(v).
getVector();
694 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).
getVector();
697 (*ahuvp)[i] = 2.0*
dx_*(*vp)[i]*(*up)[0];
712 ROL::Ptr<vector> v1p =
dynamic_cast<XPrim&
>(v1).
getVector();
713 ROL::Ptr<vector> v2p =
dynamic_cast<CDual&
>(v2).
getVector();
714 ROL::Ptr<const vector> b1p =
dynamic_cast<const XDual&
>(b1).
getVector();
715 ROL::Ptr<const vector> b2p =
dynamic_cast<const CPrim&
>(b2).
getVector();
716 ROL::Ptr<const vector> psip =
dynamic_cast<const XPrim&
>(psi).
getVector();
718 ROL::Ptr<vector> jacp = ROL::makePtr<vector>(
nx_, 0.0);
719 ROL::Ptr<vector> b1dp = ROL::makePtr<vector>(
nx_, 0.0);
722 (*jacp)[i] = (*psip)[i];
723 (*b1dp)[i] = (*b1p)[i];
734 Real d = 1.0/jac.dot(jac);
735 Real p = jac.dot(b1d);
737 (*v2p)[0] = d*(p-(*b2p)[0]);
740 v1.
scale(-(*v2p)[0]);
743 return std::vector<Real>(0);
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
ROL::Ptr< const std::vector< Element > > getVector() const
ROL::Ptr< ConStdVector< Real > > dual_vec_
Real dot(const Vector< Real > &x) const
Compute where .
ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
std::vector< Element > vector
int dimension() const
Return dimension of the vector space.
void plus(const Vector< Real > &x)
Compute , where .
Real norm() const
Returns where .
ConDualStdVector(const ROL::Ptr< std::vector< Element > > &std_vec)
void scale(const Real alpha)
Compute where .
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()
ROL::Ptr< std::vector< Element > > std_vec_
Real dot(const ROL::Vector< Real > &x) const
Compute where .
ROL::Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Real dot(const Vector< Real > &x) const
Compute where .
Real norm() const
Returns where .
ROL::Ptr< ConDualStdVector< Real > > dual_vec_
ROL::Ptr< std::vector< Element > > std_vec_
Real dot(const ROL::Vector< Real > &x) const
Compute where .
ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
void scale(const Real alpha)
Compute where .
std::vector< Element > vector
ConStdVector(const ROL::Ptr< std::vector< Element > > &std_vec)
ROL::Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ROL::Ptr< std::vector< Element > > getVector()
ROL::Ptr< const std::vector< Element > > getVector() const
void plus(const Vector< Real > &x)
Compute , where .
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.
ROL::Ptr< FiniteDifference< Real > > fd_
std::vector< Real > solveAugmentedSystem(Vector< Real > &v1, Vector< Real > &v2, const Vector< Real > &b1, const Vector< Real > &b2, const Vector< Real > &psi, Real &tol)
Normalization_Constraint(int n, Real dx, ROL::Ptr< FiniteDifference< Real > > fd, bool exactsolve)
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Evaluate .
void value(Vector< Real > &c, const Vector< Real > &psi, Real &tol)
Evaluate .
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Evaluate .
std::vector< Real > vector
ROL::Ptr< const vector > getVector(const V &x)
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Evaluate .
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Evaluate .
Objective_GrossPitaevskii(const Real &g, const Vector< Real > &V, ROL::Ptr< FiniteDifference< Real > > fd)
ROL::Ptr< const std::vector< Real > > Vp_
ROL::Ptr< FiniteDifference< Real > > fd_
ROL::Ptr< const vector > Vp_
ROL::Ptr< const vector > getVector(const V &x)
void applyK(const Vector< Real > &v, Vector< Real > &kv)
Apply finite difference operator.
void gradient(Vector< Real > &g, const Vector< Real > &psi, Real &tol)
Evaluate .
std::vector< Real > vector
Real value(const Vector< Real > &psi, Real &tol)
Evaluate .
Real norm() const
Returns where .
int dimension() const
Return dimension of the vector space.
Real dot(const Vector< Real > &x) const
Compute where .
ROL::Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
void scale(const Real alpha)
Compute where .
Real dot(const ROL::Vector< Real > &x) const
Compute where .
ROL::Ptr< std::vector< Element > > std_vec_
ROL::Ptr< const std::vector< Element > > getVector() const
ROL::Ptr< std::vector< Element > > getVector()
ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
void plus(const Vector< Real > &x)
Compute , where .
OptDualStdVector(const ROL::Ptr< std::vector< Element > > &std_vec, ROL::Ptr< FiniteDifference< Real > >fd)
std::vector< Element > vector
ROL::Ptr< OptStdVector< Real > > dual_vec_
ROL::Ptr< FiniteDifference< Real > > fd_
OptStdVector(const ROL::Ptr< std::vector< Element > > &std_vec, ROL::Ptr< FiniteDifference< Real > >fd)
void plus(const Vector< Real > &x)
Compute , where .
ROL::Ptr< vector > getVector()
ROL::Ptr< const std::vector< Element > > getVector() const
ROL::Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Real dot(const ROL::Vector< Real > &x) const
Compute where .
int dimension() const
Return dimension of the vector space.
ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
const Vector< Real > & dual() const
Modify the dual of vector u to be .
Real dot(const Vector< Real > &x) const
Modify the dot product between primal variables to be .
ROL::Ptr< FiniteDifference< Real > > fd_
Real norm() const
Returns where .
ROL::Ptr< const vector > getVector() const
ROL::Ptr< OptDualStdVector< Real > > dual_vec_
ROL::Ptr< std::vector< Element > > std_vec_
void scale(const Real alpha)
Compute where .
std::vector< Element > vector
Defines the general constraint operator interface.
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
Provides the interface to evaluate objective functions.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .