summaryrefslogtreecommitdiff
path: root/examples/particles_gpu
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-11-13 14:12:49 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-11-13 14:12:49 +0100
commite821d617802ebbfff756844e4d9720342fc78a4e (patch)
tree1dcf33b84698b5074218e44ea491b77a9c23ee66 /examples/particles_gpu
parent0c0087ef9482634273ec1a23d3a915754f94926d (diff)
downloadlibs-lbm-e821d617802ebbfff756844e4d9720342fc78a4e.tar.gz
Swarm POCdev
Diffstat (limited to 'examples/particles_gpu')
-rw-r--r--examples/particles_gpu/.nix/derivation.nix37
-rw-r--r--examples/particles_gpu/SConscript34
-rw-r--r--examples/particles_gpu/SConstruct82
-rw-r--r--examples/particles_gpu/particles_gpu.cpp136
4 files changed, 0 insertions, 289 deletions
diff --git a/examples/particles_gpu/.nix/derivation.nix b/examples/particles_gpu/.nix/derivation.nix
deleted file mode 100644
index 6ab8825..0000000
--- a/examples/particles_gpu/.nix/derivation.nix
+++ /dev/null
@@ -1,37 +0,0 @@
-{ lib
-, stdenv
-, scons
-, clang-tools
-, forstio
-, python3
-, pname
-, version
-, kel
-, adaptive-cpp
-}:
-
-stdenv.mkDerivation {
- pname = pname + "-examples-" + "particles";
- inherit version;
- src = ./..;
-
- nativeBuildInputs = [
- scons
- clang-tools
- python3
- ];
-
- buildInputs = [
- forstio.core
- forstio.async
- forstio.codec
- forstio.codec-unit
- forstio.codec-json
- kel.lbm.core
- adaptive-cpp
- ];
-
- preferLocalBuild = true;
-
- outputs = [ "out" "dev" ];
-}
diff --git a/examples/particles_gpu/SConscript b/examples/particles_gpu/SConscript
deleted file mode 100644
index f22fdf2..0000000
--- a/examples/particles_gpu/SConscript
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/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, ['particles_gpu.cpp'], shared=False);
-examples_env.particles_gpu = examples_env.Program('#bin/particles_gpu', [examples_objects]);
-
-# Set Alias
-env.examples = [
- examples_env.particles_gpu
-];
-env.Alias('examples', env.examples);
-env.targets += ['examples'];
-env.Install('$prefix/bin/', env.examples);
diff --git a/examples/particles_gpu/SConstruct b/examples/particles_gpu/SConstruct
deleted file mode 100644
index fe206e1..0000000
--- a/examples/particles_gpu/SConstruct
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/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',
- '-isystem', 'AdaptiveCpp'
- ],
- LIBS=[
- 'forstio-core',
- 'acpp-rt',
- 'omp'
- ]
-);
-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/particles_gpu/particles_gpu.cpp b/examples/particles_gpu/particles_gpu.cpp
deleted file mode 100644
index 94ec5f1..0000000
--- a/examples/particles_gpu/particles_gpu.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-#include <kel/lbm/lbm.hpp>
-#include <AdaptiveCpp/sycl/sycl.hpp>
-
-
-#include <kel/lbm/particle/particle.hpp>
-#include <iostream>
-
-namespace kel{
-namespace lbm {
-namespace sch {
-}
-}
-
-kel::lbm::error_or<void> lbm_main(int argc, char** argv){
- (void) argc;
- (void) argv;
-
- using namespace lbm;
- using namespace acpp;
-
- kel::lbm::data<sch::Array<sch::Particle<sch::Float32,2u>>> particles{1024u};
-
- for(kel::lbm::data<sch::UInt64> i{0u}; i < kel::lbm::data<sch::UInt64>{32u}; ++i){
- for(kel::lbm::data<sch::UInt64> j{0u}; j < kel::lbm::data<sch::UInt64>{32u}; ++j){
-
- auto& part = particles.at(i*32ul+j);
- auto& body = part.template get<"rigid_body">();
-
- auto& pos = body.template get<"position">();
- auto& old_pos = body.template get<"position_old">();
- auto& acceleration = body.template get<"acceleration">();
- auto& p_rad = part.template get<"collision">().template get<"radius">();
- // Scalar<T> base, so the value goes through the element rather than a
- // braced whole-unit assignment.
- p_rad.at({}).set(0.4f);
-
- if(j.get() % 2u == 0) acceleration.at({{1u}}) = {-9.81};
-
- pos.at({{0u}}) = {i.template cast_to<sch::Float32>()+0.5f};
- pos.at({{1u}}) = {j.template cast_to<sch::Float32>()+64.0f};
-
- old_pos = pos;
- }
- }
-
- // A timestep is a lattice time, which makes (pos - pos_old)/time_step a
- // velocity rather than an unlabelled vector.
- kel::lbm::data<sch::LbmSecond<sch::Scalar<sch::Float32>>> time_step;
- time_step.at({}).set(0.05f);
-
- for(kel::lbm::data<sch::UInt64> dt{0u}; dt < kel::lbm::data<sch::UInt64>{32ul}; ++dt){
- // Do Verlet Step
- for(kel::lbm::data<sch::UInt64> i{0u}; i < particles.size(); ++i){
- auto& part_i = particles.at(i);
-
- verlet_step_lambda<sch::Float32,2u>(part_i,time_step);
- auto& body_i = part_i.template get<"rigid_body">();
- auto& acc_i = body_i.template get<"acceleration">();
-
- acc_i.at({{0u}}) = 0.0;
- acc_i.at({{1u}}) = -9.81;
- }
-
- //
- for(kel::lbm::data<sch::UInt64> i{0u}; i < particles.size(); ++i){
- auto& part_i = particles.at(i);
- auto& body_i = part_i.template get<"rigid_body">();
- auto& pos_i = body_i.template get<"position">();
- auto& pos_old_i = body_i.template get<"position_old">();
- /**
- * Test against other particles
- */
- for(kel::lbm::data<sch::UInt64> j{i+1ul}; j < particles.size(); ++j){
- auto& part_j = particles.at(j);
- auto& body_j = part_j.template get<"rigid_body">();
- auto& pos_j = body_j.template get<"position">();
- auto& pos_old_j = body_j.template get<"position_old">();
-
- auto res = broadphase_collision_distance_squared<sch::Float32,2u>(part_i, part_j);
- if(res.first){
- //std::cout<<"Collision"<<std::endl;
- // Do collision
-
- auto vel_i = (pos_i - pos_old_i)/time_step;
- auto vel_j = (pos_j - pos_old_j)/time_step;
-
- auto vel_rel = vel_i - vel_j;
- auto pos_rel = pos_i - pos_j;
-
- auto vel_pos_rel_dot = kel::lbm::math::dot(vel_rel,pos_rel);
- if(vel_pos_rel_dot.at({}).get() < 0.0){
- auto pos_rel_normed = pos_rel / kel::lbm::math::sqrt(res.second);
- }
-
- // auto vel_ij = kel::lbm::math::dot(vel_i,vel_j);
-
- }
- }
- /**
- * Test against walls
- */
- if(pos_i.at({{0u}}).get() <= 0 or pos_i.at({{0u}}).get() >= 40 ){
- auto pos_i_0 = pos_i.at({{0u}});
- pos_i.at({{0u}}) = pos_old_i.at({{0u}});
- pos_old_i.at({{0u}}) = pos_i_0;
- }
- if(pos_i.at({{1u}}).get() <= 0 ){
- auto pos_i_1 = pos_i.at({{1u}});
- pos_i.at({{1u}}) = pos_old_i.at({{1u}});
- pos_old_i.at({{1u}}) = pos_i_1;
- }
- }
- auto& pos = particles.at({0u}).template get<"rigid_body">().template get<"position">();
-
- std::cout<<pos.at({{0u}}).get()<<" "<<pos.at({{1u}}).get()<<std::endl;
- }
-
- return kel::lbm::make_void();
-}
-}
-
-int main(int argc, char** argv){
- auto eov = kel::lbm_main(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;
-}