#include #include "../src/physics.h" #include "../src/bodies.h" #include "../src/test_utilities.h" #include TEST_CASE("Energy conservation - Earth circular orbit", "[energy][rk4]") { const double TIME_STEP = 60.0; const double DAYS_TO_SIMULATE = 10.0; const double SECONDS_PER_DAY = 86400.0; SimulationState* sim = create_simulation(10, TIME_STEP); Vec3 sun_pos = {0, 0, 0}; Vec3 sun_vel = {0, 0, 0}; add_body(sim, "Sun", 1.989e30, 6.96e8, sun_pos, sun_vel, -1, 1.0, 1.0, 0.0, 0, 0); Vec3 earth_pos = {1.496e11, 0, 0}; Vec3 earth_vel = {0, 29800, 0}; add_body(sim, "Earth", 5.972e24, 6.371e6, earth_pos, earth_vel, 0, 0.0, 0.5, 1.0, 0, 1.496e11); double initial_energy = calculate_system_total_energy(sim); double total_time = DAYS_TO_SIMULATE * SECONDS_PER_DAY; while (sim->time < total_time) { update_simulation(sim); } double final_energy = calculate_system_total_energy(sim); double energy_drift_percent = fabs((final_energy - initial_energy) / initial_energy) * 100.0; INFO("Initial energy: " << initial_energy << " J"); INFO("Final energy: " << final_energy << " J"); INFO("Energy drift: " << energy_drift_percent << "%"); REQUIRE(energy_drift_percent < 5.0); destroy_simulation(sim); }