From 04940fe64b714bcfad9026d54ee75a2fbdc7fe7b Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 17 Sep 2025 21:35:41 +0200 Subject: Streamlining and thoughts about changes in particle dynamics --- c++/descriptor.hpp | 1 + c++/macroscopic.hpp | 29 +++++++++++++++++++++++++++++ c++/util.hpp | 40 +++++++++++++++++++++++++++++++--------- c++/write_vtk.hpp | 26 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 9 deletions(-) (limited to 'c++') diff --git a/c++/descriptor.hpp b/c++/descriptor.hpp index 0c6707a..d04d217 100644 --- a/c++/descriptor.hpp +++ b/c++/descriptor.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include namespace kel { diff --git a/c++/macroscopic.hpp b/c++/macroscopic.hpp index 8a25248..51368e9 100644 --- a/c++/macroscopic.hpp +++ b/c++/macroscopic.hpp @@ -59,5 +59,34 @@ void compute_rho_u ( vel().at({i}) = vel().at({i}) / rho(); } } + +/** + * Calculate the macroscopic variables rho and u in Lattice Units. + */ +template +void compute_rho_u ( + const saw::data>& dfs, + saw::ref> rho, + saw::ref>> vel + ) +{ + using dfi = df_info; + + rho().set(0); + for(uint64_t i = 0; i < Desc::D; ++i){ + vel().at({{i}}).set(0); + } + + for(size_t j = 0; j < Desc::Q; ++j){ + rho() = rho() + dfs(j); + for(size_t i = 0; i < Desc::D; ++i){ + vel().at({{i}}) = vel().at({{i}}) + saw::data{static_cast::type>(dfi::directions[j][i])} * dfs(j); + } + } + + for(size_t i = 0; i < Desc::D; ++i){ + vel().at({{i}}) = vel().at({{i}}) / rho(); + } +} } } diff --git a/c++/util.hpp b/c++/util.hpp index 441ffc8..c5b6a05 100644 --- a/c++/util.hpp +++ b/c++/util.hpp @@ -4,6 +4,8 @@ #include #include +#include +#include namespace kel { namespace lbm { @@ -46,18 +48,37 @@ public: }; */ -void print_progress_bar(uint32_t progress, uint32_t progress_target){ - std::cout - <<"\r" - <<"Progress: " - <<((100 * progress) / progress_target) - <<"% ["; +void print_progress_bar(const uint32_t progress, const uint32_t progress_target){ + std::cout<<"\r"; + // <<"Progress: " + // <<((100 * progress) / progress_target) + // <<"% ["; - uint64_t i{0u}; + uint64_t perc_prog = (100ul*progress) / progress_target; + constexpr uint64_t max_perc_progress = 100u; + perc_prog = std::min(perc_prog, max_perc_progress); - uint64_t max_display = 64u; + std::string_view prog_str{"Progress: "}; + // Progress string + (100 width and perc char) + ([] brackets) + space + pointer + uint64_t i{prog_str.size() + 4u + 2u + 1u + 1u}; + + std::cout< uint64_t{ + struct winsize w; + if(ioctl(STDOUT_FILENO, TIOCGWINSZ,&w) == -1){ + // Standardized Terminal size + return 80u; + } + return w.ws_col; + }(); + max_display = std::max(max_display,i) - i; uint64_t progress_display = (max_display * progress) / progress_target; - for(; i < progress_display; ++i){ + + for(i = 0u; i < progress_display; ++i){ std::cout<<"#"; } for(; i < max_display; ++i){ @@ -65,6 +86,7 @@ void print_progress_bar(uint32_t progress, uint32_t progress_target){ } std::cout<<"]"; + std::cout< #include +#include #include "descriptor.hpp" @@ -55,6 +56,31 @@ struct lbm_vtk_writer> { } }; +template +struct lbm_vtk_writer> { + static saw::error_or apply_header(std::ostream& vtk_file, std::string_view name){ + vtk_file<<"VECTORS "< apply(std::ostream& vtk_file, const saw::data>& field){ + static_assert(D > 0, "Non-dimensionality is bad for velocity."); + static_assert(D <= 3, "4th dimension as well. Mostly due to vtk."); + + // vtk_file<<"VECTORS "< 0){ + vtk_file<<" "; + } + vtk_file< struct lbm_vtk_writer...> , Dim>> { -- cgit v1.2.3