Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
Interpolator.h
Go to the documentation of this file.
1 
9 #ifndef __INTERPOLATOR_H
10 #define __INTERPOLATOR_H
11 
12 #include "../Core/SharedLibraryExportMacros.h"
15 #include "ThreadedInterpolation.h"
16 #include "../Core/StellarZone.h"
17 #include "../Core/Error.h"
18 #include <valarray>
19 #include <list>
20 #include <string>
21 #include <iostream>
22 #include <fstream>
23 #include <boost/archive/text_oarchive.hpp>
24 #include <boost/archive/text_iarchive.hpp>
25 #include <boost/serialization/base_object.hpp>
26 #include <boost/serialization/list.hpp>
27 #include <boost/serialization/valarray.hpp>
28 #include <boost/serialization/vector.hpp>
29 
30 namespace StellarEvolution {
31 
42  class LIB_PUBLIC Interpolator {
43  private:
44  friend class boost::serialization::access;
45 
47  template<class Archive> void serialize(
49  Archive & ar,
50 
52  const unsigned int
53  );
54 
55  std::valarray<double>
59 
62  __track_feh;
63 
68  std::vector< std::vector<const OneArgumentDiffFunction*> >
70 
72  std::vector<bool> __vs_log_age;
73 
75  std::vector<bool> __log_quantity;
76 
79 
81  int find_first_core_index(
82  const std::valarray<double> &core_mass
83  ) const;
84 
86  void perform_queued_interpolations(
88  InterpolationQueue &interpolation_queue,
89 
91  unsigned num_threads = 1
92  );
93  public:
97  __track_masses(),
98  __track_feh(),
99  __interpolated_quantities(NUM_QUANTITIES),
100  __core_formation(Core::NaN)
101  {}
102 
107  const std::valarray<double> &tabulated_masses,
108 
110  const std::valarray<double> &tabulated_feh,
111 
115  const std::list< std::valarray<double> > &tabulated_ages,
116 
120  const std::vector< std::list< std::valarray<double> > >
121  &tabulated_quantities,
122 
126  const std::vector<double> &smoothing,
127 
132  const std::vector<int> &nodes,
133 
136  const std::vector<bool> &vs_log_age,
137 
140  const std::vector<bool> &log_quantity,
141 
144  unsigned num_threads
145  )
146  {
147  create_from(tabulated_masses,
148  tabulated_feh,
149  tabulated_ages,
150  tabulated_quantities,
151  smoothing,
152  nodes,
153  vs_log_age,
154  log_quantity,
155  num_threads);
156  }
157 
159  void create_from(
162  const std::valarray<double> &tabulated_masses,
163 
166  const std::valarray<double> &tabulated_feh,
167 
171  const std::list< std::valarray<double> > &tabulated_ages,
172 
176  const std::vector< std::list< std::valarray<double> > >
177  &tabulated_quantities,
178 
182  const std::vector<double> &smoothing,
183 
188  const std::vector<int> &nodes,
189 
192  const std::vector<bool> &vs_log_age,
193 
196  const std::vector<bool> &log_quantity,
197 
200  unsigned num_threads
201  );
202 
207  virtual EvolvingStellarQuantity *operator()(
209  QuantityID quantity,
210 
212  double mass,
213 
215  double feh
216  ) const;
217 
219  virtual double core_formation_age() const {return __core_formation;}
220 
221 #ifndef NO_SERIALIZE
222  virtual void save_state(
228  const std::string &filename="../interp_state_data"
229  ) const;
230 
250  virtual void load_state(
252  const std::string &filename="../interp_state_data"
253  );
254 #endif
255 
263  void delete_tracks();
264 
265  virtual ~Interpolator() {}
266  }; //End of Interpolator class declaration.
267 
268 #ifndef NO_SERIALIZE
269  template<class Archive> void Interpolator::serialize(
271  Archive & ar,
272  const unsigned int
273  )
274  {
275  if(!std::isfinite(__core_formation)) __core_formation = -1;
276  ar & __track_masses;
277  ar & __track_feh;
278 
279  ar & __interpolated_quantities;
280 
281  ar & __vs_log_age;
282  ar & __log_quantity;
283 
284  ar & __core_formation;
285 #ifndef NDEBUG
286  std::cerr << "Track masses: " << __track_masses << std::endl;
287  std::cerr << "Track [Fe/H]: " << __track_masses << std::endl;
288  std::cerr << "Quantities with sizes: ";
289  for(unsigned i = 0; i < __interpolated_quantities.size(); ++i)
290  std::cerr << (i ? ", " : "") << __interpolated_quantities[i].size();
291  std::cerr << std::endl;
292 
293  std::cerr << "vs log(age): ";
294  for(unsigned i = 0; i < __vs_log_age.size(); ++i)
295  std::cerr << (i ? ", " : "") << __vs_log_age[i];
296  std::cerr << std::endl;
297 
298  std::cerr << "log(quantity): ";
299  for(unsigned i = 0; i < __log_quantity.size(); ++i)
300  std::cerr << (i ? ", " : "") << __log_quantity[i];
301  std::cerr << std::endl;
302 #endif
303  if(__core_formation < 0) __core_formation = Core::Inf;
304  }
305 #endif
306 
307 }//End of StellarEvolution namespace
308 
309 #endif
std::valarray< double > __track_masses
Definition: Interpolator.h:58
Declaration of a class that handles multithreaded stellar evolution interpolation.
std::vector< bool > __log_quantity
Was the interpolation of the log(corresponding quantity)?
Definition: Interpolator.h:75
Defines constant to serve as identifier of the various quantities handled by the stellar evolution in...
Declares a class implementing the intepolation of a single stellar quantity from stellar evolution tr...
virtual double core_formation_age() const
The age at which the core begins to form in Gyr.
Definition: Interpolator.h:219
void serialize(Archive &ar, const unsigned int)
Serialize the current interpolation.
Definition: Interpolator.h:270
A class for stellar properties that depend on age.
A class that interpolates among stellar evolution tracks.
Definition: Interpolator.h:42
std::vector< std::vector< const OneArgumentDiffFunction * > > __interpolated_quantities
The interpolated stellar evolution quantities for each track.
Definition: Interpolator.h:69
A class that handles a queue of interpolation tasks. Also functions as an iterator over the results...
double __core_formation
The age at which the core starts forming in Gyr.
Definition: Interpolator.h:78
Interpolator(const std::valarray< double > &tabulated_masses, const std::valarray< double > &tabulated_feh, const std::list< std::valarray< double > > &tabulated_ages, const std::vector< std::list< std::valarray< double > > > &tabulated_quantities, const std::vector< double > &smoothing, const std::vector< int > &nodes, const std::vector< bool > &vs_log_age, const std::vector< bool > &log_quantity, unsigned num_threads)
Creates a fully functional stellar evolution interpolator.
Definition: Interpolator.h:104
const int NUM_QUANTITIES
The number of interpolation quantities currentyl supported.
Definition: CInterface.cpp:17
QuantityID
Defines the quantities tracked by stellar evolution and their order.
std::vector< bool > __vs_log_age
Was the interpolation of the corresponding quantity vs. log(age)?
Definition: Interpolator.h:72
Interpolator()
Construct an object that can be set to interpolate between tabulated evolution tracks.
Definition: Interpolator.h:96