[PR] Sketcher Solver Improvements

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: [request for testing] Sketcher Solver Improvements

Postby abdullah » Fri Apr 27, 2018 7:15 pm

chrisb
Posts: 16861
Joined: Tue Mar 17, 2015 9:14 am

Re: [request for testing] Sketcher Solver Improvements

Postby chrisb » Fri Apr 27, 2018 8:17 pm

abdullah wrote:
Fri Apr 27, 2018 6:13 pm
If the additional constraint is removed internally, it shouldn't lead to problems later.
[/quote]

It should not. Does it in your experience?
[/quote]Usually it is the other way round: There is a problem with a sweep or loft and I go back looking at the sketches and find some redundancies.
To be honest: I cannot remember having seen perpendicular+symmetry before.
abdullah wrote:
Fri Apr 27, 2018 6:16 pm
Congratulations!! :)
No, that's not fair. You deserve all honour. It seems we have now the best sketcher ever.
chrisb
Posts: 16861
Joined: Tue Mar 17, 2015 9:14 am

Re: [request for testing] Sketcher Solver Improvements

Postby chrisb » Fri Apr 27, 2018 9:30 pm

I'm goiing through the CSG bugs

issue #743Most information is lost, probably tangent/coincidence issue. Closed as not reproducible
issue #1267To be closed when in Master.
issue #2342->@triplus please test.
issue #2363Duplicate of 1267

issue #002729 fixed the macro, tested, ok. To be closed when in Master.
issue #3366To be closed

More to come
chrisb
Posts: 16861
Joined: Tue Mar 17, 2015 9:14 am

Re: [request for testing] Sketcher Solver Improvements

Postby chrisb » Fri Apr 27, 2018 10:00 pm

issue #1557To be solved when in master.
issue #1041Duplicate, closed
issue #2406To be solved
chrisb
Posts: 16861
Joined: Tue Mar 17, 2015 9:14 am

Re: [request for testing] Sketcher Solver Improvements

Postby chrisb » Fri Apr 27, 2018 10:11 pm

issue #2170 Not sure about this, I don't even see what the error message is. But I realized the following:

This sketch
Bildschirmfoto 2018-04-28 um 00.05.07.png
Bildschirmfoto 2018-04-28 um 00.05.07.png (20.52 KiB) Viewed 279 times
shows one degree of freedom; which is correct, it could be solved e.g. by applying a vertical constraint to the points.

Applying a symmetry constraint (usually consuming 2 DOFs) solves this last DOF and shows a fully constrained sketch while I would expect it to be overconstrained.
chrisb
Posts: 16861
Joined: Tue Mar 17, 2015 9:14 am

Re: [request for testing] Sketcher Solver Improvements

Postby chrisb » Fri Apr 27, 2018 10:20 pm

When creating the following from scratch:
Bildschirmfoto 2018-04-28 um 00.15.22.png
Bildschirmfoto 2018-04-28 um 00.15.22.png (54.28 KiB) Viewed 278 times
it show only one DOF, while it needs e.g. radius+angle to fully constrain it.

However, when I delete the symmetry and reapply it, I get correctly two DOFs (with the same possible overconstraint as before).
Bildschirmfoto 2018-04-28 um 00.17.39.png
Bildschirmfoto 2018-04-28 um 00.17.39.png (38.39 KiB) Viewed 278 times
chrisb
Posts: 16861
Joined: Tue Mar 17, 2015 9:14 am

Re: [request for testing] Sketcher Solver Improvements

Postby chrisb » Fri Apr 27, 2018 10:28 pm

Similar situation with perpendiculars at an arc:
Bildschirmfoto 2018-04-28 um 00.25.38.png
Bildschirmfoto 2018-04-28 um 00.25.38.png (14.18 KiB) Viewed 277 times
If I connect the loose end of the radius to the center it shows erroneously 2 DOFs while it are in fact three.
Bildschirmfoto 2018-04-28 um 00.28.04.png
Bildschirmfoto 2018-04-28 um 00.28.04.png (30.24 KiB) Viewed 277 times
chrisb
Posts: 16861
Joined: Tue Mar 17, 2015 9:14 am

Re: [request for testing] Sketcher Solver Improvements

