Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
OrbitSolver.h
Go to the documentation of this file.
1 
9 #ifndef __ORBIT_SOLVER_H
10 #define __ORBIT_SOLVER_H
11 
12 #include "../Core/SharedLibraryExportMacros.h"
13 #include "../Core/AstronomicalConstants.h"
14 #include "../Core/Common.h"
15 #include "../Core/OrbitalExpressions.h"
16 #include "../Core/Common.h"
17 #include "BinarySystem.h"
20 #include "StopInformation.h"
21 #include "StopHistoryInterval.h"
22 #include <math.h>
23 #include <list>
24 #include <vector>
25 #include <stdlib.h>
26 #include <fstream>
27 #include <iostream>
28 #include <gsl/gsl_odeiv2.h>
29 #include <gsl/gsl_errno.h>
30 #include <gsl/gsl_poly.h>
31 #include <sstream>
32 #include <iostream>
33 #include <limits>
34 #include <ctime>
35 
36 namespace Evolve {
37 
38  typedef int (*GSL_ODE_TYPE)(double, const double*, double*, void*);
39  typedef int (*GSL_JAC_TYPE)(double, const double*, double*, double*, void*);
40  typedef bool (*STOP_EVOL_TYPE)(double, const double*, void*);
41 
44  LIB_LOCAL int stellar_system_diff_eq(
46  double age,
47 
50  const double *parameters,
51 
53  double *derivatives,
54 
58  void *system);
59 
62  LIB_LOCAL int stellar_system_jacobian(
64  double age,
65 
68  const double *parameters,
69 
71  double *param_derivs,
72 
75  double *age_derivs,
76 
79  void *system_mode);
80 
84  class LIB_LOCAL ExtremumInformation {
85  private:
87  double __x,
88 
90  __y;
91  public:
95  double x=Core::Inf,
96 
98  double y=Core::NaN) : __x(x), __y(y) {}
99 
101  double x() const {return __x;}
103  double &x() {return __x;}
104 
106  double y() const {return __y;}
108  double &y() {return __y;}
109  };//End ExtremumInformation class.
110 
115  class LIB_PUBLIC OrbitSolver {
116  private:
117  double
119  __end_age,
120 
122  __precision,
123 
127  __e_order_downgrade_threshold,
128 
130  __last_e_order_upgrade_age;
131 
133  std::list<double> __tabulated_ages;
134 
136  std::list<Core::EvolModeType> __tabulated_evolution_modes;
137 
140  std::valarray<size_t> __skip_history_zerocrossing;
141 
143  std::valarray<double> __skip_history_extremum;
144 
146  std::list<double> __stop_history_ages,
147 
150  __discarded_stop_ages;
151 
152  std::list< std::valarray<double> >
153  __orbit_history,
154  __orbit_deriv_history,
155  __stop_cond_history,
156 
159 
163  __stop_cond_discarded,
164 
168  __stop_deriv_discarded;
169 
172 
175  std::vector<StopInformation> __stop_info;
176 
179 
182 
185 
186 #ifndef NDEBUG
187  void output_history_and_discarded(std::ostream &os);
192 #endif
193 
195  void clear_discarded();
196 
201  void insert_discarded(double age,
202  const std::valarray<double> &current_stop_cond,
203  const std::valarray<double> &current_stop_deriv);
204 
206  void add_to_evolution(
208  double age,
209 
211  Core::EvolModeType evolution_mode,
212 
214  BinarySystem &system);
215 
221  double go_back(double max_age,
222  BinarySystem &system,
223  std::valarray<double> &orbit);
224 
225 
227  void clear_history();
228 
238  StopHistoryInterval select_stop_condition_interval(bool crossing,
239  size_t cond_ind, size_t max_points) const;
240 
247  ExtremumInformation extremum_from_history_no_deriv(
248  size_t condition_index) const;
249 
256  ExtremumInformation extremum_from_history(size_t condition_index) const;
257 
262  double crossing_from_history_no_deriv(
264  size_t condition_index) const;
265 
270  double crossing_from_history(
272  size_t condition_index) const;
273 
276  void initialize_skip_history(const StoppingCondition &stop_cond,
277  StoppingConditionType stop_reason);
278 
281  bool at_exact_condition(double previous_age,
282  const StopInformation &stop_info);
283 
286  /* void update_skip_history(
287  const std::valarray<double> &current_stop_cond,
288  const StopInformation &stop_info);*/
289 
292  bool acceptable_step(double current_age,
293  double previous_age,
294  const StopInformation &stop_info);
295 
298  //(e-order should be increased).
299  int check_expansion_error(
301  const std::valarray<double> &derivatives,
302 
305  const std::valarray<double> &expansion_errors
306  );
307 
314  StopInformation update_stop_condition_history(
316  double age,
317 
319  const std::valarray<double> &orbit,
320 
322  const std::valarray<double> &derivatives,
323 
326  const std::valarray<double> &expansion_errors,
327 
329  Core::EvolModeType evolution_mode,
330 
335  StoppingConditionType stop_reason=NO_STOP,
336 
339  bool ignore_e_order_decrease=false
340  );
341 
343  void reject_step(
346  double &age,
347 
350  StopInformation &stop,
351 
353  BinarySystem &system,
354 
357  std::valarray<double> &orbit,
358 
361  double &max_next_t,
362 
364  double &step_size
365 #ifndef NDEBUG
367  , std::string reason
368 #endif
369  );
370 
380  StopInformation evolve_until(
382  BinarySystem &system,
383 
387  double &max_age,
388 
395  std::valarray<double> &orbit,
396 
401  StoppingConditionType &stop_reason,
402 
404  double max_step,
405 
407  Core::EvolModeType evolution_mode
408  );
409 
412  CombinedStoppingCondition *get_stopping_condition(
414  BinarySystem &system
415  );
416 
419  double stopping_age(
421  double age,
422 
424  const BinarySystem &system,
425 
427  const std::list<double> &required_ages);
428 
433  void reached_stopping_condition(
435  double stop_age,
436 
438  StoppingConditionType stop_reason
439  );
440 
443  void adjust_eccentricity_order(
445  BinarySystem &system,
446 
448  const std::valarray<double> &orbit,
449 
451  Core::EvolModeType evolution_mode,
452 
454  bool must_increase = false
455  );
456 
457 
459  void reset(BinarySystem &system);
460  public:
462  OrbitSolver(
464  double max_age,
465 
467  double required_precision,
468 
471  bool print_progress=false
472  );
473 
476  void operator()(
478  BinarySystem &system,
479 
482  double max_step=Core::Inf,
483 
485  const std::list<double> &required_ages=std::list<double>(),
486 
490  double max_runtime=0
491  );
492 
494  const std::list<double> &evolution_ages() const
495  {return __tabulated_ages;}
496 
498  const std::list<Core::EvolModeType> &mode_evolution() const
499  {return __tabulated_evolution_modes;}
500 
503  {if(__stopping_conditions) delete __stopping_conditions;}
504 
505  }; //End OrbitSolver class.
506 
507 }//End Evolve namespace.
508 
509 #endif
Declares the StopInformation class.
double __runtime_limit
Max number of seconds current evolution is allowed to run.
Definition: OrbitSolver.h:184
double __precision
The precision required of the solution.
Definition: OrbitSolver.h:119
const std::list< Core::EvolModeType > & mode_evolution() const
The tabulated evolution modes so far.
Definition: OrbitSolver.h:498
std::list< Core::EvolModeType > __tabulated_evolution_modes
The evolution mode corresponding to the matching tabulated age.
Definition: OrbitSolver.h:136
Declares the StopHistoryInterval class.
Users can define any stopping condition they wish the evolution to search for in this file...
double __y
The value of the function at the extremum.
Definition: OrbitSolver.h:87
ExtremumInformation(double x=Core::Inf, double y=Core::NaN)
Create an object to hold information about a function extremum.
Definition: OrbitSolver.h:93
struct LIB_PUBLIC OrbitSolver
Opaque struct to cast to/from Evolve::OrbitSolver.
Definition: CInterface.h:38
Infomation about an extremum of a function.
Definition: OrbitSolver.h:84
StoppingConditionType
The reasons for stopping the evolution currently supported.
Orientations of zones of bodies in a binary system.
time_t __evolution_start_time
When did the currently running evolution start.
Definition: OrbitSolver.h:181
std::list< std::valarray< double > > __stop_deriv_history
Past values of the stop condition derivatives.
Definition: OrbitSolver.h:153
~OrbitSolver()
Clean up.
Definition: OrbitSolver.h:502
The information about why and where the evolution should stop.
No reason to stop.
std::vector< StopInformation > __stop_info
Definition: OrbitSolver.h:175
double x() const
The value of the argument where the extremum occurs.
Definition: OrbitSolver.h:101
A base class for all stopping conditions.
Defines the BinarySystem class.
bool __print_progress
See print_progress argument of constructor.
Definition: OrbitSolver.h:178
EvolModeType
The various evolution modes.
Definition: Common.h:42
std::valarray< size_t > __skip_history_zerocrossing
The number of points at the start of the history to skip when lookng for a zero crossing for each con...
Definition: OrbitSolver.h:140
int stellar_system_jacobian(double age, const double *orbital_parameters, double *param_derivs, double *age_derivs, void *system_mode)
A wrapper tha allows the stellar system jacobian to be passed to the GSL ODE solver.
Definition: OrbitSolver.cpp:39
Solves the system of ODEs describing the evolution of a single planet around a single star...
Definition: OrbitSolver.h:115
double & y()
The value of the function at the extremum.
Definition: OrbitSolver.h:108
double & x()
The value of the argument where the extremum occurs.
Definition: OrbitSolver.h:103
Declares a class for a stopping condition that combines other stopping conditions.
double y() const
The value of the function at the extremum.
Definition: OrbitSolver.h:106
A class combining the the outputs of multiple stopping conditions.
std::list< double > __stop_history_ages
The ages at which the stop condition history is kept.
Definition: OrbitSolver.h:146
std::valarray< double > __skip_history_extremum
The age after which to look for extrema for each condition.
Definition: OrbitSolver.h:143
std::list< double > __tabulated_ages
The ages at which solution is tabulated.
Definition: OrbitSolver.h:133
Describes a system of two bodies orbiting each other.
Definition: BinarySystem.h:56
A collection of accepted and discarded evolution steps which contain some reason to stop...
StoppingCondition * __stopping_conditions
The current set of stopping conditions.
Definition: OrbitSolver.h:171
const std::list< double > & evolution_ages() const
The ages at which evolution has been tabulated so far.
Definition: OrbitSolver.h:494
int stellar_system_diff_eq(double age, const double *parameters, double *derivatives, void *system_mode)
A wrapper tha allows the stellar system differential equation to be passed to the GSL ODE solver...
Definition: OrbitSolver.cpp:23