Reimplementing constraint solver

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

No, things are worse than that. I changed a to 0.1, and now it takes 32 subdivisions to arrive at error better than 1e-6 :(
And in this case, the accuracy is improving extremely slowly as the number of subdivisions is increased, which is depressing. Something's wrong with my estimate.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: Sat Mar 28, 2020 10:58 pm No, things are worse than that. I changed a to 0.1, and now it takes 32 subdivisions to arrive at error better than 1e-6 :(
And in this case, the accuracy is improving extremely slowly as the number of subdivisions is increased, which is depressing. Something's wrong with my estimate.
I guess you are looking for a general method for other closed curves too, not only for an ellipse.

Surely you know about the specific infinite series for the ellipse.

Something like "Infinite Series 2" of:
https://www.mathsisfun.com/geometry/ell ... meter.html

Then you do not have to subdivide...
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

abdullah wrote: Tue Mar 31, 2020 3:01 pm Surely you know about the specific infinite series for the ellipse.

Something like "Infinite Series 2" of:
https://www.mathsisfun.com/geometry/ell ... meter.html

Then you do not have to subdivide...
No, I didn't. Is there a version for an arc, not full ellipse?
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

abdullah wrote: Tue Mar 31, 2020 3:01 pm I guess you are looking for a general method for other closed curves too, not only for an ellipse.
Well, a general method is better than ellipse-specific, but either will do.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: Tue Mar 31, 2020 4:08 pm
abdullah wrote: Tue Mar 31, 2020 3:01 pm I guess you are looking for a general method for other closed curves too, not only for an ellipse.
Well, a general method is better than ellipse-specific, but either will do.
None for an arc to my knowledge.

I found as advice, what you were doing:
http://mathforum.org/library/drmath/view/51945.html

I have started rewriting the solver interface of SketchObject to accomodate different solvers.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

abdullah wrote: Tue Mar 31, 2020 5:30 pm I have started rewriting the solver interface of SketchObject to accomodate different solvers.
Great news! :D
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: Tue Mar 31, 2020 5:51 pmGreat news!
I have a question regarding ParameterStore and HParameterStore.

I have been looking at your example code to create the "Sketcher.h" equivalent of FCS, which I called "FCSSketcher.h"

I appears to me that in FCSSketcher.h, I need an HParameterStore to... well ... to store the parameters of geometry and constraints.

I initially wrote something like:

Code: Select all

class SketcherExport FCSSketch : public SketchSolver
{
    TYPESYSTEM_HEADER();

public:
    FCSSketch();
    
...
private:
    FCS::HParameterStore parameterStore;
};
This obviously won't work because HParameterStore is designed to only be susceptible of being created via the static make() function, so the constructor won't be able to initialise the object and I won't be able to arrive to the body of the constructor to call make.

This makes me think that maybe you thought it to be used in a different way... and that is the question. How did you intend to use it from c++.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

I guess you are getting a compile error that parameterStore must be initialized. Add : parameterStore(Py::None()) to the constructor, and then fill it in in constructor code by calling make method.

Or we can change it to support construction via new, I wanted to do that.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: ...
More questions.

So far, in FCSSketch, I have these data members:

Code: Select all

private:
    // Solver
    FCS::HParameterStore parameterStore;
    
    // Interface classes
    std::vector<GeoDef>         Geoms;
    std::vector<FCS::G2D::HParaPoint>     Points;
    
};
I am here:

Code: Select all

int FCSSketch::addPoint(const Part::GeomPoint &point, bool fixed)
{
    //std::vector<double *> &params = fixed ? FixParameters : Parameters;

    // create our own copy
    GeomPoint *p = static_cast<GeomPoint*>(point.clone());
    // create the definition struct for that geom
    GeoDef def;
    def.geo  = p;
    def.type = GeoType::Point;

    FCS::G2D::HParaPoint hp = new FCS::G2D::ParaPoint();
    
    hp->
Here I have to do the setValue(). In the Python code you pass parameter store to the ParaPointPy. I have learnt that this is then use with a Dic and setAttrib. I think that the c++ way you thought may differ from that. Do I have to do a setAttrib? Could you give me an example of what to do in this addPoint function?
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

The easiest is to call makeParameters method of ParaPoint.
Also, you can assign attributes x and y of parapoint directly, they are public. You can use setAttr, but it is for python, and thus has no compile-time type checking.

If you modify ParameterRefs x and y of parapoint after calling update, you should call update() again. There is a "touch" mechanism for automating the update calls to an extent, but it only really works one time. I have not bothered to set up a comprehensive mechanism, it seems to be too much of a challenge for too little gain.
Post Reply