#pragma once #include "component.hpp" #include "equilibrium.hpp" namespace kel { namespace lbm { namespace cmpt { struct BounceBack {}; template struct ZouHeHorizontal{}; struct Equilibrium {}; template struct ZouHeVertical{}; } /** * Full-Way BounceBack. */ template class component { private: public: component() = default; using Component = cmpt::BounceBack; /** * 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 = "full_way_bounce_back"; static constexpr saw::string_literal after = ""; static constexpr saw::string_literal before = "streaming"; /** * Raw setup */ template void apply(const saw::data& field, const saw::data>& index, saw::data time_step)const{ bool is_even = ((time_step.get() % 2u) == 0u); // This is a ref // 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">(); using dfi = df_info; // Technically use .copy() auto& dfs_old = dfs_old_f.at(index); auto df_cpy = dfs_old; for(uint64_t i = 0u; i < Descriptor::Q; ++i){ dfs_old.at({i}) = df_cpy.at({dfi::opposite_index.at(i)}); } } }; template class component final { private: saw::data> density_; saw::data> velocity_; public: component( saw::data> density__, saw::data> velocity__ ): density_{density__}, velocity_{velocity__} {} template void apply(const saw::data& field, const saw::data>& index, saw::data time_step) const { bool is_even = ((time_step.get() % 2u) == 0u); using dfi = df_info; auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); auto eq = equilibrium(density_,velocity_); dfs_old_f.at(index) = eq; } }; /** * 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 class component, Encode> final { private: saw::data rho_setting_; public: component(const saw::data& density_setting__): rho_setting_{density_setting__} {} template void apply(const saw::data& field, saw::data> index, saw::data time_step) const { using dfi = df_info; constexpr int known_dir = Dir ? 1 : -1; bool is_even = ((time_step.get() % 2) == 0); auto& info_f = field.template get<"info">(); // 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& dfs_old = dfs_old_f.at(index); /** * Sum all known DFs */ saw::data sum_df{0}; 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){ sum_df += dfs_old.at({k}); } } /** * Get the sum of the unknown dfs and precalculate the direction */ auto sum_unknown_dfs = (rho_setting_ - sum_df) * saw::data{known_dir}; 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){ sum_unknown_dfs += dfs_old.at({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.at({2u}) = dfs_old.at({1u}) + saw::data{2.0 / 3.0} * rho_setting_ * vel_x; dfs_old.at({6u}) = dfs_old.at({5u}) + saw::data{1.0 / 6.0} * rho_setting_ * vel_x + saw::data{0.5} * (dfs_old.at({4u}) - dfs_old.at({3u})); dfs_old.at({8u}) = dfs_old.at({7u}) + saw::data{1.0 / 6.0} * rho_setting_ * vel_x + saw::data{0.5} * (dfs_old.at({3u}) - dfs_old.at({4u})); }else if constexpr (not Dir){ dfs_old.at({1u}) = dfs_old.at({2u}) - saw::data{2.0 / 3.0} * rho_setting_ * vel_x; dfs_old.at({5u}) = dfs_old.at({6u}) - saw::data{1.0 / 6.0} * rho_setting_ * vel_x + saw::data{0.5} * (dfs_old.at({3u}) - dfs_old.at({4u})); dfs_old.at({7u}) = dfs_old.at({8u}) - saw::data{1.0 / 6.0} * rho_setting_ * vel_x + saw::data{0.5} * (dfs_old.at({4u}) - dfs_old.at({3u})); } } }; } }