Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | List of all members
Nektar::FieldUtils::OutputVtkBase Class Reference

Converter from fld to vtk. More...

#include <OutputVtkBase.h>

Inheritance diagram for Nektar::FieldUtils::OutputVtkBase:
[legend]

Public Member Functions

 OutputVtkBase (FieldSharedPtr f)
 
 ~OutputVtkBase () override
 
- Public Member Functions inherited from Nektar::FieldUtils::OutputFileBase
 OutputFileBase (FieldSharedPtr f)
 
 ~OutputFileBase () override
 
- Public Member Functions inherited from Nektar::FieldUtils::OutputModule
 OutputModule (FieldSharedPtr p_f)
 
FIELD_UTILS_EXPORT void OpenStream ()
 Open a file for output.
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
virtual ~Module ()=default
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
std::vector< ModuleKeyGetModulePrerequisites ()
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::string value="")
 Register a configuration option with a module.
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module.
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set.
 
FIELD_UTILS_EXPORT void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static std::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class.
 

Static Public Attributes

static ModuleKey m_className
 

Protected Member Functions

std::string v_GetModuleName () override
 
void v_OutputFromPts (po::variables_map &vm) override
 Write from pts to output file.
 
void v_OutputFromExp (po::variables_map &vm) override
 Write from m_exp to output file.
 
void v_OutputFromData (po::variables_map &vm) override
 Write from data to output file.
 
fs::path v_GetPath (std::string &filename, po::variables_map &vm) override
 
fs::path v_GetFullOutName (std::string &filename, po::variables_map &vm) override
 
std::string PrepareOutput (po::variables_map &vm)
 
- Protected Member Functions inherited from Nektar::FieldUtils::OutputFileBase
void v_Process (po::variables_map &vm) override
 Write fld to output file.
 
std::string v_GetModuleDescription () override
 
ModulePriority v_GetModulePriority () override
 
fs::path GetPath (std::string &filename, po::variables_map &vm)
 
fs::path GetFullOutName (std::string &filename, po::variables_map &vm)
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
virtual std::vector< ModuleKeyv_GetModulePrerequisites ()
 

Private Member Functions

void WriteVtkHeader (std::ostream &outfile)
 
void WriteVtkFooter (std::ostream &outfile)
 
void WriteEmptyVtkPiece (std::ofstream &outfile)
 
void WritePVtu (po::variables_map &vm)
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object.
 
- Protected Attributes inherited from Nektar::FieldUtils::OutputFileBase
bool m_requireEquiSpaced
 
bool m_prohibitWrite = false
 
bool m_equispacedSetup = false
 
- Protected Attributes inherited from Nektar::FieldUtils::OutputModule
std::ofstream m_fldFile
 Output stream.
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values.
 
std::set< std::string > m_allowedFiles
 List of allowed file formats.
 

Detailed Description

Converter from fld to vtk.

Definition at line 45 of file OutputVtkBase.h.

Constructor & Destructor Documentation

◆ OutputVtkBase()

Nektar::FieldUtils::OutputVtkBase::OutputVtkBase ( FieldSharedPtr  f)

◆ ~OutputVtkBase()

Nektar::FieldUtils::OutputVtkBase::~OutputVtkBase ( )
override

Definition at line 63 of file OutputVtkBase.cpp.

64{
65}

Member Function Documentation

◆ create()

static std::shared_ptr< Module > Nektar::FieldUtils::OutputVtkBase::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 49 of file OutputVtkBase.h.

