diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-02-17 18:29:22 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-02-17 18:29:22 +0100 |
| commit | dcee24278ed28d21cd3addffeeb8e5f9f7248602 (patch) | |
| tree | d590ede2996f04f69e2c4521019ae5b1bedd05df | |
| parent | bb90083ca62483a1cf0e1b72dfb96e05701035ef (diff) | |
| download | libs-lbm-dcee24278ed28d21cd3addffeeb8e5f9f7248602.tar.gz | |
| -rw-r--r-- | examples/poiseulle_3d_gpu/sim.cpp | 16 | ||||
| -rw-r--r-- | examples/poiseulle_particles_2d_gpu/sim.cpp | 16 | ||||
| -rw-r--r-- | lib/core/c++/descriptor.hpp | 10 | ||||
| -rw-r--r-- | lib/core/c++/environment.hpp | 1 | ||||
| -rw-r--r-- | lib/core/c++/equilibrium.hpp | 3 | ||||
| -rw-r--r-- | lib/core/c++/lbm.hpp | 1 | ||||
| -rw-r--r-- | lib/core/c++/memory.hpp | 62 | ||||
| -rw-r--r-- | lib/core/c++/write_vtk.hpp | 22 | ||||
| -rw-r--r-- | lib/core/tests/memory.cpp | 18 | ||||
| -rw-r--r-- | lib/core/tests/particles.cpp | 23 |
10 files changed, 148 insertions, 24 deletions
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<void> lbm_main(int argc, char** argv){ } } - converter<sch::Float64> conv { + converter<T> conv { // delta_x {{1.0}}, // delta_t {{1.0}} }; + print_lbm_meta<T,Desc>(conv,{0.01}); + auto lbm_data_ptr = saw::heap<saw::data<sch::ChunkStruct<T,Desc>>>(); auto lbm_macro_data_ptr = saw::heap<saw::data<sch::MacroStruct<T,Desc>>>(); auto lbm_particle_data_ptr = saw::heap<saw::data<sch::FixedArray<sch::Particle<T,Desc::D>, particle_size>>>(); + + std::cout<<"Estimated Bytes: "<<memory_estimate<sch::ChunkStruct<T,Desc>,sch::MacroStruct<T,Desc>>().get()<<std::endl; auto eo_aio = saw::setup_async_io(); if(eo_aio.is_error()){ @@ -335,10 +339,7 @@ saw::error_or<void> lbm_main(int argc, char** argv){ for(saw::data<sch::UInt64> 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<void> 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<void> lbm_main(int argc, char** argv){ } } - converter<sch::Float64> conv { + converter<T> conv { // delta_x {{1.0}}, // delta_t {{1.0}} }; + + print_lbm_meta<T,Desc>(conv,{0.01}); // saw::data<sch::FixedArray<sch::UInt64,Desc::D>> meta{{dim_x,dim_y}}; auto lbm_data_ptr = saw::heap<saw::data<sch::ChunkStruct<T,Desc>>>(); auto lbm_macro_data_ptr = saw::heap<saw::data<sch::MacroStruct<T,Desc>>>(); auto lbm_particle_data_ptr = saw::heap<saw::data<sch::FixedArray<sch::Particle<T,Desc::D>, particle_size>>>(); + + std::cout<<"Estimated Bytes: "<<memory_estimate<sch::ChunkStruct<T,Desc>,sch::MacroStruct<T,Desc>>().get()<<std::endl; auto eo_aio = saw::setup_async_io(); if(eo_aio.is_error()){ @@ -335,10 +339,7 @@ saw::error_or<void> lbm_main(int argc, char** argv){ for(saw::data<sch::UInt64> 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<void> 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<std::array<int32_t, D>, 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<typename saw::native_data_type<T>::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<std::filesystem::path> 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<sch::FixedArray<T, Descriptor::Q>> equilibrium(saw::data<sch::Scalar<T using dfi = df_info<T, Descriptor>; saw::data<sch::FixedArray<T,Descriptor::Q>> eq; + // Brain broken, here's an owl // ^ // 0.0 // / \ @@ -23,7 +24,7 @@ saw::data<sch::FixedArray<T, Descriptor::Q>> equilibrium(saw::data<sch::Scalar<T /** * Calculate equilibrium */ - for(uint64_t i = 0u; i < eq.template get_dim_size<0u>(); ++i){ + for(uint64_t i = 0u; i < Descriptor::Q; ++i){ saw::data<T> vel_c{}; for(uint64_t j = 0u; j < Descriptor::D; ++j){ // <vel,c_i>_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<typename Sch> +struct memory_size_helper; + +template<typename Sch, uint64_t N> +struct memory_size_helper<sch::Primitive<Sch,N>> { + static constexpr uint64_t bytes = N; +}; + +template<typename Sch, uint64_t... N> +struct memory_size_helper<sch::FixedArray<Sch,N...>> { + static constexpr uint64_t bytes = saw::ct_multiply<uint64_t,N...>::value * memory_size_helper<Sch>::bytes; +}; + +template<typename Sch, uint64_t Ghost, uint64_t... N> +struct memory_size_helper<sch::Chunk<Sch,Ghost,N...>> { + static constexpr uint64_t bytes = memory_size_helper<typename sch::Chunk<Sch,Ghost,N...>::InnerSchema>::bytes; +}; + +template<typename... T> +class memory_estimate_helper final { +private: + + template<uint64_t i> + static void apply_i(saw::data<sch::UInt64>& bytes){ + + if constexpr ( i < sizeof...(T)){ + using T_I = typename saw::parameter_pack_type<i,T...>::type; + + bytes.set(bytes.get() + memory_size_helper<T_I>::bytes); + + apply_i<i+1u>(bytes); + } + } + +public: + + static void apply(saw::data<sch::UInt64>& bytes){ + apply_i<0u>(bytes); + } +}; +} + +template<typename... T> +saw::data<sch::UInt64> memory_estimate(){ + saw::data<sch::UInt64> bytes; + + impl::memory_estimate_helper<T...>::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<sch::Struct<sch::Member<sch::Chunk<MemberT,Ghost,Dims...>, } template<typename Sch> -saw::error_or<void> write_vtk_file(const std::filesystem::path& file_name, const saw::data<Sch>& field){ +saw::error_or<void> write_vtk_file(const std::filesystem::path& out_dir, const std::string_view& file_name, uint64_t d_t, const saw::data<Sch>& 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<saw::err::critical>("Could not create directory for write_vtk_file function"); + } + } + std::string ft_name{file_name}; + + std::stringstream sstr; + sstr + <<file_name + <<"_" + <<d_t + <<".vtk" + ; - std::ofstream vtk_file{file_name}; + std::ofstream vtk_file{vtk_dir / sstr.str() }; if( not vtk_file.is_open() ){ return saw::make_error<saw::err::critical>("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 <forstio/test/suite.hpp> + +#include "../c++/memory.hpp" + +namespace { +namespace sch { +using namespace saw::schema; +} + +SAW_TEST("Memory Estimate"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate<sch::Float32>().get() == 4u), std::string{"Float32 isn't 4 bytes, but "} + std::to_string(memory_estimate<sch::Float32>().get()) ); + SAW_EXPECT((memory_estimate<sch::FixedArray<sch::Float32,5u,3u>>().get() == 60u), "FixedArray<Float32,5u,3u> isn't 60 bytes"); + SAW_EXPECT((memory_estimate<sch::FixedArray<sch::Float32,5u,3u>, sch::UInt8>().get() == 61u), "FixedArray<Float32,5u,3u> + 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<sch::Particle<sch::T,2u>> 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; |
