Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
SynchronizedCondition.cpp
1 #define BUILDING_LIBRARY
3 #include "BinarySystem.h"
4 #include "DissipatingZone.h"
5 
6 namespace Evolve {
7 
9  int spin_freq_mult,
10  short deriv_sign,
11  bool primary,
12  unsigned zone_index,
13  BinarySystem &system) :
14  StoppingCondition(deriv_sign),
15  __orbital_freq_mult(orbital_freq_mult),
16  __spin_freq_mult(spin_freq_mult),
17  __primary(primary),
18  __zone_index(zone_index),
19  __zone((primary
20  ? system.primary()
21  : system.secondary()).zone(zone_index)),
22  __system(system)
23  {}
24 
25  std::valarray<double> SynchronizedCondition::operator()(
27 #ifndef NDEBUG
28  evol_mode
29 #endif
30  , const std::valarray<double> &orbit,
31  const std::valarray<double> &derivatives,
32  std::valarray<double> &stop_deriv
33  ) const
34  {
35 #ifndef NDEBUG
36  assert(evol_mode == Core::BINARY);
38  assert(orbit[0] == __system.semimajor());
39  else assert(std::pow(std::max(0.0, orbit[0]), 1.0 / 6.5)
40  ==
42  assert(orbit.size() == (1
43  +
45  -
47  assert(orbit.size() == derivatives.size());
48 #endif
49  double m1 = __system.primary().mass(),
50  m2 = __system.secondary().mass(),
51  semimajor = __system.semimajor(),
52  worb = Core::orbital_angular_velocity(m1, m2, semimajor),
53  wspin = __zone.spin_frequency(),
54  dworb_dt = (Core::orbital_angular_velocity(m1,
55  m2,
56  semimajor,
57  true)
58  *
59  derivatives[0]
60  *
62 
63 
64  unsigned angmom_ind = 1 + 2 * __system.number_zones();
65  if(!__primary) angmom_ind += (__system.primary().number_zones()
66  -
68 
69  const DissipatingBody &body = (__primary
70  ? __system.primary()
71  : __system.secondary());
72  for(unsigned i = 0; i < __zone_index; ++i)
73  if(!body.zone(i).locked()) ++angmom_ind;
74 
75  double dwspin_dt = (
76  (derivatives[angmom_ind] - __zone.moment_of_inertia(1) * wspin)
77  /
79  );
80  if(__system.number_locked_zones() == 0)
81  dworb_dt /= 6.5 * orbit[0] / semimajor;
82 
83 #ifdef VERBOSE_DEBUG
84  std::cerr << describe() << " angmom index: " << angmom_ind
85  << " worb = " << worb
86  << " dworb_dt = " << dworb_dt
87  << " wspin = " << wspin
88  << " dwspin_dt = " << dwspin_dt
89  << " adot = " << derivatives[0] / (6.5 * orbit[0] / semimajor)
90  << std::endl;
91 #endif
92 
93  stop_deriv.resize(
94  1,
95  (
96  (wspin * dworb_dt - dwspin_dt * worb)
97  /
98  std::pow(worb, 2)
99  *
101  )
102  );
103 #ifndef NDEBUG
104  if(
105  std::isnan((__orbital_freq_mult * worb - wspin * __spin_freq_mult)
106  /
107  worb)
108  ) {
109  std::cerr << "Synchronized value for zone " << __zone_index << "/"
110  << __system.primary().number_zones() << " for worb=" << worb
111  << ", wspin=" << wspin
112  << ", m'=" << __orbital_freq_mult << ", m="
113  << "__spin_freq_mult is NaN."
114  << ", semimajor=" << semimajor << std::endl ;
115  assert(false);
116  }
117 #endif
118  return std::valarray<double>(
119  (__orbital_freq_mult * worb - wspin * __spin_freq_mult) / worb,
120  1
121  );
122  }
123 
124  void SynchronizedCondition::reached(short deriv_sign, unsigned index)
125  {
126 #ifndef NDEBUG
127  std::cerr << "Synchronization reached: "
128  << "Expected sign: " << expected_crossing_deriv_sign()
129  << "sign: " << deriv_sign
130  << std::endl;
131 #endif
132  StoppingCondition::reached(deriv_sign, index);
133 #ifndef NDEBUG
134  std::cerr << "Now expected sign: " << expected_crossing_deriv_sign()
135  << std::endl;
136 #endif
139  (__primary ? 0 : 1),
140  __zone_index,
141  (__spin_freq_mult>0 ? -deriv_sign : deriv_sign));
142  }
143 
144  std::string SynchronizedCondition::describe(int ) const
145  {
146  std::ostringstream description;
147  description << (__primary ? "Primary" : "Secondary")
148  << " body, zone "
149  << __zone_index
150  << " satisfying "
152  << "(orbital frequency) = "
154  << "(spin frequency)";
155  return description.str();
156  }
157 
158 } //End Evolve namespace.
int __spin_freq_mult
The multiplier in front of the spin frequency in the lock.
BinarySystem & __system
The binary system this locking condition is attached to.
const DissipatingBody & primary() const
Returns the primary body in the system (const).
Definition: BinarySystem.h:836
unsigned number_locked_zones() const
The number of zones currently in a spin-orbit lock.
Declares a class representing one zone of a body dissipative to tidal distortions.
SynchronizedCondition(int orbital_freq_mult, int spin_freq_mult, short deriv_sign, bool primary, unsigned zone_index, BinarySystem &system)
Create the synchronization condition for the given planet.
virtual std::string describe(int index=-1) const
See StoppingCondition::describe().
A base class for any body contributing to tidal dissipation.
int __orbital_freq_mult
The mutiplier in front of the orbital frequency in the lock.
virtual const DissipatingZone & zone(unsigned zone_index) const =0
A modifiable reference to one of the body&#39;s zones.
void check_for_lock(int orbital_freq_mult, int spin_freq_mult, unsigned short body_index, unsigned zone_index, short direction)
Check if a spin-orbit lock can be held and updates the system as necessary to calculate subsequent ev...
const DissipatingZone & __zone
The zone whose spin is monitored.
Orientations of zones of bodies in a binary system.
virtual double moment_of_inertia(int deriv_order=0) const =0
Moment of inertia of the zone or its age derivative at the age of last configure() call...
double mass() const
The mass of the body (constant with age).
bool __primary
Which body&#39;s spin is checked for locking.
const double solar_radius
Radius of the sun [m].
unsigned number_locked_zones() const
How many zones on either body are currently locked.
Definition: BinarySystem.h:848
const DissipatingBody & secondary() const
Returns the secondary body in the system (const).
Definition: BinarySystem.h:839
virtual short expected_crossing_deriv_sign(unsigned index=0) const
The expected sign of the derivative at the next zero-crossing.
A base class for all stopping conditions.
Defines the BinarySystem class.
virtual bool locked(int orbital_frequency_multiplier, int spin_frequency_multiplier) const
Should return true iff the given term is presently locked.
void reached(short deriv_sign, unsigned index=0)
Which body&#39;s spin is checked for locking.
EvolModeType
The various evolution modes.
Definition: Common.h:42
unsigned __zone_index
Which zone is checked for locking.
double semimajor() const
The current semimajor axis of the system.
Definition: BinarySystem.h:852
std::valarray< double > operator()(Core::EvolModeType evol_mode, const std::valarray< double > &orbit, const std::valarray< double > &derivatives, std::valarray< double > &stop_deriv) const
Return the difference between the orbital and multiplier scaled stellar spin angular velocities divid...
unsigned number_zones() const
The total number of zones in both system bodies.
Definition: BinarySystem.h:842
Describes a system of two bodies orbiting each other.
Definition: BinarySystem.h:56
double spin_frequency() const
The spin frequency of the given zone.
virtual unsigned number_zones() const =0
The number of zones the body consists of.
Declares a stopping condition monitoring spin-orbit synchronization.
virtual void reached(short deriv_sign, unsigned index=0)
Called when a stopping condition has been reached by the evolution.