50 {
52 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ PrepareOutput()

std::string OutputVtkBase::PrepareOutput ( po::variables_map &  vm)
protected

Definition at line 428 of file OutputVtkBase.cpp.

429{
430 // Extract the output filename and extension
431 string filename = m_config["outfile"].as<string>();
432
433 ASSERTL0(filename != "", "Legacy VTK output requires a filename.");
434
435 fs::path specPath = GetPath(filename, vm);
436 fs::path fulloutname = GetFullOutName(filename, vm);
437 filename = LibUtilities::PortablePath(fulloutname);
438
439 if (m_f->m_comm->GetSpaceComm()->GetSize() != 1)
440 {
441 if (m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
442 {
443 try
444 {
445 fs::create_directory(specPath);
446 }
447 catch (fs::filesystem_error &e)
448 {
449 ASSERTL0(false, "Filesystem error: " + string(e.what()));
450 }
451 cout << "Writing files to directory: " << specPath << endl;
452 }
453 m_f->m_comm->GetSpaceComm()->Block();
454 }
455 else
456 {
457 cout << "Writing: " << specPath << endl;
458 }
459 return filename;
460}
#define ASSERTL0(condition, msg)
FieldSharedPtr m_f
Field object.
Definition Module.h:239
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition Module.h:272
fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
fs::path GetPath(std::string &filename, po::variables_map &vm)
static std::string PortablePath(const fs::path &path)
create portable path on different platforms for std::filesystem path.

References ASSERTL0, Nektar::FieldUtils::OutputFileBase::GetFullOutName(), Nektar::FieldUtils::OutputFileBase::GetPath(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, and Nektar::LibUtilities::PortablePath().

Referenced by Nektar::FieldUtils::OutputVtk::v_OutputFromExp(), v_OutputFromExp(), and v_OutputFromPts().

◆ v_GetFullOutName()

fs::path OutputVtkBase::v_GetFullOutName ( std::string &  filename,
po::variables_map &  vm 
)
overrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::OutputFileBase.

Definition at line 306 of file OutputVtkBase.cpp.

308{
309 int nprocs = m_f->m_comm->GetSpaceComm()->GetSize();
310
311 fs::path fulloutname;
312 if (nprocs == 1)
313 {
314 fulloutname = filename;
315 }
316 else
317 {
318 // Guess at filename that might belong to this process.
319 boost::format pad("P%1$07d.%2$s");
320 pad % m_f->m_comm->GetSpaceComm()->GetRank() % "vtu";
321
322 // Generate full path name
323 fs::path specPath = GetPath(filename, vm);
324 fs::path poutfile(pad.str());
325 fulloutname = specPath / poutfile;
326 }
327 return fulloutname;
328}

References Nektar::FieldUtils::OutputFileBase::GetPath(), and Nektar::FieldUtils::Module::m_f.

◆ v_GetModuleName()

std::string Nektar::FieldUtils::OutputVtkBase::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::OutputFileBase.

Definition at line 59 of file OutputVtkBase.h.

60 {
61 return "OutputVtk";
62 }

◆ v_GetPath()

fs::path OutputVtkBase::v_GetPath ( std::string &  filename,
po::variables_map &  vm 
)
overrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::OutputFileBase.

Definition at line 287 of file OutputVtkBase.cpp.

289{
290 int nprocs = m_f->m_comm->GetSpaceComm()->GetSize();
291 fs::path specPath;
292 if (nprocs == 1)
293 {
294 specPath = fs::path(filename);
295 }
296 else
297 {
298 // replace .vtu by _vtu
299 int dot = filename.find_last_of('.');
300 string path = filename.substr(0, dot) + "_vtu";
301 specPath = fs::path(path);
302 }
303 return fs::path(specPath);
304}

References Nektar::FieldUtils::Module::m_f.

Referenced by Nektar::FieldUtils::OutputVtk::WritePVtu().

◆ v_OutputFromData()

void OutputVtkBase::v_OutputFromData ( po::variables_map &  vm)
overrideprotectedvirtual

Write from data to output file.

Implements Nektar::FieldUtils::OutputFileBase.

Definition at line 280 of file OutputVtkBase.cpp.

281{
283 "OutputVtk can't write using only FieldData. You may need "
284 "to add a mesh XML file to your input files.");
285}
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...

References Nektar::ErrorUtil::efatal, and NEKERROR.

◆ v_OutputFromExp()

void OutputVtkBase::v_OutputFromExp ( po::variables_map &  vm)
overrideprotectedvirtual

Write from m_exp to output file.

Implements Nektar::FieldUtils::OutputFileBase.

Definition at line 232 of file OutputVtkBase.cpp.

233{
234 int i, j;
235 // Extract the output filename and extension
236 string filename = PrepareOutput(vm);
237
238 // Write solution.
239 ofstream outfile(filename.c_str());
240 WriteVtkHeader(outfile);
241 int nfields = m_f->m_variables.size();
242
243 int nstrips;
244 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
245
246 // Homogeneous strip variant
247 for (int s = 0; s < nstrips; ++s)
248 {
249 // For each field write out field data for each expansion.
250 for (i = 0; i < m_f->m_exp[0]->GetNumElmts(); ++i)
251 {
252 m_f->m_exp[0]->WriteVtkPieceHeader(outfile, i, s);
253
254 // For this expansion write out each field.
255 for (j = 0; j < nfields; ++j)
256 {
257 m_f->m_exp[s * nfields + j]->WriteVtkPieceData(
258 outfile, i, m_f->m_variables[j]);
259 }
260 m_f->m_exp[0]->WriteVtkPieceFooter(outfile, i);
261 }
262 }
263
264 if (m_f->m_exp[0]->GetNumElmts() == 0)
265 {
266 WriteEmptyVtkPiece(outfile);
267 }
268
269 WriteVtkFooter(outfile);
270 cout << "Written file: " << filename << endl;
271
272 // output parallel outline info if necessary
273 if ((m_f->m_comm->GetSpaceComm()->GetRank() == 0) &&
274 (m_f->m_comm->GetSpaceComm()->GetSize() != 1))
275 {
276 WritePVtu(vm);
277 }
278}
void WriteVtkHeader(std::ostream &outfile)
void WritePVtu(po::variables_map &vm)
void WriteEmptyVtkPiece(std::ofstream &outfile)
std::string PrepareOutput(po::variables_map &vm)
void WriteVtkFooter(std::ostream &outfile)

References Nektar::FieldUtils::Module::m_f, PrepareOutput(), WriteEmptyVtkPiece(), WritePVtu(), WriteVtkFooter(), and WriteVtkHeader().

Referenced by Nektar::FieldUtils::OutputVtk::v_OutputFromExp().

◆ v_OutputFromPts()

void Nektar::FieldUtils::OutputVtkBase::v_OutputFromPts ( po::variables_map &  vm)
overrideprotectedvirtual

◆ WriteEmptyVtkPiece()

void OutputVtkBase::WriteEmptyVtkPiece ( std::ofstream &  outfile)
private

Definition at line 344 of file OutputVtkBase.cpp.

345{
346 // write out empty piece of data.
347 outfile << " <Piece NumberOfPoints=\"" << 0 << "\" NumberOfCells=\"" << 0
348 << "\">" << endl;
349 outfile << " <Points>" << endl;
350 outfile << " <DataArray type=\"Float64\" "
351 << "NumberOfComponents=\"" << 3 << R"(" format="ascii">)" << endl;
352 outfile << " </DataArray>" << endl;
353 outfile << " </Points>" << endl;
354 outfile << " <Cells>" << endl;
355 outfile << " <DataArray type=\"Int32\" "
356 << R"(Name="connectivity" format="ascii">)" << endl;
357 outfile << " </DataArray>" << endl;
358 outfile << " <DataArray type=\"Int32\" "
359 << R"(Name="offsets" format="ascii">)" << endl;
360
361 outfile << " ";
362 outfile << endl;
363 outfile << " </DataArray>" << endl;
364 outfile << " <DataArray type=\"UInt8\" "
365 << R"(Name="types" format="ascii">)" << endl;
366 outfile << " ";
367 outfile << endl;
368 outfile << " </DataArray>" << endl;
369 outfile << " </Cells>" << endl;
370 outfile << " <PointData>" << endl;
371
372 outfile << " </PointData>" << endl;
373 outfile << " </Piece>" << endl;
374}

Referenced by v_OutputFromExp().

◆ WritePVtu()

void OutputVtkBase::WritePVtu ( po::variables_map &  vm)
private

Definition at line 376 of file OutputVtkBase.cpp.

377{
378 string filename = m_config["outfile"].as<string>();
379 int dot = filename.find_last_of('.');
380 string body = filename.substr(0, dot);
381 filename = body + ".pvtu";
382
383 ofstream outfile(filename.c_str());
384
385 int nprocs = m_f->m_comm->GetSpaceComm()->GetSize();
386 string path = LibUtilities::PortablePath(GetPath(filename, vm));
387
388 outfile << "<?xml version=\"1.0\"?>" << endl;
389 outfile << R"(<VTKFile type="PUnstructuredGrid" version="0.1" )"
390 << "byte_order=\"LittleEndian\">" << endl;
391 outfile << "<PUnstructuredGrid GhostLevel=\"0\">" << endl;
392 outfile << "<PPoints> " << endl;
393 outfile << R"(<PDataArray type="Float64" NumberOfComponents=")" << 3
394 << "\"/> " << endl;
395 outfile << "</PPoints>" << endl;
396 outfile << "<PCells>" << endl;
397 outfile << "<PDataArray type=\"Int32\" Name=\"connectivity\" "
398 "NumberOfComponents=\"1\"/>"
399 << endl;
400 outfile << "<PDataArray type=\"Int32\" Name=\"offsets\" "
401 "NumberOfComponents=\"1\"/>"
402 << endl;
403 outfile << "<PDataArray type=\"UInt8\" Name=\"types\" "
404 "NumberOfComponents=\"1\"/>"
405 << endl;
406 outfile << "</PCells>" << endl;
407 outfile << "<PPointData Scalars=\"Material\">" << endl;
408 for (int i = 0; i < m_f->m_variables.size(); ++i)
409 {
410 outfile << R"(<PDataArray type="Float64" Name=")" << m_f->m_variables[i]
411 << "\"/>" << endl;
412 }
413 outfile << "</PPointData>" << endl;
414
415 for (int i = 0; i < nprocs; ++i)
416 {
417 boost::format pad("P%1$07d.vtu");
418 pad % i;
419 outfile << "<Piece Source=\"" << path << "/" << pad.str() << "\"/>"
420 << endl;
421 }
422 outfile << "</PUnstructuredGrid>" << endl;
423 outfile << "</VTKFile>" << endl;
424
425 cout << "Written file: " << filename << endl;
426}

