Sketcher: Solver Debug functionality: Ability to export a subsystem
=================================================================== It allows to export the c++ code to create a subsystem with the same information as the one solved using LM/DL/BGFS. In this commit the functionality is disabled (for production). To enable the functionality uncomment this line in planegcs/Constraints.h: //#define _GCS_EXTRACT_SOLVER_SUBSYSTEM_ When enabled, upon solving with LM/DL/BGFS, the c++ code to generate the subsystem is added to a subsystem.txt that is created in the FreeCAD execution directory. Note that the file is created in append mode, so it will append all normal/redundant solvings until the file is deleted. The resulting code can be directly pasted into a project similar to: https://github.com/abdullahtahiriyo/Eigen_LUPiv_Convergence Such a project only has libeigen as external dependency.
This commit is contained in:
parent
a029d90a98
commit
7c1c56a550
|
@ -26,6 +26,14 @@
|
|||
#include "Geo.h"
|
||||
#include "Util.h"
|
||||
|
||||
//#define _GCS_EXTRACT_SOLVER_SUBSYSTEM_ // This enables debuging code intended to extract information to file bug reports against Eigen, not for production code
|
||||
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
#define _PROTECTED_UNLESS_EXTRACT_MODE_ public
|
||||
#else
|
||||
#define _PROTECTED_UNLESS_EXTRACT_MODE_ protected
|
||||
#endif
|
||||
|
||||
namespace GCS
|
||||
{
|
||||
|
||||
|
@ -71,7 +79,7 @@ namespace GCS
|
|||
|
||||
class Constraint
|
||||
{
|
||||
protected:
|
||||
_PROTECTED_UNLESS_EXTRACT_MODE_:
|
||||
VEC_pD origpvec; // is used only as a reference for redirecting and reverting pvec
|
||||
VEC_pD pvec;
|
||||
double scale;
|
||||
|
@ -137,6 +145,9 @@ namespace GCS
|
|||
inline double* distance() { return pvec[4]; }
|
||||
public:
|
||||
ConstraintP2PDistance(Point &p1, Point &p2, double *d);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintP2PDistance(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -156,6 +167,9 @@ namespace GCS
|
|||
double da;
|
||||
public:
|
||||
ConstraintP2PAngle(Point &p1, Point &p2, double *a, double da_=0.);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintP2PAngle(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -176,6 +190,9 @@ namespace GCS
|
|||
inline double* distance() { return pvec[6]; }
|
||||
public:
|
||||
ConstraintP2LDistance(Point &p, Line &l, double *d);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintP2LDistance(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -197,6 +214,9 @@ namespace GCS
|
|||
public:
|
||||
ConstraintPointOnLine(Point &p, Line &l);
|
||||
ConstraintPointOnLine(Point &p, Point &lp1, Point &lp2);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintPointOnLine(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -216,6 +236,9 @@ namespace GCS
|
|||
public:
|
||||
ConstraintPointOnPerpBisector(Point &p, Line &l);
|
||||
ConstraintPointOnPerpBisector(Point &p, Point &lp1, Point &lp2);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintPointOnPerpBisector(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -236,6 +259,9 @@ namespace GCS
|
|||
inline double* l2p2y() { return pvec[7]; }
|
||||
public:
|
||||
ConstraintParallel(Line &l1, Line &l2);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintParallel(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -257,6 +283,9 @@ namespace GCS
|
|||
public:
|
||||
ConstraintPerpendicular(Line &l1, Line &l2);
|
||||
ConstraintPerpendicular(Point &l1p1, Point &l1p2, Point &l2p1, Point &l2p2);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintPerpendicular(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -280,6 +309,9 @@ namespace GCS
|
|||
ConstraintL2LAngle(Line &l1, Line &l2, double *a);
|
||||
ConstraintL2LAngle(Point &l1p1, Point &l1p2,
|
||||
Point &l2p1, Point &l2p2, double *a);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintL2LAngle(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -302,6 +334,9 @@ namespace GCS
|
|||
public:
|
||||
ConstraintMidpointOnLine(Line &l1, Line &l2);
|
||||
ConstraintMidpointOnLine(Point &l1p1, Point &l1p2, Point &l2p1, Point &l2p2);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintMidpointOnLine(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -322,6 +357,10 @@ namespace GCS
|
|||
public:
|
||||
ConstraintTangentCircumf(Point &p1, Point &p2,
|
||||
double *rd1, double *rd2, bool internal_=false);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintTangentCircumf(bool internal_){internal=internal_;};
|
||||
#endif
|
||||
inline bool getInternal() {return internal;};
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
@ -341,6 +380,9 @@ namespace GCS
|
|||
public:
|
||||
ConstraintPointOnEllipse(Point &p, Ellipse &e);
|
||||
ConstraintPointOnEllipse(Point &p, ArcOfEllipse &a);
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
inline ConstraintPointOnEllipse(){};
|
||||
#endif
|
||||
virtual ConstraintType getTypeId();
|
||||
virtual void rescale(double coef=1.);
|
||||
virtual double error();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -96,6 +96,10 @@ namespace GCS
|
|||
int solve_BFGS(SubSystem *subsys, bool isFine=true, bool isRedundantsolving=false);
|
||||
int solve_LM(SubSystem *subsys, bool isRedundantsolving=false);
|
||||
int solve_DL(SubSystem *subsys, bool isRedundantsolving=false);
|
||||
|
||||
#ifdef _GCS_EXTRACT_SOLVER_SUBSYSTEM_
|
||||
void extractSubsystem(SubSystem *subsys, bool isRedundantsolving);
|
||||
#endif
|
||||
public:
|
||||
int maxIter;
|
||||
int maxIterRedundant;
|
||||
|
|
|
@ -200,6 +200,11 @@ void SubSystem::setParams(Eigen::VectorXd &xIn)
|
|||
pvals[i] = xIn[i];
|
||||
}
|
||||
|
||||
void SubSystem::getConstraintList(std::vector<Constraint *> &clist_)
|
||||
{
|
||||
clist_= clist;
|
||||
}
|
||||
|
||||
double SubSystem::error()
|
||||
{
|
||||
double err = 0.;
|
||||
|
|
|
@ -63,6 +63,8 @@ namespace GCS
|
|||
void getParams(Eigen::VectorXd &xOut);
|
||||
void setParams(VEC_pD ¶ms, Eigen::VectorXd &xIn);
|
||||
void setParams(Eigen::VectorXd &xIn);
|
||||
|
||||
void getConstraintList(std::vector<Constraint *> &clist_);
|
||||
|
||||
double error();
|
||||
void calcResidual(Eigen::VectorXd &r);
|
||||
|
|
Loading…
Reference in New Issue
Block a user