Postby chrisb » Fri Apr 27, 2018 10:30 pm

I want to add that I still am very grateful for the phantastic improvements in sketcher.

Thanks Abdullah!
chrisb
Posts: 16861
Joined: Tue Mar 17, 2015 9:14 am

Re: [request for testing] Sketcher Solver Improvements

Postby chrisb » Fri Apr 27, 2018 11:00 pm

issue #2797 To be solved as soon as merged to master.
issue #1865 to be solved
issue #1519 closed (was no bug)
issue #1460 to be closed
issue #1223 solved - from version: 0.13.2041 sic!
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: [request for testing] Sketcher Solver Improvements

Postby abdullah » Sat Apr 28, 2018 6:55 am

Great job with the tickets!!!
chrisb wrote:
Fri Apr 27, 2018 10:11 pm
issue #2170 Not sure about this, I don't even see what the error message is. But I realized the following:

This sketch
Bildschirmfoto 2018-04-28 um 00.05.07.png
shows one degree of freedom; which is correct, it could be solved e.g. by applying a vertical constraint to the points.

Applying a symmetry constraint (usually consuming 2 DOFs) solves this last DOF and shows a fully constrained sketch while I would expect it to be overconstrained.
I remember very well this sketch. Triplus brought it forward during a previous effort to improve the sketcher. It was of those that we reserved for investigating on a rainy day. Well, the rainy day has come ;)

Approach 1 (radius+angle+vertical alignment)
EigenSparseQR, Threads: 1, Vectorization: On, Pivot Threshold: 1e-13, Params: 17, Constr: 14, Rank: 14

Add radius

EigenSparseQR, Threads: 1, Vectorization: On, Pivot Threshold: 1e-13, Params: 17, Constr: 15, Rank: 15


Add Angle

EigenSparseQR, Threads: 1, Vectorization: On, Pivot Threshold: 1e-13, Params: 17, Constr: 16, Rank: 16

Add Vertical alignment constraint

EigenSparseQR, Threads: 1, Vectorization: On, Pivot Threshold: 1e-13, Params: 17, Constr: 17, Rank: 17
Sketcher::setUpSketch()-T:0
FullyConstr_1.png
FullyConstr_1.png (14.59 KiB) Viewed 254 times
I think that with this approach the sketcher behaves perfectly. There is never a (partially) redundant constraint. At the time of the ticket there was no vertical alignment constraint.

Approach 2 (radius+angle+symmetry)
EigenSparseQR, Threads: 1, Vectorization: On, Pivot Threshold: 1e-13, Params: 17, Constr: 18, Rank: 17
...
Sketcher::RedundantSolving-DogLeg-
Sketcher Redundant solving: 1 redundants
...
EigenSparseQR, Threads: 1, Vectorization: On, Pivot Threshold: 1e-13, Params: 17, Constr: 18, Rank: 17
...
Sketcher::RedundantSolving-DogLeg-
Sketcher Redundant solving: 1 redundants
If you get this, it would be ok, because it is the combination of radius and angle, what is partly redundant with the symmetric. In other words, removing radius or angle would no compensate for what the symmetry constraint introduces. The partly redundant part of the symmetric is transparently removed by the solver and you get "Fully constraint". There is no other way. This is correct behaviour.

The problem is that with this specific case, I have tried to reproduce it several times, and sometimes I get conflicting or redundant constraints. I have even closed the AppImage and started it again. Sometimes an extra solve changing the redundant solver to LM has solved the problem, others no. I think this is why this is marked with "J malformed matrix". The gradients of the Jacobian may be (part of) the problem. This needs more investigation from my side.

Approach 3 (symmetry+angle+radius or symmetry+radius+angle)

I have not managed to reproduce the symmetry alone reducing the DoFs to 1 DoF. But I believe you, it may be the case of above with J formation.

Following this approach of "symmetry first" I systematically arrive to a fully constrained sketch without problems of redundants or conflicting constraints. This may help me investigate what is happening above.

I think this ticket is unrelated to the problem we are trying to solve. The redundancy, when present, is always a partial redundancy, which this work does not fix (unless there is a single constraint that can be removed instead of solving that partial redundancy).