From b097a89f1dd01eb57e605ab2e3002fff127787af Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 24 Mar 2026 12:14:57 +0100 Subject: Do more env handling --- lib/core/c++/environment.hpp | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/core/c++/environment.hpp b/lib/core/c++/environment.hpp index 9e587d0..f9bac48 100644 --- a/lib/core/c++/environment.hpp +++ b/lib/core/c++/environment.hpp @@ -7,18 +7,70 @@ namespace kel { namespace lbm { +struct environment { + std::filesystem::path lbm_dir; + std::filesystem::path data_dir; +}; + +saw::error_or lbm_directory(){ + namespace fs = std::filesystem; + + const char* home_dir = std::getenv("HOME"); + if(not home_dir){ + return saw::make_error("Couldn't find home dir"); + } + + environment env; + + env.lbm_dir = std::filesystem::path{home_dir} / ".lbm"; + + { + env.data_dir = env.lbm_dir / "data"; + // LBM + auto lbm_dir_config = lbm_dir / "data_dir_location.txt"; + if( fs::exists(lbm_dir_config) && fs::is_regular_file(lbm_dir_config) ){ + std::ifstream file{lbm_dir_config}; + + if(file.is_open()){ + std::stringstream buffer; + buffer < output_directory(){ + namespace fs = std::filesystem; + const char* home_dir = std::getenv("HOME"); if(not home_dir){ return saw::make_error("Couldn't find home dir"); } - return std::filesystem::path{home_dir} / ".lbm"; + auto lbm_dir = std::filesystem::path{home_dir} / ".lbm"; + + { + auto lbm_dir_config = lbm_dir / "data_dir_location.txt"; + if( fs::exists(lbm_dir_config) && fs::is_regular_file(lbm_dir_config) ){ + std::ifstream file{lbm_dir_config}; + + if(file.is_open()){ + std::stringstream buffer; + buffer < Date: Tue, 24 Mar 2026 12:44:17 +0100 Subject: Moving dir and fixing env error --- lib/core/c++/environment.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/core/c++/environment.hpp b/lib/core/c++/environment.hpp index f9bac48..27d8f3a 100644 --- a/lib/core/c++/environment.hpp +++ b/lib/core/c++/environment.hpp @@ -26,8 +26,8 @@ saw::error_or lbm_directory(){ { env.data_dir = env.lbm_dir / "data"; - // LBM - auto lbm_dir_config = lbm_dir / "data_dir_location.txt"; + // LBM Data Location + auto lbm_dir_config = env.lbm_dir / "data_dir_location.txt"; if( fs::exists(lbm_dir_config) && fs::is_regular_file(lbm_dir_config) ){ std::ifstream file{lbm_dir_config}; -- cgit v1.2.3 From 72e61f9d345c43a6106e68c207bb0d2e11237adb Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 24 Mar 2026 15:48:47 +0100 Subject: Fixing guo Forcing --- lib/core/c++/abstract/templates.hpp | 3 +++ lib/core/c++/collision.hpp | 41 ++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/core/c++/abstract/templates.hpp b/lib/core/c++/abstract/templates.hpp index d4d4ace..f675a99 100644 --- a/lib/core/c++/abstract/templates.hpp +++ b/lib/core/c++/abstract/templates.hpp @@ -1,4 +1,7 @@ #pragma once namespace kel { +namespace lbm { + +} } diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp index ef6bfe2..f8312c0 100644 --- a/lib/core/c++/collision.hpp +++ b/lib/core/c++/collision.hpp @@ -115,39 +115,56 @@ public: static constexpr saw::string_literal after = ""; static constexpr saw::string_literal before = "streaming"; - template - void apply(saw::data& field, saw::data> index, saw::data time_step){ + template + void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { + // void apply(saw::data& field, saw::data> index, saw::data 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); - saw::data> rho; - saw::data> vel; + auto& rho_f = macros.template get<"density">(); + auto& vel_f = macros.template get<"velocity">(); + + saw::data>& rho = rho_f.at(index); + saw::data>& vel = vel_f.at(index); + compute_rho_u(dfs_old_f.at(index),rho,vel); auto eq = equilibrium(rho,vel); using dfi = df_info; - auto& force_f = field.template get<"force">(); + auto& force_f = macros.template get<"force">(); auto& force = force_f.at(index); + + saw::data> dfi_inv_cs2; + dfi_inv_cs2.at({}).set(dfi::inv_cs2); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ // saw::data ci_min_u{0}; - saw::data ci_dot_u{0}; + saw::data> ci; for(uint64_t d = 0u; d < Descriptor::D; ++d){ - ci_dot_u = ci_dot_u + vel.at({{d}}) * saw::data{static_cast::type>(dfi::directions[i][d])}; + ci.at({{d}}).set(static_cast::type>(dfi::directions[i][d])); } - saw::data F_i{0};// = saw::data{dfi::weights[i]} * (ci_dot_F * dfi::inv_cs2 + ci_dot_u * ci_dot_F * (dfi::inv_cs2 * dfi::inv_cs2)); + auto ci_dot_u = saw::math::dot(ci,vel); + + // saw::data> F_i; + // F_i = f * (c_i - u * ics2 + * c_i * ics2 * ics2) * w_i; + saw::data> 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> F_i_sum; for(uint64_t d = 0u; d < Descriptor::D; ++d){ - F_i = F_i + - saw::data{dfi::weights[i]} * ((saw::data{static_cast::type>(dfi::directions[i][d])} - - vel.at({d}) ) * dfi::inv_cs2 + ci_dot_u * saw::data{static_cast::type>(dfi::directions[i][d])} * dfi::inv_cs2 * dfi::inv_cs2 ) * force.at({d}); + saw::data> 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 * (saw::data{1} - saw::data{0.5f} * frequency_); + dfs.at({i}) = dfs.at({i}) + frequency_ * (eq.at(i) - dfs.at({i}) ) + F_i_d.at({}) * (saw::data{1} - saw::data{0.5f} * frequency_); } } }; -- cgit v1.2.3 From 3af0e20773b21b519ea474e34e7c1df73d04a307 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 24 Mar 2026 17:41:28 +0100 Subject: Dangling changes --- lib/core/c++/collision.hpp | 15 +++++++++++++-- lib/core/c++/particle/particle.hpp | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp index f8312c0..df45bbe 100644 --- a/lib/core/c++/collision.hpp +++ b/lib/core/c++/collision.hpp @@ -95,10 +95,21 @@ class component { private: typename saw::native_data_type::type relaxation_; saw::data frequency_; + saw::data> global_force_; public: component(typename saw::native_data_type::type relaxation__): relaxation_{relaxation__}, - frequency_{typename saw::native_data_type::type(1) / relaxation_} + frequency_{typename saw::native_data_type::type(1) / relaxation_}, + global_force_{} + {} + + component( + typename saw::native_data_type::type relaxation__, + saw::data>& global_force__ + ): + relaxation_{relaxation__}, + frequency_{typename saw::native_data_type::type(1) / relaxation_}, + global_force_{global_force__} {} using Component = cmpt::BGKGuo; @@ -153,7 +164,7 @@ public: saw::data> 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 )); + 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> F_i_sum; for(uint64_t d = 0u; d < Descriptor::D; ++d){ diff --git a/lib/core/c++/particle/particle.hpp b/lib/core/c++/particle/particle.hpp index 8ef590d..f8104fd 100644 --- a/lib/core/c++/particle/particle.hpp +++ b/lib/core/c++/particle/particle.hpp @@ -43,12 +43,15 @@ using ParticleCollisionSpheroid = Struct< Member, "radius"> >; +tem + template> using Particle = Struct< Member, "rigid_body">, Member, // Problem is that dynamic data would two layered - // Member, "mask">, + // Member, "mask">, + Member, Member, "mass"> >; } -- cgit v1.2.3