Commit Graph

117 Commits

Author SHA1 Message Date
Abdullah Tahiri
fc904cc1f1 Sketcher: Fixes wrong redundancy reporting
==========================================

fixes #6174

Problem
=======

The popularity contest heuristic was designed to assume that removing one solver constraint from a redundant group would potentially satisfy it.

This means that for sketcher constraints comprising several solver constraints, the sketcher constraint would never be notified as redundant, but
always partially redundant (where the case may be that it is redundant or that it is partially redundant). This happens because after removing one
solver constraint, it may happen:

(a) that no other solver constraint corresponding to the sketcher constraint remains in the redundant group (so it is indeed partially redundant)
(b) that at least one other solver constraint corresponding to the sketcher constraint remains in the redundant group (so if all solver constraints
remain in the redundant group, the sketcher constraint is actually redundant). This happens because solver constraints of a single sketcher constraint
are orthogonal and consequently, a conflict (or redundancy) emanating from removing one of them cannot actually satisfy the group, as it has no effect
on the other.

Solution
========

When popularity constraint decides on one solver constraint, remove any other solver constraint of the same tag (i.e. same sketcher constraint) that is
present in the conflict group (case b). This does not affect case a, because the solver constraint that is not redundant is not present in the conflict
(redundancy) group.
2023-05-03 16:32:50 +02:00
Florian Foinant-Willig
d3322ead12 Sketcher : Circle to Line Distance Constraint 2023-05-02 15:41:51 +02:00
luzpaz
38a01939e0 Migrate domain name from freecadweb to freecad (#9352)
* Migrate domain name from freecadweb to freecad
* Migrate src/Mod/Material files
* Migrate Stylesheet related files
* Migrate *.svg files
* Migrate miscellaneous files
* Migrate some build files
* Migrate recently added TD AR_IRAM template files

Closes #6415
2023-04-24 15:19:20 -05:00
André Caldas
82900b2417 Deletes GCS::Constraint directly instead of calling GCS::free(). 2023-04-06 16:29:48 +02:00
Uwe
53de24ae2d [Sketch] placecgs: remove unused includes
- also sort includes
- also fix too long lines etc. (done by clang formatter)
2023-03-26 20:27:18 +02:00
Ajinkya Dahale
68d67ecb87 [Sketcher][planegcs] Fix knot position in non-uniform B-spline
The default factors set in `addConstraintInternalAlignmentKnotPoint` does not
work if the knots around a C1 knot are not equally far.
2023-03-24 16:30:48 +01:00
flachyjoe
e2a13763e9 Sketcher: Add circle to circle distance constraint 2023-03-19 14:05:35 +01:00
Abdullah Tahiri
ee0c3ad5c1 Console/ILogger: Refactor and extension
=======================================

Refactor:
 - Substitute the use of variadic templates with parameter packs.
 - Use recently incorporated external library "fmt" to handle printf like formating.
 - Extensive cleaning of pragmas and unnecessary forward declarations.
 - Parameter packs and libfmt provide a much stronger type checking now, so
   conversions that are by standard implicit as bool to int need an explicit static_cast
   to avoid compilation warnings.

Extension:
 - Include a notifier field, so that the originator of the message can be provided. E.g. Document#DocumentObject
 - Include a new type of message called CriticalMessage, this message is intended to have
   special behaviour in the future. Namely, it will be used to notify forward compatilibity issues.
   It will be used to substitute the current signal/slot mechanism.
 - Include two new types of messages for user notifications (Notification and TranslatedNotification). This messages
   will be use to convey UI notifications intended for the user (such as non-intrusive message about the usage of a tool). There
   are two versions to mark whether the string provided as a message is already translated or not. When using the console system for
   notifications, these notifications may originate from the App or the Gui. In the former, it is generally the case that the strings
   of messages are not (yet) translated (but they can be marked with QT_TRANSLATE_NOOP). In the latter, often the messages to be provided
   are already translated.

Python support for CriticalMessage, Notification and TranslatedNofification, including shortcuts:

    Crt = FreeCAD.Console.PrintCritical
    Ntf = FreeCAD.Console.PrintNotification
    Tnf = FreeCAD.Console.PrintTranslatedNotification
2023-03-07 16:13:23 +01:00
luzpaz
79e150a81b Fix trailing whitespace, typos, headers
Fix trailing whitespace, typos, and header uniformity.
2023-01-23 00:34:37 +01:00
Ajinkya Dahale
4f3f566423 [Sketcher] [planegcs] Add point-on-bspline constraint in planegcs
Only non-rational B-spline for now
2023-01-21 21:41:27 +01:00
Abdullah Tahiri
9811d6cbb9 GCS: Improvements to popularity contest and conflicting identification
======================================================================

1. Instead of excluding internal alignment constraints from popularity candidate selection, exclude them from the group altogether. This
ensures no group is non-empty with uneligible candidates, which prevents an infinite loop in uncommon circumnstances (when DoFs collapse).

2. Ensure no internal alignment constraint is identified when conflict ensues.
2023-01-06 13:49:56 -06:00
Ajinkya Dahale
af5bc953c9 [Sketcher][planegcs] Handle type issues with int and size_t
... and `unsigned int`

Suggestions thanks to @abdullahtahiriyo
2022-12-24 18:22:16 -06:00
Ajinkya Dahale
4c71957a97 [Sketcher] [planegcs] Add "tangent at b-spline knot" constraint
Also squashes:

[Sketcher] [planegcs] Support tangent at NURBS knot

...which means support rational B-splines
2022-12-24 18:22:16 -06:00
luz paz
056d1aea87 Fix various typos and grammatical issues 2022-11-30 12:45:29 +01:00
Ajinkya Dahale
e1485388d4 [Sketcher][planegcs] Make changes as per comments on #7484
Comments by @abdullahtahiriyo.

Remove default values and smaller constructor for `CenterOfGravity` and
`WeightedLinearCombination` constraints.

Clarify comments.

Improve readability of `CenterOfGravity` and `WeightedLinearCombination`
constraints.
2022-11-16 15:35:37 +01:00
Ajinkya Dahale
473a380b49 [Sketcher][planegcs] Set knot constraint as internal alignment 2022-11-16 15:35:37 +01:00
Ajinkya Dahale
ba4f2bf128 [Sketcher] Constrain B-spline knots as linear combination of poles
Also squashes:

[Sketcher] Create center of gravity constraint in planegcs

[Sketcher] typo

[Sketcher] Use accurate "weights" for knots

By weights we mean the linear combination factor B_i(x) such that
spline(x) = sum(pole_i * B_i(x)) for _non-rational_ splines.

[Sketcher] Use more appropriate weights for knots

These are relevant for knots _away_ from any ends (and possibly other high
multiplicity knots).

[Sketcher] Make COG constraint weights user-definable

[Sketcher] Make `flattenedknots` for periodic B-Splines

[Sketcher] Fix incorrect setup of `flattenedknots`

Without ensuring enough space, iterators become invalid. These iterators are
needed because for periodic B-splines we need to pad flattenedknots with offset
values within flattenedknots.

Apparently there is still some iterator issues even after the reserve. Just use
fresh vectors instead.

[Sketcher] Apply knot constraints by parameter

Hopefully this will allow directly applying constraints on knots.

[Sketcher] Disable some knot updating

[Sketcher] Use center of gravity constraint on knots

[Sketcher] Fix knot COG constraint for periodic splines

[Sketcher] Add start/end point of periodic spline to solver

This removes the trouble of transferring constraints to the underlying knot.

[Sketcher] Support knot constraints on rational B-splines

[Sketcher] Remove virtual from overridden methods in planegcs

Follow 0penbrain's comments

[Sketcher][planegcs] Use `unsigned int` in signatures

Also `size_t` at places

Suggestions by @abdullahtahiriyo
2022-11-16 15:35:37 +01:00
Abdullah Tahiri
4d1e1733e3 Sketcher: Solver - Improvement of popularity contest and bug fix
================================================================

Master has a problem in that internal alignment constraints are suggested to the user for removal.

This is fundamentally wrong, as an internal alignment constraint are an inherent part of the geometry. They cannot be the ones suggested for removal.

The popularity contest algorithm is an heuristic algorithm that determines which redundant/conflicting constraints should be proposed for removal.

Basically, the algorithm works on groups of redundant/conflicting constraints detected via the QR decomposition. A constraint may belong to more than one group.

The algorithm runs some heuristics, each constraint scoring a value, the one constraint from each group scoring the highest is proposed (is more popular and wins the contest).

This PR documents the algorithm, and adds a further condition, that internal alignment constraints are never proposed.

As the solver works with solver constraints as opposed to the sketcher, which works with sketcher constraints, information about whether a solver constraint originated from a
sketcher constraint that is internal alignment is necessary. So the solver constraint is extended to accomodate this piece of information.

As a bonus, it fixes a bug. Solver constraints carry information of the ID of the corresponding sketcher constraint in their tag. Knots are not currently implemented as constraints.
However, the tag index was not being update. This caused the popularity contest to provide wrong suggestions despite good detection.
2022-10-21 19:54:51 +02:00
Ajinkya Dahale
1b7fbe087a [Sketcher] [planegcs] Add references for equations
Some equations were mentioned by just the number without telling the resource they were from. The book was found couple years ago but not mentioned here.
2022-10-11 08:07:47 +02:00
wmayer
138629633f Sketcher: modernize C++: replace 'typedef' with 'using' 2022-08-29 23:13:16 +02:00
berniev
53ba98d636 Mod: use empty 2022-08-06 19:30:13 +02:00
wmayer
50ef527ded Sketcher: [skip ci] Fix several clazy issues:
* Missing reference in range-for with non trivial type [-Wclazy-range-loop-reference]
* Unused QString [-Wclazy-unused-non-trivial-variable]
* Missing emit keyword on signal call [-Wclazy-incorrect-emit]
* Don't call QList::operator[]() on temporary [-Wclazy-detaching-temporary]
* Use multi-arg instead [-Wclazy-qstring-arg]
* Maybe you meant to call ViewProvider2DObjectGrid::onChanged() instead [-Wclazy-skipped-base-method]
2022-07-25 12:56:09 +02:00
wmayer
51186c018e Sketcher: modernize C++11
* use nullptr
2022-03-23 19:26:15 +01:00
Abdullah Tahiri
cc75dc2ab0 Sketcher: Fix wrong diameter reference constraint value when blocked
====================================================================

Fixes:
https://forum.freecadweb.org/viewtopic.php?p=474276#p474276
2021-02-06 06:22:30 +01:00
Abdullah Tahiri
e87c01590f GCS/Sketcher: Add equal length line constraint using the new single constraint 2021-01-23 07:53:28 +01:00
Abdullah Tahiri
567c80fb67 GCS: report partially redundant constraints 2021-01-23 07:53:28 +01:00
Abdullah Tahiri
c0e06f7f19 Sketcher/GCS: New Block constraint fixes
========================================

Previous versions relied on a heuristic that proved insufficient for cummulative use of the Block constraint.
The effect is that Block constraints stopped blocking, which is a major bug, as it lead to inadvertedly moving
geometry that was supposed to be blocked.

Fixes:
https://forum.freecadweb.org/viewtopic.php?f=13&t=53515&start=30#p461215
(Thanks Chaospilot)

Know problems with old block constraint (v0.18):
1. If driving constraints were present, they were ignored if inserted before the block constraint (to avoid
redundancy/conflicting). They resulted in

Principles of Working of the new block constraint:
1. Handling of the new block constraint is based two processes, a pre-analysis and a post-analysis. Pre-analysis
works *before* diagnosing the system in the solver. Post-analysis works *after* diagnosing the system in the solver.

2. Pre-analysis is directed to detect geometries affected *exclusively* by a block constraint. This is important
because these geometries can be pre-fixed when creating the solver geometry and constraints before GCS::diagnose()
via initSolution() AND because if no other constraint affects the geometry, the geometry parameters won't even appear
in the Jacobian of GCS, so they won't be reported as dependent parameters (for which post-analysis would be of no use).

3. Post-analysis is directed to detect Geometries affected *not only* by a block constraint. This is important
because pre-fixing these geometries would lead to redundant constraints. The post-analysis, enables to fix just the
parameters that fulfil the dependacy groups.

4. Post-analysis basically identifies which parameters shall be fixed to make geometries having blocking constraints
fixed, while not leading to redundant/conflicting constraints. These parameters must belong to blocked geometry. This
is, groups may comprise parameters belonging to blocked geometry and parameters belonging to unconstrained geometry. It
is licit that the latter remain as dependent parameters. The former are referred to as "blockable parameters". Extending
this concept, there may be unsatisfiable groups (because they do not comprise any bloackable parameter), and it is the
desired outcome NOT to satisfy such groups. It must be emphasised that there is not a single combination of fixed parameters
from the blockable parameters that satisfy all the dependency groups. However:
     1) some combinations do not satisfy all the dependency groups that must be satisfied (e.g. fixing one group containing
        two blockable parameters with a given one may result in another group, fixable only by the former, not to be satisfied).
        This leads, in a subsequent diagnosis, to satisfiable unsatisfied groups.
     2) some combinations lead to partially redundant constraints, that the solver will silently drop in a subsequent diagnosis,
        thereby reducing the rank of the system fixing less than it should.

