From aebd3c2acbb0c86d2e13dea35e8e0031c80c4888 Mon Sep 17 00:00:00 2001 From: FG-TUM Date: Fri, 18 Feb 2022 18:05:59 +0100 Subject: [PATCH 1/3] fix tests where particles are too far apart to collide --- tests/testladds/CollisionFunctorTest.cpp | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/testladds/CollisionFunctorTest.cpp b/tests/testladds/CollisionFunctorTest.cpp index a18de51e..a11fb1c3 100644 --- a/tests/testladds/CollisionFunctorTest.cpp +++ b/tests/testladds/CollisionFunctorTest.cpp @@ -16,22 +16,23 @@ * The functor is expected to identify a collision between each particle and its direct neighbors. */ TEST(CollisionFunctorTest, ThreeParticles) { - constexpr double cutoff{1.5}; + constexpr double cutoff{1}; constexpr bool newton3{false}; constexpr size_t numDebris{3}; std::vector debris; debris.reserve(numDebris); - // Add three particles in a row on the X axis separated by 1 + // Add three particles with radius .6m in a row on the X axis separated by 1 m + // => direct neighbors overlap for (size_t i = 0; i < numDebris; ++i) { - debris.emplace_back(std::array{static_cast(i), 0., 0.}, + debris.emplace_back(std::array{static_cast(i) / 1000., 0., 0.}, std::array{0., static_cast(i), 0.}, i, "dummy", Particle::ActivityState::passive, 1., - 1., + .6, Particle::calculateBcInv(0., 1., 1., 2.2)); } @@ -49,8 +50,8 @@ TEST(CollisionFunctorTest, ThreeParticles) { auto collisions = collisionFunctor.getCollisions(); decltype(collisions) expected{ - {&debris[0], &debris[1], 1.0}, - {&debris[1], &debris[2], 1.0}, + {&debris[0], &debris[1], 1.0 / (1000 * 1000)}, // convert distance to km^2 + {&debris[1], &debris[2], 1.0 / (1000 * 1000)}, // convert distance to km^2 }; EXPECT_THAT(collisionFunctor.getCollisions(), ::testing::UnorderedElementsAreArray(expected)); @@ -199,7 +200,7 @@ TEST(CollisionFunctorTest, MixActivityStates) { } /** - * Two particles each with radius 1 are placed at a distance of 3. + * Two particles each with radius 1 are placed at a distance of 3 m. * Using collisionDistanceFactor 1 they should not be considered colliding, using 2 they should. */ TEST(CollisionFunctorTest, CollisionDistanceFactorTest) { @@ -217,7 +218,7 @@ TEST(CollisionFunctorTest, CollisionDistanceFactorTest) { particleMass, particleRadius, Particle::calculateBcInv(0., particleMass, particleRadius, 2.2)}, - {{3., 0., 0.}, + {{3. / 1000, 0., 0.}, {-1., 0., 0.}, 2, "B", @@ -233,10 +234,12 @@ TEST(CollisionFunctorTest, CollisionDistanceFactorTest) { collisionFunctor.endTraversal(newton3); if (collisionDistanceFactor == 1.) { // distance too far -> no collisions - EXPECT_EQ(collisionFunctor.getCollisions().size(), 0); + EXPECT_EQ(collisionFunctor.getCollisions().size(), 0) + << "For collisionDistanceFactor: " << collisionDistanceFactor; } else if (collisionDistanceFactor == 2.) { // over approximation should now include particles -> collision - EXPECT_EQ(collisionFunctor.getCollisions().size(), 1); + EXPECT_EQ(collisionFunctor.getCollisions().size(), 1) + << "For collisionDistanceFactor: " << collisionDistanceFactor; } else { GTEST_FAIL() << "Unexpected collisionDistanceFactor: " << collisionDistanceFactor; } @@ -247,11 +250,11 @@ TEST_P(CollisionFunctorTest, LinearInterpolationTest) { constexpr double cutoff{80.0}; constexpr bool newton3{false}; constexpr size_t numDebris{2}; - constexpr double particleRadius{1.}; + constexpr double particleRadius{1000.}; const auto &[x1, x2, v1, v2, dt, expected_dist] = GetParam(); - CollisionFunctor collisionFunctor(cutoff, dt, 10., 0.1); + CollisionFunctor collisionFunctor(cutoff, dt, 1., 0.1); std::vector debris; debris.reserve(numDebris); @@ -293,6 +296,7 @@ TEST_P(CollisionFunctorTest, LinearInterpolationTest) { // Generate tests for all configuration combinations INSTANTIATE_TEST_SUITE_P(Generated, CollisionFunctorTest, + // x1 [km], x2 [km], v1 [km/s], v2 [km/2], dt [s], squared expected_dist [km^2] testing::ValuesIn({std::make_tuple(std::array{0., 1., 2.}, std::array{2., 4., 6.}, std::array{0., 0., 0.}, From 1d16be88bb6162472242453f54ac3634410548e5 Mon Sep 17 00:00:00 2001 From: FG-TUM Date: Fri, 18 Feb 2022 18:07:12 +0100 Subject: [PATCH 2/3] clarify that this is a squared distance --- tests/testladds/CollisionFunctorTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testladds/CollisionFunctorTest.cpp b/tests/testladds/CollisionFunctorTest.cpp index a11fb1c3..b8e6f7c4 100644 --- a/tests/testladds/CollisionFunctorTest.cpp +++ b/tests/testladds/CollisionFunctorTest.cpp @@ -252,7 +252,7 @@ TEST_P(CollisionFunctorTest, LinearInterpolationTest) { constexpr size_t numDebris{2}; constexpr double particleRadius{1000.}; - const auto &[x1, x2, v1, v2, dt, expected_dist] = GetParam(); + const auto &[x1, x2, v1, v2, dt, squaredExpectedDist] = GetParam(); CollisionFunctor collisionFunctor(cutoff, dt, 1., 0.1); @@ -276,7 +276,7 @@ TEST_P(CollisionFunctorTest, LinearInterpolationTest) { auto collisions = collisionFunctor.getCollisions(); - decltype(collisions) expected{{&debris[0], &debris[1], expected_dist}}; + decltype(collisions) expected{{&debris[0], &debris[1], squaredExpectedDist}}; // helper function for debugging output auto getIDsStringFromPointers = [](const auto &collisions) { From 7a8faa13b166a3bbbc8b2104f2260d1f7fb8fdac Mon Sep 17 00:00:00 2001 From: FG-TUM Date: Fri, 18 Feb 2022 18:20:53 +0100 Subject: [PATCH 3/3] collisionDistanceFactor > 1 to actually cover all conjunctions --- tests/testladds/CollisionFunctorTest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testladds/CollisionFunctorTest.cpp b/tests/testladds/CollisionFunctorTest.cpp index b8e6f7c4..3e04b9ce 100644 --- a/tests/testladds/CollisionFunctorTest.cpp +++ b/tests/testladds/CollisionFunctorTest.cpp @@ -254,7 +254,8 @@ TEST_P(CollisionFunctorTest, LinearInterpolationTest) { const auto &[x1, x2, v1, v2, dt, squaredExpectedDist] = GetParam(); - CollisionFunctor collisionFunctor(cutoff, dt, 1., 0.1); + // collisionDistanceFactor > 1 to actually cover all conjunctions + CollisionFunctor collisionFunctor(cutoff, dt, 10., 0.1); std::vector debris; debris.reserve(numDebris);