From a1afab28506cbb52da8229b84a146fbf30c4a4ce Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 12 Aug 2025 17:32:39 +0200 Subject: End of day, building util funcs --- c++/util.hpp | 13 +++++++++ examples/cavity_2d_gpu.cpp | 2 +- examples/poiseulle_particles_channel_2d.cpp | 41 ++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 c++/util.hpp diff --git a/c++/util.hpp b/c++/util.hpp new file mode 100644 index 0000000..a215cc1 --- /dev/null +++ b/c++/util.hpp @@ -0,0 +1,13 @@ +#pragma once + +namespace kel { +namespace lbm { +template +struct is_neighbour { + template + static bool operator()(saw::data& latt, saw::data& index, saw::data range) { + using dfi = df_info; + } +}; +} +} diff --git a/examples/cavity_2d_gpu.cpp b/examples/cavity_2d_gpu.cpp index e1e6333..b24ca38 100644 --- a/examples/cavity_2d_gpu.cpp +++ b/examples/cavity_2d_gpu.cpp @@ -197,7 +197,7 @@ void lbm_step( /** * 1. Relaxation parameter \tau */ - component coll{0.5384}; + component coll{0.59}; component bb; component bb_lid; diff --git a/examples/poiseulle_particles_channel_2d.cpp b/examples/poiseulle_particles_channel_2d.cpp index 286b211..9498ba7 100644 --- a/examples/poiseulle_particles_channel_2d.cpp +++ b/examples/poiseulle_particles_channel_2d.cpp @@ -256,6 +256,28 @@ void set_geometry(saw::data& latt){ } }, {{0u,0u}}, meta, {{4u,1u}}); + + /** + * Set channel circular obstacle + */ + iterate_over([&](const saw::data>& index){ + auto& cell = latt(index); + auto& info = cell.template get<"info">(); + + saw::data> area{{meta.at({0u})-4u, meta.at({1u})-4u}}; + double pos_x = 0.8 * area.at({0u}).get(); + double pos_y = 0.5 * area.at({1u}).get(); + + double dist_x = pos_x - index.at({0u}).get(); + double dist_y = pos_y - index.at({1u}).get(); + + double r = 16.0; + double dist_sq = dist_x * dist_x + dist_y * dist_y; + if(dist_sq < r*r){ + info({0u}).set(2u); + } + + }, {{0u,0u}}, meta, {{2u,2u}}); } void set_initial_conditions(saw::data& latt){ @@ -290,7 +312,7 @@ void add_particles(kel::lbm::particle_system& part_sys){ auto& p_mask = part.template get<"mask">(); { particle_circle_geometry geo; - p_mask = geo.template generate_mask(16u); + p_mask = geo.template generate_mask(2u,1u); } auto& rigid_body = part.template get<"rigid_body">(); auto& p_size = part.template get<"size">(); @@ -417,6 +439,23 @@ void couple_particles_to_lattice( // Add forces to put away from walls /// 1. Check if neighbour is wall + for(saw::data k{0u}; k.get() < sch::D2Q9::Q; ++k){ + auto n_p_cell_pos = saw::data> {{ + p_cell_pos.at({{0u}}) + dfi::directions[k.get()][0u], + p_cell_pos.at({{1u}}) + dfi::directions[k.get()][1u] + }}; + + auto& n_cell = latt(n_p_cell_pos); + auto& n_info = n_cell.template get<"info">()({0u}); + + // If neighbour is wall, then add force pushing the particle away + if(n_info.get() <= 1u){ + // add to p_acc + p_acc.at({{0u}}) = p_acc.at({{0u}}) + saw::data{10 * dfi::directions[dfi::opposite_index[k.get()]][0u]}.template cast_to(); + p_acc.at({{1u}}) = p_acc.at({{1u}}) + saw::data{10 * dfi::directions[dfi::opposite_index[k.get()]][1u]}.template cast_to(); + ; + } + } /// 2. Add force pushing away from wall // Add forces to push away from other particles -- cgit v1.2.3