40 #include <boost/core/ignore_unused.hpp>
41 #include <boost/format.hpp>
57 OutputVtkBase::create,
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->GetRank() == 0) && (
m_f->m_comm->GetSize() != 1))
230 cout <<
"Written file: " << filename << endl;
241 ofstream outfile(filename.c_str());
243 int nfields =
m_f->m_variables.size();
246 m_f->m_session->LoadParameter(
"Strip_Z", nstrips, 1);
249 for (
int s = 0; s < nstrips; ++s)
252 for (i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
254 m_f->m_exp[0]->WriteVtkPieceHeader(outfile, i, s);
257 for (j = 0; j < nfields; ++j)
259 m_f->m_exp[s * nfields + j]->WriteVtkPieceData(
260 outfile, i,
m_f->m_variables[j]);
262 m_f->m_exp[0]->WriteVtkPieceFooter(outfile, i);
266 if (
m_f->m_exp[0]->GetNumElmts() == 0)
272 cout <<
"Written file: " << filename << endl;
275 if ((
m_f->m_comm->GetRank() == 0) && (
m_f->m_comm->GetSize() != 1))
283 boost::ignore_unused(vm);
289 boost::ignore_unused(vm);
291 int nprocs =
m_f->m_comm->GetSize();
295 specPath = fs::path(filename);
300 int dot = filename.find_last_of(
'.');
301 string path = filename.substr(0, dot) +
"_vtu";
302 specPath = fs::path(path);
304 return fs::path(specPath);
308 po::variables_map &vm)
310 int nprocs =
m_f->m_comm->GetSize();
312 fs::path fulloutname;
315 fulloutname = filename;
321 pad %
m_f->m_comm->GetRank() %
"vtu";
324 fs::path specPath =
GetPath(filename, vm);
325 fs::path poutfile(pad.str());
326 fulloutname = specPath / poutfile;
333 outfile <<
"<?xml version=\"1.0\"?>" << endl;
334 outfile <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" "
335 <<
"byte_order=\"LittleEndian\">" << endl;
336 outfile <<
" <UnstructuredGrid>" << endl;
341 outfile <<
" </UnstructuredGrid>" << endl;
342 outfile <<
"</VTKFile>" << endl;
348 outfile <<
" <Piece NumberOfPoints=\"" << 0 <<
"\" NumberOfCells=\"" << 0
350 outfile <<
" <Points>" << endl;
351 outfile <<
" <DataArray type=\"Float64\" "
352 <<
"NumberOfComponents=\"" << 3 <<
"\" format=\"ascii\">" << endl;
353 outfile <<
" </DataArray>" << endl;
354 outfile <<
" </Points>" << endl;
355 outfile <<
" <Cells>" << endl;
356 outfile <<
" <DataArray type=\"Int32\" "
357 <<
"Name=\"connectivity\" format=\"ascii\">" << endl;
358 outfile <<
" </DataArray>" << endl;
359 outfile <<
" <DataArray type=\"Int32\" "
360 <<
"Name=\"offsets\" format=\"ascii\">" << endl;
364 outfile <<
" </DataArray>" << endl;
365 outfile <<
" <DataArray type=\"UInt8\" "
366 <<
"Name=\"types\" format=\"ascii\">" << endl;
369 outfile <<
" </DataArray>" << endl;
370 outfile <<
" </Cells>" << endl;
371 outfile <<
" <PointData>" << endl;
373 outfile <<
" </PointData>" << endl;
374 outfile <<
" </Piece>" << endl;
379 string filename =
m_config[
"outfile"].as<
string>();
380 int dot = filename.find_last_of(
'.');
381 string body = filename.substr(0, dot);
382 filename = body +
".pvtu";
384 ofstream outfile(filename.c_str());
386 int nprocs =
m_f->m_comm->GetSize();
389 outfile <<
"<?xml version=\"1.0\"?>" << endl;
390 outfile <<
"<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" "
391 <<
"byte_order=\"LittleEndian\">" << endl;
392 outfile <<
"<PUnstructuredGrid GhostLevel=\"0\">" << endl;
393 outfile <<
"<PPoints> " << endl;
394 outfile <<
"<PDataArray type=\"Float64\" NumberOfComponents=\"" << 3
396 outfile <<
"</PPoints>" << endl;
397 outfile <<
"<PCells>" << endl;
398 outfile <<
"<PDataArray type=\"Int32\" Name=\"connectivity\" "
399 "NumberOfComponents=\"1\"/>"
401 outfile <<
"<PDataArray type=\"Int32\" Name=\"offsets\" "
402 "NumberOfComponents=\"1\"/>"
404 outfile <<
"<PDataArray type=\"UInt8\" Name=\"types\" "
405 "NumberOfComponents=\"1\"/>"
407 outfile <<
"</PCells>" << endl;
408 outfile <<
"<PPointData Scalars=\"Material\">" << endl;
409 for (
int i = 0; i <
m_f->m_variables.size(); ++i)
411 outfile <<
"<PDataArray type=\"Float64\" Name=\"" <<
m_f->m_variables[i]
414 outfile <<
"</PPointData>" << endl;
416 for (
int i = 0; i < nprocs; ++i)
420 outfile <<
"<Piece Source=\"" << path <<
"/" << pad.str() <<
"\"/>"
423 outfile <<
"</PUnstructuredGrid>" << endl;
424 outfile <<
"</VTKFile>" << endl;
426 cout <<
"Written file: " << filename << endl;
432 string filename =
m_config[
"outfile"].as<
string>();
434 fs::path specPath =
GetPath(filename, vm);
438 if (
m_f->m_comm->GetSize() != 1)
440 if (
m_f->m_comm->TreatAsRankZero())
444 fs::create_directory(specPath);
446 catch (fs::filesystem_error &e)
448 ASSERTL0(
false,
"Filesystem error: " +
string(e.what()));
450 cout <<
"Writing files to directory: " << specPath << endl;
452 m_f->m_comm->Block();
456 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.
std::string PrepareOutput(po::variables_map &vm)
void WriteEmptyVtkPiece(std::ofstream &outfile)
virtual fs::path GetPath(std::string &filename, po::variables_map &vm)
virtual void OutputFromPts(po::variables_map &vm)
Write from pts to output file.
virtual fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
void WriteVtkHeader(std::ostream &outfile)
void WritePVtu(po::variables_map &vm)
virtual void OutputFromData(po::variables_map &vm)
Write from data to output file.
virtual void OutputFromExp(po::variables_map &vm)
Write from m_exp to output file.
void WriteVtkFooter(std::ostream &outfile)
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.