MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 writeVTKRadius (std::fstream &file) const
 

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
 

Detailed Description

Definition at line 33 of file SphericalParticleVtkWriter.h.

Constructor & Destructor Documentation

SphericalParticleVtkWriter::SphericalParticleVtkWriter ( ParticleHandler particleHandler)
inlineexplicit

Definition at line 39 of file SphericalParticleVtkWriter.h.

39  : ParticleVtkWriter(particleHandler)
40  {}
ParticleVtkWriter(ParticleHandler &particleHandler)
SphericalParticleVtkWriter::~SphericalParticleVtkWriter ( )
overridedefault

Member Function Documentation

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

Implements ParticleVtkWriter.

Definition at line 50 of file SphericalParticleVtkWriter.h.

51  {
52  return "SphericalParticleVtkWriter";
53  }
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 >.

Definition at line 35 of file SphericalParticleVtkWriter.cc.

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

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);
45  writeVTKRadius(file);
46  writeVTKIndSpecies(file);
47  writeExtraFields(file);
48 
49  file << "</PointData>\n";
51 }
void writeVTKPositions(std::fstream &file) const
void writeVTKIndSpecies(std::fstream &file) const
ParticleHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
bool particleMustBeWritten(BaseParticle *particle) const
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
std::fstream makeVTKFileWithHeader() const
void writeVTKFooterAndClose(std::fstream &file) const
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
void writeVTKVelocity(std::fstream &file) const
void writeExtraFields(std::fstream &file) const
void writeVTKRadius(std::fstream &file) const
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.

Definition at line 76 of file SphericalParticleVtkWriter.cc.

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

Referenced by writeVTK().

77 {
78  file << " <DataArray type=\"Float32\" Name=\"Radius\" format=\"ascii\">\n";
79  // Add radius
80  for (const auto& p: handler_)
81  {
82 #ifdef MERCURY_USE_MPI
83  if (particleMustBeWritten(p))
84  {
85  file << '\t' << p->getRadius() << '\n';
86  }
87 #else
88  file << '\t' << p->getRadius() << '\n';//Radius
89 #endif
90  }
91  file << " </DataArray>\n";
92 }
ParticleHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
bool particleMustBeWritten(BaseParticle *particle) const
void SphericalParticleVtkWriter::writeVTKVelocity ( std::fstream &  file) const
private

Definition at line 53 of file SphericalParticleVtkWriter.cc.

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

Referenced by writeVTK().

54 {
55  file << " <DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"ascii\">\n";
56  // Add velocity
57  for (const auto& p: handler_) {
58 #ifdef MERCURY_USE_MPI
59  if (particleMustBeWritten(p))
60 #endif
61  {
62  file << ' ' << (float) p->getVelocity().X
63  << ' ' << (float) p->getVelocity().Y
64  << ' ' << (float) p->getVelocity().Z << '\n';
65  }
66  }
67  file << " </DataArray>\n";
68 }
ParticleHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
bool particleMustBeWritten(BaseParticle *particle) const

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