diff options
-rw-r--r-- | c++/particle/particle.hpp | 2 | ||||
-rw-r--r-- | c++/write_vtk.hpp | 70 | ||||
-rw-r--r-- | tests/vtk_write.cpp | 38 |
3 files changed, 92 insertions, 18 deletions
diff --git a/c++/particle/particle.hpp b/c++/particle/particle.hpp index d253e64..1c7b241 100644 --- a/c++/particle/particle.hpp +++ b/c++/particle/particle.hpp @@ -35,7 +35,7 @@ class particle_system { private: saw::data<sch::Array<Particle, D>> particles_; - void verlet_step(saw::data<sch::Particle<T,D>& particle, saw::data<T> time_step_delta){ + void verlet_step(saw::data<sch::Particle<T,D>>& particle, saw::data<T> time_step_delta){ auto& body = particle.template get<"rigid_body">(); auto& pos = body.template get<"position">(); diff --git a/c++/write_vtk.hpp b/c++/write_vtk.hpp index 7bde854..3a2bd68 100644 --- a/c++/write_vtk.hpp +++ b/c++/write_vtk.hpp @@ -2,34 +2,64 @@ #include <forstio/error.hpp> +#include <forstio/codec/data.hpp> + +#include "descriptor.hpp" + +#include <fstream> + namespace kel { namespace lbm { namespace impl { +template<typename CellFieldSchema> +struct lbm_vtk_writer { +}; + template<typename... MemberTypes, saw::string_literal... MemberNames> -struct lbm_vtk_writer<sch::Struct<MemberTypes,MemberNames>...> { +struct lbm_vtk_writer<sch::Struct<sch::Member<MemberTypes,MemberNames>...>> { saw::error_or<void> apply(){ return saw::make_void(); } }; -template<typename CellFieldSchema> -struct lbm_vtk_writer { +template<typename T, uint64_t D> +struct lbm_vtk_writer<sch::FixedArray<T,D>> { + static saw::error_or<void> apply(std::ofstream& vtk_file, std::string_view name){ + vtk_file<<"VECTORS "<<name<<" float\n"; + } }; template<typename Desc, typename... StructT, saw::string_literal... StructN> -struct lbm_vtk_writer<CellField<Desc,Struct<Member<StructT,StructN>...>>> { +struct lbm_vtk_writer<sch::CellField<Desc,sch::Struct<sch::Member<StructT,StructN>...>>> { + template<uint64_t i, uint64_t Dep> + saw::error_or<void> write_i_iterate_d(std::ofstream& vtk_file, const saw::data<sch::CellField<Desc,sch::Struct<sch::Member<StructT,StructN>...>>>& field, saw::data<sch::FixedArray<sch::UInt64,Desc::D>>& index){ + if constexpr (Dep == Desc::D){ + + } + } + template<uint64_t i> - saw::error_or<void> write_i(std::ofstream& vtk_file, const saw::data<CellField<Desc,Struct<Member<StructT,StructN>...>>>& field){ + saw::error_or<void> write_i(std::ofstream& vtk_file, const saw::data<sch::CellField<Desc,sch::Struct<sch::Member<StructT,StructN>...>>>& field){ - // vtk_file<< + auto meta = field.meta(); + saw::data<sch::FixedArray<sch::UInt64,Desc::D>> index; + for(saw::data<sch::UInt64> it{0}; it.get() < Desc::D; ++it){ + index.at({0u}).set(0u); + } + // vtk_file write? + // Data header + { + auto eov = lbm_vtk_writer<typename saw::parameter_pack_type<i,StructT...>::type>::apply(vtk_file, saw::parameter_key_pack_type<i, StructN...>::literal.view()); + } + return write_i_iterate_d<i,0u>(vtk_file, field, index); return saw::make_void(); } template<uint64_t i> - saw::error_or<void> iterate_i(std::ofstream& vtk_file, const saw::data<CellField<Desc,Struct<Member<StructT,StructN>...>>>& field){ + saw::error_or<void> iterate_i(std::ofstream& vtk_file, const saw::data<sch::CellField<Desc,sch::Struct<sch::Member<StructT,StructN>...>>>& field){ { auto eov = write_i<i>(vtk_file, field); if(eov.is_error()){ @@ -43,28 +73,35 @@ struct lbm_vtk_writer<CellField<Desc,Struct<Member<StructT,StructN>...>>> { } saw::error_or<void> apply(std::ofstream& vtk_file, - const saw::data<CellField<Desc,Struct<Member<StructT,StructN>...>>>& field){ + const saw::data<sch::CellField<Desc,sch::Struct<sch::Member<StructT,StructN>...>>>& field){ auto meta = field.meta(); + saw::data<sch::UInt64> pd_size{1u}; // DIMENSIONS { vtk_file << "DIMENSIONS "; - for(saw::data<sch::UInt64> i{0u}; i < Desc::D; ++i){ + for(saw::data<sch::UInt64> i{0u}; i.get() < Desc::D; ++i){ + pd_size = pd_size * meta.at(i); vtk_file << " " << meta.at(i).get(); } - for(saw::data<sch::UInt64> i{Desc::D}; i < 3u; ++i){ + for(saw::data<sch::UInt64> i{Desc::D}; i.get() < 3u; ++i){ vtk_file << " 1"; } vtk_file << "\n"; } - // HEADER TO BODY - { - 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); } @@ -93,7 +130,7 @@ saw::error_or<void> write_vtk(const std::string_view file_name, const saw::data< ; - auto eov = lbm_vtk_writer::apply(vtk_file, field); + auto eov = impl::lbm_vtk_writer<Struct>::apply(vtk_file, field); return eov; /* vtk_file <<"# vtk DataFile Version 3.0\n"; @@ -106,7 +143,6 @@ saw::error_or<void> write_vtk(const std::string_view file_name, const saw::data< vtk_file <<"POINT_DATA "<<(dim_x*dim_y)<<"\n"; vtk_file <<"VECTORS Velocity float\n"; */ -:w } } } diff --git a/tests/vtk_write.cpp b/tests/vtk_write.cpp new file mode 100644 index 0000000..7aea628 --- /dev/null +++ b/tests/vtk_write.cpp @@ -0,0 +1,38 @@ +#include <forstio/test/suite.hpp> + +#include <iostream> +#include "../c++/write_vtk.hpp" + + +namespace { +namespace sch { +using namespace kel::lbm::sch; + +using T = Float64; +using D2Q5 = Descriptor<2,5>; +using D2Q9 = Descriptor<2,9>; + +template<typename Desc> +using DfCell = Cell<T, Desc, 0, 0, 1>; + +template<typename Desc> +using CellInfo = Cell<UInt8, D2Q9, 1, 0, 0>; + +/** + * Basic type for simulation + */ +template<typename Desc> +using CellStruct = Struct< + Member<DfCell<Desc>, "dfs">, + Member<DfCell<Desc>, "dfs_old">, + Member<CellInfo<Desc>, "info"> +>; + +} + +SAW_TEST("VTK Write test example"){ + using namespace kel; + + // using Type = typename parameter_pack_type<i,T...>::type; +} +} |