From cb514e099515934322d9400d559a65b831cf4c5f Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 20 Feb 2026 13:55:00 +0100 Subject: Adding fake particles --- examples/poiseulle_particles_2d_gpu/sim.cpp | 69 ++++++++++++++++++++--------- lib/core/c++/particle.hpp | 2 +- lib/core/c++/particle/particle.hpp | 14 +++--- lib/core/tests/particles.cpp | 18 ++++---- 4 files changed, 66 insertions(+), 37 deletions(-) diff --git a/examples/poiseulle_particles_2d_gpu/sim.cpp b/examples/poiseulle_particles_2d_gpu/sim.cpp index de2bb40..8e522b4 100644 --- a/examples/poiseulle_particles_2d_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_gpu/sim.cpp @@ -12,7 +12,7 @@ namespace lbm { constexpr uint64_t dim_x = 1024ul; constexpr uint64_t dim_y = 512ul; -constexpr uint64_t particle_size = 128ul; +constexpr uint64_t particle_size = 1ul; namespace sch { using namespace saw::schema; @@ -63,6 +63,7 @@ saw::error_or setup_initial_conditions( saw::data, particle_size>>& particles ){ auto& info_f = fields.template get<"info">(); + auto& porous_f = macros.template get<"porosity">(); // Set everything as walls iterator::apply( [&](auto& index){ @@ -137,9 +138,41 @@ saw::error_or setup_initial_conditions( df_f.get_dims(), {{1u,1u}} ); + + iterator::apply( + [&](auto& index){ + saw::data> middle, ind_vec; + middle.at({{0u}}) = dim_x * 0.5; + middle.at({{1u}}) = dim_y * 0.5; + + ind_vec.at({{0u}}) = index.at({{0u}}).template cast_to(); + ind_vec.at({{1u}}) = index.at({{1u}}).template cast_to(); + + auto dist = middle - ind_vec; + auto dist_2 = saw::math::dot(dist,dist); + if(dist_2.at({}).get() < 128*128){ + porous_f.at(index).at({}) = 0.0; + } + }, + {},// 0-index + df_f.get_dims() + ); for(saw::data i{0u}; i < saw::data{particle_size}; ++i){ auto& part = particles.at(i); + + saw::data> pos; + pos.at({{0u}}) = dim_x * 0.5; + pos.at({{1u}}) = dim_y * 0.5; + saw::data> rad, dense, dt; + rad.at({}) = dim_y * 0.2; + dense.at({}) = 1.0; + dt.at({}) = 1.0; + part = create_spheroid_particle( + pos,{},{}, + {},{},{}, + rad, dense,dt + ); } return saw::make_void(); @@ -149,11 +182,21 @@ template saw::error_or step( saw::data>,encode::Sycl>& fields, saw::data>,encode::Sycl>& macros, + saw::data, particle_size>>& particles, saw::data t_i, device& dev ){ auto& q = dev.get_handle(); auto& info_f = fields.template get<"info">(); + auto& porous_f = macros.template get<"porosity">(); + + { + auto& p = particles.at({{0u}}); + + auto& p_coll = p.template get<"collision">(); + auto& p_rad = p_coll.template get<"radius">(); + } + // auto coll_ev = q.submit([&](acpp::sycl::handler& h){ @@ -180,6 +223,7 @@ saw::error_or step( }; component,encode::Sycl> flow_out{1.0}; + h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ saw::data> index; for(uint64_t i = 0u; i < Desc::D; ++i){ @@ -334,7 +378,7 @@ saw::error_or lbm_main(int argc, char** argv){ } } sycl_q.wait(); - saw::data time_steps{2048ul}; + saw::data time_steps{1024ul}; for(saw::data i{0u}; i < time_steps and krun; ++i){ { @@ -344,18 +388,9 @@ saw::error_or lbm_main(int argc, char** argv){ return eov; } } - /*{ - std::string file_name = "p_"; - file_name += std::to_string(i.get()); - file_name += ".json"; - auto eov = saw::easy::encode_and_write_file,particle_size>,saw::encode::Json>(out_dir, *lbm_particle_data_ptr); - if(eov.is_error()){ - return eov; - } - }*/ } { - auto eov = step(lsd_view,lsdm_view,i,dev); + auto eov = step(lsd_view,lsdm_view,*lbm_particle_data_ptr,i,dev); if(eov.is_error()){ return eov; } @@ -387,16 +422,6 @@ saw::error_or lbm_main(int argc, char** argv){ } } - /* - iterator::apply( - [&](auto& index){ - std::cout<().at(index).template cast_to().get()<<"\n"; - }, - {{0u,0u}}, - {{dim_x, dim_y}} - ); - */ - sycl_q.wait(); return saw::make_void(); } diff --git a/lib/core/c++/particle.hpp b/lib/core/c++/particle.hpp index f8a5cb0..b098ecc 100644 --- a/lib/core/c++/particle.hpp +++ b/lib/core/c++/particle.hpp @@ -24,8 +24,8 @@ public: verlet_step_lambda(p,{1.0}); // Update porosity over lattice nodes + - } }; } diff --git a/lib/core/c++/particle/particle.hpp b/lib/core/c++/particle/particle.hpp index a82b12d..8ef590d 100644 --- a/lib/core/c++/particle/particle.hpp +++ b/lib/core/c++/particle/particle.hpp @@ -40,19 +40,21 @@ using ParticleRigidBody = Struct< template using ParticleCollisionSpheroid = Struct< - Member + Member, "radius"> >; template> using Particle = Struct< Member, "rigid_body">, Member, - Member + // Problem is that dynamic data would two layered + // Member, "mask">, + Member, "mass"> >; } template -saw::data, sch::ParticleCollisionSpheroid> create_spheroid_particle( +saw::data>> create_spheroid_particle( saw::data> pos_p, saw::data> vec_p, saw::data> acc_p, @@ -175,9 +177,11 @@ constexpr auto broadphase_collision_distance_squared = [](saw::data::type>(2); + saw::data> two; + two.at({}) = 2.0; + auto rad_ab_2 = rad_l * rad_l + rad_r * rad_r + rad_r * rad_l * two; - return std::make_pair((norm_2.at({}).get() < rad_ab_2.get()), norm_2); + return std::make_pair((norm_2.at({}).get() < rad_ab_2.at({}).get()), norm_2); }; /** * diff --git a/lib/core/tests/particles.cpp b/lib/core/tests/particles.cpp index fcca19a..a9984ec 100644 --- a/lib/core/tests/particles.cpp +++ b/lib/core/tests/particles.cpp @@ -40,7 +40,7 @@ SAW_TEST("No Collision Spheroid 2D"){ auto& coll = part_a.template get<"collision">(); auto& radius = coll.template get<"radius">(); - radius.set(1.0); + radius.at({}).set(1.0); pos.at({{0u}}) = 0.1; pos.at({{1u}}) = 0.2; @@ -53,7 +53,7 @@ SAW_TEST("No Collision Spheroid 2D"){ auto& coll = part_b.template get<"collision">(); auto& radius = coll.template get<"radius">(); - radius.set(1.0); + radius.at({}).set(1.0); pos.at({{0u}}) = -2.1; pos.at({{1u}}) = 0.0; @@ -73,7 +73,7 @@ SAW_TEST("Collision Spheroid 2D"){ auto& coll = part_a.template get<"collision">(); auto& radius = coll.template get<"radius">(); - radius.set(1.0); + radius.at({}).set(1.0); pos.at({{0u}}) = 0.1; pos.at({{1u}}) = 0.2; @@ -86,7 +86,7 @@ SAW_TEST("Collision Spheroid 2D"){ auto& coll = part_b.template get<"collision">(); auto& radius = coll.template get<"radius">(); - radius.set(1.0); + radius.at({}).set(1.0); pos.at({{0u}}) = -1.5; pos.at({{1u}}) = 0.0; @@ -108,7 +108,7 @@ SAW_TEST("Moving particles 2D"){ auto& radius = coll.template get<"radius">(); auto& acc = body.template get<"acceleration">(); - radius.set(1.0); + radius.at({}).set(1.0); pos.at({{0u}}) = -5.0; pos.at({{1u}}) = 0.2; @@ -125,7 +125,7 @@ SAW_TEST("Moving particles 2D"){ auto& radius = coll.template get<"radius">(); auto& acc = body.template get<"acceleration">(); - radius.set(1.0); + radius.at({}).set(1.0); pos.at({{0u}}) = 5.0; pos.at({{1u}}) = 0.0; @@ -162,7 +162,7 @@ SAW_TEST("Particle Matrix Rotation"){ auto& radius = coll.template get<"radius">(); auto& acc = body.template get<"acceleration">(); - radius.set(1.0); + radius.at({}).set(1.0); pos.at({{0u}}) = -5.0; pos.at({{1u}}) = 0.2; @@ -185,7 +185,7 @@ SAW_TEST("Particle Collision Impulse"){ auto& radius = coll.template get<"radius">(); auto& acc = body.template get<"acceleration">(); - radius.set(1.0); + radius.at({}).set(1.0); pos.at({{0u}}) = -5.0; pos.at({{1u}}) = 0.2; @@ -202,7 +202,7 @@ SAW_TEST("Particle Collision Impulse"){ auto& radius = coll.template get<"radius">(); auto& acc = body.template get<"acceleration">(); - radius.set(1.5); + radius.at({}).set(1.5); pos.at({{0u}}) = 5.0; pos.at({{1u}}) = 0.0; -- cgit v1.2.3