From 98c91326f5952e951247b42299a2a56515603025 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 2 Apr 2025 23:11:31 +0200 Subject: wip tests --- .nix/derivation.nix | 4 +- SConstruct | 1 + c++/descriptor.h | 181 --------------------------------------------- c++/descriptor.hpp | 181 +++++++++++++++++++++++++++++++++++++++++++++ c++/examples/cavity_2d.cpp | 2 +- tests/SConscript | 32 ++++++++ tests/equilibrium.cpp | 3 + 7 files changed, 221 insertions(+), 183 deletions(-) delete mode 100644 c++/descriptor.h create mode 100644 c++/descriptor.hpp create mode 100644 tests/SConscript create mode 100644 tests/equilibrium.cpp diff --git a/.nix/derivation.nix b/.nix/derivation.nix index b328e56..7dc7c7f 100644 --- a/.nix/derivation.nix +++ b/.nix/derivation.nix @@ -20,7 +20,9 @@ stdenv.mkDerivation { forstio.async forstio.codec forstio.codec-unit - ]; + ]; + + doCheck = true; outputs = [ "out" "dev" ]; } diff --git a/SConstruct b/SConstruct index b5690d8..71818ae 100644 --- a/SConstruct +++ b/SConstruct @@ -58,6 +58,7 @@ env.targets = []; Export('env') SConscript('c++/SConscript') +SConscript('tests/SConscript') env.Alias('cdb', env.cdb); env.Alias('all', [env.targets]); diff --git a/c++/descriptor.h b/c++/descriptor.h deleted file mode 100644 index 8c0036a..0000000 --- a/c++/descriptor.h +++ /dev/null @@ -1,181 +0,0 @@ -#pragma once - -#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; -}; - -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 Field; - -template -struct Field< - Desc, - Struct< - CellMembers... - > ->; - -} - -template -class df_info{}; - -template -class df_info> { -public: - 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: - static constexpr uint64_t D = 2u; - static constexpr uint64_t Q = 9u; - - static constexpr std::array, Q> directions = {{ - { 0, 0}, - {-1, 0}, - { 1, 0}, - { 0,-1}, - { 0, 1}, - {-1,-1}, - { 1, 1}, - {-1, 1}, - { 1,-1} - }}; - - 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.; -}; -} -} - -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::Field; -}; - -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); - } -}; - -template -class data, Encode> final { -public: - using Schema = kel::lbm::sch::Field; - using MetaSchema = typename meta_schema::MetaSchema; -private: - data, Encode> inner_; -public: - data() = default; - data(const data>& inner_meta__): - inner_{inner_meta__} - {} - - 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); - } -}; -} diff --git a/c++/descriptor.hpp b/c++/descriptor.hpp new file mode 100644 index 0000000..8c0036a --- /dev/null +++ b/c++/descriptor.hpp @@ -0,0 +1,181 @@ +#pragma once + +#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; +}; + +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 Field; + +template +struct Field< + Desc, + Struct< + CellMembers... + > +>; + +} + +template +class df_info{}; + +template +class df_info> { +public: + 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: + static constexpr uint64_t D = 2u; + static constexpr uint64_t Q = 9u; + + static constexpr std::array, Q> directions = {{ + { 0, 0}, + {-1, 0}, + { 1, 0}, + { 0,-1}, + { 0, 1}, + {-1,-1}, + { 1, 1}, + {-1, 1}, + { 1,-1} + }}; + + 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.; +}; +} +} + +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::Field; +}; + +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); + } +}; + +template +class data, Encode> final { +public: + using Schema = kel::lbm::sch::Field; + using MetaSchema = typename meta_schema::MetaSchema; +private: + data, Encode> inner_; +public: + data() = default; + data(const data>& inner_meta__): + inner_{inner_meta__} + {} + + 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); + } +}; +} diff --git a/c++/examples/cavity_2d.cpp b/c++/examples/cavity_2d.cpp index 82cdd0c..9e91c6c 100644 --- a/c++/examples/cavity_2d.cpp +++ b/c++/examples/cavity_2d.cpp @@ -1,4 +1,4 @@ -#include "../descriptor.h" +#include "../descriptor.hpp" /** */ diff --git a/tests/SConscript b/tests/SConscript new file mode 100644 index 0000000..d1b381e --- /dev/null +++ b/tests/SConscript @@ -0,0 +1,32 @@ +#!/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/tests/equilibrium.cpp b/tests/equilibrium.cpp new file mode 100644 index 0000000..8d53125 --- /dev/null +++ b/tests/equilibrium.cpp @@ -0,0 +1,3 @@ +#include + +#include "../c++/descriptor.hpp" -- cgit v1.2.3