Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4INCLRootFinder.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// INCL++ intra-nuclear cascade model
27// Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
28// Davide Mancusi, CEA
29// Alain Boudard, CEA
30// Sylvie Leray, CEA
31// Joseph Cugnon, University of Liege
32//
33// INCL++ revision: v5.1.8
34//
35#define INCLXX_IN_GEANT4_MODE 1
36
37#include "globals.hh"
38
39/** \file G4INCLRootFinder.hh
40 * \brief Static root-finder algorithm.
41 *
42 * Provides a (nearly) stateless root-finder algorithm.
43 *
44 * \date 2nd March 2011
45 * \author Davide Mancusi
46 */
47
48#ifndef G4INCLROOTFINDER_HH_
49#define G4INCLROOTFINDER_HH_
50
51#include <utility>
52#include "G4INCLIFunction1D.hh"
53
54namespace G4INCL {
55
56 class RootFunctor : public IFunction1D {
57 public:
58 virtual void cleanUp(const G4bool success) const = 0;
59 virtual ~RootFunctor() {};
60 protected:
61 RootFunctor(const G4double x0, const G4double x1) :
62 IFunction1D(x0, x1)
63 {};
64 };
65
66 class RootFinder {
67 public:
68 /** \brief Numerically solve a one-dimensional equation.
69 *
70 * Numerically solves the equation f(x)==0. This implementation uses the
71 * false-position method.
72 *
73 * If a root is found, it can be retrieved using the getSolution() method,
74 *
75 * \param f pointer to a RootFunctor
76 * \param x0 initial value of the function argument
77 * \return true if a root was found
78 */
79 static G4bool solve(RootFunctor const * const f, const G4double x0);
80
81 /** \brief Get the solution of the last call to solve().
82 *
83 * \return the solution, as an (x,y) pair
84 */
85 static std::pair<G4double,G4double> const &getSolution() { return RootFinder::solution; }
86
87 private:
88 /// \brief The solution obtained in the last call to solve().
89 static std::pair<G4double,G4double> solution;
90
91 /** \brief Bracket the root of the function f.
92 *
93 * Tries to find a bracketing value for the function root.
94 *
95 * \param f pointer to a RootFunctor
96 * \param x0 starting value
97 * \return if the root could be bracketed, returns two values of x
98 * bracketing the root, as a pair. If the bracketing failed, returns a
99 * pair with first > second.
100 */
101 static std::pair<G4double,G4double> bracketRoot(RootFunctor const * const f, const G4double x0);
102
103 /// \brief Maximum number of iterations for convergence
104 static const G4int maxIterations=50;
105
106 /// \brief Tolerance on the y value
107 static const G4double toleranceY;
108
109 protected:
112
113 };
114}
115#endif /* G4INCLROOTFINDER_HH_ */
Functor for 1-dimensional mathematical functions.
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
static std::pair< G4double, G4double > const & getSolution()
Get the solution of the last call to solve().
static G4bool solve(RootFunctor const *const f, const G4double x0)
Numerically solve a one-dimensional equation.
virtual void cleanUp(const G4bool success) const =0
RootFunctor(const G4double x0, const G4double x1)