5. The implementation rationale is as follows:
     1) The implementation is on the order of the groups provided by the QR decomposition used to reveal the parameters
        (see System::identifyDependentParameters in GCS). Zeros are made over the pilot of the full R matrix of the QR decomposition,
        which is a top triangular matrix.This, together with the permutation matrix, allow to know groups of dependent parameters
        (cols between rank and full size). Each group refers to a new parameter not affected by the rank in combination with other free
        parameters intervening in the rank (because of the triangular shape of the R matrix). This results in that each the first column
        between the rank and the full size, may only depend on a number of parameters, while the last full size colum may dependent on
        any amount of previously introduced parameters.
     2) Thus the rationale is to start from the last group (having **potentially** the larger amount of parameters) and selecting as blocking
        for that group the latest blockable parameter. Because previous groups do not have access to the last parameter, this can never
        interfere with previous groups. However, because the last parameter may not be a blockable one, there is a risk of selecting a parameter
        common with other group, albeit the probability is reduced and probably (I have not demonstrated it though and I am not sure), it
        systematically leads to the right solution in one iteration.

GCS: Change dependency group from std::set to std::vector to prevent reordering of parameters.
2020-12-30 18:59:15 +01:00
wmayer
eac4062b3f Boost: [skip ci] Fix build warnings from deprecated Boost headers (v1.75) 2020-12-29 15:34:25 +01:00
luz paz
c89e6eec13 Sketcher: Fix typos and code linting [skip ci] 2020-12-28 23:15:22 +01:00
Abdullah Tahiri
99c530bcf1 GCS: Const correctness and override qualifier
=============================================

