From 81b7d6d2c09bbff6d9c1738fbb52f7c9a90b10de Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 19 May 2026 15:04:59 +0200 Subject: IBM reimplement --- examples/poiseulle_particles_2d_ibm_gpu/sim.cpp | 87 ++++++++++++++++++------- 1 file changed, 64 insertions(+), 23 deletions(-) (limited to 'examples/poiseulle_particles_2d_ibm_gpu') diff --git a/examples/poiseulle_particles_2d_ibm_gpu/sim.cpp b/examples/poiseulle_particles_2d_ibm_gpu/sim.cpp index 9905906..ea49d51 100644 --- a/examples/poiseulle_particles_2d_ibm_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_ibm_gpu/sim.cpp @@ -54,12 +54,21 @@ using MacroStruct = Struct< //using ParticleArray = Array< // Particle //>; + +template +using ParticleSpheroidGroup = ParticleGroup< + T, + Desc::D, + sch::ParticleCollisionSpheroid +>; + } template saw::error_or setup_initial_conditions( saw::data>& fields, - saw::data>& macros + saw::data>& macros, + saw::data>& particles ){ auto& info_f = fields.template get<"info">(); // Set everything as walls @@ -136,25 +145,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.25; - 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(); + // Particles + { + saw::data> dense_p; + dense_p.at({}).set(1); - auto dist = middle - ind_vec; - auto dist_2 = saw::math::dot(dist,dist); - if(dist_2.at({}).get() < dim_y*dim_y*0.01){ - info_f.at(index) = 1u; - } - }, - {},// 0-index - df_f.get_dims() - ); + auto& spheroid_grp = particles; + + spheroid_grp = create_spheroid_particle_group( + dense_p, + {32u} + ); + + { + auto& p = spheroid_grp.template get<"particles">(); + p = {{{1u}}}; + + iterator<1u>::apply( + [&](auto& index){ + auto& p_ind = p.at(index); + auto& p_rb = p_ind.template get<"rigid_body">(); + auto& p_pos = p_rb.template get<"position">(); + auto& p_pos_old = p_rb.template get<"position_old">(); + + // Set position + p_pos.at({{0u}}) = dim_x * 0.25; + p_pos.at({{1u}}) = dim_y * 0.5; + + p_pos_old = p_pos; + }, + {}, + p.meta() + ); + } + } return saw::make_void(); } @@ -163,6 +188,7 @@ template saw::error_or step( saw::data>,encode::Sycl>& fields, saw::data>,encode::Sycl>& macros, + saw::data>,encode::Sycl>& particles, saw::data t_i, device& dev ){ @@ -172,9 +198,10 @@ saw::error_or step( // auto coll_ev = q.submit([&](acpp::sycl::handler& h){ // Need nicer things to handle the flow. I see improvement here - saw::data> f; - f.at({{0u}}) = 0.0; - f.at({{1u}}) = -1.0; + saw::data> f; + f.at({{0u}}) = 0.0; + f.at({{1u}}) = -1.0; + component> collision{0.65,f}; component> bb; component,encode::Sycl> abb; @@ -237,6 +264,11 @@ saw::error_or step( // h.depends_on(collision_ev); }).wait(); */ + q.submit([&](acpp::sycl::handler& h){ + h.parallel_for(acpp::sycl::range<1u>{1u}, [=](acpp::sycl::id<1u> idx){ + + }); + }).wait(); return saw::make_void(); } @@ -285,6 +317,7 @@ saw::error_or lbm_main(int argc, char** argv){ // saw::data> meta{{dim_x,dim_y}}; auto lbm_data_ptr = saw::heap>>(); auto lbm_macro_data_ptr = saw::heap>>(); + auto lbm_particle_ptr = saw::heap>>(); std::cout<<"Estimated Bytes: "<,sch::MacroStruct>().get()< lbm_main(int argc, char** argv){ sycl_q.wait(); { - auto eov = setup_initial_conditions(*lbm_data_ptr,*lbm_macro_data_ptr); + auto eov = setup_initial_conditions(*lbm_data_ptr,*lbm_macro_data_ptr,*lbm_particle_ptr); if(eov.is_error()){ return eov; } @@ -324,6 +357,7 @@ saw::error_or lbm_main(int argc, char** argv){ saw::data, encode::Sycl> lbm_sycl_data{sycl_q}; saw::data, encode::Sycl> lbm_sycl_macro_data{sycl_q}; + saw::data, encode::Sycl> lbm_sycl_particle{sycl_q}; sycl_q.wait(); { @@ -338,9 +372,16 @@ saw::error_or lbm_main(int argc, char** argv){ return eov; } } + { + auto eov = dev.copy_to_device(*lbm_particle_ptr,lbm_sycl_particle); + if(eov.is_error()){ + return eov; + } + } sycl_q.wait(); auto lsd_view = make_view(lbm_sycl_data); auto lsdm_view = make_view(lbm_sycl_macro_data); + auto lsdp_view = make_view(lbm_sycl_particle); saw::data time_steps{16u*4096ul}; auto& info_f = lsd_view.template get<"info">(); @@ -348,7 +389,7 @@ saw::error_or lbm_main(int argc, char** argv){ for(saw::data i{0u}; i < time_steps and krun; ++i){ // BC + Collision { - auto eov = step(lsd_view,lsdm_view,i,dev); + auto eov = step(lsd_view,lsdm_view,lsdp_view,i,dev); if(eov.is_error()){ return eov; } -- cgit v1.2.3