Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:11:18

0001 // @(#)root/mathmore:$Id$
0002 // Authors: L. Moneta, A. Zsenei   08/2005
0003 
0004  /**********************************************************************
0005   *                                                                    *
0006   * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
0007   *                                                                    *
0008   * This library is free software; you can redistribute it and/or      *
0009   * modify it under the terms of the GNU General Public License        *
0010   * as published by the Free Software Foundation; either version 2     *
0011   * of the License, or (at your option) any later version.             *
0012   *                                                                    *
0013   * This library is distributed in the hope that it will be useful,    *
0014   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
0015   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
0016   * General Public License for more details.                           *
0017   *                                                                    *
0018   * You should have received a copy of the GNU General Public License  *
0019   * along with this library (see file COPYING); if not, write          *
0020   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
0021   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
0022   *                                                                    *
0023   **********************************************************************/
0024 
0025 // Header file for class GSLRootFinderDeriv
0026 //
0027 // Created by: moneta  at Sun Nov 21 16:26:03 2004
0028 //
0029 // Last update: Sun Nov 21 16:26:03 2004
0030 //
0031 #ifndef ROOT_Math_GSL_RootFinderDeriv
0032 #define ROOT_Math_GSL_RootFinderDeriv
0033 
0034 
0035 #include "Math/GSLFunctionAdapter.h"
0036 
0037 #include "Math/IFunctionfwd.h"
0038 #include "Math/IFunction.h"
0039 
0040 #include "Math/IRootFinderMethod.h"
0041 
0042 #include <iostream>
0043 
0044 namespace ROOT {
0045 namespace Math {
0046 
0047 
0048    class GSLRootFdFSolver;
0049    class GSLFunctionDerivWrapper;
0050 
0051 
0052 //_____________________________________________________________________________________
0053    /**
0054       Base class for GSL Root-Finding algorithms for one dimensional functions which use function derivatives.
0055       For finding the roots users should not use this class directly but instantiate the derived classes,
0056       for example  ROOT::Math::Roots::Newton for using the Newton algorithm.
0057       All the classes defining the alhorithms are defined in the header Math/RootFinderAlgorithm.h
0058       They possible types implementing root bracketing algorithms which use function
0059       derivatives are:
0060       <ul>
0061          <li>ROOT::Math::Roots::Newton
0062          <li>ROOT::Math::Roots::Secant
0063          <li>ROOT::Math::Roots::Steffenson
0064      </ul>
0065 
0066       See also those classes  for the documentation.
0067       See the GSL <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Root-Finding-Algorithms-using-Derivatives.html"> online manual</A> for
0068       information on the GSL Root-Finding algorithms
0069 
0070       @ingroup RootFinders
0071    */
0072 
0073 
0074 class GSLRootFinderDeriv: public IRootFinderMethod {
0075 
0076 public:
0077    GSLRootFinderDeriv();
0078    ~GSLRootFinderDeriv() override;
0079 
0080    // usually copying is non trivial, so we delete this
0081    GSLRootFinderDeriv(const GSLRootFinderDeriv &) = delete;
0082    GSLRootFinderDeriv &operator=(const GSLRootFinderDeriv &) = delete;
0083    GSLRootFinderDeriv(GSLRootFinderDeriv &&) = delete;
0084    GSLRootFinderDeriv &operator=(GSLRootFinderDeriv &&) = delete;
0085 
0086 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
0087    bool SetFunction( const IGenFunction & , double , double ) override {
0088       std::cerr <<"GSLRootFinderDeriv - Error : Algorithm requirs derivatives" << std::endl;
0089       return false;
0090    }
0091 #endif
0092 
0093    bool SetFunction( const IGradFunction & f, double xstart) override {
0094       const void * p = &f;
0095       return SetFunction(  &GSLFunctionAdapter<IGradFunction>::F, &GSLFunctionAdapter<IGradFunction>::Df, &GSLFunctionAdapter<IGradFunction>::Fdf, const_cast<void *>(p), xstart );
0096    }
0097 
0098 
0099    typedef double ( * GSLFuncPointer ) ( double, void *);
0100    typedef void ( * GSLFdFPointer ) ( double, void *, double *, double *);
0101    bool SetFunction( GSLFuncPointer f, GSLFuncPointer df, GSLFdFPointer fdf, void * p, double Root );
0102 
0103    using IRootFinderMethod::SetFunction;
0104 
0105    /// iterate (return GSL_SUCCESS in case of successful iteration)
0106    int Iterate() override;
0107 
0108    double Root() const override;
0109 
0110    /// Find the root (return false if failed)
0111    bool Solve( int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10) override;
0112 
0113    /// Return number of iterations
0114    int Iterations() const override {
0115       return fIter;
0116    }
0117 
0118    /// Return the status of last root finding
0119    int Status() const override { return fStatus; }
0120 
0121    const char * Name() const override;
0122 
0123 protected:
0124 
0125    void SetSolver (  GSLRootFdFSolver * s );
0126 
0127    void FreeSolver();
0128 
0129 private:
0130 
0131    GSLFunctionDerivWrapper * fFunction;
0132    GSLRootFdFSolver * fS;
0133 
0134    mutable double fRoot;
0135    mutable double fPrevRoot;
0136    int fIter;
0137    int fStatus;
0138    bool fValidPoint;
0139 
0140 };
0141 
0142 } // namespace Math
0143 } // namespace ROOT
0144 
0145 
0146 #endif /* ROOT_Math_GSL_RootFinderDeriv */