1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0032763: Coding Rules - eliminate CLang warning -Wbitwise-instead-of-logical in math_FunctionSetRoot.cxx

This commit is contained in:
kgv 2022-01-12 19:51:18 +03:00 committed by smoskvin
parent 9ff36dac47
commit dfa2a6719c
4 changed files with 87 additions and 135 deletions

View File

@ -52,7 +52,6 @@ math_FunctionSet.cxx
math_FunctionSet.hxx math_FunctionSet.hxx
math_FunctionSetRoot.cxx math_FunctionSetRoot.cxx
math_FunctionSetRoot.hxx math_FunctionSetRoot.hxx
math_FunctionSetRoot.lxx
math_FunctionSetWithDerivatives.hxx math_FunctionSetWithDerivatives.hxx
math_FunctionWithDerivative.cxx math_FunctionWithDerivative.cxx
math_FunctionWithDerivative.hxx math_FunctionWithDerivative.hxx

View File

@ -736,12 +736,15 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
myIsDivergent = Standard_False; myIsDivergent = Standard_False;
for (i = 1; i <= Ninc; i++) for (i = 1; i <= Ninc; i++)
{ {
myIsDivergent |= (Sol(i) < theInfBound(i)) | (theSupBound(i) < Sol(i)); myIsDivergent = myIsDivergent
|| Sol(i) < theInfBound(i)
|| Sol(i) > theSupBound(i);
} }
if (theStopOnDivergent & myIsDivergent) if (theStopOnDivergent && myIsDivergent)
{ {
return; return;
} }
// Verification de la validite des inconnues par rapport aux bornes. // Verification de la validite des inconnues par rapport aux bornes.
// Recentrage sur les bornes si pas valide. // Recentrage sur les bornes si pas valide.
for ( i = 1; i <= Ninc; i++) { for ( i = 1; i <= Ninc; i++) {
@ -811,9 +814,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
// //
for (i = 1; i <= Ninc; i++) for (i = 1; i <= Ninc; i++)
{ {
myIsDivergent |= (Sol(i) < theInfBound(i)) | (theSupBound(i) < Sol(i)); myIsDivergent = myIsDivergent
|| Sol(i) < theInfBound(i)
|| Sol(i) > theSupBound(i);
} }
if (theStopOnDivergent & myIsDivergent) if (theStopOnDivergent && myIsDivergent)
{ {
return; return;
} }
@ -877,9 +882,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
// //
for (i = 1; i <= Ninc; i++) for (i = 1; i <= Ninc; i++)
{ {
myIsDivergent |= (Sol(i) < theInfBound(i)) | (theSupBound(i) < Sol(i)); myIsDivergent = myIsDivergent
|| Sol(i) < theInfBound(i)
|| Sol(i) > theSupBound(i);
} }
if (theStopOnDivergent & myIsDivergent) if (theStopOnDivergent && myIsDivergent)
{ {
return; return;
} }
@ -915,9 +922,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
// //
for (i = 1; i <= Ninc; i++) for (i = 1; i <= Ninc; i++)
{ {
myIsDivergent |= (Sol(i) < theInfBound(i)) | (theSupBound(i) < Sol(i)); myIsDivergent = myIsDivergent
|| Sol(i) < theInfBound(i)
|| Sol(i) > theSupBound(i);
} }
if (theStopOnDivergent & myIsDivergent) if (theStopOnDivergent && myIsDivergent)
{ {
return; return;
} }
@ -997,9 +1006,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
// //
for (i = 1; i <= Ninc; i++) for (i = 1; i <= Ninc; i++)
{ {
myIsDivergent |= (Sol(i) < theInfBound(i)) | (theSupBound(i) < Sol(i)); myIsDivergent = myIsDivergent
|| Sol(i) < theInfBound(i)
|| Sol(i) > theSupBound(i);
} }
if (theStopOnDivergent & myIsDivergent) if (theStopOnDivergent && myIsDivergent)
{ {
return; return;
} }
@ -1040,9 +1051,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
// //
for (i = 1; i <= Ninc; i++) for (i = 1; i <= Ninc; i++)
{ {
myIsDivergent |= (Sol(i) < theInfBound(i)) | (theSupBound(i) < Sol(i)); myIsDivergent = myIsDivergent
|| Sol(i) < theInfBound(i)
|| Sol(i) > theSupBound(i);
} }
if (theStopOnDivergent & myIsDivergent) if (theStopOnDivergent && myIsDivergent)
{ {
return; return;
} }
@ -1083,9 +1096,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
// //
for (i = 1; i <= Ninc; i++) for (i = 1; i <= Ninc; i++)
{ {
myIsDivergent |= (Sol(i) < theInfBound(i)) | (theSupBound(i) < Sol(i)); myIsDivergent = myIsDivergent
|| Sol(i) < theInfBound(i)
|| Sol(i) > theSupBound(i);
} }
if (theStopOnDivergent & myIsDivergent) if (theStopOnDivergent && myIsDivergent)
{ {
return; return;
} }

View File

@ -17,18 +17,14 @@
#ifndef _math_FunctionSetRoot_HeaderFile #ifndef _math_FunctionSetRoot_HeaderFile
#define _math_FunctionSetRoot_HeaderFile #define _math_FunctionSetRoot_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Boolean.hxx>
#include <math_Vector.hxx>
#include <math_Matrix.hxx>
#include <Standard_Integer.hxx>
#include <math_IntegerVector.hxx> #include <math_IntegerVector.hxx>
#include <math_Matrix.hxx>
#include <math_Vector.hxx>
#include <Standard_OStream.hxx> #include <Standard_OStream.hxx>
class math_FunctionSetWithDerivatives; #include <Standard_DimensionError.hxx>
#include <StdFail_NotDone.hxx>
class math_FunctionSetWithDerivatives;
//! The math_FunctionSetRoot class calculates the root //! The math_FunctionSetRoot class calculates the root
//! of a set of N functions of M variables (N<M, N=M or N>M). Knowing //! of a set of N functions of M variables (N<M, N=M or N>M). Knowing
@ -43,7 +39,6 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! is used in a sub-class to initialize correctly all the fields //! is used in a sub-class to initialize correctly all the fields
//! of this class. //! of this class.
//! The range (1, F.NbVariables()) must be especially //! The range (1, F.NbVariables()) must be especially
@ -69,8 +64,17 @@ public:
//! in a sub-class to implement a specific test to stop the iterations. //! in a sub-class to implement a specific test to stop the iterations.
//! In this case, the solution is found when: abs(Xi - Xi-1) <= Tolerance //! In this case, the solution is found when: abs(Xi - Xi-1) <= Tolerance
//! for all unknowns. //! for all unknowns.
virtual Standard_Boolean IsSolutionReached (math_FunctionSetWithDerivatives& F); virtual Standard_Boolean IsSolutionReached (math_FunctionSetWithDerivatives& )
{
for (Standard_Integer i = 1; i <= Sol.Length(); ++i)
{
if (Abs (Delta(i)) > Tol(i))
{
return Standard_False;
}
}
return Standard_True;
}
//! Improves the root of function from the initial guess point. //! Improves the root of function from the initial guess point.
//! The infinum and supremum may be given to constrain the solution. //! The infinum and supremum may be given to constrain the solution.
@ -78,29 +82,39 @@ public:
//! for all unknowns. //! for all unknowns.
Standard_EXPORT void Perform (math_FunctionSetWithDerivatives& theFunction, const math_Vector& theStartingPoint, const Standard_Boolean theStopOnDivergent = Standard_False); Standard_EXPORT void Perform (math_FunctionSetWithDerivatives& theFunction, const math_Vector& theStartingPoint, const Standard_Boolean theStopOnDivergent = Standard_False);
//! Improves the root of function from the initial guess point. //! Improves the root of function from the initial guess point.
//! The infinum and supremum may be given to constrain the solution. //! The infinum and supremum may be given to constrain the solution.
//! In this case, the solution is found when: abs(Xi - Xi-1) <= Tolerance //! In this case, the solution is found when: abs(Xi - Xi-1) <= Tolerance
//! for all unknowns. //! for all unknowns.
Standard_EXPORT void Perform (math_FunctionSetWithDerivatives& theFunction, const math_Vector& theStartingPoint, const math_Vector& theInfBound, const math_Vector& theSupBound, const Standard_Boolean theStopOnDivergent = Standard_False); Standard_EXPORT void Perform (math_FunctionSetWithDerivatives& theFunction, const math_Vector& theStartingPoint, const math_Vector& theInfBound, const math_Vector& theSupBound, const Standard_Boolean theStopOnDivergent = Standard_False);
//! Returns true if the computations are successful, otherwise returns false. //! Returns true if the computations are successful, otherwise returns false.
Standard_Boolean IsDone() const; Standard_Boolean IsDone() const { return Done; }
//! Returns the number of iterations really done //! Returns the number of iterations really done
//! during the computation of the root. //! during the computation of the root.
//! Exception NotDone is raised if the root was not found. //! Exception NotDone is raised if the root was not found.
Standard_Integer NbIterations() const; Standard_Integer NbIterations() const
{
StdFail_NotDone_Raise_if(!Done, " ");
return Kount;
}
//! returns the stateNumber (as returned by //! returns the stateNumber (as returned by
//! F.GetStateNumber()) associated to the root found. //! F.GetStateNumber()) associated to the root found.
Standard_Integer StateNumber() const; Standard_Integer StateNumber() const
{
StdFail_NotDone_Raise_if(!Done, " ");
return State;
}
//! Returns the value of the root of function F. //! Returns the value of the root of function F.
//! Exception NotDone is raised if the root was not found. //! Exception NotDone is raised if the root was not found.
const math_Vector& Root() const; const math_Vector& Root() const
{
StdFail_NotDone_Raise_if(!Done, " ");
return Sol;
}
//! Outputs the root vector in Root. //! Outputs the root vector in Root.
//! Exception NotDone is raised if the root was not found. //! Exception NotDone is raised if the root was not found.
@ -110,19 +124,32 @@ public:
//! Returns the matrix value of the derivative at the root. //! Returns the matrix value of the derivative at the root.
//! Exception NotDone is raised if the root was not found. //! Exception NotDone is raised if the root was not found.
const math_Matrix& Derivative() const; const math_Matrix& Derivative() const
{
StdFail_NotDone_Raise_if(!Done, " ");
return DF;
}
//! outputs the matrix value of the derivative //! outputs the matrix value of the derivative
//! at the root in Der. //! at the root in Der.
//! Exception NotDone is raised if the root was not found. //! Exception NotDone is raised if the root was not found.
//! Exception DimensionError is raised if the column range //! Exception DimensionError is raised if the column range
//! of <Der> is not equal to the range of the startingPoint. //! of <Der> is not equal to the range of the startingPoint.
void Derivative (math_Matrix& Der) const; void Derivative (math_Matrix& Der) const
{
StdFail_NotDone_Raise_if(!Done, " ");
Standard_DimensionError_Raise_if(Der.ColNumber() != Sol.Length(), " ");
Der = DF;
}
//! returns the vector value of the error done //! returns the vector value of the error done
//! on the functions at the root. //! on the functions at the root.
//! Exception NotDone is raised if the root was not found. //! Exception NotDone is raised if the root was not found.
const math_Vector& FunctionSetErrors() const; const math_Vector& FunctionSetErrors() const
{
StdFail_NotDone_Raise_if(!Done, " ");
return Delta;
}
//! outputs the vector value of the error done //! outputs the vector value of the error done
//! on the functions at the root in Err. //! on the functions at the root in Err.
@ -136,25 +163,17 @@ public:
//! Is used to redefine the operator <<. //! Is used to redefine the operator <<.
Standard_EXPORT void Dump (Standard_OStream& o) const; Standard_EXPORT void Dump (Standard_OStream& o) const;
Standard_Boolean IsDivergent() const; Standard_Boolean IsDivergent() const { return myIsDivergent; }
protected: protected:
math_Vector Delta; math_Vector Delta;
math_Vector Sol; math_Vector Sol;
math_Matrix DF; math_Matrix DF;
math_Vector Tol; math_Vector Tol;
private: private:
Standard_Boolean Done; Standard_Boolean Done;
Standard_Integer Kount; Standard_Integer Kount;
Standard_Integer State; Standard_Integer State;
@ -175,14 +194,13 @@ private:
math_Vector Temp4; math_Vector Temp4;
Standard_Boolean myIsDivergent; Standard_Boolean myIsDivergent;
}; };
inline Standard_OStream& operator<< (Standard_OStream& theStream,
#include <math_FunctionSetRoot.lxx> const math_FunctionSetRoot& theF)
{
theF.Dump (theStream);
return theStream;
}
#endif // _math_FunctionSetRoot_HeaderFile #endif // _math_FunctionSetRoot_HeaderFile

View File

@ -1,80 +0,0 @@
// Copyright (c) 1997-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdFail_NotDone.hxx>
#include <Standard_DimensionError.hxx>
inline Standard_Boolean math_FunctionSetRoot::IsSolutionReached(math_FunctionSetWithDerivatives&)
{
for (Standard_Integer i = 1; i <= Sol.Length(); ++i)
if ( Abs(Delta(i)) > Tol(i) )
return Standard_False;
return Standard_True;
}
inline Standard_Boolean math_FunctionSetRoot::IsDone() const
{
return Done;
}
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_FunctionSetRoot& F)
{
F.Dump(o);
return o;
}
inline const math_Vector& math_FunctionSetRoot::Root() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Sol;
}
inline const math_Vector& math_FunctionSetRoot::FunctionSetErrors() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Delta;
}
inline const math_Matrix& math_FunctionSetRoot::Derivative() const{
StdFail_NotDone_Raise_if(!Done, " ");
return DF;
}
inline void math_FunctionSetRoot::Derivative(math_Matrix& Der) const{
StdFail_NotDone_Raise_if(!Done, " ");
Standard_DimensionError_Raise_if(Der.ColNumber() != Sol.Length(), " ");
Der = DF;
}
inline Standard_Integer math_FunctionSetRoot::StateNumber() const{
StdFail_NotDone_Raise_if(!Done, " ");
return State;
}
inline Standard_Integer math_FunctionSetRoot::NbIterations() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Kount;
}
inline Standard_Boolean math_FunctionSetRoot::IsDivergent() const
{
return myIsDivergent;
}