Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
testGravitationalPotential.cpp
Go to the documentation of this file.
1 
9 
10 namespace Evolve {
11 
13  const EccentricOrbit &orbit
14  ) const
15  {
16  std::cout << std::setw(25) << "phase"
17  << std::setw(25) << "x"
18  << std::setw(25) << "y"
19  << std::setw(25) << "z"
20  << std::endl;
21  for(double phase = 0.0; phase < 4.0 * M_PI; phase += 0.001 * M_PI) {
22  Eigen::Vector3d secondary_position = orbit.secondary_position(phase);
23  std::cout << std::setw(25) << phase
24  << std::setw(25) << secondary_position[0]
25  << std::setw(25) << secondary_position[1]
26  << std::setw(25) << secondary_position[2]
27  << std::endl;
28  }
29  }
30 
32  double primary_mass,
33  double secondary_mass,
34  double semimajor,
35  double eccentricity,
36  double inclination,
37  double arg_of_periapsis,
38  const Eigen::Vector3d &position,
39  unsigned e_order
40  ) const
41  {
42  TidalPotential exact_potential(primary_mass,
43  secondary_mass,
44  semimajor,
45  eccentricity,
46  inclination,
47  arg_of_periapsis);
48  TidalPotentialExpansion approx_potential(primary_mass,
49  secondary_mass,
50  semimajor,
51  eccentricity,
52  inclination,
53  arg_of_periapsis);
54  approx_potential.set_eccentricity_order(e_order);
55 
56 
57  double orbital_period = exact_potential.orbit().orbital_period();
58  std::ostringstream Uexact_label, Uapprox_label;
59  Uexact_label << "Uexact("
60  << "x=" << position[0]
61  << ", y=" << position[1]
62  << ", z=" << position[2]
63  << ", t=time)";
64  Uapprox_label << "Uapprox("
65  << "x=" << position[0]
66  << ", y=" << position[1]
67  << ", z=" << position[2]
68  << ", t=time)";
69  std::cout << std::setw(35) << "time/Porb"
70  << std::setw(35) << Uexact_label.str()
71  << std::setw(35) << Uapprox_label.str()
72  << std::endl;
73  for(
74  double time = 0;
75  time < 5.0 * orbital_period;
76  time += 0.01 * orbital_period
77  ) {
78  std::cout << std::setw(35) << time/orbital_period
79  << std::setw(35) << exact_potential(position, time)
80  << std::setw(35) << approx_potential(position, time)
81  << std::endl;
82  }
83  }
84 
85 
87  const Eigen::Vector3d &position,
88  const EccentricOrbit &orbit
89  ) const
90  {
91  const double safety = 1.1;
92  return safety * (
93  (
95  *
97  /
98  (
100  *
101  (1.0 - orbit.eccentricity())
102  )
103  )
104  *
105  std::pow(
106  (
107  position.norm()
108  /
109  (orbit.semimajor() * (1.0 - orbit.eccentricity()))
110  ),
111  3
112  )
113  );
114  }
115 
117  TidalPotentialExpansion &approx_potential,
118  const TidalPotential &exact_potential,
119  const Eigen::Vector3d &position
120  )
121  {
122  double orbital_period = exact_potential.orbit().orbital_period(),
123  abs_tolerance = abs_expected_precision(position,
124  exact_potential.orbit());
125 
126  std::ostringstream message_start;
127  message_start << "M = " << exact_potential.orbit().primary_mass()
128  << "; M' = " << exact_potential.orbit().secondary_mass()
129  << "; a = " << exact_potential.orbit().semimajor()
130  << "; e = " << exact_potential.orbit().eccentricity()
131  << "; inclination = " << exact_potential.inclination()
132  << "; periapsis = " << exact_potential.arg_of_periapsis()
133  << "; U(x = " << position[0]
134  << ", y = " << position[1]
135  << ", z = " << position[2];
136 
137  for(
138  double time = 0;
139  time < 5.0 * orbital_period;
140  time += 0.03 * M_PI * orbital_period
141  ) {
142  double expected = exact_potential(position, time);
143  double got = approx_potential(position, time);
144 
145  std::ostringstream message;
146  message << message_start.str()
147  << ", t = " << time
148  << " = " << time / orbital_period
149  << " Porb): expected " << expected
150  << "; got " << got
151  << "; difference " << got - expected
152  << " > " << abs_tolerance;
153 
154  TEST_ASSERT_MSG(
155  check_diff(got,
156  expected,
157  0.0,
158  abs_tolerance),
159  message.str().c_str()
160  );
161  }
162  }
163 
165  double primary_mass,
166  double secondary_mass,
167  double semimajor,
168  double eccentricity,
169  double inclination,
170  double arg_of_periapsis,
171  unsigned e_order
172  )
173  {
174  TidalPotential exact_potential(primary_mass,
175  secondary_mass,
176  semimajor,
177  eccentricity,
178  inclination,
179  arg_of_periapsis);
180  TidalPotentialExpansion approx_potential(primary_mass,
181  secondary_mass,
182  semimajor,
183  eccentricity,
184  inclination,
185  arg_of_periapsis);
186  approx_potential.set_eccentricity_order(e_order);
187 
188  double test_offsets[]= {-0.01, -0.001, 0.0, 0.001, 0.01};
189  unsigned num_offsets = sizeof(test_offsets) / sizeof(double);
190  for(unsigned z_index = 0; z_index < num_offsets; ++z_index)
191  for(unsigned y_index = 0; y_index < num_offsets; ++y_index)
192  for(unsigned x_index = 0; x_index < num_offsets; ++x_index) {
193  test_single_point(approx_potential,
194  exact_potential,
195  Eigen::Vector3d(test_offsets[x_index],
196  test_offsets[y_index],
197  test_offsets[z_index]));
198  }
199  }
200 
202  {
203  double test_angles[] = {-M_PI/2, -1.0, -0.1, 0.0, 0.1, 1.0, M_PI/2};
204  unsigned num_angles = sizeof(test_angles) / sizeof(double);
205  for(
206  double e = 0.0;
207  e <= 0.55;
208  e += 0.1
209  ) {
210  unsigned e_order = 0;
211  if(e > 0.05) e_order = 10;
212  if(e > 0.25) e_order = 20;
213  if(e > 0.45) e_order = 35;
214  std::cout << "Eccentricity : " << e << std::endl;
215 
216  for(
217  unsigned inclination_i = 0;
218  inclination_i < num_angles;
219  ++inclination_i
220  ) {
221  for(
222  unsigned periapsis_i = 0;
223  periapsis_i < num_angles;
224  ++periapsis_i
225  ) {
226  test_system(1.0,
227  0.1,
228  M_PI,
229  e,
230  test_angles[inclination_i],
231  2.0 * test_angles[periapsis_i],
232  e_order);
233  }
234  }
235  }
236  }
237 
239  {
241  }
242 
243 } //End Evolve namespace.
Basic description of two bodies in an eccentric orbit.
void test_single_point(TidalPotentialExpansion &approx_potential, const TidalPotential &exact_potential, const Eigen::Vector3d &position)
Test the expansion for a given system at a given position, sampling time.
Unit tests that check the expansion of the gravitational potential vs. analytic expressions.
void print_tidal_potential(double primary_mass, double secondary_mass, double semimajor, double eccentricity, double inclination, double arg_of_periapsis, const Eigen::Vector3d &position, unsigned e_order) const
Print to stdout the value of the tidal potential without an approximation and using the expansion as ...
double inclination() const
See __inclination attribute.
void test_expansion()
Test the expansion of the potential for multiple system configurations, locations and times...
Evaluate the tidal potential using the expansion.
double arg_of_periapsis() const
The argument of periapsis of the system.
double eccentricity() const
The semimajor axis of the system.
double semimajor() const
The semimajor axis of the system.
Orientations of zones of bodies in a binary system.
double abs_expected_precision(const Eigen::Vector3d &position, const EccentricOrbit &orbit) const
const double solar_radius
Radius of the sun [m].
double primary_mass() const
The semimajor axis of the system.
void test_system(double primary_mass, double secondary_mass, double semimajor, double eccentricity, double inclination, double arg_of_periapsis, unsigned e_order=0)
Test the expansion for a given system, sampling positions and times.
bool check_diff(double x, double y, double frac_tolerance, double abs_tolerance)
Returns true iff .
Definition: Common.cpp:3
const double solar_mass
Mass of the sun [kg].
Calculate the tidal potential over one component of an eccentric binary.
const EccentricOrbit & orbit() const
An unmutable reference to the binary orbit.
void print_orbit(const EccentricOrbit &orbit) const
Print to stdout the location of the secondary relative to the primary as a function of time for the g...
double orbital_period() const
The orbital period of the system in days.
Eigen::Vector3d secondary_position(double orbital_phase) const
Secondary position vector in a coordinate system centered on the primary, with and ...
double secondary_mass() const
The semimajor axis of the system.
const double G
Gravitational constant in SI.