diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-09-03 13:42:38 +0200 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-09-03 13:42:38 +0200 |
| commit | 576b566d09194e923f73e0aa5a576bfdb5cfe945 (patch) | |
| tree | 51326d2b3652607325a800d80c4e52cc4ce1f404 /modules/core/c++/fplbm.hpp | |
| parent | 8c2e629878ab1c73c73ae92d76e8883ccfa032a2 (diff) | |
| download | libs-lbm-576b566d09194e923f73e0aa5a576bfdb5cfe945.tar.gz | |
Dangling
Diffstat (limited to 'modules/core/c++/fplbm.hpp')
| -rw-r--r-- | modules/core/c++/fplbm.hpp | 143 |
1 files changed, 141 insertions, 2 deletions
diff --git a/modules/core/c++/fplbm.hpp b/modules/core/c++/fplbm.hpp index 5ad692b..f50cb1b 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 = ( vel_s - mom) * two * flip_por; // force = (vel_s - mom) * flip_por / (flip_por / two + one); force_p = force_p - force; |
