Skip to content
Snippets Groups Projects
Commit b6bcdc75 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add output for node and cell value to VTKWriter

parent 9ec7fc19
Branches
Tags
1 merge request!10Feature/data output
......@@ -14,11 +14,131 @@
class VTKWriter
{
private:
template <typename DataType> struct VTKType {};
template <> struct VTKType<int8_t>
{
inline const static std::string name{"Int8"};
};
template <> struct VTKType<uint8_t>
{
inline const static std::string name{"UInt8"};
};
template <> struct VTKType<int16_t>
{
inline const static std::string name{"Int16"};
};
template <> struct VTKType<uint16_t>
{
inline const static std::string name{"UInt16"};
};
template <> struct VTKType<int32_t>
{
inline const static std::string name{"Int32"};
};
template <> struct VTKType<uint32_t>
{
inline const static std::string name{"UInt32"};
};
template <> struct VTKType<int64_t>
{
inline const static std::string name{"Int64"};
};
template <> struct VTKType<uint64_t>
{
inline const static std::string name{"UInt64"};
};
template <> struct VTKType<float>
{
inline const static std::string name{"Float32"};
};
template <> struct VTKType<double>
{
inline const static std::string name{"Float64"};
};
const std::string m_base_filename;
unsigned int m_file_number;
double m_last_time;
const double m_time_period;
template <typename DataType>
void _write_node_value(std::ofstream& os,
const std::string& name,
const NodeValue<const DataType>& item_value)
{
os << "<DataArray type=\"" << VTKType<DataType>::name
<< "\" Name=\"" << name << "\">\n";
for (NodeId i=0; i<item_value.size(); ++i) {
os << item_value[i] << ' ';
}
os << "\n</DataArray>\n";
}
template <size_t N,
typename DataType>
void _write_node_value(std::ofstream& os,
const std::string& name,
const NodeValue<const TinyVector<N, DataType>>& item_value)
{
os << "<DataArray type=\"" << VTKType<DataType>::name
<< "\" Name=\"" << name << "\" NumberOfComponents=\"" << N << "\">\n";
for (NodeId i=0; i<item_value.size(); ++i) {
for (size_t j=0; j<N; ++j) {
os << item_value[i][j] << ' ';
}
}
os << "\n</DataArray>\n";
}
template <typename DataType>
void _write_node_value(std::ofstream& os,
const std::string& name,
const CellValue<const DataType>& item_value) {}
template <typename DataType>
void _write_cell_value(std::ofstream& os,
const std::string& name,
const NodeValue<const DataType>& item_value) {}
template <typename DataType>
void _write_cell_value(std::ofstream& os,
const std::string& name,
const CellValue<const DataType>& item_value)
{
os << "<DataArray type=\"Float64\" Name=\"" << name << "\">\n";
for (CellId i=0; i<item_value.size(); ++i) {
os << item_value[i] << ' ';
}
os << "\n</DataArray>\n";
}
template <size_t N,
typename DataType>
void _write_cell_value(std::ofstream& os,
const std::string& name,
const CellValue<const TinyVector<N, DataType>>& item_value)
{
os << "<DataArray type=\"Float64\" Name=\"" << name << "\" NumberOfComponents=\"" << N << "\">\n";
for (CellId i=0; i<item_value.size(); ++i) {
for (size_t j=0; j<N; ++j) {
os << item_value[i][j] << ' ';
}
}
os << "\n</DataArray>\n";
}
public:
template <typename MeshType>
void write(const MeshType& mesh,
......@@ -40,7 +160,20 @@ class VTKWriter
fout << "<UnstructuredGrid>\n";
fout << "<Piece NumberOfPoints=\""<< mesh.numberOfNodes()
<< "\" NumberOfCells=\"" << mesh.numberOfCells() << "\">\n";
fout << "<CellData>\n";
for(const auto& [name, item_value_variant] : output_named_item_value_set) {
std::visit([&, name=name](auto&& item_value) {
return this->_write_cell_value(fout, name, item_value);
}, item_value_variant);
}
fout << "</CellData>\n";
fout << "<PointData>\n";
for(const auto& [name, item_value_variant] : output_named_item_value_set) {
std::visit([&, name=name](auto&& item_value) {
return this->_write_node_value(fout, name, item_value);
}, item_value_variant);
}
fout << "</PointData>\n";
fout << "<Points>\n";
fout << "<DataArray Name=\"Positions\" NumberOfComponents=\"3\" type=\"Float64\" format=\"ascii\">\n";
using Rd = TinyVector<MeshType::dimension>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment