12 #include "gsl/gsl_errno.h"
13 #include "gsl/gsl_integration.h"
33 #pragma warning(disable:1572)
39 #pragma warning(disable:4996)
44 namespace GaudiMathImplementation
48 { gsl_integration_workspace*
ws ; };
50 { gsl_function*
fn ; };
110 ( const AbsFunction& function ,
116 const
double epsabs ,
117 const
double epsrel ,
120 , m_function ( function.clone () )
132 , m_epsabs ( epsabs )
133 , m_epsrel ( epsrel )
134 , m_result ( GSL_NEGINF )
135 , m_error ( GSL_POSINF )
143 if (
function.dimensionality() < 2 )
144 { Exception(
"::constructor: invalid dimensionality ") ; }
145 if ( m_index >=
function.dimensionality() )
146 { Exception(
"::constructor: invalid variable index") ; }
148 m_DIM =
function.dimensionality() - 1 ;
149 m_argument = Argument( m_DIM ) ;
150 m_argF = Argument( m_DIM + 1 ) ;
165 (
const AbsFunction&
function ,
170 const double epsabs ,
171 const double epsrel ,
174 , m_function (
function.clone() )
184 , m_points ( points )
186 , m_epsabs ( epsabs )
187 , m_epsrel ( epsrel )
189 , m_result ( GSL_NEGINF )
190 , m_error ( GSL_POSINF )
197 if (
function.dimensionality() < 2 )
198 { Exception(
"::constructor: invalid dimensionality ") ; }
199 if ( m_index >=
function.dimensionality() )
200 { Exception(
"::constructor: invalid variable index") ; }
202 m_DIM =
function.dimensionality() - 1 ;
203 m_argument = Argument( m_DIM ) ;
204 m_argF = Argument( m_DIM + 1 ) ;
206 const double l1 =
std::min ( a , b ) ;
207 const double l2 = std::max ( a , b ) ;
208 m_points.push_back ( l1 ) ;
209 m_points.push_back ( l2 ) ;
210 std::sort ( m_points.begin() , m_points.end() ) ;
211 m_points.erase( std::unique( m_points.begin () ,
215 Points::iterator lower =
216 std::lower_bound ( m_points.begin () , m_points.end () , l1 ) ;
217 m_points.erase ( m_points.begin () , lower ) ;
218 Points::iterator upper =
219 std::upper_bound ( m_points.begin () , m_points.end () , l2 ) ;
220 m_points.erase ( upper , m_points.end () ) ;
222 m_pdata =
new double[ m_points.size() ] ;
223 std::copy( m_points.begin() , m_points.end() , m_pdata );
252 (
const AbsFunction&
function ,
256 const double epsabs ,
257 const double epsrel ,
260 , m_function (
function.clone() )
272 , m_epsabs ( epsabs )
273 , m_epsrel ( epsrel )
275 , m_result ( GSL_NEGINF )
276 , m_error ( GSL_POSINF )
283 if (
function.dimensionality() < 2 )
284 { Exception(
"::constructor: invalid dimensionality ") ; }
285 if ( m_index >=
function.dimensionality() )
286 { Exception(
"::constructor: invalid variable index") ; }
288 m_DIM =
function.dimensionality() - 1 ;
289 m_argument = Argument( m_DIM ) ;
290 m_argF = Argument( m_DIM + 1 ) ;
321 (
const AbsFunction&
function ,
325 const double epsabs ,
326 const double epsrel ,
329 , m_function (
function.clone() )
341 , m_epsabs ( epsabs )
342 , m_epsrel ( epsrel )
344 , m_result ( GSL_NEGINF )
345 , m_error ( GSL_POSINF )
352 if (
function.dimensionality() < 2 )
353 { Exception(
"::constructor: invalid dimensionality ") ; }
354 if ( m_index >=
function.dimensionality() )
355 { Exception(
"::constructor: invalid variable index") ; }
357 m_DIM =
function.dimensionality() - 1 ;
358 m_argument = Argument( m_DIM ) ;
359 m_argF = Argument( m_DIM + 1 ) ;
386 (
const AbsFunction&
function ,
392 , m_function (
function.clone() )
404 , m_epsabs ( epsabs )
405 , m_epsrel ( epsrel )
407 , m_result ( GSL_NEGINF )
408 , m_error ( GSL_POSINF )
415 if (
function.dimensionality() < 2 )
416 { Exception(
"::constructor: invalid dimensionality ") ; }
417 if ( m_index >=
function.dimensionality() )
418 { Exception(
"::constructor: invalid variable index") ; }
420 m_DIM =
function.dimensionality() - 1 ;
421 m_argument = Argument( m_DIM ) ;
422 m_argF = Argument( m_DIM + 1 ) ;
431 , m_DIM ( right.
m_DIM )
435 , m_ia ( right.
m_ia )
436 , m_ib ( right.
m_ib )
444 , m_result ( GSL_NEGINF )
445 , m_error ( GSL_POSINF )
453 m_pdata =
new double[m_points.size()] ;
454 std::copy( m_points.begin() , m_points.end() , m_pdata );
468 (
const std::string& message ,
472 "*GaudiMath*" , sc ) ;
480 double NumericalDefiniteIntegral::operator()
481 (
const double argument )
const
484 m_result = GSL_NEGINF ;
485 m_error = GSL_POSINF ;
488 if( 1 != m_DIM ) { Exception (
"operator(): invalid argument size " ) ; };
490 m_argument[0] = argument ;
491 return (*
this) ( m_argument );
502 {
Exception (
"::partial(i): invalid variable index " ) ; };
505 return Genfun::FunctionNoop( &aux ) ;
513 double NumericalDefiniteIntegral::operator()
514 (
const Argument& argument )
const
517 m_result = GSL_NEGINF ;
518 m_error = GSL_POSINF ;
521 if( argument.dimension() != m_DIM )
522 { Exception (
"operator(): invalid argument size " ) ; };
526 for(
size_t i = 0 ;
i < m_DIM ; ++
i )
528 m_argument [
i] = argument [
i] ;
529 const size_t j =
i < m_index ?
i :
i + 1 ;
530 m_argF [j] = argument [
i] ;
534 GSL_Helper helper( *m_function , m_argF , m_index );
544 {
return QAGI ( &F1 ) ; }
548 m_result = 0 ; m_error = 0 ;
553 {
return QAGP ( &F1 ) ; }
556 {
return QNG ( &F1 ) ; }
558 {
return QAG ( &F1 ) ; }
560 {
return QAGS ( &F1 ) ; }
562 { Exception (
"::operator(): invalid type " ); }
564 { Exception (
"::operator(): invalid category " ); }
577 gsl_integration_workspace* aux =
578 gsl_integration_workspace_alloc( size () );
579 if ( 0 == aux ) {
Exception (
"allocate()::invalid workspace" ) ; };
592 if ( 0 == F ) {
Exception(
"::QAGI: invalid function"); }
601 ierror = gsl_integration_qagi ( F->
fn ,
608 ierror = gsl_integration_qagil ( F->
fn ,
m_b ,
615 ierror = gsl_integration_qagiu ( F->
fn ,
m_a ,
621 {
Exception (
"::QAGI: invalid mode" ) ; };
623 if( ierror ) { gsl_error(
"NumericalDefiniteIntegral::QAGI" ,
624 __FILE__ , __LINE__ , ierror ) ;}
635 if( 0 == F ) {
Exception(
"QAGP::invalid function") ; }
640 const size_t npts =
points().size();
644 gsl_integration_qagp ( F->
fn ,
650 if( ierror ) { gsl_error(
"NumericalDefiniteIntegral::QAGI " ,
651 __FILE__ , __LINE__ , ierror ) ; }
665 if( 0 == F ) {
Exception(
"QNG::invalid function") ; }
669 const double high = std::max (
m_a ,
m_b ) ;
673 gsl_integration_qng ( F->
fn ,
678 if( ierror ) { gsl_error(
"NumericalIndefiniteIntegral::QNG " ,
679 __FILE__ , __LINE__ , ierror ) ; }
694 if( 0 == F ) {
Exception(
"QAG::invalid function") ; }
701 const double high = std::max (
m_a ,
m_b ) ;
704 gsl_integration_qag ( F->
fn ,
707 size () , (
int)
rule() ,
ws ()->
ws ,
710 if( ierror ) { gsl_error(
"NumericalDefiniteIntegral::QAG " ,
711 __FILE__ , __LINE__ , ierror ) ; }
725 if( 0 == F ) {
Exception(
"QAG::invalid function") ; }
739 const double high = std::max (
m_a ,
m_b ) ;
742 gsl_integration_qags ( F->
fn ,
748 if( ierror ) { gsl_error(
"NumericalDefiniteIntegral::QAGS " ,
749 __FILE__ , __LINE__ , ierror ) ; }
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Define general base for Gaudi exception.
gsl_integration_workspace * ws
GaudiMath::Integration::Category m_category
virtual ~NumericalDefiniteIntegral()
destructor
NumericalDefiniteIntegral()
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
GaudiMath::Integration::KronrodRule m_rule
This class is used for returning status codes from appropriate routines.
double QAG(_Function *fun) const
double GSL_Adaptor(double x, void *params)
Numerical derivative (using GSL adaptive numerical differentiation)
_Workspace * allocate() const
allocate the integration workspace
GaudiMath::Integration::Type m_type
const AbsFunction * m_function
std::vector< double > Points
typedef for vector of singular points
const Points & points() const
known singularities
virtual Genfun::Derivative partial(unsigned int index) const
Derivatives.
double QAGP(_Function *fun) const
KronrodRule
integration rule
double QNG(_Function *fun) const
double QAGI(_Function *fun) const
the simple structure to be used for adaption interface Genfun::AbsFunction to gsl_function structure ...
Type
the list of available types for ntuples
GaudiMath::Integration::KronrodRule rule() const
integration rule
collection of common types for classes NumericalIndefiniteIntegral and NumericalDefiniteIntegral ...
double QAGS(_Function *fun) const
This class allows the numerical evaluation of the following functions: