42 #include <boost/format.hpp>
75 if (
m_f->m_comm->TreatAsRankZero())
77 cout <<
"OutputVtk: Writing file..." << endl;
82 string filename =
m_config[
"outfile"].as<
string>();
86 if (
m_f->m_session->GetComm()->GetSize() != 1)
88 int dot = filename.find_last_of(
'.');
89 string ext = filename.substr(dot, filename.length() - dot);
90 string start = filename.substr(0, dot);
91 path = start +
"_vtu";
94 pad %
m_f->m_session->GetComm()->GetRank();
97 fs::path poutfile(filename.c_str());
98 fs::path specPath(path.c_str());
100 if (
m_f->m_comm->TreatAsRankZero())
104 fs::create_directory(specPath);
106 catch (fs::filesystem_error &e)
108 ASSERTL0(
false,
"Filesystem error: " +
string(e.what()));
110 cout <<
"Writing files to directory: " << specPath << endl;
113 fs::path fulloutname = specPath / poutfile;
115 m_f->m_comm->Block();
119 fs::path specPath(filename.c_str());
120 cout <<
"Writing: " << specPath << endl;
125 ofstream outfile(filename.c_str());
126 m_f->m_exp[0]->WriteVtkHeader(outfile);
130 vector<string> fieldname;
135 if (
m_f->m_fielddef.size() == 0)
141 nfields =
m_f->m_fielddef[0]->m_fields.size();
143 m_f->m_session->LoadParameter(
"Strip_Z", nstrips, 1);
146 for (
int s = 0; s < nstrips; ++s)
149 for (i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
151 m_f->m_exp[0]->WriteVtkPieceHeader(outfile, i, s);
154 for (j = 0; j < nfields; ++j)
156 m_f->m_exp[s * nfields + j]->WriteVtkPieceData(
157 outfile, i,
m_f->m_fielddef[0]->m_fields[j]);
159 m_f->m_exp[0]->WriteVtkPieceFooter(outfile, i);
163 if (
m_f->m_exp[0]->GetNumElmts() == 0)
168 for (i = 0; i < nfields; ++i)
170 fieldname.push_back(
m_f->m_fielddef[0]->m_fields[i]);
179 dim = fPts->GetDim();
182 switch (fPts->GetPtsType())
188 "VTK output needs setting up for ePtsFile and ePtsLine");
193 ASSERTL0(
false,
"VTK output needs settig up for PtsPlane");
198 ASSERTL0(
false,
"VTK output needs settig up for PtsBox");
220 ASSERTL0(
false,
"ptsType not supported yet.");
223 vector<Array<OneD, int> > ptsConn;
224 fPts->GetConnectivity(ptsConn);
226 nfields = fPts->GetNFields();
228 int nPts = fPts->GetNpoints();
230 for (i = 0; i < ptsConn.size(); ++i)
232 numBlocks += ptsConn[i].num_elements() / nvert;
236 outfile <<
" <Piece NumberOfPoints=\"" << nPts
237 <<
"\" NumberOfCells=\"" << numBlocks <<
"\">" << endl;
238 outfile <<
" <Points>" << endl;
239 outfile <<
" <DataArray type=\"Float64\" "
240 <<
"NumberOfComponents=\"" << 3 <<
"\" format=\"ascii\">"
242 for (i = 0; i < nPts; ++i)
244 for (j = 0; j < dim; ++j)
246 outfile <<
" " << setprecision(8) << scientific
247 << fPts->GetPointVal(j, i) <<
" ";
252 outfile <<
" 0.000000";
256 outfile <<
" </DataArray>" << endl;
257 outfile <<
" </Points>" << endl;
258 outfile <<
" <Cells>" << endl;
259 outfile <<
" <DataArray type=\"Int32\" "
260 <<
"Name=\"connectivity\" format=\"ascii\">" << endl;
265 for (i = 0; i < ptsConn.size(); ++i)
267 for (j = 0; j < ptsConn[i].num_elements(); ++j)
269 outfile << ptsConn[i][j] <<
" ";
270 if ((!(cnt % nvert)) && cnt)
272 outfile << std::endl;
278 outfile <<
" </DataArray>" << endl;
279 outfile <<
" <DataArray type=\"Int32\" "
280 <<
"Name=\"offsets\" format=\"ascii\">" << endl;
283 for (i = 0; i < numBlocks; ++i)
285 outfile << i * nvert + nvert <<
" ";
288 outfile <<
" </DataArray>" << endl;
289 outfile <<
" <DataArray type=\"UInt8\" "
290 <<
"Name=\"types\" format=\"ascii\">" << endl;
292 for (i = 0; i < numBlocks; ++i)
294 outfile << vtktype <<
" ";
297 outfile <<
" </DataArray>" << endl;
298 outfile <<
" </Cells>" << endl;
299 outfile <<
" <PointData>" << endl;
302 for (j = 0; j < nfields; ++j)
304 fieldname.push_back(fPts->GetFieldName(j));
305 outfile <<
" <DataArray type=\"Float64\" Name=\""
306 << fPts->GetFieldName(j) <<
"\">" << endl;
308 for (i = 0; i < fPts->GetNpoints(); ++i)
310 outfile << fPts->GetPointVal(dim + j, i) <<
" ";
313 outfile <<
" </DataArray>" << endl;
316 outfile <<
" </PointData>" << endl;
317 outfile <<
" </Piece>" << endl;
320 m_f->m_exp[0]->WriteVtkFooter(outfile);
321 cout <<
"Written file: " << filename << endl;
324 if (
m_f->m_comm->GetRank() == 0)
326 ASSERTL1(fieldname.size() == nfields,
327 "fieldname not the same size as nfields");
328 int nprocs =
m_f->m_comm->GetSize();
331 filename =
m_config[
"outfile"].as<
string>();
332 int dot = filename.find_last_of(
'.');
333 string body = filename.substr(0, dot);
334 filename = body +
".pvtu";
336 ofstream outfile(filename.c_str());
338 outfile <<
"<?xml version=\"1.0\"?>" << endl;
339 outfile <<
"<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" "
340 <<
"byte_order=\"LittleEndian\">" << endl;
341 outfile <<
"<PUnstructuredGrid GhostLevel=\"0\">" << endl;
342 outfile <<
"<PPoints> " << endl;
343 outfile <<
"<PDataArray type=\"Float64\" NumberOfComponents=\"" << 3
345 outfile <<
"</PPoints>" << endl;
346 outfile <<
"<PCells>" << endl;
347 outfile <<
"<PDataArray type=\"Int32\" Name=\"connectivity\" "
348 "NumberOfComponents=\"1\"/>"
350 outfile <<
"<PDataArray type=\"Int32\" Name=\"offsets\" "
351 "NumberOfComponents=\"1\"/>"
353 outfile <<
"<PDataArray type=\"UInt8\" Name=\"types\" "
354 "NumberOfComponents=\"1\"/>"
356 outfile <<
"</PCells>" << endl;
357 outfile <<
"<PPointData Scalars=\"Material\">" << endl;
358 for (
int i = 0; i < nfields; ++i)
360 outfile <<
"<PDataArray type=\"Float64\" Name=\""
361 << fieldname[i] <<
"\"/>" << endl;
363 outfile <<
"</PPointData>" << endl;
365 for (
int i = 0; i < nprocs; ++i)
369 outfile <<
"<Piece Source=\"" << path <<
"/" << pad.str()
372 outfile <<
"</PUnstructuredGrid>" << endl;
373 outfile <<
"</VTKFile>" << endl;
374 cout <<
"Written file: " << filename << endl;
382 outfile <<
" <Piece NumberOfPoints=\"" << 0 <<
"\" NumberOfCells=\"" << 0
384 outfile <<
" <Points>" << endl;
385 outfile <<
" <DataArray type=\"Float64\" "
386 <<
"NumberOfComponents=\"" << 3 <<
"\" format=\"ascii\">" << endl;
387 outfile <<
" </DataArray>" << endl;
388 outfile <<
" </Points>" << endl;
389 outfile <<
" <Cells>" << endl;
390 outfile <<
" <DataArray type=\"Int32\" "
391 <<
"Name=\"connectivity\" format=\"ascii\">" << endl;
392 outfile <<
" </DataArray>" << endl;
393 outfile <<
" <DataArray type=\"Int32\" "
394 <<
"Name=\"offsets\" format=\"ascii\">" << endl;
398 outfile <<
" </DataArray>" << endl;
399 outfile <<
" <DataArray type=\"UInt8\" "
400 <<
"Name=\"types\" format=\"ascii\">" << endl;
403 outfile <<
" </DataArray>" << endl;
404 outfile <<
" </Cells>" << endl;
405 outfile <<
" <PointData>" << endl;
407 outfile <<
" </PointData>" << endl;
408 outfile <<
" </Piece>" << endl;
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
pair< ModuleType, string > ModuleKey
virtual void Process(po::variables_map &vm)
Write fld to output file.
boost::shared_ptr< PtsField > PtsFieldSharedPtr
boost::shared_ptr< Field > FieldSharedPtr
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
static PtsFieldSharedPtr NullPtsField
void WriteEmptyVtkPiece(std::ofstream &outfile)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Abstract base class for output modules.
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.