From 1f993006305952f4cafddd08267731877e808bba Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 8 Sep 2025 17:15:27 +0200 Subject: Dangling changes Fixed ForcedGuo collision --- c++/boundary.hpp | 2 +- c++/collision.hpp | 32 ++++++++++++++--------------- c++/particle/particle.hpp | 3 ++- c++/statistics.hpp | 11 ++++++++++ c++/write_vtk.hpp | 2 +- examples/cavity_2d_gpu.cpp | 16 +++++++++++---- examples/poiseulle_2d.cpp | 7 ++----- examples/poiseulle_channel_2d.cpp | 8 ++++---- examples/poiseulle_particles_channel_2d.cpp | 9 ++++---- 9 files changed, 54 insertions(+), 36 deletions(-) create mode 100644 c++/statistics.hpp diff --git a/c++/boundary.hpp b/c++/boundary.hpp index 3cf6f3f..bc4859c 100644 --- a/c++/boundary.hpp +++ b/c++/boundary.hpp @@ -51,7 +51,7 @@ public: auto& cell = field(index); auto& dfs_old = (is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - auto& dfs = (not is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); + // auto& dfs = (not is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); using dfi = df_info; diff --git a/c++/collision.hpp b/c++/collision.hpp index df9a734..cd6cf14 100644 --- a/c++/collision.hpp +++ b/c++/collision.hpp @@ -17,11 +17,11 @@ template class component { private: typename saw::native_data_type::type relaxation_; - typename saw::native_data_type::type frequency_; + saw::data frequency_; public: component(typename saw::native_data_type::type relaxation__): relaxation_{relaxation__}, - frequency_{1 / relaxation_} + frequency_{typename saw::native_data_type::type(1) / relaxation_} {} using Component = cmpt::BGK; @@ -57,7 +57,8 @@ public: auto eq = equilibrium(rho,vel); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - dfs_old({i}).set(dfs_old({i}).get() + (1.0 / relaxation_) * (eq.at(i).get() - dfs_old({i}).get())); + dfs_old({i}) = dfs_old({i}) + frequency_ * (eq.at(i) - dfs_old({i})); + // dfs_old({i}).set(dfs_old({i}).get() + (1.0 / relaxation_) * (eq.at(i).get() - dfs_old({i}).get())); } } }; @@ -66,11 +67,11 @@ template class component { private: typename saw::native_data_type::type relaxation_; - typename saw::native_data_type::type frequency_; + saw::data frequency_; public: component(typename saw::native_data_type::type relaxation__): relaxation_{relaxation__}, - frequency_{1 / relaxation_} + frequency_{typename saw::native_data_type::type(1) / relaxation_} {} using Component = cmpt::BGKGuo; @@ -89,7 +90,7 @@ public: template void apply(saw::data& field, saw::data> index, uint64_t time_step){ - bool is_even = ((time_step & 2) == 0); + bool is_even = ((time_step % 2) == 0); auto& cell = field(index); auto& dfs_old = (is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); @@ -105,22 +106,21 @@ public: auto& force = cell.template get<"force">(); for(uint64_t i = 0u; i < Descriptor::Q; ++i){ + saw::data ci_min_u{0}; saw::data ci_dot_u{0}; - saw::data ci_dot_F{0}; - saw::data u_dot_F{0}; for(uint64_t d = 0u; d < Descriptor::D; ++d){ - ci_dot_u = ci_dot_u + vel.at({d}) * dfi::directions[i][d]; - ci_dot_F = ci_dot_F + force({d}) * dfi::directions[i][d]; - u_dot_F = u_dot_F + vel.at({d}) * force({d}); + ci_dot_u = ci_dot_u + vel.at({d}) * saw::data{static_cast::type>(dfi::directions[i][d])}; } + saw::data F_i{0};// = saw::data{dfi::weights[i]} * (ci_dot_F * dfi::inv_cs2 + ci_dot_u * ci_dot_F * (dfi::inv_cs2 * dfi::inv_cs2)); - // auto df_old = dfs_old({i}); - saw::data F_i = saw::data{dfi::weights[i]} * (ci_dot_F / dfi::cs2 + ci_dot_u * ci_dot_F / (dfi::cs2 * dfi::cs2)); - if(F_i.get() != 0){ - std::cerr<<"AAAH"; + for(uint64_t d = 0u; d < Descriptor::D; ++d){ + F_i = F_i + + saw::data{dfi::weights[i]} * ((saw::data{static_cast::type>(dfi::directions[i][d])} + - vel.at({d}) ) * dfi::inv_cs2 + ci_dot_u * saw::data{static_cast::type>(dfi::directions[i][d])} * dfi::inv_cs2 * dfi::inv_cs2 ) * force({d}); } - dfs_old({i}) = dfs_old({i}) + saw::data{frequency_} * (eq.at(i) - dfs_old({i}) ) - F_i * saw::data{1.0f - 0.5f * frequency_}; + + dfs_old({i}) = dfs_old({i}) + frequency_ * (eq.at(i) - dfs_old({i}) ) + F_i * (saw::data{1} - saw::data{0.5f} * frequency_); } } }; diff --git a/c++/particle/particle.hpp b/c++/particle/particle.hpp index a55b06e..ae7769a 100644 --- a/c++/particle/particle.hpp +++ b/c++/particle/particle.hpp @@ -27,7 +27,7 @@ using ParticleMask = Struct< template using Particle = Struct< Member, "rigid_body">, - Member, "mask">, + Member, "mask">, Member >; } @@ -84,6 +84,7 @@ public: template void update_particle_border(saw::data& latt){ + (void) latt; for(auto& iter : particles_){ auto& par = iter; diff --git a/c++/statistics.hpp b/c++/statistics.hpp new file mode 100644 index 0000000..c07ccb7 --- /dev/null +++ b/c++/statistics.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace kel { +namespace lbm { +template +class statistics { +private: +public: +}; +} +} diff --git a/c++/write_vtk.hpp b/c++/write_vtk.hpp index eb2545a..c9ecc99 100644 --- a/c++/write_vtk.hpp +++ b/c++/write_vtk.hpp @@ -81,7 +81,7 @@ struct lbm_vtk_writer...> , template static saw::error_or write_i(std::ostream& vtk_file, const saw::data...>,Dim>>& field){ - auto meta = field.get_dims(); + // auto meta = field.get_dims(); saw::data> index; for(saw::data it{0}; it.get() < Dim; ++it){ index.at({0u}).set(0u); diff --git a/examples/cavity_2d_gpu.cpp b/examples/cavity_2d_gpu.cpp index 19563e2..b5c9b7f 100644 --- a/examples/cavity_2d_gpu.cpp +++ b/examples/cavity_2d_gpu.cpp @@ -189,7 +189,8 @@ void set_initial_conditions(saw::data& latt){ void lbm_step( saw::data& latt, - uint64_t time_step + uint64_t time_step, + sycl::queue& sycl_q ){ using namespace kel::lbm; using dfi = df_info; @@ -260,8 +261,6 @@ void lbm_step( int main(){ using namespace kel::lbm; - saw::remote sycl_rmt; - saw::data> dim{{dim_x, dim_y}}; saw::data lattice{dim}; @@ -273,6 +272,13 @@ int main(){ print_lbm_meta(conv, {1e-3}); + auto eo_lbm_dir = output_directory(); + if(eo_lbm_dir.is_error()){ + return -1; + } + auto& lbm_dir = eo_lbm_dir.get_value(); + auto out_dir = lbm_dir / "cavity_gpu_2d"; + //auto& df_field = lattices.at(0).template get<"dfs">(); //for(uint64_t i = 0; i < df_field.get_dim_size<0u>(); ++i){ // lattices.at(i) = {dim_x, dim_y}; @@ -288,6 +294,8 @@ int main(){ */ set_initial_conditions(lattice); + sycl::queue sycl_q{sycl::default_selector_v, sycl::property::queue::in_order{}}; + /** * Timeloop */ @@ -307,7 +315,7 @@ int main(){ write_vtk_file(vtk_f_name, macros); } - // lbm_step(lattice, i); + lbm_step(lattice, i, sycl_q); } return 0; } diff --git a/examples/poiseulle_2d.cpp b/examples/poiseulle_2d.cpp index 8e1ba94..8c31cb8 100644 --- a/examples/poiseulle_2d.cpp +++ b/examples/poiseulle_2d.cpp @@ -93,7 +93,7 @@ public: return; } auto& dfs_old = (is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - auto& dfs = (not is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); + // auto& dfs = (not is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); /** * Sum all known DFs @@ -121,7 +121,7 @@ public: auto& cell_n = field({{index.at({0u})+c_k[0u], index.at({1u})+c_k[1u]}}); auto& info_n = cell_n.template get<"info">(); auto info_n_val = info_n({0u}); - auto k_opp = dfi::opposite_index[k.get()]; + // auto k_opp = dfi::opposite_index[k.get()]; if(info_n_val.get() > 0u){ sum_unknown_dfs += dfs_old({k}) * c_k[0u]; @@ -255,9 +255,6 @@ void lbm_step( auto& cell = latt(index); auto& info = cell.template get<"info">(); - auto& dfs = cell.template get<"dfs">(); - auto& dfs_old = cell.template get<"dfs_old">(); - switch(info({0u}).get()){ case 1u: { coll.apply(latt, index, time_step); diff --git a/examples/poiseulle_channel_2d.cpp b/examples/poiseulle_channel_2d.cpp index d34703a..ffc7201 100644 --- a/examples/poiseulle_channel_2d.cpp +++ b/examples/poiseulle_channel_2d.cpp @@ -93,7 +93,7 @@ public: return; } auto& dfs_old = (is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); - auto& dfs = (not is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); + //auto& dfs = (not is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">(); /** * Sum all known DFs @@ -121,7 +121,7 @@ public: auto& cell_n = field({{index.at({0u})+c_k[0u], index.at({1u})+c_k[1u]}}); auto& info_n = cell_n.template get<"info">(); auto info_n_val = info_n({0u}); - auto k_opp = dfi::opposite_index[k.get()]; + //auto k_opp = dfi::opposite_index[k.get()]; if(info_n_val.get() > 0u){ sum_unknown_dfs += dfs_old({k}) * c_k[0u]; @@ -294,8 +294,8 @@ void lbm_step( auto& cell = latt(index); auto& info = cell.template get<"info">(); - auto& dfs = cell.template get<"dfs">(); - auto& dfs_old = cell.template get<"dfs_old">(); + //auto& dfs = cell.template get<"dfs">(); + //auto& dfs_old = cell.template get<"dfs_old">(); switch(info({0u}).get()){ case 1u: { diff --git a/examples/poiseulle_particles_channel_2d.cpp b/examples/poiseulle_particles_channel_2d.cpp index fed78b2..bc5d241 100644 --- a/examples/poiseulle_particles_channel_2d.cpp +++ b/examples/poiseulle_particles_channel_2d.cpp @@ -24,6 +24,7 @@ using namespace saw::schema; * Q factor */ using T = Float32; +// using T = MixedPrecision; using D2Q5 = Descriptor<2u,5u>; using D2Q9 = Descriptor<2u,9u>; @@ -349,6 +350,7 @@ void couple_particles_to_lattice( saw::data time_step ){ using namespace kel::lbm; + (void) time_step; auto meta = latt.meta(); using dfi = df_info; @@ -398,7 +400,7 @@ void couple_particles_to_lattice( // Fluid to Particle Coupling // Prepare force sum - saw::data> forces; + saw::data> forces; iterate_over([&](const saw::data>& index){ @@ -500,8 +502,8 @@ void lbm_step( auto& cell = latt(index); auto& info = cell.template get<"info">(); - auto& dfs = cell.template get<"dfs">(); - auto& dfs_old = cell.template get<"dfs_old">(); + //auto& dfs = cell.template get<"dfs">(); + //auto& dfs_old = cell.template get<"dfs_old">(); switch(info({0u}).get()){ case 1u: { @@ -595,7 +597,6 @@ int main(int argc, char** argv){ particle_system particle_sys; add_particles(particle_sys); - /** * Setup geometry */ -- cgit v1.2.3