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++/examples/cavity_2d.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'c++/examples') 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