From eeb01452fe46fcb5efdc9c34b660305262097ca4 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 10 Dec 2025 11:26:13 +0100 Subject: Dangling changes --- lib/core/c++/particle/particle.hpp | 22 ++++++++++++++++++++++ lib/core/tests/particles.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) (limited to 'lib/core') diff --git a/lib/core/c++/particle/particle.hpp b/lib/core/c++/particle/particle.hpp index c87f15e..446e8a3 100644 --- a/lib/core/c++/particle/particle.hpp +++ b/lib/core/c++/particle/particle.hpp @@ -43,6 +43,28 @@ using Particle = Struct< >; } +template +constexpr auto verlet_step_lambda = [](saw::data>& particle, saw::data time_step_delta){ + auto& body = particle.template get<"rigid_body">(); + + auto& pos = body.template get<"position">(); + auto& pos_old = body.template get<"position_old">(); + + // auto& rot = body.template get<"rotation">(); + auto& acc = body.template get<"acceleration">(); + + auto tsd_squared = time_step_delta * time_step_delta; + + saw::data> pos_new; + // Actual step + for(uint64_t i = 0u; i < D; ++i){ + pos_new.at({{i}}) = saw::data{2.0} * pos.at({{i}}) - pos_old.at({{i}}) + acc.at({{i}}) * tsd_squared; + } + + pos_old = pos; + pos = pos_new; +}; + template > class particle_system { private: diff --git a/lib/core/tests/particles.cpp b/lib/core/tests/particles.cpp index 277a8d0..60cdc14 100644 --- a/lib/core/tests/particles.cpp +++ b/lib/core/tests/particles.cpp @@ -10,6 +10,25 @@ using namespace kel::lbm::sch; using T = Float64; } +SAW_TEST("Verlet step"){ + using namespace kel; + + + saw::data> particle; + auto& body = particle.template get<"rigid_body">(); + auto& pos = body.template get<"position">(); + auto& pos_old = body.template get<"position_old">(); + + // auto& rot = body.template get<"rotation">(); + auto& acc = body.template get<"acceleration">(); + + acc.at({{0}}).set({1.0}); + + lbm::verlet_step_lambda(particle,{0.5}); + + 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("Minor Test for mask"){ using namespace kel; @@ -31,8 +50,9 @@ SAW_TEST("Minor Test for mask"){ //saw::data> reference_mask{{{4+2,4+2}}}; //reference_mask.at({{0,0}}); } - -SAW_TEST("Verlet integration test"){ +*/ +/* +SAW_TEST("Verlet integration test 2D"){ using namespace kel; lbm::particle_system> system; @@ -79,7 +99,6 @@ SAW_TEST("Verlet integration test"){ } } - } */ } -- cgit v1.2.3