summaryrefslogtreecommitdiff
path: root/lib/core/c++
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-02-20 10:53:05 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-02-20 10:53:05 +0100
commitdc1c481df599550fd5717790d908a3879f62960a (patch)
tree097812a0ef10074cfa746ab5a47b71fe37cc3540 /lib/core/c++
parentabd0dbdca5735a8281e5df27181cc08ec51dae54 (diff)
downloadlibs-lbm-dc1c481df599550fd5717790d908a3879f62960a.tar.gz
Fixing Guo forcing problems
Diffstat (limited to 'lib/core/c++')
-rw-r--r--lib/core/c++/collision.hpp14
-rw-r--r--lib/core/c++/psm.hpp39
2 files changed, 42 insertions, 11 deletions
diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp
index f259c9f..ef6bfe2 100644
--- a/lib/core/c++/collision.hpp
+++ b/lib/core/c++/collision.hpp
@@ -118,19 +118,19 @@ public:
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){
bool is_even = ((time_step.get() % 2) == 0);
- auto& cell = field(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_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
+ auto& dfs = dfs_old_f.at(index);
saw::data<sch::Scalar<T>> rho;
saw::data<sch::Vector<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);
using dfi = df_info<T,Descriptor>;
- auto& force = cell.template get<"force">();
+ auto& force_f = field.template get<"force">();
+ auto& force = force_f.at(index);
for(uint64_t i = 0u; i < Descriptor::Q; ++i){
// saw::data<T> ci_min_u{0};
@@ -143,11 +143,11 @@ public:
for(uint64_t d = 0u; d < Descriptor::D; ++d){
F_i = F_i +
saw::data<T>{dfi::weights[i]} * ((saw::data<T>{static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d])}
- - vel.at({d}) ) * dfi::inv_cs2 + ci_dot_u * saw::data<T>{static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d])} * dfi::inv_cs2 * dfi::inv_cs2 ) * force({d});
+ - vel.at({d}) ) * dfi::inv_cs2 + ci_dot_u * saw::data<T>{static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d])} * dfi::inv_cs2 * dfi::inv_cs2 ) * force.at({d});
}
- dfs_old({i}) = dfs_old({i}) + frequency_ * (eq.at(i) - dfs_old({i}) ) + F_i * (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 * (saw::data<T>{1} - saw::data<T>{0.5f} * frequency_);
}
}
};
diff --git a/lib/core/c++/psm.hpp b/lib/core/c++/psm.hpp
index 8e151c3..94d5ccd 100644
--- a/lib/core/c++/psm.hpp
+++ b/lib/core/c++/psm.hpp
@@ -11,23 +11,54 @@ struct PSM {};
}
/**
- * HLBM collision operator for LBM
+ * PSM collision operator for LBM
*/
template<typename T, typename Descriptor, typename Encode>
class component<T, Descriptor, cmpt::PSM> {
private:
+ saw::data<sch::Scalar<T>> relaxation_;
+ saw::data<sch::Scalar<T>> frequency_;
public:
- component() = default;
+ component(
+ saw::data<sch::Scalar<T>> relaxation__
+ ):
+ relaxation_{relaxation__}
+ {
+ saw::data<sch::Scalar<T>> one;
+ frequency_ = one / relaxation_;
+ }
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 {
-
+
+ using dfi = df_info<T,Descriptor>;
bool is_even = ((time_step.get() % 2) == 0);
auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
auto& porous = field.template get<"porosity">();
-
+ 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);
+
+ saw::data<sch::Scalar<T>> one;
+ one.at({}) = 1.0;
+ auto flip_porous = one - porous;
+
+ auto& dfs = dfs_old_f.at(index);
+
+ auto dfs_cpy = dfs;
+
+ for(uint64_t i = 0u; i < Descriptor::Q; ++i){
+ uint64_t i_opp = dfi::opposite_index[i];
+ dfs.at({i}) = dfs_cpy.at({i}) + frequency_ * (eq.at(i) - dfs_cpy.at({i})) * flip_porous + (dfs_cpy.at({i_opp}) - dfs_cpy.at({i}) ) * porous;
+ }
}
};