hp-FEM
Adaptive hp-FEM suite for nano-optics
Loading...
Searching...
No Matches
vtk.hpp
Go to the documentation of this file.
1#pragma once
5
6#include <cstdint>
7#include <filesystem>
8#include <ostream>
9#include <span>
10#include <string>
11#include <variant>
12#include <vector>
13
14#include <Eigen/Core>
15
16#include "hpfem/core/types.hpp"
17#include "hpfem/mesh/mesh.hpp"
18
19namespace hpfem::io {
20
23enum class VtkFormat : std::uint8_t { kAscii, kBinary };
24
33template <int Dim>
34class VtkWriter {
35 public:
36 explicit VtkWriter(const mesh::Mesh<Dim>& mesh, VtkFormat format = VtkFormat::kBinary);
37
39 [[nodiscard]] Index num_points() const noexcept;
40
41 VtkWriter& cell_scalars(std::string name, std::span<const Real> values);
42 VtkWriter& cell_scalars(std::string name, std::span<const Complex> values);
43 VtkWriter& cell_scalars(std::string name, std::span<const Index> values);
44 VtkWriter& cell_vectors(std::string name, std::span<const Point<Dim>> values);
45 VtkWriter& cell_vectors(std::string name, std::span<const Eigen::Matrix<Complex, Dim, 1>> values);
46 VtkWriter& point_scalars(std::string name, std::span<const Real> values);
47 VtkWriter& point_scalars(std::string name, std::span<const Complex> values);
48 VtkWriter& point_vectors(std::string name, std::span<const Point<Dim>> values);
49 VtkWriter& point_vectors(std::string name,
50 std::span<const Eigen::Matrix<Complex, Dim, 1>> values);
51
52 void write(std::ostream& out) const;
54 void write(const std::filesystem::path& file) const;
55
57 struct Array {
58 std::string name;
59 int components = 1;
60 std::variant<std::vector<Real>, std::vector<Index>, std::vector<std::int32_t>,
61 std::vector<std::uint8_t>>
63 };
64
65 private:
66 const mesh::Mesh<Dim>& mesh_;
67 VtkFormat format_;
68 std::vector<Array> cell_arrays_;
69 std::vector<Array> point_arrays_;
70};
71
76template <int Dim>
77void write_vtu_facets(const mesh::Mesh<Dim>& mesh, const std::filesystem::path& file,
78 bool boundary_only = true, VtkFormat format = VtkFormat::kBinary);
79template <int Dim>
80void write_vtu_facets(const mesh::Mesh<Dim>& mesh, std::ostream& out, bool boundary_only = true,
82
83extern template class VtkWriter<2>;
84extern template class VtkWriter<3>;
85extern template void write_vtu_facets<2>(const mesh::Mesh<2>&, const std::filesystem::path&, bool,
86 VtkFormat);
87extern template void write_vtu_facets<3>(const mesh::Mesh<3>&, const std::filesystem::path&, bool,
88 VtkFormat);
89extern template void write_vtu_facets<2>(const mesh::Mesh<2>&, std::ostream&, bool, VtkFormat);
90extern template void write_vtu_facets<3>(const mesh::Mesh<3>&, std::ostream&, bool, VtkFormat);
91
92} // namespace hpfem::io
Definition vtk.hpp:34
VtkWriter(const mesh::Mesh< Dim > &mesh, VtkFormat format=VtkFormat::kBinary)
VtkWriter & cell_scalars(std::string name, std::span< const Real > values)
Index num_points() const noexcept
Number of points written: vertices, plus one edge node per edge for order-2 meshes.
VtkWriter & cell_vectors(std::string name, std::span< const Point< Dim > > values)
VtkWriter & point_scalars(std::string name, std::span< const Real > values)
VtkWriter & point_vectors(std::string name, std::span< const Point< Dim > > values)
void write(std::ostream &out) const
Definition mesh.hpp:61
Definition field_export.hpp:21
void write_vtu_facets(const mesh::Mesh< Dim > &mesh, const std::filesystem::path &file, bool boundary_only=true, VtkFormat format=VtkFormat::kBinary)
VtkFormat
Definition vtk.hpp:23
template void write_vtu_facets< 2 >(const mesh::Mesh< 2 > &, const std::filesystem::path &, bool, VtkFormat)
template void write_vtu_facets< 3 >(const mesh::Mesh< 3 > &, const std::filesystem::path &, bool, VtkFormat)
double Real
Definition types.hpp:15
Eigen::Matrix< Real, Dim, 1 > Point
Definition types.hpp:27
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition types.hpp:22
std::int64_t Index
global indices (DoFs, entities)
Definition types.hpp:17
std::complex< double > Complex
Definition types.hpp:16
One data array of the file; public so that write_vtu_facets can reuse the encoder.
Definition vtk.hpp:57
std::variant< std::vector< Real >, std::vector< Index >, std::vector< std::int32_t >, std::vector< std::uint8_t > > data
Definition vtk.hpp:62
std::string name
Definition vtk.hpp:58