Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Nektar::Utilities::OutputVtk Class Reference

Converter from fld to vtk. More...

#include <OutputVtk.h>

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

Public Member Functions

 OutputVtk (FieldSharedPtr f)
 
virtual ~OutputVtk ()
 
virtual void Process (po::variables_map &vm)
 Write fld to output file. More...
 
 OutputVtk (MeshSharedPtr m)
 
virtual ~OutputVtk ()
 
virtual void Process ()
 Write mesh to output file. More...
 
- Public Member Functions inherited from Nektar::Utilities::OutputModule
 OutputModule (FieldSharedPtr p_f)
 
void OpenStream ()
 Open a file for output. More...
 
 OutputModule (MeshSharedPtr p_m)
 
void OpenStream ()
 
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
 
void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
void PrintConfig ()
 Print out all configuration options for a module. More...
 
void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
bool GetRequireEquiSpaced (void)
 
void SetRequireEquiSpaced (bool pVal)
 
void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 
 Module (MeshSharedPtr p_m)
 
void RegisterConfig (string key, string value)
 
void PrintConfig ()
 
void SetDefaults ()
 
MeshSharedPtr GetMesh ()
 
virtual void ProcessVertices ()
 Extract element vertices. More...
 
virtual void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual void ProcessElements ()
 Generate element IDs. More...
 
virtual void ProcessComposites ()
 Generate composites. More...
 
virtual void ClearElementLinks ()
 

Static Public Member Functions

static boost::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 
static boost::shared_ptr< Modulecreate (MeshSharedPtr m)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey m_className
 
static ModuleKey className
 

Additional Inherited Members

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

Detailed Description

Converter from fld to vtk.

Converter for Gmsh files.

Definition at line 48 of file FieldConvert/OutputModules/OutputVtk.h.

Constructor & Destructor Documentation

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

Definition at line 60 of file FieldConvert/OutputModules/OutputVtk.cpp.

61 {
62 }
Nektar::Utilities::OutputVtk::OutputVtk ( MeshSharedPtr  m)

Definition at line 56 of file NekMesh/OutputModules/OutputVtk.cpp.

56  : OutputModule(m)
57 {
58 }
virtual Nektar::Utilities::OutputVtk::~OutputVtk ( )
virtual

Member Function Documentation

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

Creates an instance of this class.

Definition at line 51 of file NekMesh/OutputModules/OutputVtk.h.

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

