OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::VTUpointWriter< T, W, 2 > Class Template Reference

#include <vtuPointWriter.h>

+ Collaboration diagram for olb::VTUpointWriter< T, W, 2 >:

Public Member Functions

 VTUpointWriter (std::string const name, bool binary=false)
 
void createMasterFile ()
 
void write (std::size_t iT, std::vector< Vector< T, 2 > > &new_positions)
 write function to call during runtime, also accepts additional points during call
 
void write (std::size_t iT)
 
void addFunctor (AnalyticalF2D< T, W > &f, const std::string &name)
 accepts functors to write out
 
void addFunctor (AnalyticalF2D< T, W > &f)
 
void addFunctor (SuperF2D< T, W > &f, const std::string &name)
 
void addFunctor (SuperF2D< T, W > &f)
 
void addPoint (Vector< T, 2 > &new_position)
 functions to add multiple or single points.
 
void addPoints (std::vector< olb::Vector< T, 2 > > &new_positions)
 

Protected Member Functions

void preamblePVD (const std::string &fullNamePVD)
 
void closePVD (const std::string &fullNamePVD)
 
void preambleVTU (const std::string &fullName, int num)
 performes <VTKFile ...>, <ImageData ...> and <PieceExtent ...>
 
void closeVTU (const std::string &fullNamePiece)
 performes </ImageData> and </VTKFile>
 
void dataPVD (int iT, int i, const std::string &fullNamePVD, const std::string &namePiece)
 performes <DataSet timestep= ... file=namePiece >
 
void dataPVDmaster (int iT, int i, const std::string &fullNamePVDMaster, const std::string &namePiece)
 performes <DataSet timestep= ... file=namePiece >
 
void dataArray (const std::string &fullName)
 
void writeFunctor (const std::string &fullName, std::ofstream &fout, SuperF2D< T, W > &f)
 interpolates and writes functors stored at functors
 
void writeAnalyticalFunctor (const std::string &fullName, std::ofstream &fout, AnalyticalF2D< T, W > &f)
 
void writePosition (std::ofstream &fout)
 writes coordinates of points to plot
 

Protected Attributes

std::string _name
 
std::vector< SuperF2D< T, W > * > functors
 
std::vector< AnalyticalF2D< T, W > * > functorsA
 
std::vector< Vector< T, 2 > > pos
 
bool _binary
 
OstreamManager clout
 

Detailed Description

template<typename T, typename W>
class olb::VTUpointWriter< T, W, 2 >

Definition at line 39 of file vtuPointWriter.h.

Constructor & Destructor Documentation

◆ VTUpointWriter()

template<typename T , typename W >
olb::VTUpointWriter< T, W, 2 >::VTUpointWriter ( std::string const name,
bool binary = false )

Definition at line 35 of file vtuPointWriter.hh.

36 : _name( name ), _binary( binary ),
37 clout(std::cout, "VTUpointWriter2D")
38{}

Member Function Documentation

◆ addFunctor() [1/4]

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::addFunctor ( AnalyticalF2D< T, W > & f)

Definition at line 47 of file vtuPointWriter.hh.

47 {
48 functorsA.push_back(&f);
49}
std::vector< AnalyticalF2D< T, W > * > functorsA

◆ addFunctor() [2/4]

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::addFunctor ( AnalyticalF2D< T, W > & f,
const std::string & name )

accepts functors to write out

Definition at line 41 of file vtuPointWriter.hh.

41 {
42 f.getName() = name;
43 functorsA.push_back(&f);
44}
std::string name()
Returns name of FIELD for human consumption.
Definition fields.h:49

References olb::GenericF< T, S >::getName().

+ Here is the call graph for this function:

◆ addFunctor() [3/4]

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::addFunctor ( SuperF2D< T, W > & f)

Definition at line 58 of file vtuPointWriter.hh.

58 {
59 functors.push_back(&f);
60}
std::vector< SuperF2D< T, W > * > functors

◆ addFunctor() [4/4]

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::addFunctor ( SuperF2D< T, W > & f,
const std::string & name )

Definition at line 52 of file vtuPointWriter.hh.

52 {
53 f.getName() = name;
54 functors.push_back(&f);
55}

References olb::GenericF< T, S >::getName().

+ Here is the call graph for this function:

◆ addPoint()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::addPoint ( Vector< T, 2 > & new_position)

functions to add multiple or single points.

Definition at line 70 of file vtuPointWriter.hh.

70 {
71 pos.push_back(new_position);
72}
std::vector< Vector< T, 2 > > pos

◆ addPoints()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::addPoints ( std::vector< olb::Vector< T, 2 > > & new_positions)

Definition at line 63 of file vtuPointWriter.hh.

63 {
64 for( unsigned long i=0; i<new_positions.size(); i++ ){
65 pos.push_back(new_positions[i]);
66 }
67}

◆ closePVD()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::closePVD ( const std::string & fullNamePVD)
protected

Definition at line 149 of file vtuPointWriter.hh.

151{
152 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
153 if (!fout) {
154 clout << "Error: could not open " << fullNamePVD << std::endl;
155 }
156 fout << "</Collection>\n";
157 fout << "</VTKFile>\n";
158 fout.close();
159}

◆ closeVTU()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::closeVTU ( const std::string & fullNamePiece)
protected

performes </ImageData> and </VTKFile>

Definition at line 183 of file vtuPointWriter.hh.

185{
186 std::ofstream fout(fullNamePiece.c_str(), std::ios::app);
187 if (!fout) {
188 clout << "Error: could not open " << fullNamePiece << std::endl;
189 }
190 fout << "</UnstructuredGrid>\n";
191 fout << "</VTKFile>\n";
192 fout.close();
193}

◆ createMasterFile()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::createMasterFile ( )

Definition at line 124 of file vtuPointWriter.hh.

125{
126 std::string fullNamePVDmaster = singleton::directories().getVtkOutDir()
127 + createFileName(_name) + "_master.pvd";
128 preamblePVD(fullNamePVDmaster);
129 closePVD(fullNamePVDmaster);
130
131}
void preamblePVD(const std::string &fullNamePVD)
void closePVD(const std::string &fullNamePVD)
std::string getVtkOutDir() const
Definition singleton.h:103
Directories & directories()
Definition singleton.h:162
std::string createFileName(std::string name)
for .pvd masterFile
Definition fileName.hh:34

References olb::createFileName(), olb::singleton::directories(), and olb::singleton::Directories::getVtkOutDir().

+ Here is the call graph for this function:

◆ dataArray()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::dataArray ( const std::string & fullName)
protected

Definition at line 228 of file vtuPointWriter.hh.

230{
231 std::ofstream fout(fullName.c_str(), std::ios::app);
232 if (!fout) {
233 clout << "Error: could not open " << fullName << std::endl;
234 }
235
236 for(unsigned long i=0; i<functors.size(); i++){
237 writeFunctor( fullName, fout, *functors[i]);
238
239 }
240 for(unsigned long i=0; i<functorsA.size(); i++){
241 writeAnalyticalFunctor( fullName, fout, *functorsA[i]);
242 }
243
244 fout << "</PointData>" << std::endl;
245 fout << "<CellData /> " << std::endl;
246 fout << "<Cells>" << std::endl;
247 fout << "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">"
248 << std::endl;
249 for ( int i=0; i < 1; ++i){
250 for ( unsigned long j=0; j<pos.size(); ++j){
251 fout << j << " ";
252 }
253 }
254 fout << "</DataArray>" << std::endl;
255 fout << "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">"
256 << std::endl;
257 for ( int i=0; i < 1; ++i){
258 for ( unsigned long j=1; j <= pos.size(); ++j){
259 fout << j << " ";
260 }
261 }
262 fout << "</DataArray>" << std::endl;
263 fout << "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">"
264 << std::endl;
265 for ( unsigned long j=0; j < pos.size(); ++j){
266 fout << 1 << " ";
267 }
268 fout << "</DataArray>" << std::endl;
269 fout << "</Cells>" << std::endl;
270 fout << "<Points>" << std::endl;
271 writePosition( fout );
272 fout << "</Points>" << std::endl;
273 fout << "</Piece>" << std::endl;
274
275 fout.close();
276}
void writeFunctor(const std::string &fullName, std::ofstream &fout, SuperF2D< T, W > &f)
interpolates and writes functors stored at functors
void writePosition(std::ofstream &fout)
writes coordinates of points to plot
void writeAnalyticalFunctor(const std::string &fullName, std::ofstream &fout, AnalyticalF2D< T, W > &f)

◆ dataPVD()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::dataPVD ( int iT,
int i,
const std::string & fullNamePVD,
const std::string & namePiece )
protected

performes <DataSet timestep= ... file=namePiece >

Definition at line 197 of file vtuPointWriter.hh.

199{
200 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
201 if (!fout) {
202 clout << "Error: could not open " << fullNamePVD << std::endl;
203 }
204 fout << "<DataSet timestep=\"" << iT << "\" " << "group=\"\" part=\" " << i
205 << "\" " << "file=\"" << namePiece << "\"/>\n";
206 fout.close();
207}

◆ dataPVDmaster()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::dataPVDmaster ( int iT,
int i,
const std::string & fullNamePVDMaster,
const std::string & namePiece )
protected

performes <DataSet timestep= ... file=namePiece >

Definition at line 210 of file vtuPointWriter.hh.

212{
213 std::ofstream fout(fullNamePVDMaster.c_str(),
214 std::ios::in | std::ios::out | std::ios::ate);
215 if (fout) {
216 fout.seekp(-25, std::ios::end); // jump -25 form the end of file to overwrite closePVD
217 fout << "<DataSet timestep=\"" << iT << "\" " << "group=\"\" part=\" "
218 << i << "\" " << "file=\"" << namePiece << "\"/>\n";
219 fout.close();
220 closePVD(fullNamePVDMaster);
221 } else {
222 clout << "Error: could not open " << fullNamePVDMaster << std::endl;
223 }
224}

◆ preamblePVD()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::preamblePVD ( const std::string & fullNamePVD)
protected

Definition at line 134 of file vtuPointWriter.hh.

136{
137 std::ofstream fout(fullNamePVD.c_str(), std::ios::trunc);
138 if (!fout) {
139 clout << "Error: could not open " << fullNamePVD << std::endl;
140 }
141 fout << "<?xml version=\"1.0\"?>\n";
142 fout << "<VTKFile type=\"Collection\" version=\"0.1\" "
143 << "byte_order=\"LittleEndian\">\n" << "<Collection>\n";
144 fout.close();
145}

◆ preambleVTU()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::preambleVTU ( const std::string & fullName,
int num )
protected

performes <VTKFile ...>, <ImageData ...> and <PieceExtent ...>

Definition at line 163 of file vtuPointWriter.hh.

165{
166 std::ofstream fout(fullName.c_str(), std::ios::trunc);
167 if (!fout) {
168 clout << "Error: could not open " << fullName << std::endl;
169 }
170 fout << "<?xml version=\"1.0\"?>" << std::endl << std::flush;
171 fout
172 << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">"
173 << std::endl;
174 fout << "<UnstructuredGrid>" << std::endl;
175 fout << "<Piece NumberOfPoints=\"" << num
176 << "\" NumberOfCells=\"" << num << "\">"
177 << std::endl;
178 fout << "<PointData Vectors=\"Particles\">" << std::endl;
179 fout.close();
180}

◆ write() [1/2]

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::write ( std::size_t iT)

◆ write() [2/2]

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::write ( std::size_t iT,
std::vector< Vector< T, 2 > > & new_positions )

write function to call during runtime, also accepts additional points during call

◆ writeAnalyticalFunctor()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::writeAnalyticalFunctor ( const std::string & fullName,
std::ofstream & fout,
AnalyticalF2D< T, W > & f )
protected

Definition at line 301 of file vtuPointWriter.hh.

