diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-07-03 15:37:25 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-07-03 15:37:25 +0200 |
commit | 6393b959829a1f7513f3daccbaeb9e275fc4ac0d (patch) | |
tree | 93dcab7399f955cc9a6bc27a91cdb9ad49f2faea | |
parent | 6119b94098385da3983a82a3c1472991e9e2f467 (diff) |
Wrote minor iterator confirmation tests
-rw-r--r-- | c++/geometry.hpp | 5 | ||||
-rw-r--r-- | c++/iterator.hpp | 18 | ||||
-rw-r--r-- | examples/SConscript | 6 | ||||
-rw-r--r-- | examples/poiseulle_2d.cpp | 21 | ||||
-rw-r--r-- | tests/iterator.cpp | 33 |
5 files changed, 75 insertions, 8 deletions
diff --git a/c++/geometry.hpp b/c++/geometry.hpp index f675a99..fe0fe7e 100644 --- a/c++/geometry.hpp +++ b/c++/geometry.hpp @@ -2,6 +2,11 @@ namespace kel { namespace lbm { +template<typename Schema> +struct geometry { + void apply(const saw::data<Schema>& field, const saw::data<sch::FixedArray<sch::UInt64,2u>>& start, const saw::data<sch::FixedArray<sch::UInt64,2u>>& end, const saw::data<sch::UInt8>& type){ + } +}; } } diff --git a/c++/iterator.hpp b/c++/iterator.hpp new file mode 100644 index 0000000..01163cf --- /dev/null +++ b/c++/iterator.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "descriptor.hpp" + +namespace kel { +namespace lbm { +template<typename Func> +void iterate_over(Func&& func, const saw::data<sch::FixedArray<sch::UInt64,2u>>& start, const saw::data<sch::FixedArray<sch::UInt64,2u>>& end, const saw::data<sch::UInt64>& dist = {0u}){ + // static_assert(D == 2u, "Currently a lazy implementation for AND combinations of intervalls."); + for(saw::data<sch::UInt64> i{start.at({0u}) + dist}; (i+dist) < end.at({0u}); ++i){ + for(saw::data<sch::UInt64> j{start.at({0u}) + dist}; (j+dist) < end.at({1u}); ++j){ + func({{i,j}}); + } + } + return; +} +} +} diff --git a/examples/SConscript b/examples/SConscript index 13ed580..9bac1f0 100644 --- a/examples/SConscript +++ b/examples/SConscript @@ -33,11 +33,17 @@ examples_env.cavity_2d = examples_env.Program('#bin/cavity_2d', [env.library_sta #examples_env.add_source_files(examples_objects, ['particle_ibm.cpp'], shared=False); #examples_env.particle_ibm_2d = examples_env.Program('#bin/particle_ibm_2d', [env.library_static, examples_objects]); +# Poiseulle 2D +examples_objects = []; +examples_env.add_source_files(examples_objects, ['poiseulle_2d.cpp'], shared=False); +examples_env.poiseulle_2d = examples_env.Program('#bin/poiseulle_2d', [env.library_static, examples_objects]); + # Set Alias env.examples = [ examples_env.meta_2d, examples_env.cavity_2d, # examples_env.particle_ibm_2d + examples_env.poiseulle_2d ]; env.Alias('examples', env.examples); diff --git a/examples/poiseulle_2d.cpp b/examples/poiseulle_2d.cpp index c933319..2770221 100644 --- a/examples/poiseulle_2d.cpp +++ b/examples/poiseulle_2d.cpp @@ -1,6 +1,7 @@ #include "../c++/lbm.hpp" #include "../c++/collision.hpp" #include "../c++/boundary.hpp" +#include "../c++/iterator.hpp" #include <forstio/codec/data.hpp> @@ -38,6 +39,11 @@ using CellStruct = Struct< Member<CellInfo<Desc>, "info"> >; +template<typename T, uint64_t D> +using MacroStruct = Struct< + Member<FixedArray<T,D>, "velocity">, + Member<T, "pressure"> +>; using CavityFieldD2Q9 = CellField<D2Q9, CellStruct<D2Q9>>; } @@ -48,15 +54,14 @@ void set_geometry(saw::data<kel::lbm::sch::CavityFieldD2Q9>& latt){ using namespace kel::lbm; auto meta = latt.meta(); - for(saw::data<sch::UInt64> i{0u}; i < meta.at(0u); ++i){ - for(saw::data<sch::UInt64> j{0u}; j < meta.at(1u); ++j ){ - auto& cell = latt({{i,j}}); - auto& info = cell.template get<"info">(); - // if() - } - } + iterate_over([&](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){ + auto& cell = latt(index); + auto& info = cell.template get<"info">(); + + info({0u}).set(1u); + }, {{0u,0u}}, meta, {1u}); } void set_initial_conditions(saw::data<kel::lbm::sch::CavityFieldD2Q9>& latt){ @@ -136,7 +141,7 @@ int main(int argc, char** argv){ write_vtk_file(vtk_f_name, macros); } - lbm_step(lattice, even_step, step); + // lbm_step(lattice, i); } return 0; diff --git a/tests/iterator.cpp b/tests/iterator.cpp new file mode 100644 index 0000000..85037da --- /dev/null +++ b/tests/iterator.cpp @@ -0,0 +1,33 @@ +#include <forstio/test/suite.hpp> + +#include "../c++/iterator.hpp" + +#include <iostream> + +namespace { +namespace sch { +using namespace kel::lbm::sch; +} + +SAW_TEST("Iterate"){ + using namespace kel; + + saw::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; + saw::data<sch::FixedArray<sch::UInt64,2u>> end{{3u,3u}}; + + lbm::iterate_over([](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){ + std::cout<<"Index: "<<index.at({0u}).get()<<" "<<index.at({1u}).get()<<std::endl; + }, start, end); +} + +SAW_TEST("Iterate with Distance 1"){ + using namespace kel; + + saw::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; + saw::data<sch::FixedArray<sch::UInt64,2u>> end{{4u,4u}}; + + lbm::iterate_over([](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){ + std::cout<<"Index: "<<index.at({0u}).get()<<" "<<index.at({1u}).get()<<std::endl; + }, start, end, {1u}); +} +} |