diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-12-10 11:26:13 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-12-10 11:26:13 +0100 |
| commit | eeb01452fe46fcb5efdc9c34b660305262097ca4 (patch) | |
| tree | 804f2355ef8bc4c256b10f76006f752430a72975 /lib | |
| parent | 1d7c55abaa8a17905e5b523f1fdd5c0080b97b7b (diff) | |
| download | libs-lbm-eeb01452fe46fcb5efdc9c34b660305262097ca4.tar.gz | |
Dangling changes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/core/c++/particle/particle.hpp | 22 | ||||
| -rw-r--r-- | lib/core/tests/particles.cpp | 25 |
2 files changed, 44 insertions, 3 deletions
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<typename T,uint64_t D> +constexpr auto verlet_step_lambda = [](saw::data<sch::Particle<T,D>>& particle, saw::data<T> 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<sch::Vector<T,D>> pos_new; + // Actual step + for(uint64_t i = 0u; i < D; ++i){ + pos_new.at({{i}}) = saw::data<T>{2.0} * pos.at({{i}}) - pos_old.at({{i}}) + acc.at({{i}}) * tsd_squared; + } + + pos_old = pos; + pos = pos_new; +}; + template<typename T, uint64_t D, typename ParticleCollision = sch::ParticleMask<T,D> > 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<sch::Particle<sch::T,2u>> 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<sch::T,2u>(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<sch::Array<sch::T,2>> 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<sch::T,2,sch::Particle<sch::T,2>> system; @@ -79,7 +99,6 @@ SAW_TEST("Verlet integration test"){ } } - } */ } |
