Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:17

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 private:
0081    // usually copying is non trivial, so we make this unaccessible
0082    GSLRootFinderDeriv(const GSLRootFinderDeriv &);
0083    GSLRootFinderDeriv & operator = (const GSLRootFinderDeriv &);
0084 
0085 public:
0086 
0087 
0088 
0089 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
0090    bool SetFunction( const IGenFunction & , double , double ) override {
0091       std::cerr <<"GSLRootFinderDeriv - Error : Algorithm requirs derivatives" << std::endl;
0092       return false;
0093    }
0094 #endif
0095 
0096    bool SetFunction( const IGradFunction & f, double xstart) override {
0097       const void * p = &f;
0098       return SetFunction(  &GSLFunctionAdapter<IGradFunction>::F, &GSLFunctionAdapter<IGradFunction>::Df, &GSLFunctionAdapter<IGradFunction>::Fdf, const_cast<void *>(p), xstart );
0099    }
0100 
0101 
0102    typedef double ( * GSLFuncPointer ) ( double, void *);
0103    typedef void ( * GSLFdFPointer ) ( double, void *, double *, double *);
0104    bool SetFunction( GSLFuncPointer f, GSLFuncPointer df, GSLFdFPointer fdf, void * p, double Root );
0105 
0106    using IRootFinderMethod::SetFunction;
0107 
0108    /// iterate (return GSL_SUCCESS in case of successful iteration)
0109    int Iterate() override;
0110 
0111    double Root() const override;
0112 
0113    /// Find the root (return false if failed)
0114    bool Solve( int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10) override;
0115 
0116    /// Return number of iterations
0117    int Iterations() const override {
0118       return fIter;
0119    }
0120 
0121    /// Return the status of last root finding
0122    int Status() const override { return fStatus; }
0123 
0124    const char * Name() const override;
0125 
0126 protected:
0127 
0128    void SetSolver (  GSLRootFdFSolver * s );
0129 
0130    void FreeSolver();
0131 
0132 private:
0133 
0134    GSLFunctionDerivWrapper * fFunction;
0135    GSLRootFdFSolver * fS;
0136 
0137    mutable double fRoot;
0138    mutable double fPrevRoot;
0139    int fIter;
0140    int fStatus;
0141    bool fValidPoint;
0142 
0143 };
0144 
0145 } // namespace Math
0146 } // namespace ROOT
0147 
0148 
0149 #endif /* ROOT_Math_GSL_RootFinderDeriv */