@@ -64,20 +64,23 @@ InnerProduct::InnerProduct(hiopNlpFormulation* nlp)
6464{
6565 printf (" InnerProduct::InnerProduct begin\n " ); fflush (stdout);
6666 assert (nlp);
67+ M_lump_ = nullptr ;
6768 if (nlp->useWeightedInnerProd ()) {
6869 vec_n_ = nlp_->alloc_primal_vec ();
6970 vec_n2_ = nlp_->alloc_primal_vec ();
7071 } else {
7172 vec_n_ = nullptr ;
7273 vec_n2_ = nullptr ;
7374 }
75+
7476 printf (" InnerProduct::InnerProduct end\n " ); fflush (stdout);
7577}
7678
7779InnerProduct::~InnerProduct ()
7880{
7981 delete vec_n2_;
8082 delete vec_n_;
83+ delete M_lump_;
8184}
8285
8386bool InnerProduct::apply_M (const hiopVector& x, hiopVector& y) const
@@ -153,12 +156,13 @@ double InnerProduct::norm_M_one(const hiopVector&x) const
153156double InnerProduct::norm_complementarity (const hiopVector& x) const
154157{
155158 if (nlp_->useWeightedInnerProd ()) {
156- // opt! pre-compute M*1
157- vec_n_->copyFrom (x);
158- vec_n_->component_abs ();
159- nlp_->eval_M (*vec_n_, *vec_n2_);
160- vec_n_->setToConstant (1 .);
161- return vec_n_->dotProductWith (*vec_n2_);
159+ // //opt! pre-compute M*1
160+ // vec_n_->copyFrom(x);
161+ // vec_n_->component_abs();
162+ // nlp_->eval_M(*vec_n_, *vec_n2_);
163+ // vec_n_->setToConstant(1.);
164+ // return vec_n_->dotProductWith(*vec_n2_);
165+ return x.infnorm ();
162166 } else {
163167 return x.infnorm ();
164168 }
@@ -168,13 +172,53 @@ double InnerProduct::norm_complementarity(const hiopVector& x) const
168172double InnerProduct::volume () const
169173{
170174 if (nlp_->useWeightedInnerProd ()) {
171- // opt! pre-compute M*1
172- vec_n_->setToConstant (1 .);
173- nlp_->eval_M (*vec_n_, *vec_n2_);
174- return vec_n2_->dotProductWith (*vec_n_);
175+ double vol_total = nlp_->m_ineq_low () + nlp_->m_ineq_upp ();
176+ if (nlp_->n_low () > 0 || nlp_->n_upp () > 0 ) {
177+ // compute ||1||_M
178+ // vec_n_->setToConstant(1.);
179+ const double vol_mult_bnds = M_lumped ()->onenorm ();
180+ if (nlp_->n_low () > 0 ) {
181+ // For weighted Hilbert spaces we assume that if lower bounds are present, they are for all vars
182+ vol_total += vol_mult_bnds;
183+ }
184+ if (nlp_->n_upp () > 0 ) {
185+ // For weighted Hilbert spaces we assume that if lower bounds are present, they are for all vars
186+ vol_total += vol_mult_bnds;
187+ }
188+ }
189+ return vol_total;
175190 } else {
176191 return nlp_->n_complem ();
177192 }
178193}
179194
195+ // Return vector containing the diagonals of the lumped mass matrix, possibly creating the internal object
196+ const hiopVector* InnerProduct::M_lumped () const
197+ {
198+ if (M_lump_ == nullptr ) {
199+ M_lump_ = nlp_->alloc_primal_vec ();
200+ if (nlp_->useWeightedInnerProd ()) {
201+ vec_n_->setToConstant (1 .);
202+ apply_M (*vec_n_, *M_lump_);
203+ } else {
204+ M_lump_->setToConstant (1 .);
205+ }
206+ }
207+ return M_lump_;
208+ }
209+
210+ void InnerProduct::
211+ add_linear_damping_term (const hiopVector& ixl, const hiopVector& ixu, const double & ct, hiopVector& x) const
212+ {
213+ if (nlp_->useWeightedInnerProd ()) {
214+ vec_n_->copyFrom (ixl);
215+ vec_n_->axpy (-1.0 , ixu);
216+ vec_n_->componentMult (*M_lumped ());
217+ x.axpy (ct, *vec_n_);
218+ } else {
219+ x.addLinearDampingTerm (ixl, ixu, 1.0 , ct);
220+ }
221+ }
222+
223+
180224} // end namespace
0 commit comments