Skip to content

Commit 5887c75

Browse files
committed
added volume and lumped matrix
1 parent bf79f0d commit 5887c75

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed

src/Optimization/InnerProduct.cpp

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7779
InnerProduct::~InnerProduct()
7880
{
7981
delete vec_n2_;
8082
delete vec_n_;
83+
delete M_lump_;
8184
}
8285

8386
bool InnerProduct::apply_M(const hiopVector& x, hiopVector& y) const
@@ -153,12 +156,13 @@ double InnerProduct::norm_M_one(const hiopVector&x) const
153156
double 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
168172
double 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

src/Optimization/InnerProduct.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ class InnerProduct
109109

110110
// Computes the "volume" of the space, norm of 1 function
111111
double volume() const;
112+
113+
// Return vector containing the diagonals of the lumped mass matrix, possibly creating the internal object
114+
const hiopVector* M_lumped() const;
115+
116+
/*
117+
* @brief add linear damping term
118+
* Performs `this[i] = alpha*this[i] + sign[i]*ct*M_lumped[i]` where sign[i]=1 when EXACTLY one of
119+
* ixleft[i] and ixright[i] is 1.0 and sign=0 otherwise.
120+
*/
121+
void add_linear_damping_term(const hiopVector& ixl, const hiopVector& ixu, const double& ct, hiopVector& x) const;
112122
private:
113123
// Pointer to "client" NLP
114124
hiopNlpFormulation* nlp_;
@@ -117,6 +127,8 @@ class InnerProduct
117127
mutable hiopVector* vec_n_;
118128
// Working vector in the size n of the variables, allocated only when for the weighted case
119129
mutable hiopVector* vec_n2_;
130+
// Lumped mass matrix
131+
mutable hiopVector* M_lump_;
120132
};
121133

122134
} //end namespace

0 commit comments

Comments
 (0)