From 2ac145b3bb6d2de3887ab08e0cf26423b5e6c5ee Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 25 Feb 2026 20:33:36 +0100 Subject: Changes to run, reworking meta reporting for easier estimation of runtime parameters --- default.nix | 2 +- examples/meta/.nix/derivation.nix | 33 ++++++++++ examples/meta/SConscript | 32 ++++++++++ examples/meta/SConstruct | 79 ++++++++++++++++++++++++ examples/meta/meta.cpp | 96 +++++++++++++++++++++++++++++ examples/meta_2d/.nix/derivation.nix | 33 ---------- examples/meta_2d/SConscript | 32 ---------- examples/meta_2d/SConstruct | 79 ------------------------ examples/meta_2d/meta_2d.cpp | 36 ----------- examples/poiseulle_3d_gpu/sim.cpp | 2 +- examples/poiseulle_particles_2d_gpu/sim.cpp | 2 +- lib/core/c++/converter.hpp | 8 +++ lib/core/c++/lbm.hpp | 24 +++++++- 13 files changed, 272 insertions(+), 186 deletions(-) create mode 100644 examples/meta/.nix/derivation.nix create mode 100644 examples/meta/SConscript create mode 100644 examples/meta/SConstruct create mode 100644 examples/meta/meta.cpp delete mode 100644 examples/meta_2d/.nix/derivation.nix delete mode 100644 examples/meta_2d/SConscript delete mode 100644 examples/meta_2d/SConstruct delete mode 100644 examples/meta_2d/meta_2d.cpp diff --git a/default.nix b/default.nix index cc0a84c..81a03b4 100644 --- a/default.nix +++ b/default.nix @@ -132,7 +132,7 @@ in rec { inherit kel; }; - meta_2d = pkgs.callPackage ./examples/meta_2d/.nix/derivation.nix { + meta = pkgs.callPackage ./examples/meta/.nix/derivation.nix { inherit pname version stdenv forstio; inherit kel; }; diff --git a/examples/meta/.nix/derivation.nix b/examples/meta/.nix/derivation.nix new file mode 100644 index 0000000..26706e6 --- /dev/null +++ b/examples/meta/.nix/derivation.nix @@ -0,0 +1,33 @@ +{ lib +, stdenv +, scons +, clang-tools +, forstio +, pname +, version +, kel +}: + +stdenv.mkDerivation { + pname = pname + "-examples-" + "meta_2d"; + inherit version; + src = ./..; + + nativeBuildInputs = [ + scons + clang-tools + ]; + + buildInputs = [ + forstio.core + forstio.async + forstio.codec + forstio.codec-unit + forstio.codec-json + kel.lbm.core + ]; + + preferLocalBuild = true; + + outputs = [ "out" "dev" ]; +} diff --git a/examples/meta/SConscript b/examples/meta/SConscript new file mode 100644 index 0000000..066a741 --- /dev/null +++ b/examples/meta/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; + +# Cavity2D +examples_objects = []; +examples_env.add_source_files(examples_objects, ['meta.cpp'], shared=False); +examples_env.meta_2d = examples_env.Program('#bin/meta', [examples_objects]); + +# Set Alias +env.examples = [ + examples_env.meta_2d +]; +env.Alias('examples', env.examples); +env.targets += ['examples']; +env.Install('$prefix/bin/', env.examples); diff --git a/examples/meta/SConstruct b/examples/meta/SConstruct new file mode 100644 index 0000000..a7201cb --- /dev/null +++ b/examples/meta/SConstruct @@ -0,0 +1,79 @@ +#!/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' + ] +); +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/meta/meta.cpp b/examples/meta/meta.cpp new file mode 100644 index 0000000..5d3aaa4 --- /dev/null +++ b/examples/meta/meta.cpp @@ -0,0 +1,96 @@ +#include + +#include + +namespace sch { +using namespace saw::schema; + +using MetaArgsStruct = Struct< + Member, + Member, + Member, + Member, + Member +>; + +using MetaArgs = Args< + MetaArgsStruct, + Tuple +>; +} + +template< + +saw::error_or meta_main(int argc, char** argv){ + using namespace kel::lbm; + + std::string_view cfg_file_name = "config.json"; + if(argc > 1){ + cfg_file_name = argv[1]; + } + + saw::data args_dat; + { + saw::data args_enc{argc,argv}; + saw::codec args_codec; + + auto eov = args_codec.decode(args_enc,args_dat); + if(eov.is_error()){ + return eov; + } + + auto& args_str = args_dat.template get<"args">(); + auto& args_pos = args_dat.template get<"positionals">(); + + converter conv{ + {args_str.template get<"delta_x">()}, + {args_str.template get<"delta_t">()} + }; + + switch(args_pos.get<0u>().get()){ + case 1u: + { + } + break; + case 2u: + { + switch(args_pos.get<1u>().get()){ + case 5u: + break; + case 9u: + break; + default: + return saw::make_error("Second positional needs to be a valid velocity set"); + } + } + break; + case 3u: + { + + } + break; + default: + return saw::make_error("First positional needs to be Dimension 1,2 or 3"); + } + print_lbm_meta>(conv, {args_str.template get<"kinematic_viscosity">()},{args_str.template get<"char_vel">()},{args_str.template get<"char_len">()}); + + return saw::make_void(); +} + +int main(int argc, char** argv){ + auto eov = meta_main(argc,argv); + if(eov.is_error()){ + auto& err = eov.get_error(); + + std::cerr<<"[Error]: "< - -#include - -int main(int argc, char** argv){ - using namespace kel::lbm; - - std::string_view cfg_file_name = "config.json"; - if(argc > 1){ - cfg_file_name = argv[1]; - } - - auto eo_conf = load_lbm_config>(cfg_file_name); - if(eo_conf.is_error()){ - auto& err = eo_conf.get_error(); - std::cerr<<"[Error]: "< conv{ - {conf.template get<"delta_x">()}, - {conf.template get<"delta_t">()} - }; - - print_lbm_meta>(conv, {conf.template get<"kinematic_viscosity">()}); - - return 0; -} diff --git a/examples/poiseulle_3d_gpu/sim.cpp b/examples/poiseulle_3d_gpu/sim.cpp index e7294e5..93df1f8 100644 --- a/examples/poiseulle_3d_gpu/sim.cpp +++ b/examples/poiseulle_3d_gpu/sim.cpp @@ -274,7 +274,7 @@ saw::error_or lbm_main(int argc, char** argv){ {{1.0}} }; - print_lbm_meta(conv,{0.1}); + print_lbm_meta(conv,{0.1},{0.01},{1024.0}); auto lbm_data_ptr = saw::heap>>(); auto lbm_macro_data_ptr = saw::heap>>(); diff --git a/examples/poiseulle_particles_2d_gpu/sim.cpp b/examples/poiseulle_particles_2d_gpu/sim.cpp index ae197f9..01fec89 100644 --- a/examples/poiseulle_particles_2d_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_gpu/sim.cpp @@ -316,7 +316,7 @@ saw::error_or lbm_main(int argc, char** argv){ {{1.0}} }; - print_lbm_meta(conv,{0.01}); + print_lbm_meta(conv,{0.01},{0.1},{1024.0}); // saw::data> meta{{dim_x,dim_y}}; auto lbm_data_ptr = saw::heap>>(); diff --git a/lib/core/c++/converter.hpp b/lib/core/c++/converter.hpp index 5c19c68..4370a2c 100644 --- a/lib/core/c++/converter.hpp +++ b/lib/core/c++/converter.hpp @@ -50,6 +50,14 @@ public: return second_conv_*saw::data>{1.0}; } + auto delta_v() const { + return (meter_conv_ / second_conv_) * saw::data>{1.0}; + } + + auto delta_a() const { + return (meter_conv_ / (second_conv_*second_conv_)) * saw::data>{1.0}; + } + saw::data> meter_si_to_lbm(const saw::data>& m_si) const { return m_si / meter_conv_; } diff --git a/lib/core/c++/lbm.hpp b/lib/core/c++/lbm.hpp index 27a7df3..a1e088e 100644 --- a/lib/core/c++/lbm.hpp +++ b/lib/core/c++/lbm.hpp @@ -26,15 +26,33 @@ namespace kel { namespace lbm { template -void print_lbm_meta(const converter& conv, const saw::data>& kin_vis_si){ +void print_lbm_meta( + const converter& conv, + const saw::data>& kin_vis_si, + const saw::data>& char_vel, + const saw::data>& char_len +){ std::cout - <<"[LBM Meta]\n" - <<"==========\n" + <<"[Meta]\n" + <<"======\n" + <<"Re: "<<(char_vel * char_len / kin_vis_si)<<"\n" + <<"Ma: "<<(char_vel * saw::data, sch::SiVelocity>::Schema>{std::sqrt(df_info::inv_cs2)})<<"\n" <<"\n" + <<"[SI]\n" + <<"====\n" <<"Δx: "<, sch::LbmKinematicViscosity>::Schema >{df_info::inv_cs2} * conv.kinematic_viscosity_si_to_lbm(kin_vis_si) + saw::data>{0.5})<<"\n" + <