Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
CombinedStoppingCondition.cpp
1 #define BUILDING_LIBRARY
3 
4 namespace Evolve {
5 
7  const StoppingCondition *rhs
8  )
9  {
10  size_t num_new_subcond = rhs->num_subconditions();
11  __num_subconditions += num_new_subcond;
12  __types.reserve(__types.size() + num_new_subcond);
13  for(size_t i = 0; i < num_new_subcond; i++)
14  __types.push_back(rhs->type(i));
15  }
16 
18  const StoppingCondition *cond,
19  Core::EvolModeType evol_mode,
20  const std::valarray<double> &orbit,
21  const std::valarray<double> &derivatives,
22  size_t &first_index,
23  std::valarray<double> &values,
24  std::valarray<double> &derivs) const
25  {
26  std::valarray<double> sub_stop_deriv(cond->num_subconditions()),
27  temp_array=(*cond)(evol_mode, orbit, derivatives, sub_stop_deriv);
28  for(size_t subcond_ind=0; subcond_ind<temp_array.size();
29  subcond_ind++) {
30  values[first_index]=temp_array[subcond_ind];
31  derivs[first_index]=sub_stop_deriv[subcond_ind];
32  ++first_index;
33  }
34  }
35 
36  std::vector<StoppingCondition *>::const_iterator
38  {
39  std::vector<StoppingCondition *>::const_iterator sc_iter=
40  __sub_conditions.begin();
41  while(index >= (*sc_iter)->num_subconditions()) {
42  assert(sc_iter != __sub_conditions.end());
43  index -= (*sc_iter)->num_subconditions();
44  ++sc_iter;
45  }
46  return sc_iter;
47  }
48 
49  std::vector<StoppingCondition *>::iterator
51  {
52  std::vector<StoppingCondition *>::const_iterator
53  const_result =
54  static_cast<const CombinedStoppingCondition *>(
55  this
56  )->find_condition(index);
57 
58  return (
59  __sub_conditions.begin()
60  +
61  (const_result - __sub_conditions.begin())
62  );
63  }
64 
67  )
68  {
71  rhs.__sub_conditions.begin(), rhs.__sub_conditions.end());
72  if(__delete_subcond) {
73  assert(rhs.__delete_subcond);
74 
75  const_cast<CombinedStoppingCondition &>(rhs).__delete_subcond=false;
76  }
77  return *this;
78  }
79 
82  )
83  {
85  __sub_conditions.push_back(rhs);
86  return *this;
87  }
88 
90  Core::EvolModeType evol_mode,
91  const std::valarray<double> &orbit,
92  const std::valarray<double> &derivatives,
93  std::valarray<double> &stop_deriv
94  ) const
95  {
96  std::valarray<double> result(__num_subconditions);
97  stop_deriv.resize(__num_subconditions, Core::NaN);
98  size_t i=0;
99  for(std::vector<StoppingCondition *>::const_iterator
100  cond=__sub_conditions.begin(); cond!=__sub_conditions.end();
101  ++cond)
102  add_subcondition_values(*cond, evol_mode, orbit, derivatives, i,
103  result, stop_deriv);
104  return result;
105  }
106 
107  void CombinedStoppingCondition::reached(short deriv_sign, unsigned index)
108  {
109  std::vector<StoppingCondition *>::iterator sc_iter=find_condition(index);
110  (*sc_iter)->reached(deriv_sign, index);
111  }
112 
114  unsigned index
115  ) const
116  {
117  std::vector<StoppingCondition *>::const_iterator
118  sc_iter = find_condition(index);
119  return (*sc_iter)->expected_crossing_deriv_sign(index);
120  }
121 
122  std::string CombinedStoppingCondition::describe(int index = -1) const
123  {
124  std::ostringstream description;
125  if(index >= 0) {
126  unsigned unsigned_index = index;
127  std::vector<StoppingCondition *>::const_iterator
128  sc_iter = find_condition(unsigned_index);
129  description << (*sc_iter)->describe(unsigned_index);
130  } else {
131  for(
132  std::vector<StoppingCondition *>::const_iterator
133  cond = __sub_conditions.begin();
134  cond != __sub_conditions.end();
135  ++cond
136  )
137  description << (*cond)->describe() << std::endl;
138  }
139  return description.str();
140  }
141 
143  {
144  if(!__delete_subcond) return;
145  for(std::vector<StoppingCondition *>::const_iterator
146  i=__sub_conditions.begin(); i!=__sub_conditions.end(); ++i)
147  delete *i;
148  }
149 
150 } //End Evolve namespace.
151 
virtual void reached(short deriv_sign, unsigned index=0)
See StoppingCondition::reached().
short expected_crossing_deriv_sign(unsigned index=0) const
See StoppingCondition::expected_crossing_deriv_sign().
virtual std::string describe(int index) const
See StoppingCondition::describe().
unsigned __num_subconditions
The number of subconditinos included, allowing for subconditions with multiple entries.
virtual StoppingConditionType type(unsigned index=0) const =0
What event is the index-th stopping sub-condition associated with.
virtual size_t num_subconditions() const
The number of subconditions in the current condition.
Orientations of zones of bodies in a binary system.
std::vector< StoppingConditionType > __types
The types of the subconditinos, including subconditions of subconditions.
void add_subcondition_values(const StoppingCondition *cond, Core::EvolModeType evol_mode, const std::valarray< double > &orbit, const std::valarray< double > &derivatives, size_t &first_index, std::valarray< double > &values, std::valarray< double > &derivs) const
Adds the values of the given sub-condition to the given array.
std::vector< StoppingCondition * >::const_iterator find_condition(unsigned &index) const
Finds the condition corresponding to the given index and modifies the index to be the index within th...
void update_meta_information(const StoppingCondition *rhs)
std::vector< StoppingCondition * > __sub_conditions
The conditions that are combined.
A base class for all stopping conditions.
bool __delete_subcond
Whether to delete the sub-conditions then *this is destroyed.
EvolModeType
The various evolution modes.
Definition: Common.h:42
std::valarray< double > operator()(Core::EvolModeType evol_mode, const std::valarray< double > &orbit, const std::valarray< double > &derivatives, std::valarray< double > &stop_deriv) const
Returns the values of all stopping sub_conditions, not necessarily in the order added.
~CombinedStoppingCondition()
Deletes all subconditions, unless no_delete_subcond has been previously called.
Declares a class for a stopping condition that combines other stopping conditions.
A class combining the the outputs of multiple stopping conditions.
CombinedStoppingCondition & operator|=(CombinedStoppingCondition &rhs)
Adds the conditions in RHS to the conditions of *this.