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 
125  __last_order_upgrade_age,
126 
128  __min_extremum_search_step;
129 
131  std::list<double> __tabulated_ages;
132 
134  std::list<Core::EvolModeType> __tabulated_evolution_modes;
135 
138  std::valarray<size_t> __skip_history_zerocrossing;
139 
141  std::valarray<double> __skip_history_extremum;
142 
144  std::list<double> __stop_history_ages,
145 
148  __discarded_stop_ages;
149 
150  std::list< std::valarray<double> >
151  __orbit_history,
152  __orbit_deriv_history,
153  __stop_cond_history,
154 
157 
161  __stop_cond_discarded,
162 
166  __stop_deriv_discarded;
167 
170 
173  std::vector<StopInformation> __stop_info;
174 
177 
180 
183 
186 
187 #ifndef NDEBUG
188  void output_history_and_discarded(std::ostream &os);
193 #endif
194 
196  void clear_discarded();
197 
202  void insert_discarded(double age,
203  const std::valarray<double> &current_stop_cond,
204  const std::valarray<double> &current_stop_deriv);
205 
207  void add_to_evolution(
209  double age,
210 
212  Core::EvolModeType evolution_mode,
213 
215  BinarySystem &system);
216 
222  double go_back(double max_age,
223  BinarySystem &system,
224  std::valarray<double> &orbit);
225 
226 
228  void clear_history();
229 
239  StopHistoryInterval select_stop_condition_interval(bool crossing,
240  size_t cond_ind, size_t max_points) const;
241 
248  ExtremumInformation extremum_from_history_no_deriv(
249  size_t condition_index
250  ) const;
251 
258  ExtremumInformation extremum_from_history(
259  size_t condition_index,
260  double min_extremum_x
261  ) const;
262 
267  double crossing_from_history_no_deriv(
269  size_t condition_index) const;
270 
275  double crossing_from_history(
277  size_t condition_index) const;
278 
281  void initialize_skip_history(
282  const StoppingCondition &stop_cond,
283  const std::valarray<double> &stop_cond_values,
284  StoppingConditionType stop_reason
285  );
286 
289  bool at_exact_condition(double previous_age,
290  const StopInformation &stop_info);
291 
294  void update_skip_history(
295  const std::valarray<double> &current_stop_cond,
296  const StopInformation &stop_info);
297 
300  bool acceptable_step(double current_age,
301  double previous_age,
302  const StopInformation &stop_info);
303 
310  StopInformation update_stop_condition_history(
312  double age,
313 
315  const std::valarray<double> &orbit,
316 
318  const std::valarray<double> &derivatives,
319 
321  Core::EvolModeType evolution_mode,
322 
324  unsigned current_expansion_order,
325 
330  StoppingConditionType stop_reason=NO_STOP
331  );
332 
334  void reject_step(
337  double &age,
338 
341  StopInformation &stop,
342 
344  BinarySystem &system,
345 
348  std::valarray<double> &orbit,
349 
352  double &max_next_t,
353 
355  double &step_size
356 #ifndef NDEBUG
358  , std::string reason
359 #endif
360  );
361 
371  StopInformation evolve_until(
373  BinarySystem &system,
374 
378  double &max_age,
379 
386  std::valarray<double> &orbit,
387 
392  StoppingConditionType &stop_reason,
393 
395  double max_step,
396 
398  Core::EvolModeType evolution_mode
399  );
400 
403  CombinedStoppingCondition *get_stopping_condition(
405  BinarySystem &system
406  );
407 
410  double stopping_age(
412  double age,
413 
415  const BinarySystem &system,
416 
418  const std::list<double> &required_ages);
419 
424  void reached_stopping_condition(
426  double stop_age,
427 
429  StoppingConditionType stop_reason
430  );
431 
434  void adjust_expansion_order(
436  BinarySystem &system,
437 
439  const std::valarray<double> &orbit,
440 
442  Core::EvolModeType evolution_mode,
443 
445  bool must_increase = false
446  );
447 
448 
450  void reset(BinarySystem &system);
451  public:
453  OrbitSolver(
455  double max_age,
456 
458  double required_precision,
459 
462  bool print_progress=false
463  );
464 
467  void operator()(
469  BinarySystem &system,
470 
473  double max_step=Core::Inf,
474 
476  const std::list<double> &required_ages=std::list<double>(),
477 
481  double max_runtime=0,
482 
484  unsigned max_time_steps=0,
485 
490  double min_extremum_search_step=1e-5
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:182
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
LIB_LOCAL int stellar_system_jacobian(double age, const double *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.
std::list< Core::EvolModeType > __tabulated_evolution_modes
The evolution mode corresponding to the matching tabulated age.
Definition: OrbitSolver.h:134
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:179
std::list< std::valarray< double > > __stop_deriv_history
Past values of the stop condition derivatives.
Definition: OrbitSolver.h:151
~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:173
double x() const
The value of the argument where the extremum occurs.
Definition: OrbitSolver.h:101
unsigned __num_step_limit
Max number of steps allowed to be stored in history and/or discarded.
Definition: OrbitSolver.h:185
A base class for all stopping conditions.
Defines the BinarySystem class.
bool __print_progress
See print_progress argument of constructor.
Definition: OrbitSolver.h:176
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:138
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:144
std::valarray< double > __skip_history_extremum
The age after which to look for extrema for each condition.
Definition: OrbitSolver.h:141
std::list< double > __tabulated_ages
The ages at which solution is tabulated.
Definition: OrbitSolver.h:131
Describes a system of two bodies orbiting each other.
Definition: BinarySystem.h:57
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:169
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