Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
Nektar::Utilities::OutputVtk Class Reference

Converter for VTK files. More...

#include <OutputVtk.h>

Inheritance diagram for Nektar::Utilities::OutputVtk:
[legend]

Public Member Functions

 OutputVtk (NekMeshUtils::MeshSharedPtr m)
 
virtual ~OutputVtk ()
 
virtual void Process ()
 Write mesh to output file. More...
 
- Public Member Functions inherited from Nektar::NekMeshUtils::OutputModule
NEKMESHUTILS_EXPORT OutputModule (MeshSharedPtr p_m)
 
NEKMESHUTILS_EXPORT void OpenStream ()
 Open a file for output. More...
 
- Public Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT Module (MeshSharedPtr p_m)
 
NEKMESHUTILS_EXPORT void RegisterConfig (std::string key, std::string value=std::string())
 Register a configuration option with a module. More...
 
NEKMESHUTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
NEKMESHUTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
NEKMESHUTILS_EXPORT MeshSharedPtr GetMesh ()
 
virtual NEKMESHUTILS_EXPORT void ProcessVertices ()
 Extract element vertices. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessElements ()
 Generate element IDs. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessComposites ()
 Generate composites. More...
 
virtual NEKMESHUTILS_EXPORT void ClearElementLinks ()
 

Static Public Member Functions

static std::shared_ptr< Modulecreate (NekMeshUtils::MeshSharedPtr m)
 Creates an instance of this class. More...
 

Static Public Attributes

static NekMeshUtils::ModuleKey className
 

Private Member Functions

int GetVtkCellType (std::string pType)
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
NEKMESHUTILS_EXPORT void PrismLines (int prism, PerMap &perFaces, std::set< int > &prismsDone, std::vector< ElementSharedPtr > &line)
 
- Protected Attributes inherited from Nektar::NekMeshUtils::OutputModule
io::filtering_ostream m_mshFile
 Output stream. More...
 
std::ofstream m_mshFileStream
 Input stream. More...
 
- Protected Attributes inherited from Nektar::NekMeshUtils::Module
MeshSharedPtr m_mesh
 Mesh object. More...
 
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 

Detailed Description

Converter for VTK files.

Definition at line 46 of file utilities/NekMesh/OutputModules/OutputVtk.h.

Constructor & Destructor Documentation

◆ OutputVtk()

Nektar::Utilities::OutputVtk::OutputVtk ( NekMeshUtils::MeshSharedPtr  m)

Definition at line 57 of file utilities/NekMesh/OutputModules/OutputVtk.cpp.

57  : OutputModule(m)
58 {
59  m_config["uncompress"] = ConfigOption(true, "0", "Uncompress xml sections");
60  m_config["legacy"] = ConfigOption(true, "0", "Output in legacy format");
61 }
std::map< std::string, ConfigOption > m_config
List of configuration values.
NEKMESHUTILS_EXPORT OutputModule(MeshSharedPtr p_m)
Represents a command-line configuration option.

References Nektar::NekMeshUtils::Module::m_config.

◆ ~OutputVtk()

Nektar::Utilities::OutputVtk::~OutputVtk ( )
virtual

Definition at line 63 of file utilities/NekMesh/OutputModules/OutputVtk.cpp.

64 {
65 }

Member Function Documentation

◆ create()

static std::shared_ptr<Module> Nektar::Utilities::OutputVtk::create ( NekMeshUtils::MeshSharedPtr  m)
inlinestatic

Creates an instance of this class.

Definition at line 52 of file utilities/NekMesh/OutputModules/OutputVtk.h.

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

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

◆ GetVtkCellType()

int Nektar::Utilities::OutputVtk::GetVtkCellType ( std::string  pType)
private

Definition at line 67 of file utilities/NekMesh/OutputModules/OutputVtk.cpp.