Make several functions operate as const.
Use the override qualifier
2020-12-27 08:24:43 +01:00
Abdullah Tahiri
4d6257895d GCS: Return a zero sized reduced Jacobian if only driven constraints present
=============================================================================

The reduced Jacobian defaults to the size of the full Jacobian, where driven constraints
and parameters are not considered to build the reduced Jacobian and thus empty rows remain.

This is generally not a problem as QR decomposition ignores this rows, except in case where
only driven constraints exist. In such a case no QR decomposition is necessary, and in fact
relying on the size of the QR decomposition leads to the incorrect result that the sketch
is fully constraint, when the opposite is true.

This commit resizes an effectively empty reduced Jacobian to avoid this issue.

Fixes the problem that a line with a single reference constraint is shown as fully constraint.
2020-12-27 08:24:43 +01:00
Abdullah Tahiri
5d8172e190 GCS: Improve documentation about debug
======================================

Explicitly indicate that if parameter diagnosis must be silent=false in order to debug,
then the lauch policy during the debug must be set to deferred in order to avoid concurrent
access to Base::Console which is not thread-safe.
2020-12-24 11:59:51 +01:00
Abdullah Tahiri
13d8a16047 GCS: enable to invalidate diagnosis result 2020-12-21 05:57:42 +01:00
luz paz
590cbd85e3 Fix typos [skip ci]
Found via `codespell v2.1.dev0`  
```
codespell -q 3 -L aci,ake,aline,alle,alledges,alocation,als,ang,anid,apoints,ba,beginn,behaviour,bloaded,byteorder,calculater,cancelled,cancelling,cas,cascade,click,dum,eiter,elemente,ende,feld,finde,findf,freez,hist,iff,indicies,initialisation,initialise,initialised,initialises,initialisiert,ist,kilometre,lod,mantatory,methode,metres,millim,ot,pard,pres,programm,que,recurrance,rougly,seperator,serie,sinc,strack,substraction,te,thist,thru,tread,uint,unter,vertexes,wallthickness,whitespaces -S ./.git,*.po,*.ts,./ChangeLogpios++,./src/Base/swig*,./src/Mod/Robot/App/kdl_cp,./src/Mod/Import/App/SCL,./src/WindowsInstaller,./src/Doc/FreeCAD.uml
```
2020-12-19 16:35:16 +01:00
Abdullah Tahiri
7a76b9b7d2 GCS: Set SparseQR conditional compilation guards 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
076eebc0a9 GCS: Change asynchronous launch policy to default to avoid having to take care of exceptions on oversubscription
================================================================================================================

std:async can take two policies one that forces the task to be run in parallel another (deferred) that runs the task
when wait is called on the future (kind of lazy evaluation).

Default policy is let the system decide (an or of both policies). Nobody is a better position than the system to know
its load and whether it is possible to run the task in parallel or not.

If the system cannot allocate a thread and parallel processing is enforced (as before this commit), then it will throw an
exception. In the present case we would catch it and run the task sequencially. Thus, it makes sense to let the system
decide from the beginning and save the exception and the handling.

In tests I have only managed to see it run in parallel with the default policy.
2020-12-19 11:58:54 +01:00
Abdullah Tahiri
813afc0617 GCS: renaming parameters to make them more descriptive 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
54373798cd GCS: Augment information provided by GCS with groups of dependent parameters 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
3605770b68 GCS: Interface to query whether the used diagnose matrix is empty
=================================================================

Diagnose constraints do not include among others driven constraints. This
function allows to know whether the solver is considering an empty matrix.
2020-12-19 11:58:54 +01:00
Abdullah Tahiri
229c515b72 GCS: Deactivate Debug code and fix warnings in non-Debug mode 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
9bb917b91b GCS: Asynchronous full geometry parameter identification for Dense QR 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
718d17b634 GCS: Make QR decompositions for constraints and parameters run asynchronously 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
56705d0c3a GCS: QR profiling debug code 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
fac1ffa624 GCS: Rewrite diagnose() so that it has a single return point 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
f0dcb12475 GCS: Diagnose() - Separate DenseQR and SparseQR 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
82b4cfeba6 GCS: Refactor new SparseQR Dependent Parameter detection code and const correctness 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
0ef05d4f99 GCS: Detect dependent parameters (geometry) during diagnosis using two SparseQR factorisations 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
c565ef6793 GCS: makeSparseQRDecomposition generalise for transposed and non-transposed matrices 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
0d5e120a2c GCS: SparseQR compilation guards 2020-12-19 11:58:54 +01:00
Abdullah Tahiri
72c2830a52 GCS: reduce input parameters in makeDenseQRDecomposition 2020-12-19 11:58:54 +01:00