Bayeux  3.4.1
Core Foundation library for SuperNEMO
tabulated_function.h
Go to the documentation of this file.
1 /* Author(s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2007-12-07
4  * Last modified: 2018-12-23
5  *
6  * License: GPL3
7  *
8  * Description:
9  *
10  * Tabulated function
11  *
12  */
13 
14 #ifndef MYGSL_TABULATED_FUNCTION_H
15 #define MYGSL_TABULATED_FUNCTION_H 1
16 
17 // Standard library:
18 #include <iostream>
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 // Third party:
24 // - Bayeux/datatools :
25 #include <datatools/i_cloneable.h>
27 
28 // This project:
29 #include <mygsl/i_unary_function.h>
30 
31 namespace mygsl {
32 
35  : public i_unary_function
36  , public datatools::i_cloneable
37  {
38  public:
39  typedef std::map<double,double> points_map_type;
40 
41  static const std::string & linear_interp_name();
42  static const std::string & polynomial_interp_name();
43  static const std::string & cspline_interp_name();
44  static const std::string & cspline_periodic_interp_name();
45  static const std::string & akima_interp_name();
46  static const std::string & akima_periodic_interp_name();
47  static const std::string & steffen_interp_name();
48  static const std::string & default_interp_name();
49 
50  public:
51 
53  virtual bool has_explicit_domain_of_definition() const;
54 
56  virtual bool is_in_domain_of_definition(double x_) const;
57 
59  tabulated_function(const std::string & interp_name_ = "");
60 
62  tabulated_function(const tabulated_function & tab_func_);
63 
65  virtual ~tabulated_function();
66 
69 
71  bool is_verbose() const;
72 
74  void set_verbose(bool v_ = true);
75 
77  bool is_valid(double x_) const;
78 
80  const std::string & interpolator_name() const;
81 
83  const points_map_type & points() const;
84 
86  bool export_to_vectors(std::vector<double> & keys_,
87  std::vector<double> & values_) const;
88 
90  static const std::string & default_interpolator_name();
91 
93  static bool interpolator_name_is_valid(const std::string & name_);
94 
96  void scale(double s_);
97 
99  size_t size() const;
100 
102  bool is_table_locked() const;
103 
105  void lock_table(const std::string & interp_name_ = "");
106 
108  void unlock_table();
109 
111  void relock_table(const std::string & interp_name_ = "");
112 
114  void add_point(double x_, double y_, bool lock_after_ = false);
115 
117  double x_min() const;
118 
120  double x_max() const;
121 
123  void load_from_file(const std::string & filename_, uint32_t options_ = 0);
124 
126  virtual void tabfunc_load(std::istream & in_, void * context_ = 0);
127 
129  virtual void tabfunc_store(std::ostream & out_, void * context_ = 0) const;
130 
132  void print_points(std::ostream & out_,
133  const std::string & header_comment_ = "",
134  const std::string & footer_comment_ = "") const;
135 
136 
138  virtual bool is_initialized() const;
139 
141  virtual void initialize(const datatools::properties & config_,
142  const unary_function_dict_type & functors_);
143 
145  void reset();
146 
148  virtual void tree_dump(std::ostream & out_ = std::clog,
149  const std::string & title_ = "",
150  const std::string & indent_ = "",
151  bool inherit_ = false) const;
152 
153  protected:
154 
156  virtual double _eval(double x_) const;
157 
158  private:
159 
160  struct tabfunc_impl;
161  tabfunc_impl * pImpl = nullptr;
162 
165 
166 
168 
170 
171  };
172 
173 } // end of namespace mygsl
174 
175 #endif // MYGSL_TABULATED_FUNCTION_H
176 
177 // Local Variables: --
178 // mode: c++ --
179 // c-file-style: "gnu" --
180 // tab-width: 2 --
181 // End: --
#define DATATOOLS_CLONEABLE_DECLARATION(Copyable)
Definition: i_cloneable.h:113
static const std::string & akima_periodic_interp_name()
static bool interpolator_name_is_valid(const std::string &name_)
Check the validity of the name of the interpolation algorithm (GSL)
static const std::string & akima_interp_name()
void add_point(double x_, double y_, bool lock_after_=false)
Add a point to the collection.
static const std::string & steffen_interp_name()
bool is_verbose() const
Check verbosity flag.
virtual void tabfunc_load(std::istream &in_, void *context_=0)
Load from an input stream.
virtual ~tabulated_function()
Destructor.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart printing.
static const std::string & linear_interp_name()
double x_min() const
Return the minimum x value from the collection of points.
static const std::string & cspline_periodic_interp_name()
bool is_valid(double x_) const
Check validity.
virtual bool is_in_domain_of_definition(double x_) const
Check if a value is in the domain of definition of the function (default: true)
Tabulated function.
Definition: tabulated_function.h:34
virtual bool is_initialized() const
Check initialization status.
void set_verbose(bool v_=true)
Set verbosity flag.
void lock_table(const std::string &interp_name_="")
Lock the table using a given interpolation algorithm (GSL)
void load_from_file(const std::string &filename_, uint32_t options_=0)
Load the collection of points from a file.
bool is_table_locked() const
Check the table lock flag.
virtual bool has_explicit_domain_of_definition() const
Check if the function has an explicit domain of definition (default: false)
virtual void initialize(const datatools::properties &config_, const unary_function_dict_type &functors_)
Initialization from a container of parameters and a dictionary of functors.
tabulated_function & operator=(const tabulated_function &tab_func_)
Assignement.
static const std::string & cspline_interp_name()
static const std::string & default_interpolator_name()
Return the name of the default interpolation algorithm (GSL)
Abstract interface for unary functions : R -> R.
Definition: i_unary_function.h:44
virtual void tabfunc_store(std::ostream &out_, void *context_=0) const
Store to an output stream.
bool export_to_vectors(std::vector< double > &keys_, std::vector< double > &values_) const
Export to vectors of doubles.
virtual double _eval(double x_) const
Evaluation.
void unlock_table()
Unlock the table.
void relock_table(const std::string &interp_name_="")
Relock the table using a given interpolation algorithm (GSL)
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
A pure abstract class (interface) for inherited cloneable classes.
Definition: i_cloneable.h:75
void print_points(std::ostream &out_, const std::string &header_comment_="", const std::string &footer_comment_="") const
Print points.
tabulated_function(const std::string &interp_name_="")
Default constructor.
double x_max() const
Return the maximum x value from the collection of points.
std::map< std::string, unary_function_handle_type > unary_function_dict_type
Alias for dictionary of handles to unary function objects.
Definition: unary_function_utils.h:30
#define MYGSL_UNARY_FUNCTOR_REGISTRATION_INTERFACE(UnaryFunctorClass)
Definition: i_unary_function.h:206
size_t size() const
Return the size of the collection of points.
const points_map_type & points() const
Return the collection of points.
void scale(double s_)
Scale the function by a given factor.
std::map< double, double > points_map_type
Definition: tabulated_function.h:39
static const std::string & polynomial_interp_name()
void reset()
Reset the functor.
#define BOOST_SERIALIZATION_BASIC_DECLARATION()
Definition: serialization_macros.h:62
static const std::string & default_interp_name()
const std::string & interpolator_name() const
Return the name of the interpolation algorithm (GSL)
A dictionary of arbitrary properties.
Definition: properties.h:125