From 6b10cae1ffa2521ce3c7e6aec85513a24d25934b Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 9 Feb 2026 11:21:55 +0100 Subject: Set equilibrium boundary for sim --- examples/poiseulle_particles_2d_gpu/sim.cpp | 14 ++++++++++++-- lib/core/c++/boundary.hpp | 18 ++++++++++++------ lib/core/c++/collision.hpp | 4 ++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/examples/poiseulle_particles_2d_gpu/sim.cpp b/examples/poiseulle_particles_2d_gpu/sim.cpp index d53a00c..6fdff7b 100644 --- a/examples/poiseulle_particles_2d_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_gpu/sim.cpp @@ -119,6 +119,14 @@ saw::error_or step( // Need nicer things to handle the flow. I see improvement here component> collision{0.6}; component> bb; + + saw::data> rho_b; + rho_b.at({}) = 1.0; + saw::data> vel_b; + vel_b.at({{0u}}) = 0.01; + + component> equi{rho_b,vel_b}; + component,encode::Sycl> flow_in{ [&](){ uint64_t target_t_i = 256u; @@ -148,11 +156,13 @@ saw::error_or step( collision.apply(fields,macros,index,t_i); break; case 3u: - flow_in.apply(fields,index,t_i); + equi.apply(fields,index,t_i); + // flow_in.apply(fields,index,t_i); collision.apply(fields,macros,index,t_i); break; case 4u: - flow_out.apply(fields,index,t_i); + equi.apply(fields,index,t_i); + // flow_out.apply(fields,index,t_i); collision.apply(fields,macros,index,t_i); break; default: diff --git a/lib/core/c++/boundary.hpp b/lib/core/c++/boundary.hpp index b70ffbf..d5f3022 100644 --- a/lib/core/c++/boundary.hpp +++ b/lib/core/c++/boundary.hpp @@ -69,22 +69,28 @@ public: template class component final { private: - saw::data density_; - saw::data velocity_; + saw::data> density_; + saw::data> velocity_; public: component( - saw::data density__, - saw::Data velocity__ + saw::data> density__, + saw::data> velocity__ ): density_{density__}, velocity_{velocity__} {} template - void apply(const saw::data& field, const saw::data>& index, saw::data time_step)const{ - using dfi = df_info; + void apply(const saw::data& field, const saw::data>& index, saw::data time_step) const { + + bool is_even = ((time_step.get() % 2u) == 0u); + using dfi = df_info; auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); + + auto eq = equilibrium(density_,velocity_); + + dfs_old_f.at(index) = eq; } }; diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp index a05e263..6c39646 100644 --- a/lib/core/c++/collision.hpp +++ b/lib/core/c++/collision.hpp @@ -52,8 +52,8 @@ public: // auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - saw::data rho; - saw::data> vel; + saw::data> rho; + saw::data> vel; compute_rho_u(dfs_old_f.at(index),rho,vel); auto eq = equilibrium(rho,vel); -- cgit v1.2.3