From 3489ac1d725c0eadb7d75329f9e6074ed177d125 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Thu, 23 Jul 2026 16:53:05 +0200 Subject: Somethings wrong with the particle interaction --- .../moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp | 2 +- modules/core/c++/abstract/schema.hpp | 25 ++++++++++++++++++- modules/core/c++/environment.hpp | 15 ++++++++++-- modules/core/c++/hlbm.hpp | 28 +++++++++++++--------- modules/core/c++/particle/particle.hpp | 12 +++++++++- modules/core/tests/schema.cpp | 3 ++- 6 files changed, 68 insertions(+), 17 deletions(-) diff --git a/examples/moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp b/examples/moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp index b2061f9..5e8f30a 100644 --- a/examples/moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp +++ b/examples/moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp @@ -380,7 +380,7 @@ saw::error_or lbm_main(int argc, char** argv){ } sycl_q.wait(); - if( i.get() % 128u == 0u){ + if( i.get() % 32u == 0u){ { auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); if(eov.is_error()){ diff --git a/modules/core/c++/abstract/schema.hpp b/modules/core/c++/abstract/schema.hpp index 8305005..8bc23b4 100644 --- a/modules/core/c++/abstract/schema.hpp +++ b/modules/core/c++/abstract/schema.hpp @@ -4,6 +4,7 @@ #include "templates.hpp" namespace kel { +namespace lbm { namespace sch { struct Void {}; @@ -26,6 +27,27 @@ struct Primitive { static constexpr uint64_t Bytes = N; }; +using UInt8 = Primitive; +using UInt16 = Primitive; +using UInt32 = Primitive; +using UInt64 = Primitive; + +using Int8 = Primitive; +using Int16 = Primitive; +using Int32 = Primitive; +using Int64 = Primitive; + +using Float8 = Primitive; +using Float16 = Primitive; +using Float32 = Primitive; +using Float64 = Primitive; + +template +struct MixedPrecision { + using Meta = Void; + using Inner = Sch; +}; + template struct FixedArray { using Meta = Void; @@ -37,7 +59,7 @@ template struct Array { using Meta = FixedArray; using Inner = T; - static constexpr std::array Dimensions{Dims}; + static constexpr std::array Dimensions{Dims}; }; template @@ -58,3 +80,4 @@ struct schema { }; } +} diff --git a/modules/core/c++/environment.hpp b/modules/core/c++/environment.hpp index d8aa9ae..ed9cd40 100644 --- a/modules/core/c++/environment.hpp +++ b/modules/core/c++/environment.hpp @@ -7,16 +7,23 @@ namespace kel { namespace lbm { -struct environment { +class environment { +public: std::string name; std::filesystem::path lbm_dir; std::filesystem::path data_dir; + std::filesystem::path name_dir; +public: }; -saw::error_or setup_lbm_env(const std::string_view name){ +template +saw::error_or init_lbm_env(const saw::data& args){ namespace fs = std::filesystem; + auto& args_n = args.template get<"args">(); + auto& name = args_n.template get<"name">(); + const char* home_dir = std::getenv("HOME"); if(not home_dir){ return saw::make_error("Couldn't find home dir"); @@ -42,6 +49,10 @@ saw::error_or setup_lbm_env(const std::string_view name){ } } + { + env.name_dir = env.data_dir / name.view(); + } + return env; } diff --git a/modules/core/c++/hlbm.hpp b/modules/core/c++/hlbm.hpp index 799d2b5..9356264 100644 --- a/modules/core/c++/hlbm.hpp +++ b/modules/core/c++/hlbm.hpp @@ -82,7 +82,7 @@ public: // Convex combination of velocities vel = vel * porosity + [&]() -> saw::data> { - return (D.at({}).get() > 0.0 ? N * flip_porosity / D : N); + return (D.at({}).get() > 0.0) ? ( N * flip_porosity / D ): N; }(); // Equilibrium auto eq = equilibrium(rho,vel); @@ -125,7 +125,6 @@ public: auto& particle_N_f = field.template get<"particle_N">(); auto& particle_D_f = field.template get<"particle_D">(); - { auto parts = part_spheroid_group.template get<"particles">(); auto parts_size = parts.meta().at({0u}); @@ -136,6 +135,11 @@ public: auto& pi = parts.at(index); auto& pirb = pi.template get<"rigid_body">(); auto& pirb_pos = pirb.template get<"position">(); + auto& pirb_pos_old = pirb.template get<"position_old">(); + + // TODO !!!! Divide by actual time step - for now it's ok + saw::data> ts; + ts.at({}) = 1.0f; saw::data> start; saw::data> stop; @@ -185,21 +189,23 @@ public: eps.at({}) = 1.5f; mpor = particle_porosity>::calculate(rel_dist,p_rad,eps); force_p = force_p + momentum * mpor; - - auto& N = particle_N_f.at(index_f); - auto& D = particle_D_f.at(index_f); - auto flip_porosity = one - mpor; - D = D + flip_porosity; - N = N + mvel_f.at(index_f) * flip_porosity; },start,stop); auto& pirb_acc = pirb.template get<"acceleration">(); - pirb_acc = force_p; + pirb_acc = force_p / part_spheroid_group.template get<"total_mass">().at({}); - saw::data> ts; - ts.at({}) = 1u; verlet_step_lambda(pi,ts); + auto vel_p = (pirb_pos-pirb_pos_old) / ts; + iterator::apply([&](const auto& index_f){ + auto& N = particle_N_f.at(index_f); + auto& D = particle_D_f.at(index_f); + auto& mpor = mpor_f.at(index_f); + auto flip_porosity = one - mpor; + + D = D + flip_porosity; + N = N + vel_p * flip_porosity; + },start,stop); // Check } } diff --git a/modules/core/c++/particle/particle.hpp b/modules/core/c++/particle/particle.hpp index f759c8d..a3669b4 100644 --- a/modules/core/c++/particle/particle.hpp +++ b/modules/core/c++/particle/particle.hpp @@ -74,9 +74,19 @@ saw::data>> create_sphero } total_mass.at({}) = total_mass.at({}) + dpi; - },{},mask_dims); + + // TODO ? Do mass properly + if constexpr ( D == 2u ) { + total_mass.at({}) = rad_d * rad_d * density.at({}) * 3.141592; + }else if constexpr ( D == 3u ){ + + }else if constexpr ( D== 1u ){ + + } + std::cout<<"Total Mass: "< +/* #include "../c++/abstract/schema.hpp" namespace { @@ -15,5 +16,5 @@ SAW_TEST("Abstract/Schema/Ptr"){ // static_assert(std::is_same_v::Schema, ts::TVal>, "schema decay failed"); } - } +*/ -- cgit v1.2.3