diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-09-25 19:40:33 +0200 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-09-25 19:40:33 +0200 |
| commit | 95b74577fe5c75e3e8497dc16241b7e6b8d30408 (patch) | |
| tree | 444455743b3576d327295a1d4bb796948a35fab9 /modules | |
| parent | 01a24574ebbe3d37feb95b94c06d573639c80704 (diff) | |
| download | libs-lbm-95b74577fe5c75e3e8497dc16241b7e6b8d30408.tar.gz | |
Vacationdev
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/core/c++/fplbm.hpp | 157 |
1 files changed, 10 insertions, 147 deletions
diff --git a/modules/core/c++/fplbm.hpp b/modules/core/c++/fplbm.hpp index c48e127..aefc568 100644 --- a/modules/core/c++/fplbm.hpp +++ b/modules/core/c++/fplbm.hpp @@ -94,13 +94,14 @@ public: auto& force_f = macros.template get<"force">(); auto& force = force_f.at(index); - auto& vel_f = macros.template get<"momentum">(); - saw::data<sch::Vector<T,Descriptor::D>> vel = vel_f.at(index); + auto& mom_f = macros.template get<"momentum">(); + auto& mom = mom_f.at(index); // We already computed this in reset // compute_rho_u<T,Descriptor>(dfs,rho,vel); - vel = vel + force * half; - auto eq = equilibrium<T,Descriptor>(rho,vel / rho); + mom = mom + force * half; + auto vel = mom / rho; + auto eq = equilibrium<T,Descriptor>(rho,vel); using dfi = df_info<T,Descriptor>; @@ -115,12 +116,12 @@ public: for(uint64_t d{0u}; d < Descriptor::D; ++d){ ci.at({{d}}).set(static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d])); } - auto ci_dot_u = saw::math::dot(ci,vel/rho); + auto ci_dot_u = saw::math::dot(ci,vel); saw::data<sch::Scalar<T>> w; w.at({}).set(dfi::weights[i]); - auto term1 = (ci-vel/rho) * dfi_inv_cs2; + auto term1 = (ci-vel) * dfi_inv_cs2; auto term2 = ci * (ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2); auto force_projection = saw::math::dot(term1 + term2, force); @@ -137,145 +138,6 @@ 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; @@ -342,7 +204,7 @@ public: sss.at({}) = sub_steps.template cast_to<T>(); auto vel_s = (pirb_pos-pirb_pos_old) * sss; - saw::data<sch::Vector<T,Descriptor::D>> force_p; + saw::data<sch::Vector<T,Descriptor::D>> force_p{{}}; //= global_force_; iterator<Descriptor::D>::apply([&](const auto& index_f) -> void { @@ -358,7 +220,8 @@ public: // vel_s is technically time the density of the particle? - force = global_force_ * por + ( vel_s - mom) * two * flip_por; + // force = global_force_ * por + ( vel_s - mom) * two * flip_por; + force = ( vel_s - mom) * two * flip_por; // force = (vel_s - mom) * flip_por / (flip_por / two + one); force_p = force_p - force; |
