-
Notifications
You must be signed in to change notification settings - Fork 13
/
lgr_vtk_util.hpp
104 lines (93 loc) · 3.02 KB
/
lgr_vtk_util.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once
#include <fstream>
#include <hpc_array_vector.hpp>
#include <hpc_matrix3x3.hpp>
#include <hpc_range.hpp>
#include <hpc_symmetric3x3.hpp>
#include <hpc_vector.hpp>
#include <hpc_vector3.hpp>
#include <iomanip>
#include <lgr_print.hpp>
#include <sstream>
#include <string>
namespace lgr {
inline std::ofstream
make_vtk_output_stream(const std::string& prefix, int const file_output_index)
{
std::stringstream filename_stream;
filename_stream << prefix << "_" << file_output_index << ".vtk";
std::ofstream stream(filename_stream.str().c_str());
stream << std::scientific << std::setprecision(17);
return stream;
}
inline void
start_vtk_unstructured_grid_file(std::ostream& stream)
{
stream << "# vtk DataFile Version 3.0\n";
stream << "vtk output\n";
stream << "ASCII\n";
stream << "DATASET UNSTRUCTURED_GRID\n";
}
template <typename PointIndexType>
inline void
write_vtk_point_data(std::ostream& stream, hpc::counting_range<PointIndexType> const& point_range)
{
stream << "POINT_DATA " << point_range.size() << "\n";
}
template <class Quantity, class Index>
inline void
write_vtk_points(std::ostream& stream, hpc::pinned_array_vector<hpc::vector3<Quantity>, Index> const& x)
{
stream << "POINTS " << x.size() << " double\n";
for (auto ref : x) {
stream << hpc::vector3<double>(ref.load()) << "\n";
}
}
template <class Quantity, class Index>
inline void
write_vtk_full_tensors(
std::ostream& stream,
std::string const& name,
hpc::pinned_array_vector<hpc::matrix3x3<Quantity>, Index> const& tensor)
{
stream << "SCALARS " << name << " double 9\n";
stream << "LOOKUP_TABLE default\n";
for (auto const ref : tensor) {
stream << hpc::matrix3x3<double>(ref.load()) << "\n";
}
}
template <class Quantity, class Index>
inline void
write_vtk_sym_tensors(
std::ostream& stream,
char const* name,
hpc::pinned_array_vector<hpc::symmetric3x3<Quantity>, Index> const& tensor)
{
stream << "TENSORS " << name << " double\n";
for (auto const ref : tensor) {
stream << hpc::symmetric3x3<double>(ref.load()) << "\n";
}
}
template <class Quantity, class Index>
inline void
write_vtk_vectors(
std::ostream& stream,
char const* name,
hpc::pinned_array_vector<hpc::vector3<Quantity>, Index> const& vec)
{
stream << "VECTORS " << name << " double\n";
for (auto const ref : vec) {
stream << hpc::vector3<double>(ref.load()) << "\n";
}
}
template <class Quantity, class Index>
inline void
write_vtk_scalars(std::ostream& stream, std::string const& name, hpc::pinned_vector<Quantity, Index> const& vec)
{
stream << "SCALARS " << name << " double 1\n";
stream << "LOOKUP_TABLE default\n";
for (Quantity const val : vec) {
stream << double(val) << "\n";
}
}
} // namespace lgr