From a2d9db3144a57f915b5c40660cd9c07826e49787 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 8 Jun 2026 23:20:10 +0200 Subject: added comment --- lib/core/c++/particle/blur.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/core/c++/particle/blur.hpp b/lib/core/c++/particle/blur.hpp index 7b93ae9..b7a1988 100644 --- a/lib/core/c++/particle/blur.hpp +++ b/lib/core/c++/particle/blur.hpp @@ -13,6 +13,7 @@ void blur_mask(saw::data>& p_mask){ auto meta = p_mask.dims(); saw::data> blurred_mask{meta}; + /* 1D blur into N-D Blur*/ for(saw::data i{0u}; i < saw::data{D}; ++i){ iterator::apply([&](const auto& index){ blurred_mask.at(index) = p_mask.at(index) * mid; -- cgit v1.2.3 From ad0efe4d0e43a2a4f122677578107c2a0398e53f Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 9 Jun 2026 14:14:30 +0200 Subject: Dangling --- examples/poiseulle_particles_2d_gpu/sim.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/poiseulle_particles_2d_gpu/sim.cpp b/examples/poiseulle_particles_2d_gpu/sim.cpp index 3de3cfb..42710f1 100644 --- a/examples/poiseulle_particles_2d_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_gpu/sim.cpp @@ -2,6 +2,20 @@ #include "init.hpp" #include "step.hpp" +#include + +/** + * For deciding what parameters to use maybe? + */ +namespace sch { +using namespace saw::schema; + +using LbmArgs = Args< + Struct<>, + Tuple<> +>; +} + template saw::error_or lbm_main(int argc, char** argv){ using namespace kel::lbm; -- cgit v1.2.3 From 4c9e43a42c15ce93ffded21dfcaa171f63d20d69 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Thu, 11 Jun 2026 14:07:27 +0200 Subject: Fixing deduction issues from constexpr values --- examples/poiseulle_particles_2d_gpu/common.hpp | 2 +- examples/poiseulle_particles_2d_gpu/init.hpp | 7 ++- examples/poiseulle_particles_2d_gpu/sim.cpp | 35 +++++++++---- examples/poiseulle_particles_2d_gpu/step.hpp | 7 +-- lib/core/c++/hlbm.hpp | 11 +++-- lib/core/c++/particle/aabb.hpp | 30 +++++++----- lib/core/c++/particle/common.hpp | 3 ++ lib/core/c++/particle/particle.hpp | 68 +++++--------------------- lib/core/c++/particle/schema.hpp | 67 +++++++++++++++++++++++++ lib/core/c++/schema.hpp | 10 ++-- 10 files changed, 145 insertions(+), 95 deletions(-) create mode 100644 lib/core/c++/particle/common.hpp create mode 100644 lib/core/c++/particle/schema.hpp diff --git a/examples/poiseulle_particles_2d_gpu/common.hpp b/examples/poiseulle_particles_2d_gpu/common.hpp index a69a2cf..6c05b64 100644 --- a/examples/poiseulle_particles_2d_gpu/common.hpp +++ b/examples/poiseulle_particles_2d_gpu/common.hpp @@ -55,7 +55,7 @@ using MacroStruct = Struct< >; template -using ParticleSpheroidGroup = ParticleGroup>; +using ParticleSpheroidGroup = ParticleGroup>; } } diff --git a/examples/poiseulle_particles_2d_gpu/init.hpp b/examples/poiseulle_particles_2d_gpu/init.hpp index 70d59fc..617b296 100644 --- a/examples/poiseulle_particles_2d_gpu/init.hpp +++ b/examples/poiseulle_particles_2d_gpu/init.hpp @@ -7,10 +7,13 @@ namespace lbm { template saw::error_or setup_initial_conditions( + const converter& conv, saw::data>& fields, saw::data>& macros, saw::data>& particles ){ + (void) conv; + auto& info_f = fields.template get<"info">(); auto& porous_f = macros.template get<"porosity">(); // Set everything as walls @@ -110,9 +113,11 @@ saw::error_or setup_initial_conditions( ); { + saw::data> radius_p; + radius_p.at({}).set(2); saw::data> dense_p; dense_p.at({}).set(1); - particles = create_spheroid_particle_group(dense_p, {{16u}}); + particles = create_spheroid_particle_group(radius_p, dense_p, {{16u}}); } return saw::make_void(); diff --git a/examples/poiseulle_particles_2d_gpu/sim.cpp b/examples/poiseulle_particles_2d_gpu/sim.cpp index 42710f1..47c5daa 100644 --- a/examples/poiseulle_particles_2d_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_gpu/sim.cpp @@ -7,11 +7,16 @@ /** * For deciding what parameters to use maybe? */ -namespace sch { +namespace args { using namespace saw::schema; +using LbmArgsStruct = Struct< + Member, + Member +>; + using LbmArgs = Args< - Struct<>, + LbmArgsStruct, Tuple<> >; } @@ -22,6 +27,13 @@ saw::error_or lbm_main(int argc, char** argv){ using dfi = df_info; + auto eo_args = saw::parse_args(argc,argv); + if(eo_args.is_error()){ + return std::move(eo_args.get_error()); + } + auto& args = eo_args.get_value(); + (void)args; + auto eo_lbm_dir = output_directory(); if(eo_lbm_dir.is_error()){ return std::move(eo_lbm_dir.get_error()); @@ -51,7 +63,7 @@ saw::error_or lbm_main(int argc, char** argv){ auto lbm_data_ptr = saw::heap>>(); auto lbm_macro_data_ptr = saw::heap>>(); auto lbm_particle_data_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,*lbm_particle_data_ptr); + auto eov = setup_initial_conditions(conv,*lbm_data_ptr,*lbm_macro_data_ptr,*lbm_particle_data_ptr); if(eov.is_error()){ return eov; } @@ -106,21 +118,24 @@ saw::error_or lbm_main(int argc, char** argv){ } } 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_data); saw::data time_steps{16u*4096ul}; + auto& info_f = lsd_view.template get<"info">(); for(saw::data i{0u}; i < time_steps and krun; ++i){ // BC + Collision { - auto eov = step(lsd_view,lsdm_view,lsdp_view,i,dev); + auto eov = step(conv,lsd_view,lsdm_view,lsdp_view,i,dev); if(eov.is_error()){ return eov; } } + sycl_q.wait(); if(i.get() % 32u == 0u){ { @@ -145,22 +160,22 @@ saw::error_or lbm_main(int argc, char** argv){ for(uint64_t i = 0u; i < Desc::D; ++i){ index.at({{i}}).set(idx[i]); } - - auto info = info_f.at(index); - - if(info.get() > 0u){ + + auto info = info_f.at(index).get(); + + if(info > 0u){ stream.apply(lsd_view,index,i); } }); }).wait(); wait.poll(); + if(print_status){ std::cout<<"Status: "<().get() * 100 / time_steps.get())<<"%"< saw::error_or step( + const converter& conv, saw::data>,encode::Sycl>& fields, saw::data>,encode::Sycl>& macros, saw::data>,encode::Sycl>& particles, @@ -19,7 +20,8 @@ saw::error_or step( // auto coll_ev = q.submit([&](acpp::sycl::handler& h){ - component> collision{0.65}; + component> collision{0.8}; + component> particle; component> bb; component,encode::Sycl> abb; @@ -32,7 +34,7 @@ saw::error_or step( component,encode::Sycl> flow_in{ [&](){ - uint64_t target_t_i = 64u; + uint64_t target_t_i = 16u; if(t_i.get() < target_t_i){ return 1.0 + (0.0002 / target_t_i) * t_i.get(); } @@ -41,7 +43,6 @@ saw::error_or step( }; component,encode::Sycl> flow_out{1.0}; - h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ saw::data> index; for(uint64_t i = 0u; i < Desc::D; ++i){ diff --git a/lib/core/c++/hlbm.hpp b/lib/core/c++/hlbm.hpp index 6ae7d80..85e5357 100644 --- a/lib/core/c++/hlbm.hpp +++ b/lib/core/c++/hlbm.hpp @@ -4,6 +4,8 @@ #include "component.hpp" #include "equilibrium.hpp" +#include "particle/particle.hpp" + namespace kel { namespace lbm { namespace cmpt { @@ -114,14 +116,15 @@ public: */ template - void apply(const saw::data& field, const saw::data& macros, const saw::data& part_groups, saw::data> index, saw::data time_step) const { + void apply(const saw::data& field, const saw::data& macros, const saw::data& part_group, saw::data> index, saw::data time_step) const { /// Figure out how to access the particle list // auto& p = particles.at(i); /// Iterate over the grid bounds // auto& grid = p.template get<"grid">(); - auto& part_spheroid_group = part_groups.template get<0>(); + auto& part_spheroid_group = part_group; + auto& mvel = macros.template get<"velocity">(); { auto& parts = part_spheroid_group.template get<"particles">(); auto parts_size = parts.size(); @@ -133,10 +136,8 @@ public: saw::data> start; saw::data> stop; + auto aabb = particle_aabb::calculate(part_spheroid_group,index,mvel.meta()); /// Ok, I iterate over the space which covers our particle? So lower bounds to upper bounds - for(uint64_t i{0u}; i < Desc::D; ++i){ - - } iterator::apply([&](const auto& index){ // ask for the d_k value here. diff --git a/lib/core/c++/particle/aabb.hpp b/lib/core/c++/particle/aabb.hpp index aec95ca..8579695 100644 --- a/lib/core/c++/particle/aabb.hpp +++ b/lib/core/c++/particle/aabb.hpp @@ -1,36 +1,39 @@ #pragma once -#include "particle.hpp" +#include "common.hpp" +#include "schema.hpp" namespace kel { namespace lbm { -template +template class particle_aabb final { }; -template::type radius> -class particle_aabb > > final { +template +class particle_aabb< + sch::ParticleGroup> +> final { public: - using Schema = sch::ParticleGroup>; + using Schema = sch::ParticleGroup>; - using AABB = Struct< - Member"a">, - Member"b"> + using AABB = sch::Struct< + sch::Member,"a">, + sch::Member,"b"> >; public: - static constexpr saw::data get(const saw::data& p_grp, const saw::data>& i, const saw::data>& meta){ + static constexpr saw::data calculate(const saw::data& p_grp, const saw::data>& i, const saw::data>& meta){ + + saw::data aabb; auto& parts = p_grp.template get<"particles">(); auto& pi = parts.at(i); auto& pirb = pi.template get<"rigid_body">(); auto& pirb_pos = pirb.template get<"position">(); - saw::data aabb; auto& a = aabb.template get<"a">(); auto& b = aabb.template get<"b">(); - saw::data> rad_d; - rad_d.at({}).set(radius); + const saw::data>& rad_d = p_grp.template get<"collision">().template get<"radius">().at({0u}); saw::data> lower; saw::data> upper; @@ -39,10 +42,11 @@ public: lower.at({{i}}) = pirb_pos.at({{i}}) >= rad_d.at({}) ? (pirb_pos.at({{i}}) - rad_d.at({})) : saw::data{0}; a.at({i}) = lower.at({{i}}).template cast_to(); upper.at({{i}}) = pirb_pos.at({{i}}) + rad_d.at({}); - b.at({i}) = (upper.at({{i}})+saw::data{1}).template cast_to() + b.at({i}) = (upper.at({{i}})+saw::data{1}).template cast_to(); } return aabb; + } }; } diff --git a/lib/core/c++/particle/common.hpp b/lib/core/c++/particle/common.hpp new file mode 100644 index 0000000..9e673c2 --- /dev/null +++ b/lib/core/c++/particle/common.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include "../common.hpp" diff --git a/lib/core/c++/particle/particle.hpp b/lib/core/c++/particle/particle.hpp index 1a99dcd..13ed37b 100644 --- a/lib/core/c++/particle/particle.hpp +++ b/lib/core/c++/particle/particle.hpp @@ -6,68 +6,22 @@ #include "../iterator.hpp" +#include "schema.hpp" +#include "aabb.hpp" + namespace kel { namespace lbm { -namespace coll { -struct Spheroid{}; -} -namespace sch { -using namespace saw::schema; - -namespace impl { -template -struct rotation_type_helper; - -template -struct rotation_type_helper { - using Schema = Scalar; -}; - -template -struct rotation_type_helper { - using Schema = Vector; -}; -} - -template -using ParticleRigidBody = Struct< - Member, "position">, - Member, "position_old">, - Member::Schema, "rotation">, - Member::Schema, "rotation_old">, - - Member, "acceleration">, - Member::Schema, "angular_acceleration"> ->; - -template::type radius = 1.0f> -using ParticleCollisionSpheroid = Struct< ->; template -using Particle = Struct< - Member, "rigid_body"> - // Problem is that dynamic data would two layered - // Member, "mask">, ->; - -template> -using ParticleGroup = Struct< - Member, "mask">, - Member,1u>, "mask_step">, - Member,1u>, "density">, - Member,1u>, "center_of_mass">, - Member,1u>, "total_mass">, - Member,1u>, "particles"> ->; -} - -template::type radius> -saw::data>> create_spheroid_particle_group( +saw::data>> create_spheroid_particle_group( + saw::data> radius_p, saw::data> density_p, const saw::data& mask_resolution ){ - saw::data>> part; + saw::data>> part; + + auto& rad_s = part.template get<"collision">().at({0u}).template get<"radius">(); + rad_s = radius_p; auto& mask = part.template get<"mask">(); auto& density = part.template get<"density">().at({{0u}}); @@ -83,7 +37,7 @@ saw::data>> cre for(uint64_t i = 0u; i < D; ++i){ mask_dims.at({i}) = mask_resolution; } - saw::data rad_d{radius}; + saw::data rad_d = radius_p.at({}); saw::data dia_d = rad_d * 2; mask = {mask_dims}; @@ -104,7 +58,7 @@ saw::data>> cre saw::data> center; for(uint64_t i = 0u; i < D; ++i){ - center.at({{i}}).set(radius); + center.at({{i}}) = rad_d; } iterator::apply([&](const auto& index){ diff --git a/lib/core/c++/particle/schema.hpp b/lib/core/c++/particle/schema.hpp new file mode 100644 index 0000000..18a697a --- /dev/null +++ b/lib/core/c++/particle/schema.hpp @@ -0,0 +1,67 @@ +#pragma once + +#include "common.hpp" + +namespace kel { +namespace lbm { + +namespace coll { +template +struct Spheroid { + using ValueSchema = T; + using Schema = sch::Struct< + sch::Member,"radius"> + >; +}; +} + +namespace sch { +using namespace saw::schema; + +namespace impl { +template +struct rotation_type_helper; + +template +struct rotation_type_helper { + using Schema = Scalar; +}; + +template +struct rotation_type_helper { + using Schema = Vector; +}; +} + +template +using ParticleRigidBody = Struct< + Member, "position">, + Member, "position_old">, + Member::Schema, "rotation">, + Member::Schema, "rotation_old">, + + Member, "acceleration">, + Member::Schema, "angular_acceleration"> +>; + + +template +using Particle = Struct< + Member, "rigid_body"> + // Problem is that dynamic data would two layered + // Member, "mask">, +>; + +template> +using ParticleGroup = Struct< + Member, "mask">, + Member, "collision">, + Member,1u>, "mask_step">, + Member,1u>, "density">, + Member,1u>, "center_of_mass">, + Member,1u>, "total_mass">, + Member,1u>, "particles"> +>; +} +} +} diff --git a/lib/core/c++/schema.hpp b/lib/core/c++/schema.hpp index 0c92ae6..7712f99 100644 --- a/lib/core/c++/schema.hpp +++ b/lib/core/c++/schema.hpp @@ -3,9 +3,9 @@ #include namespace kel { - namespace lbm { - namespace sch { - using namespace saw::schema; - } - } +namespace lbm { +namespace sch { +using namespace saw::schema; +} +} } -- cgit v1.2.3 From ff702d3c9427794c5557360c53b93f9861f97554 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 22 Jun 2026 17:36:51 +0200 Subject: Dangling --- examples/poiseulle_particles_2d_gpu/step.hpp | 8 +++++++- lib/core/c++/hlbm.hpp | 1 + lib/core/c++/particle/aabb.hpp | 4 +++- lib/core/tests/particles.cpp | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/examples/poiseulle_particles_2d_gpu/step.hpp b/examples/poiseulle_particles_2d_gpu/step.hpp index 52e8c59..aa0e382 100644 --- a/examples/poiseulle_particles_2d_gpu/step.hpp +++ b/examples/poiseulle_particles_2d_gpu/step.hpp @@ -18,10 +18,11 @@ saw::error_or step( auto& info_f = fields.template get<"info">(); auto& porous_f = macros.template get<"porosity">(); + component> particle; + // auto coll_ev = q.submit([&](acpp::sycl::handler& h){ component> collision{0.8}; - component> particle; component> bb; component,encode::Sycl> abb; @@ -76,6 +77,11 @@ saw::error_or step( }); }).wait(); + q.submit([&](acpp::sycl::handler& h){ + h.parallel_for(acpp::sycl::range<1u>{1u}, [=](acpp::sycl::id<1u> idx){ + particle.apply(fields,macros,particles,{{0u}},t_i); + }); + }).wait(); // Step /* diff --git a/lib/core/c++/hlbm.hpp b/lib/core/c++/hlbm.hpp index 85e5357..0ba9cc2 100644 --- a/lib/core/c++/hlbm.hpp +++ b/lib/core/c++/hlbm.hpp @@ -142,6 +142,7 @@ public: iterator::apply([&](const auto& index){ // ask for the d_k value here. // For every value im iterating over I need sth + std::cout<<"Pos: "< class particle_aabb final { + static_assert(saw::always_false::value, "Not supported"); }; template @@ -21,7 +22,8 @@ public: sch::Member,"b"> >; public: - static constexpr saw::data calculate(const saw::data& p_grp, const saw::data>& i, const saw::data>& meta){ + template + static constexpr saw::data calculate(const saw::data& p_grp, const saw::data>& i, const saw::data>& meta){ saw::data aabb; auto& parts = p_grp.template get<"particles">(); diff --git a/lib/core/tests/particles.cpp b/lib/core/tests/particles.cpp index 1c18fbb..de9477c 100644 --- a/lib/core/tests/particles.cpp +++ b/lib/core/tests/particles.cpp @@ -272,4 +272,10 @@ SAW_TEST("Verlet integration test 2D"){ } } */ + +SAW_TEST("Particle / AABB"){ + using namespace kel; + + +} } -- cgit v1.2.3 From 90f242af3036e0863a067c3f55457566d1f1e4ce Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 23 Jun 2026 14:13:48 +0200 Subject: Fixing hlbm and particle aabb --- lib/core/c++/hlbm.hpp | 2 ++ lib/core/c++/particle/aabb.hpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/core/c++/hlbm.hpp b/lib/core/c++/hlbm.hpp index 0ba9cc2..c15bfc4 100644 --- a/lib/core/c++/hlbm.hpp +++ b/lib/core/c++/hlbm.hpp @@ -6,6 +6,8 @@ #include "particle/particle.hpp" +#include + namespace kel { namespace lbm { namespace cmpt { diff --git a/lib/core/c++/particle/aabb.hpp b/lib/core/c++/particle/aabb.hpp index d74ea88..1773dea 100644 --- a/lib/core/c++/particle/aabb.hpp +++ b/lib/core/c++/particle/aabb.hpp @@ -7,7 +7,7 @@ namespace kel { namespace lbm { template class particle_aabb final { - static_assert(saw::always_false::value, "Not supported"); + static_assert(saw::always_false, "Not supported"); }; template -- cgit v1.2.3 From 70fda0ecf925fb5010b2e23cbdbc4e2076715958 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 24 Jun 2026 22:11:24 +0200 Subject: Adding python script for the graph generation --- lib/core/c++/hlbm.hpp | 2 +- scripts/python/graph.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 scripts/python/graph.py diff --git a/lib/core/c++/hlbm.hpp b/lib/core/c++/hlbm.hpp index c15bfc4..726f2d8 100644 --- a/lib/core/c++/hlbm.hpp +++ b/lib/core/c++/hlbm.hpp @@ -129,7 +129,7 @@ public: auto& mvel = macros.template get<"velocity">(); { auto& parts = part_spheroid_group.template get<"particles">(); - auto parts_size = parts.size(); + auto parts_size = parts.meta().at({0u}); auto& pi = parts.at(index); auto& pirb = pi.template get<"rigid_body">(); diff --git a/scripts/python/graph.py b/scripts/python/graph.py new file mode 100755 index 0000000..ab42154 --- /dev/null +++ b/scripts/python/graph.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 + +import numpy as np +import matplotlib.pyplot as plt + +x = np.linspace(0, 1, 1000) + +# Linear function +y_linear = x + +# Step function +y_step = np.piecewise( + x, + [ + x < 0.125, + (x >= 0.125) & (x < 0.375), + (x >= 0.375) & (x < 0.625), + (x >= 0.625) & (x < 0.875), + x >= 0.875 + ], + [0.0, 1/4, 2/4, 3/4, 1.0] +) + +y_step2 = np.piecewise( + x, + [ + x < 0.0625, + (x >= 0.0625) & (x < 0.1875), + (x >= 0.1875) & (x < 0.3125), + (x >= 0.3125) & (x < 0.4375), + (x >= 0.4375) & (x < 0.5625), + (x >= 0.5625) & (x < 0.6875), + (x >= 0.6875) & (x < 0.8125), + (x >= 0.8125) & (x < 0.9375), + x >= 0.9375 + ], + [0/8, 1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8, 1.0] +) + +# Smooth cos²-like ramp from 0 → 1 over full domain +y_cos2 = np.sin((np.pi / 2.0) * x) ** 2 + +y_cos2_shift = np.sin((np.pi / 2.0) * (x+0.125)/1.25) ** 2 + + + +# Plot +plt.figure(figsize=(8, 6)) + +plt.plot(x, y_linear, label="y = x", linewidth=2) +plt.step(x, y_step, where="post", label="PSM subgrid of 8", linewidth=2) +plt.step(x, y_step2, where="post", label="PSM subgrid of 8", linewidth=2) +plt.plot(x, y_cos2, label=r'HLBM e_h:cell size 1:1', linewidth=2) +plt.plot(x, y_cos2_shift, label=r'HLBM e_h:cell size 1.25:1', linewidth=2) + +plt.xlim(0, 1) +plt.ylim(0, 1) +plt.grid(True) +plt.legend() + +plt.xlabel("x") +plt.ylabel("y") +plt.title("Linear + Step + Smooth Cos² Ramp") + +plt.show() -- cgit v1.2.3 From e6e9cc9ce84539813e7e14fae5cdf3d4466fdeaf Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 26 Jun 2026 15:21:26 +0200 Subject: Added runs and script --- default.nix | 10 + .../.nix/derivation.nix | 41 ++ .../SConscript | 34 ++ .../SConstruct | 81 ++++ .../poiseulle_moving_particle_2d_psm_gpu/sim.cpp | 447 ++++++++++++++++++++ .../.nix/derivation.nix | 41 ++ .../stokes_drag_particle_2d_hlbm_gpu/SConscript | 34 ++ .../stokes_drag_particle_2d_hlbm_gpu/SConstruct | 81 ++++ examples/stokes_drag_particle_2d_hlbm_gpu/sim.cpp | 461 +++++++++++++++++++++ .../.nix/derivation.nix | 41 ++ .../stokes_drag_particle_2d_psm_gpu/SConscript | 34 ++ .../stokes_drag_particle_2d_psm_gpu/SConstruct | 81 ++++ examples/stokes_drag_particle_2d_psm_gpu/sim.cpp | 461 +++++++++++++++++++++ scripts/python/graph.py | 8 +- 14 files changed, 1852 insertions(+), 3 deletions(-) create mode 100644 examples/poiseulle_moving_particle_2d_psm_gpu/.nix/derivation.nix create mode 100644 examples/poiseulle_moving_particle_2d_psm_gpu/SConscript create mode 100644 examples/poiseulle_moving_particle_2d_psm_gpu/SConstruct create mode 100644 examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp create mode 100644 examples/stokes_drag_particle_2d_hlbm_gpu/.nix/derivation.nix create mode 100644 examples/stokes_drag_particle_2d_hlbm_gpu/SConscript create mode 100644 examples/stokes_drag_particle_2d_hlbm_gpu/SConstruct create mode 100644 examples/stokes_drag_particle_2d_hlbm_gpu/sim.cpp create mode 100644 examples/stokes_drag_particle_2d_psm_gpu/.nix/derivation.nix create mode 100644 examples/stokes_drag_particle_2d_psm_gpu/SConscript create mode 100644 examples/stokes_drag_particle_2d_psm_gpu/SConstruct create mode 100644 examples/stokes_drag_particle_2d_psm_gpu/sim.cpp diff --git a/default.nix b/default.nix index 53c11d3..29f4ba4 100644 --- a/default.nix +++ b/default.nix @@ -157,6 +157,16 @@ in rec { inherit kel; }; + stokes_drag_particle_2d_psm_gpu = pkgs.callPackage ./examples/stokes_drag_particle_2d_psm_gpu/.nix/derivation.nix { + inherit pname version stdenv forstio adaptive-cpp; + inherit kel; + }; + + stokes_drag_particle_2d_hlbm_gpu = pkgs.callPackage ./examples/stokes_drag_particle_2d_hlbm_gpu/.nix/derivation.nix { + inherit pname version stdenv forstio adaptive-cpp; + inherit kel; + }; + poiseulle_3d = pkgs.callPackage ./examples/poiseulle_3d/.nix/derivation.nix { inherit pname version stdenv forstio adaptive-cpp; inherit kel; diff --git a/examples/poiseulle_moving_particle_2d_psm_gpu/.nix/derivation.nix b/examples/poiseulle_moving_particle_2d_psm_gpu/.nix/derivation.nix new file mode 100644 index 0000000..d4c1b0f --- /dev/null +++ b/examples/poiseulle_moving_particle_2d_psm_gpu/.nix/derivation.nix @@ -0,0 +1,41 @@ +{ lib +, stdenv +, scons +, clang-tools +, forstio +, python3 +, pname +, version +, adaptive-cpp +, kel +}: + +stdenv.mkDerivation { + pname = pname + "-examples-" + "poiseulle_moving_particle_2d_psm_gpu"; + inherit version; + src = ./..; + + nativeBuildInputs = [ + scons + clang-tools + python3 + ]; + + buildInputs = [ + forstio.core + forstio.async + forstio.codec + forstio.codec-unit + forstio.io + forstio.remote + forstio.remote-filesystem + forstio.codec-json + adaptive-cpp + kel.lbm.core + kel.lbm.sycl + ]; + + preferLocalBuild = true; + + outputs = [ "out" "dev" ]; +} diff --git a/examples/poiseulle_moving_particle_2d_psm_gpu/SConscript b/examples/poiseulle_moving_particle_2d_psm_gpu/SConscript new file mode 100644 index 0000000..eb856b6 --- /dev/null +++ b/examples/poiseulle_moving_particle_2d_psm_gpu/SConscript @@ -0,0 +1,34 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +examples_env = env.Clone(); +examples_env['CXX'] = 'syclcc-clang'; +examples_env['CXXFLAGS'] += ['-O3']; + +examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += examples_env.sources; +env.headers += examples_env.headers; + +# Cavity2D +examples_objects = []; +examples_env.add_source_files(examples_objects, ['sim.cpp'], shared=False); +examples_env.poiseulle_2d_gpu = examples_env.Program('#bin/poiseulle_particles_2d_psm_gpu', [examples_objects]); + +# Set Alias +env.examples = [ + examples_env.poiseulle_2d_gpu +]; +env.Alias('examples', env.examples); +env.targets += ['examples']; +env.Install('$prefix/bin/', env.examples); diff --git a/examples/poiseulle_moving_particle_2d_psm_gpu/SConstruct b/examples/poiseulle_moving_particle_2d_psm_gpu/SConstruct new file mode 100644 index 0000000..0611b67 --- /dev/null +++ b/examples/poiseulle_moving_particle_2d_psm_gpu/SConstruct @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 + +import sys +import os +import os.path +import glob +import re + + +if sys.version_info < (3,): + def isbasestring(s): + return isinstance(s,basestring) +else: + def isbasestring(s): + return isinstance(s, (str,bytes)) + +def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""): + + if isbasestring(filetype): + dir_path = self.Dir('.').abspath + filetype = sorted(glob.glob(dir_path+"/"+filetype)) + + for path in filetype: + target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path ) + if shared: + target_name+='.os' + sources.append( self.SharedObject( target=target_name, source=path ) ) + else: + target_name+='.o' + sources.append( self.StaticObject( target=target_name, source=path ) ) + pass + +def isAbsolutePath(key, dirname, env): + assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,) + +env_vars = Variables( + args=ARGUMENTS +) + +env_vars.Add('prefix', + help='Installation target location of build results and headers', + default='/usr/local/', + validator=isAbsolutePath +) + +env_vars.Add('build_examples', + help='If examples should be built', + default="true" +) + +env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], + CPPDEFINES=['SAW_UNIX'], + CXXFLAGS=[ + '-std=c++20', + '-g', + '-Wall', + '-Wextra' + ], + LIBS=[ + 'forstio-core', + 'forstio-async', + 'forstio-io' + ] +); +env.__class__.add_source_files = add_kel_source_files +env.Tool('compilation_db'); +env.cdb = env.CompilationDatabase('compile_commands.json'); + +env.objects = []; +env.sources = []; +env.headers = []; +env.targets = []; + +Export('env') +SConscript('SConscript') + +env.Alias('cdb', env.cdb); +env.Alias('all', [env.targets]); +env.Default('all'); + +env.Alias('install', '$prefix') diff --git a/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp b/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp new file mode 100644 index 0000000..3001ba9 --- /dev/null +++ b/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp @@ -0,0 +1,447 @@ +#include +#include +#include + +#include +#include +#include +#include + +namespace kel { +namespace lbm { + +constexpr uint64_t dim_y = 256ul; +constexpr uint64_t dim_x = dim_y * 20ul; + +constexpr uint64_t particle_amount = 1ul; + +namespace sch { +using namespace saw::schema; + +using InfoChunk = Chunk; + +template +using DfChunk = Chunk, 1u, dim_x, dim_y>; + +template +using ScalarChunk = Chunk, 0u, dim_x, dim_y>; + +template +using VectorChunk = Chunk, 0u, dim_x, dim_y>; + +template +using ChunkStruct = Struct< + Member, + Member, "dfs">, + Member, "dfs_old">, + Member, "particle_N">, + Member, "particle_D"> +>; + +template +using VelChunk = Chunk, 0u, dim_x, dim_y>; + +template +using RhoChunk = Chunk, 0u, dim_x, dim_y>; + +template +using MacroStruct = Struct< + Member, "velocity">, + Member, "density">, + Member, "porosity"> +>; + +//template +//using ParticleArray = Array< +// Particle +//>; +} + +template +saw::error_or setup_initial_conditions( + saw::data>& fields, + saw::data>& macros +){ + auto& info_f = fields.template get<"info">(); + auto& porous_f = macros.template get<"porosity">(); + // Set everything as walls + iterator::apply( + [&](auto& index){ + info_f.at(index).set(1u); + }, + {}, + info_f.get_dims(), + {} + ); + // Fluid + iterator::apply( + [&](auto& index){ + info_f.at(index).set(2u); + }, + {}, + info_f.get_dims(), + {{1u,1u}} + ); + // Corners + /// Inflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(5u); + }, + {{0u,0u}}, + {{1u,dim_y}} + ); + /// Outflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(5u); + }, + {{dim_x-1u,0u}}, + {{dim_x, dim_y}} + ); + // Overwrite with + // Inflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(3u); + }, + {{0u,0u}}, + {{1u,dim_y}}, + {{0u,1u}} + ); + + // Outflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(4u); + }, + {{dim_x-1u,0u}}, + {{dim_x, dim_y}}, + {{0u,1u}} + ); + // + auto& df_f = fields.template get<"dfs_old">(); + auto& rho_f = macros.template get<"density">(); + auto& vel_f = macros.template get<"velocity">(); + auto& por_f = macros.template get<"porosity">(); + + iterator::apply( + [&](auto& index){ + auto& df = df_f.at(index); + auto& rho = rho_f.at(index); + por_f.at(index).at({}) = {1}; + rho.at({}) = {1}; + auto& vel = vel_f.at(index); + auto eq = equilibrium(rho,vel); + + df = eq; + }, + {},// 0-index + df_f.get_dims() + ); + + iterator::apply( + [&](auto& index){ + auto& df = df_f.at(index); + auto& rho = rho_f.at(index); + rho.at({}) = {1}; + auto& vel = vel_f.at(index); + if(info_f.at(index).get() == 2u){ + vel.at({{0u}}) = 0.0; + } + auto eq = equilibrium(rho,vel); + + df = eq; + }, + {},// 0-index + df_f.get_dims(), + {{1u,1u}} + ); + + iterator::apply( + [&](auto& index){ + saw::data> middle, ind_vec; + middle.at({{0u}}) = dim_x * 0.5; + 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(); + + auto dist = middle - ind_vec; + auto dist_2 = saw::math::dot(dist,dist); + if(dist_2.at({}).get() < dim_y*dim_y*0.01){ + porous_f.at(index).at({}) = 0.0; + } + }, + {},// 0-index + df_f.get_dims() + ); + + return saw::make_void(); +} + +template +saw::error_or step( + saw::data>,encode::Sycl>& fields, + saw::data>,encode::Sycl>& macros, + saw::data t_i, + device& dev +){ + auto& q = dev.get_handle(); + auto& info_f = fields.template get<"info">(); + auto& porous_f = macros.template get<"porosity">(); + + q.submit([&](acpp::sycl::handler& h){ + component> collision{0.8}; + component> bb; + component,encode::Sycl> abb; + + component,encode::Sycl> flow_in{1.0}; + component,encode::Sycl> flow_out{1.0}; + + component> opa; + + h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ + saw::data> index; + for(uint64_t i = 0u; i < Desc::D; ++i){ + index.at({{i}}).set(idx[i]); + } + + auto info = info_f.at(index); + + switch(info.get()){ + case 0u: + break; + case 1u: + bb.apply(fields,index,t_i); + break; + case 2u: + collision.apply(fields,macros,index,t_i); + break; + case 3u: + flow_in.apply(fields,index,t_i); + //equi.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); + collision.apply(fields,macros,index,t_i); + break; + case 5u: + // Corners + bb.apply(fields,index,t_i); + break; + default: + break; + } + }); + }).wait(); + + + // Step + /* + q.submit([&](acpp::sycl::handler& h){ + // h.depends_on(collision_ev); + }).wait(); + */ + + return saw::make_void(); +} +} +} + +template +saw::error_or lbm_main(int argc, char** argv){ + using namespace kel::lbm; + + using dfi = df_info; + + auto eo_lbm_dir = output_directory(); + if(eo_lbm_dir.is_error()){ + return std::move(eo_lbm_dir.get_error()); + } + auto& lbm_dir = eo_lbm_dir.get_value(); + + auto out_dir = lbm_dir / "poiseulle_moving_particle_2d_psm_gpu"; + + { + std::error_code ec; + std::filesystem::create_directories(out_dir,ec); + if(ec != std::errc{}){ + return saw::make_error("Could not create output directory"); + } + } + + converter conv { + // delta_x + {{1.0}}, + // delta_t + {{1.0}} + }; + + print_lbm_meta(conv,{0.1},{1e-4},{0.4 * dim_y}); + + // saw::data> meta{{dim_x,dim_y}}; + auto lbm_data_ptr = saw::heap>>(); + auto lbm_macro_data_ptr = saw::heap>>(); + + std::cout<<"Estimated Bytes: "<,sch::MacroStruct>().get()<(*lbm_data_ptr,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_vtk_file(out_dir,"initial_state",0u,*lbm_data_ptr); + if(eov.is_error()){ + return eov; + } + } + + saw::data, encode::Sycl> lbm_sycl_data{sycl_q}; + saw::data, encode::Sycl> lbm_sycl_macro_data{sycl_q}; + sycl_q.wait(); + + { + auto eov = dev.copy_to_device(*lbm_data_ptr,lbm_sycl_data); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = dev.copy_to_device(*lbm_macro_data_ptr,lbm_sycl_macro_data); + 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); + + saw::data time_steps{16u*4096ul}; + + auto& info_f = lsd_view.template get<"info">(); + + for(saw::data i{0u}; i < time_steps and krun; ++i){ + // BC + Collision + { + auto eov = step(lsd_view,lsdm_view,i,dev); + if(eov.is_error()){ + return eov; + } + } + sycl_q.wait(); + /* + if(i.get() % 32u == 0u){ + { + auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_vtk_file(out_dir,"m",i.get(), *lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + } + */ + if(i.get() % 32u == 0u){ + { + auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_csv_file(out_dir,"m",i.get(), *lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + } + // Stream + sycl_q.submit([&](acpp::sycl::handler& h){ + component> stream; + + h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ + saw::data> index; + for(uint64_t i = 0u; i < Desc::D; ++i){ + index.at({{i}}).set(idx[i]); + } + + auto info = info_f.at(index); + + if(info.get() > 0u){ + stream.apply(lsd_view,index,i); + } + }); + }).wait(); + wait.poll(); + if(print_status){ + std::cout<<"Status: "<().get() * 100 / time_steps.get())<<"%"<(argc, argv); + if(eov.is_error()){ + auto& err = eov.get_error(); + std::cerr<<"[Error] "< 0u){ + std::cerr<<" - "< +#include +#include + +#include +#include +#include +#include + +namespace kel { +namespace lbm { + +constexpr uint64_t dim_y = 1024ul; +constexpr uint64_t dim_x = dim_y * 2ul; + +constexpr uint64_t particle_amount = 1ul; + +namespace sch { +using namespace saw::schema; + +using InfoChunk = Chunk; + +template +using DfChunk = Chunk, 1u, dim_x, dim_y>; + +template +using ScalarChunk = Chunk, 0u, dim_x, dim_y>; + +template +using VectorChunk = Chunk, 0u, dim_x, dim_y>; + +template +using ChunkStruct = Struct< + Member, + Member, "dfs">, + Member, "dfs_old">, + Member, "particle_N">, + Member, "particle_D"> +>; + +template +using VelChunk = Chunk, 0u, dim_x, dim_y>; + +template +using RhoChunk = Chunk, 0u, dim_x, dim_y>; + +template +using MacroStruct = Struct< + Member, "velocity">, + Member, "density">, + Member, "porosity"> +>; + +//template +//using ParticleArray = Array< +// Particle +//>; +} + +template +saw::error_or setup_initial_conditions( + saw::data>& fields, + saw::data>& macros +){ + auto& info_f = fields.template get<"info">(); + auto& porous_f = macros.template get<"porosity">(); + // Set everything as walls + iterator::apply( + [&](auto& index){ + info_f.at(index).set(1u); + }, + {}, + info_f.get_dims(), + {} + ); + // Fluid + iterator::apply( + [&](auto& index){ + info_f.at(index).set(2u); + }, + {}, + info_f.get_dims(), + {{1u,1u}} + ); + // Corners + /// Inflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(5u); + }, + {{0u,0u}}, + {{1u,dim_y}} + ); + /// Outflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(5u); + }, + {{dim_x-1u,0u}}, + {{dim_x, dim_y}} + ); + // Overwrite with + // Inflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(3u); + }, + {{0u,0u}}, + {{1u,dim_y}}, + {{0u,1u}} + ); + + // Outflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(4u); + }, + {{dim_x-1u,0u}}, + {{dim_x, dim_y}}, + {{0u,1u}} + ); + // + auto& df_f = fields.template get<"dfs_old">(); + auto& rho_f = macros.template get<"density">(); + auto& vel_f = macros.template get<"velocity">(); + auto& por_f = macros.template get<"porosity">(); + + iterator::apply( + [&](auto& index){ + auto& df = df_f.at(index); + auto& rho = rho_f.at(index); + por_f.at(index).at({}) = {1}; + rho.at({}) = {1}; + auto& vel = vel_f.at(index); + auto eq = equilibrium(rho,vel); + + df = eq; + }, + {},// 0-index + df_f.get_dims() + ); + + iterator::apply( + [&](auto& index){ + auto& df = df_f.at(index); + auto& rho = rho_f.at(index); + rho.at({}) = {1}; + auto& vel = vel_f.at(index); + if(info_f.at(index).get() == 2u){ + vel.at({{0u}}) = 0.0; + } + auto eq = equilibrium(rho,vel); + + df = eq; + }, + {},// 0-index + df_f.get_dims(), + {{1u,1u}} + ); + + iterator::apply( + [&](auto& index){ + saw::data> middle, ind_vec; + middle.at({{0u}}) = dim_x * 0.5; + 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(); + + auto dist = middle - ind_vec; + auto dist_2 = saw::math::dot(dist,dist); + if(dist_2.at({}).get() < dim_y*dim_y*0.01){ + porous_f.at(index).at({}) = 0.0; + } + }, + {},// 0-index + df_f.get_dims() + ); + + return saw::make_void(); +} + +template +saw::error_or step( + saw::data>,encode::Sycl>& fields, + saw::data>,encode::Sycl>& macros, + saw::data t_i, + device& dev +){ + auto& q = dev.get_handle(); + auto& info_f = fields.template get<"info">(); + auto& porous_f = macros.template get<"porosity">(); + + q.submit([&](acpp::sycl::handler& h){ + component> collision{0.8}; + component> bb; + component,encode::Sycl> abb; + + saw::data> rho_b; + rho_b.at({}) = 1.0; + saw::data> vel_b; + vel_b.at({{0u}}) = 0.015; + + component> equi{rho_b,vel_b}; + + component,encode::Sycl> flow_in{ + [&](){ + uint64_t target_t_i = 64u; + if(t_i.get() < target_t_i){ + return 1.0 + (0.0002 / target_t_i) * t_i.get(); + } + return 1.0002; + }() + }; + component,encode::Sycl> flow_out{1.0}; + + + h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ + saw::data> index; + for(uint64_t i = 0u; i < Desc::D; ++i){ + index.at({{i}}).set(idx[i]); + } + + auto info = info_f.at(index); + + switch(info.get()){ + case 0u: + break; + case 1u: + abb.apply(fields,index,t_i); + break; + case 2u: + collision.apply(fields,macros,index,t_i); + break; + case 3u: + flow_in.apply(fields,index,t_i); + //equi.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); + collision.apply(fields,macros,index,t_i); + break; + case 5u: + // Corners + bb.apply(fields,index,t_i); + break; + default: + break; + } + }); + }).wait(); + + + // Step + /* + q.submit([&](acpp::sycl::handler& h){ + // h.depends_on(collision_ev); + }).wait(); + */ + + return saw::make_void(); +} +} +} + +template +saw::error_or lbm_main(int argc, char** argv){ + using namespace kel::lbm; + + using dfi = df_info; + + auto eo_lbm_dir = output_directory(); + if(eo_lbm_dir.is_error()){ + return std::move(eo_lbm_dir.get_error()); + } + auto& lbm_dir = eo_lbm_dir.get_value(); + + auto out_dir = lbm_dir / "stokes_drag_particle_2d_hlbm_gpu"; + + { + std::error_code ec; + std::filesystem::create_directories(out_dir,ec); + if(ec != std::errc{}){ + return saw::make_error("Could not create output directory"); + } + } + + converter conv { + // delta_x + {{1.0}}, + // delta_t + {{1.0}} + }; + + print_lbm_meta(conv,{0.1},{1e-4},{0.4 * dim_y}); + + // saw::data> meta{{dim_x,dim_y}}; + auto lbm_data_ptr = saw::heap>>(); + auto lbm_macro_data_ptr = saw::heap>>(); + + std::cout<<"Estimated Bytes: "<,sch::MacroStruct>().get()<(*lbm_data_ptr,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_vtk_file(out_dir,"initial_state",0u,*lbm_data_ptr); + if(eov.is_error()){ + return eov; + } + } + + saw::data, encode::Sycl> lbm_sycl_data{sycl_q}; + saw::data, encode::Sycl> lbm_sycl_macro_data{sycl_q}; + sycl_q.wait(); + + { + auto eov = dev.copy_to_device(*lbm_data_ptr,lbm_sycl_data); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = dev.copy_to_device(*lbm_macro_data_ptr,lbm_sycl_macro_data); + 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); + + saw::data time_steps{16u*4096ul}; + + auto& info_f = lsd_view.template get<"info">(); + + for(saw::data i{0u}; i < time_steps and krun; ++i){ + // BC + Collision + { + auto eov = step(lsd_view,lsdm_view,i,dev); + if(eov.is_error()){ + return eov; + } + } + sycl_q.wait(); + /* + if(i.get() % 32u == 0u){ + { + auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_vtk_file(out_dir,"m",i.get(), *lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + } + */ + if(i.get() % 32u == 0u){ + { + auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_csv_file(out_dir,"m",i.get(), *lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + } + // Stream + sycl_q.submit([&](acpp::sycl::handler& h){ + component> stream; + + h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ + saw::data> index; + for(uint64_t i = 0u; i < Desc::D; ++i){ + index.at({{i}}).set(idx[i]); + } + + auto info = info_f.at(index); + + if(info.get() > 0u){ + stream.apply(lsd_view,index,i); + } + }); + }).wait(); + wait.poll(); + if(print_status){ + std::cout<<"Status: "<().get() * 100 / time_steps.get())<<"%"<(argc, argv); + if(eov.is_error()){ + auto& err = eov.get_error(); + std::cerr<<"[Error] "< 0u){ + std::cerr<<" - "< +#include +#include + +#include +#include +#include +#include + +namespace kel { +namespace lbm { + +constexpr uint64_t dim_y = 1024ul; +constexpr uint64_t dim_x = dim_y * 2ul; + +constexpr uint64_t particle_amount = 1ul; + +namespace sch { +using namespace saw::schema; + +using InfoChunk = Chunk; + +template +using DfChunk = Chunk, 1u, dim_x, dim_y>; + +template +using ScalarChunk = Chunk, 0u, dim_x, dim_y>; + +template +using VectorChunk = Chunk, 0u, dim_x, dim_y>; + +template +using ChunkStruct = Struct< + Member, + Member, "dfs">, + Member, "dfs_old">, + Member, "particle_N">, + Member, "particle_D"> +>; + +template +using VelChunk = Chunk, 0u, dim_x, dim_y>; + +template +using RhoChunk = Chunk, 0u, dim_x, dim_y>; + +template +using MacroStruct = Struct< + Member, "velocity">, + Member, "density">, + Member, "porosity"> +>; + +//template +//using ParticleArray = Array< +// Particle +//>; +} + +template +saw::error_or setup_initial_conditions( + saw::data>& fields, + saw::data>& macros +){ + auto& info_f = fields.template get<"info">(); + auto& porous_f = macros.template get<"porosity">(); + // Set everything as walls + iterator::apply( + [&](auto& index){ + info_f.at(index).set(1u); + }, + {}, + info_f.get_dims(), + {} + ); + // Fluid + iterator::apply( + [&](auto& index){ + info_f.at(index).set(2u); + }, + {}, + info_f.get_dims(), + {{1u,1u}} + ); + // Corners + /// Inflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(5u); + }, + {{0u,0u}}, + {{1u,dim_y}} + ); + /// Outflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(5u); + }, + {{dim_x-1u,0u}}, + {{dim_x, dim_y}} + ); + // Overwrite with + // Inflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(3u); + }, + {{0u,0u}}, + {{1u,dim_y}}, + {{0u,1u}} + ); + + // Outflow + iterator::apply( + [&](auto& index){ + info_f.at(index).set(4u); + }, + {{dim_x-1u,0u}}, + {{dim_x, dim_y}}, + {{0u,1u}} + ); + // + auto& df_f = fields.template get<"dfs_old">(); + auto& rho_f = macros.template get<"density">(); + auto& vel_f = macros.template get<"velocity">(); + auto& por_f = macros.template get<"porosity">(); + + iterator::apply( + [&](auto& index){ + auto& df = df_f.at(index); + auto& rho = rho_f.at(index); + por_f.at(index).at({}) = {1}; + rho.at({}) = {1}; + auto& vel = vel_f.at(index); + auto eq = equilibrium(rho,vel); + + df = eq; + }, + {},// 0-index + df_f.get_dims() + ); + + iterator::apply( + [&](auto& index){ + auto& df = df_f.at(index); + auto& rho = rho_f.at(index); + rho.at({}) = {1}; + auto& vel = vel_f.at(index); + if(info_f.at(index).get() == 2u){ + vel.at({{0u}}) = 0.0; + } + auto eq = equilibrium(rho,vel); + + df = eq; + }, + {},// 0-index + df_f.get_dims(), + {{1u,1u}} + ); + + iterator::apply( + [&](auto& index){ + saw::data> middle, ind_vec; + middle.at({{0u}}) = dim_x * 0.5; + 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(); + + auto dist = middle - ind_vec; + auto dist_2 = saw::math::dot(dist,dist); + if(dist_2.at({}).get() < dim_y*dim_y*0.01){ + porous_f.at(index).at({}) = 0.0; + } + }, + {},// 0-index + df_f.get_dims() + ); + + return saw::make_void(); +} + +template +saw::error_or step( + saw::data>,encode::Sycl>& fields, + saw::data>,encode::Sycl>& macros, + saw::data t_i, + device& dev +){ + auto& q = dev.get_handle(); + auto& info_f = fields.template get<"info">(); + auto& porous_f = macros.template get<"porosity">(); + + q.submit([&](acpp::sycl::handler& h){ + component> collision{0.8}; + component> bb; + component,encode::Sycl> abb; + + saw::data> rho_b; + rho_b.at({}) = 1.0; + saw::data> vel_b; + vel_b.at({{0u}}) = 0.015; + + component> equi{rho_b,vel_b}; + + component,encode::Sycl> flow_in{ + [&](){ + uint64_t target_t_i = 64u; + if(t_i.get() < target_t_i){ + return 1.0 + (0.0002 / target_t_i) * t_i.get(); + } + return 1.0002; + }() + }; + component,encode::Sycl> flow_out{1.0}; + + + h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ + saw::data> index; + for(uint64_t i = 0u; i < Desc::D; ++i){ + index.at({{i}}).set(idx[i]); + } + + auto info = info_f.at(index); + + switch(info.get()){ + case 0u: + break; + case 1u: + abb.apply(fields,index,t_i); + break; + case 2u: + collision.apply(fields,macros,index,t_i); + break; + case 3u: + flow_in.apply(fields,index,t_i); + //equi.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); + collision.apply(fields,macros,index,t_i); + break; + case 5u: + // Corners + bb.apply(fields,index,t_i); + break; + default: + break; + } + }); + }).wait(); + + + // Step + /* + q.submit([&](acpp::sycl::handler& h){ + // h.depends_on(collision_ev); + }).wait(); + */ + + return saw::make_void(); +} +} +} + +template +saw::error_or lbm_main(int argc, char** argv){ + using namespace kel::lbm; + + using dfi = df_info; + + auto eo_lbm_dir = output_directory(); + if(eo_lbm_dir.is_error()){ + return std::move(eo_lbm_dir.get_error()); + } + auto& lbm_dir = eo_lbm_dir.get_value(); + + auto out_dir = lbm_dir / "stokes_drag_particle_2d_psm_gpu"; + + { + std::error_code ec; + std::filesystem::create_directories(out_dir,ec); + if(ec != std::errc{}){ + return saw::make_error("Could not create output directory"); + } + } + + converter conv { + // delta_x + {{1.0}}, + // delta_t + {{1.0}} + }; + + print_lbm_meta(conv,{0.1},{1e-4},{0.4 * dim_y}); + + // saw::data> meta{{dim_x,dim_y}}; + auto lbm_data_ptr = saw::heap>>(); + auto lbm_macro_data_ptr = saw::heap>>(); + + std::cout<<"Estimated Bytes: "<,sch::MacroStruct>().get()<(*lbm_data_ptr,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_vtk_file(out_dir,"initial_state",0u,*lbm_data_ptr); + if(eov.is_error()){ + return eov; + } + } + + saw::data, encode::Sycl> lbm_sycl_data{sycl_q}; + saw::data, encode::Sycl> lbm_sycl_macro_data{sycl_q}; + sycl_q.wait(); + + { + auto eov = dev.copy_to_device(*lbm_data_ptr,lbm_sycl_data); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = dev.copy_to_device(*lbm_macro_data_ptr,lbm_sycl_macro_data); + 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); + + saw::data time_steps{16u*4096ul}; + + auto& info_f = lsd_view.template get<"info">(); + + for(saw::data i{0u}; i < time_steps and krun; ++i){ + // BC + Collision + { + auto eov = step(lsd_view,lsdm_view,i,dev); + if(eov.is_error()){ + return eov; + } + } + sycl_q.wait(); + /* + if(i.get() % 32u == 0u){ + { + auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_vtk_file(out_dir,"m",i.get(), *lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + } + */ + if(i.get() % 32u == 0u){ + { + auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_csv_file(out_dir,"m",i.get(), *lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + } + // Stream + sycl_q.submit([&](acpp::sycl::handler& h){ + component> stream; + + h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ + saw::data> index; + for(uint64_t i = 0u; i < Desc::D; ++i){ + index.at({{i}}).set(idx[i]); + } + + auto info = info_f.at(index); + + if(info.get() > 0u){ + stream.apply(lsd_view,index,i); + } + }); + }).wait(); + wait.poll(); + if(print_status){ + std::cout<<"Status: "<().get() * 100 / time_steps.get())<<"%"<(argc, argv); + if(eov.is_error()){ + auto& err = eov.get_error(); + std::cerr<<"[Error] "< 0u){ + std::cerr<<" - "< Date: Sat, 27 Jun 2026 23:54:56 +0200 Subject: Helper component which resets the field porosity --- lib/core/c++/particle/particle_opa.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/core/c++/particle/particle_opa.hpp diff --git a/lib/core/c++/particle/particle_opa.hpp b/lib/core/c++/particle/particle_opa.hpp new file mode 100644 index 0000000..470c4e9 --- /dev/null +++ b/lib/core/c++/particle/particle_opa.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "component.hpp" + +namespace kel { +namespace lbm { +namespace cmpt { +struct OneParticleAt {}; +} + +template + +class component final { +private: +public: + component() = default; + + template + void apply(const saw::data& macros, const saw::data> index, saw::data time_step) const { + using dfi = df_info; + + auto& porous_f = macros.template get<"porosity">(); + + auto& porous = porous_f.at(index); + + + } +}; +} +} -- cgit v1.2.3 From 7a7d681ce70133ef0bc47a701f5b8448b15b3a29 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 28 Jun 2026 19:17:52 +0200 Subject: Dangling --- default.nix | 5 +++++ .../poiseulle_moving_particle_2d_psm_gpu/SConscript | 2 +- .../poiseulle_moving_particle_2d_psm_gpu/sim.cpp | 2 +- lib/core/c++/particle/particle.hpp | 1 + lib/core/c++/particle/particle_opa.hpp | 20 ++++++++++++++++++-- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/default.nix b/default.nix index 29f4ba4..dc75b57 100644 --- a/default.nix +++ b/default.nix @@ -151,6 +151,11 @@ in rec { inherit pname version stdenv forstio adaptive-cpp; inherit kel; }; + + poiseulle_moving_particle_2d_psm_gpu = pkgs.callPackage ./examples/poiseulle_moving_particle_2d_psm_gpu/.nix/derivation.nix { + inherit pname version stdenv forstio adaptive-cpp; + inherit kel; + }; poiseulle_particles_2d_gpu = pkgs.callPackage ./examples/poiseulle_particles_2d_gpu/.nix/derivation.nix { inherit pname version stdenv forstio adaptive-cpp; diff --git a/examples/poiseulle_moving_particle_2d_psm_gpu/SConscript b/examples/poiseulle_moving_particle_2d_psm_gpu/SConscript index eb856b6..b062091 100644 --- a/examples/poiseulle_moving_particle_2d_psm_gpu/SConscript +++ b/examples/poiseulle_moving_particle_2d_psm_gpu/SConscript @@ -23,7 +23,7 @@ env.headers += examples_env.headers; # Cavity2D examples_objects = []; examples_env.add_source_files(examples_objects, ['sim.cpp'], shared=False); -examples_env.poiseulle_2d_gpu = examples_env.Program('#bin/poiseulle_particles_2d_psm_gpu', [examples_objects]); +examples_env.poiseulle_2d_gpu = examples_env.Program('#bin/poiseulle_moving_particle_2d_psm_gpu', [examples_objects]); # Set Alias env.examples = [ diff --git a/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp b/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp index 3001ba9..0c10d38 100644 --- a/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp +++ b/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp @@ -199,7 +199,7 @@ saw::error_or step( component,encode::Sycl> flow_in{1.0}; component,encode::Sycl> flow_out{1.0}; - component> opa; + component> opa{{},{}}; h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ saw::data> index; diff --git a/lib/core/c++/particle/particle.hpp b/lib/core/c++/particle/particle.hpp index 13ed37b..8e75e5a 100644 --- a/lib/core/c++/particle/particle.hpp +++ b/lib/core/c++/particle/particle.hpp @@ -8,6 +8,7 @@ #include "schema.hpp" #include "aabb.hpp" +#include "particle_opa.hpp" namespace kel { namespace lbm { diff --git a/lib/core/c++/particle/particle_opa.hpp b/lib/core/c++/particle/particle_opa.hpp index 470c4e9..4588a55 100644 --- a/lib/core/c++/particle/particle_opa.hpp +++ b/lib/core/c++/particle/particle_opa.hpp @@ -1,6 +1,7 @@ #pragma once -#include "component.hpp" +#include "common.hpp" +#include "../component.hpp" namespace kel { namespace lbm { @@ -12,8 +13,19 @@ template class component final { private: + saw::data> pos_; + saw::data> rad_; + saw::data> eps_; public: - component() = default; + component( + const saw::data> pos__, + const saw::data> rad__, + const saw::data> eps__ + ): + pos_{pos__}, + rad_{rad__}, + eps_{eps__} + {} template void apply(const saw::data& macros, const saw::data> index, saw::data time_step) const { @@ -24,6 +36,10 @@ public: auto& porous = porous_f.at(index); + auto pos_ind = saw::math::vectorize_data(index); + + auto diff = pos_ind - pos_; + auto diff_dot = saw::math::dot(diff,diff); } }; } -- cgit v1.2.3 From 283ff837896c805bddf4962caaa54c26aa8bab1f Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 28 Jun 2026 19:35:07 +0200 Subject: Doing porosity work --- lib/core/c++/particle/porosity.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/core/c++/particle/porosity.hpp b/lib/core/c++/particle/porosity.hpp index 39d9652..f555cae 100644 --- a/lib/core/c++/particle/porosity.hpp +++ b/lib/core/c++/particle/porosity.hpp @@ -28,10 +28,17 @@ public: }; + template::type radius, typename saw::native_data_type::type eps> class particle_porosity> final { public: - saw::data> calculate(const saw::data > >& part_group, uint64_t i, const saw::data>& lbm_pos){ + saw::data> calculate(const saw::data>& lbm_pos, saw::data> rad) const { + saw::data> pos; + + + } + + saw::data> calculate(const saw::data > >& part_group, uint64_t i, const saw::data>& lbm_pos) const { saw::data> por; por.at({}); -- cgit v1.2.3