13#ifndef DUMUX_IO_PARTICLES_WRITER_HH
14#define DUMUX_IO_PARTICLES_WRITER_HH
26#ifdef DUMUX_HAVE_GRIDFORMAT
27#include <gridformat/gridformat.hpp>
29namespace Dumux::IO::Particles {
36template <
class ParticleCloud>
39 using Particle =
typename std::remove_cvref_t<ParticleCloud>::Particle;
41 template <
class Format>
42 Writer(Format fmt, std::shared_ptr<ParticleCloud> cloud,
const std::string& name)
43 : cloud_(std::move(cloud))
45 , writer_(std::move(fmt), *cloud_, name)
48 Writer(std::shared_ptr<ParticleCloud> cloud,
const std::string& name)
50 IO::Format::pvd_with(IO::Format::vtp.with({.encoder = IO::Encoding::raw})
51 ), std::move(cloud), name)
54 template<std::
floating_po
int T>
55 std::string write(T time)
56 {
return writer_.write(time); }
58 template<Detail::Container C, Gr
idFormat::Concepts::Scalar T>
60 const C& data,
const std::string& name,
61 const GridFormat::Precision<T>& prec
63 writer_.set_point_field(name, [&] (
const auto& p) -> std::ranges::range_value_t<C> {
68 template<Detail::Container C>
70 const C& data,
const std::string& name
72 this->addParticleData(
74 GridFormat::Precision<GridFormat::MDRangeScalar<C>>{}
78 template<std::invocable<const Particle&> F>
80 F&& f,
const std::string& name,
81 const GridFormat::Precision<std::invoke_result_t<F, Particle>> prec = {}
83 writer_.set_point_field(name, std::forward<F>(f), prec);
88 writer_.set_point_field(
"id", [&] (
const auto& p) -> std::size_t {
90 }, GridFormat::Precision<std::size_t>{});
94 std::shared_ptr<ParticleCloud> cloud_;
95 const std::string name_;
96 GridFormat::Writer<std::remove_cvref_t<ParticleCloud>> writer_;
Generic writer for a variety of grid file formats.