| 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: testIntegration.cc,v 1.6 2006/06/29 19:00:39 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $
|
|---|
| 29 | //
|
|---|
| 30 | // Test program for G4SimpleIntegration class. The function std::exp(-x)*std::cos(x) is
|
|---|
| 31 | // integrated between zero and two pi. The true result is 0.499066278634
|
|---|
| 32 | //
|
|---|
| 33 |
|
|---|
| 34 | #include "G4ios.hh"
|
|---|
| 35 | #include "globals.hh"
|
|---|
| 36 | #include "G4SimpleIntegration.hh"
|
|---|
| 37 |
|
|---|
| 38 | G4double TestFunction(G4double x)
|
|---|
| 39 | {
|
|---|
| 40 | return std::exp(-x)*std::cos(x) ;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | int main()
|
|---|
| 44 | {
|
|---|
| 45 | G4int i, n ;
|
|---|
| 46 | G4double pTolerance ;
|
|---|
| 47 | G4double a = 0.0 ;
|
|---|
| 48 | G4double b = twopi ;
|
|---|
| 49 | G4SimpleIntegration myIntegrand(TestFunction) ;
|
|---|
| 50 |
|
|---|
| 51 | G4cout<<"Iteration"<<"\t"<<"Trapezoidal"<<"\t"
|
|---|
| 52 | <<"MidPoint"<<"\t"<<"Gauss"<<"\t"<<"Simpson"<<G4endl ;
|
|---|
| 53 | for(i=0;i<13;i++)
|
|---|
| 54 | {
|
|---|
| 55 | n = (int)pow(2,i) ;
|
|---|
| 56 | G4cout<<n<<"\t"
|
|---|
| 57 | <<myIntegrand.Trapezoidal(a,b,n)<<"\t"
|
|---|
| 58 | <<myIntegrand.MidPoint(a,b,n)<<"\t"
|
|---|
| 59 | <<myIntegrand.Gauss(a,b,n)<<"\t"
|
|---|
| 60 | <<myIntegrand.Simpson(a,b,n)<<G4endl ;
|
|---|
| 61 | }
|
|---|
| 62 | G4cout<<G4endl ;
|
|---|
| 63 | for(i=0;i<13;i++)
|
|---|
| 64 | {
|
|---|
| 65 | pTolerance = std::pow(10.0,-i) ;
|
|---|
| 66 | G4SimpleIntegration adaptIntegrand(TestFunction,pTolerance) ;
|
|---|
| 67 | G4cout<<adaptIntegrand.AdaptGaussIntegration(a,b)<<G4endl;
|
|---|
| 68 | }
|
|---|
| 69 | return 0;
|
|---|
| 70 | }
|
|---|