40 #include <boost/core/ignore_unused.hpp>
41 #include <boost/format.hpp>
73 ofstream outfile(filename.c_str());
76 int dim = fPts->GetDim();
80 switch (fPts->GetPtsType())
86 "VTK output needs setting up for ePtsFile and ePtsLine");
92 "VTK output needs setting up for PtsPlane");
98 "VTK output needs setting up for PtsBox");
123 vector<Array<OneD, int> > ptsConn;
124 fPts->GetConnectivity(ptsConn);
126 nfields = fPts->GetNFields();
128 int nPts = fPts->GetNpoints();
130 for (i = 0; i < ptsConn.size(); ++i)
132 numBlocks += ptsConn[i].size() / nvert;
136 outfile <<
" <Piece NumberOfPoints=\"" << nPts
137 <<
"\" NumberOfCells=\"" << numBlocks <<
"\">" << endl;
138 outfile <<
" <Points>" << endl;
139 outfile <<
" <DataArray type=\"Float64\" "
140 <<
"NumberOfComponents=\"" << 3 <<
"\" format=\"ascii\">"
142 for (i = 0; i < nPts; ++i)
144 for (j = 0; j < dim; ++j)
146 outfile <<
" " << setprecision(8) << scientific
147 << fPts->GetPointVal(j, i) <<
" ";
149 for (j = dim; j < 3; ++j)
152 outfile <<
" 0.000000";
156 outfile <<
" </DataArray>" << endl;
157 outfile <<
" </Points>" << endl;
158 outfile <<
" <Cells>" << endl;
159 outfile <<
" <DataArray type=\"Int32\" "
160 <<
"Name=\"connectivity\" format=\"ascii\">" << endl;
165 for (i = 0; i < ptsConn.size(); ++i)
167 for (j = 0; j < ptsConn[i].size(); ++j)
169 outfile << ptsConn[i][j] <<
" ";
170 if ((!(cnt % nvert)) && cnt)
172 outfile << std::endl;
178 outfile <<
" </DataArray>" << endl;
179 outfile <<
" <DataArray type=\"Int32\" "
180 <<
"Name=\"offsets\" format=\"ascii\">" << endl;
183 for (i = 0; i < numBlocks; ++i)
185 outfile << i * nvert + nvert <<
" ";
188 outfile <<
" </DataArray>" << endl;
189 outfile <<
" <DataArray type=\"UInt8\" "
190 <<
"Name=\"types\" format=\"ascii\">" << endl;
192 for (i = 0; i < numBlocks; ++i)
194 outfile << vtktype <<
" ";
197 outfile <<
" </DataArray>" << endl;
198 outfile <<
" </Cells>" << endl;
199 outfile <<
" <PointData>" << endl;
202 for (j = 0; j < nfields; ++j)
204 outfile <<
" <DataArray type=\"Float64\" Name=\""
205 <<
m_f->m_variables[j] <<
"\">" << endl;
207 for (i = 0; i < fPts->GetNpoints(); ++i)
209 outfile << fPts->GetPointVal(dim + j, i) <<
" ";
212 outfile <<
" </DataArray>" << endl;
215 outfile <<
" </PointData>" << endl;
216 outfile <<
" </Piece>" << endl;
219 cout <<
"Written file: " << filename << endl;
222 if ( (
m_f->m_comm->GetRank() == 0) &&
223 (
m_f->m_comm->GetSize() != 1))
226 cout <<
"Written file: " << filename << endl;
237 ofstream outfile(filename.c_str());
239 int nfields =
m_f->m_variables.size();
242 m_f->m_session->LoadParameter(
"Strip_Z", nstrips, 1);
245 for (
int s = 0; s < nstrips; ++s)
248 for (i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
250 m_f->m_exp[0]->WriteVtkPieceHeader(outfile, i, s);
253 for (j = 0; j < nfields; ++j)
255 m_f->m_exp[s * nfields + j]->WriteVtkPieceData(
256 outfile, i,
m_f->m_variables[j]);
258 m_f->m_exp[0]->WriteVtkPieceFooter(outfile, i);
262 if (
m_f->m_exp[0]->GetNumElmts() == 0)
268 cout <<
"Written file: " << filename << endl;
271 if ( (
m_f->m_comm->GetRank() == 0) &&
272 (
m_f->m_comm->GetSize() != 1))
280 boost::ignore_unused(vm);
285 po::variables_map &vm)
287 boost::ignore_unused(vm);
289 int nprocs =
m_f->m_comm->GetSize();
293 specPath = fs::path(filename);
298 int dot = filename.find_last_of(
'.');
299 string path = filename.substr(0, dot) +
"_vtu";
300 specPath = fs::path(path);
302 return fs::path(specPath);
306 po::variables_map &vm)
308 int nprocs =
m_f->m_comm->GetSize();
310 fs::path fulloutname;
313 fulloutname = filename;
319 pad %
m_f->m_comm->GetRank() %
"vtu";
322 fs::path specPath =
GetPath(filename, vm);
323 fs::path poutfile(pad.str());
324 fulloutname = specPath / poutfile;
331 outfile <<
"<?xml version=\"1.0\"?>" << endl;
332 outfile <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" "
333 <<
"byte_order=\"LittleEndian\">" << endl;
334 outfile <<
" <UnstructuredGrid>" << endl;
339 outfile <<
" </UnstructuredGrid>" << endl;
340 outfile <<
"</VTKFile>" << endl;
346 outfile <<
" <Piece NumberOfPoints=\"" << 0 <<
"\" NumberOfCells=\"" << 0
348 outfile <<
" <Points>" << endl;
349 outfile <<
" <DataArray type=\"Float64\" "
350 <<
"NumberOfComponents=\"" << 3 <<
"\" format=\"ascii\">" << endl;
351 outfile <<
" </DataArray>" << endl;
352 outfile <<
" </Points>" << endl;
353 outfile <<
" <Cells>" << endl;
354 outfile <<
" <DataArray type=\"Int32\" "
355 <<
"Name=\"connectivity\" format=\"ascii\">" << endl;
356 outfile <<
" </DataArray>" << endl;
357 outfile <<
" <DataArray type=\"Int32\" "
358 <<
"Name=\"offsets\" format=\"ascii\">" << endl;
362 outfile <<
" </DataArray>" << endl;
363 outfile <<
" <DataArray type=\"UInt8\" "
364 <<
"Name=\"types\" format=\"ascii\">" << endl;
367 outfile <<
" </DataArray>" << endl;
368 outfile <<
" </Cells>" << endl;
369 outfile <<
" <PointData>" << endl;
371 outfile <<
" </PointData>" << endl;
372 outfile <<
" </Piece>" << endl;
377 string filename =
m_config[
"outfile"].as<
string>();
378 int dot = filename.find_last_of(
'.');
379 string body = filename.substr(0, dot);
380 filename = body +
".pvtu";
382 ofstream outfile(filename.c_str());
384 int nprocs =
m_f->m_comm->GetSize();
387 outfile <<
"<?xml version=\"1.0\"?>" << endl;
388 outfile <<
"<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" "
389 <<
"byte_order=\"LittleEndian\">" << endl;
390 outfile <<
"<PUnstructuredGrid GhostLevel=\"0\">" << endl;
391 outfile <<
"<PPoints> " << endl;
392 outfile <<
"<PDataArray type=\"Float64\" NumberOfComponents=\"" << 3
394 outfile <<
"</PPoints>" << endl;
395 outfile <<
"<PCells>" << endl;
396 outfile <<
"<PDataArray type=\"Int32\" Name=\"connectivity\" "
397 "NumberOfComponents=\"1\"/>"
399 outfile <<
"<PDataArray type=\"Int32\" Name=\"offsets\" "
400 "NumberOfComponents=\"1\"/>"
402 outfile <<
"<PDataArray type=\"UInt8\" Name=\"types\" "
403 "NumberOfComponents=\"1\"/>"
405 outfile <<
"</PCells>" << endl;
406 outfile <<
"<PPointData Scalars=\"Material\">" << endl;
407 for (
int i = 0; i <
m_f->m_variables.size(); ++i)
409 outfile <<
"<PDataArray type=\"Float64\" Name=\""
410 <<
m_f->m_variables[i] <<
"\"/>" << endl;
412 outfile <<
"</PPointData>" << endl;
414 for (
int i = 0; i < nprocs; ++i)
418 outfile <<
"<Piece Source=\"" << path <<
"/" << pad.str()
421 outfile <<
"</PUnstructuredGrid>" << endl;
422 outfile <<
"</VTKFile>" << endl;
424 cout <<
"Written file: " << filename << endl;
430 string filename =
m_config[
"outfile"].as<
string>();
432 fs::path specPath =
GetPath(filename,vm);
436 if (
m_f->m_comm->GetSize() != 1)
438 if (
m_f->m_comm->TreatAsRankZero())
442 fs::create_directory(specPath);
444 catch (fs::filesystem_error &e)
446 ASSERTL0(
false,
"Filesystem error: " +
string(e.what()));
448 cout <<
"Writing files to directory: " << specPath << endl;
450 m_f->m_comm->Block();
454 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.
virtual void OutputFromPts(po::variables_map &vm)
Write from pts to output file.
virtual fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
virtual fs::path GetPath(std::string &filename, po::variables_map &vm)
void WriteVtkHeader(std::ostream &outfile)
void WriteVtkFooter(std::ostream &outfile)
void WriteEmptyVtkPiece(std::ofstream &outfile)
virtual void OutputFromExp(po::variables_map &vm)
Write from m_exp to output file.
std::string PrepareOutput(po::variables_map &vm)
virtual void OutputFromData(po::variables_map &vm)
Write from data to output file.
void WritePVtu(po::variables_map &vm)
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.