Bayeux  3.4.1
Core Foundation library for SuperNEMO
ode.h
Go to the documentation of this file.
1 
3 #ifndef MYGSL_ODE_H
4 #define MYGSL_ODE_H 1
5 
6 // Standard library:
7 #include <string>
8 #include <iostream>
9 #include <sstream>
10 #include <stdexcept>
11 
12 // Third party:
13 // - GSL:
14 #include <gsl/gsl_odeiv.h>
15 
16 namespace mygsl {
17 
19  struct ode_system
20  {
21  public:
22 
23  virtual bool has_jacobian () const;
24 
25  virtual size_t get_dimension () const = 0;
26 
27  virtual int compute_derivatives ( double t_ ,
28  const double * y_ ,
29  double * f_ ) = 0;
30 
31  virtual int compute_jacobian ( double t_ ,
32  const double * y_ ,
33  double * dfdy_ ,
34  double * dfdt_ );
35 
36  virtual void to_double_star ( double * y_ , size_t dimension_ ) const = 0;
37 
38  virtual void from_double_star ( const double * y_ , size_t dimension_ ) = 0;
39 
40 
41  // GSL interface:
42  static int gsl_ode_function ( double t_ ,
43  const double * y_ ,
44  double * f_ ,
45  void * params_ );
46 
47  static int gsl_ode_jacobian ( double t_ ,
48  const double * y_ ,
49  double * dfdy_ ,
50  double * dfdt_ ,
51  void * params_ );
52  };
53 
54 
55  class ode_driver
56  {
57  public:
58 
59  static const std::string DEFAULT_TYPE;
60 
62  {
63  public:
64  virtual void action ( double t_ ,
65  double * y_ ,
66  size_t dim_ ) = 0;
67 
68  void operator () ( double t_ ,
69  double * y_ ,
70  size_t dim_ )
71  {
72  action (t_,y_,dim_);
73  }
74 
75  };
76 
77  public:
78 
80  {
81  virtual void action ( double t_ , double * y_ , size_t dim_ );
82  };
83 
85 
86  bool is_regular () const;
87 
88  void regular ();
89 
90  void not_regular ();
91 
92  void unset_step_action ();
93 
95 
96  void set_step_action ( at_step_action & asd_ );
97 
98  static bool type_is_valid ( const std::string & type_ );
99 
100  static bool type_requires_jacobian ( const std::string & type_ );
101 
102  static void print_types ( std::ostream & );
103 
104  const std::string & get_type () const;
105 
106  void set_type ( const std::string & type_ );
107 
108  size_t get_dimension () const;
109 
110  ode_driver ( ode_system & sys_ ,
111  const std::string & type_ = DEFAULT_TYPE ,
112  double epsabs_ = 1.e-6,
113  double epsrel_ = 1.e-6,
114  bool regular_ = false );
115 
116  void reset ();
117 
118  virtual ~ode_driver ();
119 
120  void init ();
121 
122  int run ( double t_begin_ , double t_end_ , double h_ );
123 
124  protected:
125 
126  void _at_step_hook ();
127 
128  private:
129 
130  void _init_step_ ();
131 
132  int _inner_run_not_regular_ ();
133 
134  int _inner_run_regular_ ();
135 
136  void _init_run_ ();
137 
138  void _done_run_ ();
139 
140  private:
141  ode_system * _ode_sys_;
142 
143  // GSL stuff:
144  std::string _type_;
145  const gsl_odeiv_step_type * _step_type_;
146  gsl_odeiv_step * _step_;
147  gsl_odeiv_control * _control_;
148  gsl_odeiv_evolve * _evolve_;
149  gsl_odeiv_system _system_;
150  bool _has_jacobian_;
151  bool _regular_;
152  double _epsabs_;
153  double _epsrel_;
154 
155  // internal state:
156  double _t_begin_;
157  double _t_end_;
158  double _h_;
159  double _t_;
160  double * _y_;
161 
162  // hook step function:
163  at_step_action * _at_step_action_;
164 
165  };
166 
167 }
168 
169 #endif // MYGSL_ODE_H
170 
171 /* Local Variables: */
172 /* mode: c++ */
173 /* coding: utf-8 */
174 /* End: */
Definition: ode.h:55
virtual ~ode_driver()
void set_step_action(at_step_action &asd_)
virtual int compute_jacobian(double t_, const double *y_, double *dfdy_, double *dfdt_)
static const std::string DEFAULT_TYPE
Definition: ode.h:59
static void print_types(std::ostream &)
const std::string & get_type() const
virtual bool has_jacobian() const
void unset_step_action()
size_t get_dimension() const
virtual void action(double t_, double *y_, size_t dim_)
void set_type(const std::string &type_)
virtual void action(double t_, double *y_, size_t dim_)=0
System for ODE solving.
Definition: ode.h:19
virtual size_t get_dimension() const =0
void operator()(double t_, double *y_, size_t dim_)
Definition: ode.h:68
static default_step_action _default_step_action_
Definition: ode.h:84
bool is_regular() const
void set_default_step_action()
virtual int compute_derivatives(double t_, const double *y_, double *f_)=0
static bool type_is_valid(const std::string &type_)
ode_driver(ode_system &sys_, const std::string &type_=DEFAULT_TYPE, double epsabs_=1.e-6, double epsrel_=1.e-6, bool regular_=false)
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
int run(double t_begin_, double t_end_, double h_)
virtual void from_double_star(const double *y_, size_t dimension_)=0
static bool type_requires_jacobian(const std::string &type_)
static int gsl_ode_jacobian(double t_, const double *y_, double *dfdy_, double *dfdt_, void *params_)
static int gsl_ode_function(double t_, const double *y_, double *f_, void *params_)
virtual void to_double_star(double *y_, size_t dimension_) const =0