From 210b04098cfc12e0fdcff0578d39cc9ccafb3b37 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 25 Jun 2025 15:01:48 +0200 Subject: Debugging commit --- c++/boundary.hpp | 30 ++++++++++---------- c++/collision.hpp | 2 +- c++/descriptor.hpp | 4 +++ examples/cavity_2d.cpp | 74 +++++++++++++++----------------------------------- 4 files changed, 43 insertions(+), 67 deletions(-) diff --git a/c++/boundary.hpp b/c++/boundary.hpp index 77542c5..e52715e 100644 --- a/c++/boundary.hpp +++ b/c++/boundary.hpp @@ -9,14 +9,14 @@ namespace cmpt { struct BounceBack {}; } +/** + * Full-Way BounceBack. + */ template class component { private: - typename saw::native_data_type::type relaxation_; public: - component(typename saw::native_data_type::type relaxation__): - relaxation_{relaxation__} - {} + component() = default; using Component = cmpt::BounceBack; @@ -30,7 +30,7 @@ public: /** * Thoughts regarding automating order setup */ - static constexpr saw::string_literal name = "collision"; + static constexpr saw::string_literal name = "full_way_bounce_back"; static constexpr saw::string_literal after = ""; static constexpr saw::string_literal before = "streaming"; @@ -38,20 +38,22 @@ public: * Raw setup */ template - void apply(saw::data& field, saw::data> index, uint64_t time_step){ - bool is_even = ((time_step % 2) == 0); - auto& cell = field.at(index); + void apply(saw::data& field, const saw::data>& index, uint64_t time_step){ + bool is_even = ((time_step % 2u) == 0u); - auto& dfs_old = is_even ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - auto& dfs = (!is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); + // This is a ref + auto& cell = field(index); - using dfi = df_info; + 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">(); + + using dfi = df_info; // Technically use .copy() - auto df_cpy = dfs; + auto df_cpy = dfs_old; - for(uint64_t i = 1u; i < Desc::Q; ++i){ - dfs({i}) = df_cpy({dfi::opposite_index.at(i)}); + for(uint64_t i = 1u; i < Descriptor::Q; ++i){ + dfs_old({i}) = df_cpy({dfi::opposite_index.at(i)}); } } }; diff --git a/c++/collision.hpp b/c++/collision.hpp index 128a499..451e4bb 100644 --- a/c++/collision.hpp +++ b/c++/collision.hpp @@ -51,7 +51,7 @@ public: auto eq = equilibrium(rho,vel); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - dfs({i}).set(dfs({i}).get() + (1.0 / relaxation_) * (eq.at(i).get() - dfs({i}).get())); + dfs_old({i}).set(dfs_old({i}).get() + (1.0 / relaxation_) * (eq.at(i).get() - dfs_old({i}).get())); } } diff --git a/c++/descriptor.hpp b/c++/descriptor.hpp index b1ee5b1..23c82f2 100644 --- a/c++/descriptor.hpp +++ b/c++/descriptor.hpp @@ -205,6 +205,10 @@ public: const data& operator()(const data& index)const{ return inner_.at(index); } + + const data, Encode> copy() const { + return *this; + } }; template diff --git a/examples/cavity_2d.cpp b/examples/cavity_2d.cpp index c409165..e2b28c9 100644 --- a/examples/cavity_2d.cpp +++ b/examples/cavity_2d.cpp @@ -3,9 +3,8 @@ #include "../c++/lbm.hpp" #include "../c++/component.hpp" #include "../c++/collision.hpp" +#include "../c++/boundary.hpp" -/** - */ #include #include @@ -27,14 +26,14 @@ using namespace saw::schema; * Q factor */ using T = Float32; -using D2Q5 = Descriptor<2,5>; -using D2Q9 = Descriptor<2,9>; +using D2Q5 = Descriptor<2u,5u>; +using D2Q9 = Descriptor<2u,9u>; template -using DfCell = Cell; +using DfCell = Cell; template -using CellInfo = Cell; +using CellInfo = Cell; /** * Basic type for simulation @@ -67,13 +66,13 @@ std::array::type,Desc::Q> equilibrium( typename std::array::type,Desc::Q> eq; - for(std::size_t i = 0; i < eq.size(); ++i){ - auto vel_c = (vel[0]*dfi::directions[i][0] + vel[1]*dfi::directions[i][1]); + for(std::size_t i = 0u; i < eq.size(); ++i){ + auto vel_c = (vel[0u]*dfi::directions[i][0u] + vel[1u]*dfi::directions[i][1u]); auto vel_c_cs2 = vel_c * dfi::inv_cs2; eq[i] = dfi::weights[i] * rho * ( 1.0 + vel_c_cs2 - - dfi::inv_cs2 * 0.5 * ( vel[0] * vel[0] + vel[1] * vel[1] ) + - dfi::inv_cs2 * 0.5 * ( vel[0u] * vel[0u] + vel[1u] * vel[1u] ) + vel_c_cs2 * vel_c_cs2 * 0.5 ); } @@ -105,30 +104,9 @@ public: }; */ namespace cmpt { -struct BounceBack{}; struct MovingWall {}; } - -/** - * Full-Way BounceBack. I suspect that the moving wall requires half-way bounce back. - */ -template -class component { -public: - - void apply(saw::data>& dfs){ - using dfi = df_info; - - // Technically use .copy() - auto df_cpy = dfs; - - for(uint64_t i = 1u; i < Desc::Q; ++i){ - dfs({i}) = df_cpy({dfi::opposite_index.at(i)}); - } - } -}; - /** * Full-Way moving wall Bounce back, something is not right here. * Technically it should reflect properly. @@ -247,41 +225,33 @@ void lbm_step( * 1. Relaxation parameter \tau */ component coll{0.5384}; - component bb; + component bb_lid; bb_lid.lid_vel = {0.1,0.0}; - auto dim = latt.meta(); + auto meta = latt.meta(); - for(saw::data i{0u}; i < dim.at(0u); ++i){ - for(saw::data j{0u}; j < dim.at(1u); ++j ){ + // Collide + for(saw::data i{0u}; i < meta.at(0u); ++i){ + for(saw::data j{0u}; j < meta.at(1u); ++j ){ auto& cell = latt({{i,j}}); auto& info = cell.template get<"info">(); switch(info({0u}).get()){ case 1u: { - coll.apply(latt, {{i,j}}, time_step+1u); - } break; + coll.apply(latt, {{i,j}}, time_step); + }; break; + case 2u: { + auto& df = even_step ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); + bb_lid.apply(df); + }; break; + case 3u: { + bb.apply(latt, {{i,j}}, time_step); + }; break; } } } - // Collide - apply_for_cells([&](auto& cell, std::size_t i, std::size_t j){ - auto& df = even_step ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - auto& info = cell.template get<"info">(); - - auto info_val = info({0u}).get(); - switch(info_val){ - case 2u: - // bb.apply(df); - bb_lid.apply(df); - break; - case 3u: - bb.apply(df); - break; - } - }, latt); // Stream for(uint64_t i = 1; (i+1) < latt.template get_dim_size<0>().get(); ++i){ -- cgit v1.2.3