8 #include "gsl/gsl_vector.h" 9 #include "gsl/gsl_multimin.h" 10 #include "gsl/gsl_math.h" 11 #include "gsl/gsl_matrix.h" 12 #include "gsl/gsl_linalg.h" 13 #include "gsl/gsl_blas.h" 14 #include "gsl/gsl_errno.h" 39 const size_t N = funcs.size () ;
40 for(
size_t i = 0 ; i <
N ; ++i )
43 for(
size_t j = 0 ; j <
N ; ++j )
45 Genfun::GENFUNCTION fij = funcs[i]->partial(j);
46 last.push_back( fij.clone() ) ;
48 m_jac.push_back( last );
56 while( !m_jac.empty() )
58 Equations& last = m_jac.back() ;
59 while( !last.empty() )
75 int fun_gsl (
const gsl_vector* v ,
81 const EqSolver::Equations& eqs = *(local->
equations()) ;
84 {
for (
unsigned int i = 0; i < v->size; ++i)
86 arg[i] = gsl_vector_get (v, i);
90 {
for (
unsigned int i = 0; i < v->size; ++i)
92 gsl_vector_set(f, i, (*eqs[i])(arg));
101 int dfun_gsl (
const gsl_vector* v ,
108 Argument& arg = local ->
argument() ;
110 {
for (
unsigned int i = 0; i < v->size; ++i)
112 arg[i] = gsl_vector_get (v, i);
116 {
for(
unsigned int i = 0 ; i < v->size ; ++i )
118 for (
unsigned int j = 0; j < v->size; ++j)
120 Genfun::GENFUNCTION f = *(jac[i][j]) ;
121 gsl_matrix_set ( df , i , j , f ( arg ) ) ;
131 int fdfun_gsl (
const gsl_vector* v ,
138 const EqSolver::Equations& eqs = *(local->
equations()) ;
142 {
for (
unsigned int i = 0; i < v->size; ++i)
144 arg[i] = gsl_vector_get (v, i);
148 {
for(
unsigned int i = 0 ; i < v->size ; ++i )
150 gsl_vector_set(f, i, (*eqs[i])(arg ) ) ;
151 for (
unsigned int j = 0; j < v->size; ++j)
153 Genfun::GENFUNCTION f1 = *(jac[i][j]) ;
154 gsl_matrix_set ( df , i , j , f1(arg) ) ;
173 gsl_vector_view vect = gsl_vector_view_array ( &arg[0] ,
179 const gsl_multiroot_fdfsolver_type *T =
m_type;
180 gsl_multiroot_fdfsolver *
s;
184 gsl_multiroot_function_fdf
function;
186 function.f = &fun_gsl;
187 function.df = &dfun_gsl;
188 function.fdf = &fdfun_gsl;
189 function.n = vect.vector.size;
190 function.params = (
void*) &local;
192 s = gsl_multiroot_fdfsolver_alloc(T, vect.vector.size);
193 gsl_multiroot_fdfsolver_set (s, &
function, &vect.vector);
197 status = gsl_multiroot_fdfsolver_iterate (s);
201 (
"Error from gsl_gsl_multiroot_fdfsolver_iterate '" 205 status = gsl_multiroot_test_residual (s->f,
208 if ( status != GSL_CONTINUE ) {
break; }
211 for (
unsigned int i = 0; i < vect.vector.size; ++i)
213 gsl_vector_set (&vect.vector, i, gsl_vector_get (s->x, i));
216 if (status == GSL_SUCCESS)
219 <<
"We stopped in the method on the " << iter
220 <<
" iteration (we have maximum " << m_max_iter
221 <<
" iterations)" <<
endmsg;
223 else if (status == GSL_CONTINUE && iter <= m_max_iter )
225 return Error (
"Method finished with '" 231 return Error (
"Method finished with '" +
236 gsl_multiroot_fdfsolver_free (s);
240 return Error (
"Method finished with '" 258 return Error (
"Could not initiliaze base class GaudiTool", sc);
265 m_type = gsl_multiroot_fdfsolver_hybridsj ;
267 <<
"Root findind algoritms to be used: " 268 <<
"'gsl_multiroot_fdfsolver_hybridsj'" 271 else if (
"fdfsolver_hybridj" ==
m_algType )
273 m_type = gsl_multiroot_fdfsolver_hybridj ;
275 <<
"Root findind algoritms to be used: " 276 <<
"'gsl_multiroot_fdfsolver_hybridj'" 279 else if (
"fdfsolver_newton" ==
m_algType )
281 m_type = gsl_multiroot_fdfsolver_newton ;
283 <<
"Root findind algoritms to be used: " 284 <<
"'gsl_multiroot_fdfsolver_newton'" 287 else if (
"fdfsolver_gnewton" ==
m_algType )
289 m_type = gsl_multiroot_fdfsolver_gnewton ;
291 <<
"Root findind algoritms to be used: " 292 <<
"'gsl_multiroot_fdfsolver_gnewton'" 297 return Error(
" Unknown algorith type '" 312 return Error(
"Could not finaliaze base class GaudiTool", sc);
Definition of the MsgStream class used to transmit messages.
const Jacobi & jacobi() const
bool isFailure() const
Test for a status code of FAILURE.
#define DECLARE_COMPONENT(type)
Gaudi::Property< std::string > m_algType
The simplest concrete implementation of IEqSolver interface.
Gaudi::Property< double > m_max_iter
StatusCode initialize() override
Overriding initialize.
const Arg & argument() const
This class is used for returning status codes from appropriate routines.
const Equations * equations() const
StatusCode solver(const Equations &funcs, Arg &arg) const override
Solving nonlinear system with N equations in N unknowns of the function "GenFunc".
StatusCode finalize() override
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
const gsl_multiroot_fdfsolver_type * m_type
~EqSolver() override
Destructor.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Gaudi::Property< double > m_norm_residual