From 24bf28a8fb9cc8c3a90b77de9b60728bece7885d Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sat, 18 Oct 2025 18:01:14 +0200 Subject: Moving project structure for more less compilation --- lib/tests/SConscript | 32 ++++++++++++++ lib/tests/converter.cpp | 26 +++++++++++ lib/tests/descriptor.cpp | 35 +++++++++++++++ lib/tests/equilibrium.cpp | 40 +++++++++++++++++ lib/tests/iterator.cpp | 33 ++++++++++++++ lib/tests/particle_flow_coupling.cpp | 23 ++++++++++ lib/tests/particles.cpp | 85 ++++++++++++++++++++++++++++++++++++ lib/tests/vtk_write.cpp | 64 +++++++++++++++++++++++++++ 8 files changed, 338 insertions(+) create mode 100644 lib/tests/SConscript create mode 100644 lib/tests/converter.cpp create mode 100644 lib/tests/descriptor.cpp create mode 100644 lib/tests/equilibrium.cpp create mode 100644 lib/tests/iterator.cpp create mode 100644 lib/tests/particle_flow_coupling.cpp create mode 100644 lib/tests/particles.cpp create mode 100644 lib/tests/vtk_write.cpp (limited to 'lib/tests') diff --git a/lib/tests/SConscript b/lib/tests/SConscript new file mode 100644 index 0000000..d1b381e --- /dev/null +++ b/lib/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/lib/tests/converter.cpp b/lib/tests/converter.cpp new file mode 100644 index 0000000..4fc536f --- /dev/null +++ b/lib/tests/converter.cpp @@ -0,0 +1,26 @@ +#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/tests/descriptor.cpp b/lib/tests/descriptor.cpp new file mode 100644 index 0000000..a8337e6 --- /dev/null +++ b/lib/tests/descriptor.cpp @@ -0,0 +1,35 @@ +#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>(); +} +} diff --git a/lib/tests/equilibrium.cpp b/lib/tests/equilibrium.cpp new file mode 100644 index 0000000..9201e55 --- /dev/null +++ b/lib/tests/equilibrium.cpp @@ -0,0 +1,40 @@ +#include + +#include "../c++/equilibrium.hpp" + + +namespace { + +template +void check_equilibrium(){ + using namespace kel; + + using dfi = lbm::df_info; + + saw::data rho{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/tests/iterator.cpp b/lib/tests/iterator.cpp new file mode 100644 index 0000000..cd1cb7c --- /dev/null +++ b/lib/tests/iterator.cpp @@ -0,0 +1,33 @@ +#include + +#include "../c++/iterator.hpp" + +#include + +namespace { +namespace sch { +using namespace kel::lbm::sch; +} + +SAW_TEST("Iterate"){ + using namespace kel; + + saw::data> start{{0u,0u}}; + saw::data> end{{3u,3u}}; + + lbm::iterate_over([](const saw::data>& index){ + std::cout<<"Index: "<> start{{0u,0u}}; + saw::data> end{{4u,4u}}; + + lbm::iterate_over([](const saw::data>& index){ + std::cout<<"Index: "< + +#include +#include "../c++/particle/geometry/circle.hpp" + + +namespace { +namespace sch { +using namespace kel::lbm::sch; + +using T = Float64; +} + +SAW_TEST("Particle Coupling"){ + using namespace kel; + lbm::particle_system> system; + + /// What are the steps?# + /// + /// Collide and Stream + +} +} diff --git a/lib/tests/particles.cpp b/lib/tests/particles.cpp new file mode 100644 index 0000000..277a8d0 --- /dev/null +++ b/lib/tests/particles.cpp @@ -0,0 +1,85 @@ +#include + +#include +#include "../c++/particle/geometry/circle.hpp" + + +namespace { +namespace sch { +using namespace kel::lbm::sch; + +using T = Float64; +} +/* +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"){ + 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; +} +} -- cgit v1.2.3