From f3dde8285baf87a89d2a9b79ac719573c47538ff Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sat, 2 Sep 2023 18:04:18 +0200 Subject: c++: Generating example layouts --- c++/collide_and_stream.h | 3 --- c++/descriptor.h | 24 +++++++++---------- c++/examples/cavity_2d.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 16 deletions(-) diff --git a/c++/collide_and_stream.h b/c++/collide_and_stream.h index 5682437..5cbb551 100644 --- a/c++/collide_and_stream.h +++ b/c++/collide_and_stream.h @@ -2,8 +2,5 @@ namespace kel { namespace lbm { -class bgk_dynamics { - -}; } } diff --git a/c++/descriptor.h b/c++/descriptor.h index 4d29831..33fef9b 100644 --- a/c++/descriptor.h +++ b/c++/descriptor.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace kel { namespace lbm { @@ -32,24 +32,24 @@ template class df_info{}; template -class df_info> { - static constexpr std::array, 5> directions = { +class df_info> { + static constexpr std::array, 5> directions = {{ { 0, 0}, {-1, 0}, { 0,-1}, { 0, 1}, { 1, 0} + }}; + + static constexpr std::array::type,5> weights = { + 1./3., + 1./6., + 1./6., + 1./6., + 1./6. }; - static constexpr std::array,5> weights = { - {1,3}, - {1,6}, - {1,6}, - {1,6}, - {1,6} - }; - - static constexpr std::ratio cs2 = {1,3}; + static constexpr typename saw::native_data_type::type cs2 = 1./3.; }; } } diff --git a/c++/examples/cavity_2d.cpp b/c++/examples/cavity_2d.cpp index e06ba2d..88e53fe 100644 --- a/c++/examples/cavity_2d.cpp +++ b/c++/examples/cavity_2d.cpp @@ -17,7 +17,8 @@ namespace schema { * D factor * Q factor */ -using DfCell2DType = CellType; +using T = Float32; +using DfCell2DType = CellType; using CellInfo2DType = CellType; @@ -30,9 +31,59 @@ using Cell = CellData< >; } + +template +class collision { +public: + typename saw::native_data_type::type relaxation_; +public: + std::array::type,Q> equilibrium( + typename saw::native_data_type::type rho, + std::array::type, D> vel + ){ + using dfi = df_info>; + + typename std::array::type,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]); + auto vel_c_cs2 = vel_c / dfi::cs2; + eq[i] = dfi::weights[i] * rho * ( + 1 + + vel_c_cs2 + + vel_c_cs2 * vel_c_cs2 + - ( vel[0] * vel[0] + vel[1] * vel[1] ) / ( 2. * dfi::cs2 ) + ); + } + + return eq; + + } + + void compute_rho_u( + saw::data& dfs, + typename saw::native_data_type::type& rho, + std::array::type, 2>& vel + ){ + using dfi = df_info>; + + rho = 0; + std::fill(vel.begin(), vel.end(), 0); + + for(size_t i = 0; i < Q; ++i){ + rho += dfs[i]; + vel[0] += dfi::directions[i][0] * dfs.at(i).get(); + vel[1] += dfi::directions[i][1] * dfs.at(i).get(); + } + + vel[0] /= rho; + vel[1] /= rho; + } +}; } } +constexpr size_t dim_size = 2; constexpr size_t dim_x = 32; constexpr size_t dim_y = 32; @@ -95,6 +146,10 @@ int main(){ */ set_initial_conditions(lattice); + /** + * Timeloop + */ + /** * Print basic setup info */ -- cgit v1.2.3