summaryrefslogtreecommitdiff
path: root/examples/poiseulle_particles_2d_gpu/init.hpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-06-08 20:15:59 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-06-08 20:15:59 +0200
commit3a27bca74e7645874e52f101d467aff8ff7d78f4 (patch)
treeb5f742bd3f146a9747c159f9fd8d099a6d566c1f /examples/poiseulle_particles_2d_gpu/init.hpp
parent5ea4875b96bfacd4c5f0125c9e7b64b70f0ccfb9 (diff)
parent932fbf86d60df48623ad5fbc9d60e572bb68ef12 (diff)
downloadlibs-lbm-3a27bca74e7645874e52f101d467aff8ff7d78f4.tar.gz
Merge branch 'dev'HEADmaster
Diffstat (limited to 'examples/poiseulle_particles_2d_gpu/init.hpp')
-rw-r--r--examples/poiseulle_particles_2d_gpu/init.hpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/examples/poiseulle_particles_2d_gpu/init.hpp b/examples/poiseulle_particles_2d_gpu/init.hpp
new file mode 100644
index 0000000..70d59fc
--- /dev/null
+++ b/examples/poiseulle_particles_2d_gpu/init.hpp
@@ -0,0 +1,122 @@
+#pragma once
+
+#include "common.hpp"
+
+namespace kel {
+namespace lbm {
+
+template<typename T, typename Desc>
+saw::error_or<void> setup_initial_conditions(
+ saw::data<sch::ChunkStruct<T,Desc>>& fields,
+ saw::data<sch::MacroStruct<T,Desc>>& macros,
+ saw::data<sch::ParticleSpheroidGroup<T,Desc>>& particles
+){
+ auto& info_f = fields.template get<"info">();
+ auto& porous_f = macros.template get<"porosity">();
+ // Set everything as walls
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(1u);
+ },
+ {},
+ info_f.get_dims(),
+ {}
+ );
+ // Fluid
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(2u);
+ },
+ {},
+ info_f.get_dims(),
+ {{1u,1u}}
+ );
+
+ // Inflow
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(3u);
+ },
+ {{0u,0u}},
+ {{1u,dim_y}},
+ {{0u,1u}}
+ );
+
+ // Outflow
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(4u);
+ },
+ {{dim_x-1u,0u}},
+ {{dim_x, dim_y}},
+ {{0u,1u}}
+ );
+ //
+ auto& df_f = fields.template get<"dfs_old">();
+ auto& rho_f = macros.template get<"density">();
+ auto& vel_f = macros.template get<"velocity">();
+ auto& por_f = macros.template get<"porosity">();
+
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ auto& df = df_f.at(index);
+ auto& rho = rho_f.at(index);
+ por_f.at(index).at({}) = {1};
+ rho.at({}) = {1};
+ auto& vel = vel_f.at(index);
+ auto eq = equilibrium<T,Desc>(rho,vel);
+
+ df = eq;
+ },
+ {},// 0-index
+ df_f.get_dims()
+ );
+
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ auto& df = df_f.at(index);
+ auto& rho = rho_f.at(index);
+ rho.at({}) = {1};
+ auto& vel = vel_f.at(index);
+ if(info_f.at(index).get() == 2u){
+ vel.at({{0u}}) = 0.0;
+ }
+ auto eq = equilibrium<T,Desc>(rho,vel);
+
+ df = eq;
+ },
+ {},// 0-index
+ df_f.get_dims(),
+ {{1u,1u}}
+ );
+
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ saw::data<sch::Vector<T,Desc::D>> middle, ind_vec;
+ middle.at({{0u}}) = dim_x * 0.25;
+ middle.at({{1u}}) = dim_y * 0.5;
+
+ ind_vec.at({{0u}}) = index.at({{0u}}).template cast_to<T>();
+ ind_vec.at({{1u}}) = index.at({{1u}}).template cast_to<T>();
+
+ 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()
+ );
+
+ {
+ saw::data<sch::Scalar<T>> dense_p;
+ dense_p.at({}).set(1);
+ particles = create_spheroid_particle_group<T,Desc::D,2.0f>(dense_p, {{16u}});
+ }
+
+ return saw::make_void();
+}
+
+}
+}