diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/core/c++/particle/particle.hpp | 14 | ||||
| -rw-r--r-- | lib/core/tests/particles.cpp (renamed from lib/core/tests/particles.dummy) | 71 |
2 files changed, 75 insertions, 10 deletions
diff --git a/lib/core/c++/particle/particle.hpp b/lib/core/c++/particle/particle.hpp index b647ebe..3089378 100644 --- a/lib/core/c++/particle/particle.hpp +++ b/lib/core/c++/particle/particle.hpp @@ -51,7 +51,7 @@ constexpr auto verlet_step_lambda = [](saw::data<sch::Particle<T,D>>& particle, auto& pos = body.template get<"position">(); auto& pos_old = body.template get<"position_old">(); - // auto& rot = body.template get<"rotation">(); + auto& rot = body.template get<"rotation">(); auto& acc = body.template get<"acceleration">(); auto tsd_squared = time_step_delta * time_step_delta; @@ -70,7 +70,7 @@ constexpr auto verlet_step_lambda = [](saw::data<sch::Particle<T,D>>& particle, * * */ -template<typename T, uint64_t> +template<typename T, uint64_t D> constexpr auto broadphase_collision_check = [](saw::data<sch::Particle<T,D>>& left, saw::data<sch::Particle<T,D>>& right){ auto rad_l = left.template get<"collision">().template get<"radius">(); auto rad_r = right.template get<"collision">().template get<"radius">(); @@ -80,7 +80,15 @@ constexpr auto broadphase_collision_check = [](saw::data<sch::Particle<T,D>>& le auto& pos_l = rb_l.template get<"position">(); auto& pos_r = rb_r.template get<"position">(); -} + + auto pos_dist = pos_l - pos_r; + + auto norm_2 = saw::math::dot(pos_dist,pos_dist); + + auto rad_ab_2 = rad_l * rad_l + rad_r * rad_r + rad_r * rad_l * static_cast<saw::native_data_type<T>::type>(2); + + return (norm_2.at({}).get() < rad_ab_2.get()); +}; template<typename T, uint64_t D, typename ParticleCollision = sch::ParticleMask<T,D> > class particle_system { diff --git a/lib/core/tests/particles.dummy b/lib/core/tests/particles.cpp index cbbeefa..0806375 100644 --- a/lib/core/tests/particles.dummy +++ b/lib/core/tests/particles.cpp @@ -2,7 +2,8 @@ #include <iostream> //#include "../c++/particle/geometry/circle.hpp" - +#include "../c++/particle/particle.hpp" +#include <forstio/codec/data.hpp> namespace { namespace sch { @@ -11,10 +12,8 @@ using namespace kel::lbm::sch; using T = Float64; } SAW_TEST("Verlet step 2D - Planar"){ -/* using namespace kel; - saw::data<sch::Particle<sch::T,2u>> particle; auto& body = particle.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -29,14 +28,72 @@ SAW_TEST("Verlet step 2D - Planar"){ SAW_EXPECT(pos.at({{0}}).get() == 0.25, std::string{"Incorrect Pos X: "} + std::to_string(pos.at({{0}}).get())); SAW_EXPECT(pos.at({{1}}).get() == 0.0, std::string{"Incorrect Pos Y: "} + std::to_string(pos.at({{1}}).get())); -*/ } -SAW_TEST("Collision spheroid Test"){ +SAW_TEST("No Collision Spheroid 2D"){ + using namespace kel; + + saw::data<sch::Particle<sch::T,2u>> part_a; + { + auto& body = part_a.template get<"rigid_body">(); + auto& pos = body.template get<"position">(); + auto& coll = part_a.template get<"collision">(); + auto& radius = coll.template get<"radius">(); + + radius.set(1.0); + + pos.at({{0u}}) = 0.1; + pos.at({{1u}}) = 0.2; + + } + saw::data<sch::Particle<sch::T,2u>> part_b; + { + auto& body = part_b.template get<"rigid_body">(); + auto& pos = body.template get<"position">(); + auto& coll = part_b.template get<"collision">(); + auto& radius = coll.template get<"radius">(); + + radius.set(1.0); + + pos.at({{0u}}) = -2.1; + pos.at({{1u}}) = 0.0; + } + + bool have_collided = lbm::broadphase_collision_check<sch::T,2u>(part_a,part_b); + SAW_EXPECT(not have_collided, "Particles shouldn't collide"); +} + +SAW_TEST("Collision Spheroid 2D"){ using namespace kel; - saw::data<sch::Particle<sch::T,2u> part_a; - saw::data<sch::Particle<sch::T,2u> part_b; + saw::data<sch::Particle<sch::T,2u>> part_a; + { + auto& body = part_a.template get<"rigid_body">(); + auto& pos = body.template get<"position">(); + auto& coll = part_a.template get<"collision">(); + auto& radius = coll.template get<"radius">(); + + radius.set(1.0); + + pos.at({{0u}}) = 0.1; + pos.at({{1u}}) = 0.2; + + } + saw::data<sch::Particle<sch::T,2u>> part_b; + { + auto& body = part_b.template get<"rigid_body">(); + auto& pos = body.template get<"position">(); + auto& coll = part_b.template get<"collision">(); + auto& radius = coll.template get<"radius">(); + + radius.set(1.0); + + pos.at({{0u}}) = -1.5; + pos.at({{1u}}) = 0.0; + } + + bool have_collided = lbm::broadphase_collision_check<sch::T,2u>(part_a,part_b); + SAW_EXPECT(have_collided, "Particles should collide"); } /* |
