From c0549d71b2109f10c1238db8b22362e7826ba61b Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 5 Jul 2026 15:59:23 +0200 Subject: Just rename from lib to modules --- lib/core/.nix/derivation.nix | 36 --- lib/core/SConstruct | 75 ----- lib/core/c++/SConscript | 35 --- lib/core/c++/abstract/data.hpp | 52 ---- lib/core/c++/abstract/templates.hpp | 8 - lib/core/c++/args.hpp | 27 -- lib/core/c++/boundary.hpp | 249 ---------------- lib/core/c++/chunk.hpp | 103 ------- lib/core/c++/collision.hpp | 201 ------------- lib/core/c++/common.hpp | 12 - lib/core/c++/component.hpp | 38 --- lib/core/c++/config.hpp | 53 ---- lib/core/c++/converter.hpp | 87 ------ lib/core/c++/descriptor.hpp | 438 ---------------------------- lib/core/c++/dfs.hpp | 9 - lib/core/c++/environment.hpp | 80 ----- lib/core/c++/equilibrium.hpp | 50 ---- lib/core/c++/flatten.hpp | 42 --- lib/core/c++/fplbm.hpp | 191 ------------ lib/core/c++/geometry.hpp | 21 -- lib/core/c++/geometry/poiseulle_channel.hpp | 22 -- lib/core/c++/grid.hpp | 34 --- lib/core/c++/hlbm.hpp | 168 ----------- lib/core/c++/index.hpp | 30 -- lib/core/c++/iterator.hpp | 99 ------- lib/core/c++/lbm.hpp | 65 ----- lib/core/c++/lbm_unit.hpp | 70 ----- lib/core/c++/macroscopic.hpp | 36 --- lib/core/c++/math/math.hpp | 4 - lib/core/c++/math/n_closest.hpp | 54 ---- lib/core/c++/math/n_linear.hpp | 139 --------- lib/core/c++/math/round.hpp | 26 -- lib/core/c++/memory.hpp | 82 ------ lib/core/c++/momentum_gather.hpp | 54 ---- lib/core/c++/particle.hpp | 37 --- lib/core/c++/particle/aabb.hpp | 55 ---- lib/core/c++/particle/blur.hpp | 37 --- lib/core/c++/particle/common.hpp | 3 - lib/core/c++/particle/geometry/circle.hpp | 85 ------ lib/core/c++/particle/geometry/cube.hpp | 22 -- lib/core/c++/particle/particle.hpp | 246 ---------------- lib/core/c++/particle/particle_opa.hpp | 49 ---- lib/core/c++/particle/porosity.hpp | 129 -------- lib/core/c++/particle/schema.hpp | 68 ----- lib/core/c++/psm.hpp | 83 ------ lib/core/c++/rar.hpp | 25 -- lib/core/c++/schema.hpp | 11 - lib/core/c++/simulation/common.hpp | 7 - lib/core/c++/simulation/hlbm.hpp | 12 - lib/core/c++/statistics.hpp | 11 - lib/core/c++/stream.hpp | 61 ---- lib/core/c++/util.hpp | 93 ------ lib/core/c++/write_csv.hpp | 184 ------------ lib/core/c++/write_json.hpp | 27 -- lib/core/c++/write_vtk.hpp | 256 ---------------- lib/core/tests/SConscript | 32 -- lib/core/tests/chunk.cpp | 47 --- lib/core/tests/collision.cpp | 6 - lib/core/tests/converter.cpp | 26 -- lib/core/tests/descriptor.cpp | 39 --- lib/core/tests/equilibrium.cpp | 41 --- lib/core/tests/flatten.cpp | 22 -- lib/core/tests/iterator.cpp | 72 ----- lib/core/tests/math.cpp | 79 ----- lib/core/tests/memory.cpp | 58 ---- lib/core/tests/particles.cpp | 281 ------------------ lib/core/tests/vtk_write.cpp | 93 ------ 67 files changed, 4987 deletions(-) delete mode 100644 lib/core/.nix/derivation.nix delete mode 100644 lib/core/SConstruct delete mode 100644 lib/core/c++/SConscript delete mode 100644 lib/core/c++/abstract/data.hpp delete mode 100644 lib/core/c++/abstract/templates.hpp delete mode 100644 lib/core/c++/args.hpp delete mode 100644 lib/core/c++/boundary.hpp delete mode 100644 lib/core/c++/chunk.hpp delete mode 100644 lib/core/c++/collision.hpp delete mode 100644 lib/core/c++/common.hpp delete mode 100644 lib/core/c++/component.hpp delete mode 100644 lib/core/c++/config.hpp delete mode 100644 lib/core/c++/converter.hpp delete mode 100644 lib/core/c++/descriptor.hpp delete mode 100644 lib/core/c++/dfs.hpp delete mode 100644 lib/core/c++/environment.hpp delete mode 100644 lib/core/c++/equilibrium.hpp delete mode 100644 lib/core/c++/flatten.hpp delete mode 100644 lib/core/c++/fplbm.hpp delete mode 100644 lib/core/c++/geometry.hpp delete mode 100644 lib/core/c++/geometry/poiseulle_channel.hpp delete mode 100644 lib/core/c++/grid.hpp delete mode 100644 lib/core/c++/hlbm.hpp delete mode 100644 lib/core/c++/index.hpp delete mode 100644 lib/core/c++/iterator.hpp delete mode 100644 lib/core/c++/lbm.hpp delete mode 100644 lib/core/c++/lbm_unit.hpp delete mode 100644 lib/core/c++/macroscopic.hpp delete mode 100644 lib/core/c++/math/math.hpp delete mode 100644 lib/core/c++/math/n_closest.hpp delete mode 100644 lib/core/c++/math/n_linear.hpp delete mode 100644 lib/core/c++/math/round.hpp delete mode 100644 lib/core/c++/memory.hpp delete mode 100644 lib/core/c++/momentum_gather.hpp delete mode 100644 lib/core/c++/particle.hpp delete mode 100644 lib/core/c++/particle/aabb.hpp delete mode 100644 lib/core/c++/particle/blur.hpp delete mode 100644 lib/core/c++/particle/common.hpp delete mode 100644 lib/core/c++/particle/geometry/circle.hpp delete mode 100644 lib/core/c++/particle/geometry/cube.hpp delete mode 100644 lib/core/c++/particle/particle.hpp delete mode 100644 lib/core/c++/particle/particle_opa.hpp delete mode 100644 lib/core/c++/particle/porosity.hpp delete mode 100644 lib/core/c++/particle/schema.hpp delete mode 100644 lib/core/c++/psm.hpp delete mode 100644 lib/core/c++/rar.hpp delete mode 100644 lib/core/c++/schema.hpp delete mode 100644 lib/core/c++/simulation/common.hpp delete mode 100644 lib/core/c++/simulation/hlbm.hpp delete mode 100644 lib/core/c++/statistics.hpp delete mode 100644 lib/core/c++/stream.hpp delete mode 100644 lib/core/c++/util.hpp delete mode 100644 lib/core/c++/write_csv.hpp delete mode 100644 lib/core/c++/write_json.hpp delete mode 100644 lib/core/c++/write_vtk.hpp delete mode 100644 lib/core/tests/SConscript delete mode 100644 lib/core/tests/chunk.cpp delete mode 100644 lib/core/tests/collision.cpp delete mode 100644 lib/core/tests/converter.cpp delete mode 100644 lib/core/tests/descriptor.cpp delete mode 100644 lib/core/tests/equilibrium.cpp delete mode 100644 lib/core/tests/flatten.cpp delete mode 100644 lib/core/tests/iterator.cpp delete mode 100644 lib/core/tests/math.cpp delete mode 100644 lib/core/tests/memory.cpp delete mode 100644 lib/core/tests/particles.cpp delete mode 100644 lib/core/tests/vtk_write.cpp (limited to 'lib/core') diff --git a/lib/core/.nix/derivation.nix b/lib/core/.nix/derivation.nix deleted file mode 100644 index 55a414f..0000000 --- a/lib/core/.nix/derivation.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ lib -, stdenv -, scons -, clang-tools -, forstio -, pname -, version -}: - -stdenv.mkDerivation { - inherit pname version; - src = ./..; - - nativeBuildInputs = [ - scons - clang-tools - ]; - - buildInputs = [ - forstio.core - forstio.async - forstio.codec - forstio.codec-unit - forstio.codec-json - ]; - - doCheck = true; - checkPhase = '' - scons test - ./bin/tests - ''; - - preferLocalBuild = true; - - outputs = [ "out" "dev" ]; -} diff --git a/lib/core/SConstruct b/lib/core/SConstruct deleted file mode 100644 index 8b3ab01..0000000 --- a/lib/core/SConstruct +++ /dev/null @@ -1,75 +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=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('c++/SConscript') -SConscript('tests/SConscript') - -env.Alias('cdb', env.cdb); -env.Alias('all', [env.targets]); -env.Default('all'); - -env.Alias('install', '$prefix') diff --git a/lib/core/c++/SConscript b/lib/core/c++/SConscript deleted file mode 100644 index 91f5b3e..0000000 --- a/lib/core/c++/SConscript +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/false - -import os -import os.path -import glob - - -Import('env') - -dir_path = Dir('.').abspath - -# Environment for base library -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")); - -core_env.math_headers = sorted(glob.glob(dir_path + "/math/*.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/', 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); -env.Install('$prefix/include/kel/lbm/math/', core_env.math_headers); diff --git a/lib/core/c++/abstract/data.hpp b/lib/core/c++/abstract/data.hpp deleted file mode 100644 index ed23268..0000000 --- a/lib/core/c++/abstract/data.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "templates.hpp" - -namespace kel { -namespace sch { -struct Void {}; - -struct UnsignedInteger {}; -struct SignedInteger {}; -struct FloatingPoint {}; - -template -struct MixedPrecision { - using Meta = Void; - using StorageType = StorageT; - using InterfaceType = InterfaceT; -}; - -template -struct Primitive { - using Meta = Void; - using Type = PrimType; - static constexpr uint64_t Bytes = N; -}; - -template -struct FixedArray { - using Meta = Void; - using Inner = T; - static constexpr std::array Dimensions{Dims...}; -}; - -template -struct Array { - using Meta = FixedArray; - using Inner = T; - static constexpr std::array Dimensions{Dims}; -}; - -template -struct Tuple { -}; - -} - -template -struct schema { - using Type = Sch; -}; - -} diff --git a/lib/core/c++/abstract/templates.hpp b/lib/core/c++/abstract/templates.hpp deleted file mode 100644 index d9d9faa..0000000 --- a/lib/core/c++/abstract/templates.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace kel { -namespace lbm { -template -constexpr bool always_false = false; -} -} diff --git a/lib/core/c++/args.hpp b/lib/core/c++/args.hpp deleted file mode 100644 index a0aa941..0000000 --- a/lib/core/c++/args.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -#include - -namespace kel { -namespace lbm { -namespace sch { -using namespace saw::schema; -} - -template -saw::error_or> setup_lbm_env(int argc, char** argv){ - saw::data args_data{argc,argv}; - - saw::codec args_codec; - - saw::data args_decoded; - auto eov = args_codec.decode(args_data,args_decoded); - if(eov.is_error()){ - return eov; - } - - return args_decoded; -} -} -} diff --git a/lib/core/c++/boundary.hpp b/lib/core/c++/boundary.hpp deleted file mode 100644 index 01ae7b5..0000000 --- a/lib/core/c++/boundary.hpp +++ /dev/null @@ -1,249 +0,0 @@ -#pragma once - -#include "component.hpp" -#include "equilibrium.hpp" - -namespace kel { -namespace lbm { -namespace cmpt { -struct BounceBack {}; - -template -struct AntiBounceBack {}; - -template -struct ZouHeHorizontal{}; - -struct Equilibrium {}; - -template -struct ZouHePressureY{}; - -template -struct ZouHeVelocityX {}; -} - -/** - * Full-Way BounceBack. - */ -template -class component { -private: -public: - component() = default; - - using Component = cmpt::BounceBack; - - /** - * Thoughts regarding automating order setup - */ - using access = cmpt::access_tuple< - cmpt::access<"dfs", 1, true, true, true> - >; - - /** - * Thoughts regarding automating order setup - */ - static constexpr saw::string_literal name = "full_way_bounce_back"; - static constexpr saw::string_literal after = ""; - static constexpr saw::string_literal before = "streaming"; - - /** - * Raw setup - */ - template - void apply(const saw::data& field, const saw::data>& index, saw::data time_step)const{ - bool is_even = ((time_step.get() % 2u) == 0u); - - // This is a ref - - // auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - - using dfi = df_info; - - // Technically use .copy() - auto& dfs_old = dfs_old_f.at(index); - auto df_cpy = dfs_old; - - for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - dfs_old.at({i}) = df_cpy.at({dfi::opposite_index.at(i)}); - } - } -}; - -/** - * Anti Full-Way BounceBack. - */ -template -class component, Encode> { -private: -public: - component() = default; - - using Component = cmpt::AntiBounceBack; - - /** - * Thoughts regarding automating order setup - */ - using access = cmpt::access_tuple< - cmpt::access<"dfs", 1, true, true, true> - >; - - /** - * Thoughts regarding automating order setup - */ - static constexpr saw::string_literal name = "full_way_anti_bounce_back"; - static constexpr saw::string_literal after = ""; - static constexpr saw::string_literal before = "streaming"; - - /** - * Raw setup - */ - template - void apply(const saw::data& field, const saw::data>& index, saw::data time_step)const{ - bool is_even = ((time_step.get() % 2u) == 0u); - - // This is a ref - - // auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - - using dfi = df_info; - - // Technically use .copy() - auto& dfs_old = dfs_old_f.at(index); - auto df_cpy = dfs_old; - - static_assert(Descriptor::D == 2u and Descriptor::Q == 9u, "Some parts are hard coded sadly"); - - dfs_old.at({0u}) = df_cpy.at({0u}); - dfs_old.at({1u}) = df_cpy.at({1u}); - dfs_old.at({2u}) = df_cpy.at({2u}); - dfs_old.at({3u}) = df_cpy.at({4u}); - dfs_old.at({4u}) = df_cpy.at({3u}); - dfs_old.at({5u}) = df_cpy.at({7u}); - dfs_old.at({6u}) = df_cpy.at({8u}); - dfs_old.at({7u}) = df_cpy.at({5u}); - dfs_old.at({8u}) = df_cpy.at({6u}); - } -}; - -template -class component final { -private: - saw::data> density_; - saw::data> velocity_; -public: - component( - saw::data> density__, - saw::data> velocity__ - ): - density_{density__}, - velocity_{velocity__} - {} - - template - void apply(const saw::data& field, const saw::data>& index, saw::data time_step) const { - - bool is_even = ((time_step.get() % 2u) == 0u); - using dfi = df_info; - - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - - auto eq = equilibrium(density_,velocity_); - - dfs_old_f.at(index) = eq; - } -}; - -/** - * This is massively hacky and expects a lot of conditions - * Either this or mirrored along the horizontal line works - * - * 0 - 2 - 2 - * 0 - 3 - 1 - * 0 - 3 - 1 - * ......... - * 0 - 3 - 1 - * 0 - 2 - 2 - * - */ -template -class component, Encode> final { -private: - saw::data rho_setting_; -public: - component(const saw::data& rho_setting__): - rho_setting_{rho_setting__} - {} - - template - void apply(const saw::data& field, saw::data> index, saw::data time_step) const { - using dfi = df_info; - - bool is_even = ((time_step.get() % 2) == 0); - - auto& info_f = field.template get<"info">(); - - // auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - - auto& dfs_old = dfs_old_f.at(index); - - auto rho_vel_x = [&]() -> saw::data { - if constexpr (Dir){ - auto S = dfs_old.at({0u}) - + dfs_old.at({3u}) + dfs_old.at({4u}) - + (dfs_old.at({1u}) + dfs_old.at({5u}) + dfs_old.at({7u})) * 2u; - return rho_setting_ - S; - } - else if constexpr (not Dir) { - auto S = dfs_old.at({0u}) - + dfs_old.at({3u}) + dfs_old.at({4u}) - + (dfs_old.at({2u}) + dfs_old.at({6u}) + dfs_old.at({8u})) * 2u; - return S - rho_setting_; - } - return {}; - }(); - - static_assert(Descriptor::D == 2u and Descriptor::Q == 9u, "Some parts are hard coded sadly"); - - if constexpr (Dir) { - dfs_old.at({2u}) = dfs_old.at({1u}) + saw::data{2.0 / 3.0} * rho_vel_x; - dfs_old.at({6u}) = dfs_old.at({5u}) + saw::data{1.0 / 6.0} * rho_vel_x + saw::data{0.5} * (dfs_old.at({3u}) - dfs_old.at({4u})); - dfs_old.at({8u}) = dfs_old.at({7u}) + saw::data{1.0 / 6.0} * rho_vel_x + saw::data{0.5} * (dfs_old.at({4u}) - dfs_old.at({3u})); - }else if constexpr (not Dir){ - dfs_old.at({1u}) = dfs_old.at({2u}) - saw::data{2.0 / 3.0} * rho_vel_x; - dfs_old.at({5u}) = dfs_old.at({6u}) - saw::data{1.0 / 6.0} * rho_vel_x + saw::data{0.5} * (dfs_old.at({4u}) - dfs_old.at({3u})); - dfs_old.at({7u}) = dfs_old.at({8u}) - saw::data{1.0 / 6.0} * rho_vel_x + saw::data{0.5} * (dfs_old.at({3u}) - dfs_old.at({4u})); - } - } -}; - -/* -template -class component, Encode> final { -private: - saw::data> velocity_; -public: - component( - saw::data> velocity__ - ): - velocity_{velocity__} - {} - - template - void apply(const saw::data& field, const saw::data>& index, saw::data time_step) const { - - bool is_even = ((time_step.get() % 2u) == 0u); - using dfi = df_info; - - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - - } -}; -*/ - -} -} diff --git a/lib/core/c++/chunk.hpp b/lib/core/c++/chunk.hpp deleted file mode 100644 index 635af91..0000000 --- a/lib/core/c++/chunk.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -#include "common.hpp" -#include "flatten.hpp" - -namespace kel { -namespace lbm { -namespace sch { -namespace impl { -template> -struct chunk_schema_type_helper; - -template -struct chunk_schema_type_helper, saw::tmpl_value_group> final { - using Schema = typename chunk_schema_type_helper, saw::tmpl_value_group>::Schema; -}; - -template -struct chunk_schema_type_helper, saw::tmpl_value_group> final { - using Schema = FixedArray; -}; -} - - -template -struct Chunk { - using InnerSchema = typename impl::chunk_schema_type_helper>::Schema; - using StoredValueSchema = Sch; -}; - -// Not needed for now -template -using SuperChunk = Array; -} -} -} - -namespace saw { - -template -class data,Encode> final { -public: - using Schema = kel::lbm::sch::Chunk; -private: - using InnerSchema = typename Schema::InnerSchema; - using ValueSchema = typename InnerSchema::ValueType; - - data values_; -public: - data& ghost_at(const data>& index){ - return values_.at(index); - } - - const data& ghost_at(const data>& index) const { - return values_.at(index); - } - - static constexpr auto get_ghost_dims() { - return data::get_dims(); - } - - static constexpr auto to_ghost_index(const data>& index){ - std::decay_t ind; - for(uint64_t i = 0u; i < sizeof...(Sides); ++i){ - ind.at({i}) = index.at({i}) + Ghost; - } - return ind; - } - - data& at(const data>& index){ - std::decay_t ind = to_ghost_index(index); - return values_.at(ind); - } - - const data& at(const data>& index) const { - std::decay_t ind = to_ghost_index(index); - return values_.at(ind); - } - - /* - const data& neighbour_at(const data>& index) const { - } - */ - - static constexpr auto get_dims(){ - return data,Encode>{{Sides...}}; - } - - auto flat_data(){ - return values_.flat_data(); - } - - static constexpr auto flat_size() { - return data::flat_dims(); - } -}; - -template -struct meta_schema> { - using MetaSchema = typename meta_schema::MetaSchema; -}; - -} diff --git a/lib/core/c++/collision.hpp b/lib/core/c++/collision.hpp deleted file mode 100644 index 023f61f..0000000 --- a/lib/core/c++/collision.hpp +++ /dev/null @@ -1,201 +0,0 @@ -#pragma once - -#include "macroscopic.hpp" -#include "component.hpp" -#include "equilibrium.hpp" -#include "chunk.hpp" - -namespace kel { -namespace lbm { -namespace cmpt { -struct BGK {}; -struct BGKGuo {}; -} - -/** - * Standard BGK collision operator for LBM - */ -template -class component { -private: - saw::data relaxation_; - saw::data frequency_; -public: - component(typename saw::native_data_type::type relaxation__): - relaxation_{{relaxation__}}, - frequency_{saw::data{1} / relaxation_} - {} - - component(const saw::data& relaxation__): - relaxation_{relaxation__}, - frequency_{saw::data{1} / relaxation_} - {} - - using Component = cmpt::BGK; - - /** - * Thoughts regarding automating order setup - */ - using access = cmpt::access_tuple< - cmpt::access<"dfs", 1, true, true, true> - >; - - /** - * Thoughts regarding automating order setup - */ - static constexpr saw::string_literal name = "collision"; - static constexpr saw::string_literal after = ""; - static constexpr saw::string_literal before = "streaming"; - - /** - * Raw setup - */ - template - void apply(const saw::data& field, saw::data> index, saw::data time_step) const { - bool is_even = ((time_step.get() % 2) == 0); - - // auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - - saw::data> rho; - saw::data> vel; - compute_rho_u(dfs_old_f.at(index),rho,vel); - auto eq = equilibrium(rho,vel); - - for(uint64_t i = 0u; i < Descriptor::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})); - } - } - - template - void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { - bool is_even = ((time_step.get() % 2) == 0); - - // auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - - auto& rho_f = macros.template get<"density">(); - auto& vel_f = macros.template get<"velocity">(); - - saw::data>& rho = rho_f.at(index); - saw::data>& vel = vel_f.at(index); - - compute_rho_u(dfs_old_f.at(index),rho,vel); - - auto eq = equilibrium(rho,vel); - - for(uint64_t i = 0u; i < Descriptor::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})); - } - } -}; - -template -class component { -private: - typename saw::native_data_type::type relaxation_; - saw::data frequency_; - saw::data> global_force_; -public: - component(typename saw::native_data_type::type relaxation__): - relaxation_{relaxation__}, - frequency_{typename saw::native_data_type::type(1) / relaxation_}, - global_force_{} - {} - - component( - typename saw::native_data_type::type relaxation__, - saw::data>& global_force__ - ): - relaxation_{relaxation__}, - frequency_{typename saw::native_data_type::type(1) / relaxation_}, - global_force_{global_force__} - {} - - using Component = cmpt::BGKGuo; - - using access = cmpt::access_tuple< - cmpt::access<"dfs", 1, true, true, true>, - cmpt::access<"force", 0, true, false> - >; - - /** - * Thoughts regarding automating order setup - */ - static constexpr saw::string_literal name = "collision"; - static constexpr saw::string_literal after = ""; - static constexpr saw::string_literal before = "streaming"; - - template - void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { - // void apply(saw::data& field, saw::data> index, saw::data time_step){ - bool is_even = ((time_step.get() % 2) == 0); - - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - auto& dfs = dfs_old_f.at(index); - - auto& rho_f = macros.template get<"density">(); - auto& vel_f = macros.template get<"velocity">(); - - saw::data>& rho = rho_f.at(index); - - auto& force_f = macros.template get<"force">(); - auto& force = force_f.at(index); - - auto total_force = force + global_force_; - - saw::data> half; - half.at({}).set(0.5); - auto& vel = vel_f.at(index); - vel = vel + total_force * ( half / rho ); - - compute_rho_u(dfs_old_f.at(index),rho,vel); - auto eq = equilibrium(rho,vel); - - using dfi = df_info; - - - saw::data> dfi_inv_cs2; - dfi_inv_cs2.at({}).set(dfi::inv_cs2); - - - // auto vel = vel_f.at(index); - - for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - // saw::data ci_min_u{0}; - saw::data> ci; - for(uint64_t d = 0u; d < Descriptor::D; ++d){ - ci.at({{d}}).set(static_cast::type>(dfi::directions[i][d])); - } - auto ci_dot_u = saw::math::dot(ci,vel); - - // saw::data> F_i; - // F_i = f * ((c_i - u) * ics2 + * c_i * ics2 * ics2) * w_i; - saw::data> w; - w.at({}).set(dfi::weights[i]); - - /* - saw::data> F_i_sum; - for(uint64_t d = 0u; d < Descriptor::D; ++d){ - saw::data> F_i_d; - F_i_d.at({}) = F_i.at({{d}}); - F_i_sum = F_i_sum + F_i_d; - } - */ - auto term1 = (ci-vel) * dfi_inv_cs2; - auto term2 = ci * (ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2); - - auto force_projection = saw::math::dot(term1 + term2, total_force); - - auto F_i = w * force_projection; - - dfs.at({i}) = dfs.at({i}) - + frequency_ - * (eq.at(i) - dfs.at({i}) ) - + F_i.at({}) - * (saw::data{1} - saw::data{0.5f} * frequency_); - } - } -}; -} -} diff --git a/lib/core/c++/common.hpp b/lib/core/c++/common.hpp deleted file mode 100644 index 280d953..0000000 --- a/lib/core/c++/common.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -namespace kel { -namespace lbm { -namespace sch { -using namespace saw::schema; -} -} -} diff --git a/lib/core/c++/component.hpp b/lib/core/c++/component.hpp deleted file mode 100644 index 1e5dbbf..0000000 --- a/lib/core/c++/component.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include "descriptor.hpp" - -namespace kel { -namespace lbm { - -namespace cmpt { - -/** - * Maybe for the future - */ -template -class access { -public: - static constexpr saw::string_literal name = Name; - static constexpr uint64_t distance = Dist; - static constexpr bool read = Read; - static constexpr bool write = Write; - static constexpr bool skip_sync = SkipSync; -}; - -/** - * Maybe for the future - */ -template -class access_tuple { -public: -}; -} - -/** - * Component class which forms the basis of each processing step - */ -template -class component {}; -} -} diff --git a/lib/core/c++/config.hpp b/lib/core/c++/config.hpp deleted file mode 100644 index 64f7a0f..0000000 --- a/lib/core/c++/config.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include -#include - -namespace kel { -namespace lbm { -namespace sch { -using namespace saw::schema; -template -using LbmConfig = Struct< - Member, - Member, - Member ->; -} - -template -saw::error_or>> load_lbm_config(std::string_view file_name){ - std::ifstream file{std::string{file_name}}; - - if(!file.is_open()){ - return saw::make_error("Couldn't open file"); - } - - saw::data, saw::encode::Json> lbm_json_conf{saw::heap(1u)}; - - uint8_t ele{}; - while(file.readsome(reinterpret_cast(&ele), 1u) > 0u){ - auto err = lbm_json_conf.get_buffer().push(ele,1u); - if(err.failed()){ - return err; - } - } - - saw::data> lbm_conf; - saw::codec, saw::encode::Json> json_codec; - { - auto eov = json_codec.decode(lbm_json_conf, lbm_conf); - if(eov.is_error()){ - return std::move(eov.get_error()); - } - } - - return lbm_conf; -} -} -} diff --git a/lib/core/c++/converter.hpp b/lib/core/c++/converter.hpp deleted file mode 100644 index 4370a2c..0000000 --- a/lib/core/c++/converter.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once - -#include "lbm_unit.hpp" -#include "descriptor.hpp" - -namespace kel { -namespace lbm { - -namespace sch { -using namespace saw::schema; -} - -/** - * Helps converting from SI types to LBM types - */ -template -class converter { -private: - saw::data, sch::LbmMeter >::Schema > meter_conv_; - saw::data, sch::LbmSecond >::Schema > second_conv_; -public: - converter() = delete; - converter( - saw::data, sch::LbmMeter >::Schema > meter_conv__, - saw::data, sch::LbmSecond >::Schema > second_conv__ - ): - meter_conv_{meter_conv__}, - second_conv_{second_conv__} - {} - - /** - * Get the conversion parameter with the conversion type - */ - auto conversion_x() const { - return meter_conv_; - } - - /** - * Get the conversion parameter with the conversion type - */ - auto conversion_t() const { - return second_conv_; - } - - auto delta_x() const { - return meter_conv_*saw::data>{1.0}; - } - - auto delta_t() const { - 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_; - } - - saw::data> second_si_to_lbm(const saw::data>& s_si) const { - return s_si / second_conv_; - } - - saw::data> velocity_si_to_lbm(const saw::data>& vel_si) const { - return vel_si * second_conv_ / meter_conv_; - } - - saw::data> acceleration_si_to_lbm(const saw::data>& acc_si) const { - return acc_si * (second_conv_ * second_conv_) / meter_conv_; - } - - saw::data> kinematic_viscosity_si_to_lbm (const saw::data>& kin_si) const { - return (kin_si / (meter_conv_ * meter_conv_)) * second_conv_; - } - - template - saw::data> kinematic_viscosity_si_to_tau(const saw::data>& kin_si) const { - return saw::data>{saw::data, sch::LbmKinematicViscosity>::Schema >{df_info::inv_cs2} * kinematic_viscosity_si_to_lbm(kin_si) + saw::data>{0.5}}; - } -}; -} -} diff --git a/lib/core/c++/descriptor.hpp b/lib/core/c++/descriptor.hpp deleted file mode 100644 index 9f7399a..0000000 --- a/lib/core/c++/descriptor.hpp +++ /dev/null @@ -1,438 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace kel { -namespace lbm { -namespace sch { -using namespace saw::schema; - -template -struct Descriptor { - static constexpr uint64_t D = DV; - static constexpr uint64_t Q = QV; -}; - -using D2Q9 = Descriptor<2u,9u>; -//using D2Q5 = Descriptor<2u,5u>; -using D3Q27 = Descriptor<3u,27u>; - -template -struct Cell { - using Descriptor = Desc; - static constexpr uint64_t SC = SC_V; - static constexpr uint64_t DC = DC_V; - static constexpr uint64_t QC = QC_V; - static constexpr uint64_t Size = SC + Desc::D * DC + Desc::Q * QC; -}; - -template -struct CellField{ - using Descriptor = Desc; -}; - -template -struct CellField< - Desc, - Struct< - Member... - > -> { - using Descriptor = Desc; -}; - -template -struct CellFieldStruct { - using Descriptor = Desc; - // using MetaSchema = FixedArray; -}; - -} - -template -class df_info{}; - -/* -namespace impl { -template -struct df_ct_helper { - template - static constexpr uint64_t apply_i(const std::array,Desc::Q>& dirs, const std::array& inp){ - if constexpr ( i < Desc::Q ){ - for(uint64_t j = 0u; j < Desc::D; ++j){ - } - } - return 0u; - } -}; -} -*/ - -template -class df_info> { -public: - using Descriptor = sch::Descriptor<1,3>; - - static constexpr uint64_t D = 1u; - static constexpr uint64_t Q = 3u; - - static constexpr std::array,Q> directions = {{ - { 0}, - {-1}, - { 1} - }}; - - static constexpr std::array::type, Q> weights = { - 2./3., - 1./6., - 1./6. - }; - - static constexpr std::array opposite_index = { - 0,2,1 - }; - - static constexpr typename saw::native_data_type::type inv_cs2 = 3.0; - static constexpr typename saw::native_data_type::type cs2 = 1./3.; -}; - -/** - * D2Q5 Descriptor - */ -template -class df_info> { -public: - using Descriptor = sch::Descriptor<2,5>; - - static constexpr uint64_t D = 2u; - static constexpr uint64_t Q = 5u; - - static constexpr std::array, Q> directions = {{ - { 0, 0}, - {-1, 0}, - { 1, 0}, - { 0,-1}, - { 0, 1}, - }}; - - static constexpr std::array::type,Q> weights = { - 1./3., - 1./6., - 1./6., - 1./6., - 1./6. - }; - - static constexpr std::array opposite_index = { - 0, - 2, - 1, - 4, - 3 - }; - - static constexpr typename saw::native_data_type::type inv_cs2 = 3.0; - static constexpr typename saw::native_data_type::type cs2 = 1./3.; -}; - -template -class df_info> { -public: - using Descriptor = sch::Descriptor<2,9>; - - static constexpr uint64_t D = 2u; - static constexpr uint64_t Q = 9u; - - static constexpr std::array, Q> directions = {{ - { 0, 0}, // 0 - {-1, 0}, // 1 - { 1, 0}, // 2 - { 0,-1}, // 3 - { 0, 1}, // 4 - {-1,-1}, // 5 - { 1, 1}, // 6 - {-1, 1}, // 7 - { 1,-1} // 8 - }}; - - static constexpr std::array::type,Q> weights = { - 4./9., - 1./9., - 1./9., - 1./9., - 1./9., - 1./36., - 1./36., - 1./36., - 1./36. - }; - - static constexpr std::array opposite_index = { - 0, - 2, - 1, - 4, - 3, - 6, - 5, - 8, - 7 - }; - - static constexpr typename saw::native_data_type::type inv_cs2 = 3.0; - static constexpr typename saw::native_data_type::type cs2 = 1./3.; -}; - - -template -class df_info> { -public: - using Descriptor = sch::Descriptor<3,27>; - - static constexpr uint64_t D = 3u; - static constexpr uint64_t Q = 27u; - - static constexpr std::array, Q> directions = {{ - { 0, 0, 0}, // 0 - // Into 1D - {-1, 0, 0}, // 1 - { 1, 0, 0}, // 2 - // Expand into 2D - { 0, -1, 0}, // 3 - {-1, -1, 0}, // 4 - { 1, -1, 0}, // 5 - { 0, 1, 0}, // 6 - {-1, 1, 0}, // 7 - { 1, 1, 0}, // 8 - // Expand into 3D - { 0, 0, -1}, // 9 - {-1, 0, -1}, // 10 - { 1, 0, -1}, // 11 - { 0, -1, -1},// 12 - {-1, -1, -1},// 13 - { 1, -1, -1},// 14 - { 0, 1, -1}, // 15 - {-1, 1, -1}, // 16 - { 1, 1, -1}, // 17 - { 0, 0, 1}, // 18 - {-1, 0, 1}, // 19 - { 1, 0, 1}, // 20 - { 0, -1, 1}, // 21 - {-1, -1, 1}, // 22 - { 1, -1, 1}, // 23 - { 0, 1, 1}, // 24 - {-1, 1, 1}, // 25 - { 1, 1, 1} // 26 - }}; - - static constexpr std::array::type,Q> weights = { - 8./27., - // 1D - 1./36., - 1./36., - // 2D - 1./36., - 1./54., - 1./54., - 1./36., - 1./54., - 1./54., - // 3D - 1./36., - 1./54., - 1./54., - 1./54., - 1./216., - 1./216., - 1./54., - 1./216., - 1./216., - 1./36., - 1./54., - 1./54., - 1./54., - 1./216., - 1./216., - 1./54., - 1./216., - 1./216. - }; - - static constexpr std::array opposite_index = { - 0,2,1, - 6,8,7,3,5,4, - 18,20,19,24,26,25,21,23,22,9,11,10,15,17,16,12,14,13 - }; - - static constexpr typename saw::native_data_type::type inv_cs2 = 3.0; - static constexpr typename saw::native_data_type::type cs2 = 1./3.; -}; - - -template -class cell_schema_builder { -private: - saw::schema_factory factory_struct_; -public: - cell_schema_builder() = default; - - cell_schema_builder(saw::schema_factory inp): - factory_struct_{inp} - {} - - /* - template - constexpr auto require() const noexcept { - return {factory_struct_.add_maybe()}; - } - */ -}; - -} -} - -namespace saw { -template -struct meta_schema> { - using MetaSchema = schema::Void; - using Schema = kel::lbm::sch::Cell; -}; - -template -struct meta_schema> { - using MetaSchema = schema::FixedArray; - using Schema = kel::lbm::sch::CellField; -}; - -template -struct meta_schema>> { - using MetaSchema = schema::FixedArray; - using Schema = kel::lbm::sch::CellFieldStruct>; -}; - -template -class data, Encode> final { -public: - using Schema = kel::lbm::sch::Cell; - using MetaSchema = typename meta_schema::MetaSchema; -private: - data, Encode> inner_; -public: - data() = default; - - data& operator()(const data& index){ - return inner_.at(index); - } - - const data& operator()(const data& index)const{ - return inner_.at(index); - } - - const data, Encode> copy() const { - return *this; - } -}; - -/* - * Create a cellfield - */ -template -class data, Encode> final { -public: - using Schema = kel::lbm::sch::CellField; - using MetaSchema = typename meta_schema::MetaSchema; -private: - data, Encode> inner_; -public: - data() = default; - data(const data& inner_meta__): - inner_{inner_meta__} - {} - - const data meta() const { - return inner_.dims(); - } - - template - data get_dim_size() const { - static_assert(i < Desc::D, "Not enough dimensions"); - return inner_.template get_dim_size(); - } - - const data& operator()(const data, Encode>& index)const{ - return inner_.at(index); - } - - data& operator()(const data, Encode>& index){ - return inner_.at(index); - } - - const data& at(const data, Encode>& index)const{ - return inner_.at(index); - } - - data& at(const data, Encode>& index){ - return inner_.at(index); - } - - data internal_size() const { - return inner_.internal_size(); - } - - data* internal_data() { - return inner_.internal_data(); - } -}; - -/** - * Is basically a struct, but additionally has members for meta() calls. It technically is a Field of a struct, but organized through a struct of fields. - */ -template -class data>, Encode> final { -public: - using Schema = kel::lbm::sch::CellFieldStruct>; - /// @TODO Add MetaSchema to Schema - using MetaSchema = typename meta_schema::MetaSchema; -private: - static_assert(sizeof...(CellFieldsT) > 0u, ""); - data, Encode> inner_; - - template - saw::error_or helper_constructor(const data>& grid_size){ - using MemT = saw::parameter_pack_type::type; - { - inner_.template get() = {grid_size}; - } - if constexpr (sizeof...(CellFieldsT) > (i+1u)){ - return helper_constructor(grid_size); - } - return saw::make_void(); - } -public: - data() = delete; - - data(const data>& grid_size__){ - auto eov = helper_constructor<0u>(grid_size__); - (void)eov; - } - - const data meta() const { - using MemT = saw::parameter_pack_type<0u,CellFieldsT...>::type; - return inner_.template get().meta(); - } - - template - auto& get() { - return inner_.template get(); - } - - template - const auto& get() const { - return inner_.template get(); - } -}; - - -} diff --git a/lib/core/c++/dfs.hpp b/lib/core/c++/dfs.hpp deleted file mode 100644 index 175e9f2..0000000 --- a/lib/core/c++/dfs.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "common.hpp" - -namespace kel { -namespace lbm { -// Make a view class which handles the AA push pull pattern, or alternatively the esoteric twist -} -} diff --git a/lib/core/c++/environment.hpp b/lib/core/c++/environment.hpp deleted file mode 100644 index d8aa9ae..0000000 --- a/lib/core/c++/environment.hpp +++ /dev/null @@ -1,80 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace kel { -namespace lbm { - -struct environment { - std::string name; - - std::filesystem::path lbm_dir; - std::filesystem::path data_dir; -}; - -saw::error_or setup_lbm_env(const std::string_view name){ - namespace fs = std::filesystem; - - const char* home_dir = std::getenv("HOME"); - if(not home_dir){ - return saw::make_error("Couldn't find home dir"); - } - - environment env; - - env.lbm_dir = std::filesystem::path{home_dir} / ".lbm"; - - { - // Set default data location to "${lbm_dir}/data" - env.data_dir = env.lbm_dir / "data"; - // LBM Data Location - auto lbm_dir_config = env.lbm_dir / "data_dir_location.txt"; - if( fs::exists(lbm_dir_config) && fs::is_regular_file(lbm_dir_config) ){ - std::ifstream file{lbm_dir_config}; - - if(file.is_open()){ - std::stringstream buffer; - buffer < output_directory(){ - namespace fs = std::filesystem; - - const char* home_dir = std::getenv("HOME"); - if(not home_dir){ - return saw::make_error("Couldn't find home dir"); - } - - auto lbm_dir = std::filesystem::path{home_dir} / ".lbm"; - - { - auto lbm_dir_config = lbm_dir / "data_dir_location.txt"; - if( fs::exists(lbm_dir_config) && fs::is_regular_file(lbm_dir_config) ){ - std::ifstream file{lbm_dir_config}; - - if(file.is_open()){ - std::stringstream buffer; - buffer < -saw::data> equilibrium(saw::data> rho, saw::data> vel){ - using dfi = df_info; - - saw::data> eq; - // Brain broken, here's an owl - // ^ - // 0.0 - // / \ - // | | - // - // Velocity * Velocity meaning || vel ||_2^2 or _2 - saw::data vel_vel{0.0}; - for(uint64_t j = 0u; j < Descriptor::D; ++j){ - vel_vel = vel_vel + vel.at({{j}}) * vel.at({{j}}); - } - - /** - * Calculate equilibrium - */ - for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - saw::data vel_c{}; - for(uint64_t j = 0u; j < Descriptor::D; ++j){ - // _2 - vel_c = vel_c + (vel.at({{j}}) * saw::data{static_cast::type>(dfi::directions[i][j])}); - } - - auto vel_c_cs2 = vel_c * saw::data{dfi::inv_cs2}; - - eq.at(i).set( - dfi::weights[i] * rho.at({}).get() * - ( - 1.0 - + vel_c_cs2.get() - - dfi::inv_cs2 * 0.5 * vel_vel.get() - + vel_c_cs2.get() * vel_c_cs2.get() * 0.5 - ) - ); - } - - return eq; -} -} -} diff --git a/lib/core/c++/flatten.hpp b/lib/core/c++/flatten.hpp deleted file mode 100644 index 1609589..0000000 --- a/lib/core/c++/flatten.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include - -namespace kel { -namespace lbm { -namespace sch { -using namespace saw::schema; -} - -template -struct flatten_index { -public: - template - static constexpr saw::data stride(const saw::data>& meta) { - if constexpr (i > 0u){ - return stride(meta) * meta.at({i-1u}); - } - - return 1u; - } -private: - /// 2,3,4 => 2,6,24 - /// i + j * 2 + k * 3*2 - /// 1 + 2 * 2 + 3 * 3*2 = 1+4+18 = 23 - template - static void apply_i(saw::data& flat_ind, const saw::data>& index, const saw::data>& meta){ - if constexpr ( D > i ) { - flat_ind = flat_ind + index.at({i}) * stride(meta); - apply_i(flat_ind,index,meta); - } - } -public: - static saw::data apply(const saw::data>& index, const saw::data>& meta){ - saw::data flat_ind{0u}; - apply_i<0u>(flat_ind, index, meta); - return flat_ind; - } -}; -} -} diff --git a/lib/core/c++/fplbm.hpp b/lib/core/c++/fplbm.hpp deleted file mode 100644 index c974472..0000000 --- a/lib/core/c++/fplbm.hpp +++ /dev/null @@ -1,191 +0,0 @@ -#pragma once - -#include "common.hpp" - -namespace kel { -namespace lbm { -namespace cmpt { -struct FpLbm {}; -struct FpLbmOneParticleNoVelocity{}; -} - -template -class component final { -private: - saw::data relaxation_; - saw::data frequency_; -public: - component(typename saw::native_data_type::type relaxation__): - relaxation_{{relaxation__}}, - frequency_{saw::data{1} / relaxation_} - {} - - component(const saw::data& relaxation__): - relaxation_{relaxation__}, - frequency_{saw::data{1} / relaxation_} - {} - - using Component = cmpt::FpLbm; - - - template - void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { - // void apply(saw::data& field, saw::data> index, saw::data time_step){ - bool is_even = ((time_step.get() % 2) == 0); - - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - auto& dfs = dfs_old_f.at(index); - - auto& rho_f = macros.template get<"density">(); - auto& vel_f = macros.template get<"velocity">(); - - saw::data>& rho = rho_f.at(index); - saw::data>& vel = vel_f.at(index); - - compute_rho_u(dfs_old_f.at(index),rho,vel); - auto eq = equilibrium(rho,vel); - - using dfi = df_info; - - auto& force_f = macros.template get<"force">(); - auto& force = force_f.at(index); - - auto& porosity_f = macros.template get<"porosity">(); - auto& porosity = porosity_f.at(index); - - saw::data> dfi_inv_cs2; - dfi_inv_cs2.at({}).set(dfi::inv_cs2); - - for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - // saw::data ci_min_u{0}; - saw::data> ci; - for(uint64_t d = 0u; d < Descriptor::D; ++d){ - ci.at({{d}}).set(static_cast::type>(dfi::directions[i][d])); - } - auto ci_dot_u = saw::math::dot(ci,vel); - - // saw::data> F_i; - // F_i = f * (c_i - u * ics2 + * c_i * ics2 * ics2) * w_i; - saw::data> w; - w.at({}).set(dfi::weights[i]); - - auto F_i_d = saw::math::dot(force * w, (ci - vel * dfi_inv_cs2 + ci * ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2 )); - /* - saw::data> F_i_sum; - for(uint64_t d = 0u; d < Descriptor::D; ++d){ - saw::data> F_i_d; - F_i_d.at({}) = F_i.at({{d}}); - F_i_sum = F_i_sum + F_i_d; - } - */ - - dfs.at({i}) = dfs.at({i}) + frequency_ * (eq.at(i) - dfs.at({i}) ) + F_i_d.at({}) * (saw::data{1} - saw::data{0.5f} * frequency_); - } - } -}; - -template -class component final { -private: - saw::data relaxation_; - saw::data frequency_; -public: - component(typename saw::native_data_type::type relaxation__): - relaxation_{{relaxation__}}, - frequency_{saw::data{1} / relaxation_} - {} - - component(const saw::data& relaxation__): - relaxation_{relaxation__}, - frequency_{saw::data{1} / relaxation_} - {} - - using Component = cmpt::FpLbmOneParticleNoVelocity; - - template - void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { - // void apply(saw::data& field, saw::data> index, saw::data time_step){ - bool is_even = ((time_step.get() % 2) == 0); - - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - auto& dfs = dfs_old_f.at(index); - - auto& rho_f = macros.template get<"density">(); - auto& vel_f = macros.template get<"velocity">(); - auto& por_f = macros.template get<"porosity">(); - - // Temporary find a better way - auto& force_f = macros.template get<"force">(); - - - /** - * The other methods all work with a flipped porosity. - * For compat reasons this is also flipped - */ - auto porosity = por_f.at(index); - saw::data> one; - one.at({}) = 1.0; - auto flip_porosity = one - porosity; - - saw::data>& rho = rho_f.at(index); - - saw::data> half; - half.at({}).set(0.5); - saw::data>& vel = vel_f.at(index);// + total_force * ( half / rho ); - - compute_rho_u(dfs_old_f.at(index),rho,vel); - auto eq = equilibrium(rho,vel); - - using dfi = df_info; - - saw::data> min_two; - min_two.at({}).set(-2); - - // Maybe ? - auto& force = force_f.at(index); - force = vel * rho * min_two * flip_porosity; - - saw::data> dfi_inv_cs2; - dfi_inv_cs2.at({}).set(dfi::inv_cs2); - - // auto vel = vel_f.at(index); - - for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - // saw::data ci_min_u{0}; - saw::data> ci; - for(uint64_t d = 0u; d < Descriptor::D; ++d){ - ci.at({{d}}).set(static_cast::type>(dfi::directions[i][d])); - } - auto ci_dot_u = saw::math::dot(ci,vel); - - // saw::data> F_i; - // F_i = f * ((c_i - u) * ics2 + * c_i * ics2 * ics2) * w_i; - saw::data> w; - w.at({}).set(dfi::weights[i]); - - /* - saw::data> F_i_sum; - for(uint64_t d = 0u; d < Descriptor::D; ++d){ - saw::data> F_i_d; - F_i_d.at({}) = F_i.at({{d}}); - F_i_sum = F_i_sum + F_i_d; - } - */ - auto term1 = (ci-vel) * dfi_inv_cs2; - auto term2 = ci * (ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2); - - auto force_projection = saw::math::dot(term1 + term2, force); - - auto F_i = w * force_projection; - - dfs.at({i}) = dfs.at({i}) - + frequency_ - * (eq.at(i) - dfs.at({i}) ) - + F_i.at({}) - * (saw::data{1} - saw::data{0.5f} * frequency_); - } - } - -}; -} -} diff --git a/lib/core/c++/geometry.hpp b/lib/core/c++/geometry.hpp deleted file mode 100644 index 1c5d0a3..0000000 --- a/lib/core/c++/geometry.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "component.hpp" - -namespace kel { -namespace lbm { -/* -template -struct geometry { - void apply(const saw::data& field, const saw::data>& start, const saw::data>& end, const saw::data& type){ - - } -}; -*/ - -// Ghost - 0 -// Wall - 1 -// Fluid - 2 -// Other Stuff - 3-x -} -} diff --git a/lib/core/c++/geometry/poiseulle_channel.hpp b/lib/core/c++/geometry/poiseulle_channel.hpp deleted file mode 100644 index f719ec4..0000000 --- a/lib/core/c++/geometry/poiseulle_channel.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "../geometry.hpp" - -namespace kel { -namespace lbm { -namespace cmpt { -struct PoiseulleChannel; -} - -template -class component final { -private: -public: - template - void apply(saw::data& field, const saw::data){ - auto& info_f = field.template get<"info">(); - } -}; - -} -} diff --git a/lib/core/c++/grid.hpp b/lib/core/c++/grid.hpp deleted file mode 100644 index c9a3b05..0000000 --- a/lib/core/c++/grid.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "common.hpp" - -namespace kel { -namespace lbm { - -/** - * I'm mixing up the geometry values regarding inflow etc. And a bit of logic - */ -template -class domain_registry final { -private: - saw::data> infos_; -public: - template - saw::data get_template_id() { - static saw::data id{std::numeric_limits::type>::max()}; - - if( id == std::numeric_limits::type>::max() ){ - auto err_or_id = search_or_register_id(T::name); - if(err_or_id.is_error()){ - // Unsure about recovery from this - exit(-1); - } - } - } -}; - -template -void clean_grid(saw::data& info_field){ -} -} -} diff --git a/lib/core/c++/hlbm.hpp b/lib/core/c++/hlbm.hpp deleted file mode 100644 index 18c32a5..0000000 --- a/lib/core/c++/hlbm.hpp +++ /dev/null @@ -1,168 +0,0 @@ -#pragma once - -#include "macroscopic.hpp" -#include "component.hpp" -#include "equilibrium.hpp" - -#include "particle/particle.hpp" - -#include - -namespace kel { -namespace lbm { -namespace cmpt { -struct HlbmInit {}; -struct Hlbm {}; -struct HlbmParticle {}; - -struct HlbmOneParticleMomentumExchange {}; -} - -template -class component final { -private: - typename saw::native_data_type::type relaxation_; - saw::data frequency_; -public: - component(typename saw::native_data_type::type relaxation__): - relaxation_{relaxation__}, - frequency_{typename saw::native_data_type::type(1) / relaxation_} - {} - - template - void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { - auto& porosity_f = macros.template get<"porosity">(); - auto& particle_N_f = field.template get<"particle_N">(); - auto& particle_D_f = field.template get<"particle_D">(); - - auto& por = porosity_f.at(index); - por = {}; - - auto& pnf = particle_N_f.at(index); - pnf = {}; - - auto& pnd = particle_D_f.at(index); - pnd = {}; - } -}; - -/** - * HLBM collision operator for LBM - */ -template -class component final { -private: - typename saw::native_data_type::type relaxation_; - saw::data frequency_; -public: - component(typename saw::native_data_type::type relaxation__): - relaxation_{relaxation__}, - frequency_{typename saw::native_data_type::type(1) / relaxation_} - {} - - template - void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data 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& particle_N_f = field.template get<"particle_N">(); - auto& particle_D_f = field.template get<"particle_D">(); - - auto& porosity_f = macros.template get<"porosity">(); - auto& rho_f = macros.template get<"density">(); - auto& vel_f = macros.template get<"velocity">(); - - saw::data>& rho = rho_f.at(index); - saw::data>& vel = vel_f.at(index); - - compute_rho_u(dfs_old_f.at(index), rho, vel); - - auto& porosity = porosity_f.at(index); - saw::data> one; - one.at({}) = 1.0; - auto flip_porosity = one - porosity; - - auto& N = particle_N_f.at(index); - auto& D = particle_D_f.at(index); - // Convex combination of velocities - vel = vel * porosity + [&]() -> saw::data> { - return (D.at({}).get() > 0.0 ? N * flip_porosity / D : N); - }(); - // Equilibrium - auto eq = equilibrium(rho,vel); - - 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})); - } - - porosity.at({}) = 1.0; - D.at({}) = 0.0; - N = {}; - } -}; - -namespace impl { - -} - -template -class component final { -private: - template - void apply_i(const saw::data& field, const saw::data& macros, const saw::data& part_groups, saw::data> index, saw::data time_step) const { - - } -public: - /* - template - void apply_i() - */ - - template - void apply(const saw::data& field, const saw::data& macros, const saw::data& part_group, saw::data> index, saw::data 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_group; - auto& mvel = macros.template get<"velocity">(); - { - auto& parts = part_spheroid_group.template get<"particles">(); - auto parts_size = parts.meta().at({0u}); - - auto& pi = parts.at(index); - auto& pirb = pi.template get<"rigid_body">(); - auto& pirb_pos = pirb.template get<"position">(); - - saw::data> start; - saw::data> stop; - - auto aabb = particle_aabb::calculate(part_spheroid_group,index,mvel.meta()); - /// Ok, I iterate over the space which covers our particle? So lower bounds to upper bounds - - iterator::apply([&](const auto& index){ - // ask for the d_k value here. - // For every value im iterating over I need sth - std::cout<<"Pos: "< -class component final { -public: - template - void apply(const saw::data& field, const saw::data& macros, const saw::data& part_group, saw::data> index, saw::data time_step) const { - // - } -}; -} -} diff --git a/lib/core/c++/index.hpp b/lib/core/c++/index.hpp deleted file mode 100644 index 00e597e..0000000 --- a/lib/core/c++/index.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "common.hpp" - -namespace kel { -namespace lbm { - -template -saw::data> lower_index_from_pos(const saw::data>& pos){ - saw::data> ind; - - for(saw::data i{0u}; i < ind.size(); ++i){ - ind.at(i).set(std::max(pos.at(i).template cast_to().get(),0)); - } - - return ind; -} - -template -saw::data> upper_index_from_pos(const saw::data>& pos){ - auto ind = lower_index_from_pos(pos); - - for(saw::data i{0u}; i < ind.size(); ++i){ - ++ind.at(i); - } - return ind; -} - -} -} diff --git a/lib/core/c++/iterator.hpp b/lib/core/c++/iterator.hpp deleted file mode 100644 index 7fd6f58..0000000 --- a/lib/core/c++/iterator.hpp +++ /dev/null @@ -1,99 +0,0 @@ -#pragma once - -#include "descriptor.hpp" - -namespace kel { -namespace lbm { -template -void iterate_over(Func&& func, const saw::data>& start, const saw::data>& end, const saw::data>& dist = {{{0u,0u}}}){ - // static_assert(D == 2u, "Currently a lazy implementation for AND combinations of intervalls."); - for(saw::data i{start.at({0u}) + dist.at({0u})}; (i+dist.at({0u})) < end.at({0u}); ++i){ - for(saw::data j{start.at({1u}) + dist.at({1u})}; (j+dist.at({1u})) < end.at({1u}); ++j){ - func({{i,j}}); - } - } - return; -} - -/** - * - */ -template -struct iterator { -private: - template - static void iterate_over_i(Func& func, - const saw::data>& start, - const saw::data>& end, - const saw::data>& dist, - saw::data>& iter - ){ - static_assert(i <= D, "Eh. Too tired to think of a good message"); - if constexpr ( i == D ){ - func(iter); - }else{ - for(iter.at({i}) = start.at({i})+dist.at({i}); (iter.at({i})+dist.at({i}) < end.at({i})); ++iter.at({i})){ - iterate_over_i(func,start,end,dist,iter); - } - } - } -public: - template - static void apply( - Func&& func, - const saw::data>& start, - const saw::data>& end, - const saw::data>& dist = {} - ){ - saw::data> iter; - iterate_over_i<0u,Func>(func, start, end, dist, iter); - } -}; - -template -struct ct_tuple_iterator; - -template -struct ct_tuple_iterator> final { -private: - template - static constexpr saw::error_or apply_i( - Func& func, - saw::data>& tup - ){ - if constexpr ( i < sizeof...(Tup) ){ - auto eov = func(tup.template get()); - if(eov.is_error()){ - return eov; - } - return apply_i(func,tup); - } - - return saw::make_void(); - } -public: - template - static constexpr saw::error_or apply( - Func&& func, - saw::data>& tup - ){ - return apply_i(func,tup); - } -}; - -/* Ambiguous -template -void iterate_over(Func&& func, const saw::data>& start, const saw::data>& end, const saw::data>& dist = {{{0u,0u,0u}}}){ - // static_assert(D == 2u, "Currently a lazy implementation for AND combinations of intervalls."); - for(saw::data i{start.at({0u}) + dist.at({0u})}; (i+dist.at({0u})) < end.at({0u}); ++i){ - for(saw::data j{start.at({1u}) + dist.at({1u})}; (j+dist.at({1u})) < end.at({1u}); ++j){ - for(saw::data k{start.at({2u}) + dist.at({2u})}; (j+dist.at({2u})) < end.at({2u}); ++j){ - func({{k,j,i}}); - } - } - } - return; -} -*/ -} -} diff --git a/lib/core/c++/lbm.hpp b/lib/core/c++/lbm.hpp deleted file mode 100644 index 23d30b1..0000000 --- a/lib/core/c++/lbm.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include "args.hpp" -#include "schema.hpp" -#include "descriptor.hpp" -#include "boundary.hpp" -#include "converter.hpp" -#include "config.hpp" -#include "collision.hpp" -#include "component.hpp" -#include "environment.hpp" -#include "equilibrium.hpp" -#include "flatten.hpp" -#include "fplbm.hpp" -#include "chunk.hpp" -#include "iterator.hpp" -#include "hlbm.hpp" -#include "macroscopic.hpp" -#include "momentum_gather.hpp" -#include "memory.hpp" -#include "psm.hpp" -#include "stream.hpp" -#include "write_csv.hpp" -#include "write_vtk.hpp" -#include "util.hpp" - -#include "math/math.hpp" - -#include -#include - -namespace kel { -namespace lbm { -template -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 - <<"[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" - < - -#include - -namespace kel { -namespace lbm { -namespace lbm_type { -struct meter { - static constexpr std::string_view name = "meter_lbm"; - static constexpr std::string_view short_name = "m_lbm"; -}; - -struct second { - static constexpr std::string_view name = "second_lbm"; - static constexpr std::string_view short_name = "s_lbm"; -}; -} - -namespace si_type { -struct meter { - static constexpr std::string_view name = "meter_si"; - static constexpr std::string_view short_name = "m_si"; -}; - -struct second { - static constexpr std::string_view name = "second_si"; - static constexpr std::string_view short_name = "s_si"; -}; -} - -namespace sch { -using namespace saw::schema; -template -using SiMeter = Unit>; - -template -using LbmMeter = Unit>; - -template -using SiSecond = Unit>; - -template -using LbmSecond = Unit>; - -template -using SiVelocity = Unit, UnitElement>; - -template -using LbmVelocity = Unit, UnitElement>; - -template -using SiAcceleration = Unit, UnitElement>; - -template -using LbmAcceleration = Unit, UnitElement>; - -template -using SiKinematicViscosity = Unit, UnitElement>; - -template -using LbmKinematicViscosity = Unit, UnitElement>; - -} -} -} diff --git a/lib/core/c++/macroscopic.hpp b/lib/core/c++/macroscopic.hpp deleted file mode 100644 index 19ab3e9..0000000 --- a/lib/core/c++/macroscopic.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "descriptor.hpp" - -namespace kel { -namespace lbm { -/** - * Calculate the macroscopic variables rho and u in Lattice Units. - */ -template -void compute_rho_u ( - const saw::data>& dfs, - saw::ref>> rho, - saw::ref>> vel - ) -{ - using dfi = df_info; - - rho().at({}).set(0); - for(uint64_t i = 0; i < Desc::D; ++i){ - vel().at({{i}}).set(0); - } - - for(size_t j = 0; j < Desc::Q; ++j){ - rho().at({}) = rho().at({}) + dfs.at({j}); - for(size_t i = 0; i < Desc::D; ++i){ - vel().at({{i}}) = vel().at({{i}}) + saw::data{static_cast::type>(dfi::directions[j][i])} * dfs.at({j}); - } - } - - for(size_t i = 0; i < Desc::D; ++i){ - vel().at({{i}}) = vel().at({{i}}) / rho().at({}); - } -} -} -} diff --git a/lib/core/c++/math/math.hpp b/lib/core/c++/math/math.hpp deleted file mode 100644 index 3920bec..0000000 --- a/lib/core/c++/math/math.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#include "n_linear.hpp" -#include "n_closest.hpp" diff --git a/lib/core/c++/math/n_closest.hpp b/lib/core/c++/math/n_closest.hpp deleted file mode 100644 index ac0fe2f..0000000 --- a/lib/core/c++/math/n_closest.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include "../common.hpp" -#include "../iterator.hpp" - -namespace kel { -namespace lbm { - -template -saw::data n_closest_read(const saw::data,Encode>& f, const saw::data>& frac_ind){ - - auto shift_frac_ind = frac_ind; - for(uint64_t i{0u}; i < D; ++i){ - - shift_frac_ind.at({{i}}) = shift_frac_ind.at({{i}}) + saw::data{0.5}; - if(shift_frac_ind.at({{i}}).get() < 0){ - shift_frac_ind.at({{i}}) = {}; - } - } - - saw::data> shift_ind; - for(uint64_t i{0u}; i < D; ++i){ - shift_ind.at({i}) = frac_ind.at({{i}}).template cast_to(); - } - - return f.at(shift_ind); -} - -template -void n_closest_add(const saw::data,Encode>& f, const saw::data>& frac_ind, const saw::data& val){ - auto shift_frac_ind = frac_ind; - for(uint64_t i{0u}; i < D; ++i){ - - shift_frac_ind.at({{i}}) = shift_frac_ind.at({{i}}) + saw::data{0.5}; - if(shift_frac_ind.at({{i}}).get() < 0){ - shift_frac_ind.at({{i}}) = {}; - } - } - - auto f_meta = f.meta(); - saw::data> shift_ind; - for(uint64_t i{0u}; i < D; ++i){ - shift_ind.at({i}) = frac_ind.at({{i}}).template cast_to(); - if(shift_ind.at({i}) < f_meta.at({i})){ - shift_ind.at({i}) = f_meta.at({i}) - 1u; - } - } - auto& f_i = f.at(shift_ind); - - f_i = f_i + val; -} - -} -} diff --git a/lib/core/c++/math/n_linear.hpp b/lib/core/c++/math/n_linear.hpp deleted file mode 100644 index b378440..0000000 --- a/lib/core/c++/math/n_linear.hpp +++ /dev/null @@ -1,139 +0,0 @@ -#pragma once - -#include "../common.hpp" -#include "../iterator.hpp" - -namespace kel { -namespace lbm { -namespace impl { -template -struct n_linear_interpolate_helper final { - template - auto apply(const saw::data& field, const saw::data>& pos){ - return pos; - } -}; -} - -template -saw::data,sch::Vector>> position_to_index_and_fraction(const saw::data>& pos){ - saw::data,sch::Vector>> sep; - - auto& ind = sep.template get<0u>(); - auto& frac = sep.template get<1u>(); - - auto pos_cpy = pos; - // Guarantee that the pos is at least 0 - for(uint64_t i = 0u; i < D; ++i){ - pos_cpy.at({{i}}).set(std::max(pos.at({{i}}).get(), static_cast::type>(0))); - } - - // Now we can cast to uint64_t - for(uint64_t i = 0u; i < D; ++i){ - ind.at({{i}}) = pos_cpy.at({{i}}).template cast_to(); - } - - frac = pos_cpy - ind.template cast_to(); - - return sep; -} - -template -auto floor_index_from_position(const saw::data>& pos){ - return position_to_index_and_fraction(pos).template get<0u>(); -} - -template -saw::data,sch::Vector>> position_to_index_and_fraction_bounded( - const saw::data>& pos, - const saw::data>& bound) -{ - auto infr = position_to_index_and_fraction(pos); - auto& ind = infr.template get<0u>(); - auto& fra = infr.template get<1u>(); - for(uint64_t i = 0u; i < D; ++i){ - // If index is higher than bound. Set to bound and reset fraction - if((ind.at({{i}}).get()+1u) >= bound.at({{i}}).get()){ - ind.at({{i}}).set(bound.at({{i}}).get()-1u); - fra.at({{i}}) = {}; - } - } - return infr; -} - - -template -auto n_linear_interpolate( - const saw::data& field, const saw::data>& pos){ - - // Pos - auto pos_bound = pos; - - // Dimensions - auto meta = field.dims(); - - // Lower Index - saw::data> ind; - - for(saw::data i{0u}; i < saw::data{D}; ++i){ - // Native Positive i - auto npos_i = pos.at({i}).get(); - - { - // Ok I want to stay in bounds - npos_i = std::min(npos_i,meta.at(i).get()-1.0); - npos_i = std::max(npos_i,1.0); - } - - // Native Index i - auto nind_i = static_cast(std::floor(npos_i))-1ul; - - // Set index to i - ind.at(i).set(nind_i); - } - saw::data> pos_frac; - for(saw::data i{0u}; i < saw::data{D}; ++i){ - pos_frac.at({i}) = pos_bound.at({i}) - ind.at(i).template cast_to(); - } - - // Base value - saw::data res; - - // constexpr uint64_t d_corners = 1ul << D; - - saw::data> ones_ind; - for(saw::data i{0u}; i < saw::data{D}; ++i){ - ones_ind.at({i}).set(1u); - } - - iterator::apply([&](auto ind){ - // Iterates over (0,0,0) to (1,1,1) - saw::data weight{1.0}; - - for(saw::data d{0u}; d < saw::data{D}; ++d){ - - saw::data t = pos_frac.at({d}); - - if(ind.at(d).get() == 0u){ - weight = weight * (saw::data{1} - t); - }else{ - weight = weight * t; - } - } - - }, {}, ones_ind); - - /// TODO I need to actually calc stuff - return field.at({}); -} - -template -saw::data> bilinear_interpolate(const saw::data& field, const saw::data>& pos){ - saw::data> res; - - { - } - return {}; -} -} -} diff --git a/lib/core/c++/math/round.hpp b/lib/core/c++/math/round.hpp deleted file mode 100644 index d3a2586..0000000 --- a/lib/core/c++/math/round.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../common.hpp" - -namespace kel { -namespace lbm { - -template -saw::data> round_to_unsigned(const saw::data>& inp){ - saw::data> rv; - - auto zero = static_cast::type>(0); - auto half = static_cast::type>(0.5); - - for(uint64_t i{0u}; i < D; ++i){ - auto val = inp.at({{i}}).get()+half; - val = std::max(zero,val); - - rv.at({i}).set(static_cast(val)); - } - - return rv; -} - -} -} diff --git a/lib/core/c++/memory.hpp b/lib/core/c++/memory.hpp deleted file mode 100644 index e97c7fc..0000000 --- a/lib/core/c++/memory.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#pragma once - -#include "common.hpp" -#include "chunk.hpp" - -namespace kel { -namespace lbm { - -namespace impl { - -template -struct memory_size_helper; - -template -struct memory_size_helper> { - static constexpr uint64_t bytes = N; -}; - -template -struct memory_size_helper> { - static constexpr uint64_t bytes = saw::ct_multiply::value * memory_size_helper::bytes; -}; - -template -struct memory_size_helper> { - static constexpr uint64_t bytes = saw::ct_multiply::value * memory_size_helper::bytes; -}; - -template -struct memory_size_helper> { - static constexpr uint64_t bytes = memory_size_helper::InnerSchema>::bytes; -}; - -template -struct memory_size_helper> { - - template - static constexpr uint64_t apply_i() { - if constexpr ( i < sizeof...(Members) ){ - using M_I = typename saw::parameter_pack_type::type; - return apply_i() + memory_size_helper::bytes; - } - return 0u; - } - - static constexpr uint64_t bytes = apply_i<0u>(); -}; - -template -class memory_estimate_helper final { -private: - - template - static void apply_i(saw::data& bytes){ - - if constexpr ( i < sizeof...(T)){ - using T_I = typename saw::parameter_pack_type::type; - - bytes.set(bytes.get() + memory_size_helper::bytes); - - apply_i(bytes); - } - } - -public: - - static void apply(saw::data& bytes){ - apply_i<0u>(bytes); - } -}; -} - -template -saw::data memory_estimate(){ - saw::data bytes; - - impl::memory_estimate_helper::apply(bytes); - - return bytes; -} -} -} diff --git a/lib/core/c++/momentum_gather.hpp b/lib/core/c++/momentum_gather.hpp deleted file mode 100644 index 7b1fc96..0000000 --- a/lib/core/c++/momentum_gather.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include "common.hpp" -#include "macroscopic.hpp" -#include "component.hpp" -#include "equilibrium.hpp" - -namespace kel { -namespace lbm { -namespace cmpt { -// Gather the force, Luke! -struct ForceGather {}; -} - -template -class component { -private: -public: - template - void apply(const saw::data& field, const saw::data& macros, - saw::data> index, saw::data time_step) const { - - using dfi = df_info; - 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_f = macros.template get<"porosity">(); - auto& porous = porous_f.at(index); - - auto& force_f = macros.template get<"force">(); - auto& force = force_f.at(index); - - for(uint64_t k{0u}; k < Descriptor::D; ++k){ - force.at({{k}}).set(0); - } - - auto& dfs = dfs_old_f.at(index); - for(uint64_t i{0u}; i < Descriptor::Q; ++i){ - uint64_t i_opp = dfi::opposite_index[i]; - auto dfs_diff = dfs.at({i}) - dfs.at({i_opp}); - for(uint64_t k{0u}; k < Descriptor::D; ++k){ - force.at({{k}}) = force.at({{k}}) + dfs_diff * saw::data{dfi::directions[i][k]}; - } - } - - saw::data> one; - one.at({}) = 1.0; - auto flip_porous = one - porous; - force = force * flip_porous; - } -}; -} -} diff --git a/lib/core/c++/particle.hpp b/lib/core/c++/particle.hpp deleted file mode 100644 index 691a74b..0000000 --- a/lib/core/c++/particle.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "component.hpp" -#include "particle/particle.hpp" - -namespace kel { -namespace lbm { -namespace cmpt { -struct Particle {}; -} - -template -class component { -private: - saw::data> dt_; -public: - component(saw::data> dt__): - dt_{dt__} - {} - - template - void apply(const saw::data& particles, const saw::data& macros, saw::data index, saw::data time_step) const { - - auto& p = particles.at(index); - - // Compute forces - - // Update particle velocity - verlet_step_lambda(p,{1.0}); - - // Update porosity over lattice nodes - - - } -}; -} -} diff --git a/lib/core/c++/particle/aabb.hpp b/lib/core/c++/particle/aabb.hpp deleted file mode 100644 index 1773dea..0000000 --- a/lib/core/c++/particle/aabb.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include "common.hpp" -#include "schema.hpp" - -namespace kel { -namespace lbm { -template -class particle_aabb final { - static_assert(saw::always_false, "Not supported"); -}; - -template -class particle_aabb< - sch::ParticleGroup> -> final { -public: - using Schema = sch::ParticleGroup>; - - using AABB = sch::Struct< - sch::Member,"a">, - sch::Member,"b"> - >; -public: - template - static constexpr saw::data calculate(const saw::data& p_grp, const saw::data>& i, const saw::data>& meta){ - - saw::data aabb; - 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">(); - - auto& a = aabb.template get<"a">(); - auto& b = aabb.template get<"b">(); - - const saw::data>& rad_d = p_grp.template get<"collision">().template get<"radius">().at({0u}); - - saw::data> lower; - saw::data> 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{0}; - a.at({i}) = lower.at({{i}}).template cast_to(); - upper.at({{i}}) = pirb_pos.at({{i}}) + rad_d.at({}); - b.at({i}) = (upper.at({{i}})+saw::data{1}).template cast_to(); - } - - return aabb; - - } -}; -} -} diff --git a/lib/core/c++/particle/blur.hpp b/lib/core/c++/particle/blur.hpp deleted file mode 100644 index b7a1988..0000000 --- a/lib/core/c++/particle/blur.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -namespace kel { -namespace lbm { -template -void blur_mask(saw::data>& p_mask){ - - saw::data mid{2.0/3.0}; - saw::data edge{1.0/6.0}; - - // saw::data,2u> blur_weights{{2.0/3.0},{1.0/6.0}}; - - auto meta = p_mask.dims(); - saw::data> blurred_mask{meta}; - - /* 1D blur into N-D Blur*/ - for(saw::data i{0u}; i < saw::data{D}; ++i){ - iterator::apply([&](const auto& index){ - blurred_mask.at(index) = p_mask.at(index) * mid; - - if(index.at({i}).get() > 0u){ - auto l_ind = index; - l_ind.at({i}) = ind.at({i}) - 1u; - blurred_mask.at(index) = blurred_mask.at(index) + p_mask.at(l_ind) * edge; - } - if((index.at({i}).get() + 1u) < meta.at({i})){ - auto r_ind = index; - r_ind.at({i}) = ind.at({i}) + 1u; - blurred_mask.at(index) = blurred_mask.at(index) + p_mask.at(r_ind) * edge; - } - },{},meta); - - p_mask = blurred_mask; - } -} -} -} diff --git a/lib/core/c++/particle/common.hpp b/lib/core/c++/particle/common.hpp deleted file mode 100644 index 9e673c2..0000000 --- a/lib/core/c++/particle/common.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "../common.hpp" diff --git a/lib/core/c++/particle/geometry/circle.hpp b/lib/core/c++/particle/geometry/circle.hpp deleted file mode 100644 index cf9b87e..0000000 --- a/lib/core/c++/particle/geometry/circle.hpp +++ /dev/null @@ -1,85 +0,0 @@ -#pragma once - -#include "../particle.hpp" - -namespace kel { -namespace lbm { - -template -class particle_circle_geometry { -private: -public: - particle_circle_geometry() - {} - - template - saw::data> generate_mask(uint64_t resolution, uint64_t boundary_nodes = 0) const { - saw::data> mask; - - auto& grid = mask.template get<"grid">(); - auto& com = mask.template get<"center_of_mass">(); - com = {}; - - //uint64_t rad_i = static_cast(resolution * radius_.get())+1u; - uint64_t diameter_i = resolution; - uint64_t size = diameter_i + 2*boundary_nodes; - grid = {{{size,size}}}; - - saw::data delta_x{static_cast::type>(2.0 / static_cast(diameter_i))}; - saw::data center = (saw::data{1.0} + saw::data{2.0} * saw::data{static_cast::type>(boundary_nodes)/diameter_i}); - - saw::data> boundary_arr; - for(uint64_t i = 0u; i < D; ++i){ - boundary_arr.set(boundary_nodes); - } - - iterator::apply([&](const auto& index){ - grid.at(index).set(0); - }, {}, grid.dims()); - - iterator::apply([&](const auto& index){ - saw::data> f_ind; - for(uint64_t i = 0u; i < D; ++i){ - f_ind.at({{i}}) = (index.at({{i}}) + 0.5) * delta_x - center; - } - - auto norm_f_ind = saw::math::norm(f_ind); - }, {}, grid.dims(),boundary_arr); - - for(uint64_t i = 0; i < size; ++i){ - for(uint64_t j = 0; j < size; ++j){ - grid.at({{i,j}}).set(0); - if(i >= boundary_nodes and j >= boundary_nodes and i < (diameter_i + boundary_nodes) and j < (diameter_i + boundary_nodes) ){ - saw::data fi = saw::data{static_cast::type>(0.5+i)} * delta_x - center; - saw::data fj = saw::data{static_cast::type>(0.5+j)} * delta_x - center; - - auto norm_f_ij = fi*fi + fj*fj; - if(norm_f_ij.get() <= 1){ - grid.at({{i,j}}).set(1); - } - } - } - } - - // I don't fully remember what this did - saw::data total_mass{}; - iterator::apply::apply([&](const saw::data>& index){ - auto ind_vec = saw::math::vectorize_data(index).template cast_to(); - for(uint64_t i{0u}; i < D; ++i){ - ind_vec.at({{i}}) = ind_vec.at({{i}}) * grid.at(index); - } - com = com + ind_vec; - - total_mass = total_mass + grid.at(index); - },{}, grid.dims()); - - for(uint64_t i{0u}; i < D; ++i){ - com.at({{i}}) = com.at({{i}}) / total_mass; - } - - return mask; - } -}; - -} -} diff --git a/lib/core/c++/particle/geometry/cube.hpp b/lib/core/c++/particle/geometry/cube.hpp deleted file mode 100644 index 6392de8..0000000 --- a/lib/core/c++/particle/geometry/cube.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "../particle.hpp" - -namespace kel { -namespace lbm { -template -class particle_cubic_geometry { -private: -public: - template - saw::data> generate_mask(uint64_t resolution, uint64_t bound_nodes = 0u){ - - saw::data> mask; - - auto& grid = mask.template get<"grid">(); - auto& com = mask.template get<"center_of_mass">(); - - - } -} -} diff --git a/lib/core/c++/particle/particle.hpp b/lib/core/c++/particle/particle.hpp deleted file mode 100644 index 8e75e5a..0000000 --- a/lib/core/c++/particle/particle.hpp +++ /dev/null @@ -1,246 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "../iterator.hpp" - -#include "schema.hpp" -#include "aabb.hpp" -#include "particle_opa.hpp" - -namespace kel { -namespace lbm { - -template -saw::data>> create_spheroid_particle_group( - saw::data> radius_p, - saw::data> density_p, - const saw::data& mask_resolution -){ - saw::data>> part; - - auto& rad_s = part.template get<"collision">().at({0u}).template get<"radius">(); - rad_s = radius_p; - - auto& mask = part.template get<"mask">(); - auto& density = part.template get<"density">().at({{0u}}); - - auto& total_mass = part.template get<"total_mass">().at({{0u}}); - // Paranoia - total_mass.at({}) = {}; - - static_assert(D >= 1u and D <= 3u, "Dimensions only supported for Dim 1,2 & 3."); - density = density_p; - - saw::data> mask_dims; - for(uint64_t i = 0u; i < D; ++i){ - mask_dims.at({i}) = mask_resolution; - } - saw::data rad_d = radius_p.at({}); - saw::data dia_d = rad_d * 2; - - mask = {mask_dims}; - - auto& mask_step = part.template get<"mask_step">().at({{0u}}); - mask_step.at({}) = dia_d / mask_resolution.template cast_to(); - - auto& com = part.template get<"center_of_mass">().at({{0u}}); - // Paranoia - for(uint64_t i = 0u; i < D; ++i){ - com.at({{i}}) = {}; - } - saw::data ele_ctr{0u}; - - // Radius ^ 2 - saw::data> rad_2_d; - rad_2_d.at({}) = rad_d * rad_d; - - saw::data> center; - for(uint64_t i = 0u; i < D; ++i){ - center.at({{i}}) = rad_d; - } - - iterator::apply([&](const auto& index){ - ++ele_ctr; - - saw::data> offset_index = saw::math::vectorize_data(index).template cast_to() - center; - - auto& dpi = mask.at(index); - - for(uint64_t i = 0u; i < D; ++i){ - com.at({{i}}) = com.at({{i}}) + index.at({i}).template cast_to() * dpi; - } - - total_mass.at({}) = total_mass.at({}) + dpi; - - },{},mask_dims); - - for(uint64_t i = 0u; i < D; ++i){ - com.at({{i}}) = com.at({{i}}) / total_mass.at({}); - } - return part; -} - -/* -template -saw::data>> create_spheroid_particle( - saw::data> pos_p, - saw::data> vec_p, - saw::data> acc_p, - saw::data> rot_pos_p, - saw::data> rot_vel_p, - saw::data> rot_acc_p, - saw::data> rad_p, - saw::data> density_p, - saw::data> dt - ){ - - saw::data> part; - auto& body = part.template get<"rigid_body">(); - auto& mass = part.template get<"mass">(); - - auto& pos = body.template get<"position">(); - auto& pos_old = body.template get<"position_old">(); - auto& acc = body.template get<"acceleration">(); - - auto& rot = body.template get<"rotation">(); - auto& rot_old = body.template get<"rotation_old">(); - - auto& coll = part.template get<"collision">(); - auto& rad = coll.template get<"radius">(); - - pos = pos_p; - pos_old = pos - vec_p * dt; - acc = acc_p; - rad = rad_p; - - if constexpr ( D == 1u){ - saw::data> c; - c.at({}).set(2.0); - mass = rad_p * c * density_p; - } else if constexpr ( D == 2u){ - saw::data> pi; - pi.at({}).set(3.14159); - mass = rad_p * rad_p * pi * density_p; - } else if constexpr ( D == 3u ){ - saw::data> c; - c.at({}).set(3.14159 * 4.0 / 3.0); - mass = rad_p * rad_p * rad_p * c * density_p; - } else { - static_assert(D == 0u or D > 3u, "Dimensions only supported for Dim 1,2 & 3."); - } - - return part; -} -*/ - -template -constexpr auto verlet_step_lambda = [](saw::data>& particle, saw::data> time_step_delta){ - auto& body = particle.template get<"rigid_body">(); - - auto& pos = body.template get<"position">(); - auto& pos_old = body.template get<"position_old">(); - - auto& pos_acc = body.template get<"acceleration">(); - - auto& rot = body.template get<"rotation">(); - auto& rot_old = body.template get<"rotation_old">(); - - auto& rot_acc = body.template get<"angular_acceleration">(); - - auto tsd_squared = time_step_delta * time_step_delta; - - saw::data> pos_new; - // Actual step - saw::data> two; - two.at({}).set(2.0); - pos_new = pos * two - pos_old + pos_acc * tsd_squared; - - // Angular - saw::data::Schema> rot_new; - rot_new = rot * two - rot_old + rot_acc * tsd_squared; - - // Swap - Could be std::swap? - pos_old = pos; - pos = pos_new; - - rot_old = rot; - rot = rot_new; -}; - -template -constexpr auto handle_collision = []( - saw::data>& left, const saw::data>& mass_l, - saw::data>& right, const saw::data>& mass_r, - saw::data> unit_pos_rel, saw::data> vel_rel, - saw::data> d_t -){ - auto& rb_l = left.template get<"rigid_body">(); - auto& pos_l = rb_l.template get<"position">(); - auto& pos_old_l = rb_l.template get<"position_old">(); - auto vel_l = (pos_l-pos_old_l)/d_t; - - auto& rb_r = right.template get<"rigid_body">(); - auto& pos_r = rb_r.template get<"position">(); - auto& pos_old_r = rb_r.template get<"position_old">(); - auto vel_r = (pos_r-pos_old_r)/d_t; - - auto vel_pos_rel_dot = saw::math::dot(unit_pos_rel,vel_rel); - - if( vel_pos_rel_dot.at({{0u}}).get() < 0.0 ){ - pos_l = pos_l + vel_rel * unit_pos_rel * d_t; - pos_r = pos_r - vel_rel * unit_pos_rel * d_t; - } -}; - - -template -constexpr auto broadphase_collision_distance_squared = []( - saw::data>& left, - const saw::data& coll_l, - saw::data>& right, - const saw::data& coll_r -) -> std::pair>>{ - - auto rad_l = coll_l.template get<"radius">(); - auto rad_r = coll_r.template get<"radius">(); - - auto& rb_l = left.template get<"rigid_body">(); - auto& rb_r = right.template get<"rigid_body">(); - - auto& pos_l = rb_l.template get<"position">(); - auto& pos_r = rb_r.template get<"position">(); - - auto pos_dist = pos_l - pos_r; - - auto norm_2 = saw::math::dot(pos_dist,pos_dist); - - saw::data> two; - two.at({}) = 2.0; - auto rad_ab_2 = rad_l * rad_l + rad_r * rad_r + rad_r * rad_l * two; - - return std::make_pair((norm_2.at({}).get() < rad_ab_2.at({}).get()), norm_2); -}; -/** -* -* -*/ -template -constexpr auto broadphase_collision_check = []( - saw::data>& left, - const saw::data& coll_l, - saw::data>& right, - const saw::data& coll_r -) -> bool{ - return broadphase_collision_distance_squared(left,coll_l,right,coll_r).first; -}; - - - -namespace impl { -} - -} -} diff --git a/lib/core/c++/particle/particle_opa.hpp b/lib/core/c++/particle/particle_opa.hpp deleted file mode 100644 index a5e6c28..0000000 --- a/lib/core/c++/particle/particle_opa.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "../component.hpp" -#include "common.hpp" -#include "schema.hpp" -#include "porosity.hpp" - -namespace kel { -namespace lbm { -namespace cmpt { -struct OneParticleAt {}; -} - -template - -class component final { -private: - saw::data> pos_; - saw::data> rad_; - saw::data> eps_; -public: - component( - const saw::data> pos__, - const saw::data> rad__, - const saw::data> eps__ - ): - pos_{pos__}, - rad_{rad__}, - eps_{eps__} - {} - - template - void apply(const saw::data& macros, const saw::data> index, saw::data time_step) const { - using dfi = df_info; - - auto& porous_f = macros.template get<"porosity">(); - - auto& porous = porous_f.at(index); - - auto pos_ind = saw::math::vectorize_data(index); - - // Write out value - auto diff = pos_ind.template cast_to() - pos_; - auto diff_dot = saw::math::dot(diff,diff); - porous = particle_porosity>::calculate(diff, rad_, eps_); - } -}; -} -} diff --git a/lib/core/c++/particle/porosity.hpp b/lib/core/c++/particle/porosity.hpp deleted file mode 100644 index 2f39d2e..0000000 --- a/lib/core/c++/particle/porosity.hpp +++ /dev/null @@ -1,129 +0,0 @@ -#pragma once - -#include "common.hpp" -#include "schema.hpp" -#include "../math/n_closest.hpp" - -namespace kel { -namespace lbm { -namespace por { -template -struct ParticleSpheroid {}; -} - -template -class particle_porosity { -public: - - static saw::data> calculate(const saw::data>& part_group, uint64_t p_i, const saw::data>& lbm_pos){ - auto& mask = part_group.template get<"mask">(); - - auto& particles = part_group.template get<"particles">(); - auto& part_i = particles.at({p_i}); - - auto& part_i_rb = part_i.template get<"rigid_body">(); - auto& pirb = part_i_rb.template get<"position">(); - - auto dist = lbm_pos - pirb; - - // index 0 is at - - return {}; - } -}; - -template -class particle_porosity> final { -public: - static saw::data> calculate(const saw::data>& lbm_rel_dist, saw::data> rad, saw::data> eps){ - saw::data> por; - - auto s_dist_2 = saw::math::dot(lbm_rel_dist,lbm_rel_dist); - auto s_dist = saw::math::sqrt(s_dist_2); - - saw::data> eps_h; - eps_h.at({}) = eps.at({}).get() / 2; - - auto rad_low = rad - eps_h; - auto rad_high = rad + eps_h; - - if(s_dist.at({}) <= rad_low.at({})){ - por.at({}).set(0); - return por; - } - if(s_dist.at({}) >= rad_high.at({})){ - por.at({}).set(1); - return por; - } - - { - typename saw::native_data_type::type inner = (std::numbers::pi / ( 2 * eps.at({}).get() )) * (s_dist - rad_low).at({}).get(); - auto cos_inner = std::sin(inner); - auto cos_i_2 = cos_inner * cos_inner; - por.at({}).set(cos_i_2); - } - - return por; - } -}; - - -template -class particle_porosity> final { -public: - static saw::data> calculate(const saw::data > >& part_group, uint64_t i, const saw::data>& lbm_pos) { - saw::data> por; - - 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> dist_len = saw::math::dot(dist,dist); - dist_len.at({}).set(std::sqrt(dist_len.at({}).get())); - - auto& coll = part_group.template get<"collision">(); - const saw::data>& rad_d = coll.template get<"radius">(); - const auto& eps = part_group.template get<"epsilon">(); - // Move this somewhere - - saw::data> eps_h; - eps_h.at({}) = eps.at({}).get() / 2; - - saw::data> rad_d_eps_p = rad_d + eps_h; - saw::data> rad_d_eps_n = rad_d - eps_h; - - // saw::data> rad_d_eps_p_2 = rad_d_eps_p * rad_d_eps_p; - // saw::data> rad_d_eps_n_2 = rad_d_eps_n * rad_d_eps_n; - // saw::data> rad_2; - // rad_2 = rad_d * rad_d; - - saw::data> inside; - if(dist_len.at({}) <= rad_d_eps_n.at({})){ - inside.at({}).set(0); - return inside; - } - if(dist_len.at({}) > rad_d_eps_p.at({})){ - inside.at({}).set(1); - return inside; - } - - /* - * cos^2 ( ||x-X(t)||_2 - (R-eps/2) ) - */ - { - typename saw::native_data_type::type inner = (std::numbers::pi / (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; - } -}; - -} -} diff --git a/lib/core/c++/particle/schema.hpp b/lib/core/c++/particle/schema.hpp deleted file mode 100644 index 714a16f..0000000 --- a/lib/core/c++/particle/schema.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once - -#include "common.hpp" - -namespace kel { -namespace lbm { - -namespace coll { -template -struct Spheroid { - using ValueSchema = T; - using Schema = sch::Struct< - sch::Member,"radius"> - >; -}; -} - -namespace sch { -using namespace saw::schema; - -namespace impl { -template -struct rotation_type_helper; - -template -struct rotation_type_helper { - using Schema = Scalar; -}; - -template -struct rotation_type_helper { - using Schema = Vector; -}; -} - -template -using ParticleRigidBody = Struct< - Member, "position">, - Member, "position_old">, - Member::Schema, "rotation">, - Member::Schema, "rotation_old">, - - Member, "acceleration">, - Member::Schema, "angular_acceleration"> ->; - - -template -using Particle = Struct< - Member, "rigid_body"> - // Problem is that dynamic data would two layered - // Member, "mask">, ->; - -template> -using ParticleGroup = Struct< - Member, "mask">, - Member, "collision">, - Member,1u>, "epsilon">, - Member,1u>, "mask_step">, - Member,1u>, "density">, - Member,1u>, "center_of_mass">, - Member,1u>, "total_mass">, - Member,1u>, "particles"> ->; -} -} -} diff --git a/lib/core/c++/psm.hpp b/lib/core/c++/psm.hpp deleted file mode 100644 index 6dc146f..0000000 --- a/lib/core/c++/psm.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include "macroscopic.hpp" -#include "component.hpp" -#include "equilibrium.hpp" - -namespace kel { -namespace lbm { -namespace cmpt { -struct PSM {}; -} - -/** - * PSM collision operator for LBM - */ -template -class component { -private: - saw::data relaxation_; - saw::data frequency_; -public: - component( - typename saw::native_data_type::type relaxation__ - ): - relaxation_{relaxation__} - { - saw::data one; - one = 1.0; - frequency_ = one / relaxation_; - } - - template - void apply(const saw::data& field, const saw::data& macros, saw::data> index, saw::data time_step) const { - - using dfi = df_info; - 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_f = macros.template get<"porosity">(); - - auto& rho_f = macros.template get<"density">(); - auto& vel_f = macros.template get<"velocity">(); - - saw::data>& rho = rho_f.at(index); - saw::data>& vel = vel_f.at(index); - - compute_rho_u(dfs_old_f.at(index),rho,vel); - - auto eq = equilibrium(rho,vel); - - saw::data one{1.0}; - auto& porous = porous_f.at(index); - auto flip_porous = one - porous.at({}); - - auto& dfs = dfs_old_f.at(index); - - auto dfs_cpy = dfs; - - for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - uint64_t i_opp = dfi::opposite_index[i]; - dfs.at({i}) = dfs_cpy.at({i}) + frequency_ * (eq.at(i) - dfs_cpy.at({i})) * porous.at({}) + (dfs_cpy.at({i_opp}) - dfs_cpy.at({i}) ) * flip_porous; - } - - auto& force_f = macros.template get<"force">(); - auto& force = force_f.at(index); - for(uint64_t k{0u}; k < Descriptor::D; ++k){ - force.at({{k}}).set(0); - } - - for(uint64_t i{0u}; i < Descriptor::Q; ++i){ - uint64_t i_opp = dfi::opposite_index[i]; - auto dfs_diff = dfs.at({i}) - dfs.at({i_opp}); - for(uint64_t k{0u}; k < Descriptor::D; ++k){ - force.at({{k}}) = force.at({{k}}) + dfs_diff; - } - } - - force = force * porous; - } -}; - -} -} diff --git a/lib/core/c++/rar.hpp b/lib/core/c++/rar.hpp deleted file mode 100644 index dc2b61c..0000000 --- a/lib/core/c++/rar.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "common.hpp" - -namespace kel { -namespace lbm { -saw::error_or run_and_record(int argc, char** argv){ - using RarGit = Struct< - Member, - Member - >; - using RarCommand = Struct< - Member, - Member, "arguments"> - >; - using Rar = Struct< - Member, "commands">, - Member, - Member - >; - - return saw::make_void(); -} -} -} diff --git a/lib/core/c++/schema.hpp b/lib/core/c++/schema.hpp deleted file mode 100644 index 7712f99..0000000 --- a/lib/core/c++/schema.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -namespace kel { -namespace lbm { -namespace sch { -using namespace saw::schema; -} -} -} diff --git a/lib/core/c++/simulation/common.hpp b/lib/core/c++/simulation/common.hpp deleted file mode 100644 index f675a99..0000000 --- a/lib/core/c++/simulation/common.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -namespace kel { -namespace lbm { - -} -} diff --git a/lib/core/c++/simulation/hlbm.hpp b/lib/core/c++/simulation/hlbm.hpp deleted file mode 100644 index 93df9a7..0000000 --- a/lib/core/c++/simulation/hlbm.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "common.hpp" - -namespace kel { -namespace lbm { - -class simulation {}; - - -} -} diff --git a/lib/core/c++/statistics.hpp b/lib/core/c++/statistics.hpp deleted file mode 100644 index c07ccb7..0000000 --- a/lib/core/c++/statistics.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -namespace kel { -namespace lbm { -template -class statistics { -private: -public: -}; -} -} diff --git a/lib/core/c++/stream.hpp b/lib/core/c++/stream.hpp deleted file mode 100644 index dc7cfb3..0000000 --- a/lib/core/c++/stream.hpp +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include "component.hpp" - -namespace kel { -namespace lbm { -namespace cmpt { -struct Stream {}; -} - -template -class component final { -private: -public: - static constexpr saw::string_literal name = "streaming"; - static constexpr saw::string_literal after = "collide"; - static constexpr saw::string_literal before = ""; - - template - void apply(const saw::data& field, saw::data> index, saw::data time_step) const { - using dfi = df_info; - auto g_index = index; - - for(uint64_t i = 0u; i < Descriptor::D; ++i){ - ++g_index.at({{i}}); - } - - bool is_even = ((time_step.get() % 2) == 0); - - auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">(); - auto& dfs_new_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">(); - auto info_f = field.template get<"info">(); - - auto info_meta = info_f.get_dims(); - - /* - bool border = false; - for(uint64_t i = 0u; i < Descriptor::D; ++i){ - auto ind_i = index.at({i}); - border |= (ind_i.get()) == 0u or (ind_i == info_meta.at({i})); - } - - if (not border){ - } - */ - - auto& dfs_new = dfs_new_f.ghost_at(g_index); - - for(uint64_t i = 0u; i < Descriptor::Q; ++i){ - auto dir = dfi::directions[dfi::opposite_index[i]]; - auto g_index_nb = g_index; - for(uint64_t z = 0u; z < Descriptor::D; ++z){ - g_index_nb.at({z}).set(g_index.at({z}).get() + dir[z]); - } - - dfs_new.at({i}) = dfs_old_f.ghost_at(g_index_nb).at({i}); - } - } -}; -} -} diff --git a/lib/core/c++/util.hpp b/lib/core/c++/util.hpp deleted file mode 100644 index 0bdebd1..0000000 --- a/lib/core/c++/util.hpp +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include - -namespace kel { -namespace lbm { -/* -template -struct is_neighbour { - static bool operator()(saw::data& latt, saw::data& index) { - using dfi = df_info; - - if(index.at({0u}).get() == 0u or index.at({1u}).get() == 0u){ - return false; - } - - for(saw::data k{0u}; k.get() < Descriptor::Q; ++k){ - // TODO - saw::data> - } - - auto& cell = latt(index); - } -}; -*/ - -/* Might be stupidly complex -class cell_info_registry final { -public: - static uint8_t next_reg_id = 0u; - - template - static uint8_t get_registration_id() { - static uint8_t reg_id = std::numeric_limit::max(); - - if(reg_id == std::numeric_limit::max()){ - reg_id = next_reg_id; - ++next_reg_id; - } - - return reg_id; - } -}; -*/ - -void print_progress_bar(const uint32_t progress, const uint32_t progress_target){ - std::cout<<"\r"; - // <<"Progress: " - // <<((100 * progress) / progress_target) - // <<"% ["; - - const uint32_t progress_min = std::min(progress,progress_target); - constexpr uint64_t max_perc_progress = 100u; - uint64_t perc_prog = (max_perc_progress*progress_min) / progress_target; - - std::string_view prog_str{"Progress: "}; - // Progress string + (100 width and perc char) + ([] brackets) + space + pointer - uint64_t i{prog_str.size() + 4u + 2u + 1u + 1u}; - - std::cout< uint64_t{ - struct winsize w; - if(ioctl(STDOUT_FILENO, TIOCGWINSZ,&w) == -1){ - // Standardized Terminal size - return 80u; - } - return w.ws_col; - }(); - max_display = std::max(max_display,i) - i; - uint64_t progress_display = (max_display * progress_min) / progress_target; - - for(i = 0u; i < progress_display; ++i){ - std::cout<<"#"; - } - for(; i < max_display; ++i){ - std::cout<<"-"; - } - - std::cout<<"]"; - - std::cout< - -#include -#include - -#include "descriptor.hpp" -#include "flatten.hpp" -#include "chunk.hpp" - -#include -#include - -namespace kel { -namespace lbm { -namespace impl { - -template -struct lbm_csv_writer { -}; - -template -struct lbm_csv_writer> { - static saw::error_or apply(std::ostream& csv_file, const saw::data>& field){ - if constexpr (std::is_same_v and D == 1u) { - csv_file<().get(); - }else{ - csv_file< -struct lbm_csv_writer> { - static saw::error_or apply(std::ostream& csv_file, const saw::data>& field){ - saw::data> index; - for(saw::data it{0}; it.get() < D; ++it){ - index.at({0u}).set(0u); - } - - // csv_file<<"VECTORS "< 0){ - csv_file<<","; - } - csv_file< -struct lbm_csv_writer> { - - template - static saw::error_or apply_d(std::ostream& csv_file, const saw::data>& field, saw::data>& index){ - // VTK wants to iterate over z,y,x instead of x,y,z - // So we do the same with CSV to stay consistent for now - // We could reorder the dimensions, but eh - if constexpr ( d > 0u){ - for(index.at({d-1u}) = 0u; index.at({d-1u}) < field.get_dims().at({d-1u}); ++index.at({d-1u})){ - auto eov = apply_d(csv_file, field, index); - } - }else{ - auto eov = lbm_csv_writer::apply(csv_file, field.at(index)); - csv_file<<"\n"; - if(eov.is_error()) return eov; - } - return saw::make_void(); - } - - static saw::error_or apply(std::ostream& csv_file, const saw::data>& field, std::string_view name){ - saw::data> index; - for(saw::data it{0}; it.get() < sizeof...(D); ++it){ - index.at({0u}).set(0u); - } - - { - auto eov = apply_d(csv_file, field, index); - if(eov.is_error()){ - return eov; - } - } - - return saw::make_void(); - } -}; - -template -struct lbm_csv_writer> { - static saw::error_or apply(std::ostream& csv_file, const saw::data>& field){ - static_assert(D > 0, "Non-dimensionality is bad for velocity."); - - // csv_file<<"VECTORS "< 0){ - csv_file<<","; - } - { - auto eov = lbm_csv_writer::apply(csv_file,field.at({{i}})); - if(eov.is_error()) return eov; - } - } - return saw::make_void(); - } -}; - -template -struct lbm_csv_writer> { - static saw::error_or apply(std::ostream& csv_file, const saw::data>& field){ - return lbm_csv_writer::apply(csv_file,field.at({})); - } -}; - -template -struct lbm_csv_writer,Keys>...>> final { - template - static saw::error_or iterate_i( - const std::filesystem::path& csv_dir, const std::string_view& file_base_name, uint64_t d_t, - const saw::data,Keys>...>>& field){ - - if constexpr ( i < sizeof...(MemberT) ) { - using MT = typename saw::parameter_pack_type,Keys>...>::type; - { - std::stringstream sstr; - sstr - <("Could not open file."); - } - // - auto eov = lbm_csv_writer::apply(csv_file,field.template get(), MT::KeyLiteral.view()); - if(eov.is_error()){ - return eov; - } - } - - return iterate_i(csv_dir, file_base_name, d_t,field); - } - - return saw::make_void(); - } - - - static saw::error_or apply( - const std::filesystem::path& csv_dir, const std::string_view& file_base_name, uint64_t d_t, - const saw::data,Keys>...>>& field){ - - auto& field_0 = field.template get::literal>(); - auto meta = field_0.get_dims(); - - return iterate_i<0u>(csv_dir,file_base_name, d_t, field); - } -}; - -} - -template -saw::error_or write_csv_file(const std::filesystem::path& out_dir, const std::string_view& file_name, uint64_t d_t, const saw::data& field){ - - auto csv_dir = out_dir / "csv"; - { - std::error_code ec; - std::filesystem::create_directories(csv_dir,ec); - if(ec != std::errc{}){ - return saw::make_error("Could not create directory for write_csv_file function"); - } - } - auto eov = impl::lbm_csv_writer::apply(csv_dir, file_name, d_t, field); - return eov; -} - -} -} diff --git a/lib/core/c++/write_json.hpp b/lib/core/c++/write_json.hpp deleted file mode 100644 index 19bbfa6..0000000 --- a/lib/core/c++/write_json.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -#include -#include - -#include - - -namespace kel { -namespace lbm { - -template -saw::error_or write_json(const std::filesystem::path& file_name, const saw::data& field){ - saw::data j_data; - { - saw::codec j_codec; - auto eov = j_codec.encode(field, j_data); - if(eov.is_error()){ - return eov; - } - } - return saw::make_void(); -} -} -} diff --git a/lib/core/c++/write_vtk.hpp b/lib/core/c++/write_vtk.hpp deleted file mode 100644 index e852172..0000000 --- a/lib/core/c++/write_vtk.hpp +++ /dev/null @@ -1,256 +0,0 @@ -#pragma once - -#include - -#include -#include - -#include "descriptor.hpp" -#include "flatten.hpp" -#include "chunk.hpp" - -#include -#include - -namespace kel { -namespace lbm { -namespace impl { - -template -struct lbm_vtk_writer { -}; - -template -struct lbm_vtk_writer> { - static saw::error_or apply_header(std::ostream& vtk_file, std::string_view name){ - vtk_file<<"SCALARS "< apply(std::ostream& vtk_file, const saw::data>& field){ - if constexpr (std::is_same_v and D == 1u) { - vtk_file<().get()<<"\n"; - }else{ - vtk_file< -struct lbm_vtk_writer> { - static saw::error_or apply_header(std::ostream& vtk_file, std::string_view name){ - vtk_file<<"VECTORS "< apply(std::ostream& vtk_file, const saw::data>& field){ - saw::data> index; - for(saw::data it{0}; it.get() < D; ++it){ - index.at({0u}).set(0u); - } - - // vtk_file<<"VECTORS "< 0){ - vtk_file<<" "; - } - vtk_file< -struct lbm_vtk_writer> { - - template - static saw::error_or apply_d(std::ostream& vtk_file, const saw::data>& field, saw::data>& index){ - // VTK wants to iterate over z,y,x instead of x,y,z - // We could reorder the dimensions, but eh - if constexpr ( d > 0u){ - for(index.at({d-1u}) = 0u; index.at({d-1u}) < field.get_dims().at({d-1u}); ++index.at({d-1u})){ - auto eov = apply_d(vtk_file, field, index); - } - }else{ - auto eov = lbm_vtk_writer::apply(vtk_file, field.at(index)); - if(eov.is_error()) return eov; - } - return saw::make_void(); - } - - static saw::error_or apply(std::ostream& vtk_file, const saw::data>& field, std::string_view name){ - { - auto eov = lbm_vtk_writer::apply_header(vtk_file,name); - if(eov.is_error()){ - return eov; - } - } - saw::data> index; - for(saw::data it{0}; it.get() < sizeof...(D); ++it){ - index.at({0u}).set(0u); - } - - { - auto eov = apply_d(vtk_file, field, index); - if(eov.is_error()){ - return eov; - } - } - - vtk_file<<"\n"; - - return saw::make_void(); - } -}; - -template -struct lbm_vtk_writer> { - static saw::error_or apply_header(std::ostream& vtk_file, std::string_view name){ - vtk_file<<"VECTORS "< apply(std::ostream& vtk_file, const saw::data>& field){ - static_assert(D > 0, "Non-dimensionality is bad for velocity."); - static_assert(D <= 3, "4th dimension as well. Mostly due to vtk."); - - // vtk_file<<"VECTORS "< 0){ - vtk_file<<" "; - } - vtk_file< -struct lbm_vtk_writer> { - static saw::error_or apply_header(std::ostream& vtk_file, std::string_view name){ - vtk_file<<"SCALARS "< apply(std::ostream& vtk_file, const saw::data>& field){ - // vtk_file<<"VECTORS "< -struct lbm_vtk_writer,Keys>...>> final { - template - static saw::error_or iterate_i(std::ostream& vtk_file, - const saw::data,Keys>...>>& field){ - - if constexpr ( i < sizeof...(MemberT) ) { - using MT = typename saw::parameter_pack_type,Keys>...>::type; - { - auto eov = lbm_vtk_writer::apply(vtk_file,field.template get(), MT::KeyLiteral.view()); - if(eov.is_error()){ - return eov; - } - } - - return iterate_i(vtk_file, field); - } - - return saw::make_void(); - } - - - static saw::error_or apply(std::ostream& vtk_file, - const saw::data,Keys>...>>& field){ - - vtk_file - <<"# vtk DataFile Version 3.0\n" - <<"LBM File\n" - <<"ASCII\n" - <<"DATASET STRUCTURED_POINTS\n" - <<"SPACING 1.0 1.0 1.0\n" - <<"ORIGIN 0.0 0.0 0.0\n" - ; - - auto& field_0 = field.template get::literal>(); - auto meta = field_0.get_dims(); - - saw::data pd_size{1u}; - // DIMENSIONS - - { - vtk_file << "DIMENSIONS"; - pd_size.set(saw::ct_multiply::value); - - static_assert(saw::ct_multiply::value > 0u, "Invalid Dim size resulting in length 0u"); - - for(saw::data i{0u}; i.get() < sizeof...(Dims); ++i){ - vtk_file << " " << meta.at(i).get(); - } - for(saw::data i{sizeof...(Dims)}; i.get() < 3u; ++i){ - vtk_file << " 1"; - } - - vtk_file << "\n"; - } - if constexpr (sizeof...(MemberT) > 0u){ - // POINT DATA - { - vtk_file << "\nPOINT_DATA " << pd_size.get() <<"\n"; - } - - // HEADER TO BODY - { - vtk_file << "\n"; - } - } - - return iterate_i<0u>(vtk_file, field); - } -}; - -} - -template -saw::error_or write_vtk_file(const std::filesystem::path& out_dir, const std::string_view& file_name, uint64_t d_t, const saw::data& field){ - - auto vtk_dir = out_dir / "vtk"; - { - std::error_code ec; - std::filesystem::create_directories(vtk_dir,ec); - if(ec != std::errc{}){ - return saw::make_error("Could not create directory for write_vtk_file function"); - } - } - std::string ft_name{file_name}; - - std::stringstream sstr; - sstr - <("Could not open file."); - } - - auto eov = impl::lbm_vtk_writer::apply(vtk_file, field); - return eov; -} - -} -} diff --git a/lib/core/tests/SConscript b/lib/core/tests/SConscript deleted file mode 100644 index d1b381e..0000000 --- a/lib/core/tests/SConscript +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/false - -import os -import os.path -import glob - - -Import('env') - -dir_path = Dir('.').abspath - -# Environment for base library -test_cases_env = env.Clone(); - -test_cases_env.Append(LIBS=['forstio-test']); - -test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) -test_cases_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) - -env.sources += test_cases_env.sources; -env.headers += test_cases_env.headers; - -objects_static = [] -test_cases_env.add_source_files(objects_static, test_cases_env.sources, shared=False); -test_cases_env.program = test_cases_env.Program('#bin/tests', [objects_static]); -# , env.library_static]); - -# Set Alias -env.Alias('test', test_cases_env.program); -env.Alias('check', test_cases_env.program); - -env.targets += ['test','check']; diff --git a/lib/core/tests/chunk.cpp b/lib/core/tests/chunk.cpp deleted file mode 100644 index 008d4c6..0000000 --- a/lib/core/tests/chunk.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include - -#include "../c++/chunk.hpp" - -namespace { -namespace sch { -using namespace saw::schema; -} - -SAW_TEST("Chunk Ghost size 0"){ - using namespace kel; - - using TestChunk = lbm::sch::Chunk; - using TestArray = sch::FixedArray; - - SAW_EXPECT((std::is_same_v), "Types are not identical"); -} - -SAW_TEST("Chunk Ghost size 1"){ - using namespace kel; - - using TestChunk = lbm::sch::Chunk; - using TestArray = sch::FixedArray; - - SAW_EXPECT((std::is_same_v), "Types are not identical"); -} - -SAW_TEST("Chunk Ghost size 3"){ - using namespace kel; - - using TestChunk = lbm::sch::Chunk; - using TestArray = sch::FixedArray; - - SAW_EXPECT((std::is_same_v), "Types are not identical"); -} - -SAW_TEST("Chunk 2D setup"){ - using namespace kel; - - using TestChunk = lbm::sch::Chunk; - - auto chunk = saw::heap>(); - chunk->at({{0u,0u}}).set(1.0f); - SAW_EXPECT((chunk->ghost_at({{1u,1u}}).get() == 1.0f),"Check if ghost is at shifted spot."); -} - -} diff --git a/lib/core/tests/collision.cpp b/lib/core/tests/collision.cpp deleted file mode 100644 index cd53336..0000000 --- a/lib/core/tests/collision.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -#include "../c++/collision.hpp" - -namespace { -} diff --git a/lib/core/tests/converter.cpp b/lib/core/tests/converter.cpp deleted file mode 100644 index 4fc536f..0000000 --- a/lib/core/tests/converter.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -#include "../c++/converter.hpp" - - -namespace { -namespace sch { -using namespace kel::lbm::sch; - -using T = Float64; -} - -SAW_TEST("Si Meter to Lbm Meter"){ - using namespace kel; - - lbm::converter converter{ - {0.1}, - {0.1} - }; - - saw::data> si_m{1.0}; - - auto lbm_m = converter.meter_si_to_lbm(si_m); - SAW_EXPECT(lbm_m.handle().get() == 10.0, "Correct si to lbm conversion"); -} -} diff --git a/lib/core/tests/descriptor.cpp b/lib/core/tests/descriptor.cpp deleted file mode 100644 index 7f743ce..0000000 --- a/lib/core/tests/descriptor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include - -#include "../c++/descriptor.hpp" - - -namespace { -template -void check_opposite_dirs(){ - using namespace kel; - - using dfi = lbm::df_info; - - for(uint64_t k = 0u; k < Descriptor::Q; ++k){ - auto k_inv = dfi::opposite_index[k]; - - for(uint64_t i = 0u; i < Descriptor::D; ++i){ - SAW_EXPECT(dfi::directions[k][i] == (-1*dfi::directions[k_inv][i]), "Opposites are inconsistent"); - } - } -} - -SAW_TEST("Opposites and Dirs D1Q3"){ - using namespace kel; - check_opposite_dirs>(); -} - -SAW_TEST("Opposites and Dirs D2Q5"){ - using namespace kel; - check_opposite_dirs>(); -} -SAW_TEST("Opposites and Dirs D2Q9"){ - using namespace kel; - check_opposite_dirs>(); -} -SAW_TEST("Opposites and Dirs D3Q27"){ - using namespace kel; - check_opposite_dirs>(); -} -} diff --git a/lib/core/tests/equilibrium.cpp b/lib/core/tests/equilibrium.cpp deleted file mode 100644 index 20a1f08..0000000 --- a/lib/core/tests/equilibrium.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include - -#include "../c++/equilibrium.hpp" - - -namespace { - -template -void check_equilibrium(){ - using namespace kel; - - using dfi = lbm::df_info; - - saw::data> rho; - rho.at({}).set(1.0); - saw::data> vel; - for(saw::data i{0u}; i.get() < Descriptor::D; ++i){ - vel.at({{i}}) = {0.0}; - } - auto eq = lbm::equilibrium(rho,vel); - - for(saw::data i{0u}; i.get() < Descriptor::Q; ++i){ - SAW_EXPECT(eq.at(i).get() == dfi::weights[i.get()], std::string{"No velocity and normalized rho should be exactly the weights: "} + std::to_string(eq.at(i).get()) + std::string{" "} + std::to_string(dfi::weights[i.get()])); - } -} - -SAW_TEST("Equilibrium at rest D1Q3"){ - using namespace kel; - check_equilibrium>(); -} - -SAW_TEST("Equilibrium at rest D2Q5"){ - using namespace kel; - check_equilibrium>(); -} - -SAW_TEST("Equilibrium at rest D2Q9"){ - using namespace kel; - check_equilibrium>(); -} -} diff --git a/lib/core/tests/flatten.cpp b/lib/core/tests/flatten.cpp deleted file mode 100644 index 84b3fa4..0000000 --- a/lib/core/tests/flatten.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -#include "../c++/flatten.hpp" - -namespace { -namespace sch { -using namespace saw::schema; -} - -SAW_TEST("Flatten Index Stride"){ - using namespace kel; - - constexpr saw::data zero = lbm::flatten_index::stride<0u>({{2u,4u,3u}}); - constexpr saw::data one = lbm::flatten_index::stride<1u>({{2u,4u,3u}}); - constexpr saw::data two = lbm::flatten_index::stride<2u>({{2u,4u,3u}}); - - SAW_EXPECT(zero.get() == 1u, "Zero is correct"); - SAW_EXPECT(one.get() == 2u, "Zero is correct"); - SAW_EXPECT(two.get() == 8u, "Zero is correct"); -} - -} diff --git a/lib/core/tests/iterator.cpp b/lib/core/tests/iterator.cpp deleted file mode 100644 index 919c12c..0000000 --- a/lib/core/tests/iterator.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include - -#include "../c++/iterator.hpp" - -#include - -namespace { -namespace sch { -using namespace kel::lbm::sch; -} - -SAW_TEST("Old Iterate"){ - using namespace kel; - - saw::data> start{{0u,0u}}; - saw::data> end{{3u,3u}}; - - lbm::iterate_over([](const saw::data>& index){ - std::cout<<"Index: "< - > tup; - - lbm::ct_tuple_iterator::Schema>::apply([](auto& val) -> saw::error_or { - return saw::make_void(); - },tup); -} - -SAW_TEST("Old Iterate with Distance 1"){ - using namespace kel; - - saw::data> start{{0u,0u}}; - saw::data> end{{4u,4u}}; - - lbm::iterate_over([](const saw::data>& index){ - std::cout<<"Index: "<> start{{0u,0u}}; - saw::data> end{{3u,3u}}; - - lbm::iterator<2u>::apply([](const saw::data>& index){ - std::cout<<"Index: "<> start{{0u,0u}}; - saw::data> end{{4u,4u}}; - - lbm::iterator<2u>::apply([](const saw::data>& index){ - std::cout<<"Index: "< - -#include -#include "../c++/math/n_linear.hpp" - -namespace { -namespace sch { -using namespace saw::schema; -} - -SAW_TEST("Math 1-Linear"){ - using namespace kel; - - saw::data,2u>> field; - { - field.at({{0u}}).at({{0u}}).set(-1.0); - field.at({{1u}}).at({{0u}}).set(2.0); - } - saw::data> pos; - pos.at({{0u}}).set(0.3); -} - -SAW_TEST("Math/Floor Index and Fraction from Position"){ - using namespace kel; - - saw::data> pos; - - { - pos.at({{0u}}) = 43.999; - pos.at({{1u}}) = -50.0; - } - - auto ind_frac = lbm::position_to_index_and_fraction(pos); - auto& ind = ind_frac.template get<0u>(); - for(uint64_t i = 0u; i < 2u; ++i){ - std::cout<(); - for(uint64_t i = 0u; i < 2u; ++i){ - std::cout<> pos; - - { - pos.at({{0u}}) = 43.999; - pos.at({{1u}}) = -50.0; - } - - saw::data> bound; - { - bound.at({{0u}}) = 32u; - bound.at({{1u}}) = 16u; - } - - auto ind_frac = lbm::position_to_index_and_fraction_bounded(pos,bound); - auto& ind = ind_frac.template get<0u>(); - for(uint64_t i = 0u; i < 2u; ++i){ - std::cout<(); - for(uint64_t i = 0u; i < 2u; ++i){ - std::cout< - -#include "../c++/memory.hpp" - -namespace { -namespace sch { -using namespace saw::schema; - -using TStruct = Struct< - Member, - Member, - Member ->; - -using TChunk = kel::lbm::sch::Chunk; -using TBChunk = kel::lbm::sch::Chunk; - -using TChunkStruct = Struct< - Member, - Member ->; -} - -SAW_TEST("Memory Estimate"){ - using namespace kel::lbm; - - SAW_EXPECT((memory_estimate().get() == 4u), "Float32 isn't 4 bytes" ); - SAW_EXPECT((memory_estimate>().get() == 60u), "FixedArray isn't 60 bytes"); - SAW_EXPECT((memory_estimate, sch::UInt8>().get() == 61u), "FixedArray + UInt8 isn't 61 bytes"); -} - -SAW_TEST("Memory Estimate Struct"){ - using namespace kel::lbm; - - SAW_EXPECT((memory_estimate().get() == 13u), "TStruct isn't 13 bytes" ); - // SAW_EXPECT((memory_estimate().get() == 13u), "TStruct isn't 13 bytes" ); -} - -SAW_TEST("Memory Estimate Scalar"){ - using namespace kel::lbm; - - SAW_EXPECT((memory_estimate>().get() == 1u), "Scalar of UInt8 isn't 1 bytes" ); - // SAW_EXPECT((memory_estimate().get() == 13u), "TStruct isn't 13 bytes" ); -} - -SAW_TEST("Memory Estimate Chunk"){ - using namespace kel::lbm; - - SAW_EXPECT((memory_estimate().get() == 480u), std::string{"TChunk isn't 480 bytes, but is "} + std::to_string(memory_estimate().get()) ); -} - -SAW_TEST("Memory Estimate Struct of Chunk"){ - using namespace kel::lbm; - - SAW_EXPECT((memory_estimate().get() == 960u), std::string{"TChunkStruct isn't 960 bytes, but is "} + std::to_string(memory_estimate().get()) ); -} - -} diff --git a/lib/core/tests/particles.cpp b/lib/core/tests/particles.cpp deleted file mode 100644 index 133c343..0000000 --- a/lib/core/tests/particles.cpp +++ /dev/null @@ -1,281 +0,0 @@ -#include - -#include -#include "../c++/particle/particle.hpp" - -namespace { -namespace sch { -using namespace kel::lbm::sch; - -using T = Float64; -} -SAW_TEST("Verlet step 2D - Planar"){ - using namespace kel; - - saw::data> particle; - auto& body = particle.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - auto& pos_old = body.template get<"position_old">(); - - // auto& rot = body.template get<"rotation">(); - auto& acc = body.template get<"acceleration">(); - - acc.at({{0}}).set({1.0}); - - saw::data> dt; - dt.at({}).set(0.5); - lbm::verlet_step_lambda(particle,dt); - - SAW_EXPECT(pos.at({{0}}).get() == 0.25, std::string{"Incorrect Pos X: "} + std::to_string(pos.at({{0}}).get())); - SAW_EXPECT(pos.at({{1}}).get() == 0.0, std::string{"Incorrect Pos Y: "} + std::to_string(pos.at({{1}}).get())); -} -/* -SAW_TEST("No Collision Spheroid 2D"){ - using namespace kel; - - saw::data> part_a; - { - auto& body = part_a.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - - pos.at({{0u}}) = 0.1; - pos.at({{1u}}) = 0.2; - - } - saw::data> part_b; - { - auto& body = part_b.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - - pos.at({{0u}}) = -2.1; - pos.at({{1u}}) = 0.0; - } - - bool have_collided = lbm::broadphase_collision_check(part_a,part_b); - SAW_EXPECT(not have_collided, "Particles shouldn't collide"); -} -*/ -/* -SAW_TEST("Collision Spheroid 2D"){ - using namespace kel; - - saw::data> part_a; - { - auto& body = part_a.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - auto& coll = part_a.template get<"collision">(); - auto& radius = coll.template get<"radius">(); - - radius.at({}).set(1.0); - - pos.at({{0u}}) = 0.1; - pos.at({{1u}}) = 0.2; - - } - saw::data> part_b; - { - auto& body = part_b.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - auto& coll = part_b.template get<"collision">(); - auto& radius = coll.template get<"radius">(); - - radius.at({}).set(1.0); - - pos.at({{0u}}) = -1.5; - pos.at({{1u}}) = 0.0; - } - - bool have_collided = lbm::broadphase_collision_check(part_a,part_b); - SAW_EXPECT(have_collided, "Particles should collide"); -} -*/ -/* -SAW_TEST("Moving particles 2D"){ - using namespace kel; - - saw::data> part_a; - { - auto& body = part_a.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - auto& pos_old = body.template get<"position_old">(); - auto& coll = part_a.template get<"collision">(); - auto& radius = coll.template get<"radius">(); - auto& acc = body.template get<"acceleration">(); - - radius.at({}).set(1.0); - - pos.at({{0u}}) = -5.0; - pos.at({{1u}}) = 0.2; - pos_old = pos; - acc.at({{0u}}) = 0.1; - - } - saw::data> part_b; - { - auto& body = part_b.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - auto& pos_old = body.template get<"position_old">(); - auto& coll = part_b.template get<"collision">(); - auto& radius = coll.template get<"radius">(); - auto& acc = body.template get<"acceleration">(); - - radius.at({}).set(1.0); - - pos.at({{0u}}) = 5.0; - pos.at({{1u}}) = 0.0; - pos_old = pos; - acc.at({{0u}}) = -0.1; - } - - saw::data> dt; - dt.at({}).set(0.5); - bool has_collided = false; - for(uint64_t i = 0u; i < 32u; ++i){ - lbm::verlet_step_lambda(part_a,dt); - lbm::verlet_step_lambda(part_b,dt); - - has_collided = lbm::broadphase_collision_check(part_a,part_b); - if(has_collided){ - std::cout<<"Collided at: "<> part_a; - { - auto& body = part_a.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - auto& pos_old = body.template get<"position_old">(); - auto& acc = body.template get<"acceleration">(); - - pos.at({{0u}}) = -5.0; - pos.at({{1u}}) = 0.2; - pos_old = pos; - } -} -/* - -SAW_TEST("Particle Collision Impulse"){ - using namespace kel; - - saw::data> part_a; - { - auto& body = part_a.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - auto& pos_old = body.template get<"position_old">(); - auto& coll = part_a.template get<"collision">(); - auto& radius = coll.template get<"radius">(); - auto& acc = body.template get<"acceleration">(); - - radius.at({}).set(1.0); - - pos.at({{0u}}) = -5.0; - pos.at({{1u}}) = 0.2; - pos_old = pos; - acc.at({{0u}}) = 0.1; - - } - saw::data> part_b; - { - auto& body = part_b.template get<"rigid_body">(); - auto& pos = body.template get<"position">(); - auto& pos_old = body.template get<"position_old">(); - auto& coll = part_b.template get<"collision">(); - auto& radius = coll.template get<"radius">(); - auto& acc = body.template get<"acceleration">(); - - radius.at({}).set(1.5); - - pos.at({{0u}}) = 5.0; - pos.at({{1u}}) = 0.0; - pos_old = pos; - acc.at({{0u}}) = -0.1; - } -} -*/ -/* - -SAW_TEST("Minor Test for mask"){ - using namespace kel; - - lbm::particle_circle_geometry geo; - - auto mask = geo.generate_mask(9u,1u); - - auto& grid = mask.template get<"grid">(); - - for(saw::data i{0u}; i < grid.template get_dim_size<0>(); ++i){ - for(saw::data j{0u}; j < grid.template get_dim_size<1>(); ++j){ - std::cout<> reference_mask{{{4+2,4+2}}}; - //reference_mask.at({{0,0}}); -} -*/ -/* -SAW_TEST("Verlet integration test 2D"){ - using namespace kel; - lbm::particle_system> system; - - { - saw::data> particle; - auto& rb = particle.template get<"rigid_body">(); - auto& acc = rb.template get<"acceleration">(); - auto& pos = rb.template get<"position">(); - auto& pos_old = rb.template get<"position_old">(); - pos = {{1e-1,1e-1}}; - pos_old = {{0.0, 0.0}}; - acc = {{0.0,-1e1}}; - - auto eov = system.add_particle(std::move(particle)); - SAW_EXPECT(eov.is_value(), "Expected no error :)"); - } - { - auto& p = system.at({0u}); - auto& rb = p.template get<"rigid_body">(); - auto& pos = rb.template get<"position">(); - - for(saw::data i{0u}; i < saw::data{2u}; ++i){ - std::cout<{1e-1}); - - { - auto& p = system.at({0u}); - auto& rb = p.template get<"rigid_body">(); - auto& pos = rb.template get<"position">(); - - for(saw::data i{0u}; i < saw::data{2u}; ++i){ - std::cout< - -#include -#include "../c++/write_vtk.hpp" - -#include - -namespace { -namespace sch { -using namespace kel::lbm::sch; - -using T = Float64; -using D2Q5 = Descriptor<2,5>; -using D2Q9 = Descriptor<2,9>; - -template -using DfCell = Cell; - -template -using CellInfo = Cell; - -/** - * Basic type for simulation - */ -template -using CellStruct = Struct< - Member, "dfs">, - Member, "dfs_old">, - Member, "info"> ->; - -template -using MacroStruct = Struct< - Member, "velocity">, - Member ->; - -} -/* -SAW_TEST("VTK Write test example"){ - using namespace kel; - - // write_vtk(); - - std::stringstream sstream; - - saw::data, 2>> cells{{{2u,2u}}}; - - auto& cell_0 = cells.at({{{0,0}}}); - cell_0.template get<"velocity">()= {{0.5,-0.1}}; - cell_0.template get<"pressure">().set(1.1); - - auto eov = lbm::impl::lbm_vtk_writer, 2>>::apply(sstream, cells); - SAW_EXPECT(eov.is_value(), "vtk writer failed to write"); - - // I want to print it to see it for myself. For now I have no tooling to more easily view associated and potentially generated files - std::cout<::type; -} - -SAW_TEST("VTK Write raw test example"){ - using namespace kel; - - // write_vtk(); - - std::stringstream sstream; - - saw::data, 2>> cells{{{2u,2u}}}; - - auto meta = cells.dims(); - - auto& cell_0 = cells.at({{{0,0}}}); - cell_0.template get<"velocity">()= {{0.5,-0.1}}; - cell_0.template get<"pressure">().set(1.1); - - auto eov = lbm::impl::lbm_vtk_writer_raw,2u>::apply(sstream, &cell_0, meta); - SAW_EXPECT(eov.is_value(), "vtk writer failed to write"); - - // I want to print it to see it for myself. For now I have no tooling to more easily view associated and potentially generated files - std::cout<::type; -} -*/ - -} -- cgit v1.2.3