source: trunk/source/global/HEPNumerics/include/G4PolynomialSolver.hh @ 1358

Last change on this file since 1358 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 4.5 KB
Line 
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//
27// $Id: G4PolynomialSolver.hh,v 1.4 2006/06/29 18:59:52 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30// class G4PolynomialSolver
31//
32// Class description:
33//
34//   G4PolynomialSolver allows the user to solve a polynomial equation
35//   with a great precision. This is used by Implicit Equation solver.
36//
37//   The Bezier clipping method is used to solve the polynomial.
38//
39// How to use it:
40//   Create a class that is the function to be solved.
41//   This class could have internal parameters to allow to change
42//   the equation to be solved without recreating a new one.
43//
44//   Define a Polynomial solver, example:
45//   G4PolynomialSolver<MyFunctionClass,G4double(MyFunctionClass::*)(G4double)>
46//     PolySolver (&MyFunction,
47//                 &MyFunctionClass::Function,
48//                 &MyFunctionClass::Derivative,
49//                 precision);
50//
51//   The precision is relative to the function to solve.
52//
53//   In MyFunctionClass, provide the function to solve and its derivative:
54//   Example of function to provide :
55//
56//   x,y,z,dx,dy,dz,Rmin,Rmax are internal variables of MyFunctionClass
57//
58//   G4double MyFunctionClass::Function(G4double value)
59//   {
60//     G4double Lx,Ly,Lz;
61//     G4double result; 
62//   
63//     Lx = x + value*dx;
64//     Ly = y + value*dy;
65//     Lz = z + value*dz;
66//   
67//     result = TorusEquation(Lx,Ly,Lz,Rmax,Rmin);
68//     
69//     return result ; 
70//   }   
71//
72//   G4double MyFunctionClass::Derivative(G4double value)
73//   {
74//     G4double Lx,Ly,Lz;
75//     G4double result; 
76//     
77//     Lx = x + value*dx;
78//     Ly = y + value*dy;
79//     Lz = z + value*dz;
80//     
81//     result = dx*TorusDerivativeX(Lx,Ly,Lz,Rmax,Rmin);
82//     result += dy*TorusDerivativeY(Lx,Ly,Lz,Rmax,Rmin);
83//     result += dz*TorusDerivativeZ(Lx,Ly,Lz,Rmax,Rmin);
84//   
85//     return result;
86//   }
87//   
88//   Then to have a root inside an interval [IntervalMin,IntervalMax] do the
89//   following:
90//
91//   MyRoot = PolySolver.solve(IntervalMin,IntervalMax);
92//
93
94// History:
95//
96// - 19.12.00 E.Medernach, First implementation
97//
98
99#ifndef G4POL_SOLVER_HH
100#define G4POL_SOLVER_HH
101
102#include  "globals.hh"
103
104template <class T, class F>
105class G4PolynomialSolver 
106{
107public:  // with description
108 
109  G4PolynomialSolver(T* typeF, F func, F deriv, G4double precision); 
110  ~G4PolynomialSolver();
111 
112
113  G4double solve (G4double IntervalMin, G4double IntervalMax);
114 
115private:
116
117  G4double Newton (G4double IntervalMin, G4double IntervalMax);
118    //General Newton method with Bezier Clipping
119
120  // Works for polynomial of order less or equal than 4.
121  // But could be changed to work for polynomial of any order providing
122  // that we find the bezier control points.
123
124  G4int BezierClipping(G4double *IntervalMin, G4double *IntervalMax);
125    //   This is just one iteration of Bezier Clipping
126
127
128  T* FunctionClass ;
129  F Function ;
130  F Derivative ;
131 
132  G4double Precision;
133};
134
135#include "G4PolynomialSolver.icc"
136
137#endif
Note: See TracBrowser for help on using the repository browser.