EqSolver Class Reference

The simplest concrete implementation of IEqSolver interface. More...

#include <src/Components/EqSolver.h>

Inheritance diagram for EqSolver:
Collaboration diagram for EqSolver:

Classes

class  EqSolverMisc
 

Public Types

typedef std::vector< Equations > Jacobi
 
- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Public Member Functions

StatusCode solver (const Equations &funcs, Arg &arg) const override
 Solving nonlinear system with N equations in N unknowns of the function "GenFunc". More...
 
StatusCode initialize () override
 Overriding initialize. More...
 
StatusCode finalize () override
 
 ~EqSolver () override
 Destructor. More...
 
 EqSolver (const std::string &type, const std::string &name, const IInterface *parent)
 Standard constructor. More...
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Member Functions

 EqSolver ()
 default constructor is private More...
 
 EqSolver (const EqSolver &)
 copy constructor is private More...
 
EqSolveroperator= (const EqSolver &)
 assignment operator is More...
 

Private Attributes

std::string m_algType
 
double m_max_iter
 
double m_norm_residual
 
const gsl_multiroot_fdfsolver_type * m_type
 

Detailed Description

The simplest concrete implementation of IEqSolver interface.

See also
GaudiGSL/IEqSolver.h
Author
Kirill Miklyaev kiril.nosp@m.lm@i.nosp@m.ris1..nosp@m.itep.nosp@m..ru
Date
2003-07-07

Definition at line 23 of file EqSolver.h.

Member Typedef Documentation

typedef std::vector<Equations> EqSolver::Jacobi

Definition at line 25 of file EqSolver.h.

Constructor & Destructor Documentation

EqSolver::~EqSolver ( )
override

Destructor.

Definition at line 338 of file EqSolver.cpp.

339 {}
EqSolver::EqSolver ( const std::string &  type,
const std::string &  name,
const IInterface parent 
)

Standard constructor.

See also
GaudiTool
Parameters
typetool type
nametool name
parentparent of the tool

declare type of the algorithm for root finding

declare maximum of iteration

declare the absolute error bound for the residual value

Definition at line 72 of file EqSolver.cpp.

75  : base_class ( type, name , parent )
76  , m_algType ( "fdfsolver_hybridsj" )
77  , m_max_iter ( 1000 )
78  , m_norm_residual ( 1.0e-7 )
79  , m_type ( nullptr )
80 
81 {
83  declareProperty ( "Algorithm", m_algType );
85  declareProperty ( "Iteration", m_max_iter );
87  declareProperty ( "Residual" , m_norm_residual );
88 }
extends base_class
Typedef to this class.
Definition: extends.h:14
std::string m_algType
Definition: EqSolver.h:92
double m_norm_residual
Definition: EqSolver.h:94
double m_max_iter
Definition: EqSolver.h:93
const gsl_multiroot_fdfsolver_type * m_type
Definition: EqSolver.h:95
string type
Definition: gaudirun.py:151
EqSolver::EqSolver ( )
private

default constructor is private

EqSolver::EqSolver ( const EqSolver )
private

copy constructor is private

Member Function Documentation

StatusCode EqSolver::finalize ( )
override

Definition at line 325 of file EqSolver.cpp.

