#pragma once #include "macroscopic.hpp" #include "component.hpp" #include "equilibrium.hpp" #include "chunk.hpp" namespace kel { namespace lbm { namespace cmpt { struct BGK {}; struct BGKGuo {}; } /** * Standard BGK collision operator for LBM */ template class component { private: saw::data relaxation_; saw::data frequency_; public: component(typename saw::native_data_type::type relaxation__): relaxation_{{relaxation__}}, frequency_{saw::data{1} / relaxation_} {} component(const saw::data& relaxation__): relaxation_{relaxation__}, frequency_{saw::data{1} / relaxation_} {} using Component = cmpt::BGK; /** * Thoughts regarding automating order setup */ using access = cmpt::access_tuple< cmpt::access<"dfs", 1, true, true, true> >; /** * Thoughts regarding automating order setup */ static constexpr saw::string_literal name = "collision"; static constexpr saw::string_literal after = ""; static constexpr saw::string_literal before = "streaming"; /** * Raw setup */ template void apply(const saw::data& field, saw::data> index, saw::data time_step) const { bool is_even = ((time_step.get() % 2) == 0); // auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); saw::data> rho; saw::data> vel; compute_rho_u(dfs_old_f.at(index),rho,vel); auto eq = equilibrium(rho,vel); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ dfs_old_f.at(index).at({i}) = dfs_old_f.at(index).at({i}) + frequency_ * (eq.at(i) - dfs_old_f.at(index).at({i})); } } template void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { bool is_even = ((time_step.get() % 2) == 0); // auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); 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); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ dfs_old_f.at(index).at({i}) = dfs_old_f.at(index).at({i}) + frequency_ * (eq.at(i) - dfs_old_f.at(index).at({i})); } } }; template class component { private: typename saw::native_data_type::type relaxation_; saw::data frequency_; public: component(typename saw::native_data_type::type relaxation__): relaxation_{relaxation__}, frequency_{typename saw::native_data_type::type(1) / relaxation_} {} using Component = cmpt::BGKGuo; using access = cmpt::access_tuple< cmpt::access<"dfs", 1, true, true, true>, cmpt::access<"force", 0, true, false> >; /** * Thoughts regarding automating order setup */ static constexpr saw::string_literal name = "collision"; static constexpr saw::string_literal after = ""; static constexpr saw::string_literal before = "streaming"; template void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { // void apply(saw::data& field, saw::data> index, saw::data time_step){ bool is_even = ((time_step.get() % 2) == 0); auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); auto& dfs = dfs_old_f.at(index); 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); using dfi = df_info; auto& force_f = macros.template get<"force">(); auto& force = force_f.at(index); saw::data> dfi_inv_cs2; dfi_inv_cs2.at({}).set(dfi::inv_cs2); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ // saw::data ci_min_u{0}; saw::data> ci; for(uint64_t d = 0u; d < Descriptor::D; ++d){ ci.at({{d}}).set(static_cast::type>(dfi::directions[i][d])); } auto ci_dot_u = saw::math::dot(ci,vel); // saw::data> F_i; // F_i = f * (c_i - u * ics2 + * c_i * ics2 * ics2) * w_i; saw::data> w; w.at({}).set(dfi::weights[i]); auto F_i_d = saw::math::dot(force * w, (ci - vel * dfi_inv_cs2 + ci * ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2 )); /* saw::data> F_i_sum; for(uint64_t d = 0u; d < Descriptor::D; ++d){ saw::data> F_i_d; F_i_d.at({}) = F_i.at({{d}}); F_i_sum = F_i_sum + F_i_d; } */ dfs.at({i}) = dfs.at({i}) + frequency_ * (eq.at(i) - dfs.at({i}) ) + F_i_d.at({}) * (saw::data{1} - saw::data{0.5f} * frequency_); } } }; } }