From ae8711ba90ac2a47ea7654dc873927fb2783ff91 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 18 Apr 2025 16:25:30 +0200 Subject: wip rendering in terminal and extracting example code to files --- c++/descriptor.hpp | 18 ++++++++++++++++++ c++/equilibrium.hpp | 6 ++++++ c++/macroscopic.hpp | 32 ++++++++++++++++++++++++++++++++ c++/term_renderer.hpp | 7 +++++++ examples/cavity_2d.cpp | 26 +------------------------- examples/poiseulle_2d.cpp | 8 ++++++++ 6 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 c++/macroscopic.hpp create mode 100644 c++/term_renderer.hpp create mode 100644 examples/poiseulle_2d.cpp diff --git a/c++/descriptor.hpp b/c++/descriptor.hpp index 014327c..aa8c943 100644 --- a/c++/descriptor.hpp +++ b/c++/descriptor.hpp @@ -152,6 +152,24 @@ public: static constexpr typename saw::native_data_type::type inv_cs2 = 3.0; static constexpr typename saw::native_data_type::type cs2 = 1./3.; }; + +template +class cell_schema_builder { +private: + saw::schema_factory factory_struct_; +public: + cell_schema_builder() = default; + + cell_schema_builder(saw::schema_factory inp): + factory_struct_{inp} + {} + + template + constexpr auto require() const noexcept { + return {factory_struct_.add_maybe()}; + } +}; + } } diff --git a/c++/equilibrium.hpp b/c++/equilibrium.hpp index ac36dbc..bb55d00 100644 --- a/c++/equilibrium.hpp +++ b/c++/equilibrium.hpp @@ -13,14 +13,20 @@ saw::data> equilibrium(saw::data rho, saw:: // 0.0 // / \ // | | + // + // Velocity * Velocity meaning || vel ||_2^2 or _2 saw::data vel_vel{0.0}; for(uint64_t j = 0u; j < Descriptor::D; ++j){ vel_vel = vel_vel + vel.at(j) * vel.at(j); } + /** + * Calculate equilibrium + */ for(uint64_t i = 0u; i < eq.template get_dim_size<0u>(); ++i){ saw::data vel_c{}; for(uint64_t j = 0u; j < Descriptor::D; ++j){ + // _2 vel_c = vel_c + (vel.at(j) * saw::data{static_cast::type>(dfi::directions[i][j])}); } diff --git a/c++/macroscopic.hpp b/c++/macroscopic.hpp new file mode 100644 index 0000000..608b89e --- /dev/null +++ b/c++/macroscopic.hpp @@ -0,0 +1,32 @@ +#pragma once + +namespace kel { +namespace lbm { +/** + * Calculate the macroscopic variables rho and u in Lattice Units. + */ +template +void compute_rho_u ( + const saw::data>& dfs, + typename saw::native_data_type::type& rho, + std::array::type, 2>& vel + ) +{ + using dfi = df_info; + + rho = 0; + std::fill(vel.begin(), vel.end(), 0); + + for(size_t j = 0; j < Desc::Q; ++j){ + rho += dfs(j).get(); + for(size_t i = 0; i < Desc::D; ++i){ + vel[i] += dfi::directions[j][i] * dfs(j).get(); + } + } + + for(size_t i = 0; i < Desc::D; ++i){ + vel[i] /= rho; + } +} +} +} diff --git a/c++/term_renderer.hpp b/c++/term_renderer.hpp new file mode 100644 index 0000000..f675a99 --- /dev/null +++ b/c++/term_renderer.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace kel { +namespace lbm { + +} +} diff --git a/examples/cavity_2d.cpp b/examples/cavity_2d.cpp index 3e2e064..5085635 100644 --- a/examples/cavity_2d.cpp +++ b/examples/cavity_2d.cpp @@ -1,4 +1,5 @@ #include "../c++/descriptor.hpp" +#include "../c++/macroscopic.hpp" /** */ @@ -46,31 +47,6 @@ using CellStruct = Struct< using CavityFieldD2Q9 = CellField>; } -/** - * Calculate the macroscopic variables rho and u in Lattice Units. - */ -template -void compute_rho_u ( - saw::data>& dfs, - typename saw::native_data_type::type& rho, - std::array::type, 2>& vel - ) -{ - using dfi = df_info; - - rho = 0; - std::fill(vel.begin(), vel.end(), 0); - - for(size_t i = 0; i < Desc::Q; ++i){ - rho += dfs(i).get(); - vel[0] += dfi::directions[i][0] * dfs(i).get(); - vel[1] += dfi::directions[i][1] * dfs(i).get(); - } - - vel[0] /= rho; - vel[1] /= rho; -} - /** * Unsure if feasible. I would have a rho normalization on the dfs and then I would use the const rho_computation */ diff --git a/examples/poiseulle_2d.cpp b/examples/poiseulle_2d.cpp new file mode 100644 index 0000000..be3efbc --- /dev/null +++ b/examples/poiseulle_2d.cpp @@ -0,0 +1,8 @@ +#include "../c++/descriptor.hpp" + +#include + +int main(int argc, char** argv){ + + return 0; +} -- cgit v1.2.3