diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-10-01 13:29:47 +0200 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-10-01 13:29:47 +0200 |
| commit | ac2bc7ccecc202a152caf900debbf79cae8745a6 (patch) | |
| tree | cf2f4cefb488231c9d898a257af5c6e8d2a6a71a | |
| parent | f53b62f995af1ad0e7cbc8aa3a7522d041eb9363 (diff) | |
| download | libs-lbm-ac2bc7ccecc202a152caf900debbf79cae8745a6.tar.gz | |
Dangling commit with lots of changes
Importantly it restructures the example I'm using the most and
it fixes a index access issue in the collision
| -rw-r--r-- | c++/SConscript | 8 | ||||
| -rw-r--r-- | default.nix | 5 | ||||
| -rw-r--r-- | examples/SConscript | 6 | ||||
| -rw-r--r-- | examples/poiseulle_particles_channel_2d/.nix/derivation.nix | 33 | ||||
| -rw-r--r-- | examples/poiseulle_particles_channel_2d/SConscript | 32 | ||||
| -rw-r--r-- | examples/poiseulle_particles_channel_2d/SConstruct | 80 | ||||
| -rw-r--r-- | examples/poiseulle_particles_channel_2d/poiseulle_particles_channel_2d.cpp (renamed from examples/poiseulle_particles_channel_2d.cpp) | 55 |
7 files changed, 172 insertions, 47 deletions
diff --git a/c++/SConscript b/c++/SConscript index 857ca77..85a078f 100644 --- a/c++/SConscript +++ b/c++/SConscript @@ -15,14 +15,18 @@ core_env = env.Clone(); core_env.sources = sorted(glob.glob(dir_path + "/*.cpp")); core_env.headers = sorted(glob.glob(dir_path + "/*.hpp")); +core_env.particle_headers = sorted(glob.glob(dir_path + "/particle/*.hpp")); +core_env.particle_geometry_headers = sorted(glob.glob(dir_path + "/particle/geometry/*.hpp")); + env.sources += core_env.sources; env.headers += core_env.headers; - ## Static lib objects = [] core_env.add_source_files(objects, core_env.sources, shared=False); env.library_static = core_env.StaticLibrary('#build/kel-lbm', [objects]); env.Install('$prefix/lib/', env.library_static); -env.Install('$prefix/include/kel/lbm/', env.headers); +env.Install('$prefix/include/kel/lbm/', core_env.headers); +env.Install('$prefix/include/kel/lbm/particle/', core_env.particle_headers); +env.Install('$prefix/include/kel/lbm/particle/geometry/', core_env.particle_geometry_headers); diff --git a/default.nix b/default.nix index a26e539..52458aa 100644 --- a/default.nix +++ b/default.nix @@ -32,6 +32,11 @@ in rec { inherit pname version stdenv forstio adaptive-cpp; kel-lbm = lbm; }; + + poiseulle_particles_channel_2d = pkgs.callPackage ./examples/poiseulle_particles_channel_2d/.nix/derivation.nix { + inherit pname version stdenv forstio; + kel-lbm = lbm; + }; }; debug = { diff --git a/examples/SConscript b/examples/SConscript index 3a22897..e8c89b1 100644 --- a/examples/SConscript +++ b/examples/SConscript @@ -48,11 +48,6 @@ examples_objects = []; examples_env.add_source_files(examples_objects, ['poiseulle_channel_2d.cpp'], shared=False); examples_env.poiseulle_channel_2d = examples_env.Program('#bin/poiseulle_channel_2d', [env.library_static, examples_objects]); -# Poiseulle Particles Channel 2D -examples_objects = []; -examples_env.add_source_files(examples_objects, ['poiseulle_particles_channel_2d.cpp'], shared=False); -examples_env.poiseulle_particles_channel_2d = examples_env.Program('#bin/poiseulle_particles_channel_2d', [env.library_static, examples_objects]); - # Set Alias env.examples = [ examples_env.meta_2d, @@ -61,7 +56,6 @@ env.examples = [ # examples_env.particle_ibm_2d # examples_env.poiseulle_2d, # examples_env.poiseulle_channel_2d, - examples_env.poiseulle_particles_channel_2d ]; env.Alias('examples', env.examples); diff --git a/examples/poiseulle_particles_channel_2d/.nix/derivation.nix b/examples/poiseulle_particles_channel_2d/.nix/derivation.nix new file mode 100644 index 0000000..58c45d5 --- /dev/null +++ b/examples/poiseulle_particles_channel_2d/.nix/derivation.nix @@ -0,0 +1,33 @@ +{ lib +, stdenv +, scons +, clang-tools +, forstio +, pname +, version +, kel-lbm +}: + +stdenv.mkDerivation { + pname = pname + "-examples-" + "poiseulle_particles_channel_2d"; + inherit version; + src = ./..; + + nativeBuildInputs = [ + scons + clang-tools + ]; + + buildInputs = [ + forstio.core + forstio.async + forstio.codec + forstio.codec-unit + forstio.codec-json + kel-lbm + ]; + + preferLocalBuild = true; + + outputs = [ "out" "dev" ]; +} diff --git a/examples/poiseulle_particles_channel_2d/SConscript b/examples/poiseulle_particles_channel_2d/SConscript new file mode 100644 index 0000000..f4f111a --- /dev/null +++ b/examples/poiseulle_particles_channel_2d/SConscript @@ -0,0 +1,32 @@ +#!/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.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; + +# PoiseulleParticlesChannel2D +examples_objects = []; +examples_env.add_source_files(examples_objects, ['poiseulle_particles_channel_2d.cpp'], shared=False); +examples_env.example_bin = examples_env.Program('#bin/poiseulle_particles_channel_2d', [examples_objects]); + +# Set Alias +env.examples = [ + examples_env.example_bin +]; +env.Alias('examples', env.examples); +env.targets += ['examples']; +env.Install('$prefix/bin/', env.examples); diff --git a/examples/poiseulle_particles_channel_2d/SConstruct b/examples/poiseulle_particles_channel_2d/SConstruct new file mode 100644 index 0000000..edcd146 --- /dev/null +++ b/examples/poiseulle_particles_channel_2d/SConstruct @@ -0,0 +1,80 @@ +#!/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' + ] +); +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/poiseulle_particles_channel_2d.cpp b/examples/poiseulle_particles_channel_2d/poiseulle_particles_channel_2d.cpp index 20919b0..3b1e977 100644 --- a/examples/poiseulle_particles_channel_2d.cpp +++ b/examples/poiseulle_particles_channel_2d/poiseulle_particles_channel_2d.cpp @@ -1,8 +1,8 @@ -#include "../c++/lbm.hpp" -#include "../c++/collision.hpp" -#include "../c++/boundary.hpp" -#include "../c++/iterator.hpp" -#include "../c++/particle/geometry/circle.hpp" +#include <kel/lbm/lbm.hpp> +#include <kel/lbm/collision.hpp> +#include <kel/lbm/boundary.hpp> +#include <kel/lbm/iterator.hpp> +#include <kel/lbm/particle/geometry/circle.hpp> #include <forstio/codec/args.hpp> #include <forstio/codec/data.hpp> @@ -58,7 +58,6 @@ using CellStruct = Struct< Member<DfCell<Desc>, "dfs">, Member<DfCell<Desc>, "dfs_old">, Member<CellInfo<Desc>, "info">, - // Member<CellParticleMask<Desc>, "particle_mask">, Member<CellForceField<Desc>, "force"> >; @@ -68,7 +67,6 @@ using MacroStruct = Struct< Member<T, "pressure">, Member<UInt16, "particle">, Member<FixedArray<T,D>, "force"> - //Member<Vector<T,D>, "debug_acceleration"> >; template<typename T> @@ -397,14 +395,6 @@ void couple_particles_to_lattice( saw::data<sch::Vector<sch::T,2u>> solid_normal; - //////////// - bool coll = false; - saw::data<sch::FixedArray<sch::UInt64,2u>> first_index; - saw::data<sch::FixedArray<sch::UInt64,2u>> first_pos; - saw::data<sch::Array<sch::FixedArray<sch::UInt64,2u>>> first_indices; - saw::data<sch::Array<sch::FixedArray<sch::UInt64,2u>>> first_poses; - - iterate_over([&](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){ if(p_mask_grid.at(index).get() == 0){ @@ -418,9 +408,16 @@ void couple_particles_to_lattice( } saw::data<sch::Vector<sch::T,2u>> mask_shift; + /* { mask_shift.at({{0u}}) = index_shift.at({{0u}}) * x_dir.at({0u}) + index_shift.at({{1u}}) * y_dir.at({0u}); - mask_shift.at({{1u}}) = index_shift.at({{1u}}) * x_dir.at({1u}) + index_shift.at({{1u}}) * y_dir.at({1u}); + mask_shift.at({{1u}}) = index_shift.at({{0u}}) * x_dir.at({1u}) + index_shift.at({{1u}}) * y_dir.at({1u}); + } + */ + { + // Technically rotate and adjust here + mask_shift.at({{0u}}) = index_shift.at({{0u}}); + mask_shift.at({{1u}}) = index_shift.at({{1u}}); } auto p_pos_lie = p_pos + mask_shift; @@ -436,8 +433,6 @@ void couple_particles_to_lattice( p_cell_pos.at({{0u}}).set(std::max(1ul, std::min(p_cell_pos.at({{0u}}).get(), meta.at({0u}).get()-2ul))); p_cell_pos.at({{1u}}).set(std::max(1ul, std::min(p_cell_pos.at({{1u}}).get(), meta.at({1u}).get()-2ul))); } - first_indices.add(index); - first_poses.add(p_cell_pos); saw::data<sch::Vector<sch::UInt64,2u>> p_vec_cell_pos; { @@ -451,12 +446,6 @@ void couple_particles_to_lattice( auto& cell = latt(p_cell_pos); auto& p_info = cell.template get<"info">()({0u}); if((p_info.get() <= 1u)){ - if(not coll){ - first_index = index; - first_pos = p_cell_pos; - } - coll = true; - // Fake solid normal auto p_pos_rel_vec = p_pos - p_vec_cell_pos.template cast_to<sch::T>(); @@ -468,7 +457,7 @@ void couple_particles_to_lattice( { saw::data<sch::Scalar<sch::T>> one; - one.at({}) = {1.0f}; + one.at({}) = {0.1f}; p_pos_rel_vec.at({{0u}}) = p_pos_rel_vec.at({{0u}}) * one.at({}); p_pos_rel_vec.at({{1u}}) = p_pos_rel_vec.at({{1u}}) * one.at({}); @@ -520,24 +509,12 @@ void couple_particles_to_lattice( }, {{0u,0u}}, p_mask_grid.dims()); - std::cout<<"\nReachable check: "<<solid_normal.at({{0u}}).get()<<std::endl; solid_normal = saw::math::normalize(solid_normal); + // Calculate orientation (Leaving wall "< 0" or not "> 0") auto v_n = saw::math::dot(solid_normal, (p_vel + p_acc)); - std::cout<<"ACC: "<<p_acc.at({{0u}}).get()<<" "<<p_acc.at({{1u}}).get()<<std::endl; - std::cout<<"VEL: "<<p_vel.at({{0u}}).get()<<" "<<p_vel.at({{1u}}).get()<<std::endl; - std::cout<<"POS: "<<p_pos.at({{0u}}).get()<<" "<<p_pos.at({{1u}}).get()<<std::endl; - std::cout<<"Normal: "<<solid_normal.at({{0u}}).get()<<" "<<solid_normal.at({{1u}}).get()<<std::endl; - std::cout<<"V_N: "<<v_n.at({}).get()<<std::endl; - std::cout<<"Timestep: "<<time_step.get()<<std::endl; - if(coll){ - std::cout<<"Collision happened at "<<first_index.at({0u}).get()<<" "<<first_index.at({1u}).get()<<" and at "<<first_pos.at({0u}).get()<<" "<<first_pos.at({1u}).get()<<std::endl; - for(saw::data<sch::UInt64> i{0u}; i < first_indices.size(); ++i){ - std::cout<<"Index: "<<first_indices.at(i).at({0u}).get()<<" "<<first_indices.at(i).at({1u}).get()<<" "<<first_poses.at(i).at({0u}).get()<<" "<<first_poses.at(i).at({1u}).get()<<std::endl; - } - } + if(v_n.at({}).get() < 0.0){ - std::cout<<"Solid 0: "<<solid_normal.at({{0u}}).get()<<std::endl; solid_normal.at({{0u}}) = solid_normal.at({{0u}})*v_n.at({}); solid_normal.at({{1u}}) = solid_normal.at({{1u}})*v_n.at({}); p_acc = p_acc - solid_normal; |
