Skip to content

Commit

Permalink
Finalizing v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben1980 committed Mar 5, 2019
1 parent 9ac38d4 commit 09062c6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions solver/src/particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <random>
#include <functional>
#include <chrono>
#include <cassert>

size_t Particle::IDCounter = 0;

Expand All @@ -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++;
}

Expand Down
3 changes: 3 additions & 0 deletions solver/src/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cmath>
#include <algorithm>
#include <solver.h>
#include <cassert>


const double Solver::G = 6.67408e-11;
Expand Down Expand Up @@ -76,6 +77,8 @@ Particle Solver::AccumulateAcceleration(const std::vector<Particle> &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;
Expand Down
2 changes: 1 addition & 1 deletion solver/src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <cmath>
#include <types.h>
#include <assert.h>
#include <cassert>
#include <limits>

bool Vector2D::operator==(const Vector2D &rhs) const {
Expand Down
37 changes: 31 additions & 6 deletions solverTest/src/solverTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 09062c6

Please sign in to comment.