From bec95825e78dc1171c337f2c40790e1ad5676f54 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 29 Jun 2026 19:26:19 +0200 Subject: Dangling --- default.nix | 11 +++++++ .../poiseulle_moving_particle_2d_psm_gpu/sim.cpp | 38 ++++++++++------------ examples/poiseulle_particles_2d_bgk_gpu/sim.cpp | 14 ++++++++ examples/poiseulle_particles_2d_psm_gpu/sim.cpp | 37 +++++++++++++++++++++ lib/core/c++/particle/particle_opa.hpp | 3 +- scripts/python/csv_l2_norm.py | 26 +++++++++++++++ 6 files changed, 108 insertions(+), 21 deletions(-) create mode 100755 scripts/python/csv_l2_norm.py diff --git a/default.nix b/default.nix index dc75b57..02f9213 100644 --- a/default.nix +++ b/default.nix @@ -151,6 +151,17 @@ in rec { inherit pname version stdenv forstio adaptive-cpp; inherit kel; }; + + poiseulle_particles_2d_all_gpu = pkgs.symlinkJoin { + name = "poiseulle_particles_2d_all_gpu"; + paths = [ + examples.poiseulle_particles_2d_bgk_gpu + examples.poiseulle_particles_2d_psm_gpu + examples.poiseulle_particles_2d_hlbm_gpu + examples.poiseulle_particles_2d_fplbm_gpu + examples.poiseulle_particles_2d_ibm_gpu + ]; + }; poiseulle_moving_particle_2d_psm_gpu = pkgs.callPackage ./examples/poiseulle_moving_particle_2d_psm_gpu/.nix/derivation.nix { inherit pname version stdenv forstio adaptive-cpp; diff --git a/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp b/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp index 0c10d38..cae8a4d 100644 --- a/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp +++ b/examples/poiseulle_moving_particle_2d_psm_gpu/sim.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -157,25 +158,6 @@ saw::error_or setup_initial_conditions( df_f.get_dims(), {{1u,1u}} ); - - iterator::apply( - [&](auto& index){ - saw::data> middle, ind_vec; - middle.at({{0u}}) = dim_x * 0.5; - middle.at({{1u}}) = dim_y * 0.5; - - ind_vec.at({{0u}}) = index.at({{0u}}).template cast_to(); - ind_vec.at({{1u}}) = index.at({{1u}}).template cast_to(); - - auto dist = middle - ind_vec; - auto dist_2 = saw::math::dot(dist,dist); - if(dist_2.at({}).get() < dim_y*dim_y*0.01){ - porous_f.at(index).at({}) = 0.0; - } - }, - {},// 0-index - df_f.get_dims() - ); return saw::make_void(); } @@ -190,6 +172,8 @@ saw::error_or step( auto& q = dev.get_handle(); auto& info_f = fields.template get<"info">(); auto& porous_f = macros.template get<"porosity">(); + sch::data> eps; + eps.at({}).set(1.5f); q.submit([&](acpp::sycl::handler& h){ component> collision{0.8}; @@ -199,7 +183,7 @@ saw::error_or step( component,encode::Sycl> flow_in{1.0}; component,encode::Sycl> flow_out{1.0}; - component> opa{{},{}}; + component> opa{{},{},eps}; h.parallel_for(acpp::sycl::range{dim_x,dim_y}, [=](acpp::sycl::id idx){ saw::data> index; @@ -371,6 +355,7 @@ saw::error_or lbm_main(int argc, char** argv){ } } */ + /* if(i.get() % 32u == 0u){ { auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); @@ -385,6 +370,7 @@ saw::error_or lbm_main(int argc, char** argv){ } } } + */ // Stream sycl_q.submit([&](acpp::sycl::handler& h){ component> stream; @@ -424,6 +410,18 @@ saw::error_or lbm_main(int argc, char** argv){ return eov; } } + { + auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_csv_file(out_dir,"m",time_steps.get(), *lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } sycl_q.wait(); return saw::make_void(); diff --git a/examples/poiseulle_particles_2d_bgk_gpu/sim.cpp b/examples/poiseulle_particles_2d_bgk_gpu/sim.cpp index 9cc77ae..73964b7 100644 --- a/examples/poiseulle_particles_2d_bgk_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_bgk_gpu/sim.cpp @@ -366,6 +366,7 @@ saw::error_or lbm_main(int argc, char** argv){ } } */ + /* if(i.get() % 32u == 0u){ { auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); @@ -380,6 +381,7 @@ saw::error_or lbm_main(int argc, char** argv){ } } } + */ // Stream sycl_q.submit([&](acpp::sycl::handler& h){ component> stream; @@ -419,6 +421,18 @@ saw::error_or lbm_main(int argc, char** argv){ return eov; } } + { + auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = write_csv_file(out_dir,"m",time_steps.get(), *lbm_macro_data_ptr); + if(eov.is_error()){ + return eov; + } + } sycl_q.wait(); return saw::make_void(); diff --git a/examples/poiseulle_particles_2d_psm_gpu/sim.cpp b/examples/poiseulle_particles_2d_psm_gpu/sim.cpp index 0337158..e91686c 100644 --- a/examples/poiseulle_particles_2d_psm_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_psm_gpu/sim.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -157,7 +158,27 @@ saw::error_or setup_initial_conditions( df_f.get_dims(), {{1u,1u}} ); + + saw::data> eps; + eps.at({}).set(1.5f); + saw::data> rad; + rad.at({}).set(dim_y*0.1); + saw::data> p_pos; + { + p_pos.at({{0u}}) = dim_x * 0.25; + p_pos.at({{1u}}) = dim_y * 0.5; + } + + component opa{p_pos,rad,eps}; + iterator::apply( + [&](auto& index){ + opa.apply(macros,index,{}); + }, + {},// 0-index + df_f.get_dims() + ); + /* iterator::apply( [&](auto& index){ saw::data> middle, ind_vec; @@ -176,6 +197,7 @@ saw::error_or setup_initial_conditions( {},// 0-index df_f.get_dims() ); + */ return saw::make_void(); } @@ -203,6 +225,18 @@ saw::error_or step( component> equi{rho_b,vel_b}; + + saw::data> eps; + eps.at({}).set(1.5f); + saw::data> rad; + rad.at({}).set(dim_y*0.1); + saw::data> p_pos; + { + p_pos.at({{0u}}) = dim_x * 0.25; + p_pos.at({{1u}}) = dim_y * 0.5; + } + component> opa{p_pos,rad,eps}; + component,encode::Sycl> flow_in{ [&](){ uint64_t target_t_i = 64u; @@ -230,6 +264,7 @@ saw::error_or step( bb.apply(fields,index,t_i); break; case 2u: + opa.apply(macros,index,t_i); collision.apply(fields,macros,index,t_i); break; case 3u: @@ -385,6 +420,7 @@ saw::error_or lbm_main(int argc, char** argv){ } } */ + /* if(i.get() % 32u == 0u){ { auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr); @@ -399,6 +435,7 @@ saw::error_or lbm_main(int argc, char** argv){ } } } + */ // Stream sycl_q.submit([&](acpp::sycl::handler& h){ component> stream; diff --git a/lib/core/c++/particle/particle_opa.hpp b/lib/core/c++/particle/particle_opa.hpp index e6396d6..bfd2e3c 100644 --- a/lib/core/c++/particle/particle_opa.hpp +++ b/lib/core/c++/particle/particle_opa.hpp @@ -35,12 +35,13 @@ public: auto& porous = porous_f.at(index); - auto pos_ind = saw::math::vectorize_data(index); auto diff = pos_ind - pos_; // Write out value + auto diff = pos_ind.template cast_to() - pos_; + auto diff_dot = saw::math::dot(diff,diff); porous = particle_porosity<>::calculate(diff, rad_, eps_); } }; diff --git a/scripts/python/csv_l2_norm.py b/scripts/python/csv_l2_norm.py new file mode 100755 index 0000000..88f4817 --- /dev/null +++ b/scripts/python/csv_l2_norm.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import argparse +import numpy as np + + +def main(): + parser = argparse.ArgumentParser(description="Compute the L2 Norm"); + parser.add_argument("one"); + parser.add_argument("two"); + args = parser.parse_args(); + + a = np.loadtxt(args.one, delimiter=","); + b = np.loadtxt(args.two, delimiter=","); + + if a.shape != b.shape: + raise ValueError(f"Shape mismatch: {a.shape} vs {b.shape}"); + #endif + + print(np.linalg.norm(a-b)); + +#enddef + +if __name__ == "__main__": + main(); +#enddef -- cgit v1.2.3