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" 38 const size_t N = funcs.size () ;
39 for(
size_t i = 0 ; i <
N ; ++i ) {
41 for(
size_t j = 0 ; j <
N ; ++j ) {
42 Genfun::GENFUNCTION fij = funcs[i]->partial(j);
43 last.push_back( fij.clone() ) ;
45 m_jac.push_back( last );
56 while( !last.empty() ) {
71 int fun_gsl (
const gsl_vector* v ,
77 const EqSolver::Equations& eqs = *(local->
equations()) ;
80 for (
unsigned int i = 0; i < v->size; ++i) {
81 arg[i] = gsl_vector_get (v, i);
84 for (
unsigned int i = 0; i < v->size; ++i) {
85 gsl_vector_set(f, i, (*eqs[i])(arg));
93 int dfun_gsl (
const gsl_vector* v ,
100 Argument& arg = local ->
argument() ;
102 for (
unsigned int i = 0; i < v->size; ++i) {
103 arg[i] = gsl_vector_get (v, i);
107 for(
unsigned int i = 0 ; i < v->size ; ++i ) {
108 for (
unsigned int j = 0; j < v->size; ++j) {
109 Genfun::GENFUNCTION f = *(jac[i][j]) ;
110 gsl_matrix_set ( df , i , j , f ( arg ) ) ;
119 int fdfun_gsl (
const gsl_vector* v ,
126 const EqSolver::Equations& eqs = *(local->
equations()) ;
130 for (
unsigned int i = 0; i < v->size; ++i) {
131 arg[i] = gsl_vector_get (v, i);
134 for(
unsigned int i = 0 ; i < v->size ; ++i ) {
135 gsl_vector_set(f, i, (*eqs[i])(arg ) ) ;
136 for (
unsigned int j = 0; j < v->size; ++j) {
137 Genfun::GENFUNCTION f1 = *(jac[i][j]) ;
138 gsl_matrix_set ( df , i , j , f1(arg) ) ;
156 gsl_vector_view vect = gsl_vector_view_array ( &arg[0] ,
160 const gsl_multiroot_fdfsolver_type *T =
m_type;
161 gsl_multiroot_fdfsolver *
s =
nullptr;
165 gsl_multiroot_function_fdf
function;
167 function.f = &fun_gsl;
168 function.df = &dfun_gsl;
169 function.fdf = &fdfun_gsl;
170 function.n = vect.vector.size;
171 function.params = &local;
173 s = gsl_multiroot_fdfsolver_alloc(T, vect.vector.size);
174 gsl_multiroot_fdfsolver_set (s, &
function, &vect.vector);
177 status = gsl_multiroot_fdfsolver_iterate (s);
180 (
"Error from gsl_gsl_multiroot_fdfsolver_iterate '" 184 status = gsl_multiroot_test_residual (s->f,
187 if ( status != GSL_CONTINUE ) {
break; }
190 for (
unsigned int i = 0; i < vect.vector.size; ++i) {
191 gsl_vector_set (&vect.vector, i, gsl_vector_get (s->x, i));
194 if (status == GSL_SUCCESS) {
196 <<
"We stopped in the method on the " << iter
197 <<
" iteration (we have maximum " << m_max_iter
198 <<
" iterations)" <<
endmsg;
199 }
else if (status == GSL_CONTINUE && iter <= m_max_iter ) {
200 return Error (
"Method finished with '" 204 return Error (
"Method finished with '" +
209 gsl_multiroot_fdfsolver_free (s);
212 return Error (
"Method finished with '" 225 return Error (
"Could not initiliaze base class GaudiTool", sc);
231 if(
"fdfsolver_hybridsj" ==
m_algType ) {
232 m_type = gsl_multiroot_fdfsolver_hybridsj ;
234 <<
"Root finding algorithm to be used: " 235 <<
"'gsl_multiroot_fdfsolver_hybridsj'" 237 }
else if (
"fdfsolver_hybridj" ==
m_algType ) {
238 m_type = gsl_multiroot_fdfsolver_hybridj ;
240 <<
"Root finding algorithm to be used: " 241 <<
"'gsl_multiroot_fdfsolver_hybridj'" 243 }
else if (
"fdfsolver_newton" ==
m_algType ) {
244 m_type = gsl_multiroot_fdfsolver_newton ;
246 <<
"Root findind algorithm to be used: " 247 <<
"'gsl_multiroot_fdfsolver_newton'" 249 }
else if (
"fdfsolver_gnewton" ==
m_algType ) {
250 m_type = gsl_multiroot_fdfsolver_gnewton ;
252 <<
"Root findind algorithm to be used: " 253 <<
"'gsl_multiroot_fdfsolver_gnewton'" 256 return Error(
" Unknown algorithm type '"
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".
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
const gsl_multiroot_fdfsolver_type * m_type
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Gaudi::Property< double > m_norm_residual