From 2ae8aaa474f888ed7a5a3810cd916977df6d0dcf Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 4 Feb 2026 10:44:40 +0100 Subject: Work on vtk write and added some vars --- lib/core/c++/write_vtk.hpp | 263 ++++----------------------------------------- 1 file changed, 20 insertions(+), 243 deletions(-) (limited to 'lib/core/c++/write_vtk.hpp') diff --git a/lib/core/c++/write_vtk.hpp b/lib/core/c++/write_vtk.hpp index 9d19015..e84cf9d 100644 --- a/lib/core/c++/write_vtk.hpp +++ b/lib/core/c++/write_vtk.hpp @@ -7,6 +7,7 @@ #include "descriptor.hpp" #include "flatten.hpp" +#include "chunk.hpp" #include #include @@ -27,7 +28,11 @@ struct lbm_vtk_writer> { return saw::make_void(); } static saw::error_or apply(std::ostream& vtk_file, const saw::data>& field){ - vtk_file< and D == 1u) { + vtk_file<().get()<<"\n"; + }else{ + vtk_file<> { } }; -template -struct lbm_vtk_struct_field_writer; - -template -struct lbm_vtk_struct_field_writer> { +template +struct lbm_vtk_writer> { template - static saw::error_or apply_d(std::ostream& vtk_file, const saw::data>& field, saw::data>& index){ + 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})){ @@ -75,13 +77,11 @@ struct lbm_vtk_struct_field_writer> { }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){ + 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()){ @@ -129,16 +129,16 @@ struct lbm_vtk_writer> { } }; -template -struct lbm_vtk_writer,Keys>...>> final { +template +struct lbm_vtk_writer,Keys>...>> final { template static saw::error_or iterate_i(std::ostream& vtk_file, - const saw::data...>>& field){ + const saw::data,Keys>...>>& field){ if constexpr ( i < sizeof...(MemberT) ) { - using MT = typename saw::paramter_pack_type...>::type; + using MT = typename saw::parameter_pack_type,Keys>...>::type; { - auto eov = lbm_vtk_struct_field_writer::apply(vtk_file,field.template get(), MT::KeyLiteral.view()); + auto eov = lbm_vtk_writer::apply(vtk_file,field.template get(), MT::KeyLiteral.view()); if(eov.is_error()){ return eov; } @@ -152,7 +152,7 @@ struct lbm_vtk_writer,K static saw::error_or apply(std::ostream& vtk_file, - const saw::data...>, Dim>>& field){ + const saw::data,Keys>...>>& field){ vtk_file <<"# vtk DataFile Version 3.0\n" @@ -162,8 +162,10 @@ struct lbm_vtk_writer,K <<"SPACING 1.0 1.0 1.0\n" <<"ORIGIN 0.0 0.0 0.0\n" ; + + auto& field_0 = field.template get::literal>(); + auto meta = field_0.get_dims(); - auto meta = field.get_dims(); saw::data pd_size{1u}; // DIMENSIONS @@ -177,7 +179,7 @@ struct lbm_vtk_writer,K pd_size = pd_size * meta.at(i); vtk_file << " " << meta.at(i).get(); } - for(saw::data i{Dim}; i.get() < 3u; ++i){ + for(saw::data i{sizeof...(Dims)}; i.get() < 3u; ++i){ vtk_file << " 1"; } @@ -199,216 +201,6 @@ struct lbm_vtk_writer,K } }; -template -struct lbm_vtk_writer...> , Dim>> { - - template - static saw::error_or write_i_iterate_d(std::ostream& vtk_file, const saw::data...>,Dim>>& field, saw::data>& index){ - constexpr auto Lit = saw::parameter_key_pack_type::literal; - using Type = typename saw::parameter_pack_type::type; - - if constexpr (Dep == 0u){ - return lbm_vtk_writer::apply(vtk_file, field.at(index).template get()); - } else { - // Dep < Dim // I hope - static_assert(Dep > 0u, "Don't fall into this case"); - for(index.at({Dep-1u}) = 0; index.at({Dep-1u}) < field.get_dims().at({Dep-1u}); ++index.at({Dep-1u})){ - auto eov = write_i_iterate_d(vtk_file, field, index); - if(eov.is_error()){ - return eov; - } - } - } - return saw::make_void(); - } - - template - static saw::error_or write_i(std::ostream& vtk_file, const saw::data...>,Dim>>& field){ - - // auto meta = field.get_dims(); - saw::data> index; - for(saw::data it{0}; it.get() < Dim; ++it){ - index.at({0u}).set(0u); - } - // vtk_file write? - // Data header - { - - auto eov = lbm_vtk_writer::type>::apply_header(vtk_file, saw::parameter_key_pack_type::literal.view()); - if(eov.is_error()){ - return eov; - } - - } - return write_i_iterate_d(vtk_file, field, index); - } - - template - static saw::error_or iterate_i(std::ostream& vtk_file, const saw::data...>, Dim>>& field){ - // constexpr auto Lit = saw::parameter_key_pack_type::literal; - { - auto eov = write_i(vtk_file, field); - if(eov.is_error()){ - return eov; - } - } - if constexpr ( (i+1u) < sizeof...(StructT) ){ - 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"; - for(saw::data i{0u}; i.get() < Dim; ++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...(StructT) > 0u){ - // POINT DATA - { - vtk_file << "POINT_DATA " << pd_size.get() <<"\n"; - } - - // HEADER TO BODY - { - vtk_file << "\n"; - } - - return iterate_i<0u>(vtk_file, field); - } - - return saw::make_void(); - } -}; - -template -struct lbm_vtk_writer_raw { - template - static saw::error_or write_i_iterate_d(std::ostream& vtk_file, const saw::data* field, const saw::data>& meta, saw::data>& index){ - constexpr auto Lit = saw::schema_type_at_index::Type::KeyLiteral; - using Type = typename saw::schema_type_at_index::Type::ValueType; - - if constexpr (Dep == 0u){ - auto flat_index = flatten_index::apply(index, meta); - return lbm_vtk_writer::apply(vtk_file, field[flat_index.get()].template get()); - } else { - // Dep < Dim // I hope - static_assert(Dep > 0u, "Don't fall into this case"); - for(index.at({Dep-1u}) = 0; index.at({Dep-1u}) < meta.at({Dep-1u}); ++index.at({Dep-1u})){ - auto eov = write_i_iterate_d(vtk_file, field, meta, index); - if(eov.is_error()){ - return eov; - } - } - } - return saw::make_void(); - } - - template - static saw::error_or write_i(std::ostream& vtk_file, const saw::data* field, const saw::data>& meta){ - constexpr auto Lit = saw::schema_type_at_index::Type::KeyLiteral; - - // auto meta = field.get_dims(); - saw::data> index; - for(saw::data it{0}; it.get() < Dim; ++it){ - index.at({0u}).set(0u); - } - // vtk_file write? - // Data header - { - - auto eov = lbm_vtk_writer::Type::ValueType>::apply_header(vtk_file, Lit.view()); - if(eov.is_error()){ - return eov; - } - - } - return write_i_iterate_d(vtk_file, field, meta, index); - } - template - static saw::error_or iterate_i(std::ostream& vtk_file, const saw::data* field, - const saw::data>& meta){ - { - auto eov = write_i(vtk_file, field, meta); - if(eov.is_error()){ - return eov; - } - } - if constexpr ( (i+1u) < saw::schema_width::value ){ - return iterate_i(vtk_file, field, meta); - } - return saw::make_void(); - } - - static saw::error_or apply(std::ostream& vtk_file, const saw::data* field, - const saw::data>& meta){ - - 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" - ; - - saw::data pd_size{1u}; - // DIMENSIONS - - { - vtk_file << "DIMENSIONS"; - for(saw::data i{0u}; i.get() < Dim; ++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 (saw::schema_width::value > 0u){ - // POINT DATA - { - vtk_file << "POINT_DATA " << pd_size.get() <<"\n"; - } - - // HEADER TO BODY - { - vtk_file << "\n"; - } - - return iterate_i<0u>(vtk_file, field,meta); - } - - return saw::make_void(); - } -}; } template @@ -424,20 +216,5 @@ saw::error_or write_vtk_file(const std::filesystem::path& file_name, const return eov; } -template -saw::error_or write_vtk_file( - const std::filesystem::path& file_name, - const saw::data* field, - const saw::data>& meta - ){ - std::ofstream vtk_file{file_name}; - - if( not vtk_file.is_open() ){ - return saw::make_error("Could not open file."); - } - - auto eov = impl::lbm_vtk_writer_raw::apply(vtk_file, field, meta); - return eov; -} } } -- cgit v1.2.3