7 #ifndef SQPSTEP_H_INCLUDED
8 #define SQPSTEP_H_INCLUDED
77 bool SQPstep(
const RSVScalc &calcobj,
const Eigen::MatrixXd &dConstrAct,
const Eigen::RowVectorXd &dObjAct,
78 const Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct, Eigen::VectorXd &deltaDVAct,
bool &isNan,
79 bool &isLarge,
bool attemptConstrOnly =
true);
112 template <
template <
typename>
class T>
113 bool SQPstep(
const RSVScalc &calcobj,
const Eigen::MatrixXd &dConstrAct,
const Eigen::RowVectorXd &dObjAct,
114 const Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct, Eigen::VectorXd &deltaDVAct,
bool &isNan,
115 bool &isLarge,
bool attemptConstrOnly =
true);
131 bool SQPsens_sparse(
const Eigen::MatrixXd &sensMult,
const MatrixXd_sparse &sensInv, Eigen::MatrixXd &sensRes);
134 bool SQPsens(
const Eigen::MatrixXd &sensMult,
const Eigen::MatrixXd &sensInv, Eigen::MatrixXd &sensRes);
136 template <
template <
typename>
class T>
137 bool SQPsens(
const Eigen::MatrixXd &sensMult,
const Eigen::MatrixXd &sensInv, Eigen::MatrixXd &sensRes);
141 template <
template <
typename>
class T>
142 bool SQPstep(
const RSVScalc &calcobj,
const Eigen::MatrixXd &dConstrAct,
const Eigen::RowVectorXd &dObjAct,
143 const Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct, Eigen::VectorXd &deltaDVAct,
bool &isNan,
144 bool &isLarge,
bool attemptConstrOnly)
146 return (
SQPstep<T<Eigen::MatrixXd>>(calcobj, dConstrAct, dObjAct, constrAct, lagMultAct, deltaDVAct, isNan, isLarge,
151 bool SQPstep(
const RSVScalc &calcobj,
const Eigen::MatrixXd &dConstrAct,
const Eigen::RowVectorXd &dObjAct,
152 const Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct, Eigen::VectorXd &deltaDVAct,
bool &isNan,
153 bool &isLarge,
bool attemptConstrOnly)
155 Eigen::LDLT<Eigen::MatrixXd> condsys(calcobj.
HLag);
156 Eigen::MatrixXd temp1, temp2;
157 T HLagSystem(calcobj.
HLag);
159 std::cout <<
" (rcond) " << condsys.rcond();
161 temp1 = HLagSystem.solve(dConstrAct.transpose());
162 temp2 = HLagSystem.solve(dObjAct.transpose());
164 T LagMultSystem(dConstrAct * (temp1));
166 lagMultAct = LagMultSystem.solve(constrAct - (dConstrAct * (temp2)));
170 if (!attemptConstrOnly && (isLarge || isNan))
172 std::cout <<
"(early sqp return) ";
173 return (isLarge || isNan);
175 if (isLarge || isNan)
178 std::cout <<
"(constrmov) ";
179 deltaDVAct = -dConstrAct.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(constrAct);
183 deltaDVAct = -(HLagSystem.solve(dObjAct.transpose() + dConstrAct.transpose() * lagMultAct));
185 return (isLarge || isNan);
189 bool SQPstep_sparse(
const RSVScalc &calcobj,
const MatrixXd_sparse &dConstrAct,
const Eigen::RowVectorXd &dObjAct,
190 const Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct, Eigen::VectorXd &deltaDVAct,
191 bool &isNan,
bool &isLarge,
bool attemptConstrOnly)
195 HLagSystem.compute(calcobj.HLag_sparse);
197 if (HLagSystem.info() != Eigen::Success)
202 return (isLarge || isNan);
205 MatrixXd_sparse temp1 = dConstrAct.transpose();
206 temp1.makeCompressed();
207 MatrixXd_sparse temp2 = dConstrAct * HLagSystem.solve(temp1);
208 temp2.makeCompressed();
209 LagMultSystem.compute(temp2);
210 if (LagMultSystem.info() != Eigen::Success)
215 return (isLarge || isNan);
217 lagMultAct = LagMultSystem.solve(constrAct - (dConstrAct * HLagSystem.solve(dObjAct.transpose())));
221 if (!attemptConstrOnly && (isLarge || isNan))
223 std::cout <<
"(early sqp return) ";
224 return (isLarge || isNan);
226 if (isLarge || isNan)
229 std::cout <<
"(constrmov) ";
230 Eigen::SparseQR<MatrixXd_sparse, Eigen::COLAMDOrdering<int>> gradOnlySolver;
231 gradOnlySolver.compute(dConstrAct);
232 deltaDVAct = -gradOnlySolver.solve(constrAct);
236 deltaDVAct = -(HLagSystem.solve(dObjAct.transpose() + dConstrAct.transpose() * lagMultAct));
238 return (isLarge || isNan);
241 template <
template <
typename>
class T>
242 bool SQPsens(
const Eigen::MatrixXd &sensMult,
const Eigen::MatrixXd &sensInv, Eigen::MatrixXd &sensRes)
244 return SQPsens<T<Eigen::MatrixXd>>(sensMult, sensInv, sensRes);
248 bool SQPsens(
const Eigen::MatrixXd &sensMult,
const Eigen::MatrixXd &sensInv, Eigen::MatrixXd &sensRes)
250 T HLagSystem(sensInv);
252 sensRes = -HLagSystem.solve(sensMult);
257 bool SQPsens_sparse(
const Eigen::MatrixXd &sensMult,
const MatrixXd_sparse &sensInv, Eigen::MatrixXd &sensRes)
260 HLagSystem.compute(sensInv);
261 if (HLagSystem.info() != Eigen::Success)
267 sensRes = -(HLagSystem.solve(sensMult));
Provides the infrastructure for calculation of the RSVS equations.
void ResizeLagrangianMultiplier(const RSVScalc &calcobj, Eigen::VectorXd &lagMultAct, bool &isLarge, bool &isNan)
Resizes the lagrangian multiplier LagMultAct based on whether any of its values are nan or too large.
bool SQPsens_sparse(const Eigen::MatrixXd &sensMult, const MatrixXd_sparse &sensInv, Eigen::MatrixXd &sensRes)
Calculation for the sparse SQP sensitivity.
bool SQPstep(const RSVScalc &calcobj, const Eigen::MatrixXd &dConstrAct, const Eigen::RowVectorXd &dObjAct, const Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct, Eigen::VectorXd &deltaDVAct, bool &isNan, bool &isLarge, bool attemptConstrOnly=true)
Template for calculation of an SQP step.
Provide std::vector container with hashed index mapping.
Class to handle the RSVS calculation.
Eigen::MatrixXd HLag
Lagrangian Hessian, size: [nDv, nDv].
Provides all the mesh tools used for the generation of 3D grids and geometries.
Provides the core restricted surface snake container.
Provides a triangulation for snake and meshes.
Provides the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_NOTHROW(M)
Generic rsvs warning.