From 952940c3487856447bb80c819b61483b8028d027 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 20 Jan 2026 14:50:23 +0100 Subject: Chunk setup test --- default.nix | 2 +- lib/core/c++/chunk.hpp | 42 ++++++++++++++++++++++++++++++++++++++---- lib/core/tests/chunk.cpp | 18 ++++++++++++++---- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/default.nix b/default.nix index 77abf03..461335c 100644 --- a/default.nix +++ b/default.nix @@ -39,7 +39,7 @@ let forstio = (import ((builtins.fetchTarball { url = "https://git.keldu.de/forstio-forstio/snapshot/master.tar.gz"; - sha256 = "sha256:12wm3kgrsw3irfnafixrq89vr2gr4h05vc2ybixkgfsnc1znhwlv"; + sha256 = "sha256:0ckfcygk4f9x51y45hs5jpi95fjdfqfhl6bx6y374f7x98ng9xx3"; }) + "/default.nix"){ inherit stdenv; inherit clang-tools; diff --git a/lib/core/c++/chunk.hpp b/lib/core/c++/chunk.hpp index 1950661..607bec0 100644 --- a/lib/core/c++/chunk.hpp +++ b/lib/core/c++/chunk.hpp @@ -34,12 +34,46 @@ using SuperChunk = Array; } namespace saw { -template -class data,Encode> final { +template +class data,Encode> final { public: - using Schema = kel::lbm::sch::Chunk; + using Schema = kel::lbm::sch::Chunk; private: - data values_; + 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(); + } + + data& at(const data>& index){ + std::decay_t ind; + for(uint64_t i = 0u; i < sizeof...(Sides); ++i){ + ind.at({i}) = index.at({i}) + Ghost; + } + return values_.at(ind); + } + + const data& at(const data>& index) const { + std::decay_t ind; + for(uint64_t i = 0u; i < sizeof...(Sides); ++i){ + ind.at({i}) = index.at({i}) + Ghost; + } + return values_.at(ind); + } + + static constexpr auto get_dims(){ + return data,Encode>{{Sides...}}; + } }; } diff --git a/lib/core/tests/chunk.cpp b/lib/core/tests/chunk.cpp index 5110597..a9d1748 100644 --- a/lib/core/tests/chunk.cpp +++ b/lib/core/tests/chunk.cpp @@ -19,8 +19,8 @@ SAW_TEST("Chunk Ghost size 0"){ SAW_TEST("Chunk Ghost size 1"){ using namespace kel; - using TestChunk = lbm::sch::Chunk; - using TestArray = sch::FixedArray; + using TestChunk = lbm::sch::Chunk; + using TestArray = sch::FixedArray; SAW_EXPECT((std::is_same_v), "Types are not identical"); } @@ -28,10 +28,20 @@ SAW_TEST("Chunk Ghost size 1"){ SAW_TEST("Chunk Ghost size 3"){ using namespace kel; - using TestChunk = lbm::sch::Chunk; - using TestArray = sch::FixedArray; + using TestChunk = lbm::sch::Chunk; + using TestArray = sch::FixedArray; SAW_EXPECT((std::is_same_v), "Types are not identical"); } +SAW_TEST("Chunk 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."); +} + } -- cgit v1.2.3