Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
EvolvingStellarQuantity.h
Go to the documentation of this file.
1 
9 #ifndef __EVOLVING_STELLAR_QUANTITY_H
10 #define __EVOLVING_STELLAR_QUANTITY_H
11 
12 #include "../Core/SharedLibraryExportMacros.h"
13 #include "AllowedGridGrowth.h"
14 #include "RemoveLogDeriv.h"
15 #include "SumDerivatives.h"
16 #include "InterpolatedDerivatives.h"
17 #include "mass_feh_interp.h"
18 #include "../Core/Functions.h"
19 #include "../Core/InterpSolutionIterator.h"
20 #include "../Core/InterpolatingFunctionALGLIB.h"
21 #include "../Core/Error.h"
22 #include <valarray>
23 #include <list>
24 #include <string>
25 #include <iostream>
26 #include <fstream>
27 #include <sstream>
28 
29 namespace StellarEvolution {
30 
34 
39  private:
40  double
43 
45  __feh;
46 
47 
48  double
51 
53  __max_age;
54 
56  bool __log_age;
57 
60 
63 
64  std::valarray<double>
67 
69  __track_feh;
70 
71  std::valarray<double>
75 
78  __max_interp_ages;
79 
82  std::vector<double> __interp_grid_change_ages;
83 
86  mutable std::vector<double>::const_iterator __next_grid_change_age;
87 
88  mutable size_t
91  __mass_index_above,
92 
95 
98  __feh_index_above,
99 
102  __feh_index_below;
103 
108  std::vector<const OneArgumentDiffFunction *> __evolution_tracks;
109 
110  mutable alglib::real_1d_array
113 
116  __interp_feh;
117 
118  mutable size_t
122 
125  __max_interp_mass_index,
126 
129  __min_interp_feh_index,
130 
133  __max_interp_feh_index;
134 
137  inline size_t track_index(
139  size_t mass_index,
140 
142  size_t feh_index
143  ) const
144  {return feh_index * __track_masses.size() + mass_index;}
145 
148  inline bool track_in_range(
150  size_t track_i,
151 
153  double age) const
154  {
155  assert(track_i < __min_interp_ages.size());
156  assert(track_i < __max_interp_ages.size());
157  return (__min_interp_ages[track_i] <= age
158  &&
159  __max_interp_ages[track_i] >= age);
160  }
161 
164  inline bool track_in_range(
167  size_t mass_i,
168 
171  size_t feh_i,
172 
174  double age) const
175  {return track_in_range(track_index(mass_i, feh_i), age);}
176 
179  void check_grid_range() const;
180 
187  void find_cell(
189  const std::valarray<double> &boundaries,
190 
192  double value,
193 
195  size_t &below_index,
196 
198  size_t &above_index
199  ) const;
200 
202  void set_interp_age_ranges();
203 
209  double evaluate_track(
215  double age,
216 
219  const OneArgumentDiffFunction &track,
220 
224  const FunctionDerivatives **derivatives) const;
225 
229  void check_grid_expansion_directions(
233  AllowedGridGrowth &grow,
234 
236  double age
237  ) const;
238 
241  bool expand_grid(
243  const AllowedGridGrowth &grow,
244 
246  double age
247  ) const;
248 
250  void update_interpolation_grid() const;
251 
256  double interpolate(
257  double age,
258  const FunctionDerivatives **derivatives=NULL
259  ) const;
260 
263  inline double age_to_interp_param(double age) const
264  {return age_to_interp_param(age, __mass, __feh);}
265 
268  inline double interp_param_to_age(double interp_param) const
269  {return interp_param_to_age(interp_param, __mass, __feh);}
270 
271  protected:
276  virtual double age_to_interp_param(
279  double age,
280 
283  double mass,
284 
287  double feh
288  ) const;
289 
294  virtual double interp_param_to_age(
296  double interp_param,
297 
300  double mass,
301 
304  double feh
305  ) const;
306 
307  public:
311 
315  double mass,
316 
318  double feh,
319 
322  const std::valarray<double> &track_masses,
323 
326  const std::valarray<double> &track_feh,
327 
330  //mass index varies faster.
331  const std::vector<const OneArgumentDiffFunction *>
332  &evolution_tracks,
333 
336  bool log_age=true,
337 
340  bool log_quantity=true,
341 
344  bool starts_zero=false
345  );
346 
353  virtual void select_interpolation_region(double age) const;
354 
356  virtual double operator()(double age) const
357  {return interpolate(age);}
358 
360  virtual const FunctionDerivatives *deriv(double age) const;
361 
363  virtual double range_high() const {return __max_age;}
364 
367  virtual double range_low() const
368  {return (__initially_zero ? -Core::Inf : __min_age);}
369 
371  virtual const std::vector<double> &discontinuities() const
372  {return __interp_grid_change_ages;}
373 
380  virtual double next_discontinuity() const
381  {return *__next_grid_change_age;}
382 
385  virtual double previous_discontinuity() const;
386 
389  virtual void enable_next_interpolation_region() const;
390 
393  InterpSolutionIterator crossings(double =0) const
394  {
395  throw Core::Error::Runtime(
396  "Called EvolvingStellarQuantity::crossings, which are ill"
397  "defined."
398  );
399  }
400  }; //End EvolvingStellarQuantity class declaration.
401 
402 } //End StellarEvolution namespace
403 
404 #endif
bool __initially_zero
Should the quantity be assumed zero below the minimum track age.
double __min_age
The minimum age for which this quantity is defined in Gyr.
struct LIB_PUBLIC EvolvingStellarQuantity
Opaque struct to cast to/from StellarEvolution::EvolvingStellarQuantity pointers. ...
Definition: CInterface.h:47
std::vector< const OneArgumentDiffFunction * > __evolution_tracks
The model tracks for the evolution of the quantity on the grid defined by ::__track_masses and ::__tr...
size_t __mass_index_below
The index of the largest track mass not exceeding ::__mass.
brief The smallest age for which the quantity can be interpolated in virtual Gyr double range_low() const
The upper end of the range over which the function is defined.
bool track_in_range(size_t mass_i, size_t feh_i, double age) const
Answer if a given track can participate in interpolating to the given age.
Return the value the quantity takes at the given age in virtual Gyr double operator()(double age) const
The value of the function at the given abscissa.
size_t track_index(size_t mass_index, size_t feh_index) const
Return the index within ::__evolution_tracks for the given mass and [Fe/H] indices.
A class representing a once differentiable function of a single argument.
Definition: Functions.h:104
The largest age for which the quantity can be interpolated in virtual Gyr double range_high() const
The lower end of the range over which the function is defined.
Define a single function performing mass-[Fe/H] interpolations.
std::vector< double >::const_iterator __next_grid_change_age
The entry in ::__interp_grid_change_ages up to which the current interpolation grid is valid...
Any runtime error.
Definition: Error.h:61
Declares & defines a class describing how the mass-[Fe/H] interpolation grid is allowed to grow...
A class for stellar properties that depend on age.
An iterator over a set of solutions to an interpolating function.
Declares & defines a class for the derivative of a quantity which is the sum of two other quantities...
size_t __min_interp_mass_index
The index within ::__track_masses of the lowest mass currently participating in the interpolation...
std::valarray< double > __track_masses
The masses of the evolution tracks.
void select_interpolation_region(const EvolvingStar *star, double age)
Prepare the zone quantities for interpolation around the given age.
Definition: CInterface.cpp:99
double interp_param_to_age(double interp_param) const
Return the age for the given interpoltaion parameter for the current star.
A class representing arbitrary order derivatives of a function.
Definition: Functions.h:66
double __mass
The mass to which to interpolate in .
Declares a class to switch from logarithmic to linear derivative.
bool __log_age
Whether the tracks have log(age) instead of age as their argument.
double age_to_interp_param(double age) const
Return the interpoltaion parameter for the given age for the current star.
bool __log_quantity
Whether the tracks are of log(quantity) instead of the quantity.
EvolvingStellarQuantity()
Default constructor (only useful for derived classes which do not use the interpolation).
std::valarray< double > __min_interp_ages
The minimum interpolation age for the current star to which each track can contribute.
bool track_in_range(size_t track_i, double age) const
Answer if a given track can participate in interpolating to the given age.
std::vector< double > __interp_grid_change_ages
The ages at which the interpolation grid needs to be re-determined.
alglib::real_1d_array __interp_masses
The current track masses participating in the interpolation.