From 5c708bb3a0c9faec82a0deb32478370f9d780ea8 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 9 Nov 2026 15:13:37 +0100 Subject: Throat Clog is shit --- default.nix | 6 +++- examples/throat_clog_2d/common.hpp | 9 +++-- examples/throat_clog_2d/init.hpp | 35 +++++++++++++++--- examples/throat_clog_2d/sim.cpp | 74 ++++++++++++++++---------------------- examples/throat_clog_2d/step.hpp | 24 +++++++++++-- modules/core/c++/lbm.hpp | 3 -- 6 files changed, 93 insertions(+), 58 deletions(-) diff --git a/default.nix b/default.nix index df3f3f3..cc36692 100644 --- a/default.nix +++ b/default.nix @@ -3,6 +3,10 @@ , lld ? pkgs.lld_20 , stdenv ? llvmPackages.stdenv , clang-tools ? llvmPackages.clang-tools +# Build AdaptiveCpp with the ROCm backend. Off by default so the usual +# host/OpenMP path stays cheap to build; turn on with +# nix-build -A --arg rocm true +, rocm ? false }: let @@ -36,7 +40,7 @@ let inherit stdenv llvmPackages lld; config = { - rocm = false; + inherit rocm; }; }; diff --git a/examples/throat_clog_2d/common.hpp b/examples/throat_clog_2d/common.hpp index d74b2f9..84baeb3 100644 --- a/examples/throat_clog_2d/common.hpp +++ b/examples/throat_clog_2d/common.hpp @@ -22,10 +22,15 @@ namespace lbm { */ // Base resolution. -constexpr uint64_t dim_y = 64ul; +// +// Kept small on purpose: the SYCL JIT has to compile the whole kernel set +// before the first step runs, and on a modest machine a large domain plus a +// large particle set will exhaust memory during that compile rather than +// during the simulation itself. +constexpr uint64_t dim_y = 32ul; constexpr uint64_t dim_x = dim_y * 4ul; -constexpr uint64_t particle_amount = 1ul; +constexpr uint64_t particle_amount = 20ul; namespace sch { diff --git a/examples/throat_clog_2d/init.hpp b/examples/throat_clog_2d/init.hpp index f76cd67..e03bd5e 100644 --- a/examples/throat_clog_2d/init.hpp +++ b/examples/throat_clog_2d/init.hpp @@ -162,17 +162,42 @@ kel::lbm::error_or init( std::cout<<"RADIUS: "<> dense_p; dense_p.at({}).set(1); - particles = create_spheroid_particle_group(radius_p, dense_p, {{64u}}); + particles = create_spheroid_particle_group(radius_p, dense_p, {{64u}}); auto& parts = particles.template get<"particles">(); - { - auto& p = parts.at({0u}); + /** + * Seed the particles upstream of the throat on a staggered grid. + * + * Spacing is 2.4 radii, so they start clear of one another -- any + * initial overlap would be resolved as a contact on the first step and + * fire them apart. + */ + const auto radius = radius_p.at({}).get(); + const auto pitch = radius * 2.4; + + const auto x0 = conv.meter_si_to_lbm({{0.10}}).handle().get(); + const auto y_mid = conv.meter_si_to_lbm({{0.25}}).handle().get(); + + constexpr uint64_t per_column = 4ul; + + for(uint64_t i = 0u; i < particle_amount; ++i){ + auto col = i / per_column; + auto row = i % per_column; + + // Offset alternate columns by half a pitch so they interleave. + auto y_off = (static_cast(row) - (per_column - 1u) * 0.5) * pitch + + ((col % 2u == 1u) ? pitch * 0.5 : 0.0); + + auto& p = parts.at({i}); auto& prb = p.template get<"rigid_body">(); auto& p_pos = prb.template get<"position">(); auto& p_pos_old = prb.template get<"position_old">(); - p_pos.at({{0u}}) = conv.meter_si_to_lbm({{0.16}}).handle(); - p_pos.at({{1u}}) = conv.meter_si_to_lbm({{0.25}}).handle(); + p_pos.at({{0u}}).set(x0 + static_cast(col) * pitch); + p_pos.at({{1u}}).set(y_mid + y_off); + + // Start at rest: position_old defaults to zero, which would read + // as an enormous velocity. p_pos_old = p_pos; } } diff --git a/examples/throat_clog_2d/sim.cpp b/examples/throat_clog_2d/sim.cpp index 118e1b1..89741ca 100644 --- a/examples/throat_clog_2d/sim.cpp +++ b/examples/throat_clog_2d/sim.cpp @@ -2,30 +2,17 @@ #include "init.hpp" #include "step.hpp" -#include +#include /** - * For deciding what parameters to use maybe? + * The coupling method is the only thing this example takes from the command + * line, so it is read straight from argv rather than through a codec -- the + * args codec is forstio's and would need a schema round trip for one string. */ -namespace args { - -using LbmArgsStruct = Struct< - Member - //,Member ->; - -using LbmArgs = Args< - LbmArgsStruct, - Tuple<> ->; -} - template -kel::lbm::error_or lbm_main(const kel::lbm::data& args){ +kel::lbm::error_or lbm_main(std::string_view coupling){ using namespace kel::lbm; - auto& an = args.template get<"args">(); - using dfi = df_info; auto eo_lbm_dir = output_directory(); @@ -34,7 +21,7 @@ kel::lbm::error_or lbm_main(const kel::lbm::data& args){ } auto& lbm_dir = eo_lbm_dir.get_value(); - auto out_dir = lbm_dir / "throat_clog_2d" / an.template get<"coupling">().stl_view(); + auto out_dir = lbm_dir / "throat_clog_2d" / coupling; { std::error_code ec; @@ -151,7 +138,7 @@ kel::lbm::error_or lbm_main(const kel::lbm::data& args){ } } { - auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+an.template get<"coupling">().stl_string(),i.get(), *lbm_macro_data_ptr); + auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+std::string{coupling},i.get(), *lbm_macro_data_ptr); if(eov.is_error()){ return eov; } @@ -191,7 +178,7 @@ kel::lbm::error_or lbm_main(const kel::lbm::data& args){ } } { - auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+an.template get<"coupling">().stl_string(),time_steps.get(), *lbm_macro_data_ptr); + auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+std::string{coupling},time_steps.get(), *lbm_macro_data_ptr); if(eov.is_error()){ return eov; } @@ -211,37 +198,36 @@ using DescT = kel::lbm::sch::D2Q9; kel::lbm::error_or k_main(int argc, char** argv){ using namespace kel::lbm; - - kel::lbm::data args; - { - auto eov = saw::parse_args(args,argc,argv); - if(eov.is_error()){ - return eov; - } + + // Default to fplbm so the example runs with no arguments at all. + std::string_view coupling{"fplbm"}; + if(argc > 1){ + coupling = argv[1]; } - auto& an = args.template get<"args">(); - auto& coupling = an.template get<"coupling">(); auto resolution_resolve = [&]() -> kel::lbm::error_or{ - return lbm_main(args); - }; - - auto coupling_resolve = [&]() -> kel::lbm::error_or { - if(coupling.stl_view() == "hlbm"){ - return resolution_resolve.template operator()(); - } else if(coupling.stl_view() == "fplbm"){ - return resolution_resolve.template operator()(); - } else if(coupling.stl_view() == "psm"){ - return resolution_resolve.template operator()(); - } + return lbm_main(coupling); }; - return coupling_resolve(); + if(coupling == "hlbm"){ + return resolution_resolve.template operator()(); + } + if(coupling == "fplbm"){ + return resolution_resolve.template operator()(); + } + if(coupling == "psm"){ + return resolution_resolve.template operator()(); + } - return kel::lbm::make_error("Invalid coupling"); + /** + * Previously the dispatch lambda had no return on the unmatched path, so + * an unknown coupling fell off the end of a non-void function. + */ + return kel::lbm::make_error( + std::string{"Unknown coupling '"} + std::string{coupling} + + "', expected one of hlbm, fplbm, psm"); } - int main(int argc, char** argv){ auto eov = k_main(argc, argv); if(eov.is_error()){ diff --git a/examples/throat_clog_2d/step.hpp b/examples/throat_clog_2d/step.hpp index 840f8ba..5bb889e 100644 --- a/examples/throat_clog_2d/step.hpp +++ b/examples/throat_clog_2d/step.hpp @@ -116,9 +116,24 @@ kel::lbm::error_or step( }); }).wait(); + /** + * Particle step, split so contact lands between the fluid gather and + * the integration. With 20 particles in a converging throat they jam + * against one another, so without a contact pass they would simply + * pass through each other and through the walls. + */ q.submit([&](acpp::sycl::handler& h){ - kel::lbm::data> grav; - component> fplbm_one_part{grav}; + component> p_reset; + component> p_gather; + component> p_integrate; + + /** + * Stiffness is sized so an impact at the inflow speed stays well + * under a tenth of a radius of overlap; see dem_stiffness_for. + */ + dem_params p_dem{2.0e-2, 0.4, 0.0, 0.0}; + kel::lbm::data> p_extent{{dim_x,dim_y}}; + component> p_contact{p_dem,p_extent}; h.parallel_for(acpp::sycl::range<1u>{particle_amount}, [=](acpp::sycl::id<1u> idx){ kel::lbm::data> index; @@ -126,7 +141,10 @@ kel::lbm::error_or step( index.at({{i}}).set(idx[i]); } - fplbm_one_part.apply(fields,macros,particles,index,t_i,{4u}); + p_reset.apply(particles,index,t_i); + p_gather.apply(fields,macros,particles,index,t_i,{4u}); + p_contact.apply(particles,index,t_i,{4u}); + p_integrate.apply(particles,index,t_i,{4u}); }); }).wait(); diff --git a/modules/core/c++/lbm.hpp b/modules/core/c++/lbm.hpp index eefb556..042bad4 100644 --- a/modules/core/c++/lbm.hpp +++ b/modules/core/c++/lbm.hpp @@ -17,9 +17,6 @@ #include "macroscopic.hpp" #include "momentum_gather.hpp" #include "memory.hpp" -#include "particle/voxel_narrow.hpp" -#include "particle/cell_list.hpp" -#include "particle/couple.hpp" #include "particle/contact.hpp" #include "particle/integrate.hpp" #include "psm.hpp" -- cgit v1.3.1