Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
InterpSolutionIterator.cpp
1 #include "InterpSolutionIterator.h"
2 
3 namespace Core {
5  {
6  bool found=false;
7  while(node_index < spline->n - 1 && !found) {
8  double *coef=(spline->c.ptr.p_double + 4*node_index);
9  double x0=spline->x.ptr.p_double[node_index],
10  max_x=spline->x.ptr.p_double[node_index+1]-x0;
11  std::valarray<double> cubic_sol=solve_cubic(
12  coef[0]-y, coef[1], coef[2], coef[3]);
13  double tolerance=min_diff*max_x;
14  for(size_t sol_i=0; sol_i<cubic_sol.size(); sol_i++) {
15  double sol_value=cubic_sol[sol_i];
16  if(sol_value>-tolerance && sol_value<max_x+tolerance
17  && (solutions.size()==0 ||
18  solutions.back()<sol_value+x0-tolerance)) {
19  solutions.push_back(sol_value+x0);
20  found=true;
21  }
22  }
23  node_index++;
24  }
25  is_out_of_range=!found;
26  }
27 
29  const InterpSolutionIterator &rhs
30  ) :
31  spline(rhs.spline),
32  node_index(rhs.node_index), y(rhs.y),
34  solutions(rhs.solutions),
35  is_out_of_range(false)
36  {}
37 
39  const alglib::spline1dinterpolant &spline_var,
40  double offset,
41  double min_sol_distance
42  ) :
43  spline(spline_var.c_ptr()),
44  node_index(0),
45  min_diff(min_sol_distance),
46  y(offset),
47  is_out_of_range(false)
48  {
49  get_solutions();
50  solution_iter=solutions.begin();
51  }
52 
54  {
55  solution_iter++;
56  if(solution_iter==solutions.end()) {
57  solution_iter--;
58  get_solutions();
59  solution_iter++;
60  }
62  return *this;
63  }
64 
66  {
67  InterpSolutionIterator result(*this);
68  operator++();
69  return result;
70  }
71 
73  {
74  if(solution_iter!=solutions.begin()) solution_iter--;
75  else is_out_of_range=true;
76  return *this;
77  }
78 
80  {
81  InterpSolutionIterator result(*this);
82  operator--();
83  return result;
84  }
85 
86  const double &InterpSolutionIterator::operator*() const
87  {
88  return *solution_iter;
89  }
90 
92  const InterpSolutionIterator &rhs
93  ) const
94  {
95  return (spline==rhs.spline && node_index==rhs.node_index &&
97  }
98 
100  const InterpSolutionIterator &rhs
101  ) const
102  {
103  return !operator==(rhs);
104  }
105 
107  {
108  return is_out_of_range;
109  }
110 
111 }
bool is_out_of_range
Whether we have gone past the last solution or before the first.
bool operator!=(const InterpSolutionIterator &rhs) const
The opposite of operator==.
bool operator==(const InterpSolutionIterator &rhs) const
Checks if this iterator is at the same solution of the same spline as rhs.
const double & operator*() const
Returns the current solution.
std::valarray< double > solve_cubic(double c0, double c1, double c2, double c3)
Solves the cubic equation .
Definition: Common.cpp:49
An iterator over a set of solutions to an interpolating function.
InterpSolutionIterator & operator--()
Go to the previous solution.
const alglib_impl::spline1dinterpolant * spline
The ALGLIB spline.
bool out_of_range() const
Whether we have gone past the last solution or before the first.
std::list< double >::const_iterator solution_iter
An iterator over the list of solutions found so far.
InterpSolutionIterator & operator++()
Go to the next solution.
double y
Iterate over abscissas when the interpolation=y.
double min_diff
Controls when solutions are considered distinct.
InterpSolutionIterator()
Default constructor of a non meaningful object.
int node_index
The node up to which solutions have been reported.
std::list< double > solutions
The list of solutions found so far.
void get_solutions()
Find another set of solutions.