|
||||
File indexing completed on 2025-01-18 10:04:14
0001 // Created on: 1991-05-14 0002 // Created by: Laurent PAINNOT 0003 // Copyright (c) 1991-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _math_NewtonFunctionSetRoot_HeaderFile 0018 #define _math_NewtonFunctionSetRoot_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 0023 #include <Standard_Integer.hxx> 0024 #include <math_Vector.hxx> 0025 #include <math_IntegerVector.hxx> 0026 #include <math_Matrix.hxx> 0027 #include <Standard_OStream.hxx> 0028 class math_FunctionSetWithDerivatives; 0029 0030 0031 0032 //! This class computes the root of a set of N functions of N variables, 0033 //! knowing an initial guess at the solution and using the 0034 //! Newton Raphson algorithm. Knowledge of all the partial 0035 //! derivatives (Jacobian) is required. 0036 class math_NewtonFunctionSetRoot 0037 { 0038 public: 0039 0040 DEFINE_STANDARD_ALLOC 0041 0042 0043 0044 //! Initialize correctly all the fields of this class. 0045 //! The range (1, F.NbVariables()) must be especially respected for 0046 //! all vectors and matrix declarations. 0047 Standard_EXPORT math_NewtonFunctionSetRoot(math_FunctionSetWithDerivatives& theFunction, const math_Vector& theXTolerance, const Standard_Real theFTolerance, const Standard_Integer tehNbIterations = 100); 0048 0049 0050 //! This constructor should be used in a sub-class to initialize 0051 //! correctly all the fields of this class. 0052 //! The range (1, F.NbVariables()) must be especially respected for 0053 //! all vectors and matrix declarations. 0054 //! The method SetTolerance must be called before performing the algorithm. 0055 Standard_EXPORT math_NewtonFunctionSetRoot(math_FunctionSetWithDerivatives& theFunction, const Standard_Real theFTolerance, const Standard_Integer theNbIterations = 100); 0056 0057 //! Destructor 0058 Standard_EXPORT virtual ~math_NewtonFunctionSetRoot(); 0059 0060 //! Initializes the tolerance values for the unknowns. 0061 Standard_EXPORT void SetTolerance (const math_Vector& XTol); 0062 0063 0064 //! The Newton method is done to improve the root of the function 0065 //! from the initial guess point. The solution is found when: 0066 //! abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i; 0067 Standard_EXPORT void Perform (math_FunctionSetWithDerivatives& theFunction, const math_Vector& theStartingPoint); 0068 0069 0070 //! The Newton method is done to improve the root of the function 0071 //! from the initial guess point. Bounds may be given, to constrain the solution. 0072 //! The solution is found when: 0073 //! abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i; 0074 Standard_EXPORT void Perform (math_FunctionSetWithDerivatives& theFunction, const math_Vector& theStartingPoint, const math_Vector& theInfBound, const math_Vector& theSupBound); 0075 0076 0077 //! This method is called at the end of each iteration to check if the 0078 //! solution is found. 0079 //! Vectors DeltaX, Fvalues and Jacobian Matrix are consistent with the 0080 //! possible solution Vector Sol and can be inspected to decide whether 0081 //! the solution is reached or not. 0082 virtual Standard_Boolean IsSolutionReached (math_FunctionSetWithDerivatives& F); 0083 0084 //! Returns true if the computations are successful, otherwise returns false. 0085 Standard_Boolean IsDone() const; 0086 0087 //! Returns the value of the root of function F. 0088 //! Exceptions 0089 //! StdFail_NotDone if the algorithm fails (and IsDone returns false). 0090 const math_Vector& Root() const; 0091 0092 //! outputs the root vector in Root. 0093 //! Exception NotDone is raised if the root was not found. 0094 //! Exception DimensionError is raised if the range of Root is 0095 //! not equal to the range of the StartingPoint. 0096 void Root (math_Vector& Root) const; 0097 0098 //! Outputs the state number associated with the solution 0099 //! vector root. 0100 Standard_Integer StateNumber() const; 0101 0102 //! Returns the matrix value of the derivative at the root. 0103 //! Exception NotDone is raised if the root was not found. 0104 const math_Matrix& Derivative() const; 0105 0106 //! Outputs the matrix value of the derivative at the root in 0107 //! Der. 0108 //! Exception NotDone is raised if the root was not found. 0109 //! Exception DimensionError is raised if the range of Der is 0110 //! not equal to the range of the StartingPoint. 0111 void Derivative (math_Matrix& Der) const; 0112 0113 //! Returns the vector value of the error done on the 0114 //! functions at the root. 0115 //! Exception NotDone is raised if the root was not found. 0116 const math_Vector& FunctionSetErrors() const; 0117 0118 //! Outputs the vector value of the error done on the 0119 //! functions at the root in Err. 0120 //! Exception NotDone is raised if the root was not found. 0121 //! Exception DimensionError is raised if the range of Err is 0122 //! not equal to the range of the StartingPoint. 0123 void FunctionSetErrors (math_Vector& Err) const; 0124 0125 //! Returns the number of iterations really done 0126 //! during the computation of the Root. 0127 //! Exception NotDone is raised if the root was not found. 0128 Standard_Integer NbIterations() const; 0129 0130 //! Prints information on the current state of the object. 0131 //! Is used to redefine the operator <<. 0132 Standard_EXPORT void Dump (Standard_OStream& o) const; 0133 0134 0135 0136 0137 protected: 0138 0139 0140 0141 math_Vector TolX; 0142 Standard_Real TolF; 0143 math_IntegerVector Indx; 0144 math_Vector Scratch; 0145 math_Vector Sol; 0146 math_Vector DeltaX; 0147 math_Vector FValues; 0148 math_Matrix Jacobian; 0149 0150 0151 private: 0152 0153 0154 0155 Standard_Boolean Done; 0156 Standard_Integer State; 0157 Standard_Integer Iter; 0158 Standard_Integer Itermax; 0159 0160 0161 }; 0162 0163 0164 #include <math_NewtonFunctionSetRoot.lxx> 0165 0166 0167 0168 0169 0170 #endif // _math_NewtonFunctionSetRoot_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |