diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/core/c++/fplbm.hpp | 18 | ||||
| -rw-r--r-- | lib/core/c++/lbm.hpp | 1 | ||||
| -rw-r--r-- | lib/core/c++/momentum_gather.hpp | 54 | ||||
| -rw-r--r-- | lib/core/c++/particle/porosity.hpp | 8 | ||||
| -rw-r--r-- | lib/core/c++/psm.hpp | 18 |
5 files changed, 92 insertions, 7 deletions
diff --git a/lib/core/c++/fplbm.hpp b/lib/core/c++/fplbm.hpp index 61def6b..c974472 100644 --- a/lib/core/c++/fplbm.hpp +++ b/lib/core/c++/fplbm.hpp @@ -114,6 +114,19 @@ public: auto& vel_f = macros.template get<"velocity">(); auto& por_f = macros.template get<"porosity">(); + // Temporary find a better way + auto& force_f = macros.template get<"force">(); + + + /** + * The other methods all work with a flipped porosity. + * For compat reasons this is also flipped + */ + auto porosity = por_f.at(index); + saw::data<sch::Scalar<T>> one; + one.at({}) = 1.0; + auto flip_porosity = one - porosity; + saw::data<sch::Scalar<T>>& rho = rho_f.at(index); saw::data<sch::Scalar<T>> half; @@ -128,12 +141,13 @@ public: saw::data<sch::Scalar<T>> min_two; min_two.at({}).set(-2); - auto force = vel * rho * min_two * por_f.at(index); + // Maybe ? + auto& force = force_f.at(index); + force = vel * rho * min_two * flip_porosity; saw::data<sch::Scalar<T>> dfi_inv_cs2; dfi_inv_cs2.at({}).set(dfi::inv_cs2); - // auto vel = vel_f.at(index); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ diff --git a/lib/core/c++/lbm.hpp b/lib/core/c++/lbm.hpp index b34ec10..23d30b1 100644 --- a/lib/core/c++/lbm.hpp +++ b/lib/core/c++/lbm.hpp @@ -16,6 +16,7 @@ #include "iterator.hpp" #include "hlbm.hpp" #include "macroscopic.hpp" +#include "momentum_gather.hpp" #include "memory.hpp" #include "psm.hpp" #include "stream.hpp" diff --git a/lib/core/c++/momentum_gather.hpp b/lib/core/c++/momentum_gather.hpp new file mode 100644 index 0000000..7b1fc96 --- /dev/null +++ b/lib/core/c++/momentum_gather.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include "common.hpp" +#include "macroscopic.hpp" +#include "component.hpp" +#include "equilibrium.hpp" + +namespace kel { +namespace lbm { +namespace cmpt { +// Gather the force, Luke! +struct ForceGather {}; +} + +template<typename T, typename Descriptor, typename Encode> +class component<T,Descriptor,cmpt::ForceGather, Encode> { +private: +public: + 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_f = macros.template get<"porosity">(); + auto& porous = porous_f.at(index); + + 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); + } + + auto& dfs = dfs_old_f.at(index); + 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 * saw::data<T>{dfi::directions[i][k]}; + } + } + + saw::data<sch::Scalar<T>> one; + one.at({}) = 1.0; + auto flip_porous = one - porous; + force = force * flip_porous; + } +}; +} +} diff --git a/lib/core/c++/particle/porosity.hpp b/lib/core/c++/particle/porosity.hpp index 11185c5..2f39d2e 100644 --- a/lib/core/c++/particle/porosity.hpp +++ b/lib/core/c++/particle/porosity.hpp @@ -48,17 +48,17 @@ public: auto rad_high = rad + eps_h; if(s_dist.at({}) <= rad_low.at({})){ - por.at({}).set(1); + por.at({}).set(0); return por; } if(s_dist.at({}) >= rad_high.at({})){ - por.at({}).set(0); + por.at({}).set(1); return por; } { - typename saw::native_data_type<T>::type inner = (std::numbers::pi / ( eps.at({}).get() )) * (s_dist - rad_low).at({}).get(); - auto cos_inner = std::cos(inner); + typename saw::native_data_type<T>::type inner = (std::numbers::pi / ( 2 * eps.at({}).get() )) * (s_dist - rad_low).at({}).get(); + auto cos_inner = std::sin(inner); auto cos_i_2 = cos_inner * cos_inner; por.at({}).set(cos_i_2); } diff --git a/lib/core/c++/psm.hpp b/lib/core/c++/psm.hpp index 3bd3520..6dc146f 100644 --- a/lib/core/c++/psm.hpp +++ b/lib/core/c++/psm.hpp @@ -40,7 +40,7 @@ public: 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); @@ -60,6 +60,22 @@ 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; + } + } + + force = force * porous; } }; |
