From abeea9920c11231ed24db00e9f68b4490c12a61b Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Thu, 10 Apr 2025 15:21:55 +0200 Subject: Reworking from AoS to SoA for data handling --- c++/converter.hpp | 2 +- c++/descriptor.hpp | 57 ++++++++++++++++++++++++++++++++++++---------- c++/equilibrium.hpp | 6 ++++- c++/examples/cavity_2d.cpp | 11 ++++----- c++/lbm_unit.hpp | 2 +- c++/particle/particle.hpp | 17 ++++++++++++++ 6 files changed, 74 insertions(+), 21 deletions(-) (limited to 'c++') diff --git a/c++/converter.hpp b/c++/converter.hpp index bc307f5..e07847f 100644 --- a/c++/converter.hpp +++ b/c++/converter.hpp @@ -1,6 +1,6 @@ #pragma once -#include "lbm_unit.h" +#include "lbm_unit.hpp" namespace kel { namespace lbm { diff --git a/c++/descriptor.hpp b/c++/descriptor.hpp index 5ee9918..376e733 100644 --- a/c++/descriptor.hpp +++ b/c++/descriptor.hpp @@ -22,14 +22,14 @@ struct Cell { static constexpr uint64_t Size = SC + Desc::D * DC + Desc::Q * QC; }; -template -struct Field; +template +struct CellFields; -template -struct Field< +template +struct CellFields< Desc, Struct< - CellMembers... + Member, CellFieldNames>... > >; @@ -38,6 +38,37 @@ struct Field< template class df_info{}; +template +class df_info> { +public: + using Descriptor = sch::Descriptor<1,3>; + + static constexpr uint64_t D = 1u; + static constexpr uint64_t Q = 3u; + + static constexpr std::array,Q> directions = {{ + { 0}, + {-1}, + { 1} + }}; + + static constexpr std::array::type, Q> weights = { + 2./3., + 1./6., + 1./6. + }; + + static constexpr std::array opposite_index = { + 0,2,1 + }; + + static constexpr typename saw::native_data_type::type inv_cs2 = 3.0; + static constexpr typename saw::native_data_type::type cs2 = 1./3.; +}; + +/** + * D2Q5 Descriptor + */ template class df_info> { public: @@ -132,9 +163,9 @@ struct meta_schema> { }; template -struct meta_schema> { +struct meta_schema> { using MetaSchema = schema::FixedArray; - using Schema = kel::lbm::sch::Field; + using Schema = kel::lbm::sch::CellFields; }; template @@ -156,16 +187,18 @@ public: }; template -class data, Encode> final { +class data, Encode> final { public: - using Schema = kel::lbm::sch::Field; + using Schema = kel::lbm::sch::CellFields; using MetaSchema = typename meta_schema::MetaSchema; private: - data, Encode> inner_; + data inner_; + data inner_meta_; public: data() = default; - data(const data>& inner_meta__): - inner_{inner_meta__} + data(const data& inner_meta__): + inner_{inner_meta__}, + inner_meta_{inner_meta__} {} template diff --git a/c++/equilibrium.hpp b/c++/equilibrium.hpp index 8342ed4..326fc9e 100644 --- a/c++/equilibrium.hpp +++ b/c++/equilibrium.hpp @@ -9,7 +9,11 @@ saw::data> equilibrium(saw::data rho, using dfi = df_info; saw::data> eq; - saw::data vel_vel{}; + // ^ + // 0.0 + // / \ + // | | + saw::data vel_vel{0.0}; for(uint64_t j = 0u; j < Descriptor::D; ++j){ vel_vel = vel_vel + vel.at(j) * vel.at(j); } diff --git a/c++/examples/cavity_2d.cpp b/c++/examples/cavity_2d.cpp index 9e91c6c..f93bc64 100644 --- a/c++/examples/cavity_2d.cpp +++ b/c++/examples/cavity_2d.cpp @@ -37,12 +37,12 @@ using CellInfo = Cell; */ template using CellStruct = Struct< - Member, "dfs">, - Member, "info"> + Member,Desc::D>, "dfs">, + Member,Desc::D>, "info"> >; -using CavityFieldD2Q9 = Field>; +using CavityFieldD2Q9 = CellFields>; } /** @@ -350,9 +350,8 @@ void lbm_step( // Stream for(uint64_t i = 1; (i+1) < old_latt.template get_dim_size<0>().get(); ++i){ for(uint64_t j = 1; (j+1) < old_latt.template get_dim_size<1>().get(); ++j){ - auto& cell_new = new_latt({{i,j}}); - auto& df_new = cell_new.template get<"dfs">(); - auto& info_new = cell_new.template get<"info">(); + auto& df_new = new_latt.template get<"dfs">()({{i,j}}); + auto& info_new = new_latt.template get<"info">()({{i,j}}); if(info_new({0u}).get() > 0u && info_new({0u}).get() != 2u){ for(uint64_t k = 0u; k < sch::D2Q9::Q; ++k){ diff --git a/c++/lbm_unit.hpp b/c++/lbm_unit.hpp index c4d09f6..dc1f8e9 100644 --- a/c++/lbm_unit.hpp +++ b/c++/lbm_unit.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/c++/particle/particle.hpp b/c++/particle/particle.hpp index fd0ff59..58c028c 100644 --- a/c++/particle/particle.hpp +++ b/c++/particle/particle.hpp @@ -20,6 +20,23 @@ template using ParticleMask = Struct< Member, "mask"> >; + +template +using Particle = Struct< + Member, "rigid_body"> +>; } + +template +class particle_system { +private: + saw::data>> particles_; +public: + + void step(T time_step){ + for(auto& iter : particles_){ + } + } +}; } } -- cgit v1.2.3