SphericalParticleVtkWriter Class Referencefinal

#include <SphericalParticleVtkWriter.h>

+ Inheritance diagram for SphericalParticleVtkWriter:

Public Member Functions

 SphericalParticleVtkWriter (ParticleHandler &particleHandler)
 
 ~SphericalParticleVtkWriter () override=default
 
void writeVTK () const override
 Writes all particles into a vtk file format (unstructured grid), consisting of particle positions, velocities, radii and type of species (IndSpecies) More...
 
std::string getName () const override
 
- Public Member Functions inherited from ParticleVtkWriter
 ParticleVtkWriter (ParticleHandler &particleHandler)
 
virtual ~ParticleVtkWriter ()=default
 
- Public Member Functions inherited from BaseVTKWriter< ParticleHandler >
 BaseVTKWriter (ParticleHandler &handler)
 
 BaseVTKWriter (const BaseVTKWriter &other)
 
unsigned getFileCounter () const
 
void setFileCounter (unsigned fileCounter)
 

Private Member Functions

void writeVTKVelocity (std::fstream &file) const
 
void writeVTKAngularVelocity (std::fstream &file) const
 
void writeVTKRadius (std::fstream &file) const
 
void writeVTKId (std::fstream &file) const
 Writes the id (unique integer) of the particles to the vtu file. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ParticleVtkWriter
void writeExtraFields (std::fstream &file) const
 
void writeVTKIndSpecies (std::fstream &file) const
 
void writeVTKPositions (std::fstream &file) const
 
bool particleMustBeWritten (BaseParticle *particle) const
 
- Protected Member Functions inherited from BaseVTKWriter< ParticleHandler >
std::fstream makeVTKFileWithHeader () const
 
void writeVTKFooterAndClose (std::fstream &file) const
 
- Protected Attributes inherited from BaseVTKWriter< ParticleHandler >
ParticleHandlerhandler_
 particle handler from which the particles should be written More...
 
unsigned int fileCounter
 

Constructor & Destructor Documentation

◆ SphericalParticleVtkWriter()

SphericalParticleVtkWriter::SphericalParticleVtkWriter ( ParticleHandler particleHandler)
inlineexplicit
39  : ParticleVtkWriter(particleHandler)
40  {}
ParticleVtkWriter(ParticleHandler &particleHandler)
Definition: ParticleVtkWriter.h:38

◆ ~SphericalParticleVtkWriter()

SphericalParticleVtkWriter::~SphericalParticleVtkWriter ( )
overridedefault

Member Function Documentation

◆ getName()

std::string SphericalParticleVtkWriter::getName ( ) const
inlineoverridevirtual

Implements ParticleVtkWriter.

51  {
52  return "SphericalParticleVtkWriter";
53  }

◆ writeVTK()

void SphericalParticleVtkWriter::writeVTK ( ) const
overridevirtual

Writes all particles into a vtk file format (unstructured grid), consisting of particle positions, velocities, radii and type of species (IndSpecies)

Writes all points ans cells to a file in the VTK format. The filename is hard-coded in this method, and is based on the name of the DPMBase and has a unique counter in it to ensure there are no two files with the same name.

Implements BaseVTKWriter< ParticleHandler >.

36 {
37  std::fstream file = makeVTKFileWithHeader();
38  long numberOfParticlesToWrite = std::count_if(handler_.begin(), handler_.end(),
39  [this](BaseParticle* p){return particleMustBeWritten(p);});
40  file << "<Piece NumberOfPoints=\"" << numberOfParticlesToWrite
41  << "\" NumberOfCells=\"" << 0 << "\">\n";
42  writeVTKPositions(file);
43  file << "<PointData Vectors=\"vector\">\n";
44  writeVTKVelocity(file);
46  writeVTKRadius(file);
47  writeVTKIndSpecies(file);
48  writeExtraFields(file);
49  writeVTKId(file);
50  file << "</PointData>\n";
52 }
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:690
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:704
Definition: BaseParticle.h:54
void writeVTKFooterAndClose(std::fstream &file) const
Definition: BaseVTKWriter.h:123
ParticleHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
std::fstream makeVTKFileWithHeader() const
Definition: BaseVTKWriter.h:80
void writeVTKIndSpecies(std::fstream &file) const
Definition: ParticleVtkWriter.cc:49
void writeExtraFields(std::fstream &file) const
Definition: ParticleVtkWriter.cc:67
void writeVTKPositions(std::fstream &file) const
Definition: ParticleVtkWriter.cc:29
void writeVTKId(std::fstream &file) const
Writes the id (unique integer) of the particles to the vtu file.
Definition: SphericalParticleVtkWriter.cc:119
void writeVTKAngularVelocity(std::fstream &file) const
Definition: SphericalParticleVtkWriter.cc:71
void writeVTKRadius(std::fstream &file) const
Definition: SphericalParticleVtkWriter.cc:95
void writeVTKVelocity(std::fstream &file) const
Definition: SphericalParticleVtkWriter.cc:54

