ParticleVtkWriter Class Referenceabstract

#include <ParticleVtkWriter.h>

+ Inheritance diagram for ParticleVtkWriter:

Public Member Functions

 ParticleVtkWriter (ParticleHandler &particleHandler)
 
virtual ~ParticleVtkWriter ()=default
 
virtual std::string getName () const =0
 
- Public Member Functions inherited from BaseVTKWriter< ParticleHandler >
 BaseVTKWriter (ParticleHandler &handler)
 
 BaseVTKWriter (const BaseVTKWriter &other)
 
virtual void writeVTK () const=0
 
unsigned getFileCounter () const
 
void setFileCounter (unsigned fileCounter)
 

Protected Member Functions

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
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ ParticleVtkWriter()

ParticleVtkWriter::ParticleVtkWriter ( ParticleHandler particleHandler)
inlineexplicit
38  : BaseVTKWriter(particleHandler)
39  {}
BaseVTKWriter(ParticleHandler &handler)
Definition: BaseVTKWriter.h:44

◆ ~ParticleVtkWriter()

virtual ParticleVtkWriter::~ParticleVtkWriter ( )
virtualdefault

Member Function Documentation

◆ getName()

virtual std::string ParticleVtkWriter::getName ( ) const
pure virtual

◆ particleMustBeWritten()

bool ParticleVtkWriter::particleMustBeWritten ( BaseParticle particle) const
inlineprotected
54  {
55  return !(particle->isMPIParticle() || particle->isPeriodicGhostParticle());
56  }
bool isPeriodicGhostParticle() const
Indicates if this particle is a ghost in the periodic boundary.
Definition: BaseParticle.cc:297
bool isMPIParticle() const
Indicates if this particle is a ghost in the MPI domain.
Definition: BaseParticle.cc:181

References BaseParticle::isMPIParticle(), and BaseParticle::isPeriodicGhostParticle().

Referenced by writeExtraFields(), SphericalParticleVtkWriter::writeVTKAngularVelocity(), SphericalParticleVtkWriter::writeVTKId(), writeVTKIndSpecies(), writeVTKPositions(), SphericalParticleVtkWriter::writeVTKRadius(), and SphericalParticleVtkWriter::writeVTKVelocity().

◆ writeExtraFields()

void ParticleVtkWriter::writeExtraFields ( std::fstream &  file) const
protected
68 {
69  //check if this type of Interaction has extra fields
70  if (handler_.getSize() != 0)
71  {
72  for (unsigned i = 0; i < handler_.getLastObject()->getNumberOfFieldsVTK(); i++)
73  {
74  file << " <DataArray type=\"" << handler_.getLastObject()->getTypeVTK(i) << "\" Name=\""
75  << handler_.getLastObject()->getNameVTK(i) << "\" format=\"ascii\">\n";
76  // Add species type
77  for (const auto& p: handler_)
78  {
79  for (auto f : p->getFieldVTK(i)) {
80 #ifdef MERCURYDPM_USE_MPI
81  if (particleMustBeWritten(p))
82  {
83  file << '\t' << (float)f << '\n';
84  }
85 #else
86  file << '\t' << (float)f << '\n';
87 #endif
88  }
89  }
90  file << " </DataArray>\n";
91  }
92  }
93 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
virtual std::string getTypeVTK(unsigned i) const
Definition: BaseParticle.cc:841
virtual std::string getNameVTK(unsigned i) const
Definition: BaseParticle.cc:846
ParticleHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
bool particleMustBeWritten(BaseParticle *particle) const
Definition: ParticleVtkWriter.h:53
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References BaseHandler< T >::getLastObject(), BaseParticle::getNameVTK(), BaseHandler< T >::getSize(), BaseParticle::getTypeVTK(), BaseVTKWriter< ParticleHandler >::handler_, constants::i, and particleMustBeWritten().

Referenced by SphericalParticleVtkWriter::writeVTK().

◆ writeVTKIndSpecies()

void ParticleVtkWriter::writeVTKIndSpecies ( std::fstream &  file) const
protected
50 {
51  file << " <DataArray type=\"Float32\" Name=\"speciesType\" format=\"ascii\">\n";
52  // Add species type
53  for (const auto& p: handler_)
54  {
55 #ifdef MERCURYDPM_USE_MPI
56  if (particleMustBeWritten(p))
57  {
58  file << '\t' << p->getIndSpecies() << '\n';
59  }
60 #else
61  file << '\t' << p->getIndSpecies() << '\n';
62 #endif
63  }
64  file << " </DataArray>\n";
65 }

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

Referenced by SphericalParticleVtkWriter::writeVTK(), and SuperQuadricParticleVtkWriter::writeVTK().

◆ writeVTKPositions()

void ParticleVtkWriter::writeVTKPositions ( std::fstream &  file) const
protected
30 {
31  file << "<Points>\n";
32  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
33  for (const auto& p: handler_)
34  {
35 #ifdef MERCURYDPM_USE_MPI
36  if (particleMustBeWritten(p))
37  {
38  file << '\t' << p->getPosition() << '\n';
39  }
40 #else
41  file << '\t' << (float)p->getPosition().X << ' ' << (float)p->getPosition().Y << ' ' << (float)p->getPosition().Z << '\n';
42 #endif
43 
44  }
45  file << " </DataArray>\n";
46  file << "</Points>\n";
47 }

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

Referenced by SphericalParticleVtkWriter::writeVTK(), and SuperQuadricParticleVtkWriter::writeVTK().


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