From dfa2a6719ca7dfea6a97743f87d47ba472de8a11 Mon Sep 17 00:00:00 2001 From: kgv Date: Wed, 12 Jan 2022 19:51:18 +0300 Subject: [PATCH] 0032763: Coding Rules - eliminate CLang warning -Wbitwise-instead-of-logical in math_FunctionSetRoot.cxx --- src/math/FILES | 1 - src/math/math_FunctionSetRoot.cxx | 43 +++++++++----- src/math/math_FunctionSetRoot.hxx | 98 ++++++++++++++++++------------- src/math/math_FunctionSetRoot.lxx | 80 ------------------------- 4 files changed, 87 insertions(+), 135 deletions(-) delete mode 100644 src/math/math_FunctionSetRoot.lxx diff --git a/src/math/FILES b/src/math/FILES index 8c392c612a..c371253135 100755 --- a/src/math/FILES +++ b/src/math/FILES @@ -52,7 +52,6 @@ math_FunctionSet.cxx math_FunctionSet.hxx math_FunctionSetRoot.cxx math_FunctionSetRoot.hxx -math_FunctionSetRoot.lxx math_FunctionSetWithDerivatives.hxx math_FunctionWithDerivative.cxx math_FunctionWithDerivative.hxx diff --git a/src/math/math_FunctionSetRoot.cxx b/src/math/math_FunctionSetRoot.cxx index 3cb7d8aa6b..51801a4313 100644 --- a/src/math/math_FunctionSetRoot.cxx +++ b/src/math/math_FunctionSetRoot.cxx @@ -736,12 +736,15 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F, myIsDivergent = Standard_False; 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; } + // Verification de la validite des inconnues par rapport aux bornes. // Recentrage sur les bornes si pas valide. for ( i = 1; i <= Ninc; i++) { @@ -811,9 +814,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F, // 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; } @@ -877,9 +882,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F, // 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; } @@ -915,9 +922,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F, // 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; } @@ -997,9 +1006,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F, // 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; } @@ -1040,9 +1051,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F, // 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; } @@ -1083,9 +1096,11 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F, // 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; } diff --git a/src/math/math_FunctionSetRoot.hxx b/src/math/math_FunctionSetRoot.hxx index 60995f12a5..9a66a7e044 100644 --- a/src/math/math_FunctionSetRoot.hxx +++ b/src/math/math_FunctionSetRoot.hxx @@ -17,18 +17,14 @@ #ifndef _math_FunctionSetRoot_HeaderFile #define _math_FunctionSetRoot_HeaderFile -#include -#include -#include - -#include -#include -#include -#include #include +#include +#include #include -class math_FunctionSetWithDerivatives; +#include +#include +class math_FunctionSetWithDerivatives; //! The math_FunctionSetRoot class calculates the root //! of a set of N functions of M variables (NM). Knowing @@ -43,7 +39,6 @@ public: DEFINE_STANDARD_ALLOC - //! is used in a sub-class to initialize correctly all the fields //! of this class. //! The range (1, F.NbVariables()) must be especially @@ -69,39 +64,58 @@ public: //! 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 //! 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. //! The infinum and supremum may be given to constrain the solution. //! In this case, the solution is found when: abs(Xi - Xi-1)(j) <= Tolerance(j) //! for all unknowns. 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. //! The infinum and supremum may be given to constrain the solution. //! In this case, the solution is found when: abs(Xi - Xi-1) <= Tolerance //! 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); - //! 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 //! during the computation of the root. //! 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 //! 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. //! 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. //! Exception NotDone is raised if the root was not found. //! Exception DimensionError is raised if the range of Root @@ -110,19 +124,32 @@ public: //! Returns the matrix value of the derivative at the root. //! 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 //! at the root in Der. //! Exception NotDone is raised if the root was not found. //! Exception DimensionError is raised if the column range //! of 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 //! on the functions at the root. //! 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 //! on the functions at the root in Err. @@ -135,26 +162,18 @@ public: //! of the object. //! Is used to redefine the operator <<. Standard_EXPORT void Dump (Standard_OStream& o) const; - - Standard_Boolean IsDivergent() const; - - + Standard_Boolean IsDivergent() const { return myIsDivergent; } protected: - - math_Vector Delta; math_Vector Sol; math_Matrix DF; math_Vector Tol; - private: - - Standard_Boolean Done; Standard_Integer Kount; Standard_Integer State; @@ -175,14 +194,13 @@ private: math_Vector Temp4; Standard_Boolean myIsDivergent; - }; - -#include - - - - +inline Standard_OStream& operator<< (Standard_OStream& theStream, + const math_FunctionSetRoot& theF) +{ + theF.Dump (theStream); + return theStream; +} #endif // _math_FunctionSetRoot_HeaderFile diff --git a/src/math/math_FunctionSetRoot.lxx b/src/math/math_FunctionSetRoot.lxx deleted file mode 100644 index 24b1bad422..0000000000 --- a/src/math/math_FunctionSetRoot.lxx +++ /dev/null @@ -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 -#include - -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; -}