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
 
void setCGWidth (double cgWidth)
 
- Public Member Functions inherited from BaseVTKWriter< WallHandler >
 BaseVTKWriter (WallHandler &handler)
 
 BaseVTKWriter (const BaseVTKWriter &other)
 
unsigned getFileCounter () const
 
void setFileCounter (unsigned fileCounter)
 
void setOutputDirectory (const std::string &dir)
 
const std::string & getOutputDirectory () const
 
std::string getFileName () const
 

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 writeVTKPointData (std::fstream &file, VTKContainer &vtk) const
 
void writeCGFields (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 }
 
double cgWidth_ = 0.0
 
- Protected Attributes inherited from BaseVTKWriter< WallHandler >
WallHandlerhandler_
 particle handler from which the particles should be written More...
 
unsigned int fileCounter
 
std::string outputDirectory_
 

Constructor & Destructor Documentation

◆ WallVTKWriter() [1/2]

WallVTKWriter::WallVTKWriter ( WallHandler wallHandler)
inlineexplicit

Non-default constructor; sets the handler and fileCounter

19  : BaseVTKWriter(wallHandler)
20  {}
BaseVTKWriter(WallHandler &handler)
Definition: BaseVTKWriter.h:22

◆ 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

41  { return "WallVTKWriter"; }

◆ getVTKData()

void WallVTKWriter::getVTKData ( VTKContainer vtk) const

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

10 {
11  // set capacity of points and cells based on the previous time step
12  // the initial values are based on the minimum, which is one triangle per wall
13  static unsigned int capacityPoints = 3*handler_.getSize();
14  static unsigned int capacityTriangleStrips = handler_.getSize();
15  vtk.triangleStrips.reserve(capacityPoints);
16  vtk.points.reserve(capacityTriangleStrips);
17 
18  //add all wall data to the point and cell arrays
19  for (const auto& w: handler_)
20  {
21  w->renderWall(vtk);
22  }
23 
24 // logger(INFO, "size (capacity) of points: % (%), cells: % (%)", vtk.points.size(), capacityPoints, vtk.triangleStrips.size(), capacityTriangleStrips);
25 
26  //store from previous time step
27  capacityPoints = vtk.points.size();
28  capacityTriangleStrips = vtk.triangleStrips.size();
29 }
RowVector3d w
Definition: Matrix_resize_int.cpp:3
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:663
WallHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:71
std::vector< std::vector< double > > triangleStrips
Definition: BaseWall.h:19
std::vector< Vec3D > points
Definition: BaseWall.h:18

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

Referenced by writeVTK().

◆ getWriteWallSurfaceAreaVTK()

bool WallVTKWriter::getWriteWallSurfaceAreaVTK ( ) const
210 {
212 }
bool writeWallSurfaceAreaVTK_
Definition: WallVTKWriter.h:89

References writeWallSurfaceAreaVTK_.

Referenced by WallHandler::getWriteWallSurfaceAreaVTK().

◆ setCGWidth()

void WallVTKWriter::setCGWidth ( double  cgWidth)
inline
47  {
48  cgWidth_ = std::max(0.0,cgWidth);
49  if (cgWidth==0.0) {
50  logger(INFO, "CG Width set to zero; no CG data is written to the VTU files");
51  }
52  }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ INFO
double cgWidth_
Definition: WallVTKWriter.h:92
#define max(a, b)
Definition: datatypes.h:23

References cgWidth_, INFO, logger, and max.

◆ setWriteWallSurfaceAreaVTK()

void WallVTKWriter::setWriteWallSurfaceAreaVTK ( bool  writeWallSurfaceAreaVTK)
205 {
206  writeWallSurfaceAreaVTK_ = writeWallSurfaceAreaVTK;
207 }

References writeWallSurfaceAreaVTK_.

Referenced by WallHandler::setWriteWallSurfaceAreaVTK().

◆ write()

void WallVTKWriter::write ( std::fstream &  file,
std::string  name,
std::function< double(BaseWall *)>  f 
) const
protected
64 {
65  file << " <DataArray type=\"Float32\" Name=\""+ name + "\" format=\"ascii\">\n";
66  for (const auto& p: handler_)
67  {
68  file << '\t' << f(p) << '\n';
69  }
70  file << " </DataArray>\n";
71 }
float * p
Definition: Tutorial_Map_using.cpp:9
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
string name
Definition: plotDoE.py:33

References f(), BaseVTKWriter< WallHandler >::handler_, plotDoE::name, and p.

◆ writeCGFields()

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

writes data from coarse-graining to the vtu file.

130  {
131  logger.assert_debug(handler_.getDPMBase(),"DPMBase not found");
132  ParticleHandler& particleHandler = handler_.getDPMBase()->particleHandler;
133  file << " <DataArray type=\"Float32\" Name=\"NearbyMass\" format=\"ascii\">\n";
134  for (const auto& point : vtk.points){
135  double mass = 0;
136  for (auto& particle : particleHandler) {
137  //implement a simple Heaviside function
138  if (Vec3D::getDistance(particle->getPosition(),point)<cgWidth_) {
139  mass += particle->getMass();
140  }
141  }
142  file << '\t' << mass << '\n';
143  }
144  file << " </DataArray>\n";
145  file << " <DataArray type=\"Float32\" Name=\"NearbyParticles\" format=\"ascii\">\n";
146  for (const auto& point : vtk.points){
147  double number = 0;
148  for (auto& particle : particleHandler) {
149  //implement a simple Heaviside function
150  if (Vec3D::getDistance(particle->getPosition(),point)<cgWidth_) {
151  number ++;
152  }
153  }
154  file << '\t' << number << '\n';
155  }
156  file << " </DataArray>\n";
157 }
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:733
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1443
Container to store pointers to all particles.
Definition: ParticleHandler.h:28
static Mdouble getDistance(const Vec3D &a, const Vec3D &b)
Calculates the distance between two Vec3D: .
Definition: Vector.cc:155

References cgWidth_, Vec3D::getDistance(), BaseHandler< T >::getDPMBase(), BaseVTKWriter< WallHandler >::handler_, logger, DPMBase::particleHandler, and VTKContainer::points.

Referenced by writeVTKPointData().

◆ writeVTK()

void WallVTKWriter::writeVTK ( ) const
overridevirtual

writes a vtk file

Implements BaseVTKWriter< WallHandler >.

32 {
33  if (PROCESSOR_ID!=0) return;
34  std::fstream file = makeVTKFileWithHeader();
35 
36  VTKContainer vtk;
37  getVTKData(vtk);
38  file << "<Piece NumberOfPoints=\"" << vtk.points.size()
39  << "\" NumberOfCells=\"" << vtk.triangleStrips.size()
40  << "\">\n"
41  << "<Points>\n";
42  writeVTKPoints(file, vtk);
43  file << "</Points>\n";
44  // this cannot be done right now since we can't math Points/Cells and Walls
45  // file << "<PointData Vectors=\"vector\">\n";
46  // write(file,"indSpecies",[](BaseWall* w){return w->getIndSpecies();});
47  // file << "</PointData>\n";
48  file << "<Cells>\n";
49  writeVTKCells(file, vtk);
50  file << "</Cells>\n";
51  file << "<CellData>\n";
52  writeVTKCellData(file, vtk);
53  file << "</CellData>\n";
54  file << "<PointData>\n";
55  writeVTKPointData(file, vtk);
56  file << "</PointData>\n";
57  file << "</Piece>\n"
58  << "</UnstructuredGrid>\n"
59  << "</VTKFile>\n";
60  file.close();
61 }
#define PROCESSOR_ID
Definition: GeneralDefine.h:42
std::fstream makeVTKFileWithHeader() const
Definition: BaseVTKWriter.h:112
void writeVTKPointData(std::fstream &file, VTKContainer &vtk) const
Definition: WallVTKWriter.cc:124
void writeVTKCells(std::fstream &file, VTKContainer &vtk) const
Definition: WallVTKWriter.cc:83
void getVTKData(VTKContainer &vtk) const
Definition: WallVTKWriter.cc:9
void writeVTKCellData(std::fstream &file, VTKContainer &vtk) const
Definition: WallVTKWriter.cc:118
void writeVTKPoints(std::fstream &file, VTKContainer &vtk) const
Definition: WallVTKWriter.cc:73
Definition: BaseWall.h:17

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