References Nektar::FieldUtils::OutputFileBase::GetPath(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, and Nektar::LibUtilities::PortablePath().

Referenced by v_OutputFromExp(), and v_OutputFromPts().

◆ WriteVtkFooter()

void OutputVtkBase::WriteVtkFooter ( std::ostream &  outfile)
private

Definition at line 338 of file OutputVtkBase.cpp.

339{
340 outfile << " </UnstructuredGrid>" << endl;
341 outfile << "</VTKFile>" << endl;
342}

Referenced by v_OutputFromExp(), and v_OutputFromPts().

◆ WriteVtkHeader()

void OutputVtkBase::WriteVtkHeader ( std::ostream &  outfile)
private

Definition at line 330 of file OutputVtkBase.cpp.

331{
332 outfile << "<?xml version=\"1.0\"?>" << endl;
333 outfile << R"(<VTKFile type="UnstructuredGrid" version="0.1" )"
334 << "byte_order=\"LittleEndian\">" << endl;
335 outfile << " <UnstructuredGrid>" << endl;
336}

Referenced by v_OutputFromExp(), and v_OutputFromPts().

Member Data Documentation

◆ m_className

ModuleKey Nektar::FieldUtils::OutputVtkBase::m_className
static
Initial value:
=
"Writes a VTU file.")
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::pair< ModuleType, std::string > ModuleKey
Definition Module.h:180
ModuleFactory & GetModuleFactory()
Definition Module.cpp:47

Definition at line 53 of file OutputVtkBase.h.