diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-01-27 09:17:33 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-01-27 09:17:33 +0100 |
| commit | 624f5d8181a449f36950503859271e1a052e8a65 (patch) | |
| tree | 1e7217f411099f7d0b7ad9faf357b69a13aecd0c /lib/core | |
| parent | 6d6452b24e15e6291ba5790ede485f59d4ca28b8 (diff) | |
| download | libs-lbm-dev.tar.gz | |
Double free, but constexpr things compile nowdev
Diffstat (limited to 'lib/core')
| -rw-r--r-- | lib/core/c++/collision.hpp | 34 | ||||
| -rw-r--r-- | lib/core/c++/macroscopic.hpp | 25 |
2 files changed, 30 insertions, 29 deletions
diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp index 2f20601..85c3af9 100644 --- a/lib/core/c++/collision.hpp +++ b/lib/core/c++/collision.hpp @@ -45,43 +45,19 @@ public: * Raw setup */ template<typename CellFieldSchema> - void apply(saw::data<CellFieldSchema, Encode>& field, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, saw::data<sch::UInt64> time_step){ + void apply(const saw::data<CellFieldSchema, Encode>& field, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, saw::data<sch::UInt64> time_step) const { bool is_even = ((time_step.get() % 2) == 0); - auto& cell = field.at(index); - auto& dfs_old = (is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - // auto& dfs = (not is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); + // auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); + auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); saw::data<T> rho; saw::data<sch::FixedArray<T,Descriptor::D>> vel; - compute_rho_u<T,Descriptor>(dfs_old,rho,vel); - auto eq = equilibrium<T,Descriptor>(rho,vel); - - for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - dfs_old({i}) = dfs_old({i}) + frequency_ * (eq.at(i) - dfs_old({i})); - // dfs_old({i}).set(dfs_old({i}).get() + (1.0 / relaxation_) * (eq.at(i).get() - dfs_old({i}).get())); - } - } - - template<typename CellStructSchema> - void apply( - saw::data<CellStructSchema, Encode>* field, - const saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>>& meta, - const saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>>& index, - saw::data<sch::UInt64> time_step - ){ - bool is_even = ((time_step.get() % 2) == 0); - auto& cell = field[0u]; - - auto& dfs_old = (is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - - saw::data<T> rho; - saw::data<sch::FixedArray<T,Descriptor::D>> vel; - compute_rho_u<T,Descriptor>(dfs_old,rho,vel); + 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){ - dfs_old({i}) = dfs_old({i}) + frequency_ * (eq.at(i) - dfs_old({i})); + 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})); } } }; diff --git a/lib/core/c++/macroscopic.hpp b/lib/core/c++/macroscopic.hpp index 51368e9..1532873 100644 --- a/lib/core/c++/macroscopic.hpp +++ b/lib/core/c++/macroscopic.hpp @@ -4,6 +4,31 @@ namespace kel { namespace lbm { +template<typename T, typename Desc> +void compute_rho_u ( + const saw::data<sch::FixedArray<T,Desc::Q>>& dfs, + saw::data<T>& rho, + saw::data<sch::FixedArray<T,Desc::D>>& vel + ) +{ + using dfi = df_info<T, Desc>; + + rho = 0; + for(size_t j = 0; j < Desc::D; ++j){ + vel.at({{j}}).set(0); + } + + for(size_t j = 0; j < Desc::Q; ++j){ + rho = rho + dfs.at({j}); + for(size_t i = 0; i < Desc::D; ++i){ + vel.at({{i}}) = vel.at({{i}}) + dfi::directions[j][i] * dfs.at({j}).get(); + } + } + + for(size_t i = 0; i < Desc::D; ++i){ + vel.at({i}) = vel.at({i}) / rho; + } +} /** * Calculate the macroscopic variables rho and u in Lattice Units. */ |
