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++) {
//
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;
}
//
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;
}
//
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;
}
//
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;
}
//
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;
}
//
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;
}
#ifndef _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_Matrix.hxx>
+#include <math_Vector.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
//! of a set of N functions of M variables (N<M, N=M or N>M). Knowing
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
//! 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
//! 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 <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
//! 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.
//! 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;
math_Vector Temp4;
Standard_Boolean myIsDivergent;
-
};
-
-#include <math_FunctionSetRoot.lxx>
-
-
-
-
+inline Standard_OStream& operator<< (Standard_OStream& theStream,
+ const math_FunctionSetRoot& theF)
+{
+ theF.Dump (theStream);
+ return theStream;
+}
#endif // _math_FunctionSetRoot_HeaderFile
+++ /dev/null
-// 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;
-}