From de842630138b198bc80dfd50d221df86a0139a35 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 2 Feb 2026 18:55:50 +0100 Subject: Adding work on abstract and vtk --- lib/core/c++/abstract/data.hpp | 31 +++++++++ lib/core/c++/abstract/templates.hpp | 4 ++ lib/core/c++/write_vtk.hpp | 123 ++++++++++++++++++++++++++++++++++-- 3 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 lib/core/c++/abstract/data.hpp create mode 100644 lib/core/c++/abstract/templates.hpp diff --git a/lib/core/c++/abstract/data.hpp b/lib/core/c++/abstract/data.hpp new file mode 100644 index 0000000..e8f1757 --- /dev/null +++ b/lib/core/c++/abstract/data.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "templates.hpp" + +namespace kel { +namespace sch { +struct UnsignedInteger {}; +struct SignedInteger {}; +struct FloatingPoint {}; + +template +struct MixedPrecision { + using StorageType = StorageT; + using InterfaceType = InterfaceT; +}; + +template +struct Primitive { + using PrimitiveType = PrimType; + static constexpr uint64_t Bytes = N; +}; + +template +struct Array { + using InnerType = T; + static constexpr std::array Dimensions{Dims...}; +}; + + +} +} diff --git a/lib/core/c++/abstract/templates.hpp b/lib/core/c++/abstract/templates.hpp new file mode 100644 index 0000000..d4d4ace --- /dev/null +++ b/lib/core/c++/abstract/templates.hpp @@ -0,0 +1,4 @@ +#pragma once + +namespace kel { +} diff --git a/lib/core/c++/write_vtk.hpp b/lib/core/c++/write_vtk.hpp index 204bb87..9d19015 100644 --- a/lib/core/c++/write_vtk.hpp +++ b/lib/core/c++/write_vtk.hpp @@ -32,13 +32,18 @@ struct lbm_vtk_writer> { } }; -template +template struct lbm_vtk_writer> { static saw::error_or apply_header(std::ostream& vtk_file, std::string_view name){ vtk_file<<"VECTORS "< apply(std::ostream& vtk_file, const saw::data>& field){ + + static saw::error_or apply(std::ostream& vtk_file, const saw::data>& field){ + saw::data> index; + for(saw::data it{0}; it.get() < D; ++it){ + index.at({0u}).set(0u); + } // vtk_file<<"VECTORS "<> { } }; +template +struct lbm_vtk_struct_field_writer; + +template +struct lbm_vtk_struct_field_writer> { + template + static saw::error_or apply_d(std::ostream& vtk_file, const saw::data>& field, saw::data>& index){ + + if constexpr ( d < sizeof...(D)){ + for(index.at({d}) = 0u; index.at({d}) < field.get_dims().at({d}); ++index.at({d})){ + auto eov = apply_d(vtk_file, field, index); + } + }else{ + auto eov = lbm_vtk_writer::apply(vtk_file, field.at(index)); + if(eov.is_error()) return eov; + + + } + return saw::make_void(); + } + + static saw::error_or apply(std::ostream& vtk_file, const saw::data>& field, std::string_view name){ + { + auto eov = lbm_vtk_writer::apply_header(vtk_file,name); + if(eov.is_error()){ + return eov; + } + } + saw::data> index; + for(saw::data it{0}; it.get() < sizeof...(D); ++it){ + index.at({0u}).set(0u); + } + + { + auto eov = apply_d<0u>(vtk_file, field, index); + if(eov.is_error()){ + return eov; + } + } + + return saw::make_void(); + } +}; + template struct lbm_vtk_writer> { static saw::error_or apply_header(std::ostream& vtk_file, std::string_view name){ @@ -80,10 +129,74 @@ struct lbm_vtk_writer> { } }; -template -struct lbm_vtk_writer> final { +template +struct lbm_vtk_writer,Keys>...>> final { template - lbm_vtk_writer iterate_i(std::ostream& vtk_file, + const saw::data...>>& field){ + + if constexpr ( i < sizeof...(MemberT) ) { + using MT = typename saw::paramter_pack_type...>::type; + { + auto eov = lbm_vtk_struct_field_writer::apply(vtk_file,field.template get(), MT::KeyLiteral.view()); + if(eov.is_error()){ + return eov; + } + } + + return iterate_i(vtk_file, field); + } + + return saw::make_void(); + } + + + static saw::error_or apply(std::ostream& vtk_file, + const saw::data...>, Dim>>& field){ + + vtk_file + <<"# vtk DataFile Version 3.0\n" + <<"LBM File\n" + <<"ASCII\n" + <<"DATASET STRUCTURED_POINTS\n" + <<"SPACING 1.0 1.0 1.0\n" + <<"ORIGIN 0.0 0.0 0.0\n" + ; + + auto meta = field.get_dims(); + saw::data pd_size{1u}; + // DIMENSIONS + + { + vtk_file << "DIMENSIONS"; + pd_size.set(saw::ct_multiply::value); + + static_assert(saw::ct_multiply::value > 0u, "Invalid Dim size resulting in length 0u"); + + for(saw::data i{0u}; i.get() < sizeof...(Dims); ++i){ + pd_size = pd_size * meta.at(i); + vtk_file << " " << meta.at(i).get(); + } + for(saw::data i{Dim}; i.get() < 3u; ++i){ + vtk_file << " 1"; + } + + vtk_file << "\n"; + } + if constexpr (sizeof...(MemberT) > 0u){ + // POINT DATA + { + vtk_file << "POINT_DATA " << pd_size.get() <<"\n"; + } + + // HEADER TO BODY + { + vtk_file << "\n"; + } + } + + return iterate_i<0u>(vtk_file, field); + } }; template -- cgit v1.2.3