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

Improve VTK output

-use pvtu files to allow simple parallel output
-remain very naive implementation
parent f8e3832e
No related branches found
No related tags found
1 merge request!11Feature/mpi
...@@ -174,6 +174,9 @@ include_directories(src/output) ...@@ -174,6 +174,9 @@ include_directories(src/output)
include_directories(src/utils) include_directories(src/utils)
include_directories(src/scheme) include_directories(src/scheme)
# Pastis generated sources
include_directories(${PASTIS_BINARY_DIR}/src/utils)
# Pastis tests # Pastis tests
set(CATCH_MODULE_PATH "${PASTIS_SOURCE_DIR}/packages/Catch2") set(CATCH_MODULE_PATH "${PASTIS_SOURCE_DIR}/packages/Catch2")
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <IConnectivity.hpp> #include <IConnectivity.hpp>
#include <ItemValue.hpp> #include <ItemValue.hpp>
#include <Messenger.hpp>
class VTKWriter class VTKWriter
{ {
...@@ -18,6 +19,24 @@ class VTKWriter ...@@ -18,6 +19,24 @@ class VTKWriter
double m_last_time; double m_last_time;
const double m_time_period; const double m_time_period;
std::string _getFilenamePVTU()
{
std::ostringstream sout;
sout << m_base_filename;
sout << '.' << std::setfill('0') << std::setw(4) << m_file_number << ".pvtu";
return sout.str();
}
std::string _getFilenameVTU(const int& rank_number) const
{
std::ostringstream sout;
sout << m_base_filename;
if (parallel::size() > 1) {
sout << '-' << std::setfill('0') << std::setw(4) << rank_number;
}
sout << '.' << std::setfill('0') << std::setw(4) << m_file_number << ".vtu";
return sout.str();
}
public: public:
template <typename MeshType> template <typename MeshType>
void write(const MeshType& mesh, void write(const MeshType& mesh,
...@@ -30,9 +49,34 @@ class VTKWriter ...@@ -30,9 +49,34 @@ class VTKWriter
} else { } else {
return; return;
} }
std::ostringstream sout;
sout << m_base_filename << '.' << std::setfill('0') << std::setw(4) << m_file_number << ".vtu" << std::ends; if (parallel::rank() == 0)
std::ofstream fout(sout.str()); { // write PVTK file
std::ofstream fout(_getFilenamePVTU());
fout << "<?xml version=\"1.0\"?>\n";
fout << "<VTKFile type=\"PUnstructuredGrid\">\n";
fout << "<PUnstructuredGrid GhostLevel=\"0\">\n";
fout << "<PPoints>\n";
fout << "<PDataArray Name=\"Positions\" NumberOfComponents=\"3\" type=\"Float64\"/>\n";
fout << "</PPoints>\n";
fout << "<PCells>\n";
fout << "<PDataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\"/>\n";
fout << "<PDataArray type=\"UInt32\" Name=\"offsets\" NumberOfComponents=\"1\"/>\n";
fout << "<PDataArray type=\"Int8\" Name=\"types\" NumberOfComponents=\"1\"/>\n";
fout << "</PCells>\n";
for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) {
fout << "<Piece Source=\""<< _getFilenameVTU(i_rank) << "\"/>\n";
}
fout << "</PUnstructuredGrid>\n";
fout << "</VTKFile>\n";
}
{ // write VTK files
std::ofstream fout(_getFilenameVTU(parallel::rank()));
fout << "<?xml version=\"1.0\"?>\n"; fout << "<?xml version=\"1.0\"?>\n";
fout << "<VTKFile type=\"UnstructuredGrid\">\n"; fout << "<VTKFile type=\"UnstructuredGrid\">\n";
fout << "<UnstructuredGrid>\n"; fout << "<UnstructuredGrid>\n";
...@@ -133,7 +177,7 @@ class VTKWriter ...@@ -133,7 +177,7 @@ class VTKWriter
fout << "</Piece>\n"; fout << "</Piece>\n";
fout << "</UnstructuredGrid>\n"; fout << "</UnstructuredGrid>\n";
fout << "</VTKFile>\n"; fout << "</VTKFile>\n";
}
m_file_number++; m_file_number++;
} }
VTKWriter(const std::string& base_filename, VTKWriter(const std::string& base_filename,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment