summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-02-09 16:49:12 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-02-09 16:49:12 +0100
commit5fee9c698f5f1ebe6ef8bf07f5a75e04dab92681 (patch)
tree8c3adef346837c54fa2618e276708e4a8b3bea4d
parent08d1d887e47ddbd61236c36193b3ef304e69fc0b (diff)
downloadlibs-lbm-5fee9c698f5f1ebe6ef8bf07f5a75e04dab92681.tar.gz
Add rar as dep and implement collision
-rw-r--r--default.nix26
-rw-r--r--examples/poiseulle_2d_gpu/.nix/derivation.nix1
-rw-r--r--examples/poiseulle_particles_2d_gpu/.nix/derivation.nix5
-rw-r--r--examples/poiseulle_particles_2d_gpu/SConstruct4
-rw-r--r--examples/poiseulle_particles_2d_gpu/sim.cpp28
-rw-r--r--lib/core/c++/collision.hpp6
-rw-r--r--lib/core/c++/hlbm.hpp10
-rw-r--r--lib/core/c++/psm.hpp35
8 files changed, 107 insertions, 8 deletions
diff --git a/default.nix b/default.nix
index bb583f9..7c19841 100644
--- a/default.nix
+++ b/default.nix
@@ -36,6 +36,32 @@ let
llvmPackages = pkgs.llvmPackages_19;
lld = pkgs.lld_19;
};
+
+ sci_tools = let
+ scitoolsSrc = stdenv.mkDerivation {
+ name = "scitools-src";
+
+ src = builtins.fetchurl {
+ url = "https://git.keldu.de/apps-science_tools/snapshot/master.tar.gz";
+ sha256 = "e91c18fef798dd7b3afbd1615c2e320b90a74aa2d7ef726801a76e3f7f77ae81";
+ };
+
+ phases = [ "unpackPhase" "installPhase" ];
+
+ unpackPhase = ''
+ mkdir source
+ tar -xzf "$src" -C source --strip-components=1
+ '';
+
+ installPhase = ''
+ cp -r source $out
+ '';
+ };
+ in
+ (import "${scitoolsSrc}/default.nix" {
+ inherit stdenv clang-tools forstio;
+ });
+
forstio = let
forstioSrc = stdenv.mkDerivation {
name = "forstio-src";
diff --git a/examples/poiseulle_2d_gpu/.nix/derivation.nix b/examples/poiseulle_2d_gpu/.nix/derivation.nix
index 127243d..cc132ee 100644
--- a/examples/poiseulle_2d_gpu/.nix/derivation.nix
+++ b/examples/poiseulle_2d_gpu/.nix/derivation.nix
@@ -28,6 +28,7 @@ stdenv.mkDerivation {
forstio.codec-unit
forstio.remote
forstio.codec-json
+ forstio.io
adaptive-cpp
kel.lbm.core
# kel-lbm.sycl
diff --git a/examples/poiseulle_particles_2d_gpu/.nix/derivation.nix b/examples/poiseulle_particles_2d_gpu/.nix/derivation.nix
index e08f42a..517b6b8 100644
--- a/examples/poiseulle_particles_2d_gpu/.nix/derivation.nix
+++ b/examples/poiseulle_particles_2d_gpu/.nix/derivation.nix
@@ -26,8 +26,9 @@ stdenv.mkDerivation {
forstio.async
forstio.codec
forstio.codec-unit
- forstio.remote
- forstio.remote-filesystem
+ forstio.io
+ forstio.remote
+ forstio.remote-filesystem
forstio.codec-json
adaptive-cpp
kel.lbm.core
diff --git a/examples/poiseulle_particles_2d_gpu/SConstruct b/examples/poiseulle_particles_2d_gpu/SConstruct
index a7201cb..0611b67 100644
--- a/examples/poiseulle_particles_2d_gpu/SConstruct
+++ b/examples/poiseulle_particles_2d_gpu/SConstruct
@@ -57,7 +57,9 @@ env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
'-Wextra'
],
LIBS=[
- 'forstio-core'
+ 'forstio-core',
+ 'forstio-async',
+ 'forstio-io'
]
);
env.__class__.add_source_files = add_kel_source_files
diff --git a/examples/poiseulle_particles_2d_gpu/sim.cpp b/examples/poiseulle_particles_2d_gpu/sim.cpp
index d14be91..42d8413 100644
--- a/examples/poiseulle_particles_2d_gpu/sim.cpp
+++ b/examples/poiseulle_particles_2d_gpu/sim.cpp
@@ -1,6 +1,7 @@
#include <kel/lbm/sycl/lbm.hpp>
#include <kel/lbm/lbm.hpp>
+#include <forstio/io/io.hpp>
#include <forstio/remote/filesystem/easy.hpp>
#include <forstio/codec/json/json.hpp>
@@ -36,6 +37,9 @@ using MacroStruct = Struct<
Member<VelChunk<T,Desc>, "velocity">,
Member<RhoChunk<T>, "density">
>;
+
+// template<typename T, typename Desc>
+// using Particles = Particle<
}
template<typename T, typename Desc>
@@ -224,6 +228,22 @@ saw::error_or<void> lbm_main(int argc, char** argv){
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 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();
@@ -256,7 +276,7 @@ saw::error_or<void> lbm_main(int argc, char** argv){
sycl_q.wait();
saw::data<sch::UInt64> time_steps{4096ul};
- for(saw::data<sch::UInt64> i{0u}; i < time_steps; ++i){
+ for(saw::data<sch::UInt64> i{0u}; i < time_steps and krun; ++i){
{
std::string file_name = "tmp/t_";
file_name += std::to_string(i.get());
@@ -293,6 +313,12 @@ saw::error_or<void> lbm_main(int argc, char** argv){
return eov;
}
}
+
+ 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;
+ }
}
sycl_q.wait();
{
diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp
index 6c39646..349833f 100644
--- a/lib/core/c++/collision.hpp
+++ b/lib/core/c++/collision.hpp
@@ -118,8 +118,8 @@ public:
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">();
- saw::data<T> rho;
- saw::data<sch::FixedArray<T,Descriptor::D>> vel;
+ saw::data<sch::Scalar<T>> rho;
+ saw::data<sch::Vector<T,Descriptor::D>> vel;
compute_rho_u<T,Descriptor>(dfs_old,rho,vel);
auto eq = equilibrium<T,Descriptor>(rho,vel);
@@ -131,7 +131,7 @@ public:
// saw::data<T> ci_min_u{0};
saw::data<T> ci_dot_u{0};
for(uint64_t d = 0u; d < Descriptor::D; ++d){
- ci_dot_u = ci_dot_u + vel.at({d}) * saw::data<T>{static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d])};
+ ci_dot_u = ci_dot_u + vel.at({{d}}) * saw::data<T>{static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d])};
}
saw::data<T> F_i{0};// = saw::data<T>{dfi::weights[i]} * (ci_dot_F * dfi::inv_cs2 + ci_dot_u * ci_dot_F * (dfi::inv_cs2 * dfi::inv_cs2));
diff --git a/lib/core/c++/hlbm.hpp b/lib/core/c++/hlbm.hpp
index 1c665ce..f8f0118 100644
--- a/lib/core/c++/hlbm.hpp
+++ b/lib/core/c++/hlbm.hpp
@@ -13,11 +13,19 @@ struct HLBM {};
/**
* HLBM collision operator for LBM
*/
-template<typename T, typename Descriptor>
+template<typename T, typename Descriptor, typename Encode>
class component<T, Descriptor, cmpt::HLBM> {
private:
public:
component() = default;
+
+ 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);
+
+
+ }
};
}
diff --git a/lib/core/c++/psm.hpp b/lib/core/c++/psm.hpp
new file mode 100644
index 0000000..8e151c3
--- /dev/null
+++ b/lib/core/c++/psm.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "macroscopic.hpp"
+#include "component.hpp"
+#include "equilibrium.hpp"
+
+namespace kel {
+namespace lbm {
+namespace cmpt {
+struct PSM {};
+}
+
+/**
+ * HLBM collision operator for LBM
+ */
+template<typename T, typename Descriptor, typename Encode>
+class component<T, Descriptor, cmpt::PSM> {
+private:
+public:
+ component() = default;
+
+ 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);
+
+ auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
+ auto& porous = field.template get<"porosity">();
+
+
+ }
+};
+
+}
+}