40#include <boost/core/ignore_unused.hpp>
41#include <boost/format.hpp>
58 "Writes a VTU file.");
79 ofstream outfile(filename.c_str());
82 int dim = fPts->GetDim();
86 switch (fPts->GetPtsType())
92 "VTK output needs setting up for ePtsFile and ePtsLine");
98 "VTK output needs setting up for PtsPlane");
104 "VTK output needs setting up for PtsBox");
129 vector<Array<OneD, int>> ptsConn;
130 fPts->GetConnectivity(ptsConn);
132 nfields = fPts->GetNFields();
134 int nPts = fPts->GetNpoints();
136 for (i = 0; i < ptsConn.size(); ++i)
138 numBlocks += ptsConn[i].size() / nvert;
142 outfile <<
" <Piece NumberOfPoints=\"" << nPts <<
"\" NumberOfCells=\""
143 << numBlocks <<
"\">" << endl;
144 outfile <<
" <Points>" << endl;
145 outfile <<
" <DataArray type=\"Float64\" "
146 <<
"NumberOfComponents=\"" << 3 <<
"\" format=\"ascii\">" << endl;
147 for (i = 0; i < nPts; ++i)
149 for (j = 0; j < dim; ++j)
151 outfile <<
" " << setprecision(8) << scientific
152 << fPts->GetPointVal(j, i) <<
" ";
154 for (j = dim; j < 3; ++j)
157 outfile <<
" 0.000000";
161 outfile <<
" </DataArray>" << endl;
162 outfile <<
" </Points>" << endl;
163 outfile <<
" <Cells>" << endl;
164 outfile <<
" <DataArray type=\"Int32\" "
165 <<
"Name=\"connectivity\" format=\"ascii\">" << endl;
170 for (i = 0; i < ptsConn.size(); ++i)
172 for (j = 0; j < ptsConn[i].size(); ++j)
174 outfile << ptsConn[i][j] <<
" ";
175 if ((!(cnt % nvert)) && cnt)
177 outfile << std::endl;
183 outfile <<
" </DataArray>" << endl;
184 outfile <<
" <DataArray type=\"Int32\" "
185 <<
"Name=\"offsets\" format=\"ascii\">" << endl;
188 for (i = 0; i < numBlocks; ++i)
190 outfile << i * nvert + nvert <<
" ";
193 outfile <<
" </DataArray>" << endl;
194 outfile <<
" <DataArray type=\"UInt8\" "
195 <<
"Name=\"types\" format=\"ascii\">" << endl;
197 for (i = 0; i < numBlocks; ++i)
199 outfile << vtktype <<
" ";
202 outfile <<
" </DataArray>" << endl;
203 outfile <<
" </Cells>" << endl;
204 outfile <<
" <PointData>" << endl;
207 for (j = 0; j < nfields; ++j)
209 outfile <<
" <DataArray type=\"Float64\" Name=\""
210 <<
m_f->m_variables[j] <<
"\">" << endl;
212 for (i = 0; i < fPts->GetNpoints(); ++i)
214 outfile << fPts->GetPointVal(dim + j, i) <<
" ";
217 outfile <<
" </DataArray>" << endl;
220 outfile <<
" </PointData>" << endl;
221 outfile <<
" </Piece>" << endl;
224 cout <<
"Written file: " << filename << endl;
227 if ((
m_f->m_comm->GetSpaceComm()->GetRank() == 0) &&
228 (
m_f->m_comm->GetSpaceComm()->GetSize() != 1))
231 cout <<
"Written file: " << filename << endl;
242 ofstream outfile(filename.c_str());
244 int nfields =
m_f->m_variables.size();
247 m_f->m_session->LoadParameter(
"Strip_Z", nstrips, 1);
250 for (
int s = 0; s < nstrips; ++s)
253 for (i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
255 m_f->m_exp[0]->WriteVtkPieceHeader(outfile, i, s);
258 for (j = 0; j < nfields; ++j)
260 m_f->m_exp[s * nfields + j]->WriteVtkPieceData(
261 outfile, i,
m_f->m_variables[j]);
263 m_f->m_exp[0]->WriteVtkPieceFooter(outfile, i);
267 if (
m_f->m_exp[0]->GetNumElmts() == 0)
273 cout <<
"Written file: " << filename << endl;
276 if ((
m_f->m_comm->GetSpaceComm()->GetRank() == 0) &&
277 (
m_f->m_comm->GetSpaceComm()->GetSize() != 1))
285 boost::ignore_unused(vm);
287 "OutputVtk can't write using only FieldData. You may need "
288 "to add a mesh XML file to your input files.");
293 boost::ignore_unused(vm);
295 int nprocs =
m_f->m_comm->GetSpaceComm()->GetSize();
299 specPath = fs::path(filename);
304 int dot = filename.find_last_of(
'.');
305 string path = filename.substr(0, dot) +
"_vtu";
306 specPath = fs::path(path);
308 return fs::path(specPath);
312 po::variables_map &vm)
314 int nprocs =
m_f->m_comm->GetSpaceComm()->GetSize();
316 fs::path fulloutname;
319 fulloutname = filename;
325 pad %
m_f->m_comm->GetSpaceComm()->GetRank() %
"vtu";
328 fs::path specPath =
GetPath(filename, vm);
329 fs::path poutfile(pad.str());
330 fulloutname = specPath / poutfile;
337 outfile <<
"<?xml version=\"1.0\"?>" << endl;
338 outfile <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" "
339 <<
"byte_order=\"LittleEndian\">" << endl;
340 outfile <<
" <UnstructuredGrid>" << endl;
345 outfile <<
" </UnstructuredGrid>" << endl;
346 outfile <<
"</VTKFile>" << endl;
352 outfile <<
" <Piece NumberOfPoints=\"" << 0 <<
"\" NumberOfCells=\"" << 0
354 outfile <<
" <Points>" << endl;
355 outfile <<
" <DataArray type=\"Float64\" "
356 <<
"NumberOfComponents=\"" << 3 <<
"\" format=\"ascii\">" << endl;
357 outfile <<
" </DataArray>" << endl;
358 outfile <<
" </Points>" << endl;
359 outfile <<
" <Cells>" << endl;
360 outfile <<
" <DataArray type=\"Int32\" "
361 <<
"Name=\"connectivity\" format=\"ascii\">" << endl;
362 outfile <<
" </DataArray>" << endl;
363 outfile <<
" <DataArray type=\"Int32\" "
364 <<
"Name=\"offsets\" format=\"ascii\">" << endl;
368 outfile <<
" </DataArray>" << endl;
369 outfile <<
" <DataArray type=\"UInt8\" "
370 <<
"Name=\"types\" format=\"ascii\">" << endl;
373 outfile <<
" </DataArray>" << endl;
374 outfile <<
" </Cells>" << endl;
375 outfile <<
" <PointData>" << endl;
377 outfile <<
" </PointData>" << endl;
378 outfile <<
" </Piece>" << endl;
383 string filename =
m_config[
"outfile"].as<
string>();
384 int dot = filename.find_last_of(
'.');
385 string body = filename.substr(0, dot);
386 filename = body +
".pvtu";
388 ofstream outfile(filename.c_str());
390 int nprocs =
m_f->m_comm->GetSpaceComm()->GetSize();
393 outfile <<
"<?xml version=\"1.0\"?>" << endl;
394 outfile <<
"<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" "
395 <<
"byte_order=\"LittleEndian\">" << endl;
396 outfile <<
"<PUnstructuredGrid GhostLevel=\"0\">" << endl;
397 outfile <<
"<PPoints> " << endl;
398 outfile <<
"<PDataArray type=\"Float64\" NumberOfComponents=\"" << 3
400 outfile <<
"</PPoints>" << endl;
401 outfile <<
"<PCells>" << endl;
402 outfile <<
"<PDataArray type=\"Int32\" Name=\"connectivity\" "
403 "NumberOfComponents=\"1\"/>"
405 outfile <<
"<PDataArray type=\"Int32\" Name=\"offsets\" "
406 "NumberOfComponents=\"1\"/>"
408 outfile <<
"<PDataArray type=\"UInt8\" Name=\"types\" "
409 "NumberOfComponents=\"1\"/>"
411 outfile <<
"</PCells>" << endl;
412 outfile <<
"<PPointData Scalars=\"Material\">" << endl;
413 for (
int i = 0; i <
m_f->m_variables.size(); ++i)
415 outfile <<
"<PDataArray type=\"Float64\" Name=\"" <<
m_f->m_variables[i]
418 outfile <<
"</PPointData>" << endl;
420 for (
int i = 0; i < nprocs; ++i)
424 outfile <<
"<Piece Source=\"" << path <<
"/" << pad.str() <<
"\"/>"
427 outfile <<
"</PUnstructuredGrid>" << endl;
428 outfile <<
"</VTKFile>" << endl;
430 cout <<
"Written file: " << filename << endl;
436 string filename =
m_config[
"outfile"].as<
string>();
438 fs::path specPath =
GetPath(filename, vm);
442 if (
m_f->m_comm->GetSpaceComm()->GetSize() != 1)
444 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
448 fs::create_directory(specPath);
450 catch (fs::filesystem_error &e)
452 ASSERTL0(
false,
"Filesystem error: " +
string(e.what()));
454 cout <<
"Writing files to directory: " << specPath << endl;
456 m_f->m_comm->GetSpaceComm()->Block();
460 cout <<
"Writing: " << specPath << endl;
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
FieldSharedPtr m_f
Field object.
std::map< std::string, ConfigOption > m_config
List of configuration values.
Converter from fld to vtk.
fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
fs::path GetPath(std::string &filename, po::variables_map &vm)
std::string PrepareOutput(po::variables_map &vm)
void WriteEmptyVtkPiece(std::ofstream &outfile)
virtual fs::path v_GetFullOutName(std::string &filename, po::variables_map &vm) override
void WriteVtkHeader(std::ostream &outfile)
static ModuleKey m_className
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
virtual void v_OutputFromData(po::variables_map &vm) override
Write from data to output file.
OutputVtkBase(FieldSharedPtr f)
virtual fs::path v_GetPath(std::string &filename, po::variables_map &vm) override
void WritePVtu(po::variables_map &vm)
void WriteVtkFooter(std::ostream &outfile)
virtual void v_OutputFromExp(po::variables_map &vm) override
Write from m_exp to output file.
virtual void v_OutputFromPts(po::variables_map &vm) override
Write from pts to output file.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::shared_ptr< Field > FieldSharedPtr
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
std::shared_ptr< PtsField > PtsFieldSharedPtr
The above copyright notice and this permission notice shall be included.