References BaseHandler< T >::begin(), BaseHandler< T >::end(), BaseVTKWriter< ParticleHandler >::handler_, BaseVTKWriter< ParticleHandler >::makeVTKFileWithHeader(), ParticleVtkWriter::writeExtraFields(), writeVTKAngularVelocity(), BaseVTKWriter< ParticleHandler >::writeVTKFooterAndClose(), writeVTKId(), ParticleVtkWriter::writeVTKIndSpecies(), ParticleVtkWriter::writeVTKPositions(), writeVTKRadius(), and writeVTKVelocity().

◆ writeVTKAngularVelocity()

void SphericalParticleVtkWriter::writeVTKAngularVelocity ( std::fstream &  file) const
private
72 {
74  {
75  file << " <DataArray type=\"Float32\" Name=\"AngularVelocity\" NumberOfComponents=\"3\" format=\"ascii\">\n";
76  // Add velocity
77  for (const auto& p: handler_) {
78 #ifdef MERCURYDPM_USE_MPI
79  if (particleMustBeWritten(p))
80 #endif
81  {
82  file << '\t' << (float)p->getAngularVelocity().X << ' ' << (float)p->getAngularVelocity().Y << ' ' << (float)p->getAngularVelocity().Z << '\n';
83  }
84  }
85  file << " </DataArray>\n";
86  }
87 }
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
bool getRotation() const
Indicates whether particle rotation is enabled or disabled.
Definition: DPMBase.h:570
bool particleMustBeWritten(BaseParticle *particle) const
Definition: ParticleVtkWriter.h:53

References BaseHandler< T >::getDPMBase(), DPMBase::getRotation(), BaseVTKWriter< ParticleHandler >::handler_, and ParticleVtkWriter::particleMustBeWritten().

Referenced by writeVTK().

◆ writeVTKId()

void SphericalParticleVtkWriter::writeVTKId ( std::fstream &  file) const
private

Writes the id (unique integer) of the particles to the vtu file.

This enables the tracing of particles through multiple files.

Parameters
[in]fileOutput filestream.
Note
gmb Maybe Int64 is needed.
120 {
124  file << " <DataArray type=\"Int32\" Name=\"Id\" format=\"ascii\">\n";
125  // Add id
126  for (const auto& p: handler_) {
127 #ifdef MERCURYDPM_USE_MPI
128  if (particleMustBeWritten(p))
129 #endif
130  {
131  file << '\t' << p->getId() << '\n';
132  }
133  }
134  file << " </DataArray>\n";
135 }

References BaseVTKWriter< ParticleHandler >::handler_, and ParticleVtkWriter::particleMustBeWritten().

Referenced by writeVTK().

◆ writeVTKRadius()

void SphericalParticleVtkWriter::writeVTKRadius ( std::fstream &  file) const
private

Notice that we write GrainRadius in the file, since there is a bug in Paraview that defaults to the first scalar-value in lexicographic order. We therefore need a description for the radius which starts with a letter before N.

Parameters
fileThe filestream to which the radius must be written.
96 {
97  file << " <DataArray type=\"Float32\" Name=\"Radius\" format=\"ascii\">\n";
98  // Add radius
99  for (const auto& p: handler_)
100  {
101 #ifdef MERCURYDPM_USE_MPI
102  if (particleMustBeWritten(p))
103 #endif
104  {
105  file << '\t' << p->getRadius() << '\n';
106  }
107 
108  }
109  file << " </DataArray>\n";
110 }

References BaseVTKWriter< ParticleHandler >::handler_, and ParticleVtkWriter::particleMustBeWritten().

Referenced by writeVTK().

◆ writeVTKVelocity()

void SphericalParticleVtkWriter::writeVTKVelocity ( std::fstream &  file) const
private
55 {
56  file << " <DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"ascii\">\n";
57  // Add velocity
58  for (const auto& p: handler_) {
59 #ifdef MERCURYDPM_USE_MPI
60  if (particleMustBeWritten(p))
61 #endif
62  {
63  file << ' ' << (float) p->getVelocity().X
64  << ' ' << (float) p->getVelocity().Y
65  << ' ' << (float) p->getVelocity().Z << '\n';
66  }
67  }
68  file << " </DataArray>\n";
69 }

References BaseVTKWriter< ParticleHandler >::handler_, and ParticleVtkWriter::particleMustBeWritten().

Referenced by writeVTK().


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