Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
CInterface.cpp
Go to the documentation of this file.
1 
8 #define BUILDING_LIBRARY
9 #include "CInterface.h"
10 
18 
19 MESAInterpolator* create_interpolator(const char *mesa_dir,
20  double *smoothing,
21  int *nodes,
22  bool *vs_log_age,
23  bool *log_quantity,
24  unsigned num_threads)
25 {
27  if(!smoothing) {
28  assert(!nodes);
29  result = new StellarEvolution::MESA::Interpolator(mesa_dir,
30  num_threads);
31  } else {
32  assert(nodes);
34  mesa_dir,
35  num_threads,
36  std::vector<double>(smoothing, smoothing + NUM_QUANTITIES),
37  std::vector<int>(nodes, nodes + NUM_QUANTITIES),
38  std::vector<bool>(vs_log_age, vs_log_age + NUM_QUANTITIES),
39  std::vector<bool>(log_quantity, log_quantity + NUM_QUANTITIES)
40  );
41  }
42 
43  return reinterpret_cast<MESAInterpolator*>(result);
44 }
45 
47 {
48  delete reinterpret_cast<StellarEvolution::MESA::Interpolator*>(
49  interpolator
50  );
51 }
52 
54  const MESAInterpolator* interpolator,
55  int quantityID,
56  double mass,
57  double feh
58 )
59 {
60  assert(quantityID >= 0 && quantityID < NUM_QUANTITIES);
61  const StellarEvolution::MESA::Interpolator *actual_interpolator =
62  reinterpret_cast<const StellarEvolution::MESA::Interpolator*>(
63  interpolator
64  );
65  return
66  reinterpret_cast<EvolvingStellarQuantity*> (
67  (*actual_interpolator)(
68  static_cast<StellarEvolution::QuantityID>(quantityID),
69  mass,
70  feh
71  )
72  );
73 }
74 
76 {
77  delete reinterpret_cast<StellarEvolution::EvolvingStellarQuantity*>(
78  quantity
79  );
80 }
81 
83  double age)
84 {
85  const StellarEvolution::EvolvingStellarQuantity* actual_quantity =
86  reinterpret_cast<const StellarEvolution::EvolvingStellarQuantity*>(
87  quantity
88  );
89  actual_quantity->select_interpolation_region(age);
90  return (*actual_quantity)(age);
91 }
92 
94  double *age,
95  unsigned nvalues,
96  double *result)
97 {
98  const StellarEvolution::EvolvingStellarQuantity* actual_quantity =
99  reinterpret_cast<const StellarEvolution::EvolvingStellarQuantity*>(
100  quantity
101  );
102 
103  for(unsigned i = 0; i < nvalues; ++i) {
104  if(
105  i==0
106  ||
107  age[i] < age[i - 1]
108  ||
109  actual_quantity->next_discontinuity() < age[i]
110  )
111  actual_quantity->select_interpolation_region(age[i]);
112  result[i] = (*actual_quantity)(age[i]);
113  }
114 }
115 
117  double age, double *result)
118 {
119  const StellarEvolution::EvolvingStellarQuantity* actual_quantity =
120  reinterpret_cast<const StellarEvolution::EvolvingStellarQuantity*>(
121  quantity
122  );
123  actual_quantity->select_interpolation_region(age);
124  const Core::FunctionDerivatives *deriv = actual_quantity->deriv(age);
125 
126  for(unsigned order = 0; order < 3; ++order)
127  result[order] = deriv->order(order);
128 
129  delete deriv;
130 }
131 
133  double *age,
134  unsigned nvalues,
135  double *result)
136 {
137  const StellarEvolution::EvolvingStellarQuantity* actual_quantity =
138  reinterpret_cast<const StellarEvolution::EvolvingStellarQuantity*>(
139  quantity
140  );
141 
142  for(unsigned i = 0; i < nvalues; ++i) {
143  if(
144  i==0
145  ||
146  age[i] < age[i - 1]
147  ||
148  actual_quantity->next_discontinuity() < age[i]
149  )
150  actual_quantity->select_interpolation_region(age[i]);
152  *deriv = actual_quantity->deriv(age[i]);
153  for(unsigned order = 0; order < 3; ++order)
154  result[order * nvalues + i] = deriv->order(order);
155  delete deriv;
156  }
157 }
158 
160 {
161  return
162  reinterpret_cast<const StellarEvolution::EvolvingStellarQuantity*>(
163  quantity
164  )->range_low();
165 }
166 
168 {
169  return
170  reinterpret_cast<const StellarEvolution::EvolvingStellarQuantity*>(
171  quantity
172  )->range_high();
173 }
174 
176  double age,
177  double *range_min,
178  double *range_max)
179 {
180  const StellarEvolution::EvolvingStellarQuantity* actual_quantity =
181  reinterpret_cast<const StellarEvolution::EvolvingStellarQuantity*>(
182  quantity
183  );
184  actual_quantity->select_interpolation_region(age);
185  *range_min = actual_quantity->previous_discontinuity();
186  *range_max = actual_quantity->next_discontinuity();
187 }
188 
189 
190 #ifndef NO_SERIALIZE
191  void save_interpolator(MESAInterpolator *interpolator, const char *filename)
192  {
193  reinterpret_cast<const StellarEvolution::MESA::Interpolator*>(
194  interpolator
195  )->save_state(filename);
196  }
197 
198  MESAInterpolator *load_interpolator(const char *filename)
199  {
202  interpolator->load_state(filename);
203  return reinterpret_cast<MESAInterpolator*>(interpolator);
204  }
205 #endif
206 
207 double default_smoothing(int quantityID)
208 {
209  assert(quantityID >= 0 && quantityID < NUM_QUANTITIES);
211  static_cast<StellarEvolution::QuantityID>(quantityID)
212  );
213 }
214 
215 int default_nodes(int quantityID)
216 {
217  assert(quantityID >= 0 && quantityID < NUM_QUANTITIES);
219  static_cast<StellarEvolution::QuantityID>(quantityID)
220  );
221 }
222 
223 bool default_vs_log_age(int quantityID)
224 {
225  assert(quantityID >= 0 && quantityID < NUM_QUANTITIES);
227  static_cast<StellarEvolution::QuantityID>(quantityID)
228  );
229 }
230 
231 bool default_log_quantity(int quantityID)
232 {
233  assert(quantityID >= 0 && quantityID < NUM_QUANTITIES);
235  static_cast<StellarEvolution::QuantityID>(quantityID)
236  );
237 }
238 
239 double metallicity_from_feh(double feh)
240 {
242 }
243 
244 double feh_from_metallicity(double metallicity)
245 {
247 }
248 
249 double feh_from_z(double z)
250 {
251  return feh_from_metallicity(
253  );
254 }
255 
256 double z_from_feh(double feh)
257 {
258  return (std::pow(10.0, metallicity_from_feh(feh))
259  *
261 }
double metallicity_from_feh(double feh)
Alias for StellarEvolution::metallicity_from_feh()
Definition: CInterface.cpp:239
void destroy_interpolator(MESAInterpolator *interpolator)
Destroy a previously created interpolator.
Definition: CInterface.cpp:46
const int RADIUS
Identifier for the stellar radius as an interpolation quantity.
Definition: CInterface.cpp:11
struct LIB_PUBLIC EvolvingStellarQuantity
Opaque struct to cast to/from StellarEvolution::EvolvingStellarQuantity pointers. ...
Definition: CInterface.h:47
static const std::vector< bool > & default_vs_log_age()
Return the default vs_log_age argument to pass to constructor.
Definition: MESAIO.h:357
MESAInterpolator * load_interpolator(const char *filename)
Load a previously saved interpolator state (faster than creating it).
Definition: CInterface.cpp:198
const int ICONV
Identifier for the convective zone moment of inertia as an interpolation quantity.
Definition: CInterface.cpp:12
bool default_vs_log_age(int quantityID)
Return whether by default the given quantity is interpolated vs. log(age).
Definition: CInterface.cpp:223
const double Zprotosun
The metal fraction with which the Sun formed.
Definition: MESAIO.h:46
double quantity_max_age(const EvolvingStellarQuantity *quantity)
Return the maximum age for which the quantity is defined.
Definition: CInterface.cpp:167
const int LUM
Identifier for the stellar luminosity as an interpolation quantity.
Definition: CInterface.cpp:13
static const std::vector< bool > & default_log_quantity()
Return the default log_quantity argument to pass to constructor.
Definition: MESAIO.h:369
static const std::vector< double > & default_smoothing()
Return the default smoothing argument to pass to constructor.
Definition: MESAIO.h:335
struct LIB_PUBLIC MESAInterpolator
Opaque struct to cast to/from StellarEvolution::Interpolator pointers.
Definition: CInterface.h:43
Declare C-style functions for accessing the functionality of the StellarEvolution library...
A class for stellar properties that depend on age.
virtual double order(unsigned deriv_order=1) const =0
Derivative of the given order of the function with respect to its argument.
double evaluate_quantity(const EvolvingStellarQuantity *quantity, double age)
Evaluate a stellar quantity at a given age.
Definition: CInterface.cpp:82
void differentiate_quantity(const EvolvingStellarQuantity *quantity, double age, double *result)
Calculate the zeroth, first and second derivatives of a quantity.
Definition: CInterface.cpp:116
const EvolvingStellarQuantity * create_quantity(const MESAInterpolator *interpolator, int quantityID, double mass, double feh)
Create a single quantity interpolation for a given star.
Definition: CInterface.cpp:53
A stellar evolution interpolator based on the MESA tracks.
Definition: MESAIO.h:192
double default_smoothing(int quantityID)
Return the default smoothing argument used for the given quantity.
Definition: CInterface.cpp:207
void differentiate_quantity_array(const EvolvingStellarQuantity *quantity, double *age, unsigned nvalues, double *result)
Calculate the derivatives of a quantity at an array of ages.
Definition: CInterface.cpp:132
void quantity_continuous_range(const EvolvingStellarQuantity *quantity, double age, double *range_min, double *range_max)
Return the range of ages surrounding a given age over which a quantity is guaranteed continuous...
Definition: CInterface.cpp:175
A class representing arbitrary order derivatives of a function.
Definition: Functions.h:66
double feh_from_metallicity(double metallicity)
Alias for StellarEvolution::feh_from_metallicity()
Definition: CInterface.cpp:244
const int IRAD
Identifier for the radiative zone moment of inertia as an interpolation quantity. ...
Definition: CInterface.cpp:14
static const std::vector< int > & default_nodes()
Return the default nodes argument to pass to constructor.
Definition: MESAIO.h:346
Return the age derivative of the quantity at the given age in virtual Gyr const FunctionDerivatives * deriv(double age) const
Returns a pointer to the derivative of the function.
const int NUM_QUANTITIES
The number of interpolation quantities currentyl supported.
Definition: CInterface.cpp:17
int default_nodes(int quantityID)
Return the default number of interpolation nodes used for the given quantity.
Definition: CInterface.cpp:215
void evaluate_quantity_array(const EvolvingStellarQuantity *quantity, double *age, unsigned nvalues, double *result)
Evaluate a stellar quantity at an array of ages.
Definition: CInterface.cpp:93
virtual void load_state(const std::string &filename="../interp_state_data")
Loads data from serialization.
bool default_log_quantity(int quantityID)
Return whether by default the log(given quantity) is interpolated vs. the quantity itself...
Definition: CInterface.cpp:231
QuantityID
Defines the quantities tracked by stellar evolution and their order.
double feh_from_z(double z)
Calculate [Fe/H] given Z (metal mass fraction) for a star.
Definition: CInterface.cpp:249
void save_interpolator(MESAInterpolator *interpolator, const char *filename)
Save the state of an interpolator for faster creation.
Definition: CInterface.cpp:191
const int MRAD
Identifier for the radiative zone mass of inertia as an interpolation quantity.
Definition: CInterface.cpp:15
double quantity_min_age(const EvolvingStellarQuantity *quantity)
Return the minimum age for which the quantity is defined.
Definition: CInterface.cpp:159
MESAInterpolator * create_interpolator(const char *mesa_dir, double *smoothing, int *nodes, bool *vs_log_age, bool *log_quantity, unsigned num_threads)
Create an interpolator from a directory containing MESA tracks.
Definition: CInterface.cpp:19
const int RRAD
Identifier for the convective-radiative boundary as an interpolation quantity.
Definition: CInterface.cpp:16
double z_from_feh(double feh)
Calculate Z (metal mass fraction) given [Fe/H] for a star.
Definition: CInterface.cpp:256
void destroy_quantity(EvolvingStellarQuantity *quantity)
Destroy a previously created evolving stellar quantity.
Definition: CInterface.cpp:75