diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-09-09 10:57:25 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-09-09 10:57:25 +0200 |
commit | 3fa7dcb5684504dc99d14d2dc003876151636834 (patch) | |
tree | 8f2dee12c94c47bd218a4ce0e4770fe576fd7c08 | |
parent | 1f993006305952f4cafddd08267731877e808bba (diff) |
Removing warnings
-rw-r--r-- | c++/boundary.hpp | 85 | ||||
-rw-r--r-- | c++/collision.hpp | 2 | ||||
-rw-r--r-- | c++/descriptor.hpp | 49 | ||||
-rw-r--r-- | c++/particle/particle.hpp | 2 | ||||
-rw-r--r-- | examples/poiseulle_particles_channel_2d.cpp | 96 | ||||
-rw-r--r-- | tests/vtk_write.cpp | 2 |
6 files changed, 140 insertions, 96 deletions
diff --git a/c++/boundary.hpp b/c++/boundary.hpp index bc4859c..4e30f71 100644 --- a/c++/boundary.hpp +++ b/c++/boundary.hpp @@ -64,10 +64,91 @@ public: } }; -template<typename T, typename Descriptor, bool Dir> -class component<T, Descriptor, cmpt::ZouHeHorizontal<Dir>> final { +/** + * This is massively hacky and expects a lot of conditions + * Either this or mirrored along the horizontal line works + * + * 0 - 2 - 2 + * 0 - 3 - 1 + * 0 - 3 - 1 + * ......... + * 0 - 3 - 1 + * 0 - 2 - 2 + * + */ +template<typename FP, typename Descriptor, bool Dir> +class component<FP, Descriptor, cmpt::ZouHeHorizontal<Dir>> final { private: + saw::data<FP> pressure_setting_; + saw::data<FP> rho_setting_; public: + component(const saw::data<FP>& pressure_setting__): + pressure_setting_{pressure_setting__}, + rho_setting_{pressure_setting__ * df_info<FP,Descriptor>::inv_cs2} + {} + + template<typename CellFieldSchema> + void apply(saw::data<CellFieldSchema>& field, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, uint64_t time_step){ + using dfi = df_info<FP,Descriptor>; + + bool is_even = ((time_step % 2) == 0); + auto& cell = field(index); + + auto& info = cell.template get<"info">(); + if(info({0u}).get() == 0u){ + return; + } + auto& dfs_old = (is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); + // auto& dfs = (not is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); + + /** + * Sum all known DFs + */ + saw::data<FP> sum_df{0}; + for(saw::data<sch::UInt64> k{0u}; k < saw::data<sch::UInt64>{Descriptor::Q}; ++k){ + auto c_k = dfi::directions[k.get()]; + auto& cell_n = field({{index.at({0u})+c_k[0u], index.at({1u})+c_k[1u]}}); + auto& info_n = cell_n.template get<"info">(); + auto info_n_val = info_n({0u}); + auto k_opp = dfi::opposite_index[k.get()]; + + if(info_n_val.get() > 0u){ + sum_df += dfs_old({k_opp}); + } + } + + /** + * Get the sum of the unknown dfs and precalculate the direction + */ + constexpr int known_dir = Dir ? 1 : -1; + auto sum_unknown_dfs = (rho_setting_ - sum_df) * saw::data<FP>{known_dir}; + + for(saw::data<sch::UInt64> k{0u}; k < saw::data<sch::UInt64>{Descriptor::Q}; ++k){ + auto c_k = dfi::directions[k.get()]; + auto& cell_n = field({{index.at({0u})+c_k[0u], index.at({1u})+c_k[1u]}}); + auto& info_n = cell_n.template get<"info">(); + auto info_n_val = info_n({0u}); + // auto k_opp = dfi::opposite_index[k.get()]; + + if(info_n_val.get() > 0u){ + sum_unknown_dfs += dfs_old({k}) * c_k[0u]; + } + } + + auto vel_x = sum_unknown_dfs / rho_setting_; + + static_assert(Descriptor::D == 2u and Descriptor::Q == 9u, "Some parts are hard coded sadly"); + + if constexpr (Dir) { + dfs_old({2u}) = dfs_old({1u}) + saw::data<FP>{2.0 / 3.0} * rho_setting_ * vel_x; + dfs_old({6u}) = dfs_old({5u}) + saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old({4u}) - dfs_old({3u})); + dfs_old({8u}) = dfs_old({7u}) + saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old({3u}) - dfs_old({4u})); + }else if constexpr (not Dir){ + dfs_old({1u}) = dfs_old({2u}) - saw::data<FP>{2.0 / 3.0} * rho_setting_ * vel_x; + dfs_old({5u}) = dfs_old({6u}) - saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old({3u}) - dfs_old({4u})); + dfs_old({7u}) = dfs_old({8u}) - saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old({4u}) - dfs_old({3u})); + } + } }; } } diff --git a/c++/collision.hpp b/c++/collision.hpp index cd6cf14..1b8b82d 100644 --- a/c++/collision.hpp +++ b/c++/collision.hpp @@ -106,7 +106,7 @@ public: auto& force = cell.template get<"force">(); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - saw::data<T> ci_min_u{0}; + // saw::data<T> ci_min_u{0}; saw::data<T> ci_dot_u{0}; for(uint64_t d = 0u; d < Descriptor::D; ++d){ ci_dot_u = ci_dot_u + vel.at({d}) * saw::data<T>{static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d])}; diff --git a/c++/descriptor.hpp b/c++/descriptor.hpp index 0d05a04..0c6707a 100644 --- a/c++/descriptor.hpp +++ b/c++/descriptor.hpp @@ -153,6 +153,55 @@ public: static constexpr typename saw::native_data_type<T>::type inv_cs2 = 3.0; static constexpr typename saw::native_data_type<T>::type cs2 = 1./3.; }; +/* +template<typename T> +class df_info<T,sch::Descriptor<3, 27>> { +public: + using Descriptor = sch::Descriptor<3,27>; + + static constexpr uint64_t D = 3u; + static constexpr uint64_t Q = 27u; + + static constexpr std::array<std::array<int32_t, D>, Q> directions = {{ + { 0, 0, 0}, + {-1, 0, 0}, + { 1, 0, 0}, + { 0,-1, 0}, + { 0, 1, 0}, + {-1,-1, 0}, + { 1, 1, 0}, + {-1, 1, 0}, + { 1,-1, 0} + }}; + + static constexpr std::array<typename saw::native_data_type<T>::type,Q> weights = { + 4./9., + 1./9., + 1./9., + 1./9., + 1./9., + 1./36., + 1./36., + 1./36., + 1./36. + }; + + static constexpr std::array<uint64_t,Q> opposite_index = { + 0, + 2, + 1, + 4, + 3, + 6, + 5, + 8, + 7 + }; + + static constexpr typename saw::native_data_type<T>::type inv_cs2 = 3.0; + static constexpr typename saw::native_data_type<T>::type cs2 = 1./3.; +}; +*/ template<typename Schema> class cell_schema_builder { diff --git a/c++/particle/particle.hpp b/c++/particle/particle.hpp index ae7769a..24757c1 100644 --- a/c++/particle/particle.hpp +++ b/c++/particle/particle.hpp @@ -43,7 +43,7 @@ private: auto& pos = body.template get<"position">(); auto& pos_old = body.template get<"position_old">(); - auto& rot = body.template get<"rotation">(); + // auto& rot = body.template get<"rotation">(); auto& acc = body.template get<"acceleration">(); auto tsd_squared = time_step_delta * time_step_delta; diff --git a/examples/poiseulle_particles_channel_2d.cpp b/examples/poiseulle_particles_channel_2d.cpp index bc5d241..737488b 100644 --- a/examples/poiseulle_particles_channel_2d.cpp +++ b/examples/poiseulle_particles_channel_2d.cpp @@ -68,94 +68,6 @@ using GeometryStruct = Struct< using CavityFieldD2Q9 = CellField<D2Q9, CellStruct<D2Q9>>; } -namespace cmpt { -template<bool East> -struct PressureBoundaryRestrictedVelocityTo {}; -} - -/** - * This is massively hacky and expects a lot of conditions - * Either this or mirrored along the horizontal line works - * - * 0 - 2 - 2 - * 0 - 3 - 1 - * 0 - 3 - 1 - * ......... - * 0 - 3 - 1 - * 0 - 2 - 2 - * - */ -template<typename FP,typename Descriptor, bool East> -struct component<FP,Descriptor, cmpt::PressureBoundaryRestrictedVelocityTo<East>> { -private: - saw::data<FP> pressure_setting_; - saw::data<FP> rho_setting_; -public: - component(const saw::data<FP>& pressure_setting__): - pressure_setting_{pressure_setting__}, - rho_setting_{pressure_setting__ * df_info<FP,Descriptor>::inv_cs2} - {} - - template<typename CellFieldSchema> - void apply(saw::data<CellFieldSchema>& field, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, uint64_t time_step){ - using dfi = df_info<FP,Descriptor>; - - bool is_even = ((time_step % 2) == 0); - auto& cell = field(index); - - auto& info = cell.template get<"info">(); - if(info({0u}).get() == 0u){ - return; - } - auto& dfs_old = (is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - auto& dfs = (not is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - - /** - * Sum all known DFs - */ - saw::data<FP> sum_df{0}; - for(saw::data<sch::UInt64> k{0u}; k < saw::data<sch::UInt64>{Descriptor::Q}; ++k){ - auto c_k = dfi::directions[k.get()]; - auto& cell_n = field({{index.at({0u})+c_k[0u], index.at({1u})+c_k[1u]}}); - auto& info_n = cell_n.template get<"info">(); - auto info_n_val = info_n({0u}); - auto k_opp = dfi::opposite_index[k.get()]; - - if(info_n_val.get() > 0u){ - sum_df += dfs_old({k_opp}); - } - } - /** - * Get the sum of the unknown dfs and precalculate the direction - */ - constexpr int known_dir = East ? 1 : -1; - auto sum_unknown_dfs = (rho_setting_ - sum_df) * saw::data<FP>{known_dir}; - - for(saw::data<sch::UInt64> k{0u}; k < saw::data<sch::UInt64>{Descriptor::Q}; ++k){ - auto c_k = dfi::directions[k.get()]; - auto& cell_n = field({{index.at({0u})+c_k[0u], index.at({1u})+c_k[1u]}}); - auto& info_n = cell_n.template get<"info">(); - auto info_n_val = info_n({0u}); - auto k_opp = dfi::opposite_index[k.get()]; - - if(info_n_val.get() > 0u){ - sum_unknown_dfs += dfs_old({k}) * c_k[0u]; - } - } - - auto vel_x = sum_unknown_dfs / rho_setting_; - - if constexpr (East) { - dfs_old({2u}) = dfs_old({1u}) + saw::data<FP>{2.0 / 3.0} * rho_setting_ * vel_x; - dfs_old({6u}) = dfs_old({5u}) + saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old({4u}) - dfs_old({3u})); - dfs_old({8u}) = dfs_old({7u}) + saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old({3u}) - dfs_old({4u})); - }else if constexpr (not East){ - dfs_old({1u}) = dfs_old({2u}) - saw::data<FP>{2.0 / 3.0} * rho_setting_ * vel_x; - dfs_old({5u}) = dfs_old({6u}) - saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old({3u}) - dfs_old({4u})); - dfs_old({7u}) = dfs_old({8u}) - saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old({4u}) - dfs_old({3u})); - } - } -}; } } @@ -400,7 +312,7 @@ void couple_particles_to_lattice( // Fluid to Particle Coupling // Prepare force sum - saw::data<sch::Vector<sch::T,2u>> forces; + // saw::data<sch::Vector<sch::T,2u>> forces; iterate_over([&](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){ @@ -484,14 +396,16 @@ void lbm_step( using namespace kel::lbm; using dfi = df_info<sch::T,sch::D2Q9>; + (void) macros; + bool even_step = ((time_step % 2u) == 0u); /** * 1. Relaxation parameter \tau */ component<sch::T, sch::D2Q9, cmpt::BGKGuo> coll{0.5384}; component<sch::T, sch::D2Q9, cmpt::BounceBack> bb; - component<sch::T, sch::D2Q9, cmpt::PressureBoundaryRestrictedVelocityTo<true>> inlet{1.1 * dfi::cs2 * 2.0 / 3.0}; - component<sch::T, sch::D2Q9, cmpt::PressureBoundaryRestrictedVelocityTo<false>> outlet{1.0 * dfi::cs2 * 2.0 / 3.0}; + component<sch::T, sch::D2Q9, cmpt::ZouHeHorizontal<true>> inlet{1.1 * dfi::cs2 * 2.0 / 3.0}; + component<sch::T, sch::D2Q9, cmpt::ZouHeHorizontal<false>> outlet{1.0 * dfi::cs2 * 2.0 / 3.0}; auto meta = latt.meta(); diff --git a/tests/vtk_write.cpp b/tests/vtk_write.cpp index b2e30f0..0df9998 100644 --- a/tests/vtk_write.cpp +++ b/tests/vtk_write.cpp @@ -48,7 +48,7 @@ SAW_TEST("VTK Write test example"){ auto& cell_0 = cells.at({{{0,0}}}); cell_0.template get<"velocity">()= {{0.5,-0.1}}; - cell_0.template get<"pressure">().set({1.1}); + cell_0.template get<"pressure">().set(1.1); auto eov = lbm::impl::lbm_vtk_writer<sch::Array<sch::MacroStruct<sch::T,2>, 2>>::apply(sstream, cells); SAW_EXPECT(eov.is_value(), "vtk writer failed to write"); |