![]() |
|
|
Generated: 24 Nov 2008 |
00001 // $Id: Adapter.cpp,v 1.2 2004/03/28 18:50:36 mato Exp $ 00002 // Include files 00003 // ============================================================================ 00004 // GaudiMath 00005 // ============================================================================ 00006 #include "GaudiMath/GaudiMath.h" 00007 // ============================================================================ 00008 // AIDA 00009 // ============================================================================ 00010 #include "AIDA/IFunction.h" 00011 // ============================================================================ 00012 00013 namespace Genfun 00014 { 00015 namespace GaudiMathImplementation 00016 { 00017 00018 FUNCTION_OBJECT_IMP( AdapterIFunction ) ; 00019 00020 AdapterIFunction::AdapterIFunction ( const AIDA::IFunction& fun) 00021 : AbsFunction ( ) 00022 , m_fun ( &fun ) 00023 , m_dim ( fun.dimension() ) 00024 , m_arg ( fun.dimension() , 0 ) 00025 {} ; 00026 00027 AdapterIFunction:: AdapterIFunction ( const AdapterIFunction& right ) 00028 : AbsFunction ( ) 00029 , m_fun ( right.m_fun ) 00030 , m_dim ( right.m_dim ) 00031 , m_arg ( right.m_arg ) 00032 {} ; 00033 00034 AdapterIFunction::~AdapterIFunction(){}; 00035 00036 double AdapterIFunction::operator() ( double x ) const 00037 { 00038 for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = 0.0 ; } 00039 m_arg[0] = x ; 00040 return m_fun -> value ( m_arg ) ; 00041 }; 00042 00043 double AdapterIFunction::operator() ( const Genfun::Argument& x ) const 00044 { 00045 for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = x[i] ; } 00046 return m_fun -> value ( m_arg ) ; 00047 } ; 00048 00049 Genfun::Derivative AdapterIFunction::partial( unsigned int i ) const 00050 { 00051 if ( i >= m_dim ) 00052 { 00053 const AbsFunction& aux = GaudiMath::Constant( 0 , m_dim ) ; 00054 return Genfun::FunctionNoop( &aux ) ; 00055 }; 00056 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ; 00057 return Genfun::FunctionNoop ( &aux ) ; 00058 }; 00059 00060 FUNCTION_OBJECT_IMP( Adapter2DoubleFunction ) ; 00061 00062 Adapter2DoubleFunction::Adapter2DoubleFunction 00063 ( Adapter2DoubleFunction::Function func ) 00064 : AbsFunction ( ) 00065 , m_func ( func ) 00066 {} 00067 00068 Adapter2DoubleFunction:: Adapter2DoubleFunction 00069 ( const Adapter2DoubleFunction& right ) 00070 : AbsFunction ( ) 00071 , m_func ( right.m_func ) 00072 {} ; 00073 00074 Adapter2DoubleFunction::~Adapter2DoubleFunction(){}; 00075 00076 double Adapter2DoubleFunction::operator() 00077 ( double x ) const 00078 { return m_func ( x , 0 ) ; } ; 00079 00080 double Adapter2DoubleFunction::operator() 00081 ( const Genfun::Argument& x ) const 00082 { return m_func ( x[0] , x[1] ) ; }; 00083 00084 double Adapter2DoubleFunction::operator() 00085 ( const double x , 00086 const double y ) const 00087 { return m_func ( x , y ) ; } ; 00088 00090 Genfun::Derivative Adapter2DoubleFunction::partial( unsigned int i ) const 00091 { 00092 if ( i >= 2 ) 00093 { 00094 const AbsFunction& aux = GaudiMath::Constant( 0 , 2 ) ; 00095 return Genfun::FunctionNoop( &aux ) ; 00096 }; 00097 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ; 00098 return Genfun::FunctionNoop ( &aux ) ; 00099 }; 00100 00101 FUNCTION_OBJECT_IMP( Adapter3DoubleFunction ) ; 00102 00103 Adapter3DoubleFunction::Adapter3DoubleFunction 00104 ( Adapter3DoubleFunction::Function func ) 00105 : AbsFunction ( ) 00106 , m_func ( func ) 00107 {} 00108 00109 Adapter3DoubleFunction:: Adapter3DoubleFunction 00110 ( const Adapter3DoubleFunction& right ) 00111 : AbsFunction ( ) 00112 , m_func ( right.m_func ) 00113 {} ; 00114 00115 Adapter3DoubleFunction::~Adapter3DoubleFunction(){}; 00116 00117 double Adapter3DoubleFunction::operator() 00118 ( double x ) const 00119 { return m_func ( x , 0 , 0 ) ; } ; 00120 00121 double Adapter3DoubleFunction::operator() 00122 ( const Genfun::Argument& x ) const 00123 { return m_func ( x[0] , x[1] , x[2] ) ; }; 00124 00125 double Adapter3DoubleFunction::operator() 00126 ( const double x , 00127 const double y , 00128 const double z ) const 00129 { return m_func ( x , y , z ) ; } ; 00130 00132 Genfun::Derivative Adapter3DoubleFunction::partial( unsigned int i ) const 00133 { 00134 if ( i >= 3 ) 00135 { 00136 const AbsFunction& aux = GaudiMath::Constant( 0 , 3 ) ; 00137 return Genfun::FunctionNoop( &aux ) ; 00138 }; 00139 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ; 00140 return Genfun::FunctionNoop ( &aux ) ; 00141 }; 00142 00143 // ======================================================================== 00145 // ======================================================================== 00146 FUNCTION_OBJECT_IMP( SimpleFunction ); 00147 // ======================================================================== 00148 00149 // ======================================================================= 00153 // ======================================================================== 00154 SimpleFunction::SimpleFunction 00155 ( SimpleFunction::Function1 func ) 00156 : AbsFunction () 00157 , m_case ( SimpleFunction::TrivialArg ) 00158 , m_DIM ( 1 ) 00159 , m_func1 ( func ) 00160 , m_func2 ( 0 ) 00161 , m_arg2 ( 0 ) 00162 , m_func3 ( 0 ) 00163 , m_arg3 ( ) 00164 {}; 00165 // ======================================================================== 00166 00167 // ======================================================================== 00172 // ======================================================================== 00173 SimpleFunction::SimpleFunction 00174 ( SimpleFunction::Function2 func , 00175 const size_t dim ) 00176 : AbsFunction () 00177 , m_case ( SimpleFunction::ArrayArg ) 00178 , m_DIM ( dim ) 00179 , m_func1 ( 0 ) 00180 , m_func2 ( func ) 00181 , m_arg2 ( 0 ) 00182 , m_func3 ( 0 ) 00183 , m_arg3 ( ) 00184 { 00185 m_arg2 = new double[dim]; 00186 }; 00187 // ======================================================================== 00188 00189 // ======================================================================== 00194 // ======================================================================== 00195 SimpleFunction::SimpleFunction 00196 ( SimpleFunction::Function3 func , 00197 const size_t dim ) 00198 : AbsFunction () 00199 , m_case ( SimpleFunction::VectorArg ) 00200 , m_DIM ( dim ) 00201 , m_func1 ( 0 ) 00202 , m_func2 ( 0 ) 00203 , m_arg2 ( 0 ) 00204 , m_func3 ( func ) 00205 , m_arg3 ( dim , 0 ) 00206 {}; 00207 // ======================================================================== 00208 00209 // ======================================================================== 00211 // ======================================================================== 00212 SimpleFunction::SimpleFunction 00213 ( const SimpleFunction& right ) 00214 : AbsFunction () 00215 , m_case ( right.m_case ) 00216 , m_DIM ( right.m_DIM ) 00217 , m_func1 ( right.m_func1 ) 00218 , m_func2 ( right.m_func2 ) 00219 , m_arg2 ( 0 ) 00220 , m_func3 ( right.m_func3 ) 00221 , m_arg3 ( right.m_arg3 ) 00222 { 00223 if ( 0 != right.m_arg2 ) 00224 { 00225 m_arg2 = new double[m_DIM] ; 00226 std::copy( right.m_arg2 , right.m_arg2 + m_DIM , m_arg2 ); 00227 } 00228 }; 00229 // ======================================================================== 00230 00231 // ======================================================================== 00233 // ======================================================================== 00234 SimpleFunction::~SimpleFunction() 00235 { if( 0 != m_arg2 ) { delete m_arg2 ; m_arg2 = 0 ;} } 00236 // ======================================================================== 00237 00238 // ======================================================================== 00240 // ======================================================================== 00241 Genfun::Derivative SimpleFunction::partial( unsigned int i ) const 00242 { 00243 if ( i >= m_DIM ) 00244 { 00245 const AbsFunction& aux = GaudiMath::Constant( 0 , m_DIM ) ; 00246 return Genfun::FunctionNoop( &aux ) ; 00247 } 00248 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ; 00249 return Genfun::FunctionNoop( &aux ); 00250 }; 00251 00252 // ======================================================================== 00254 // ======================================================================== 00255 double SimpleFunction::operator() ( double value ) const 00256 { 00257 double result = 0 ; 00258 switch ( m_case ) 00259 { 00260 case TrivialArg : 00261 result = (*m_func1) ( value ) ; break ; 00262 case ArrayArg : 00263 std::fill ( m_arg2 , m_arg2 + m_DIM , 0.0 ); 00264 m_arg2[0] = value ; 00265 result = (*m_func2) ( m_arg2 ) ; break ; 00266 case VectorArg : 00267 std::fill ( m_arg3.begin () , m_arg3.end () , 0.0 ); 00268 m_arg3[0] = value ; 00269 result = (*m_func3) ( m_arg3 ) ; break ; 00270 default: 00271 break ; 00272 }; 00273 return result ; 00274 }; 00275 // ======================================================================== 00276 00277 // ======================================================================== 00279 // ======================================================================== 00280 double SimpleFunction::operator() ( const Argument& argument ) const 00281 { 00282 double result = 0 ; 00283 switch ( m_case ) 00284 { 00285 case TrivialArg : 00286 result = (*m_func1) ( argument[0] ) ; break ; 00287 case ArrayArg : 00288 for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg2[i] = argument[i] ; } 00289 return (*m_func2)( m_arg2 ) ; ; break ; 00290 case VectorArg : 00291 for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg3[i] = argument[i] ; } 00292 result = (*m_func3) ( m_arg3 ) ; break ; 00293 default: 00294 break ; 00295 } 00296 return result ; 00297 }; 00298 00299 } ; // end of namespace GaudiMathImplementation 00300 }; // end of namespace Genfun 00301 00302 00303 // ============================================================================ 00304 // The END 00305 // ============================================================================