MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseVTKWriter< H > Class Template Referenceabstract

#include <BaseVTKWriter.h>

Public Member Functions

 BaseVTKWriter (H &handler)
 
 BaseVTKWriter (const BaseVTKWriter &other)
 
virtual void writeVTK () const =0
 
unsigned getFileCounter () const
 
void setFileCounter (unsigned fileCounter)
 

Protected Member Functions

std::fstream makeVTKFileWithHeader () const
 
void writeVTKFooterAndClose (std::fstream &file) const
 

Protected Attributes

H & handler_
 particle handler from which the particles should be written More...
 
unsigned int fileCounter
 

Detailed Description

template<typename H>
class BaseVTKWriter< H >

Template Parameters
Hsome handler, e.g. particleHandler

Definition at line 39 of file BaseVTKWriter.h.

Constructor & Destructor Documentation

template<typename H>
BaseVTKWriter< H >::BaseVTKWriter ( H &  handler)
inline

Definition at line 44 of file BaseVTKWriter.h.

44  : handler_(handler)
45  {
46  fileCounter = 0;
47  }
H & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
unsigned int fileCounter
Definition: BaseVTKWriter.h:74
template<typename H>
BaseVTKWriter< H >::BaseVTKWriter ( const BaseVTKWriter< H > &  other)
inline

Definition at line 49 of file BaseVTKWriter.h.

49  : handler_(other.handler_)
50  {
51  fileCounter = other.fileCounter;
52  }
H & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
unsigned int fileCounter
Definition: BaseVTKWriter.h:74

Member Function Documentation

template<typename H>
unsigned BaseVTKWriter< H >::getFileCounter ( ) const
inline

Definition at line 56 of file BaseVTKWriter.h.

Referenced by DPMBase::write().

57  {
58  return fileCounter;
59  }
unsigned int fileCounter
Definition: BaseVTKWriter.h:74
template<typename T >
std::fstream BaseVTKWriter< T >::makeVTKFileWithHeader ( ) const
protected
Todo:
vtw wall files only need to be written by one processor

Definition at line 80 of file BaseVTKWriter.h.

References logger, NUMBER_OF_PROCESSORS, PROCESSOR_ID, helpers::to_string(), and WARN.

81 {
82  //extract the word "Wall" or "Particle" from the VTK writer name
83  std::string name = handler_.getName();
84  name = name.substr(0, name.length() - 7);
85 
86  //determine name of output file
87  std::string fileName;
88 #ifdef MERCURY_USE_MPI
89  if (NUMBER_OF_PROCESSORS > 1 && name != "Wall")
90  {
91  fileName = handler_.getDPMBase()->getName() + "Processor_" + std::to_string(PROCESSOR_ID) +
92  '_' + name + '_' + std::to_string(fileCounter++) + ".vtu";
93  }
94  else
95  {
96  fileName = handler_.getDPMBase()->getName() +
97  name + '_' +
98  std::to_string(fileCounter++) + ".vtu";
99  }
100 #else
101  fileName = handler_.getDPMBase()->getName() +
102  name + '_' +
103  std::to_string(fileCounter++) + ".vtu";
104 #endif
105 
106  //open output file
107  std::fstream file;
108  file.open(fileName.c_str(), std::ios_base::out);
109  if (file.fail())
110  {
111  logger(WARN, "File % could not be opened", fileName);
112  }
113 
114  // write output file header
115  file << "<?xml version=\"1.0\"?>\n";
116  file << "<!-- time " << handler_.getDPMBase()->getTime() << "-->\n";
117  file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
118  file << "<UnstructuredGrid>\n";
119  return file;
120 }
H & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
unsigned int fileCounter
Definition: BaseVTKWriter.h:74
#define PROCESSOR_ID
Definition: GeneralDefine.h:63
#define NUMBER_OF_PROCESSORS
For the MPI communication routines this quantity is often required. defining this macro makes the cod...
Definition: GeneralDefine.h:62
std::string to_string(const T &n)
Definition: Helpers.h:227
template<typename H>
void BaseVTKWriter< H >::setFileCounter ( unsigned  fileCounter)
inline

Definition at line 61 of file BaseVTKWriter.h.

Referenced by DPMBase::read(), and DPMBase::resetFileCounter().

62  {
63  this->fileCounter = fileCounter;
64  }
unsigned int fileCounter
Definition: BaseVTKWriter.h:74
template<typename H>
virtual void BaseVTKWriter< H >::writeVTK ( ) const
pure virtual
template<typename T >
void BaseVTKWriter< T >::writeVTKFooterAndClose ( std::fstream &  file) const
protected

Definition at line 123 of file BaseVTKWriter.h.

124 {
125  // write output file footer
126  file << "<Cells>\n";
127  file << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
128  file << " </DataArray>\n";
129  file << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
130  file << " </DataArray>\n";
131  file << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
132  file << " </DataArray>\n";
133  file << "</Cells>\n";
134  file << "</Piece>\n";
135  file << "</UnstructuredGrid>\n";
136  file << "</VTKFile>\n";
137  // close output file
138  file.close();
139 }

Member Data Documentation

template<typename H>
H& BaseVTKWriter< H >::handler_
protected

particle handler from which the particles should be written

Definition at line 72 of file BaseVTKWriter.h.


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