diff options
Diffstat (limited to 'lib/core')
| -rw-r--r-- | lib/core/c++/chunk.hpp | 42 | ||||
| -rw-r--r-- | lib/core/tests/chunk.cpp | 18 |
2 files changed, 52 insertions, 8 deletions
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<ChunkSchema,Dim>; } namespace saw { -template<typename Sch, uint64_t Dim, uint64_t Side, uint64_t Ghost, typename Encode> -class data<kel::lbm::sch::Chunk<Sch,Dim,Side,Ghost>,Encode> final { +template<typename Sch, uint64_t Ghost, uint64_t... Sides, typename Encode> +class data<kel::lbm::sch::Chunk<Sch,Ghost,Sides...>,Encode> final { public: - using Schema = kel::lbm::sch::Chunk<Sch,Dim,Side,Ghost>; + using Schema = kel::lbm::sch::Chunk<Sch,Ghost,Sides...>; private: - data<typename Schema::InnerSchema, Encode> values_; + using InnerSchema = typename Schema::InnerSchema; + using ValueSchema = typename InnerSchema::ValueType; + + data<InnerSchema, Encode> values_; public: + data<ValueSchema, Encode>& ghost_at(const data<schema::FixedArray<schema::UInt64,sizeof...(Sides)>>& index){ + return values_.at(index); + } + + const data<ValueSchema, Encode>& ghost_at(const data<schema::FixedArray<schema::UInt64,sizeof...(Sides)>>& index) const { + return values_.at(index); + } + + static constexpr auto get_ghost_dims() { + return data<InnerSchema,Encode>::get_dims(); + } + + data<ValueSchema, Encode>& at(const data<schema::FixedArray<schema::UInt64,sizeof...(Sides)>>& index){ + std::decay_t<decltype(index)> ind; + for(uint64_t i = 0u; i < sizeof...(Sides); ++i){ + ind.at({i}) = index.at({i}) + Ghost; + } + return values_.at(ind); + } + + const data<ValueSchema, Encode>& at(const data<schema::FixedArray<schema::UInt64,sizeof...(Sides)>>& index) const { + std::decay_t<decltype(index)> 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<schema::FixedArray<schema::UInt64, sizeof...(Sides)>,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<sch::UInt32, 1u, 2u, 3u, 4u>; - using TestArray = sch::FixedArray<sch::UInt32, 4u, 5u, 6u>; + using TestChunk = lbm::sch::Chunk<sch::UInt32,1u,2u,3u,4u>; + using TestArray = sch::FixedArray<sch::UInt32,4u,5u,6u>; SAW_EXPECT((std::is_same_v<TestChunk::InnerSchema,TestArray>), "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<sch::UInt32, 3u, 2u, 3u, 4u,10u,6u>; - using TestArray = sch::FixedArray<sch::UInt32, 8u, 9u, 10u,16u,12u>; + using TestChunk = lbm::sch::Chunk<sch::UInt32,3u,2u,3u,4u,10u,6u>; + using TestArray = sch::FixedArray<sch::UInt32,8u,9u,10u,16u,12u>; SAW_EXPECT((std::is_same_v<TestChunk::InnerSchema,TestArray>), "Types are not identical"); } +SAW_TEST("Chunk setup"){ + using namespace kel; + + using TestChunk = lbm::sch::Chunk<sch::Float32, 1u, 2u, 2u>; + + auto chunk = saw::heap<saw::data<TestChunk>>(); + chunk->at({{0u,0u}}).set(1.0f); + SAW_EXPECT((chunk->ghost_at({{1u,1u}}).get() == 1.0f),"Check if ghost is at shifted spot."); +} + } |
