You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.9 KiB
54 lines
1.9 KiB
#include <catch2/catch_test_macros.hpp> |
|
#include <catch2/matchers/catch_matchers_floating_point.hpp> |
|
#include "../src/physics.h" |
|
#include "../src/simulation.h" |
|
#include "../src/config_loader.h" |
|
#include "../src/test_utilities.h" |
|
#include <cmath> |
|
|
|
using Catch::Matchers::WithinAbs; |
|
|
|
SCENARIO("Orbital period measurement with analytical propagation", |
|
"[period][analytical]") { |
|
const double TIME_STEP = 60.0; |
|
const double SECONDS_PER_DAY = 86400.0; |
|
|
|
SimulationState* sim = create_simulation(10, 0, 0, TIME_STEP); |
|
REQUIRE(load_system_config(sim, "tests/test_orbital_period.toml")); |
|
|
|
auto propagate_and_check = [&](OrbitTracker* tracker, CelestialBody* body, |
|
CelestialBody* parent, double max_time, |
|
double expected_days) { |
|
while (sim->time < max_time && !tracker->orbit_completed) { |
|
update_simulation(sim); |
|
update_orbit_tracker(tracker, body, parent, sim->time); |
|
} |
|
REQUIRE(tracker->orbit_completed); |
|
|
|
const double measured_days = tracker->time_at_completion / SECONDS_PER_DAY; |
|
INFO("Measured period: " << measured_days << " days"); |
|
REQUIRE_THAT(measured_days, WithinAbs(expected_days, 0.1)); |
|
|
|
destroy_orbit_tracker(tracker); |
|
}; |
|
|
|
SECTION("Earth completes one orbit in ~365 days") { |
|
CelestialBody* earth = &sim->bodies[1]; |
|
CelestialBody* sun = &sim->bodies[0]; |
|
OrbitTracker* tracker = create_orbit_tracker(1); |
|
|
|
const double max_time = 400.0 * SECONDS_PER_DAY; |
|
propagate_and_check(tracker, earth, sun, max_time, 365.2105); |
|
} |
|
|
|
SECTION("Mars completes one orbit in ~671 days") { |
|
CelestialBody* mars = &sim->bodies[2]; |
|
CelestialBody* sun = &sim->bodies[0]; |
|
OrbitTracker* tracker = create_orbit_tracker(2); |
|
|
|
const double max_time = 750.0 * SECONDS_PER_DAY; |
|
propagate_and_check(tracker, mars, sun, max_time, 670.9345); |
|
} |
|
} |
|
|
|
|
|
|