70 #include "Teuchos_oblackholestream.hpp"
71 #include "Teuchos_GlobalMPISession.hpp"
72 #include "Teuchos_XMLParameterListHelpers.hpp"
87 template <
class Real,
class Element=Real>
90 template <
class Real,
class Element=Real>
93 template <
class Real,
class Element=Real>
96 template <
class Real,
class Element=Real>
103 template <
class Real,
class Element>
107 Teuchos::RCP<std::vector<Element> > std_vec_;
108 mutable Teuchos::RCP<OptDualStdVector<Real> > dual_vec_;
110 Teuchos::RCP<InnerProductMatrix<Real> >
ipmat_;
115 std_vec_(std_vec), dual_vec_(Teuchos::null), useRiesz_(useRiesz), ipmat_(ipmat) {}
119 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
120 unsigned dimension = std_vec_->size();
121 for (
unsigned i=0; i<dimension; i++) {
122 (*std_vec_)[i] += (*xvalptr)[i];
127 unsigned dimension = std_vec_->size();
128 for (
unsigned i=0; i<dimension; i++) {
129 (*std_vec_)[i] *= alpha;
138 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
139 unsigned dimension = std_vec_->size();
141 val = this->ipmat_->inner(std_vec_,xvalptr);
144 for (
unsigned i=0; i<dimension; i++) {
145 val += (*std_vec_)[i]*(*xvalptr)[i];
153 val = std::sqrt( dot(*
this) );
157 Teuchos::RCP<Vector<Real> >
clone()
const {
158 return Teuchos::rcp(
new OptStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size()) ),useRiesz_,ipmat_ ) );
161 Teuchos::RCP<const std::vector<Element> >
getVector()
const {
165 Teuchos::RCP<Vector<Real> >
basis(
const int i )
const {
166 Teuchos::RCP<OptStdVector> e = Teuchos::rcp(
new OptStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size(), 0.0)),useRiesz_, ipmat_ ) );
167 (const_cast <std::vector<Element> &> (*e->getVector()))[i]= 1.0;
177 dual_vec_ = Teuchos::rcp(
new OptDualStdVector<Real>( Teuchos::rcp(
new std::vector<Element>(*std_vec_) ), useRiesz_, ipmat_ ) );
180 this->ipmat_->apply(std_vec_, Teuchos::rcp_const_cast<std::vector<Real> >(dual_vec_->getVector()));
191 template <
class Real,
class Element>
195 Teuchos::RCP<std::vector<Element> > std_vec_;
196 mutable Teuchos::RCP<OptStdVector<Real> > dual_vec_;
198 Teuchos::RCP<InnerProductMatrix<Real> >
ipmat_;
203 std_vec_(std_vec), dual_vec_(Teuchos::null), useRiesz_(useRiesz), ipmat_(ipmat) {}
207 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
208 unsigned dimension = std_vec_->size();
209 for (
unsigned i=0; i<dimension; i++) {
210 (*std_vec_)[i] += (*xvalptr)[i];
215 unsigned dimension = std_vec_->size();
216 for (
unsigned i=0; i<dimension; i++) {
217 (*std_vec_)[i] *= alpha;
224 Teuchos::RCP<const std::vector<Element> > kxvalptr = ex.
getVector();
225 unsigned dimension = std_vec_->size();
228 val = ipmat_->inv_inner(std_vec_,kxvalptr);
231 for (
unsigned i=0; i<dimension; i++) {
232 val += (*std_vec_)[i]*(*kxvalptr)[i];
241 val = std::sqrt( dot(*
this) );
245 Teuchos::RCP<Vector<Real> >
clone()
const {
246 return Teuchos::rcp(
new OptDualStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size()) ), useRiesz_, ipmat_ ) );
249 Teuchos::RCP<const std::vector<Element> >
getVector()
const {
253 Teuchos::RCP<Vector<Real> >
basis(
const int i )
const {
254 Teuchos::RCP<OptDualStdVector> e = Teuchos::rcp(
new OptDualStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size(), 0.0)),useRiesz_, ipmat_ ) );
255 (const_cast <std::vector<Element> &> (*e->getVector()))[i]= 1.0;
262 dual_vec_ = Teuchos::rcp(
new OptStdVector<Real>( Teuchos::rcp(
new std::vector<Element>(*std_vec_) ), useRiesz_, ipmat_ ) );
264 this->ipmat_->solve(std_vec_, Teuchos::rcp_const_cast<std::vector<Real> >(dual_vec_->getVector()));
276 template <
class Real,
class Element>
280 Teuchos::RCP<std::vector<Element> > std_vec_;
281 mutable Teuchos::RCP<ConDualStdVector<Real> > dual_vec_;
285 ConStdVector(
const Teuchos::RCP<std::vector<Element> > & std_vec) : std_vec_(std_vec), dual_vec_(Teuchos::null) {}
289 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
290 unsigned dimension = std_vec_->size();
291 for (
unsigned i=0; i<dimension; i++) {
292 (*std_vec_)[i] += (*xvalptr)[i];
297 unsigned dimension = std_vec_->size();
298 for (
unsigned i=0; i<dimension; i++) {
299 (*std_vec_)[i] *= alpha;
306 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
310 unsigned dimension = std_vec_->size();
311 for (
unsigned i=0; i<dimension; i++) {
312 val += (*std_vec_)[i]*(*xvalptr)[i];
319 val = std::sqrt( dot(*
this) );
323 Teuchos::RCP<Vector<Real> >
clone()
const {
324 return Teuchos::rcp(
new ConStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size())) ) );
327 Teuchos::RCP<const std::vector<Element> >
getVector()
const {
331 Teuchos::RCP<Vector<Real> >
basis(
const int i )
const {
332 Teuchos::RCP<ConStdVector> e = Teuchos::rcp(
new ConStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size(), 0.0)) ) );
333 (const_cast <std::vector<Element> &> (*e->getVector()))[i]= 1.0;
340 dual_vec_ = Teuchos::rcp(
new ConDualStdVector<Real>( Teuchos::rcp(
new std::vector<Element>(*std_vec_) ) ) );
348 template <
class Real,
class Element>
352 Teuchos::RCP<std::vector<Element> > std_vec_;
353 mutable Teuchos::RCP<ConStdVector<Real> > dual_vec_;
357 ConDualStdVector(
const Teuchos::RCP<std::vector<Element> > & std_vec) : std_vec_(std_vec), dual_vec_(Teuchos::null) {}
361 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
362 unsigned dimension = std_vec_->size();
363 for (
unsigned i=0; i<dimension; i++) {
364 (*std_vec_)[i] += (*xvalptr)[i];
369 unsigned dimension = std_vec_->size();
370 for (
unsigned i=0; i<dimension; i++) {
371 (*std_vec_)[i] *= alpha;
378 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
379 unsigned dimension = std_vec_->size();
380 for (
unsigned i=0; i<dimension; i++) {
381 val += (*std_vec_)[i]*(*xvalptr)[i];
388 val = std::sqrt( dot(*
this) );
392 Teuchos::RCP<Vector<Real> >
clone()
const {
393 return Teuchos::rcp(
new ConDualStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size())) ) );
396 Teuchos::RCP<const std::vector<Element> >
getVector()
const {
400 Teuchos::RCP<Vector<Real> >
basis(
const int i )
const {
401 Teuchos::RCP<ConDualStdVector> e = Teuchos::rcp(
new ConDualStdVector( Teuchos::rcp(
new std::vector<Element>(std_vec_->size(), 0.0)) ) );
402 (const_cast <std::vector<Element> &> (*e->getVector()))[i]= 1.0;
409 dual_vec_ = Teuchos::rcp(
new ConStdVector<Real>( Teuchos::rcp(
new std::vector<Element>(*std_vec_) ) ) );
424 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real> >
433 Teuchos::RCP<NodalBasis<Real> >
nb_;
442 Teuchos::RCP<std::vector<Real> > psi2q =
443 Teuchos::rcp(
new std::vector<Real> (nb_->nq_, 0.0) );
445 nb_->lagrange_->dinterp(*psip,*psi2q);
447 for(
int i=0;i<nb_->nq_;++i) {
448 (*psi2q)[i] *= (*psi2q)[i];
450 nonlinear_->update(*psi2q);
460 ni_(ni), gnl_(gnl), nb_(nb), kinetic_(kinetic),
461 potential_(potential), nonlinear_(nonlinear) {}
467 Teuchos::RCP<const std::vector<Real> > psip =
468 (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(psi))).getVector();
470 this->updateNonlinear(psip);
473 Real J = 0.5*( kinetic_->inner(psip,psip) +
474 potential_->inner(psip,psip) +
475 gnl_*nonlinear_->inner(psip,psip) );
484 Teuchos::RCP<const std::vector<Real> > psip =
485 (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(psi))).getVector();
488 Teuchos::RCP<std::vector<Real> > gp =
489 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<XDual>(g)).getVector());
491 this->updateNonlinear(psip);
493 kinetic_->apply(psip,gp);
494 potential_->applyadd(psip,gp);
495 nonlinear_->applyaddtimes(psip,gp,2*gnl_);
500 Teuchos::RCP<const std::vector<Real> > psip =
501 (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(psi))).getVector();
504 Teuchos::RCP<const std::vector<Real> > vp = (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(v))).getVector();
507 Teuchos::RCP<std::vector<Real> > hvp = Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<XDual>(hv)).getVector());
509 kinetic_->apply(vp,hvp);
510 potential_->applyadd(vp,hvp);
511 nonlinear_->applyaddtimes(vp,hvp,6*gnl_);
520 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
524 Teuchos::RCP<InnerProductMatrix<Real> >
mass_;
533 Teuchos::RCP<std::vector<Real> > cp = Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<CPrim>(c)).getVector());
536 Teuchos::RCP<const std::vector<Real> > psip =
537 (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(psi))).getVector();
539 (*cp)[0] = mass_->inner(psip,psip)-1.0;
546 Teuchos::RCP<std::vector<Real> > jvp = Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<CPrim>(jv)).getVector());
549 Teuchos::RCP<const std::vector<Real> > vp = (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(v))).getVector();
552 Teuchos::RCP<const std::vector<Real> > psip =
553 (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(psi))).getVector();
555 (*jvp)[0] = 2.0*mass_->inner(psip,vp);
562 Teuchos::RCP<std::vector<Real> > ajvp = Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<XDual>(ajv)).getVector());
565 Teuchos::RCP<const std::vector<Real> > vp = (Teuchos::dyn_cast<CDual>(
const_cast<Vector<Real> &
>(v))).getVector();
568 Teuchos::RCP<const std::vector<Real> > psip =
569 (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(psi))).getVector();
571 mass_->apply(psip,ajvp);
572 for(
unsigned i=0;i<psip->size();++i) {
573 (*ajvp)[i] *= 2.0*(*vp)[0];
582 Teuchos::RCP<std::vector<Real> > ahuvp = Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<XDual>(ahuv)).getVector());
585 Teuchos::RCP<const std::vector<Real> > up = (Teuchos::dyn_cast<CDual>(
const_cast<Vector<Real> &
>(u))).getVector();
588 Teuchos::RCP<const std::vector<Real> > vp = (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(v))).getVector();
591 Teuchos::RCP<const std::vector<Real> > psip =
592 (Teuchos::dyn_cast<XPrim>(
const_cast<Vector<Real> &
>(psi))).getVector();
594 mass_->apply(vp,ahuvp);
595 for(
unsigned i=0;i<psip->size();++i) {
596 (*ahuvp)[i] *= 2.0*(*up)[0];
Normalization_Constraint(Teuchos::RCP< InnerProductMatrix< Real > > mass)
Provides the interface to evaluate objective functions.
Real value(const Vector< Real > &psi, Real &tol)
Compute value.
void scale(const Real alpha)
Compute where .
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ConStdVector(const Teuchos::RCP< std::vector< Element > > &std_vec)
Real norm() const
Returns where .
OptDualStdVector(const Teuchos::RCP< std::vector< Element > > &std_vec, bool useRiesz, Teuchos::RCP< InnerProductMatrix< Real > > ipmat)
void value(Vector< Real > &c, const Vector< Real > &psi, Real &tol)
Evaluate the constraint operator at .
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Apply Hessian approximation to vector.
Real dot(const Vector< Real > &x) const
Compute where .
Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Teuchos::RCP< const std::vector< Element > > getVector() const
Teuchos::RCP< InnerProductMatrix< Real > > kinetic_
Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
int dimension() const
Return dimension of the vector space.
Teuchos::RCP< const std::vector< Element > > getVector() const
Defines the linear algebra or vector space interface.
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Teuchos::RCP< InnerProductMatrix< Real > > nonlinear_
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Apply the constraint Jacobian at , , to vector .
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Teuchos::RCP< Vector< Real > > basis(const int i) const
Return i-th basis vector.
Teuchos::RCP< Vector< Real > > basis(const int i) const
Return i-th basis vector.
Defines the equality constraint operator interface.
void scale(const Real alpha)
Compute where .
Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Real dot(const Vector< Real > &x) const
Compute where .
void scale(const Real alpha)
Compute where .
Teuchos::RCP< InnerProductMatrix< Real > > ipmat_
Teuchos::RCP< const std::vector< Element > > getVector() const
Teuchos::RCP< NodalBasis< Real > > nb_
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Objective_GrossPitaevskii(const int ni, const Real gnl, Teuchos::RCP< NodalBasis< Real > > nb, Teuchos::RCP< InnerProductMatrix< Real > > kinetic, Teuchos::RCP< InnerProductMatrix< Real > > potential, Teuchos::RCP< InnerProductMatrix< Real > > nonlinear)
int dimension() const
Return dimension of the vector space.
int dimension() const
Return dimension of the vector space.
Teuchos::RCP< InnerProductMatrix< Real > > ipmat_
Teuchos::RCP< Vector< Real > > basis(const int i) const
Return i-th basis vector.
Real norm() const
Returns where .
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 .
OptStdVector(const Teuchos::RCP< std::vector< Element > > &std_vec, bool useRiesz, Teuchos::RCP< InnerProductMatrix< Real > > ipmat)
void plus(const Vector< Real > &x)
Compute , where .
const Vector< Real > & dual() const
Modify the dual of vector u to be .
Real norm() const
Returns where .
Real dot(const Vector< Real > &x) const
Modify the dot product between primal variables to be .
ConDualStdVector(const Teuchos::RCP< std::vector< Element > > &std_vec)
Teuchos::RCP< InnerProductMatrix< Real > > mass_
Teuchos::RCP< InnerProductMatrix< Real > > potential_
void gradient(Vector< Real > &g, const Vector< Real > &psi, Real &tol)
Compute gradient.
Teuchos::RCP< const std::vector< Element > > getVector() const
void plus(const Vector< Real > &x)
Compute , where .
void updateNonlinear(Teuchos::RCP< const std::vector< Real > > psip)
Teuchos::RCP< Vector< Real > > basis(const int i) const
Return i-th basis vector.
void plus(const Vector< Real > &x)
Compute , where .
Real norm() const
Returns where .
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &psi, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
void scale(const Real alpha)
Compute where .