68 {
69  if (pType == "S")
70  {
71  return VTK_LINE;
72  }
73  else if (pType == "T")
74  {
75  return VTK_TRIANGLE;
76  }
77  else if (pType == "Q")
78  {
79  return VTK_QUAD;
80  }
81  else if (pType == "A")
82  {
83  return VTK_TETRA;
84  }
85  else if (pType == "P")
86  {
87  return VTK_PYRAMID;
88  }
89  else if (pType == "R")
90  {
91  return VTK_WEDGE;
92  }
93  else if (pType == "H")
94  {
95  return VTK_HEXAHEDRON;
96  }
97  else
98  {
99  ASSERTL0(false, "Element type not supported.");
100  return 0;
101  }
102 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216

References ASSERTL0.

Referenced by Process().

◆ Process()

void Nektar::Utilities::OutputVtk::Process ( )
virtual

Write mesh to output file.

Implements Nektar::NekMeshUtils::Module.

Definition at line 104 of file utilities/NekMesh/OutputModules/OutputVtk.cpp.

105 {
106  if (m_mesh->m_verbose)
107  {
108  cout << "OutputVtk: Writing file..." << endl;
109  }
110 
111  vtkUnstructuredGrid *vtkMesh = vtkUnstructuredGrid::New();
112  vtkPoints *vtkPoints = vtkPoints::New();
113 
114  std::set<NodeSharedPtr> tmp(m_mesh->m_vertexSet.begin(),
115  m_mesh->m_vertexSet.end());
116 
117  for (auto &n : tmp)
118  {
119  vtkPoints->InsertPoint(n->m_id, n->m_x, n->m_y, n->m_z);
120  }
121 
122  vtkIdType p[8];
123  vector<ElementSharedPtr> &elmt = m_mesh->m_element[m_mesh->m_expDim];
124  for (int i = 0; i < elmt.size(); ++i)
125  {
126  int vertexCount = elmt[i]->GetVertexCount();
127  for (int j = 0; j < vertexCount; ++j)
128  {
129  p[j] = elmt[i]->GetVertex(j)->m_id;
130  }
131  // Adjust vertex order to the vtk convention
132  if (elmt[i]->GetTag() == "R")
133  {
134  std::swap(p[2], p[4]);
135  }
136  vtkMesh->InsertNextCell(GetVtkCellType(elmt[i]->GetTag()),
137  vertexCount, &p[0]);
138  }
139 
140  vtkMesh->SetPoints(vtkPoints);
141 
142  // Write out the new mesh in XML or legacy format
143  if (m_config["legacy"].beenSet)
144  {
145  vtkUnstructuredGridWriter *vtkMeshWriter = vtkUnstructuredGridWriter::New();
146  vtkMeshWriter->SetFileName(m_config["outfile"].as<string>().c_str());
147 
148 #if VTK_MAJOR_VERSION <= 5
149  vtkMeshWriter->SetInput(vtkMesh);
150 #else
151  vtkMeshWriter->SetInputData(vtkMesh);
152 #endif
153  vtkMeshWriter->Update();
154  }
155  else // XML format
156  {
157  vtkXMLUnstructuredGridWriter *vtkMeshWriter = vtkXMLUnstructuredGridWriter::New();
158  vtkMeshWriter->SetFileName(m_config["outfile"].as<string>().c_str());
159 
160 #if VTK_MAJOR_VERSION <= 5
161  vtkMeshWriter->SetInput(vtkMesh);
162 #else
163  vtkMeshWriter->SetInputData(vtkMesh);
164 #endif
165  if (m_config["uncompress"].beenSet)
166  {
167  vtkMeshWriter->SetDataModeToAscii();
168  }
169  vtkMeshWriter->Update();
170  }
171 }

References GetVtkCellType(), Nektar::NekMeshUtils::Module::m_config, Nektar::NekMeshUtils::Module::m_mesh, and CellMLToNektar.cellml_metadata::p.

Member Data Documentation

◆ className

ModuleKey Nektar::Utilities::OutputVtk::className
static
Initial value:
ModuleKey(eOutputModule, "vtk"), OutputVtk::create, "Writes a VTK file.")
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
static std::shared_ptr< Module > create(NekMeshUtils::MeshSharedPtr m)
Creates an instance of this class.
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()

Definition at line 56 of file utilities/NekMesh/OutputModules/OutputVtk.h.