From dcee24278ed28d21cd3addffeeb8e5f9f7248602 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 17 Feb 2026 18:29:22 +0100 Subject: End of day --- examples/poiseulle_3d_gpu/sim.cpp | 16 ++++---- examples/poiseulle_particles_2d_gpu/sim.cpp | 16 ++++---- lib/core/c++/descriptor.hpp | 10 +++-- lib/core/c++/environment.hpp | 1 + lib/core/c++/equilibrium.hpp | 3 +- lib/core/c++/lbm.hpp | 1 + lib/core/c++/memory.hpp | 62 +++++++++++++++++++++++++++++ lib/core/c++/write_vtk.hpp | 22 +++++++++- lib/core/tests/memory.cpp | 18 +++++++++ lib/core/tests/particles.cpp | 23 +++++++++++ 10 files changed, 148 insertions(+), 24 deletions(-) create mode 100644 lib/core/c++/memory.hpp create mode 100644 lib/core/tests/memory.cpp diff --git a/examples/poiseulle_3d_gpu/sim.cpp b/examples/poiseulle_3d_gpu/sim.cpp index 27e5297..624566f 100644 --- a/examples/poiseulle_3d_gpu/sim.cpp +++ b/examples/poiseulle_3d_gpu/sim.cpp @@ -265,16 +265,20 @@ saw::error_or lbm_main(int argc, char** argv){ } } - converter conv { + converter conv { // delta_x {{1.0}}, // delta_t {{1.0}} }; + print_lbm_meta(conv,{0.01}); + auto lbm_data_ptr = saw::heap>>(); auto lbm_macro_data_ptr = saw::heap>>(); auto lbm_particle_data_ptr = saw::heap, particle_size>>>(); + + std::cout<<"Estimated Bytes: "<,sch::MacroStruct>().get()< lbm_main(int argc, char** argv){ for(saw::data i{0u}; i < time_steps and krun; ++i){ { { - std::string file_name = "t_"; - file_name += std::to_string(i.get()); - file_name += ".vtk"; - auto eov = write_vtk_file(out_dir/file_name, *lbm_macro_data_ptr); + auto eov = write_vtk_file(out_dir,"t",i.get(),*lbm_macro_data_ptr); if(eov.is_error()){ return eov; } @@ -380,10 +381,7 @@ saw::error_or lbm_main(int argc, char** argv){ } sycl_q.wait(); { - std::string file_name = "t_"; - file_name += std::to_string(time_steps.get()); - file_name += ".vtk"; - auto eov = write_vtk_file(out_dir/file_name, *lbm_macro_data_ptr); + auto eov = write_vtk_file(out_dir,"t",time_steps.get(),*lbm_macro_data_ptr); if(eov.is_error()){ return eov; } diff --git a/examples/poiseulle_particles_2d_gpu/sim.cpp b/examples/poiseulle_particles_2d_gpu/sim.cpp index d12b7f5..de2bb40 100644 --- a/examples/poiseulle_particles_2d_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_gpu/sim.cpp @@ -264,17 +264,21 @@ saw::error_or lbm_main(int argc, char** argv){ } } - converter conv { + converter conv { // delta_x {{1.0}}, // delta_t {{1.0}} }; + + print_lbm_meta(conv,{0.01}); // saw::data> meta{{dim_x,dim_y}}; auto lbm_data_ptr = saw::heap>>(); auto lbm_macro_data_ptr = saw::heap>>(); auto lbm_particle_data_ptr = saw::heap, particle_size>>>(); + + std::cout<<"Estimated Bytes: "<,sch::MacroStruct>().get()< lbm_main(int argc, char** argv){ for(saw::data i{0u}; i < time_steps and krun; ++i){ { { - std::string file_name = "t_"; - file_name += std::to_string(i.get()); - file_name += ".vtk"; - auto eov = write_vtk_file(out_dir/file_name, *lbm_macro_data_ptr); + auto eov = write_vtk_file(out_dir,"t",i.get(), *lbm_macro_data_ptr); if(eov.is_error()){ return eov; } @@ -380,10 +381,7 @@ saw::error_or lbm_main(int argc, char** argv){ } sycl_q.wait(); { - std::string file_name = "t_"; - file_name += std::to_string(time_steps.get()); - file_name += ".vtk"; - auto eov = write_vtk_file(out_dir/file_name, *lbm_macro_data_ptr); + auto eov = write_vtk_file(out_dir,"t",time_steps.get(), *lbm_macro_data_ptr); if(eov.is_error()){ return eov; } diff --git a/lib/core/c++/descriptor.hpp b/lib/core/c++/descriptor.hpp index 9cc2591..e38daee 100644 --- a/lib/core/c++/descriptor.hpp +++ b/lib/core/c++/descriptor.hpp @@ -180,6 +180,7 @@ public: static constexpr std::array, Q> directions = {{ { 0, 0, 0}, // 0 + // Into 1D {-1, 0, 0}, // 1 { 1, 0, 0}, // 2 // Expand into 2D @@ -212,14 +213,17 @@ public: static constexpr std::array::type,Q> weights = { 8./27., - 1./9., - 1./9., - 1./9., + // 1D + 2./27., + 2./27., + // 2D + 2./27., 1./9., 1./36., 1./36., 1./36., 1./36., + // 3D 8./27., 1./9., 1./9., diff --git a/lib/core/c++/environment.hpp b/lib/core/c++/environment.hpp index 4915e3a..9e587d0 100644 --- a/lib/core/c++/environment.hpp +++ b/lib/core/c++/environment.hpp @@ -20,5 +20,6 @@ saw::error_or output_directory(){ return std::filesystem::path{home_dir} / ".lbm"; } + } } diff --git a/lib/core/c++/equilibrium.hpp b/lib/core/c++/equilibrium.hpp index 7d1324e..eb2b043 100644 --- a/lib/core/c++/equilibrium.hpp +++ b/lib/core/c++/equilibrium.hpp @@ -9,6 +9,7 @@ saw::data> equilibrium(saw::data; saw::data> eq; + // Brain broken, here's an owl // ^ // 0.0 // / \ @@ -23,7 +24,7 @@ saw::data> equilibrium(saw::data(); ++i){ + for(uint64_t i = 0u; i < Descriptor::Q; ++i){ saw::data vel_c{}; for(uint64_t j = 0u; j < Descriptor::D; ++j){ // _2 diff --git a/lib/core/c++/lbm.hpp b/lib/core/c++/lbm.hpp index 24f93f1..df89a69 100644 --- a/lib/core/c++/lbm.hpp +++ b/lib/core/c++/lbm.hpp @@ -14,6 +14,7 @@ #include "iterator.hpp" #include "hlbm.hpp" #include "macroscopic.hpp" +#include "memory.hpp" #include "stream.hpp" #include "write_vtk.hpp" #include "util.hpp" diff --git a/lib/core/c++/memory.hpp b/lib/core/c++/memory.hpp new file mode 100644 index 0000000..b6a089e --- /dev/null +++ b/lib/core/c++/memory.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include "common.hpp" +#include "chunk.hpp" + +namespace kel { +namespace lbm { + +namespace impl { + +template +struct memory_size_helper; + +template +struct memory_size_helper> { + static constexpr uint64_t bytes = N; +}; + +template +struct memory_size_helper> { + static constexpr uint64_t bytes = saw::ct_multiply::value * memory_size_helper::bytes; +}; + +template +struct memory_size_helper> { + static constexpr uint64_t bytes = memory_size_helper::InnerSchema>::bytes; +}; + +template +class memory_estimate_helper final { +private: + + template + static void apply_i(saw::data& bytes){ + + if constexpr ( i < sizeof...(T)){ + using T_I = typename saw::parameter_pack_type::type; + + bytes.set(bytes.get() + memory_size_helper::bytes); + + apply_i(bytes); + } + } + +public: + + static void apply(saw::data& bytes){ + apply_i<0u>(bytes); + } +}; +} + +template +saw::data memory_estimate(){ + saw::data bytes; + + impl::memory_estimate_helper::apply(bytes); + + return bytes; +} +} +} diff --git a/lib/core/c++/write_vtk.hpp b/lib/core/c++/write_vtk.hpp index f7b8f8f..f925361 100644 --- a/lib/core/c++/write_vtk.hpp +++ b/lib/core/c++/write_vtk.hpp @@ -222,9 +222,27 @@ struct lbm_vtk_writer, } template -saw::error_or write_vtk_file(const std::filesystem::path& file_name, const saw::data& field){ +saw::error_or write_vtk_file(const std::filesystem::path& out_dir, const std::string_view& file_name, uint64_t d_t, const saw::data& field){ + + auto vtk_dir = out_dir / "vtk"; + { + std::error_code ec; + std::filesystem::create_directories(vtk_dir,ec); + if(ec != std::errc{}){ + return saw::make_error("Could not create directory for write_vtk_file function"); + } + } + std::string ft_name{file_name}; + + std::stringstream sstr; + sstr + <("Could not open file."); diff --git a/lib/core/tests/memory.cpp b/lib/core/tests/memory.cpp new file mode 100644 index 0000000..27cd938 --- /dev/null +++ b/lib/core/tests/memory.cpp @@ -0,0 +1,18 @@ +#include + +#include "../c++/memory.hpp" + +namespace { +namespace sch { +using namespace saw::schema; +} + +SAW_TEST("Memory Estimate"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate().get() == 4u), std::string{"Float32 isn't 4 bytes, but "} + std::to_string(memory_estimate().get()) ); + SAW_EXPECT((memory_estimate>().get() == 60u), "FixedArray isn't 60 bytes"); + SAW_EXPECT((memory_estimate, sch::UInt8>().get() == 61u), "FixedArray + UInt8 isn't 61 bytes"); +} + +} diff --git a/lib/core/tests/particles.cpp b/lib/core/tests/particles.cpp index b2581f7..fcca19a 100644 --- a/lib/core/tests/particles.cpp +++ b/lib/core/tests/particles.cpp @@ -150,6 +150,29 @@ SAW_TEST("Moving particles 2D"){ SAW_EXPECT(has_collided, "Expecting collision within those steps"); } +SAW_TEST("Particle Matrix Rotation"){ + using namespace kel; + + saw::data> part_a; + { + auto& body = part_a.template get<"rigid_body">(); + auto& pos = body.template get<"position">(); + auto& pos_old = body.template get<"position_old">(); + auto& coll = part_a.template get<"collision">(); + auto& radius = coll.template get<"radius">(); + auto& acc = body.template get<"acceleration">(); + + radius.set(1.0); + + pos.at({{0u}}) = -5.0; + pos.at({{1u}}) = 0.2; + pos_old = pos; + } + + + +} + SAW_TEST("Particle Collision Impulse"){ using namespace kel; -- cgit v1.2.3