From dc1c481df599550fd5717790d908a3879f62960a Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 20 Feb 2026 10:53:05 +0100 Subject: Fixing Guo forcing problems --- lib/core/c++/collision.hpp | 14 +++++++------- lib/core/c++/psm.hpp | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp index f259c9f..ef6bfe2 100644 --- a/lib/core/c++/collision.hpp +++ b/lib/core/c++/collision.hpp @@ -118,19 +118,19 @@ public: template void apply(saw::data& field, saw::data> index, saw::data time_step){ bool is_even = ((time_step.get() % 2) == 0); - auto& cell = field(index); - 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">(); + auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); + auto& dfs = dfs_old_f.at(index); saw::data> rho; saw::data> vel; - compute_rho_u(dfs_old,rho,vel); + compute_rho_u(dfs_old_f.at(index),rho,vel); auto eq = equilibrium(rho,vel); using dfi = df_info; - auto& force = cell.template get<"force">(); + auto& force_f = field.template get<"force">(); + auto& force = force_f.at(index); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ // saw::data ci_min_u{0}; @@ -143,11 +143,11 @@ public: for(uint64_t d = 0u; d < Descriptor::D; ++d){ F_i = F_i + saw::data{dfi::weights[i]} * ((saw::data{static_cast::type>(dfi::directions[i][d])} - - vel.at({d}) ) * dfi::inv_cs2 + ci_dot_u * saw::data{static_cast::type>(dfi::directions[i][d])} * dfi::inv_cs2 * dfi::inv_cs2 ) * force({d}); + - vel.at({d}) ) * dfi::inv_cs2 + ci_dot_u * saw::data{static_cast::type>(dfi::directions[i][d])} * dfi::inv_cs2 * dfi::inv_cs2 ) * force.at({d}); } - dfs_old({i}) = dfs_old({i}) + frequency_ * (eq.at(i) - dfs_old({i}) ) + F_i * (saw::data{1} - saw::data{0.5f} * frequency_); + dfs.at({i}) = dfs.at({i}) + frequency_ * (eq.at(i) - dfs.at({i}) ) + F_i * (saw::data{1} - saw::data{0.5f} * frequency_); } } }; diff --git a/lib/core/c++/psm.hpp b/lib/core/c++/psm.hpp index 8e151c3..94d5ccd 100644 --- a/lib/core/c++/psm.hpp +++ b/lib/core/c++/psm.hpp @@ -11,23 +11,54 @@ struct PSM {}; } /** - * HLBM collision operator for LBM + * PSM collision operator for LBM */ template class component { private: + saw::data> relaxation_; + saw::data> frequency_; public: - component() = default; + component( + saw::data> relaxation__ + ): + relaxation_{relaxation__} + { + saw::data> one; + frequency_ = one / relaxation_; + } template void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { - + + using dfi = df_info; bool is_even = ((time_step.get() % 2) == 0); auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); auto& porous = field.template get<"porosity">(); - + auto& rho_f = macros.template get<"density">(); + auto& vel_f = macros.template get<"velocity">(); + + saw::data>& rho = rho_f.at(index); + saw::data>& vel = vel_f.at(index); + + compute_rho_u(dfs_old_f.at(index),rho,vel); + + auto eq = equilibrium(rho,vel); + + saw::data> one; + one.at({}) = 1.0; + auto flip_porous = one - porous; + + auto& dfs = dfs_old_f.at(index); + + auto dfs_cpy = dfs; + + for(uint64_t i = 0u; i < Descriptor::Q; ++i){ + uint64_t i_opp = dfi::opposite_index[i]; + dfs.at({i}) = dfs_cpy.at({i}) + frequency_ * (eq.at(i) - dfs_cpy.at({i})) * flip_porous + (dfs_cpy.at({i_opp}) - dfs_cpy.at({i}) ) * porous; + } } }; -- cgit v1.2.3