52  {
54  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
static boost::shared_ptr<Module> Nektar::Utilities::OutputVtk::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 52 of file FieldConvert/OutputModules/OutputVtk.h.

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

52  {
54  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Nektar::Utilities::OutputVtk::Process ( )
virtual

Write mesh to output file.

Implements Nektar::Utilities::Module.

Definition at line 64 of file NekMesh/OutputModules/OutputVtk.cpp.

References Nektar::iterator, Nektar::Utilities::Module::m_config, and Nektar::Utilities::Module::m_mesh.

65 {
66  if (m_mesh->m_verbose)
67  {
68  cout << "OutputVtk: Writing file..." << endl;
69  }
70 
71  vtkPolyData *vtkMesh = vtkPolyData::New();
72  vtkPoints *vtkPoints = vtkPoints::New();
73  vtkCellArray *vtkPolys = vtkCellArray::New();
74 
76 
77  std::set<NodeSharedPtr> tmp(m_mesh->m_vertexSet.begin(),
78  m_mesh->m_vertexSet.end());
79 
80  for (it = tmp.begin(); it != tmp.end(); ++it)
81  {
82  NodeSharedPtr n = *it;
83  vtkPoints->InsertPoint(n->m_id, n->m_x, n->m_y, n->m_z);
84  }
85 
86  vtkIdType p[8];
87  vector<ElementSharedPtr> &elmt = m_mesh->m_element[m_mesh->m_expDim];
88  for (int i = 0; i < elmt.size(); ++i)
89  {
90  int vertexCount = elmt[i]->GetVertexCount();
91  for (int j = 0; j < vertexCount; ++j)
92  {
93  p[j] = elmt[i]->GetVertex(j)->m_id;
94  }
95  vtkPolys->InsertNextCell(vertexCount, &p[0]);
96  }
97 
98  vtkMesh->SetPoints(vtkPoints);
99  vtkMesh->SetPolys(vtkPolys);
100 
101  // Write out the new mesh
102  vtkPolyDataWriter *vtkMeshWriter = vtkPolyDataWriter::New();
103  vtkMeshWriter->SetFileName(m_config["outfile"].as<string>().c_str());
104 #if VTK_MAJOR_VERSION <= 5
105  vtkMeshWriter->SetInput(vtkMesh);
106 #else
107  vtkMeshWriter->SetInputData(vtkMesh);
108 #endif
109  vtkMeshWriter->Update();
110 }
map< string, ConfigOption > m_config
List of configuration values.
MeshSharedPtr m_mesh
Mesh object.
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
void Nektar::Utilities::OutputVtk::Process ( po::variables_map &  vm)
virtual

Write fld to output file.

Implements Nektar::Utilities::Module.

Definition at line 64 of file FieldConvert/OutputModules/OutputVtk.cpp.

References ASSERTL0, ASSERTL1, Nektar::LibUtilities::ePtsFile, Nektar::LibUtilities::ePtsLine, Nektar::LibUtilities::ePtsPlane, Nektar::LibUtilities::ePtsTetBlock, Nektar::LibUtilities::ePtsTriBlock, Nektar::Utilities::Module::m_config, Nektar::Utilities::Module::m_f, Nektar::LibUtilities::NullPtsField, and Nektar::LibUtilities::PortablePath().

65 {
66  LibUtilities::PtsFieldSharedPtr fPts = m_f->m_fieldPts;
67 
68  // Do nothing if no expansion defined
69  if (fPts == LibUtilities::NullPtsField && !m_f->m_exp.size())
70  {
71  return;
72  }
73 
74  int i, j;
75  if (m_f->m_verbose)
76  {
77  cout << "OutputVtk: Writing file..." << endl;
78  }
79 
80  // Extract the output filename and extension
81  string filename = m_config["outfile"].as<string>();
82  string path;
83 
84  // amend for parallel output if required
85  if(m_f->m_session->GetComm()->GetSize() != 1)
86  {
87  int dot = filename.find_last_of('.');
88  string ext = filename.substr(dot,filename.length()-dot);
89  string start = filename.substr(0,dot);
90  path = start + "_vtu";
91 
92  boost::format pad("P%1$07d.vtu");
93  pad % m_f->m_session->GetComm()->GetRank();
94  filename = pad.str();
95 
96  fs::path poutfile(filename.c_str());
97  fs::path specPath(path.c_str());
98 
99  if(m_f->m_comm->GetRank() == 0)
100  {
101  try
102  {
103  fs::create_directory(specPath);
104  }
105  catch (fs::filesystem_error& e)
106  {
107  ASSERTL0(false, "Filesystem error: " + string(e.what()));
108  }
109  cout << "Writing files to directory: " << specPath << endl;
110  }
111 
112  fs::path fulloutname = specPath / poutfile;
113  filename = LibUtilities::PortablePath(fulloutname);
114  m_f->m_comm->Block();
115  }
116  else
117  {
118  fs::path specPath(filename.c_str());
119  cout << "Writing: " << specPath << endl;
120  filename = LibUtilities::PortablePath(specPath);
121  }
122 
123  // Write solution.
124  ofstream outfile(filename.c_str());
125  m_f->m_exp[0]->WriteVtkHeader(outfile);
126  int nfields = 0;
127  int dim = 0;
128 
129  vector<string> fieldname;
130  if(fPts == LibUtilities::NullPtsField) // standard output in collapsed coordinates
131  {
132  dim = m_f->m_exp[0]->GetExp(0)->GetCoordim();
133 
134  int nstrips;
135  if (m_f->m_fielddef.size() == 0)
136  {
137  nfields = 0;
138  }
139  else
140  {
141  nfields = m_f->m_fielddef[0]->m_fields.size();
142  }
143  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
144 
145  // Homogeneous strip variant
146  for(int s = 0; s < nstrips; ++s)
147  {
148  // For each field write out field data for each expansion.
149  for (i = 0; i < m_f->m_exp[0]->GetNumElmts(); ++i)
150  {
151  m_f->m_exp[0]->WriteVtkPieceHeader(outfile,i,s);
152 
153  // For this expansion write out each field.
154  for (j = 0; j < nfields; ++j)
155  {
156  m_f->m_exp[s*nfields+j]->WriteVtkPieceData(
157  outfile, i, m_f->m_fielddef[0]->m_fields[j]);
158  }
159  m_f->m_exp[0]->WriteVtkPieceFooter(outfile, i);
160  }
161  }
162 
163  // save field names for parallel output
164  for(i = 0; i < nfields; ++i)
165  {
166  fieldname.push_back(m_f->m_fielddef[0]->m_fields[i]);
167  }
168  }
169  else // write out data stored in fPts (for example if equispaced output is called).
170  {
171  int i = 0;
172  int j = 0;
173 
174  dim = fPts->GetDim();
175 
176  if(fPts->GetNpoints() == 0)
177  {
178  return;
179  }
180 
181  int nvert, vtktype;
182  switch(fPts->GetPtsType())
183  {
186  {
187  ASSERTL0(false,"VTK output needs settig up for PtsFile or Pts Line");
188  break;
189  }
191  {
192  ASSERTL0(false,"VTK output needs settig up for PtsPlane");
193  break;
194  }
196  {
197  nvert = 3;
198  vtktype = 5;
199  break;
200  }
202  {
203  nvert = 4;
204  vtktype = 10;
205  break;
206  }
207  default:
208  ASSERTL0(false, "ptsType not supported yet.");
209  }
210 
211  vector<Array<OneD, int> > ptsConn;
212  fPts->GetConnectivity(ptsConn);
213 
214  nfields = fPts->GetNFields();
215 
216  int nPts = fPts->GetNpoints();
217  int numBlocks = 0;
218  for(i = 0; i < ptsConn.size(); ++i)
219  {
220  numBlocks += ptsConn[i].num_elements()/nvert;
221  }
222 
223  // write out pieces of data.
224  outfile << " <Piece NumberOfPoints=\""
225  << nPts << "\" NumberOfCells=\""
226  << numBlocks << "\">" << endl;
227  outfile << " <Points>" << endl;
228  outfile << " <DataArray type=\"Float64\" "
229  << "NumberOfComponents=\""<<3<<"\" format=\"ascii\">" << endl;
230  for(i = 0; i < nPts; ++i)
231  {
232  for(j = 0; j < dim; ++j)
233  {
234  outfile << " " << setprecision(8) << scientific
235  << fPts->GetPointVal(j, i) << " ";
236  }
237  for(j = dim; j < 3; ++j) // pack to 3D since paraview does not seem to handle 2D
238  {
239  outfile << " 0.000000" ;
240  }
241  outfile << endl;
242  }
243  outfile << " </DataArray>" << endl;
244  outfile << " </Points>" << endl;
245  outfile << " <Cells>" << endl;
246  outfile << " <DataArray type=\"Int32\" "
247  << "Name=\"connectivity\" format=\"ascii\">" << endl;
248 
249  // dump connectivity data if it exists
250  outfile << " ";
251  int cnt = 1;
252  for(i = 0; i < ptsConn.size();++i)
253  {
254  for(j = 0; j < ptsConn[i].num_elements(); ++j)
255  {
256  outfile << ptsConn[i][j] << " ";
257  if( (!(cnt % nvert)) && cnt )
258  {
259  outfile << std::endl;
260  outfile << " ";
261  }
262  cnt ++;
263  }
264  }
265  outfile << " </DataArray>" << endl;
266  outfile << " <DataArray type=\"Int32\" "
267  << "Name=\"offsets\" format=\"ascii\">" << endl;
268 
269  outfile << " ";
270  for (i = 0; i < numBlocks; ++i)
271  {
272  outfile << i*nvert+nvert << " ";
273  }
274  outfile << endl;
275  outfile << " </DataArray>" << endl;
276  outfile << " <DataArray type=\"UInt8\" "
277  << "Name=\"types\" format=\"ascii\">" << endl;
278  outfile << " ";
279  for (i = 0; i < numBlocks; ++i)
280  {
281  outfile << vtktype <<" ";
282  }
283  outfile << endl;
284  outfile << " </DataArray>" << endl;
285  outfile << " </Cells>" << endl;
286  outfile << " <PointData>" << endl;
287 
288  // printing the fields
289  for(j = 0; j < nfields; ++j)
290  {
291  fieldname.push_back(fPts->GetFieldName(j));
292  outfile << " <DataArray type=\"Float64\" Name=\""
293  << fPts->GetFieldName(j) << "\">" << endl;
294  outfile << " ";
295  for(i = 0; i < fPts->GetNpoints(); ++i)
296  {
297  outfile << fPts->GetPointVal(dim+j, i) << " ";
298  }
299  outfile << endl;
300  outfile << " </DataArray>" << endl;
301  }
302 
303  outfile << " </PointData>" << endl;
304  outfile << " </Piece>" << endl;
305  }
306 
307 
308  m_f->m_exp[0]->WriteVtkFooter(outfile);
309  cout << "Written file: " << filename << endl;
310 
311 
312  // output parallel outline info if necessary
313  if(m_f->m_comm->GetRank() == 0)
314  {
315  ASSERTL1(fieldname.size() == nfields, "fieldname not the same size as nfields");
316  int nprocs = m_f->m_comm->GetSize();
317  if(nprocs != 1)
318  {
319  filename = m_config["outfile"].as<string>();
320  int dot = filename.find_last_of('.');
321  string body = filename.substr(0,dot);
322  filename = body + ".pvtu";
323 
324  ofstream outfile(filename.c_str());
325 
326  outfile << "<?xml version=\"1.0\"?>" << endl;
327  outfile << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" "
328  << "byte_order=\"LittleEndian\">" << endl;
329  outfile << "<PUnstructuredGrid GhostLevel=\"0\">" << endl;
330  outfile << "<PPoints> " << endl;
331  outfile << "<PDataArray type=\"Float64\" NumberOfComponents=\""
332  << 3 << "\"/> " << endl;
333  outfile << "</PPoints>" << endl;
334  outfile << "<PCells>" << endl;
335  outfile << "<PDataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\"/>" << endl;
336  outfile << "<PDataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\"/>" << endl;
337  outfile << "<PDataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\"/>" << endl;
338  outfile << "</PCells>" << endl;
339  outfile << "<PPointData Scalars=\"Material\">" << endl;
340  for(int i = 0; i < nfields; ++i)
341  {
342  outfile << "<PDataArray type=\"Float64\" Name=\"" <<
343  fieldname[i] << "\"/>" << endl;
344  }
345  outfile << "</PPointData>" << endl;
346 
347  for(int i = 0; i < nprocs; ++i)
348  {
349  boost::format pad("P%1$07d.vtu");
350  pad % i;
351  outfile << "<Piece Source=\"" << path << "/" << pad.str() << "\"/>" <<endl;
352  }
353  outfile << "</PUnstructuredGrid>" << endl;
354  outfile << "</VTKFile>" << endl;
355  cout << "Written file: " << filename << endl;
356  }
357  }
358 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
map< string, ConfigOption > m_config
List of configuration values.
FieldSharedPtr m_f
Field object.
boost::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:263
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
Definition: FileSystem.cpp:41
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:264
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:191

Member Data Documentation

ModuleKey Nektar::Utilities::OutputVtk::className
static
Initial value:

Definition at line 55 of file NekMesh/OutputModules/OutputVtk.h.

ModuleKey Nektar::Utilities::OutputVtk::m_className
static
Initial value:

Definition at line 55 of file FieldConvert/OutputModules/OutputVtk.h.