diff --git a/CMakeLists.txt b/CMakeLists.txt index 09d24c8..fa64595 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ if(${CMAKE_VERSION} VERSION_LESS 3.12) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) endif() -project(gravity VERSION 0.2.0 +project(gravity VERSION 0.4.0 DESCRIPTION "N-Body-Problem project of https://thoughts-on-cpp.com" LANGUAGES CXX) diff --git a/solver/src/particle.cpp b/solver/src/particle.cpp index 15b4f49..655dd20 100644 --- a/solver/src/particle.cpp +++ b/solver/src/particle.cpp @@ -2,6 +2,7 @@ #include #include #include +#include size_t Particle::IDCounter = 0; @@ -12,6 +13,7 @@ Particle::Particle() Particle::Particle(double mass, const Vector2D &acceleration, const Vector2D &velocity, const Vector2D &position) : mass(mass), acceleration(acceleration), velocity(velocity), position(position) { + assert(mass > 0); id = IDCounter++; } diff --git a/solver/src/solver.cpp b/solver/src/solver.cpp index cb6623d..249c8ab 100644 --- a/solver/src/solver.cpp +++ b/solver/src/solver.cpp @@ -3,6 +3,7 @@ #include #include #include +#include const double Solver::G = 6.67408e-11; @@ -76,6 +77,8 @@ Particle Solver::AccumulateAcceleration(const std::vector &particles, double Solver::CalculateEquivalentMass(const Particle &particleA, const Particle &particleB) { const double massA = particleA.getMass(); + assert(massA > 0); + const double massB = particleB.getMass(); return massA*massB/massA; diff --git a/solver/src/types.cpp b/solver/src/types.cpp index 63f6f69..72b4fd2 100644 --- a/solver/src/types.cpp +++ b/solver/src/types.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include bool Vector2D::operator==(const Vector2D &rhs) const { diff --git a/solverTest/src/solverTest.cpp b/solverTest/src/solverTest.cpp index 81c79ee..eb8f024 100644 --- a/solverTest/src/solverTest.cpp +++ b/solverTest/src/solverTest.cpp @@ -70,18 +70,43 @@ TEST_CASE("Benchmarking euler", "[benchmark]") { particles = solver.solve(particles); } - particles = particleBuilder.build(1000); - BENCHMARK("Benchmarking with 1000 particles") { + particles = particleBuilder.build(200); + BENCHMARK("Benchmarking with 200 particles") { particles = solver.solve(particles); } - particles = particleBuilder.build(10000); - BENCHMARK("Benchmarking with 10K particles") { + particles = particleBuilder.build(400); + BENCHMARK("Benchmarking with 400 particles") { particles = solver.solve(particles); } - particles = particleBuilder.build(100000); - BENCHMARK("Benchmarking with 100K particles") { + particles = particleBuilder.build(800); + BENCHMARK("Benchmarking with 800 particles") { + particles = solver.solve(particles); + } + + particles = particleBuilder.build(1600); + BENCHMARK("Benchmarking with 1.6K particles") { + particles = solver.solve(particles); + } + + particles = particleBuilder.build(3200); + BENCHMARK("Benchmarking with 3.2K particles") { + particles = solver.solve(particles); + } + + particles = particleBuilder.build(6400); + BENCHMARK("Benchmarking with 6.4K particles") { + particles = solver.solve(particles); + } + + particles = particleBuilder.build(12800); + BENCHMARK("Benchmarking with 12.8K particles") { + particles = solver.solve(particles); + } + + particles = particleBuilder.build(25600); + BENCHMARK("Benchmarking with 25.6K particles") { particles = solver.solve(particles); } } \ No newline at end of file