Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:20:53

0001 // Copyright (c) 2025 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _MathSys_NewtonTypes_HeaderFile
0015 #define _MathSys_NewtonTypes_HeaderFile
0016 
0017 #include <MathUtils_Config.hxx>
0018 #include <MathUtils_Types.hxx>
0019 
0020 #include <array>
0021 #include <cstddef>
0022 
0023 //! Shared types for specialized small-dimension Newton solvers.
0024 namespace MathSys
0025 {
0026 using namespace MathUtils;
0027 
0028 //! Result of N-dimensional Newton solver.
0029 template <int N>
0030 struct NewtonResultN
0031 {
0032   MathUtils::Status     Status       = MathUtils::Status::NotConverged; //!< Final solver status
0033   std::array<double, N> X            = {};                              //!< Solution estimate
0034   size_t                NbIterations = 0;                               //!< Performed iterations
0035   double                ResidualNorm = 0.0; //!< Final residual norm ||F||
0036   double                StepNorm     = 0.0; //!< Final step norm ||dX||
0037 
0038   //! Returns true if computation converged.
0039   bool IsDone() const { return Status == MathUtils::Status::OK; }
0040 
0041   //! Conversion to bool for convenient checking.
0042   explicit operator bool() const { return IsDone(); }
0043 };
0044 
0045 //! Box bounds for N-dimensional solver.
0046 template <int N>
0047 struct NewtonBoundsN
0048 {
0049   std::array<double, N> Min       = {};   //!< Lower bounds
0050   std::array<double, N> Max       = {};   //!< Upper bounds
0051   bool                  HasBounds = true; //!< True to apply bounds
0052 };
0053 
0054 //! Solver options for small-dimension Newton methods.
0055 struct NewtonOptions : MathUtils::Config
0056 {
0057   double MaxStepRatio        = 0.5;    //!< Max step as ratio of largest domain size
0058   bool   EnableLineSearch    = true;   //!< Enable Armijo backtracking line search
0059   bool   AllowSoftBounds     = false;  //!< Allow slight bounds extension
0060   double SoftBoundsExtension = 1.0e-4; //!< Extension ratio for soft bounds
0061 
0062   //! Default constructor with strict residual/step tolerances for specialized Newton.
0063   NewtonOptions()
0064   {
0065     Tolerance     = 1.0e-10;
0066     XTolerance    = 1.0e-16;
0067     FTolerance    = 1.0e-10;
0068     MaxIterations = 100;
0069   }
0070 };
0071 
0072 } // namespace MathSys
0073 
0074 #endif // _MathSys_NewtonTypes_HeaderFile