From 77afc46bf0cb5169edbec626a7c60996c81b2154 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 3 Mar 2026 16:52:53 +0100 Subject: Confusion about Boundary conditions --- lib/core/c++/geometry.hpp | 13 ------------- lib/core/c++/geometry/poiseulle_channel.hpp | 15 +++++++++++++++ lib/core/c++/particle/blur.hpp | 1 - 3 files changed, 15 insertions(+), 14 deletions(-) (limited to 'lib/core/c++') diff --git a/lib/core/c++/geometry.hpp b/lib/core/c++/geometry.hpp index c8a48a6..1c5d0a3 100644 --- a/lib/core/c++/geometry.hpp +++ b/lib/core/c++/geometry.hpp @@ -12,19 +12,6 @@ struct geometry { } }; */ -namespace cmpt { -struct PoiseulleChannel; -} - -template -class component final { -private: -public: - template - void apply(saw::data& field, const saw::data){ - auto& info_f = field.template get<"info">(); - } -}; // Ghost - 0 // Wall - 1 diff --git a/lib/core/c++/geometry/poiseulle_channel.hpp b/lib/core/c++/geometry/poiseulle_channel.hpp index f675a99..f719ec4 100644 --- a/lib/core/c++/geometry/poiseulle_channel.hpp +++ b/lib/core/c++/geometry/poiseulle_channel.hpp @@ -1,7 +1,22 @@ #pragma once +#include "../geometry.hpp" + namespace kel { namespace lbm { +namespace cmpt { +struct PoiseulleChannel; +} + +template +class component final { +private: +public: + template + void apply(saw::data& field, const saw::data){ + auto& info_f = field.template get<"info">(); + } +}; } } diff --git a/lib/core/c++/particle/blur.hpp b/lib/core/c++/particle/blur.hpp index a304e8d..7b93ae9 100644 --- a/lib/core/c++/particle/blur.hpp +++ b/lib/core/c++/particle/blur.hpp @@ -31,7 +31,6 @@ void blur_mask(saw::data>& p_mask){ p_mask = blurred_mask; } - } } } -- cgit v1.2.3 From 75fda9a23cd30efa72bd212d5642c3d30ee34913 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 3 Mar 2026 19:03:05 +0100 Subject: Added CSV for simpler script processing --- lib/core/c++/lbm.hpp | 1 + lib/core/c++/write_csv.hpp | 184 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 lib/core/c++/write_csv.hpp (limited to 'lib/core/c++') diff --git a/lib/core/c++/lbm.hpp b/lib/core/c++/lbm.hpp index a1e088e..d6a0976 100644 --- a/lib/core/c++/lbm.hpp +++ b/lib/core/c++/lbm.hpp @@ -17,6 +17,7 @@ #include "memory.hpp" #include "psm.hpp" #include "stream.hpp" +#include "write_csv.hpp" #include "write_vtk.hpp" #include "util.hpp" diff --git a/lib/core/c++/write_csv.hpp b/lib/core/c++/write_csv.hpp new file mode 100644 index 0000000..a60e208 --- /dev/null +++ b/lib/core/c++/write_csv.hpp @@ -0,0 +1,184 @@ +#pragma once + +#include + +#include +#include + +#include "descriptor.hpp" +#include "flatten.hpp" +#include "chunk.hpp" + +#include +#include + +namespace kel { +namespace lbm { +namespace impl { + +template +struct lbm_csv_writer { +}; + +template +struct lbm_csv_writer> { + static saw::error_or apply(std::ostream& csv_file, const saw::data>& field){ + if constexpr (std::is_same_v and D == 1u) { + csv_file<().get(); + }else{ + csv_file< +struct lbm_csv_writer> { + static saw::error_or apply(std::ostream& csv_file, const saw::data>& field){ + saw::data> index; + for(saw::data it{0}; it.get() < D; ++it){ + index.at({0u}).set(0u); + } + + // csv_file<<"VECTORS "< 0){ + csv_file<<","; + } + csv_file< +struct lbm_csv_writer> { + + template + static saw::error_or apply_d(std::ostream& csv_file, const saw::data>& field, saw::data>& index){ + // VTK wants to iterate over z,y,x instead of x,y,z + // So we do the same with CSV to stay consistent for now + // We could reorder the dimensions, but eh + if constexpr ( d > 0u){ + for(index.at({d-1u}) = 0u; index.at({d-1u}) < field.get_dims().at({d-1u}); ++index.at({d-1u})){ + auto eov = apply_d(csv_file, field, index); + } + }else{ + auto eov = lbm_csv_writer::apply(csv_file, field.at(index)); + csv_file<<"\n"; + if(eov.is_error()) return eov; + } + return saw::make_void(); + } + + static saw::error_or apply(std::ostream& csv_file, const saw::data>& field, std::string_view name){ + saw::data> index; + for(saw::data it{0}; it.get() < sizeof...(D); ++it){ + index.at({0u}).set(0u); + } + + { + auto eov = apply_d(csv_file, field, index); + if(eov.is_error()){ + return eov; + } + } + + return saw::make_void(); + } +}; + +template +struct lbm_csv_writer> { + static saw::error_or apply(std::ostream& csv_file, const saw::data>& field){ + static_assert(D > 0, "Non-dimensionality is bad for velocity."); + + // csv_file<<"VECTORS "< 0){ + csv_file<<","; + } + { + auto eov = lbm_csv_writer::apply(csv_file,field.at({{i}})); + if(eov.is_error()) return eov; + } + } + return saw::make_void(); + } +}; + +template +struct lbm_csv_writer> { + static saw::error_or apply(std::ostream& csv_file, const saw::data>& field){ + return lbm_csv_writer::apply(csv_file,field.at({})); + } +}; + +template +struct lbm_csv_writer,Keys>...>> final { + template + static saw::error_or iterate_i( + const std::filesystem::path& csv_dir, const std::string_view& file_base_name, uint64_t d_t, + const saw::data,Keys>...>>& field){ + + if constexpr ( i < sizeof...(MemberT) ) { + using MT = typename saw::parameter_pack_type,Keys>...>::type; + { + std::stringstream sstr; + sstr + <("Could not open file."); + } + // + auto eov = lbm_csv_writer::apply(csv_file,field.template get(), MT::KeyLiteral.view()); + if(eov.is_error()){ + return eov; + } + } + + return iterate_i(csv_dir, file_base_name, d_t,field); + } + + return saw::make_void(); + } + + + static saw::error_or apply( + const std::filesystem::path& csv_dir, const std::string_view& file_base_name, uint64_t d_t, + const saw::data,Keys>...>>& field){ + + auto& field_0 = field.template get::literal>(); + auto meta = field_0.get_dims(); + + return iterate_i<0u>(csv_dir,file_base_name, d_t, field); + } +}; + +} + +template +saw::error_or write_csv_file(const std::filesystem::path& out_dir, const std::string_view& file_name, uint64_t d_t, const saw::data& field){ + + auto csv_dir = out_dir / "csv"; + { + std::error_code ec; + std::filesystem::create_directories(csv_dir,ec); + if(ec != std::errc{}){ + return saw::make_error("Could not create directory for write_csv_file function"); + } + } + auto eov = impl::lbm_csv_writer::apply(csv_dir, file_name, d_t, field); + return eov; +} + +} +} -- cgit v1.2.3 From 16700f013886b8d8cb02e322c2d66c00179d9c89 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 3 Mar 2026 19:46:31 +0100 Subject: Fixing ZouHe? --- lib/core/c++/boundary.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/core/c++') diff --git a/lib/core/c++/boundary.hpp b/lib/core/c++/boundary.hpp index d5f3022..0a4ff4d 100644 --- a/lib/core/c++/boundary.hpp +++ b/lib/core/c++/boundary.hpp @@ -135,7 +135,7 @@ public: for(saw::data k{0u}; k < saw::data{Descriptor::Q}; ++k){ auto c_k = dfi::directions[k.get()]; - if(c_k[0u]*known_dir <= 0){ + if(c_k[0u]*known_dir >= 0){ sum_df += dfs_old.at({k}); } } @@ -147,7 +147,7 @@ public: for(saw::data k{0u}; k < saw::data{Descriptor::Q}; ++k){ auto c_k = dfi::directions[k.get()]; - if(c_k[0u]*known_dir < 0){ + if(c_k[0u]*known_dir > 0){ sum_unknown_dfs += dfs_old.at({k}) * c_k[0u]; } } -- cgit v1.2.3