diff options
| -rw-r--r-- | examples/poiseulle_particles_2d_ibm_gpu/sim.cpp | 8 | ||||
| -rw-r--r-- | lib/core/c++/collision.hpp | 28 |
2 files changed, 26 insertions, 10 deletions
diff --git a/examples/poiseulle_particles_2d_ibm_gpu/sim.cpp b/examples/poiseulle_particles_2d_ibm_gpu/sim.cpp index cc108ce..9905906 100644 --- a/examples/poiseulle_particles_2d_ibm_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_ibm_gpu/sim.cpp @@ -46,7 +46,8 @@ using RhoChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y>; template<typename T, typename Desc> using MacroStruct = Struct< Member<VelChunk<T,Desc>, "velocity">, - Member<RhoChunk<T>, "density"> + Member<RhoChunk<T>, "density">, + Member<VelChunk<T,Desc>, "force"> >; //template<typename T, typename Desc> @@ -171,7 +172,10 @@ saw::error_or<void> step( // auto coll_ev = q.submit([&](acpp::sycl::handler& h){ // Need nicer things to handle the flow. I see improvement here - component<T,Desc,cmpt::BGKGuo, encode::Sycl<saw::encode::Native>> collision{0.65}; + saw::data<sch::Vector<T,Desc::D>> f; + f.at({{0u}}) = 0.0; + f.at({{1u}}) = -1.0; + component<T,Desc,cmpt::BGKGuo, encode::Sycl<saw::encode::Native>> collision{0.65,f}; component<T,Desc,cmpt::BounceBack,encode::Sycl<saw::encode::Native>> bb; component<T,Desc,cmpt::AntiBounceBack<0u>,encode::Sycl<saw::encode::Native>> abb; diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp index df45bbe..cd941bd 100644 --- a/lib/core/c++/collision.hpp +++ b/lib/core/c++/collision.hpp @@ -66,7 +66,7 @@ public: dfs_old_f.at(index).at({i}) = dfs_old_f.at(index).at({i}) + frequency_ * (eq.at(i) - dfs_old_f.at(index).at({i})); } } - + 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 { bool is_even = ((time_step.get() % 2) == 0); @@ -76,12 +76,12 @@ 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); compute_rho_u<T,Descriptor>(dfs_old_f.at(index),rho,vel); - + auto eq = equilibrium<T,Descriptor>(rho,vel); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ @@ -138,18 +138,26 @@ public: 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); + + auto& force_f = macros.template get<"force">(); + auto& force = force_f.at(index); + + auto total_force = force + global_force_; + saw::data<sch::Scalar<T>> half; + half.at({}).set(0.5); + saw::data<sch::Vector<T,Descriptor::D>> vel = vel_f.at(index) + total_force * ( half / rho ); 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_f = macros.template get<"force">(); - auto& force = force_f.at(index); 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){ // saw::data<T> ci_min_u{0}; @@ -164,7 +172,6 @@ public: saw::data<sch::Scalar<T>> w; w.at({}).set(dfi::weights[i]); - auto F_i_d = saw::math::dot((force+global_force_) * w, (ci - vel * dfi_inv_cs2 + ci * ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2 )); /* saw::data<sch::Scalar<T>> F_i_sum; for(uint64_t d = 0u; d < Descriptor::D; ++d){ @@ -173,9 +180,14 @@ public: F_i_sum = F_i_sum + F_i_d; } */ + 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, total_force); + auto F_i = w * force_projection; - dfs.at({i}) = dfs.at({i}) + frequency_ * (eq.at(i) - dfs.at({i}) ) + F_i_d.at({}) * (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.at({}) * (saw::data<T>{1} - saw::data<T>{0.5f} * frequency_); } } }; |
