WallVTKWriter Class Referencefinal

#include <WallVTKWriter.h>

+ Inheritance diagram for WallVTKWriter:

Public Member Functions

 WallVTKWriter (WallHandler &wallHandler)
 
 WallVTKWriter (const WallVTKWriter &)=default
 
void getVTKData (VTKContainer &vtk) const
 
void writeVTK () const override
 
std::string getName () const
 
void setWriteWallSurfaceAreaVTK (bool writeWallSurfaceAreaVTK)
 
bool getWriteWallSurfaceAreaVTK () const
 
- 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
 
void writeVTKCells (std::fstream &file, VTKContainer &vtk) const
 
void writeVTKCellData (std::fstream &file, VTKContainer &vtk) const
 
void writeVTKSurfaceArea (std::fstream &file, VTKContainer &vtk) const
 Calculates and writes the surface areas of the cells to the vtu file. More...
 
- Protected Member Functions inherited from BaseVTKWriter< WallHandler >
std::fstream makeVTKFileWithHeader () const
 
void writeVTKFooterAndClose (std::fstream &file) const
 

Protected Attributes

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

Constructor & Destructor Documentation

◆ WallVTKWriter() [1/2]

WallVTKWriter::WallVTKWriter ( WallHandler wallHandler)
inlineexplicit

Non-default constructor; sets the handler and fileCounter

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

◆ WallVTKWriter() [2/2]

WallVTKWriter::WallVTKWriter ( const WallVTKWriter )
default

Default copy constructor

Member Function Documentation

◆ getName()

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

the name of the class in the restart file

63  { return "WallVTKWriter"; }

◆ getVTKData()

void WallVTKWriter::getVTKData ( VTKContainer vtk) const

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

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:40
std::vector< Vec3D > points
Definition: BaseWall.h:39

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

Referenced by writeVTK().

◆ getWriteWallSurfaceAreaVTK()

bool WallVTKWriter::getWriteWallSurfaceAreaVTK ( ) const
193 {
195 }
bool writeWallSurfaceAreaVTK_
Definition: WallVTKWriter.h:92

References writeWallSurfaceAreaVTK_.

Referenced by WallHandler::getWriteWallSurfaceAreaVTK().

◆ setWriteWallSurfaceAreaVTK()

void WallVTKWriter::setWriteWallSurfaceAreaVTK ( bool  writeWallSurfaceAreaVTK)
188 {
189  writeWallSurfaceAreaVTK_ = writeWallSurfaceAreaVTK;
190 }

References writeWallSurfaceAreaVTK_.

Referenced by WallHandler::setWriteWallSurfaceAreaVTK().

◆ write()

void WallVTKWriter::write ( std::fstream &  file,
std::string  name,
std::function< double(BaseWall *)>  f 
) const
protected
82 {
83  file << " <DataArray type=\"Float32\" Name=\""+ name + "\" format=\"ascii\">\n";
84  for (const auto& p: handler_)
85  {
86  file << '\t' << f(p) << '\n';
87  }
88  file << " </DataArray>\n";
89 }
std::string name
Definition: MercuryProb.h:48

References BaseVTKWriter< WallHandler >::handler_, and units::name.

◆ writeVTK()

void WallVTKWriter::writeVTK ( ) const
overridevirtual

writes a vtk file

Implements BaseVTKWriter< WallHandler >.

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  file << "<CellData>\n";
73  writeVTKCellData(file, vtk);
74  file << "</CellData>\n"
75  << "</Piece>\n"
76  << "</UnstructuredGrid>\n"
77  << "</VTKFile>\n";
78  file.close();
79 }
#define PROCESSOR_ID
Definition: GeneralDefine.h:63
std::fstream makeVTKFileWithHeader() const
Definition: BaseVTKWriter.h:80
void writeVTKCells(std::fstream &file, VTKContainer &vtk) const
Definition: WallVTKWriter.cc:101
void getVTKData(VTKContainer &vtk) const
Definition: WallVTKWriter.cc:30
void writeVTKCellData(std::fstream &file, VTKContainer &vtk) const
Definition: WallVTKWriter.cc:136
void writeVTKPoints(std::fstream &file, VTKContainer &vtk) const
Definition: WallVTKWriter.cc:91
Definition: BaseWall.h:38

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

Referenced by DPMBase::writeVTKFiles().

◆ writeVTKCellData()

void WallVTKWriter::writeVTKCellData ( std::fstream &  file,
VTKContainer vtk 
) const
protected

writes the cell data to the vtu file (i.e. surface area)

136  {
138  writeVTKSurfaceArea(file, vtk);
139  }
140 }
void writeVTKSurfaceArea(std::fstream &file, VTKContainer &vtk) const
Calculates and writes the surface areas of the cells to the vtu file.
Definition: WallVTKWriter.cc:151

References writeVTKSurfaceArea(), and writeWallSurfaceAreaVTK_.

Referenced by writeVTK().

◆ writeVTKCells()

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)

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

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

Referenced by writeVTK().

◆ writeVTKPoints()

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)

92 {
93  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
94  for (const Vec3D& p : vtk.points)
95  {
96  file << '\t' << p << '\n';
97  }
98  file << " </DataArray>\n";
99 }
Definition: Vector.h:51

References VTKContainer::points.

Referenced by writeVTK().

◆ writeVTKSurfaceArea()

void WallVTKWriter::writeVTKSurfaceArea ( std::fstream &  file,
VTKContainer vtk 
) const
protected

Calculates and writes the surface areas of the cells to the vtu file.

The calculation is based on the rendered VTKContainer and it takes time. This functionality is diasabled by default and can be enabled using WallHandler::setWriteWallSurfaceAreaVTK().

Parameters
[in]fileOutput filestream
[in]vtkRendered VTKContainer
Todo:
gmb This only needs to be calculated if the mesh changes.
Todo:
gmb Check if it always true.
151  {
152  file << " <DataArray type=\"Float32\" Name=\"SurfaceArea\" format=\"ascii\">\n";
156  for (const std::vector<double>& strip : vtk.triangleStrips){
157  double area = 0;
158  for(size_t i = 1; i < strip.size() - 1; i++){
159  size_t i1 = static_cast<size_t>(strip.at(i-1));
160  size_t i2 = static_cast<size_t>(strip.at(i));
161  size_t i3 = static_cast<size_t>(strip.at(i+1));
162 
166  // strip is a polygon
167  if(strip.front() == strip.back() && i == strip.size() - 2){
168  break;
169  }
170 
171  Vec3D &p1 = vtk.points.at(i1);
172  Vec3D &p2 = vtk.points.at(i2);
173  Vec3D &p3 = vtk.points.at(i3);
174 
175  Vec3D p12 = p2 - p1;
176  Vec3D p13 = p3 - p1;
177 
178  double triangleArea = 0.5 * Vec3D::cross(p12, p13).getLength();
179  area += triangleArea;
180  }
181  file << '\t' << area << '\n';
182  }
183 
184  file << " </DataArray>\n";
185 }
static Vec3D cross(const Vec3D &a, const Vec3D &b)
Calculates the cross product of two Vec3D: .
Definition: Vector.cc:163
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331

References Vec3D::cross(), Vec3D::getLength(), constants::i, VTKContainer::points, and VTKContainer::triangleStrips.

Referenced by writeVTKCellData().

Member Data Documentation

◆ writeWallSurfaceAreaVTK_

bool WallVTKWriter::writeWallSurfaceAreaVTK_ { false }
protected

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