326 {
328 
329  MsgStream log( msgSvc() , name() ) ;
330 
331  if ( sc.isFailure() )
332  {
333  return Error("Could not finaliaze base class GaudiTool", sc);
334  }
335  return StatusCode::SUCCESS;
336 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode finalize() override
standard finalization method
Definition: GaudiTool.cpp:179
StatusCode EqSolver::initialize ( )
override

Overriding initialize.

Definition at line 270 of file EqSolver.cpp.

272 {
274 
275  MsgStream log( msgSvc() , name() ) ;
276 
277  if( sc.isFailure() )
278  {
279  return Error ("Could not initiliaze base class GaudiTool", sc);
280  }
281  /* The algorithm for multiional root-finding
282  (solving nonlinear systems with n equations in n unknowns)*/
283 
284  if( "fdfsolver_hybridsj" == m_algType )
285  {
286  m_type = gsl_multiroot_fdfsolver_hybridsj ;
287  log << MSG::DEBUG
288  << "Root findind algoritms to be used: "
289  << "'gsl_multiroot_fdfsolver_hybridsj'"
290  << endmsg;
291  }
292  else if ( "fdfsolver_hybridj" == m_algType )
293  {
294  m_type = gsl_multiroot_fdfsolver_hybridj ;
295  log << MSG::DEBUG
296  << "Root findind algoritms to be used: "
297  << "'gsl_multiroot_fdfsolver_hybridj'"
298  << endmsg;
299  }
300  else if ( "fdfsolver_newton" == m_algType )
301  {
302  m_type = gsl_multiroot_fdfsolver_newton ;
303  log << MSG::DEBUG
304  << "Root findind algoritms to be used: "
305  << "'gsl_multiroot_fdfsolver_newton'"
306  << endmsg;
307  }
308  else if ( "fdfsolver_gnewton" == m_algType )
309  {
310  m_type = gsl_multiroot_fdfsolver_gnewton ;
311  log << MSG::DEBUG
312  << "Root findind algoritms to be used: "
313  << "'gsl_multiroot_fdfsolver_gnewton'"
314  << endmsg;
315  }
316  else
317  {
318  return Error(" Unknown algorith type '"
319  + std::string(m_algType) + "'");
320  }
321 
322  return StatusCode::SUCCESS;
323 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
std::string m_algType
Definition: EqSolver.h:92
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
const gsl_multiroot_fdfsolver_type * m_type
Definition: EqSolver.h:95
StatusCode initialize() override
standard initialization method
Definition: GaudiTool.cpp:161
EqSolver& EqSolver::operator= ( const EqSolver )
private

assignment operator is

StatusCode EqSolver::solver ( const Equations &  funcs,
Arg &  arg 
) const
override

Solving nonlinear system with N equations in N unknowns of the function "GenFunc".

Solving nonlinear system of the function "GenFunc".

See also
IEqSolver.h
Returns
StatusCode

Definition at line 188 of file EqSolver.cpp.

191 {
192  using namespace Genfun;
193 
194  gsl_vector_view vect = gsl_vector_view_array ( &arg[0] ,
195  arg.dimension() );
196  MsgStream log( msgSvc(), name() );
197 
198  EqSolverMisc local (funcs, arg);
199 
200  const gsl_multiroot_fdfsolver_type *T = m_type;
201  gsl_multiroot_fdfsolver *s;
202  int status = 0 ;
203  size_t iter = 0 ;
204 
205  gsl_multiroot_function_fdf function;
206 
207  function.f = &fun_gsl;
208  function.df = &dfun_gsl;
209  function.fdf = &fdfun_gsl;
210  function.n = vect.vector.size;
211  function.params = (void*) &local;
212 
213  s = gsl_multiroot_fdfsolver_alloc(T, vect.vector.size);
214  gsl_multiroot_fdfsolver_set (s, &function, &vect.vector);
215 
216  for (iter = 0; iter < m_max_iter; ++iter)
217  {
218  status = gsl_multiroot_fdfsolver_iterate (s);
219  if (status)
220  {
221  return Error
222  ("Error from gsl_gsl_multiroot_fdfsolver_iterate '"
223  + std::string(gsl_strerror(status)) + "'") ;
224  }
225 
226  status = gsl_multiroot_test_residual (s->f,
228 
229  if ( status != GSL_CONTINUE ) { break; }
230  }
231 
232  for (unsigned int i = 0; i < vect.vector.size; ++i)
233  {
234  gsl_vector_set (&vect.vector, i, gsl_vector_get (s->x, i));
235  }
236 
237  if (status == GSL_SUCCESS)
238  {
239  log << MSG::DEBUG
240  << "We stopped in the method on the " << iter
241  << " iteration (we have maximum " << m_max_iter
242  << " iterations)" << endmsg;
243  }
244  else if (status == GSL_CONTINUE && iter <= m_max_iter )
245  {
246  return Error ( "Method finished with '"
247  + std::string(gsl_strerror(status))
248  + "' error" );
249  }
250  else
251  {
252  return Error ( "Method finished with '" +
253  std::string(gsl_strerror(status))
254  + "' error" );
255  }
256 
257  gsl_multiroot_fdfsolver_free (s);
258 
259  if (status)
260  {
261  return Error ( "Method finished with '"
262  + std::string(gsl_strerror(status))
263  + "' error" );
264  }
265 
266  return GSL_SUCCESS;
267 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
double m_norm_residual
Definition: EqSolver.h:94
double m_max_iter
Definition: EqSolver.h:93
string s
Definition: gaudirun.py:245
const gsl_multiroot_fdfsolver_type * m_type
Definition: EqSolver.h:95
CLHEP.
Definition: IEqSolver.h:13
list i
Definition: ana.py:128

Member Data Documentation

std::string EqSolver::m_algType
private

Definition at line 92 of file EqSolver.h.

double EqSolver::m_max_iter
private

Definition at line 93 of file EqSolver.h.

double EqSolver::m_norm_residual
private

Definition at line 94 of file EqSolver.h.

const gsl_multiroot_fdfsolver_type* EqSolver::m_type
private

Definition at line 95 of file EqSolver.h.


The documentation for this class was generated from the following files: