MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WallVTKWriter Class Referencefinal

#include <WallVTKWriter.h>

+ Inheritance diagram for WallVTKWriter:

Public Member Functions

 WallVTKWriter (WallHandler &wallHandler)
 Non-default constructor; sets the handler and fileCounter. More...
 
 WallVTKWriter (const WallVTKWriter &)=default
 Default copy constructor. More...
 
void getVTKData (VTKContainer &vtk) const
 extracts vtk data from the wallHandler and stores it in a VTKContainer More...
 
void writeVTK () const override
 writes a vtk file More...
 
std::string getName () const
 the name of the class in the restart file More...
 
- Public Member Functions inherited from BaseVTKWriter< WallHandler >
 BaseVTKWriter (WallHandler &handler)
 
 BaseVTKWriter (const BaseVTKWriter &other)
 
unsigned getFileCounter () const
 
void setFileCounter (unsigned fileCounter)
 

Protected Member Functions

void write (std::fstream &file, std::string name, std::function< double(BaseWall *)> f) const
 
void writeVTKPoints (std::fstream &file, VTKContainer &vtk) const
 writes the point data to the vtu file (i.e. More...
 
void writeVTKCells (std::fstream &file, VTKContainer &vtk) const
 writes the cell data to the vtu file (i.e. More...
 
- Protected Member Functions inherited from BaseVTKWriter< WallHandler >
std::fstream makeVTKFileWithHeader () const
 
void writeVTKFooterAndClose (std::fstream &file) const
 

Additional Inherited Members

- Protected Attributes inherited from BaseVTKWriter< WallHandler >
WallHandlerhandler_
 particle handler from which the particles should be written More...
 
unsigned int fileCounter
 

Detailed Description

Definition at line 33 of file WallVTKWriter.h.

Constructor & Destructor Documentation

WallVTKWriter::WallVTKWriter ( WallHandler wallHandler)
inlineexplicit

Non-default constructor; sets the handler and fileCounter.

Definition at line 41 of file WallVTKWriter.h.

41  : BaseVTKWriter(wallHandler)
42  {}
BaseVTKWriter(WallHandler &handler)
Definition: BaseVTKWriter.h:44
WallVTKWriter::WallVTKWriter ( const WallVTKWriter )
default

Default copy constructor.

Member Function Documentation

std::string WallVTKWriter::getName ( ) const
inline

the name of the class in the restart file

Definition at line 62 of file WallVTKWriter.h.

63  { return "WallVTKWriter"; }
void WallVTKWriter::getVTKData ( VTKContainer vtk) const

extracts vtk data from the wallHandler and stores it in a VTKContainer

Definition at line 30 of file WallVTKWriter.cc.

References BaseHandler< T >::getSize(), BaseVTKWriter< WallHandler >::handler_, VTKContainer::points, and VTKContainer::triangleStrips.

Referenced by writeVTK().

31 {
32  // set capacity of points and cells based on the previous time step
33  // the initial values are based on the minimum, which is one triangle per wall
34  static unsigned int capacityPoints = 3*handler_.getSize();
35  static unsigned int capacityTriangleStrips = handler_.getSize();
36  vtk.triangleStrips.reserve(capacityPoints);
37  vtk.points.reserve(capacityTriangleStrips);
38 
39  //add all wall data to the point and cell arrays
40  for (const auto& w: handler_)
41  {
42  w->renderWall(vtk);
43  }
44 
45 // logger(INFO, "size (capacity) of points: % (%), cells: % (%)", vtk.points.size(), capacityPoints, vtk.triangleStrips.size(), capacityTriangleStrips);
46 
47  //store from previous time step
48  capacityPoints = vtk.points.size();
49  capacityTriangleStrips = vtk.triangleStrips.size();
50 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
WallHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
std::vector< std::vector< double > > triangleStrips
Definition: BaseWall.h:39
std::vector< Vec3D > points
Definition: BaseWall.h:38
void WallVTKWriter::write ( std::fstream &  file,
std::string  name,
std::function< double(BaseWall *)>  f 
) const
protected

Definition at line 78 of file WallVTKWriter.cc.

References BaseVTKWriter< WallHandler >::handler_.

79 {
80  file << " <DataArray type=\"Float32\" Name=\""+ name + "\" format=\"ascii\">\n";
81  for (const auto& p: handler_)
82  {
83  file << '\t' << f(p) << '\n';
84  }
85  file << " </DataArray>\n";
86 }
WallHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
void WallVTKWriter::writeVTK ( ) const
overridevirtual

writes a vtk file

Implements BaseVTKWriter< WallHandler >.

Definition at line 52 of file WallVTKWriter.cc.

References getVTKData(), BaseVTKWriter< WallHandler >::makeVTKFileWithHeader(), VTKContainer::points, PROCESSOR_ID, VTKContainer::triangleStrips, writeVTKCells(), and writeVTKPoints().

Referenced by DPMBase::writeVTKFiles().

53 {
54  if (PROCESSOR_ID!=0) return;
55  std::fstream file = makeVTKFileWithHeader();
56 
57  VTKContainer vtk;
58  getVTKData(vtk);
59  file << "<Piece NumberOfPoints=\"" << vtk.points.size()
60  << "\" NumberOfCells=\"" << vtk.triangleStrips.size()
61  << "\">\n"
62  << "<Points>\n";
63  writeVTKPoints(file, vtk);
64  file << "</Points>\n";
65  // this cannot be done right now since we can't math Points/Cells and Walls
66  // file << "<PointData Vectors=\"vector\">\n";
67  // write(file,"indSpecies",[](BaseWall* w){return w->getIndSpecies();});
68  // file << "</PointData>\n";
69  file << "<Cells>\n";
70  writeVTKCells(file, vtk);
71  file << "</Cells>\n"
72  << "</Piece>\n"
73  << "</UnstructuredGrid>\n"
74  << "</VTKFile>\n";
75  file.close();
76 }
void writeVTKPoints(std::fstream &file, VTKContainer &vtk) const
writes the point data to the vtu file (i.e.
std::fstream makeVTKFileWithHeader() const
void writeVTKCells(std::fstream &file, VTKContainer &vtk) const
writes the cell data to the vtu file (i.e.
std::vector< std::vector< double > > triangleStrips
Definition: BaseWall.h:39
#define PROCESSOR_ID
Definition: GeneralDefine.h:63
void getVTKData(VTKContainer &vtk) const
extracts vtk data from the wallHandler and stores it in a VTKContainer
std::vector< Vec3D > points
Definition: BaseWall.h:38
void WallVTKWriter::writeVTKCells ( std::fstream &  file,
VTKContainer vtk 
) const
protected

writes the cell data to the vtu file (i.e.

the faces of the mesh displayed in paraview)

Definition at line 98 of file WallVTKWriter.cc.

References constants::i, and VTKContainer::triangleStrips.

Referenced by writeVTK().

99 {
100  file << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
101  for (const std::vector<double>& c : vtk.triangleStrips)
102  {
103  file << '\t';
104  for (const double& i : c) file << i << ' ';
105  file << '\n';
106  }
107  file << " </DataArray>\n";
108  file << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
109  unsigned count = 0;
110  for (const std::vector<double>& c : vtk.triangleStrips)
111  {
112  count += c.size();
113  file << '\t' << count << '\n';
114  }
115  file << " </DataArray>\n";
116  file << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
117  for (const std::vector<double>& c : vtk.triangleStrips)
118  {
119  if (c.front() == c.back())
120  {
121  //polygon
122  file << "\t7\n";
123  }
124  else
125  {
126  //triangle strips
127  file << "\t6\n";
128  }
129  }
130  file << " </DataArray>\n";
131 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
std::vector< std::vector< double > > triangleStrips
Definition: BaseWall.h:39
void WallVTKWriter::writeVTKPoints ( std::fstream &  file,
VTKContainer vtk 
) const
protected

writes the point data to the vtu file (i.e.

the vertices of the mesh displayed in paraview)

Definition at line 88 of file WallVTKWriter.cc.

References VTKContainer::points.

Referenced by writeVTK().

89 {
90  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
91  for (const Vec3D& p : vtk.points)
92  {
93  file << '\t' << p << '\n';
94  }
95  file << " </DataArray>\n";
96 }
std::vector< Vec3D > points
Definition: BaseWall.h:38
Definition: Vector.h:49

The documentation for this class was generated from the following files: