Invalid solution from solver that is actually valid

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
numo68
Posts: 19
Joined: Wed Apr 28, 2021 10:12 pm

Invalid solution from solver that is actually valid

Post by numo68 »

Hello,

I am trying to create an enclosure and am fighting a bit with how to correctly constrain a parametric one so the solution is stable. The file in attach is experimental after several iterations one and I know it is not optimal, but I am pretty much a newbie in this area without a good intuition of what is the optimal way of doing things.

To reproduce the problem: in EncFrontBackBaseSketch change the custom property inner_length from 150 to 100. The solution converges correctly but I get the following in the report view:
Playground.FCStd
(45.87 KiB) Downloaded 10 times

Code: Select all

08:35:28  Updating geometry: Error build geometry(4): gp_Circ::SetRadius() - radius should be positive number
08:35:28  Invalid solution from LevenbergMarquardt solver.
08:35:28  Updating geometry: Error build geometry(16): gp_Circ::SetRadius() - radius should be positive number
08:35:28  Invalid solution from DogLeg solver.
08:35:28  Updating geometry: Error build geometry(20): gp_Circ::SetRadius() - radius should be positive number
08:35:28  Invalid solution from LevenbergMarquardt solver.
It can well be that the parametrization actually has multiple solutions, but I don't see that in the example provided. That happened to me with the vertical/horizontal length ones where changing a parameter caused the relative position of the constrained points (which one is left and which right) to flip - the solver was happy, I was not at all :)

I vaguely understand that when a parameter is changed, the solver has to calculate some set of possible solution and converge on one. Is this a nuisance error caused by encountering an "impossible" branch that can be safely ignored, or am I risking that the whole thing breaks for some combination of parameters?

Thanks

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.2.29177 +426 (Git)
Build type: Release
Branch: (HEAD detached from 0.20.2)
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * Assembly4 0.12.3
  * fasteners 0.3.50
  * fcgear 1.0.0
  * lattice2 1.0.0
chrisb
Veteran
Posts: 53928
Joined: Tue Mar 17, 2015 9:14 am

Re: Invalid solution from solver that is actually valid

Post by chrisb »

The message comes probably from one solver, which cannot solve and then the fallback succeeds. You can avoid the issues if you add two more expressions assuring non zero lengths, perhaps even one of them will be sufficient.
Attachments
Playground_cb.FCStd
(26.95 KiB) Downloaded 7 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
numo68
Posts: 19
Joined: Wed Apr 28, 2021 10:12 pm

Re: Invalid solution from solver that is actually valid

Post by numo68 »

chrisb wrote: Thu Mar 23, 2023 10:56 am The message comes probably from one solver, which cannot solve and then the fallback succeeds. You can avoid the issues if you add two more expressions assuring non zero lengths, perhaps even one of them will be sufficient.
The attached file actually produced the "flip" right away... Okay, at least I know that this is not an easy area :)
Attachments
FreeCAD_PpUGZhOMdz.png
FreeCAD_PpUGZhOMdz.png (26.69 KiB) Viewed 572 times
Workshop_Notes
Posts: 590
Joined: Wed Sep 29, 2021 8:35 am

Re: Invalid solution from solver that is actually valid

Post by Workshop_Notes »

If you go from 150 to 100, as you say, the report view complains. As the solver goes through its process, the 50mm change is causing something (temporarily) to go to zero, but then further along the solver process, the thing that becomes zero is recalculated to its new value and the solver completes.

You can go from 150 to 140 with no problem and then all the way to 100 in 10mm steps with no error message. By trial and error, I found that you can go from 150 to 129 with no problem, but if you try 150 to 128, the error resurfaces. You can go from 129 to 105 with no issue, but try 129 to 104 and it errors. So it is not the change as such that is causing the error but the size of the change you are asking for. The stomach of the solver can accommodate unlimited Big Macs, but its mouth can only eat them one at a time - it chokes if you try to cram in two at once.
chrisb
Veteran
Posts: 53928
Joined: Tue Mar 17, 2015 9:14 am

Re: Invalid solution from solver that is actually valid

Post by chrisb »

numo68 wrote: Thu Mar 23, 2023 12:34 pm The attached file actually produced the "flip" right away
What did you change?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
numo68
Posts: 19
Joined: Wed Apr 28, 2021 10:12 pm

Re: Invalid solution from solver that is actually valid

Post by numo68 »

chrisb wrote: Thu Mar 23, 2023 1:21 pm What did you change?
Nothing. Downloaded, opened and opened the EncFrontBackWallsSketch.

There is a

Code: Select all

16:20:06  No extension found of type 'PartGui::ViewProviderGridExtension'
16:20:06  No extension found of type 'PartGui::ViewProviderGridExtension'
in the report view, don't know whether it can be related.
Workshop_Notes wrote: Thu Mar 23, 2023 1:20 pm So it is not the change as such that is causing the error but the size of the change you are asking for. The stomach of the solver can accommodate unlimited Big Macs, but its mouth can only eat them one at a time - it chokes if you try to cram in two at once.
Yep, makes sense and I don't attempt to understand the math and logic beyond all of that. It is more that I am concerned with the inability to know whether the constraining is generally fine and it is going to converge if I do small steps, or that there is an ambiguity, the set of constraints is flawed and will explode in my face ten features later...

My gut feeling is actually that unless I am overlooking something the "flips" cannot even be fully eliminated in some cases without overconstraining the sketch. A radius has to be positive but a horizontal dim/vertical dim/length constraint has afaik no "sign" preventing it to flip the direction of the vector between those endpoints.
chrisb
Veteran
Posts: 53928
Joined: Tue Mar 17, 2015 9:14 am

Re: Invalid solution from solver that is actually valid

Post by chrisb »

numo68 wrote: Thu Mar 23, 2023 3:39 pm Nothing. Downloaded, opened and opened the EncFrontBackWallsSketch.
Oh, I didn't rework that one. It's failing because the length doesn't make any sense. You don't need it at all, use Custom_inner_length and Custom_front_back_thickness instead.
Attachments
Playground_cb2.FCStd
(26.69 KiB) Downloaded 4 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply