mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-18 14:27:39 +03:00
0025720: Incorrect code of math classes can lead to unpredicted behavior of algorithms
The calling of virtual methods has been removed from constructors & destructors: math_BissecNewton math_BrentMinimum math_FRPR math_FunctionSetRoot math_NewtonFunctionSetRoot math_NewtonMinimum math_Powell
This commit is contained in:
@@ -23,50 +23,30 @@ uses
|
||||
MultipleVarFunctionWithHessian from math
|
||||
|
||||
is
|
||||
Create(F: in out MultipleVarFunctionWithHessian;
|
||||
StartingPoint: Vector;
|
||||
SpatialTolerance : Real = 1.0e-7;
|
||||
CriteriumTolerance: Real = 1.0e-2;
|
||||
NbIterations: Integer=40;
|
||||
Convexity: Real=1.0e-6;
|
||||
WithSingularity : Boolean = Standard_True)
|
||||
---Purpose: -- Given the starting point StartingPoint,
|
||||
-- The tolerance required on the solution is given by
|
||||
-- Tolerance.
|
||||
-- Iteration are stopped if
|
||||
-- (!WithSingularity) and H(F(Xi)) is not definite
|
||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
||||
-- or IsConverged() returns True for 2 successives Iterations.
|
||||
-- Warning: Obsolete Constructor (because IsConverged can not be redefined
|
||||
-- with this. )
|
||||
returns Newton;
|
||||
|
||||
Create(F: in out MultipleVarFunctionWithHessian;
|
||||
SpatialTolerance : Real = 1.0e-7;
|
||||
Tolerance: Real=1.0e-7;
|
||||
NbIterations: Integer=40;
|
||||
Convexity: Real=1.0e-6;
|
||||
WithSingularity : Boolean = Standard_True)
|
||||
Create(theFunction: in MultipleVarFunctionWithHessian;
|
||||
theSpatialTolerance: Real = 1.0e-7;
|
||||
theCriteriumTolerance: Real=1.0e-7;
|
||||
theNbIterations: Integer=40;
|
||||
theConvexity: Real=1.0e-6;
|
||||
theWithSingularity: Boolean = Standard_True)
|
||||
---Purpose:
|
||||
-- The tolerance required on the solution is given by
|
||||
-- Tolerance.
|
||||
-- Iteration are stopped if
|
||||
-- (!WithSingularity) and H(F(Xi)) is not definite
|
||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
||||
-- or IsConverged() returns True for 2 successives Iterations.
|
||||
-- Warning: This constructor do not computation
|
||||
-- The tolerance required on the solution is given by Tolerance.
|
||||
-- Iteration are stopped if (!WithSingularity) and H(F(Xi)) is not definite
|
||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
||||
-- or IsConverged() returns True for 2 successives Iterations.
|
||||
-- Warning: This constructor do not computation
|
||||
returns Newton;
|
||||
|
||||
IsConverged(me)
|
||||
---Purpose: This method is called at the end of each
|
||||
-- iteration to check the convergence :
|
||||
-- || Xi+1 - Xi || < SpatialTolerance/100 Or
|
||||
-- || Xi+1 - Xi || < SpatialTolerance and
|
||||
-- |F(Xi+1) - F(Xi)| < CriteriumTolerance * |F(xi)|
|
||||
-- It can be redefined in a sub-class to implement a specific test.
|
||||
|
||||
returns Boolean
|
||||
is redefined;
|
||||
---Purpose:
|
||||
-- This method is called at the end of each
|
||||
-- iteration to check the convergence :
|
||||
-- || Xi+1 - Xi || < SpatialTolerance/100 Or
|
||||
-- || Xi+1 - Xi || < SpatialTolerance and
|
||||
-- |F(Xi+1) - F(Xi)| < CriteriumTolerance * |F(xi)|
|
||||
-- It can be redefined in a sub-class to implement a specific test.
|
||||
|
||||
returns Boolean is redefined;
|
||||
|
||||
fields
|
||||
mySpTol : Real;
|
||||
|
@@ -16,44 +16,37 @@
|
||||
|
||||
#include <FairCurve_Newton.ixx>
|
||||
|
||||
FairCurve_Newton::FairCurve_Newton(math_MultipleVarFunctionWithHessian& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const Standard_Real SpatialTolerance,
|
||||
const Standard_Real CriteriumTolerance,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real Convexity,
|
||||
const Standard_Boolean WithSingularity)
|
||||
:math_NewtonMinimum(F, StartingPoint, CriteriumTolerance,
|
||||
NbIterations, Convexity, WithSingularity),
|
||||
mySpTol(SpatialTolerance)
|
||||
|
||||
//=======================================================================
|
||||
//function : FairCurve_Newton
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
FairCurve_Newton::FairCurve_Newton(
|
||||
const math_MultipleVarFunctionWithHessian& theFunction,
|
||||
const Standard_Real theSpatialTolerance,
|
||||
const Standard_Real theCriteriumTolerance,
|
||||
const Standard_Integer theNbIterations,
|
||||
const Standard_Real theConvexity,
|
||||
const Standard_Boolean theWithSingularity
|
||||
)
|
||||
: math_NewtonMinimum(theFunction,
|
||||
theCriteriumTolerance,
|
||||
theNbIterations,
|
||||
theConvexity,
|
||||
theWithSingularity),
|
||||
mySpTol(theSpatialTolerance)
|
||||
{
|
||||
// Attention this writing is wrong as FairCurve_Newton::IsConverged() is not
|
||||
// used in the constructor of NewtonMinimum !!
|
||||
}
|
||||
|
||||
FairCurve_Newton::FairCurve_Newton(math_MultipleVarFunctionWithHessian& F,
|
||||
const Standard_Real SpatialTolerance,
|
||||
const Standard_Real CriteriumTolerance,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real Convexity,
|
||||
const Standard_Boolean WithSingularity)
|
||||
:math_NewtonMinimum(F, CriteriumTolerance,
|
||||
NbIterations, Convexity, WithSingularity),
|
||||
mySpTol(SpatialTolerance)
|
||||
|
||||
{
|
||||
// It is much better
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsConverged
|
||||
//purpose : Convert if the steps are too small or if the criterion
|
||||
// progresses little with a reasonable step, this last
|
||||
// requirement allows detecting infinite slidings
|
||||
// (case when the criterion varies troo slowly).
|
||||
//=======================================================================
|
||||
Standard_Boolean FairCurve_Newton::IsConverged() const
|
||||
// Convert if the steps are too small
|
||||
// or if the criterion progresses little with a reasonable step, this last requirement
|
||||
// allows detecting infinite slidings,
|
||||
// (case when the criterion varies troo slowly).
|
||||
{
|
||||
Standard_Real N = TheStep.Norm();
|
||||
return ( (N <= mySpTol/100 ) ||
|
||||
( Abs(TheMinimum-PreviousMinimum) <= XTol*Abs(PreviousMinimum)
|
||||
&& N<=mySpTol) );
|
||||
const Standard_Real N = TheStep.Norm();
|
||||
return ( N <= 0.01 * mySpTol ) || ( N <= mySpTol &&
|
||||
Abs(TheMinimum - PreviousMinimum) <= XTol * Abs(PreviousMinimum));
|
||||
}
|
||||
|
Reference in New Issue
Block a user