summaryrefslogtreecommitdiff
path: root/modules/core
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-09-07 15:08:20 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-09-07 15:08:20 +0200
commit96619fc23312e91e9fbe453cb115f116784c032a (patch)
tree9d931191117f54f2134b3ad3615e2092870a99ca /modules/core
parentd2a406aceeb935d4eac1b5ae02e268be4463b6b0 (diff)
parent54dfad7ac102fe40d71d8818d77801160a7073c1 (diff)
downloadlibs-lbm-96619fc23312e91e9fbe453cb115f116784c032a.tar.gz
Merge branch 'dev'HEADmaster
Diffstat (limited to 'modules/core')
-rw-r--r--modules/core/c++/fplbm.hpp143
-rw-r--r--modules/core/c++/hlbm.hpp15
-rw-r--r--modules/core/c++/psm.hpp57
3 files changed, 145 insertions, 70 deletions
diff --git a/modules/core/c++/fplbm.hpp b/modules/core/c++/fplbm.hpp
index 5ad692b..0ab7903 100644
--- a/modules/core/c++/fplbm.hpp
+++ b/modules/core/c++/fplbm.hpp
@@ -10,7 +10,7 @@ namespace cmpt {
struct FpLbmReset{};
struct FpLbm {};
struct FpLbmOneParticle {};
-struct FpLbmOneParticleImplicit {};
+struct FpLbmMomentumOneParticle {};
struct FpLbmOneParticleNoVelocity{};
}
namespace method {
@@ -132,6 +132,145 @@ public:
};
template<typename T, typename Descriptor, typename Encode>
+class component<T, Descriptor, cmpt::FpLbmMomentumOneParticle, Encode> final {
+public:
+ using Component = cmpt::FpLbmOneParticle;
+private:
+ saw::data<sch::Vector<T,Descriptor::D>> global_force_;
+public:
+ component():
+ global_force_{}
+ {}
+ component(saw::data<sch::Vector<T,Descriptor::D>> global_force__):
+ global_force_{global_force__}
+ {}
+
+ template<typename CellFieldSchema, typename MacroFieldSchema, typename ParticleSchema>
+ void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, const saw::data<ParticleSchema,Encode>& part_group, saw::data<sch::FixedArray<sch::UInt64,1u>> index, saw::data<sch::UInt64> time_step, saw::data<sch::UInt64> sub_steps) const {
+ /// Figure out how to access the particle list
+ // auto& p = particles.at(i);
+
+ /// Iterate over the grid bounds
+ // auto& grid = p.template get<"grid">();
+ using dfi = df_info<T,Descriptor>;
+ bool is_even = ((time_step.get() % 2) == 0);
+
+ saw::data<sch::Scalar<T>> one;
+ one.at({}) = 1.0;
+
+ auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
+
+ auto& part_spheroid_group = part_group;
+ auto& mvel_f = macros.template get<"momentum">();
+ auto& mrho_f = macros.template get<"density">();
+ auto& mpor_f = macros.template get<"porosity">();
+
+ auto& particle_N_f = field.template get<"particle_N">();
+ auto& particle_D_f = field.template get<"particle_D">();
+ {
+ auto parts = part_spheroid_group.template get<"particles">();
+ auto parts_size = parts.meta().at({0u});
+
+ auto& p_coll = part_spheroid_group.template get<"collision">().at({});
+ auto& p_rad = p_coll.template get<"radius">();
+
+ auto& pi = parts.at(index);
+ auto& pirb = pi.template get<"rigid_body">();
+ saw::data<sch::Vector<T,Descriptor::D>>& pirb_pos = pirb.template get<"position">();
+ auto& pirb_pos_old = pirb.template get<"position_old">();
+
+ // TODO !!!! Divide by actual time step - for now it's ok
+ saw::data<sch::Scalar<T>> ts;
+ ts.at({}) = one.at({}) / sub_steps.template cast_to<T>();
+
+ saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> start;
+ saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> stop;
+
+ auto eo_aabb = particle_aabb<typename ParticleSchema::ValueType>::calculate(part_spheroid_group,{{0u}},mvel_f.meta());
+ if(eo_aabb.is_error()){
+ return;
+ }
+ auto& aabb = eo_aabb.get_value();
+
+ /// Ok, I iterate over the space which covers our particle? So lower bounds to upper bounds
+ start = aabb.template get<"a">();
+ stop = aabb.template get<"b">();
+
+ saw::data<sch::Vector<T,Descriptor::D>> force_p;
+ for(uint64_t i{0u}; i < Descriptor::D; ++i){
+ force_p.at({{i}}) = 0.0;
+ }
+ auto vel_p_old = (pirb_pos-pirb_pos_old) / ts;
+
+ iterator<Descriptor::D>::apply([&](const auto& index_f) -> void{
+ auto& dfs = dfs_old_f.at(index_f);
+ saw::data<sch::Vector<T,Descriptor::D>> rel_dist = saw::math::vectorize_data(index_f).template cast_to<T>() - pirb_pos;
+ saw::data<sch::Scalar<T>> eps;
+ eps.at({}) = 1.5f;
+
+ auto& mpor = mpor_f.at(index_f);
+ mpor = particle_porosity<T,Descriptor::D,1u,por::ParticleSpheroid<T>>::calculate(rel_dist,p_rad,eps);
+
+ if(mpor.at({}).get() >= 1.0f){
+ return;
+ }
+
+ saw::data<sch::Vector<T,Descriptor::D>> momentum;
+ for(uint64_t i{0u}; i < Descriptor::D; ++i){
+ momentum.at({{i}}) = 0.0;
+ }
+
+ for(uint64_t i{0u}; i < Descriptor::Q; ++i){
+ saw::data<sch::Vector<T,Descriptor::D>> e_i;
+ saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> n_ind_i;
+ for(uint64_t k{0u}; k < Descriptor::D; ++k){
+ e_i.at({{k}}) = (dfi::directions[i])[k];
+ n_ind_i.at({k}) = index_f.at({k}) + (dfi::directions[i])[k];
+ }
+
+ uint64_t i_opp = dfi::opposite_index[i];
+
+ auto u_p_e = saw::math::dot(e_i,vel_p_old);
+
+ saw::data<T> dfs_added = dfs.at({i})*(saw::data<T>{1}-u_p_e.at({})) + dfs_old_f.at(n_ind_i).at({i_opp})*(saw::data<T>{1}+u_p_e.at({}));
+ saw::data<sch::Scalar<T>> dfs_added_v;
+ dfs_added_v.at({}) = dfs_added;
+ auto ei_dfs = e_i * dfs_added_v;
+
+ momentum = momentum + ei_dfs;
+ }
+
+ // TODO technically needs to adjust for rotation as well
+
+ auto& rho = mrho_f.at(index_f);
+
+ macros.template get<"force">().at(index_f) = momentum;
+ force_p = force_p + momentum;
+ },start,stop);
+
+ auto& pirb_acc = pirb.template get<"acceleration">();
+ pirb_acc = - force_p / part_spheroid_group.template get<"total_mass">().at({});
+
+ for(saw::data<sch::UInt64> i{0u}; i < sub_steps; ++i){
+ verlet_step_lambda<T,Descriptor::D>(pi,ts);
+ }
+ auto vel_p = (pirb_pos-pirb_pos_old) / ts;
+
+ iterator<Descriptor::D>::apply([&](const auto& index_f){
+ auto& N = particle_N_f.at(index_f);
+ auto& D = particle_D_f.at(index_f);
+ auto& mpor = mpor_f.at(index_f);
+ auto flip_porosity = one - mpor;
+
+ D = D + flip_porosity;
+ N = N + vel_p * flip_porosity;
+ },start,stop);
+ // Check
+ }
+ }
+};
+
+template<typename T, typename Descriptor, typename Encode>
class component<T, Descriptor, cmpt::FpLbmOneParticle, Encode> final {
public:
using Component = cmpt::FpLbmOneParticle;
@@ -213,7 +352,7 @@ public:
// vel_s is technically time the density of the particle?
- force = ( vel_s - mom) * flip_por;
+ force = global_force_ * por + ( vel_s - mom) * two * flip_por;
// force = (vel_s - mom) * flip_por / (flip_por / two + one);
force_p = force_p - force;
diff --git a/modules/core/c++/hlbm.hpp b/modules/core/c++/hlbm.hpp
index e8ea66a..0df5896 100644
--- a/modules/core/c++/hlbm.hpp
+++ b/modules/core/c++/hlbm.hpp
@@ -102,12 +102,6 @@ public:
template<typename T, typename Desc, typename Encode>
class component<T, Desc, cmpt::HlbmOneParticle, Encode> final {
private:
-/*
- template<typename CellFieldSchema, typename MacroFieldSchema, typename ParticleSchema, uint64_t i>
- void apply_i(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, const saw::data<ParticleSchema,Encode>& part_groups, saw::data<sch::FixedArray<sch::UInt64,1u>> index, saw::data<sch::UInt64> time_step) const {
- // if constexpr ( i < )
- }
-*/
public:
template<typename CellFieldSchema, typename MacroFieldSchema, typename ParticleSchema>
void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, const saw::data<ParticleSchema,Encode>& part_group, saw::data<sch::FixedArray<sch::UInt64,1u>> index, saw::data<sch::UInt64> time_step, saw::data<sch::UInt64> sub_steps) const {
@@ -167,10 +161,6 @@ public:
auto vel_p_old = (pirb_pos-pirb_pos_old) / ts;
iterator<Desc::D>::apply([&](const auto& index_f) -> void{
- // ask for the d_k value here.
- // For every value im iterating over I need sth
- // std::cout<<"Pos: "<<index.at({0u}).get()<<" "<<index.at({1u}).get()<<std::endl;
-
auto& dfs = dfs_old_f.at(index_f);
saw::data<sch::Vector<T,Desc::D>> rel_dist = saw::math::vectorize_data(index_f).template cast_to<T>() - pirb_pos;
saw::data<sch::Scalar<T>> eps;
@@ -207,9 +197,12 @@ public:
momentum = momentum + ei_dfs;
}
- // technically needs to adjust for rotation as well
+
+ // TODO technically needs to adjust for rotation as well
auto& rho = mrho_f.at(index_f);
+
+ macros.template get<"force">().at(index_f) = momentum;
force_p = force_p + momentum;
},start,stop);
diff --git a/modules/core/c++/psm.hpp b/modules/core/c++/psm.hpp
index 1dca64b..f5a8452 100644
--- a/modules/core/c++/psm.hpp
+++ b/modules/core/c++/psm.hpp
@@ -79,22 +79,6 @@ public:
uint64_t i_opp = dfi::opposite_index[i];
dfs.at({i}) = dfs_cpy.at({i}) + frequency_ * (eq.at(i) - dfs_cpy.at({i})) * porous.at({}) + (dfs_cpy.at({i_opp}) - dfs_cpy.at({i}) ) * flip_porous;
}
-
- auto& force_f = macros.template get<"force">();
- auto& force = force_f.at(index);
- for(uint64_t k{0u}; k < Descriptor::D; ++k){
- force.at({{k}}).set(0);
- }
-
- for(uint64_t i{0u}; i < Descriptor::Q; ++i){
- uint64_t i_opp = dfi::opposite_index[i];
- auto dfs_diff = dfs.at({i}) - dfs.at({i_opp});
- for(uint64_t k{0u}; k < Descriptor::D; ++k){
- force.at({{k}}) = force.at({{k}}) + dfs_diff * dfi::directions[i][k];
- }
- }
-
- force = force * porous;
}
};
@@ -314,14 +298,9 @@ void apply(
/*
* ------------------------------------------------
- * D3Q27 / general Q momentum exchange
- *
* We exclude i=0 because the rest population has
* no momentum.
*
- * The original code summed both directions of
- * every opposite pair. Therefore we apply 1/2
- * after the sum.
* ------------------------------------------------
*/
@@ -425,46 +404,10 @@ void apply(
+ e_i * dfs_added_v;
}
-
- /*
- * ------------------------------------------------
- * Since both i and i_opp were included above,
- * compensate for double counting.
- *
- * This is the important change from your original
- * implementation.
- * ------------------------------------------------
- */
-
-
-
- momentum =
- momentum * half;
-
-
- /*
- * ------------------------------------------------
- * PSM solid fraction
- *
- * por = 1 -> fluid
- * por = 0 -> particle
- *
- * Therefore:
- *
- * flip_por = 1 - por
- * ------------------------------------------------
- */
-
auto flip_por =
one - por;
- /*
- * ------------------------------------------------
- * Force transferred TO FLUID
- * ------------------------------------------------
- */
-
auto& force =
force_f.at(index_f);