301 {
302 int dimF = f.getTargetDim();
303 if(!_binary){
304 fout << "<DataArray type=\"Float32\" Name=\""<< f.getName()<<"\" NumberOfComponents=\""<< dimF
305 << "\">" << std::endl;
306 }else if(_binary){
307 fout << "<DataArray type=\"Float32\" Name=\""<< f.getName()<<"\" format=\"binary\" encoding=\"base64\" NumberOfComponents=\""<< dimF
308 << "\">" << std::endl;
309 }
310
311 if(_binary){
312 fout.close();
313 }
314 size_t num = pos.size();
315
316 std::ofstream ofstr(fullName.c_str(),
317 std::ios::out | std::ios::app | std::ios::binary);
318 size_t binarySize = size_t( num*dimF * sizeof(float));
319 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
320 unsigned int uintBinarySize = (unsigned int) binarySize;
321 if(_binary){
322 sizeEncoder.encode(&uintBinarySize, 1);
323 }
324 Base64Encoder<float> dataEncoder(ofstr, num);
325 T* val = new T[dimF]();
326 for ( size_t j=0; j < num; ++j){
327 T point[2]= {pos[j][0],pos[j][1]};
328 for (int i = 0; i < dimF; i++){
329 f(val,point);
330 const float helper=float(val[i]);
331 if(!_binary){
332 fout << helper << " ";
333 }
334 else{
335 dataEncoder.encode(&helper, 1);
336 }
337 }
338 }
339 delete[] val;
340
341 ofstr.close();
342 if(_binary){
343 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
344 }
345 fout << "</DataArray>" << std::endl;
346
347}

References olb::Base64Encoder< T >::encode(), olb::GenericF< T, S >::getName(), and olb::GenericF< T, S >::getTargetDim().

+ Here is the call graph for this function:

◆ writeFunctor()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::writeFunctor ( const std::string & fullName,
std::ofstream & fout,
SuperF2D< T, W > & f )
protected

interpolates and writes functors stored at functors

Definition at line 293 of file vtuPointWriter.hh.

293 {
294
295 AnalyticalFfromSuperF2D<T> interpolateF( f, true );
296 writeAnalyticalFunctor( fullName, fout , interpolateF );
297
298}

◆ writePosition()

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 2 >::writePosition ( std::ofstream & fout)
protected

writes coordinates of points to plot

Definition at line 280 of file vtuPointWriter.hh.

280 {
281 fout << "<DataArray type=\"Float32\" Name=\"Point\" NumberOfComponents=\""<< 3
282 << "\">" << std::endl;
283
284 int num = pos.size();
285 for ( int j=0; j < num; ++j){
286 fout << pos[j][0] << " "<<pos[j][1] << " 0.0 ";
287 }
288 fout << "</DataArray>" << std::endl;
289}

Member Data Documentation

◆ _binary

template<typename T , typename W >
bool olb::VTUpointWriter< T, W, 2 >::_binary
protected

Definition at line 45 of file vtuPointWriter.h.

◆ _name

template<typename T , typename W >
std::string olb::VTUpointWriter< T, W, 2 >::_name
protected

Definition at line 41 of file vtuPointWriter.h.

◆ clout

template<typename T , typename W >
OstreamManager olb::VTUpointWriter< T, W, 2 >::clout
mutableprotected

Definition at line 46 of file vtuPointWriter.h.

◆ functors

template<typename T , typename W >
std::vector<SuperF2D<T,W>*> olb::VTUpointWriter< T, W, 2 >::functors
protected

Definition at line 42 of file vtuPointWriter.h.

◆ functorsA

template<typename T , typename W >
std::vector<AnalyticalF2D<T,W>*> olb::VTUpointWriter< T, W, 2 >::functorsA
protected

Definition at line 43 of file vtuPointWriter.h.

◆ pos

template<typename T , typename W >
std::vector<Vector<T,2> > olb::VTUpointWriter< T, W, 2 >::pos
protected

Definition at line 44 of file vtuPointWriter.h.


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