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 #include "../Evolve/CInterface.h"
11 
16 
17 double lag_from_lgQ(double lgQ)
18 {
19  return 15.0 / (16.0 * M_PI * std::pow(10.0, lgQ));
20 }
21 
23  double feh,
24  double wind_strength,
25  double wind_saturation_frequency,
26  double diff_rot_coupling_timescale,
27  const MESAInterpolator *interpolator)
28 {
29  return reinterpret_cast<EvolvingStar*>(
31  mass,
32  feh,
33  wind_strength,
34  wind_saturation_frequency,
35  diff_rot_coupling_timescale,
36  *reinterpret_cast<const StellarEvolution::MESA::Interpolator*>(
37  interpolator
38  )
39  )
40  );
41 }
42 
45 {
46  delete reinterpret_cast<Star::InterpolatedEvolutionStar*>(star);
47 }
48 
50  unsigned zone_index,
51  unsigned num_tidal_frequency_breaks,
52  unsigned num_spin_frequency_breaks,
53  double *tidal_frequency_breaks,
54  double *spin_frequency_breaks,
55  double *tidal_frequency_powers,
56  double *spin_frequency_powers,
57  double reference_phase_lag,
58  double inertial_mode_enhancement,
59  double inertial_mode_sharpness)
60 {
62  reinterpret_cast<Star::InterpolatedEvolutionStar*>(star);
64  if(zone_index == 0) zone = &(real_star->envelope());
65  else zone = &(real_star->core());
66 
67 #ifndef NDEBUG
68  std::cerr << "Setting zone "
69  << zone_index
70  << " dissipation with "
71  << num_tidal_frequency_breaks
72  << " tidal and "
73  << num_spin_frequency_breaks
74  << " spin frequency breaks."
75  << std::endl;
76 #endif
77 
79  reinterpret_cast<BrokenPowerlawPhaseLagZone*>(zone),
80  num_tidal_frequency_breaks,
81  num_spin_frequency_breaks,
82  tidal_frequency_breaks,
83  spin_frequency_breaks,
84  tidal_frequency_powers,
85  spin_frequency_powers,
86  reference_phase_lag,
87  inertial_mode_enhancement,
88  inertial_mode_sharpness
89  );
90 }
91 
93 {
94  reinterpret_cast<Star::InterpolatedEvolutionStar*>(
95  star
96  )->detect_saturation();
97 }
98 
100  double age)
101 {
102  return reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
103  star
105 }
106 
107 double modified_phase_lag(const EvolvingStar *star,
108  unsigned zone_index,
109  int orbital_frequency_multiplier,
110  int spin_frequency_multiplier,
111  double forcing_frequency,
112  int entry,
113  double *above_lock_value)
114 {
115  return reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
116  star
117  )->zone(zone_index).modified_phase_lag(
118  orbital_frequency_multiplier,
119  spin_frequency_multiplier,
120  forcing_frequency,
121  static_cast<Evolve::Dissipation::QuantityEntry>(entry),
122  *above_lock_value
123  );
124 }
125 
126 double core_formation_age(const EvolvingStar *star)
127 {
128  return reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
129  star
130  )->core().formation_age();
131 }
132 
133 double lifetime(const EvolvingStar *star)
134 {
135  return reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
136  star
137  )->lifetime();
138 }
139 
140 double luminosity(EvolvingStar *star, double age)
141 {
142  const Star::InterpolatedEvolutionStar *actual_star =
143  reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
144  star
145  );
146  actual_star->select_interpolation_region(age);
147  return actual_star->luminosity(age);
148 }
149 
151  const double *age,
152  unsigned nvalues,
153  double *result)
154 {
155  Star::InterpolatedEvolutionStar *actual_star =
156  reinterpret_cast<Star::InterpolatedEvolutionStar*>(
157  star
158  );
159  for(unsigned i = 0; i < nvalues; ++i) {
160  if(
161  i == 0
162  ||
163  age[i] < age[i - 1]
164  )
165  actual_star->select_interpolation_region(age[i]);
166  else
167  actual_star->reached_critical_age(age[i]);
168  result[i] = actual_star->luminosity(age[i]);
169  }
170 }
171 
172 double core_inertia(EvolvingStar *star, double age)
173 {
174  const Star::EvolvingStellarCore &core =
175  reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
176  star
177  )->core();
178  core.select_interpolation_region(age);
179  return core.moment_of_inertia(age);
180 }
181 
182 double core_inertia_deriv(EvolvingStar *star, double age, int deriv_order)
183 {
184  const Star::EvolvingStellarCore &core =
185  reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
186  star
187  )->core();
188  core.select_interpolation_region(age);
189  return core.moment_of_inertia(age, deriv_order);
190 }
191 
192 void zone_inertia_array(Star::EvolvingStellarZone &zone,
193  const double *age,
194  int deriv_order,
195  unsigned nvalues,
196  double *result)
197 {
198  for(unsigned i = 0; i < nvalues; ++i) {
199  if(
200  i == 0
201  ||
202  age[i] < age[i - 1]
203  )
204  zone.select_interpolation_region(age[i]);
205  else
206  zone.reached_critical_age(age[i]);
207  result[i] = zone.moment_of_inertia(age[i], deriv_order);
208  }
209 }
210 
212  const double *age,
213  unsigned nvalues,
214  double *result)
215 {
216  zone_inertia_array(
217  reinterpret_cast<Star::InterpolatedEvolutionStar*>(
218  star
219  )->core(),
220  age,
221  0,
222  nvalues,
223  result
224  );
225 }
226 
228  const double *age,
229  int deriv_order,
230  unsigned nvalues,
231  double *result)
232 {
233  zone_inertia_array(
234  reinterpret_cast<Star::InterpolatedEvolutionStar*>(
235  star
236  )->core(),
237  age,
238  deriv_order,
239  nvalues,
240  result
241  );
242 }
243 
244 double envelope_inertia(EvolvingStar *star, double age)
245 {
246  const Star::EvolvingStellarEnvelope &envelope =
247  reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
248  star
249  )->envelope();
250  envelope.select_interpolation_region(age);
251  return envelope.moment_of_inertia(age);
252 }
253 
254 double envelope_inertia_deriv(EvolvingStar *star, double age, int deriv_order)
255 {
256  const Star::EvolvingStellarEnvelope &envelope =
257  reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
258  star
259  )->envelope();
260  envelope.select_interpolation_region(age);
261  return envelope.moment_of_inertia(age, deriv_order);
262 }
263 
265  const double *age,
266  unsigned nvalues,
267  double *result)
268 {
269  zone_inertia_array(
270  reinterpret_cast<Star::InterpolatedEvolutionStar*>(
271  star
272  )->envelope(),
273  age,
274  0,
275  nvalues,
276  result
277  );
278 }
279 
281  const double *age,
282  int deriv_order,
283  unsigned nvalues,
284  double *result)
285 {
286  zone_inertia_array(
287  reinterpret_cast<Star::InterpolatedEvolutionStar*>(
288  star
289  )->envelope(),
290  age,
291  deriv_order,
292  nvalues,
293  result
294  );
295 }
296 
297 double star_radius(EvolvingStar *star, double age)
298 {
299  const Star::EvolvingStellarEnvelope &envelope =
300  reinterpret_cast<const Star::InterpolatedEvolutionStar*>(
301  star
302  )->envelope();
303  envelope.select_interpolation_region(age);
304  return envelope.outer_radius(age);
305 }
306 
309  const double *age,
310  unsigned nvalues,
311  double *result)
312 {
314  reinterpret_cast<Star::InterpolatedEvolutionStar*>(
315  star
316  )->envelope();
317  for(unsigned i = 0; i < nvalues; ++i) {
318  if(
319  i == 0
320  ||
321  age[i] < age[i - 1]
322  )
323  zone.select_interpolation_region(age[i]);
324  else
325  zone.reached_critical_age(age[i]);
326  result[i] = zone.outer_radius(age[i]);
327  }
328 }
double outer_radius(double age, int deriv_order=0) const
See DissipatingZone::outer_radius(double, int).
void star_radius_array(EvolvingStar *star, const double *age, unsigned nvalues, double *result)
The radius of the star at an array of ages.
Definition: CInterface.cpp:308
void envelope_inertia_deriv_array(EvolvingStar *star, const double *age, int deriv_order, unsigned nvalues, double *result)
One of the derivatives of the moment of inertia of the stellar envelope at a given array of ages...
Definition: CInterface.cpp:280
double core_formation_age(const EvolvingStar *star)
The age at which the core of a star forms.
Definition: CInterface.cpp:126
SPIN_FREQUENCY
The derivative w.r.t. the spin frequency of a dissipating zone.
Declare C-style functions for accessing the functionality of the Evolve library.
const int SPIN_FREQUENCY_DERIV
Identifier for differentiating the phase lag w.r.t. spin freuqency.
Definition: CInterface.cpp:14
double lifetime(const EvolvingStar *star)
The lifetime of a star (the maximum age at which it can be queried)
Definition: CInterface.cpp:133
const int AGE_DERIV
Identifier for differentiating the phase lag w.r.t. age.
Definition: CInterface.cpp:13
Base class for zones of low mass evolving stars.
double core_inertia(EvolvingStar *star, double age)
The moment of inertia of the stellar core at a given age.
Definition: CInterface.cpp:172
struct LIB_PUBLIC MESAInterpolator
Opaque struct to cast to/from StellarEvolution::Interpolator pointers.
Definition: CInterface.h:43
Radiative core for low mass evolving stars.
const EvolvingStellarCore & core() const
The core of the star.
Definition: EvolvingStar.h:100
virtual void select_interpolation_region(double age) const
Prepare the zone quantities for interpolation around the given age.
void destroy_star(EvolvingStar *star)
Destroy a previously created star.
Definition: CInterface.cpp:44
void luminosity_array(EvolvingStar *star, const double *age, unsigned nvalues, double *result)
The luminosity of a star at a given array of ages.
Definition: CInterface.cpp:150
virtual double moment_of_inertia(int deriv_order=0) const =0
Moment of inertia of the zone or its age derivative at the age of last configure() call...
double lag_from_lgQ(double lgQ)
Converts lg(Q) to a tidal phase lag.
Definition: CInterface.cpp:17
double luminosity(EvolvingStar *star, double age)
The luminosity of a star at a given age.
Definition: CInterface.cpp:140
void detect_stellar_wind_saturation(EvolvingStar *star)
Definition: CInterface.cpp:92
double moment_of_inertia(double age, int deriv_order=0) const
See DissipatingZone::moment_of_inertia(double, int)
void core_inertia_deriv_array(EvolvingStar *star, const double *age, int deriv_order, unsigned nvalues, double *result)
One of the derivatives of the moment of inertia of the stellar core at a given array of ages...
Definition: CInterface.cpp:227
void reached_critical_age(double age)
Change the body as necessary at the given age.
void core_inertia_array(EvolvingStar *star, const double *age, unsigned nvalues, double *result)
The moment of inertia of the stellar core at a given array of ages.
Definition: CInterface.cpp:211
double envelope_inertia_deriv(EvolvingStar *star, double age, int deriv_order)
One of the derivatives of the moment of inertia of the stellar envelope at a given age...
Definition: CInterface.cpp:254
void select_interpolation_region(const EvolvingStar *star, double age)
Prepare the zone quantities for interpolation around the given age.
Definition: CInterface.cpp:99
double modified_phase_lag(const EvolvingStar *star, unsigned zone_index, int orbital_frequency_multiplier, int spin_frequency_multiplier, double forcing_frequency, int entry, double *above_lock_value)
See Evolve::BrokenPowerlawPhaseLagZone::modified_phase_lag for details.
Definition: CInterface.cpp:107
double core_inertia_deriv(EvolvingStar *star, double age, int deriv_order)
One of the derivatives of the moment of inertia of the stellar core at a given age.
Definition: CInterface.cpp:182
Surface convective zone for low mass evolving stars or the entire star for high mass stars...
double envelope_inertia(EvolvingStar *star, double age)
The moment of inertia of the stellar envelope at a given age.
Definition: CInterface.cpp:244
const EvolvingStellarEnvelope & envelope() const
The envelope of the star - inmodifiable.
Definition: EvolvingStar.h:94
double moment_of_inertia(int deriv_order=0) const
See DissipatingZone::moment_of_inertia(int).
AGE
The derivative w.r.t. age, excluding the dependence through the body&#39;s radius and the moments of iner...
const int NO_DERIV
Identifier for not differentiating the phase lag.
Definition: CInterface.cpp:12
A DissipatingZone where the phase lag is described by a broken powerlaw.
const int ORBITAL_FREQUENCY_DERIV
Identifier for differentiating the phase lag w.r.t. orbital freuqency.
Definition: CInterface.cpp:15
EvolvingStar * create_star(double mass, double feh, double wind_strength, double wind_saturation_frequency, double diff_rot_coupling_timescale, const MESAInterpolator *interpolator)
Create a star to participate in the orbital evolution calculation.
Definition: CInterface.cpp:22
ORBITAL_FREQUENCY
The derivative w.r.t. the orbital frequency.
virtual void reached_critical_age(double age)
Change the star as necessary at the given age.
Definition: EvolvingStar.h:126
void set_star_dissipation(EvolvingStar *star, unsigned zone_index, unsigned num_tidal_frequency_breaks, unsigned num_spin_frequency_breaks, double *tidal_frequency_breaks, double *spin_frequency_breaks, double *tidal_frequency_powers, double *spin_frequency_powers, double reference_phase_lag, double inertial_mode_enhancement, double inertial_mode_sharpness)
Set the dissipative properties of one of the zones of a star.
Definition: CInterface.cpp:49
double luminosity(double age) const
The luminosity of the star at the given age.
Definition: EvolvingStar.h:118
void set_zone_dissipation(BrokenPowerlawPhaseLagZone *zone, unsigned num_tidal_frequency_breaks, unsigned num_spin_frequency_breaks, double *tidal_frequency_breaks, double *spin_frequency_breaks, double *tidal_frequency_powers, double *spin_frequency_powers, double reference_phase_lag, double inertial_mode_enhancement, double inertial_mode_sharpness)
Definition: CInterface.cpp:22
double star_radius(EvolvingStar *star, double age)
The radius of the star at a given age.
Definition: CInterface.cpp:297
virtual void select_interpolation_region(double age) const
Prepare the stellar quantities for interpolation around the given age.
Definition: EvolvingStar.h:144
virtual double outer_radius(int deriv_order=0) const =0
Outer radius of the zone or its derivative (per last.
void envelope_inertia_array(EvolvingStar *star, const double *age, unsigned nvalues, double *result)
The moment of inertia of the stellar envelope at a given array of ages.
Definition: CInterface.cpp:264
struct LIB_PUBLIC EvolvingStar
Opaque struct to cast to/from Star::InterpolatedEvolutionStar.
Definition: CInterface.h:30