diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-05-08 12:32:54 +0200 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-05-08 12:32:54 +0200 |
| commit | 22c8f0540533c2d77201e90cdcd3dc30524a89e4 (patch) | |
| tree | b99a9780d7fe327c093ae9d714dcbeccb150cdc5 /lib | |
| parent | 4f47c2c5631b6cadef3a74eca52bb40a3c5f75a9 (diff) | |
| parent | a8c333ce640b8ca2b1923f96ff13d4e6faf55c86 (diff) | |
| download | libs-lbm-master.tar.gz | |
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/core/c++/collision.hpp | 35 | ||||
| -rw-r--r-- | lib/core/c++/fplbm.hpp | 177 | ||||
| -rw-r--r-- | lib/core/c++/lbm.hpp | 5 | ||||
| -rw-r--r-- | lib/core/c++/rar.hpp | 25 |
4 files changed, 231 insertions, 11 deletions
diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp index df45bbe..9c76c1a 100644 --- a/lib/core/c++/collision.hpp +++ b/lib/core/c++/collision.hpp @@ -66,7 +66,7 @@ public: dfs_old_f.at(index).at({i}) = dfs_old_f.at(index).at({i}) + frequency_ * (eq.at(i) - dfs_old_f.at(index).at({i})); } } - + template<typename CellFieldSchema, typename MacroFieldSchema> void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, saw::data<sch::UInt64> time_step) const { bool is_even = ((time_step.get() % 2) == 0); @@ -76,12 +76,12 @@ public: auto& rho_f = macros.template get<"density">(); auto& vel_f = macros.template get<"velocity">(); - + saw::data<sch::Scalar<T>>& rho = rho_f.at(index); saw::data<sch::Vector<T,Descriptor::D>>& vel = vel_f.at(index); compute_rho_u<T,Descriptor>(dfs_old_f.at(index),rho,vel); - + auto eq = equilibrium<T,Descriptor>(rho,vel); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ @@ -138,18 +138,27 @@ public: auto& vel_f = macros.template get<"velocity">(); saw::data<sch::Scalar<T>>& rho = rho_f.at(index); - saw::data<sch::Vector<T,Descriptor::D>>& vel = vel_f.at(index); + + auto& force_f = macros.template get<"force">(); + auto& force = force_f.at(index); + + auto total_force = force + global_force_; + + saw::data<sch::Scalar<T>> half; + half.at({}).set(0.5); + saw::data<sch::Vector<T,Descriptor::D>> vel = vel_f.at(index) + total_force * ( half / rho ); compute_rho_u<T,Descriptor>(dfs_old_f.at(index),rho,vel); auto eq = equilibrium<T,Descriptor>(rho,vel); using dfi = df_info<T,Descriptor>; - auto& force_f = macros.template get<"force">(); - auto& force = force_f.at(index); saw::data<sch::Scalar<T>> dfi_inv_cs2; dfi_inv_cs2.at({}).set(dfi::inv_cs2); + + + // auto vel = vel_f.at(index); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ // saw::data<T> ci_min_u{0}; @@ -160,11 +169,10 @@ public: auto ci_dot_u = saw::math::dot(ci,vel); // saw::data<sch::Vector<T,Descriptor::D>> F_i; - // F_i = f * (c_i - u * ics2 + <c_i,u> * c_i * ics2 * ics2) * w_i; + // F_i = f * ((c_i - u) * ics2 + <c_i,u> * c_i * ics2 * ics2) * w_i; saw::data<sch::Scalar<T>> w; w.at({}).set(dfi::weights[i]); - auto F_i_d = saw::math::dot((force+global_force_) * w, (ci - vel * dfi_inv_cs2 + ci * ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2 )); /* saw::data<sch::Scalar<T>> F_i_sum; for(uint64_t d = 0u; d < Descriptor::D; ++d){ @@ -173,9 +181,18 @@ public: F_i_sum = F_i_sum + F_i_d; } */ + auto term1 = (ci-vel) * dfi_inv_cs2; + auto term2 = ci * (ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2); + + auto force_projection = saw::math::dot(term1 + term2, total_force); + auto F_i = w * force_projection; - dfs.at({i}) = dfs.at({i}) + frequency_ * (eq.at(i) - dfs.at({i}) ) + F_i_d.at({}) * (saw::data<T>{1} - saw::data<T>{0.5f} * frequency_); + dfs.at({i}) = dfs.at({i}) + + frequency_ + * (eq.at(i) - dfs.at({i}) ) + + F_i.at({}) + * (saw::data<T>{1} - saw::data<T>{0.5f} * frequency_); } } }; diff --git a/lib/core/c++/fplbm.hpp b/lib/core/c++/fplbm.hpp new file mode 100644 index 0000000..61def6b --- /dev/null +++ b/lib/core/c++/fplbm.hpp @@ -0,0 +1,177 @@ +#pragma once + +#include "common.hpp" + +namespace kel { +namespace lbm { +namespace cmpt { +struct FpLbm {}; +struct FpLbmOneParticleNoVelocity{}; +} + +template<typename T, typename Descriptor, typename Encode> +class component<T, Descriptor, cmpt::FpLbm, Encode> final { +private: + saw::data<T> relaxation_; + saw::data<T> frequency_; +public: + component(typename saw::native_data_type<T>::type relaxation__): + relaxation_{{relaxation__}}, + frequency_{saw::data<T>{1} / relaxation_} + {} + + component(const saw::data<T>& relaxation__): + relaxation_{relaxation__}, + frequency_{saw::data<T>{1} / relaxation_} + {} + + using Component = cmpt::FpLbm; + + + template<typename CellFieldSchema, typename MacroFieldSchema> + void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, saw::data<sch::UInt64> time_step) const { + // void apply(saw::data<CellFieldSchema, Encode>& field, saw::data<sch::FixedArray<sch::UInt64, Descriptor::D>> index, saw::data<sch::UInt64> time_step){ + bool is_even = ((time_step.get() % 2) == 0); + + auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); + auto& dfs = dfs_old_f.at(index); + + auto& rho_f = macros.template get<"density">(); + auto& vel_f = macros.template get<"velocity">(); + + saw::data<sch::Scalar<T>>& rho = rho_f.at(index); + saw::data<sch::Vector<T,Descriptor::D>>& vel = vel_f.at(index); + + compute_rho_u<T,Descriptor>(dfs_old_f.at(index),rho,vel); + auto eq = equilibrium<T,Descriptor>(rho,vel); + + using dfi = df_info<T,Descriptor>; + + auto& force_f = macros.template get<"force">(); + auto& force = force_f.at(index); + + auto& porosity_f = macros.template get<"porosity">(); + auto& porosity = porosity_f.at(index); + + saw::data<sch::Scalar<T>> dfi_inv_cs2; + dfi_inv_cs2.at({}).set(dfi::inv_cs2); + + for(uint64_t i = 0u; i < Descriptor::Q; ++i){ + // saw::data<T> ci_min_u{0}; + saw::data<sch::Vector<T,Descriptor::D>> ci; + for(uint64_t d = 0u; d < Descriptor::D; ++d){ + ci.at({{d}}).set(static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d])); + } + auto ci_dot_u = saw::math::dot(ci,vel); + + // saw::data<sch::Vector<T,Descriptor::D>> F_i; + // F_i = f * (c_i - u * ics2 + <c_i,u> * c_i * ics2 * ics2) * w_i; + saw::data<sch::Scalar<T>> w; + w.at({}).set(dfi::weights[i]); + + auto F_i_d = saw::math::dot(force * w, (ci - vel * dfi_inv_cs2 + ci * ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2 )); + /* + saw::data<sch::Scalar<T>> F_i_sum; + for(uint64_t d = 0u; d < Descriptor::D; ++d){ + saw::data<sch::Scalar<T>> F_i_d; + F_i_d.at({}) = F_i.at({{d}}); + F_i_sum = F_i_sum + F_i_d; + } + */ + + dfs.at({i}) = dfs.at({i}) + frequency_ * (eq.at(i) - dfs.at({i}) ) + F_i_d.at({}) * (saw::data<T>{1} - saw::data<T>{0.5f} * frequency_); + } + } +}; + +template<typename T, typename Descriptor, typename Encode> +class component<T, Descriptor, cmpt::FpLbmOneParticleNoVelocity, Encode> final { +private: + saw::data<T> relaxation_; + saw::data<T> frequency_; +public: + component(typename saw::native_data_type<T>::type relaxation__): + relaxation_{{relaxation__}}, + frequency_{saw::data<T>{1} / relaxation_} + {} + + component(const saw::data<T>& relaxation__): + relaxation_{relaxation__}, + frequency_{saw::data<T>{1} / relaxation_} + {} + + using Component = cmpt::FpLbmOneParticleNoVelocity; + + template<typename CellFieldSchema, typename MacroFieldSchema> + void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, saw::data<sch::UInt64> time_step) const { + // void apply(saw::data<CellFieldSchema, Encode>& field, saw::data<sch::FixedArray<sch::UInt64, Descriptor::D>> index, saw::data<sch::UInt64> time_step){ + bool is_even = ((time_step.get() % 2) == 0); + + auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); + auto& dfs = dfs_old_f.at(index); + + auto& rho_f = macros.template get<"density">(); + auto& vel_f = macros.template get<"velocity">(); + auto& por_f = macros.template get<"porosity">(); + + saw::data<sch::Scalar<T>>& rho = rho_f.at(index); + + saw::data<sch::Scalar<T>> half; + half.at({}).set(0.5); + saw::data<sch::Vector<T,Descriptor::D>>& vel = vel_f.at(index);// + total_force * ( half / rho ); + + compute_rho_u<T,Descriptor>(dfs_old_f.at(index),rho,vel); + auto eq = equilibrium<T,Descriptor>(rho,vel); + + using dfi = df_info<T,Descriptor>; + + saw::data<sch::Scalar<T>> min_two; + min_two.at({}).set(-2); + + auto force = vel * rho * min_two * por_f.at(index); + + saw::data<sch::Scalar<T>> dfi_inv_cs2; + dfi_inv_cs2.at({}).set(dfi::inv_cs2); + + + // auto vel = vel_f.at(index); + + for(uint64_t i = 0u; i < Descriptor::Q; ++i){ + // saw::data<T> ci_min_u{0}; + saw::data<sch::Vector<T,Descriptor::D>> ci; + for(uint64_t d = 0u; d < Descriptor::D; ++d){ + ci.at({{d}}).set(static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d])); + } + auto ci_dot_u = saw::math::dot(ci,vel); + + // saw::data<sch::Vector<T,Descriptor::D>> F_i; + // F_i = f * ((c_i - u) * ics2 + <c_i,u> * c_i * ics2 * ics2) * w_i; + saw::data<sch::Scalar<T>> w; + w.at({}).set(dfi::weights[i]); + + /* + saw::data<sch::Scalar<T>> F_i_sum; + for(uint64_t d = 0u; d < Descriptor::D; ++d){ + saw::data<sch::Scalar<T>> F_i_d; + F_i_d.at({}) = F_i.at({{d}}); + F_i_sum = F_i_sum + F_i_d; + } + */ + auto term1 = (ci-vel) * dfi_inv_cs2; + auto term2 = ci * (ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2); + + auto force_projection = saw::math::dot(term1 + term2, force); + + auto F_i = w * force_projection; + + dfs.at({i}) = dfs.at({i}) + + frequency_ + * (eq.at(i) - dfs.at({i}) ) + + F_i.at({}) + * (saw::data<T>{1} - saw::data<T>{0.5f} * frequency_); + } + } + +}; +} +} diff --git a/lib/core/c++/lbm.hpp b/lib/core/c++/lbm.hpp index 29de83e..fbad908 100644 --- a/lib/core/c++/lbm.hpp +++ b/lib/core/c++/lbm.hpp @@ -2,8 +2,6 @@ #include "args.hpp" #include "schema.hpp" -#include "flatten.hpp" -#include "chunk.hpp" #include "descriptor.hpp" #include "boundary.hpp" #include "converter.hpp" @@ -12,6 +10,9 @@ #include "component.hpp" #include "environment.hpp" #include "equilibrium.hpp" +#include "flatten.hpp" +#include "fplbm.hpp" +#include "chunk.hpp" #include "iterator.hpp" #include "hlbm.hpp" #include "macroscopic.hpp" diff --git a/lib/core/c++/rar.hpp b/lib/core/c++/rar.hpp new file mode 100644 index 0000000..dc2b61c --- /dev/null +++ b/lib/core/c++/rar.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "common.hpp" + +namespace kel { +namespace lbm { +saw::error_or<void> run_and_record(int argc, char** argv){ + using RarGit = Struct< + Member<String, "commit">, + Member<String, "origin"> + >; + using RarCommand = Struct< + Member<String, "command">, + Member<Array<String>, "arguments"> + >; + using Rar = Struct< + Member<Array<RarCommand>, "commands">, + Member<UInt64, "runtime_ns">, + Member<RarGit, "git"> + >; + + return saw::make_void(); +} +} +} |
