Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
StopHistoryInterval.cpp
Go to the documentation of this file.
1 
8 #define BUILDING_LIBRARY
9 #include "StopHistoryInterval.h"
10 
11 namespace Evolve {
12 
14  std::list<double>::const_iterator &age_i,
15  std::list< std::valarray<double> >::const_iterator &cond_i,
16  std::list< std::valarray<double> >::const_iterator &deriv_i)
17  {
18  ++age_i; ++cond_i; ++deriv_i;
19  if(age_i == __history_age_end) {
20  assert(cond_i == __stop_cond_history_end
21  &&
22  deriv_i == __stop_deriv_history_end);
23  age_i = __discarded_age_begin;
26  }
27  }
28 
30  std::list<double>::const_iterator &age_i,
31  std::list< std::valarray<double> >::const_iterator &cond_i,
32  std::list< std::valarray<double> >::const_iterator &deriv_i)
33  {
34  if(age_i == __discarded_age_begin) {
35  assert(cond_i == __stop_cond_discarded_begin
36  &&
37  deriv_i == __stop_deriv_discarded_begin);
38  age_i = __history_age_end;
39  cond_i = __stop_cond_history_end;
40  deriv_i = __stop_deriv_history_end;
41  }
42  --age_i; --cond_i; --deriv_i;
43  }
44 
46  size_t num_points,
47  std::list<double>::const_iterator first_age,
48  std::list<double>::const_iterator history_age_end,
49  std::list<double>::const_iterator discarded_age_begin,
50  std::list< std::valarray<double> >::const_iterator first_stop_cond,
51  std::list< std::valarray<double> >::const_iterator
52  stop_cond_history_end,
53  std::list< std::valarray<double> >::const_iterator
54  stop_cond_discarded_begin,
55  std::list< std::valarray<double> >::const_iterator first_stop_deriv,
56  std::list< std::valarray<double> >::const_iterator
57  stop_deriv_history_end,
58  std::list< std::valarray<double> >::const_iterator
59  stop_deriv_discarded_begin
60  ) :
61  __num_points(num_points),
62  __point_i(0),
63  __first_age(first_age),
64  __last_age(first_age),
65  __history_age_end(history_age_end),
66  __discarded_age_begin(discarded_age_begin),
67  __age_i(first_age),
68  __first_stop_cond(first_stop_cond),
69  __last_stop_cond(first_stop_cond),
70  __stop_cond_history_end(stop_cond_history_end),
71  __stop_cond_discarded_begin(stop_cond_discarded_begin),
72  __stop_cond_i(first_stop_cond),
73  __first_stop_deriv(first_stop_deriv),
74  __last_stop_deriv(first_stop_deriv),
75  __stop_deriv_history_end(stop_deriv_history_end),
76  __stop_deriv_discarded_begin(stop_deriv_discarded_begin),
77  __stop_deriv_i(first_stop_deriv)
78  {
79  if(num_points == 0)
81  "Attempt to contsruct a StopHistoryInterval of size 0."
82  );
83  for(size_t i = 0; i < num_points - 1; i++)
87  reset();
88  }
89 
92  __point_i(orig.__point_i),
94  __last_age(orig.__last_age),
97  __age_i(orig.__age_i),
108  {}
109 
111  {
112  __point_i = 0;
116  }
117 
119  {
120  ++__point_i;
122  throw Core::Error::Runtime(
123  "Attempting to increment two points past the end of a "
124  "StopHistoryInterval!"
125  );
127  return *this;
128  }
129 
131  {
132  StopHistoryInterval result(*this);
133  operator++();
134  return result;
135  }
136 
138  {
139  if(__point_i==0) throw Core::Error::Runtime(
140  "Attempting to go before the beginning of a "
141  "StopHistoryInterval."
142  );
143  --__point_i;
145  return *this;
146  }
147 
149  {
150  StopHistoryInterval result(*this);
151  operator--();
152  return result;
153  }
154 
156  {
157  for(size_t i=0; i<n; i++) {
162  }
163  return *this;
164  }
165 
167  {
168  for(size_t i=0; i<n; i++) {
172  }
173  return *this;
174  }
175 
177  const StopHistoryInterval &rhs)
178  {
180  __point_i=rhs.__point_i;
185  __age_i=rhs.__age_i;
196  return *this;
197  }
198 
200  {
201  return __num_points==rhs.__num_points &&
202  __point_i==rhs.__point_i &&
203  __first_age==rhs.__first_age &&
204  __last_age==rhs.__last_age &&
207  __age_i==rhs.__age_i &&
218  }
219 
221  {
222  __num_points+=n;
223  for(size_t i=0; i<n; i++) {
227  }
228  }
229 
231  {
232  __num_points+=n;
233  for(size_t i=0; i<n; i++)
235  }
236 
237  std::ostream &operator<<(std::ostream &os, StopHistoryInterval interval)
238  {
239  return os;
240  std::streamsize orig_precision=os.precision();
241  std::ios_base::fmtflags orig_flags=os.flags();
242  os.setf(std::ios_base::scientific);
243  os.precision(16);
244  os << std::endl;
245  size_t current_index=interval.current_point_index();
246  os << std::setw(20) << "Age:";
247  for(interval.reset(); !interval.end(); interval++) {
248  if(current_index==interval.current_point_index())
249  os << "|";
250  os << std::setw(25) << interval.age();
251  if(current_index==interval.current_point_index())
252  os << "|";
253  }
254  os << std::endl;
255  for(size_t cond_ind=0; cond_ind<interval.number_conditions();
256  cond_ind++) {
257  os << std::setw(13) << "Condition[" << std::setw(5)
258  << cond_ind << "]:";
259  for(interval.reset(); !interval.end(); interval++) {
260  if(current_index==interval.current_point_index())
261  os << "|";
262  os << std::setw(25)
263  << interval.stop_condition_value(cond_ind);
264  if(current_index==interval.current_point_index())
265  os << "|";
266  }
267  os << std::endl;
268  os << std::setw(13) << "Derivative[" << std::setw(5)
269  << cond_ind << "]:";
270  for(interval.reset(); !interval.end(); interval++) {
271  if(current_index==interval.current_point_index())
272  os << "|";
273  os << std::setw(25) << interval.stop_condition_deriv(cond_ind);
274  if(current_index==interval.current_point_index())
275  os << "|";
276  }
277  os << std::endl;
278  }
279  os.precision(orig_precision);
280  os.flags(orig_flags);
281  return os;
282  }
283 
284 } //End Evolve namespace.
std::list< double >::const_iterator __discarded_age_begin
The first age in the discarded stopping conditions.
std::list< std::valarray< double > >::const_iterator __stop_cond_history_end
The one past last element of the history of stoppnig conditions.
Function arguments do not satisfy some requirement.
Definition: Error.h:73
std::list< std::valarray< double > >::const_iterator __first_stop_deriv
The first stopping condition derivative in the interval.
StopHistoryInterval & operator--()
Advances to the next point in the interval.
StopHistoryInterval(size_t num_points=0, std::list< double >::const_iterator first_age=std::list< double >::const_iterator(), std::list< double >::const_iterator history_age_end=std::list< double >::const_iterator(), std::list< double >::const_iterator discarded_age_begin=std::list< double >::const_iterator(), std::list< std::valarray< double > >::const_iterator first_stop_cond=std::list< std::valarray< double > >::const_iterator(), std::list< std::valarray< double > >::const_iterator stop_cond_history_end=std::list< std::valarray< double > >::const_iterator(), std::list< std::valarray< double > >::const_iterator stop_cond_discarded_begin=std::list< std::valarray< double > >::const_iterator(), std::list< std::valarray< double > >::const_iterator first_stop_deriv=std::list< std::valarray< double > >::const_iterator(), std::list< std::valarray< double > >::const_iterator stop_deriv_history_end=std::list< std::valarray< double > >::const_iterator(), std::list< std::valarray< double > >::const_iterator stop_deriv_discarded_begin=std::list< std::valarray< double > >::const_iterator())
Construct an interval of steps with some reason to stop the evolution.
double stop_condition_deriv(size_t condition_index) const
Returns the derivative of the stop condition with the given index for the current point...
void advance_iterator_set(std::list< double >::const_iterator &age_i, std::list< std::valarray< double > >::const_iterator &cond_i, std::list< std::valarray< double > >::const_iterator &deriv_i)
Increments all the iterators passed as arguments.
std::list< std::valarray< double > >::const_iterator __last_stop_deriv
The last stopping condition derivative in the interval.
size_t number_conditions()
Returns the number of conditions at the first point.
StopHistoryInterval & operator<<(size_t n)
Moves the entire interval, along with the current point left n points.
void grow_left(size_t n=1)
Adds the n points before the first point to the interval.
StopHistoryInterval & operator=(const StopHistoryInterval &rhs)
Copies rhs to this.
std::list< std::valarray< double > >::const_iterator __stop_deriv_i
The current stop condition derivative.
Declares the StopHistoryInterval class.
std::list< std::valarray< double > >::const_iterator __stop_cond_i
The current stopping condition value.
std::list< double >::const_iterator __last_age
The last age in the interval.
std::list< std::valarray< double > >::const_iterator __stop_deriv_discarded_begin
The first of the discarded stopping condition values.
Any runtime error.
Definition: Error.h:61
Orientations of zones of bodies in a binary system.
std::list< std::valarray< double > >::const_iterator __stop_deriv_history_end
The one past last element of the history of stoppnig conditions.
size_t __point_i
The index of the current point.
void reset()
Makes the current point the first point in the interval.
size_t __num_points
Number of points in the interval.
size_t current_point_index()
Returns the index of the current point within the interval.
std::list< std::valarray< double > >::const_iterator __first_stop_cond
The first stopping condition value in the interval.
StopHistoryInterval & operator>>(size_t n)
Moves the entire interval, along with the current point right n points.
std::list< std::valarray< double > >::const_iterator __last_stop_cond
The last stopping condition value in the interval.
double first_age() const
Returns the age of the first point in the interval.
std::list< double >::const_iterator __first_age
The first age in the interval.
size_t num_points()
Returns the number of points in the interval.
void grow_right(size_t n=1)
Adds the n points before the first point to the interval.
bool end()
Returns true iff this is the invalid point marking the end of the interval.
bool operator==(const StopHistoryInterval &rhs)
Checks if the RHS is the same interval and is at the same point in it.
std::list< double >::const_iterator __age_i
The age of the current point.
std::list< double >::const_iterator __history_age_end
The one past last element of the history of stoppnig condition ages.
double stop_condition_value(size_t condition_index) const
Returns the value of the stop condition with the given index for the current point.
std::list< std::valarray< double > >::const_iterator __stop_cond_discarded_begin
The first of the discarded stopping condition values.
double age() const
Returns the age of the current point.
StopHistoryInterval & operator++()
Advances to the next point in the interval.
void retreat_iterator_set(std::list< double >::const_iterator &age_i, std::list< std::valarray< double > >::const_iterator &cond_i, std::list< std::valarray< double > >::const_iterator &deriv_i)
Decrements all the iterators passed as arguments.
A collection of accepted and discarded evolution steps which contain some reason to stop...