Referenced by DPMBase::writeVTKFiles().

◆ writeVTKCellData()

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

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

118  {
120  writeVTKSurfaceArea(file, vtk);
121  }
122 }
void writeVTKSurfaceArea(std::fstream &file, VTKContainer &vtk) const
Calculates and writes the surface areas of the cells to the vtu file.
Definition: WallVTKWriter.cc:168

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)

84 {
85  file << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
86  for (const std::vector<double>& c : vtk.triangleStrips)
87  {
88  file << '\t';
89  for (const double& i : c) file << i << ' ';
90  file << '\n';
91  }
92  file << " </DataArray>\n";
93  file << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
94  unsigned count = 0;
95  for (const std::vector<double>& c : vtk.triangleStrips)
96  {
97  count += c.size();
98  file << '\t' << count << '\n';
99  }
100  file << " </DataArray>\n";
101  file << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
102  for (const std::vector<double>& c : vtk.triangleStrips)
103  {
104  if (c.front() == c.back())
105  {
106  //polygon
107  file << "\t7\n";
108  }
109  else
110  {
111  //triangle strips
112  file << "\t6\n";
113  }
114  }
115  file << " </DataArray>\n";
116 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
int c
Definition: calibrate.py:100

References calibrate::c, i, and VTKContainer::triangleStrips.

Referenced by writeVTK().

◆ writeVTKPointData()

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

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

124  {
125  if (cgWidth_>0) {
126  writeCGFields(file, vtk);
127  }
128 }
void writeCGFields(std::fstream &file, VTKContainer &vtk) const
Definition: WallVTKWriter.cc:130

References cgWidth_, and writeCGFields().

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)

74 {
75  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
76  for (const Vec3D& p : vtk.points)
77  {
78  file << '\t' << p << '\n';
79  }
80  file << " </DataArray>\n";
81 }
Definition: Kernel/Math/Vector.h:30

References p, and 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.
168  {
169  file << " <DataArray type=\"Float32\" Name=\"SurfaceArea\" format=\"ascii\">\n";
173  for (const std::vector<double>& strip : vtk.triangleStrips){
174  double area = 0;
175  for(size_t i = 1; i < strip.size() - 1; i++){
176  size_t i1 = static_cast<size_t>(strip.at(i-1));
177  size_t i2 = static_cast<size_t>(strip.at(i));
178  size_t i3 = static_cast<size_t>(strip.at(i+1));
179 
183  // strip is a polygon
184  if(strip.front() == strip.back() && i == strip.size() - 2){
185  break;
186  }
187 
188  Vec3D &p1 = vtk.points.at(i1);
189  Vec3D &p2 = vtk.points.at(i2);
190  Vec3D &p3 = vtk.points.at(i3);
191 
192  Vec3D p12 = p2 - p1;
193  Vec3D p13 = p3 - p1;
194 
195  double triangleArea = 0.5 * Vec3D::cross(p12, p13).getLength();
196  area += triangleArea;
197  }
198  file << '\t' << area << '\n';
199  }
200 
201  file << " </DataArray>\n";
202 }
Vector3f p1
Definition: MatrixBase_all.cpp:2
static Vec3D cross(const Vec3D &a, const Vec3D &b)
Calculates the cross product of two Vec3D: .
Definition: Vector.cc:143
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:350

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

Referenced by writeVTKCellData().

Member Data Documentation

◆ cgWidth_

double WallVTKWriter::cgWidth_ = 0.0
protected

◆ writeWallSurfaceAreaVTK_

bool WallVTKWriter::writeWallSurfaceAreaVTK_ { false }
protected

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