G4PolynomialSolver.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 // 
00029 // class G4PolynomialSolver
00030 //
00031 // Class description:
00032 //
00033 //   G4PolynomialSolver allows the user to solve a polynomial equation
00034 //   with a great precision. This is used by Implicit Equation solver.
00035 //
00036 //   The Bezier clipping method is used to solve the polynomial.
00037 //
00038 // How to use it:
00039 //   Create a class that is the function to be solved.
00040 //   This class could have internal parameters to allow to change
00041 //   the equation to be solved without recreating a new one.
00042 //
00043 //   Define a Polynomial solver, example:
00044 //   G4PolynomialSolver<MyFunctionClass,G4double(MyFunctionClass::*)(G4double)>
00045 //     PolySolver (&MyFunction,
00046 //                 &MyFunctionClass::Function,
00047 //                 &MyFunctionClass::Derivative,
00048 //                 precision);
00049 //
00050 //   The precision is relative to the function to solve.
00051 //
00052 //   In MyFunctionClass, provide the function to solve and its derivative:
00053 //   Example of function to provide :
00054 //
00055 //   x,y,z,dx,dy,dz,Rmin,Rmax are internal variables of MyFunctionClass
00056 //
00057 //   G4double MyFunctionClass::Function(G4double value)
00058 //   {
00059 //     G4double Lx,Ly,Lz;
00060 //     G4double result;  
00061 //   
00062 //     Lx = x + value*dx;
00063 //     Ly = y + value*dy;
00064 //     Lz = z + value*dz;
00065 //   
00066 //     result = TorusEquation(Lx,Ly,Lz,Rmax,Rmin);
00067 //     
00068 //     return result ;  
00069 //   }    
00070 // 
00071 //   G4double MyFunctionClass::Derivative(G4double value)
00072 //   {
00073 //     G4double Lx,Ly,Lz;
00074 //     G4double result;  
00075 //     
00076 //     Lx = x + value*dx;
00077 //     Ly = y + value*dy;
00078 //     Lz = z + value*dz;
00079 //      
00080 //     result = dx*TorusDerivativeX(Lx,Ly,Lz,Rmax,Rmin);
00081 //     result += dy*TorusDerivativeY(Lx,Ly,Lz,Rmax,Rmin);
00082 //     result += dz*TorusDerivativeZ(Lx,Ly,Lz,Rmax,Rmin);
00083 //   
00084 //     return result;
00085 //   }
00086 //   
00087 //   Then to have a root inside an interval [IntervalMin,IntervalMax] do the
00088 //   following:
00089 //
00090 //   MyRoot = PolySolver.solve(IntervalMin,IntervalMax);
00091 //
00092 
00093 // History:
00094 //
00095 // - 19.12.00 E.Medernach, First implementation
00096 //
00097 
00098 #ifndef G4POL_SOLVER_HH
00099 #define G4POL_SOLVER_HH
00100 
00101 #include  "globals.hh"
00102 
00103 template <class T, class F>
00104 class G4PolynomialSolver 
00105 {
00106 public:  // with description
00107   
00108   G4PolynomialSolver(T* typeF, F func, F deriv, G4double precision);  
00109   ~G4PolynomialSolver();
00110   
00111 
00112   G4double solve (G4double IntervalMin, G4double IntervalMax);
00113   
00114 private:
00115 
00116   G4double Newton (G4double IntervalMin, G4double IntervalMax);
00117     //General Newton method with Bezier Clipping
00118 
00119   // Works for polynomial of order less or equal than 4.
00120   // But could be changed to work for polynomial of any order providing
00121   // that we find the bezier control points.
00122 
00123   G4int BezierClipping(G4double *IntervalMin, G4double *IntervalMax);
00124     //   This is just one iteration of Bezier Clipping
00125 
00126 
00127   T* FunctionClass ;
00128   F Function ;
00129   F Derivative ;
00130   
00131   G4double Precision;
00132 };
00133 
00134 #include "G4PolynomialSolver.icc"
00135 
00136 #endif 

Generated on Mon May 27 17:49:24 2013 for Geant4 by  doxygen 1.4.7