12 const double epsilon = std::numeric_limits<double>::epsilon();
22 double orbital_frequency,
40 std::ostringstream &message
55 std::ostringstream &message
72 double orbital_frequency,
73 double spin_frequency,
79 std::ostringstream message;
80 message <<
"For Worb = " << orbital_frequency
81 <<
", W* = " << spin_frequency
82 <<
", should monitor ";
87 message <<
". auto selected terms to monitor: ";
102 expected_lock_below.
term(
114 message.str().c_str()
118 expected_lock_above.
term(
130 message.str().c_str()
138 std::cerr.precision(19);
140 if(range.first < 0) {
141 return range.first * (1.0 - epsilon);
142 }
else if(range.first == 0)
145 return range.first * (1.0 + epsilon);
146 }
else if(position == 1)
147 return 0.5 * (range.first + range.second);
150 return range.second * (1.0 + epsilon);
151 else if(range.second == 0)
154 return range.second * (1.0 - epsilon);
160 double lock_set_orbital_frequency,
161 double lock_set_spin_frequency,
162 double test_orbital_frequency,
163 std::pair<double, double> test_spin_frequency_range,
164 int orbital_frequency_multiplier,
165 int spin_frequency_multiplier,
166 int expected_correction
170 lock_set_spin_frequency);
172 for(
unsigned spin_choice = 0; spin_choice <= 2; ++spin_choice) {
173 double test_spin_frequency =
sample_range(test_spin_frequency_range,
177 std::numeric_limits<double>::quiet_NaN(),
184 double expected_tidal_frequency = (
185 expected_correction == 0
187 orbital_frequency_multiplier * test_orbital_frequency
189 spin_frequency_multiplier * test_spin_frequency
191 : expected_correction * epsilon
194 orbital_frequency_multiplier,
195 spin_frequency_multiplier,
196 test_orbital_frequency
199 std::ostringstream message;
200 message.precision(19);
201 message <<
"With zone locks: ";
203 message <<
", Wtide(m=" << spin_frequency_multiplier
204 <<
", s=" << orbital_frequency_multiplier
205 <<
") for Worb = " << test_orbital_frequency
206 <<
", W* = " << test_spin_frequency
207 <<
" is " << calculated_tidal_frequency
208 <<
" instead of " << expected_tidal_frequency;
210 if(expected_correction == 0) {
211 double difference = (expected_tidal_frequency
213 calculated_tidal_frequency);
214 message <<
", difference (expected - got): " << difference <<
".";
217 std::abs(difference) < 1e-14
220 expected_tidal_frequency
222 calculated_tidal_frequency
227 expected_tidal_frequency == 0
229 calculated_tidal_frequency == 0
233 message.str().c_str()
238 calculated_tidal_frequency == expected_tidal_frequency,
239 message.str().c_str()
247 int lower_lock_orbital_freuqency_multiplier,
248 double orbital_frequency
252 double lock_set_spin_frequency = (
255 0.5 * lower_lock_orbital_freuqency_multiplier
256 ) * orbital_frequency;
258 int spin_range_s = -3*expansion_order;
259 spin_range_s <= 3*expansion_order;
262 for(
int test_m = -2; test_m <= 2; test_m += 1) {
264 int test_s = -expansion_order;
265 test_s <= expansion_order;
268 std::pair<double, double> spin_frequency_range(
269 (0.5 * spin_range_s) * orbital_frequency,
270 0.5 * (spin_range_s + 1) * orbital_frequency
272 int expected_correction = 0;
274 int scaled_test_s = 2 * test_s / test_m;
279 lower_lock_orbital_freuqency_multiplier
283 scaled_test_s <= spin_range_s
286 expected_correction = boost::math::sign(test_m);
292 lower_lock_orbital_freuqency_multiplier
301 expected_correction = -boost::math::sign(test_m);
306 lock_set_spin_frequency,
308 spin_frequency_range,
323 std::vector<double>(),
324 std::vector<double>(),
325 std::vector<double>(1, 0.0),
326 std::vector<double>(1, 0.0),
393 const int expansion_order = 10;
395 int orbital_frequency_multiplier = -3 * expansion_order;
396 orbital_frequency_multiplier <= 3 * expansion_order;
397 ++orbital_frequency_multiplier
400 orbital_frequency_multiplier,
void test_tidal_frequency_fix()
Test fix applied to the tidal frequency of tidal term(s) matching lower boundary lock.
void check_monitored_locks(double orbital_frequency, double spin_frequency, const SpinOrbitLockInfo &expected_lock_below, const SpinOrbitLockInfo &expected_lock_above)
Verify a single expectation of what locks would be monitored in a given situation.
const SpinOrbitLockInfo & lock_monitored(bool other=false) const
Useful for debugging.
int orbital_frequency_multiplier() const
The multiplier in front of the orbital frequency in the lock.
virtual void change_e_order(unsigned new_e_order, BinarySystem &system, bool primary, unsigned zone_index)
Changes the order of the eccentricity expansion performed.
Single zone non-evolving planets with huge dissipation, so they always remain locked to the disk...
Orientations of zones of bodies in a binary system.
void set_orbital_spin_frequeqncy(double orbital_frequency, double spin_frequency)
Change the orbital and spin frequencies for __zone.
void check_tidal_frequency_range(double lock_set_orbital_frequency, double lock_set_spin_frequency, double test_orbital_frequency, std::pair< double, double > test_spin_frequency_range, int orbital_frequency_multiplier, int spin_frequency_multiplier, int expected_correction)
Verify a single expectation for fixing of a tidal term in a given situation over a range of spin freq...
test_LockMonitoring()
Create the test suite.
int spin_frequency_multiplier() const
The multiplier in front of the spin frequency in the lock.
short lock_direction() const
Planet::PlanetZone __zone
A dissipative zone to run the tests on.
void add_zone_locks_to_message(std::ostringstream &message)
void check_unlocked_tidal_frequency(int expansion_order, int lower_lock_orbital_freuqency_multiplier, double orbital_frequency)
Check that lock-corrected tidal frequency reproduces expectations for a single set of monitored locks...
void configure(bool initialize, double age, double orbital_frequency, double eccentricity, double orbital_angmom, double spin, double inclination, double periapsis, bool spin_is_frequency)
Calls the usual DissipatingZone::configure but with zero inclination and periapsis.
double sample_range(std::pair< double, double > range, unsigned position)
Pick a just inside each boundary or in the middle of a range.
bool term(int orbital_freq_mult, int spin_freq_mult) const
void set_expansion_order(int max_orbital_multiplier)
Change the order of the tidal potential expansion used by __zone.
Unit tests that check the machinery for monitoring potential tidal locks.
double forcing_frequency(int orbital_frequency_multiplier, int spin_frequency_multiplier, double orbital_frequency) const
The tidal forcing frequency for the given term and orbital frequency.
void test_lock_init()
Test whether the correct tidal terms are selected for lock monitoring when and.
void add_locks_to_message(const SpinOrbitLockInfo &lock_below, const SpinOrbitLockInfo &lock_above, std::ostringstream &message)
Add information about the given locks relative to the tidal frequency to the test message...
Describes a system of two bodies orbiting each other.
Defines a lock between the spin of a dissipating body and the orbit.
void setup(const std::vector< double > &tidal_frequency_breaks, const std::vector< double > &spin_frequency_breaks, const std::vector< double > &tidal_frequency_powers, const std::vector< double > &spin_frequency_powers, double reference_phase_lag, double inertial_mode_enhancement=1.0, double inertial_mode_sharpness=10.0)
Seup the zone with the given breaks/powers and inertial mode enhancement. Continuous accress all brea...