summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-06-03 09:58:54 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-06-03 09:58:54 +0200
commit42338efc99190d4f3362ecbc326a740cb7bd0479 (patch)
tree13b94bd8cfb17be13b35f7b2539bf03c7ad9592c
parent1c9d05a7cf13b4bd4ebe5583d10cae85d507ea9c (diff)
parentd7c88d561d4e2b7a2706d14c11ea5fa4cd6ceaf3 (diff)
downloadlibs-lbm-42338efc99190d4f3362ecbc326a740cb7bd0479.tar.gz
Merge branch 'fb-ibm-coupling' into dev
-rw-r--r--default.nix14
-rw-r--r--examples/settling_spheres_2d_hlbm_gpu/.nix/derivation.nix41
-rw-r--r--examples/settling_spheres_2d_hlbm_gpu/SConscript34
-rw-r--r--examples/settling_spheres_2d_hlbm_gpu/SConstruct81
-rw-r--r--examples/settling_spheres_2d_hlbm_gpu/sim.cpp469
-rw-r--r--lib/core/c++/chunk.hpp5
-rw-r--r--lib/core/c++/hlbm.hpp61
-rw-r--r--lib/core/c++/particle/aabb.hpp49
-rw-r--r--lib/core/c++/particle/porosity.hpp57
9 files changed, 787 insertions, 24 deletions
diff --git a/default.nix b/default.nix
index d233d90..c8e99f5 100644
--- a/default.nix
+++ b/default.nix
@@ -161,11 +161,23 @@ in rec {
inherit pname version stdenv forstio adaptive-cpp;
inherit kel;
};
+
+ settling_cubes_2d_hlbm_gpu = pkgs.callPackage ./examples/settling_spheres_2d_hlbm_gpu/.nix/derivation.nix {
+ inherit pname version stdenv forstio adaptive-cpp;
+ inherit kel;
+ };
heterogeneous_computing = pkgs.callPackage ./examples/heterogeneous_computing/.nix/derivation.nix {
inherit pname version stdenv forstio adaptive-cpp;
inherit kel;
};
+
+ settling_particles = pkgs.symlinkJoin {
+ name = "kel-lbm-settling_particles-${version}";
+ paths = [
+ examples.settling_cubes_2d_ibm_gpu
+ ];
+ };
};
debug = {
@@ -190,6 +202,8 @@ in rec {
examples.poiseulle_particles_2d_ibm_gpu
];
};
+
+
};
default = release.examples;
diff --git a/examples/settling_spheres_2d_hlbm_gpu/.nix/derivation.nix b/examples/settling_spheres_2d_hlbm_gpu/.nix/derivation.nix
new file mode 100644
index 0000000..26b41f2
--- /dev/null
+++ b/examples/settling_spheres_2d_hlbm_gpu/.nix/derivation.nix
@@ -0,0 +1,41 @@
+{ lib
+, stdenv
+, scons
+, clang-tools
+, forstio
+, python3
+, pname
+, version
+, adaptive-cpp
+, kel
+}:
+
+stdenv.mkDerivation {
+ pname = pname + "-examples-" + "setting_spheres_2d_hlbm_gpu";
+ inherit version;
+ src = ./..;
+
+ nativeBuildInputs = [
+ scons
+ clang-tools
+ python3
+ ];
+
+ buildInputs = [
+ forstio.core
+ forstio.async
+ forstio.codec
+ forstio.codec-unit
+ forstio.io
+ forstio.remote
+ forstio.remote-filesystem
+ forstio.codec-json
+ adaptive-cpp
+ kel.lbm.core
+ kel.lbm.sycl
+ ];
+
+ preferLocalBuild = true;
+
+ outputs = [ "out" "dev" ];
+}
diff --git a/examples/settling_spheres_2d_hlbm_gpu/SConscript b/examples/settling_spheres_2d_hlbm_gpu/SConscript
new file mode 100644
index 0000000..ae08056
--- /dev/null
+++ b/examples/settling_spheres_2d_hlbm_gpu/SConscript
@@ -0,0 +1,34 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+examples_env = env.Clone();
+examples_env['CXX'] = 'syclcc-clang';
+examples_env['CXXFLAGS'] += ['-O3'];
+
+examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += examples_env.sources;
+env.headers += examples_env.headers;
+
+# Cavity2D
+examples_objects = [];
+examples_env.add_source_files(examples_objects, ['sim.cpp'], shared=False);
+examples_env.poiseulle_2d_gpu = examples_env.Program('#bin/settling_cubes_2d_ibm_gpu', [examples_objects]);
+
+# Set Alias
+env.examples = [
+ examples_env.poiseulle_2d_gpu
+];
+env.Alias('examples', env.examples);
+env.targets += ['examples'];
+env.Install('$prefix/bin/', env.examples);
diff --git a/examples/settling_spheres_2d_hlbm_gpu/SConstruct b/examples/settling_spheres_2d_hlbm_gpu/SConstruct
new file mode 100644
index 0000000..0611b67
--- /dev/null
+++ b/examples/settling_spheres_2d_hlbm_gpu/SConstruct
@@ -0,0 +1,81 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+import os.path
+import glob
+import re
+
+
+if sys.version_info < (3,):
+ def isbasestring(s):
+ return isinstance(s,basestring)
+else:
+ def isbasestring(s):
+ return isinstance(s, (str,bytes))
+
+def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""):
+
+ if isbasestring(filetype):
+ dir_path = self.Dir('.').abspath
+ filetype = sorted(glob.glob(dir_path+"/"+filetype))
+
+ for path in filetype:
+ target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path )
+ if shared:
+ target_name+='.os'
+ sources.append( self.SharedObject( target=target_name, source=path ) )
+ else:
+ target_name+='.o'
+ sources.append( self.StaticObject( target=target_name, source=path ) )
+ pass
+
+def isAbsolutePath(key, dirname, env):
+ assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
+
+env_vars = Variables(
+ args=ARGUMENTS
+)
+
+env_vars.Add('prefix',
+ help='Installation target location of build results and headers',
+ default='/usr/local/',
+ validator=isAbsolutePath
+)
+
+env_vars.Add('build_examples',
+ help='If examples should be built',
+ default="true"
+)
+
+env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
+ CPPDEFINES=['SAW_UNIX'],
+ CXXFLAGS=[
+ '-std=c++20',
+ '-g',
+ '-Wall',
+ '-Wextra'
+ ],
+ LIBS=[
+ 'forstio-core',
+ 'forstio-async',
+ 'forstio-io'
+ ]
+);
+env.__class__.add_source_files = add_kel_source_files
+env.Tool('compilation_db');
+env.cdb = env.CompilationDatabase('compile_commands.json');
+
+env.objects = [];
+env.sources = [];
+env.headers = [];
+env.targets = [];
+
+Export('env')
+SConscript('SConscript')
+
+env.Alias('cdb', env.cdb);
+env.Alias('all', [env.targets]);
+env.Default('all');
+
+env.Alias('install', '$prefix')
diff --git a/examples/settling_spheres_2d_hlbm_gpu/sim.cpp b/examples/settling_spheres_2d_hlbm_gpu/sim.cpp
new file mode 100644
index 0000000..eb3f377
--- /dev/null
+++ b/examples/settling_spheres_2d_hlbm_gpu/sim.cpp
@@ -0,0 +1,469 @@
+#include <kel/lbm/sycl/lbm.hpp>
+#include <kel/lbm/lbm.hpp>
+#include <kel/lbm/particle.hpp>
+
+#include <forstio/io/io.hpp>
+#include <forstio/remote/filesystem/easy.hpp>
+#include <forstio/codec/json/json.hpp>
+#include <forstio/codec/simple.hpp>
+#include <forstio/codec/math.hpp>
+
+namespace kel {
+namespace lbm {
+
+constexpr uint64_t dim_x = 512ul;
+constexpr uint64_t dim_y = dim_x * 2ul;
+
+constexpr uint64_t particle_amount = 16ul;
+
+namespace sch {
+using namespace saw::schema;
+
+using InfoChunk = Chunk<UInt8, 0u, dim_x, dim_y>;
+
+template<typename T, typename Desc>
+using DfChunk = Chunk<FixedArray<T,Desc::Q>, 1u, dim_x, dim_y>;
+
+template<typename T, typename Desc>
+using ScalarChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y>;
+
+template<typename T, typename Desc>
+using VectorChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y>;
+
+template<typename T, typename Desc>
+using ChunkStruct = Struct<
+ Member<InfoChunk, "info">,
+ Member<DfChunk<T,Desc>, "dfs">,
+ Member<DfChunk<T,Desc>, "dfs_old">,
+ Member<VectorChunk<T,Desc>, "p_N">,
+ Member<ScalarChunk<T,Desc>, "p_D">
+>;
+
+template<typename T, typename Desc>
+using VelChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y>;
+
+template<typename T>
+using RhoChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y>;
+
+template<typename T>
+using PorChunk = 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<PorChunk<T>, "porosity">
+>;
+
+template<typename T, typename Desc>
+using ParticleSpheroidGroup = ParticleGroup<
+ T,
+ Desc::D,
+ sch::ParticleCollisionSpheroid<T,2.0f>
+>;
+
+template<typename T, typename Desc>
+using ParticleGroups = Tuple<
+ ParticleSpheroidGroup<T,Desc>
+>;
+
+
+}
+
+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">();
+ // 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}}
+ );
+ //
+ auto& df_f = fields.template gStarted hearing about similar cases not long after, many of which were successful on the part of the crooks. Scary stuff. et<"dfs_old">();
+ auto& rho_f = macros.template get<"density">();
+ auto& vel_f = macros.template get<"velocity">();
+
+ 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);
+ auto eq = equilibrium<T,Desc>(rho,vel);
+
+ df = eq;
+ },
+ {},// 0-index
+ df_f.get_dims()
+ );
+
+ // Particles
+ {
+ saw::data<sch::Scalar<T>> dense_p;
+ dense_p.at({}).set(1);
+ // auto& spheroid_group = particles.template get<0u>();
+ auto& spheroid_group = particles;
+
+ spheroid_group = create_spheroid_particle_group<T,Desc::D,2.0f>(
+ dense_p,
+ {64u}
+ );
+
+ {
+ auto& p = spheroid_group.template get<"particles">();
+
+ /// 16 if I remember correctly?
+ p = {{{particle_amount}}};
+
+ iterator<1u>::apply(
+ [&](auto& index){
+ // Set Pos here?
+ auto& p_ind = p.at(index);
+
+ auto& p_rb = p_ind.template get<"rigid_body">();
+ auto& p_pos = p_rb.template get<"position">();
+
+ saw::data<sch::Vector<T,Desc::D>> p;
+ uint64_t x = index.at({0u}).get() % 8u;
+ uint64_t y = index.at({1u}).get() / 8u;
+ p.at({{0u}}).set( 0.2 + 0.6 / (x-1u) );
+ p.at({{1u}}).set( 0.8 + y * 0.1 );
+
+ p_pos = p;
+
+ auto& p_pos_old = p_rb.template get<"position_old">();
+ p_pos_old = p_pos;
+ },
+ {},
+ p.meta()
+ );
+ }
+ }
+ // Particle in hacky flavour
+ {}
+
+ return saw::make_void();
+}
+
+template<typename T, typename Desc>
+saw::error_or<void> step(
+ saw::data<sch::Ptr<sch::ChunkStruct<T,Desc>>,encode::Sycl<saw::encode::Native>>& fields,
+ saw::data<sch::Ptr<sch::MacroStruct<T,Desc>>,encode::Sycl<saw::encode::Native>>& macros,
+ saw::data<sch::Ptr<sch::ParticleSpheroidGroup<T,Desc>>,encode::Sycl<saw::encode::Native>>& p_group,
+ saw::data<sch::UInt64> t_i,
+ device& dev
+){
+ auto& q = dev.get_handle();
+ auto& info_f = fields.template get<"info">();
+
+ auto& parts = p_group.template get<"particles">();
+ auto& p_mask = p_group.template get<"mask">();
+ auto& vels = macros.template get<"velocity">();
+ auto& forces = macros.template get<"force">();
+
+ auto p_meta = parts.meta();
+ q.submit([&](acpp::sycl::handler& h){
+
+ h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y}, [=](acpp::sycl::id<Desc::D> idx){
+ saw::data<sch::FixedArray<sch::UInt64,Desc::D>> index;
+ for(uint64_t i = 0u; i < Desc::D; ++i){
+ index.at({{i}}).set(idx[i]);
+ }
+
+ // Reset the force to zero
+ forces.at(index) = {};
+ });
+ }).wait();
+
+ q.submit([&](acpp::sycl::handler& h){
+ h.parallel_for(acpp::sycl::range<1u>{p_meta.at({0u}).get()}, [=](acpp::sycl::id<1u> idx){
+
+ saw::data<sch::FixedArray<sch::UInt64,1u>> index;
+ for(uint64_t i = 0u; i < 1u; ++i){
+ index.at({{i}}).set(idx[i]);
+ }
+
+ auto& pi = parts.at(index);
+ auto& pirb = pi.template get<"rigid_body">();
+
+ auto& p_pos = pirb.template get<"position">();
+ auto& p_rot = pirb.template get<"rotation">();
+ auto& p_acc = pirb.template get<"acceleration">();
+
+
+
+ saw::data<sch::Scalar<T>> delta_t;
+ delta_t.at({}).set(1.0f);
+ verlet_step_lambda<T,Desc::D>(p,delta_t);
+ });
+ }).wait();
+
+ // auto coll_ev =
+ q.submit([&](acpp::sycl::handler& h){
+ // Need nicer things to handle the flow. I see improvement here
+ component<T,Desc,cmpt::BGK, encode::Sycl<saw::encode::Native>> collision{0.8};
+ component<T,Desc,cmpt::BounceBack,encode::Sycl<saw::encode::Native>> bb;
+
+ h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y}, [=](acpp::sycl::id<Desc::D> idx){
+ saw::data<sch::FixedArray<sch::UInt64,Desc::D>> index;
+ for(uint64_t i = 0u; i < Desc::D; ++i){
+ index.at({{i}}).set(idx[i]);
+ }
+
+ auto info = info_f.at(index);
+
+ switch(info.get()){
+ case 0u:
+ break;
+ case 1u:
+ bb.apply(fields,index,t_i);
+ break;
+ case 2u:
+ // collision.apply(fields,macros,index,t_i);
+ break;
+ default:
+ break;
+ }
+ });
+ }).wait();
+
+ // Step
+ /*
+ q.submit([&](acpp::sycl::handler& h){
+ // h.depends_on(collision_ev);
+ }).wait();
+ */
+
+ return saw::make_void();
+}
+}
+}
+
+template<typename T, typename Desc>
+saw::error_or<void> lbm_main(int argc, char** argv){
+ using namespace kel::lbm;
+
+ using dfi = df_info<T,Desc>;
+
+ auto eo_lbm_env = lbm_directory();
+ if(eo_lbm_env.is_error()){
+ return std::move(eo_lbm_env.get_error());
+ }
+ auto& lbm_env = eo_lbm_env.get_value();
+
+ auto out_dir = lbm_env.data_dir / "settling_cubes_2d_ibm_gpu";
+
+ {
+ std::error_code ec;
+ std::filesystem::create_directories(out_dir,ec);
+ if(ec != std::errc{}){
+ return saw::make_error<saw::err::critical>("Could not create output directory");
+ }
+ }
+
+ converter<T> conv {
+ // delta_x
+ {{1.0}},
+ // delta_t
+ {{1.0}}
+ };
+
+ print_lbm_meta<T,Desc>(conv,{0.05},{0.01},{0.4 * dim_y});
+
+ // saw::data<sch::FixedArray<sch::UInt64,Desc::D>> meta{{dim_x,dim_y}};
+ auto lbm_data_ptr = saw::heap<saw::data<sch::ChunkStruct<T,Desc>>>();
+ auto lbm_macro_data_ptr = saw::heap<saw::data<sch::MacroStruct<T,Desc>>>();
+ auto lbm_particle_data_ptr = saw::heap<saw::data<sch::ParticleSpheroidGroup<T,Desc>>>();
+ // auto lbm_particles_ptr = saw::heap<saw::data<sch::FixedArray<sch::ParticleRigidBody<T,Desc::D>,part_count>>>();
+ // saw::data<sch::Array<T,Desc::D>> p_mask;
+
+ std::cout<<"Estimated Bytes of LBM Fields: "<<memory_estimate<sch::ChunkStruct<T,Desc>,sch::MacroStruct<T,Desc>>().get()<<std::endl;
+
+ auto eo_aio = saw::setup_async_io();
+ if(eo_aio.is_error()){
+ return std::move(eo_aio.get_error());
+ }
+ auto& aio = eo_aio.get_value();
+ saw::wait_scope wait{aio.event_loop};
+
+ bool krun = true;
+ bool print_status = false;
+ aio.event_port.on_signal(saw::Signal::Terminate).then([&](){
+ krun = false;
+ }).detach();
+ aio.event_port.on_signal(saw::Signal::User1).then([&](){
+ print_status = true;
+ }).detach();
+
+ device dev;
+
+ auto& sycl_q = dev.get_handle();
+
+ sycl_q.wait();
+ {
+ auto eov = setup_initial_conditions<T,Desc>(*lbm_data_ptr,*lbm_macro_data_ptr,*lbm_particle_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_vtk_file(out_dir,"initial_state",0u,*lbm_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+
+ saw::data<sch::ChunkStruct<T,Desc>, encode::Sycl<saw::encode::Native>> lbm_sycl_data{sycl_q};
+ saw::data<sch::MacroStruct<T,Desc>, encode::Sycl<saw::encode::Native>> lbm_sycl_macro_data{sycl_q};
+ saw::data<sch::ParticleSpheroidGroup<T,Desc>, encode::Sycl<saw::encode::Native>> lbm_sycl_particle_data{sycl_q};
+
+ {
+ auto eov = dev.copy_to_device(*lbm_data_ptr,lbm_sycl_data);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = dev.copy_to_device(*lbm_macro_data_ptr,lbm_sycl_macro_data);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = dev.copy_to_device(*lbm_particle_data_ptr,lbm_sycl_particle_data);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ sycl_q.wait();
+
+ auto lsd_view = make_view(lbm_sycl_data);
+ auto lsdm_view = make_view(lbm_sycl_macro_data);
+ auto lsdp_view = make_view(lbm_sycl_particle_data);
+
+ {
+ auto eov = write_vtk_file(out_dir,"ms",0u, *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ saw::data<sch::UInt64> time_steps{16u*4096ul};
+
+ auto& info_f = lsd_view.template get<"info">();
+
+ for(saw::data<sch::UInt64> i{0u}; i < time_steps and krun; ++i){
+ // BC + Collision
+ {
+ auto eov = step<T,Desc>(lsd_view,lsdm_view,lsdp_view,i,dev);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ sycl_q.wait();
+ if(i.get()%1u ==0u){
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_vtk_file(out_dir,"m",i.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ }
+ /*
+ {
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_data,*lbm_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_csv_file(out_dir,"lbm",i.get(), *lbm_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ }
+ */
+ // Stream
+ sycl_q.submit([&](acpp::sycl::handler& h){
+ component<T,Desc,cmpt::Stream,encode::Sycl<saw::encode::Native>> stream;
+
+ h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y}, [=](acpp::sycl::id<Desc::D> idx){
+ saw::data<sch::FixedArray<sch::UInt64,Desc::D>> index;
+ for(uint64_t i = 0u; i < Desc::D; ++i){
+ index.at({{i}}).set(idx[i]);
+ }
+
+ auto info = info_f.at(index);
+
+ if(info.get() > 0u){
+ stream.apply(lsd_view,index,i);
+ }
+ });
+ }).wait();
+ wait.poll();
+ if(print_status){
+ std::cout<<"Status: "<<i.get()<<" of "<<time_steps.get()<<" - "<<(i.template cast_to<sch::Float64>().get() * 100 / time_steps.get())<<"%"<<std::endl;
+ print_status = false;
+ }
+ print_progress_bar(i.get(), time_steps.get()-1u);
+ }
+
+ // After Loop
+ sycl_q.wait();
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_vtk_file(out_dir,"m",time_steps.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+
+ sycl_q.wait();
+ return saw::make_void();
+}
+
+using FloatT = kel::lbm::sch::Float32;
+
+int main(int argc, char** argv){
+ auto eov = lbm_main<FloatT,kel::lbm::sch::D2Q9>(argc, argv);
+ if(eov.is_error()){
+ auto& err = eov.get_error();
+ std::cerr<<"[Error] "<<err.get_category();
+ auto err_msg = err.get_message();
+ if(err_msg.size() > 0u){
+ std::cerr<<" - "<<err_msg;
+ }
+ std::cerr<<std::endl;
+ return err.get_id();
+ }
+ return 0;
+}
diff --git a/lib/core/c++/chunk.hpp b/lib/core/c++/chunk.hpp
index 0f92437..635af91 100644
--- a/lib/core/c++/chunk.hpp
+++ b/lib/core/c++/chunk.hpp
@@ -77,6 +77,11 @@ public:
return values_.at(ind);
}
+ /*
+ const data<ValueSchema, Encode>& neighbour_at(const data<schema::FixedArray<schema::UInt64,sizeof...(Sides)>>& index) const {
+ }
+ */
+
static constexpr auto get_dims(){
return data<schema::FixedArray<schema::UInt64, sizeof...(Sides)>,Encode>{{Sides...}};
}
diff --git a/lib/core/c++/hlbm.hpp b/lib/core/c++/hlbm.hpp
index 7590cc2..6ae7d80 100644
--- a/lib/core/c++/hlbm.hpp
+++ b/lib/core/c++/hlbm.hpp
@@ -43,8 +43,8 @@ public:
/**
* HLBM collision operator for LBM
*/
-template<typename T, typename Descriptor, typename Encode>
-class component<T, Descriptor, cmpt::Hlbm, Encode> final {
+template<typename T, typename Desc, typename Encode>
+class component<T, Desc, cmpt::Hlbm, Encode> final {
private:
typename saw::native_data_type<T>::type relaxation_;
saw::data<T> frequency_;
@@ -55,7 +55,7 @@ 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 {
+ void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, saw::data<sch::FixedArray<sch::UInt64,Desc::D>> index, saw::data<sch::UInt64> time_step) const {
bool is_even = ((time_step.get() % 2) == 0);
@@ -68,9 +68,9 @@ 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);
+ saw::data<sch::Vector<T,Desc::D>>& vel = vel_f.at(index);
- compute_rho_u<T,Descriptor>(dfs_old_f.at(index), rho, vel);
+ compute_rho_u<T,Desc>(dfs_old_f.at(index), rho, vel);
auto& porosity = porosity_f.at(index);
saw::data<sch::Scalar<T>> one;
@@ -80,13 +80,13 @@ public:
auto& N = particle_N_f.at(index);
auto& D = particle_D_f.at(index);
// Convex combination of velocities
- vel = vel * porosity + [&]() -> saw::data<sch::Vector<T,Descriptor::D>> {
+ vel = vel * porosity + [&]() -> saw::data<sch::Vector<T,Desc::D>> {
return (D.at({}).get() > 0.0 ? N * flip_porosity / D : N);
}();
// Equilibrium
- auto eq = equilibrium<T,Descriptor>(rho,vel);
+ auto eq = equilibrium<T,Desc>(rho,vel);
- for(uint64_t i = 0u; i < Descriptor::Q; ++i){
+ for(uint64_t i = 0u; i < Desc::Q; ++i){
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}));
}
@@ -96,20 +96,55 @@ public:
}
};
-template<typename T, typename Descriptor, typename Encode>
-class component<T, Descriptor, cmpt::HlbmParticle, Encode> final {
+namespace impl {
+
+}
+
+template<typename T, typename Desc, typename Encode>
+class component<T, Desc, cmpt::HlbmParticle, Encode> final {
private:
- typename saw::native_data_type<T>::type relaxation_;
- saw::data<T> frequency_;
+ template<typename CellFieldSchema, typename MacroFieldSchema, typename ParticleSchema, uint64_t i>
+ void apply_i(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, const saw::data<ParticleSchema,Encode>& part_groups, saw::data<sch::FixedArray<sch::UInt64,1u>> index, saw::data<sch::UInt64> time_step) const {
+
+ }
public:
+ /*
+ template<typename CellFieldSchema, typename MacroFieldSchema, typename ParticleSchema, uint64_t i>
+ void apply_i()
+ */
template<typename CellFieldSchema, typename MacroFieldSchema, typename ParticleSchema>
- void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, const saw::data<ParticleSchema,Encode>& particles, saw::data<sch::FixedArray<sch::UInt64,1u>> index, saw::data<sch::UInt64> time_step) const {
+ void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, const saw::data<ParticleSchema,Encode>& part_groups, saw::data<sch::FixedArray<sch::UInt64,1u>> index, saw::data<sch::UInt64> time_step) const {
/// Figure out how to access the particle list
// auto& p = particles.at(i);
/// Iterate over the grid bounds
// auto& grid = p.template get<"grid">();
+
+ auto& part_spheroid_group = part_groups.template get<0>();
+ {
+ auto& parts = part_spheroid_group.template get<"particles">();
+ auto parts_size = parts.size();
+
+ auto& pi = parts.at(index);
+ auto& pirb = pi.template get<"rigid_body">();
+ auto& pirb_pos = pirb.template get<"position">();
+
+ saw::data<sch::FixedArray<sch::UInt64,Desc::D>> start;
+ saw::data<sch::FixedArray<sch::UInt64,Desc::D>> stop;
+
+ /// Ok, I iterate over the space which covers our particle? So lower bounds to upper bounds
+ for(uint64_t i{0u}; i < Desc::D; ++i){
+
+ }
+
+ iterator<Desc::D>::apply([&](const auto& index){
+ // ask for the d_k value here.
+ // For every value im iterating over I need sth
+ },start,stop);
+
+ // Check
+ }
}
diff --git a/lib/core/c++/particle/aabb.hpp b/lib/core/c++/particle/aabb.hpp
new file mode 100644
index 0000000..aec95ca
--- /dev/null
+++ b/lib/core/c++/particle/aabb.hpp
@@ -0,0 +1,49 @@
+#pragma once
+
+#include "particle.hpp"
+
+namespace kel {
+namespace lbm {
+template<typename T, uint64_t D, typename PColl>
+class particle_aabb final {
+};
+
+template<typename T, uint64_t D, typename saw::native_data_type<T>::type radius>
+class particle_aabb<ParticleGroup<T,D,sch::ParticleCollisionSpheroid<T,radius> > > final {
+public:
+ using Schema = sch::ParticleGroup<T,D,sch::ParticleCollisionSpheroid<T,radius>>;
+
+ using AABB = Struct<
+ Member<sch::FixedArray<sch::UInt64,D>"a">,
+ Member<sch::FixedArray<sch::UInt64,D>"b">
+ >;
+public:
+ static constexpr saw::data<AABB> get(const saw::data<Schema>& p_grp, const saw::data<sch::FixedArray<sch::UInt64,1u>>& i, const saw::data<sch::FixedArray<sch::UInt64,D>>& meta){
+ auto& parts = p_grp.template get<"particles">();
+
+ auto& pi = parts.at(i);
+ auto& pirb = pi.template get<"rigid_body">();
+ auto& pirb_pos = pirb.template get<"position">();
+
+ saw::data<AABB> aabb;
+ auto& a = aabb.template get<"a">();
+ auto& b = aabb.template get<"b">();
+
+ saw::data<sch::Scalar<T>> rad_d;
+ rad_d.at({}).set(radius);
+
+ saw::data<sch::Vector<T,D>> lower;
+ saw::data<sch::Vector<T,D>> upper;
+
+ for(uint64_t i{0u}; i < D; ++i){
+ lower.at({{i}}) = pirb_pos.at({{i}}) >= rad_d.at({}) ? (pirb_pos.at({{i}}) - rad_d.at({})) : saw::data<T>{0};
+ a.at({i}) = lower.at({{i}}).template cast_to<sch::UInt64>();
+ upper.at({{i}}) = pirb_pos.at({{i}}) + rad_d.at({});
+ b.at({i}) = (upper.at({{i}})+saw::data<T>{1}).template cast_to<sch::UInt64>()
+ }
+
+ return aabb;
+ }
+};
+}
+}
diff --git a/lib/core/c++/particle/porosity.hpp b/lib/core/c++/particle/porosity.hpp
index aa1ce5b..39d9652 100644
--- a/lib/core/c++/particle/porosity.hpp
+++ b/lib/core/c++/particle/porosity.hpp
@@ -8,7 +8,9 @@ namespace lbm {
template<typename T, uint64_t D, typename Coll>
class particle_porosity {
public:
- saw::data<sch::Scalar<T>> calculate(const saw::data<>& part_group, uint64_t p_i, const saw::data<sch::Vector<T,D>>& lbm_pos){
+
+
+ saw::data<sch::Scalar<T>> calculate(const saw::data<sch::ParticleGroup<T,D,Coll>>& part_group, uint64_t p_i, const saw::data<sch::Vector<T,D>>& lbm_pos){
auto& mask = part_group.template get<"mask">();
auto& particles = part_group.template get<"particles">();
@@ -17,7 +19,7 @@ public:
auto& part_i_rb = part_i.template get<"rigid_body">();
auto& pirb = part_i_rb.template get<"position">();
- auto& dist = lbm_pos = lbm_pos - pirb;
+ auto dist = lbm_pos - pirb;
// index 0 is at
@@ -26,25 +28,58 @@ public:
};
-template<typename T, uint64_t D, typename saw::native_data_type<T>::type radius>
-class particle_porosity<T, D, coll::ParticleCollisionSpheroid<T,radius>> final {
+template<typename T, uint64_t D, typename saw::native_data_type<T>::type radius, typename saw::native_data_type<T>::type eps>
+class particle_porosity<T, D, coll::ParticleCollisionSpheroid<T,radius, eps>> final {
public:
- saw::data<sch::Scalar<T>> calculate(const saw::data<sch::Particle>&, uint64_t i, const saw::data<sch::Vector<T,D>>& lbm_pos){
+ saw::data<sch::Scalar<T>> calculate(const saw::data<sch::ParticleGroup<T,D,sch::ParticleCollisionSpheroid<T,radius,eps> > >& part_group, uint64_t i, const saw::data<sch::Vector<T,D>>& lbm_pos){
saw::data<sch::Scalar<T>> por;
por.at({});
- saw::data<sch::Scalar<T>> dps_2;
+ auto& parts = part_group.template get<"particles">();
+ auto& pi = parts.at({i});
+ auto& pi_rb = pi.template get<"rigid_body">();
+
+ auto& pi_rb_pos = pi_rb.template get<"position">();
+
+ // Basically the queried position minus the center of the particle
+ auto dist = lbm_pos - pi_rb_pos;
+
+ saw::data<sch::Scalar<T>> dist_len;
for(uint64_t i{0u}; i < D; ++i){
- auto& dps_i = lbm_pos.at({{i}});
- dps_2.at({}) = dps_i * dps_i;
+ auto& d_i = dist.at({{i}});
+ dist_len.at({}) = d_i * d_i;
}
+ dist_len.at({}).set(std::sqrt(dist_len.at({}).get());
- saw::data<sch::Scalar<T>> rad_2;
- rad_2.at({}).set(radius*radius);
+ saw::data<sch::Scalar<T>> rad_d{radius};
+ saw::data<sch::Scalar<T>> eps_half{eps *0.5};
+
+ saw::data<sch::Scalar<T>> rad_d_eps_p = rad_d + eps_half;
+ saw::data<sch::Scalar<T>> rad_d_eps_n = rad_d - eps_half;
+
+ // saw::data<sch::Scalar<T>> rad_d_eps_p_2 = rad_d_eps_p * rad_d_eps_p;
+ // saw::data<sch::Scalar<T>> rad_d_eps_n_2 = rad_d_eps_n * rad_d_eps_n;
+ // saw::data<sch::Scalar<T>> rad_2;
+ // rad_2 = rad_d * rad_d;
saw::data<sch::Scalar<T>> inside;
- if(dps_2.at({}).get() < rad_2.at({}).get()){
+ if(dist_len.at({}) <= rad_d_eps_n.at({})){
inside.at({}).set(1);
+ return inside;
+ }
+ if(dist_len.at({}) > rad_d_eps_p.at({})){
+ inside.at({}).set(0);
+ return inside
+ }
+
+ /*
+ * cos^2 ( ||x-X(t)||_2 - (R-eps/2) )
+ */
+ {
+ typename saw::native_data_type<T>::type inner = (std::pi / ( 2.0 * eps )) * (dist_len - rad_d_eps_n).at({}).get();
+ auto cos_inner = std::cos(inner);
+ auto cos_i_2 = cos_inner * cos_inner;
+ inside.at({}).set(cos_i_2);
}
return inside;
}