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

#include <vtuPointWriter.h>

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

Public Member Functions

 VTUpointWriter (std::string const name, bool binary=false)
 
void createMasterFile ()
 
void write (std::size_t iT, std::vector< Vector< T, 3 > > &new_positions)
 write function to call during runtime, also accepts additional points during call
 
void write (std::size_t iT)
 
void addFunctor (AnalyticalF3D< T, W > &f, const std::string &name)
 accepts functors to write out
 
void addFunctor (AnalyticalF3D< T, W > &f)
 
void addFunctor (SuperF3D< T, W > &f, const std::string &name)
 
void addFunctor (SuperF3D< T, W > &f)
 
void addPoint (Vector< T, 3 > &new_position)
 functions to add multiple or single points.
 
void addPoints (std::vector< Vector< T, 3 > > &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, SuperF3D< T, W > &f)
 interpolates and writes functors stored at functors
 
void writeAnalyticalFunctor (const std::string &fullName, std::ofstream &fout, AnalyticalF3D< T, W > &f)
 
void writePosition (std::ofstream &fout)
 writes coordinates of points to plot
 

Protected Attributes

std::string _name
 
std::vector< SuperF3D< T, W > * > functors
 
std::vector< AnalyticalF3D< T, W > * > functorsA
 
std::vector< Vector< T, 3 > > pos
 
bool _binary
 
OstreamManager clout
 

Detailed Description

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

Definition at line 88 of file vtuPointWriter.h.

Constructor & Destructor Documentation

◆ VTUpointWriter()

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

Definition at line 354 of file vtuPointWriter.hh.

356 : _name( name ), _binary( binary ),
357 clout(std::cout, "VTUpointWriter3D")
358{}

Member Function Documentation

◆ addFunctor() [1/4]

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

Definition at line 367 of file vtuPointWriter.hh.

367 {
368 functorsA.push_back(&f);
369}
std::vector< AnalyticalF3D< T, W > * > functorsA

◆ addFunctor() [2/4]

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

accepts functors to write out

Definition at line 361 of file vtuPointWriter.hh.

361 {
362 f.getName() = name;
363 functorsA.push_back(&f);
364}
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, 3 >::addFunctor ( SuperF3D< T, W > & f)

Definition at line 378 of file vtuPointWriter.hh.

378 {
379 functors.push_back(&f);
380}
std::vector< SuperF3D< T, W > * > functors

◆ addFunctor() [4/4]

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

Definition at line 372 of file vtuPointWriter.hh.

372 {
373 f.getName() = name;
374 functors.push_back(&f);
375}

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, 3 >::addPoint ( Vector< T, 3 > & new_position)

functions to add multiple or single points.

Definition at line 390 of file vtuPointWriter.hh.

390 {
391 pos.push_back(new_position);
392}
std::vector< Vector< T, 3 > > pos

◆ addPoints()

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

Definition at line 383 of file vtuPointWriter.hh.

383 {
384 for( unsigned long i=0; i<new_positions.size(); i++ ){
385 pos.push_back(new_positions[i]);
386 }
387}

◆ closePVD()

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

Definition at line 533 of file vtuPointWriter.hh.

535{
536 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
537 if (!fout) {
538 clout << "Error: could not open " << fullNamePVD << std::endl;
539 }
540 fout << "</Collection>\n";
541 fout << "</VTKFile>\n";
542 fout.close();
543}

◆ closeVTU()

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

performes </ImageData> and </VTKFile>

Definition at line 464 of file vtuPointWriter.hh.

466{
467 std::ofstream fout(fullNamePiece.c_str(), std::ios::app);
468 if (!fout) {
469 clout << "Error: could not open " << fullNamePiece << std::endl;
470 }
471 fout << "</UnstructuredGrid>\n";
472 fout << "</VTKFile>\n";
473 fout.close();
474}

◆ createMasterFile()

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

Definition at line 508 of file vtuPointWriter.hh.

509{
510 std::string fullNamePVDmaster = singleton::directories().getVtkOutDir()
511 + createFileName(_name) + "_master.pvd";
512 preamblePVD(fullNamePVDmaster);
513 closePVD(fullNamePVDmaster);
514
515}
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, 3 >::dataArray ( const std::string & fullName)
protected

Definition at line 546 of file vtuPointWriter.hh.

548{
549 std::ofstream fout(fullName.c_str(), std::ios::app);
550 if (!fout) {
551 clout << "Error: could not open " << fullName << std::endl;
552 }
553
554 for(unsigned long i=0; i<functors.size(); i++){
555 writeFunctor( fullName, fout, *functors[i]);
556 }
557 for(unsigned long i=0; i<functorsA.size(); i++){
558 writeAnalyticalFunctor( fullName, fout, *functorsA[i]);
559 }
560 fout << "</PointData>" << std::endl;
561 fout << "<CellData /> " << std::endl;
562 fout << "<Cells>" << std::endl;
563 fout << "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">"
564 << std::endl;
565 for ( size_t i=0; i < 1; ++i){
566 for ( unsigned long j=0; j<pos.size(); ++j){
567 fout << j << " ";
568 }
569 }
570 fout << "</DataArray>" << std::endl;
571 fout << "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">"
572 << std::endl;
573 for ( size_t i=0; i < 1; ++i){
574 for ( unsigned long j=1; j <= pos.size(); ++j){
575 fout << j << " ";
576 }
577 }
578 fout << "</DataArray>" << std::endl;
579 fout << "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">"
580 << std::endl;
581 for ( unsigned long j=0; j < pos.size(); ++j){
582 fout << 1 << " ";
583 }
584 fout << "</DataArray>" << std::endl;
585 fout << "</Cells>" << std::endl;
586 fout << "<Points>" << std::endl;
587 writePosition( fout );
588 fout << "</Points>" << std::endl;
589 fout << "</Piece>" << std::endl;
590
591 fout.close();
592}
void writeFunctor(const std::string &fullName, std::ofstream &fout, SuperF3D< 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, AnalyticalF3D< T, W > &f)

◆ dataPVD()

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

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

Definition at line 478 of file vtuPointWriter.hh.

480{
481 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
482 if (!fout) {
483 clout << "Error: could not open " << fullNamePVD << std::endl;
484 }
485 fout << "<DataSet timestep=\"" << iT << "\" " << "group=\"\" part=\" " << i
486 << "\" " << "file=\"" << namePiece << "\"/>\n";
487 fout.close();
488}

◆ dataPVDmaster()

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

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

Definition at line 491 of file vtuPointWriter.hh.

493{
494 std::ofstream fout(fullNamePVDMaster.c_str(),
495 std::ios::in | std::ios::out | std::ios::ate);
496 if (fout) {
497 fout.seekp(-25, std::ios::end); // jump -25 form the end of file to overwrite closePVD
498 fout << "<DataSet timestep=\"" << iT << "\" " << "group=\"\" part=\" "
499 << i << "\" " << "file=\"" << namePiece << "\"/>\n";
500 fout.close();
501 closePVD(fullNamePVDMaster);
502 } else {
503 clout << "Error: could not open " << fullNamePVDMaster << std::endl;
504 }
505}

◆ preamblePVD()

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

Definition at line 519 of file vtuPointWriter.hh.

521{
522 std::ofstream fout(fullNamePVD.c_str(), std::ios::trunc);
523 if (!fout) {
524 clout << "Error: could not open " << fullNamePVD << std::endl;
525 }
526 fout << "<?xml version=\"1.0\"?>\n";
527 fout << "<VTKFile type=\"Collection\" version=\"0.1\" "
528 << "byte_order=\"LittleEndian\">\n" << "<Collection>\n";
529 fout.close();
530}

◆ preambleVTU()

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

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

Definition at line 444 of file vtuPointWriter.hh.

446{
447 std::ofstream fout(fullName.c_str(), std::ios::trunc);
448 if (!fout) {
449 clout << "Error: could not open " << fullName << std::endl;
450 }
451 fout << "<?xml version=\"1.0\"?>" << std::endl << std::flush;
452 fout
453 << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">"
454 << std::endl;
455 fout << "<UnstructuredGrid>" << std::endl;
456 fout << "<Piece NumberOfPoints=\"" << num
457 << "\" NumberOfCells=\"" << num << "\">"
458 << std::endl;
459 fout << "<PointData Vectors=\"Particles\">" << std::endl;
460 fout.close();
461}

◆ write() [1/2]

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

◆ write() [2/2]

template<typename T , typename W >
void olb::VTUpointWriter< T, W, 3 >::write ( std::size_t iT,
std::vector< Vector< T, 3 > > & 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, 3 >::writeAnalyticalFunctor ( const std::string & fullName,
std::ofstream & fout,
AnalyticalF3D< T, W > & f )
protected

Definition at line 615 of file vtuPointWriter.hh.

615 {
616 int dimF = f.getTargetDim();
617 if(!_binary){
618 fout << "<DataArray type=\"Float32\" Name=\""<< f.getName()<<"\" NumberOfComponents=\""<< dimF
619 << "\">" << std::endl;
620 }else if(_binary){
621 fout << "<DataArray type=\"Float32\" Name=\""<< f.getName()<<"\" format=\"binary\" encoding=\"base64\" NumberOfComponents=\""<< dimF
622 << "\">" << std::endl;
623 }
624
625 if(_binary){
626 fout.close();
627 }
628 size_t num = pos.size();
629 std::ofstream ofstr(fullName.c_str(),
630 std::ios::out | std::ios::app | std::ios::binary);
631 size_t binarySize = size_t( num*dimF * sizeof(float));
632 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
633 unsigned int uintBinarySize = (unsigned int) binarySize;
634 if(_binary){
635 sizeEncoder.encode(&uintBinarySize, 1);
636 }
637
638 Base64Encoder<float> dataEncoder(ofstr, num);
639 T* val = new T[dimF]();
640 for ( size_t j=0; j < num; ++j){
641 T point[3]= {pos[j][0],pos[j][1],pos[j][2]};
642 for (int i = 0; i < dimF; i++){
643 f(val,point);
644 if(!_binary){
645 fout << val[i] << " ";
646 }
647 else{
648 const float helper=float(val[i]);
649 dataEncoder.encode(&helper, 1);
650 }
651 }
652 }
653 delete[] val;
654 ofstr.close();
655 if(_binary){
656 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
657 }
658 fout << "</DataArray>" << std::endl;
659
660}

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, 3 >::writeFunctor ( const std::string & fullName,
std::ofstream & fout,
SuperF3D< T, W > & f )
protected

interpolates and writes functors stored at functors

Definition at line 608 of file vtuPointWriter.hh.

608 {
609 AnalyticalFfromSuperF3D<T> interpolateF( f, true );
610 writeAnalyticalFunctor( fullName, fout , interpolateF );
611}

◆ writePosition()

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

writes coordinates of points to plot

Definition at line 595 of file vtuPointWriter.hh.

595 {
596 fout << "<DataArray type=\"Float32\" Name=\"Point\" NumberOfComponents=\""<< 3
597 << "\">" << std::endl;
598
599 int num = pos.size();
600 for ( int j=0; j < num; ++j){
601 fout << pos[j][0] << " "<< pos[j][1] << " " << pos[j][2] << " ";
602 }
603 fout << "</DataArray>" << std::endl;
604}

Member Data Documentation

◆ _binary

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

Definition at line 94 of file vtuPointWriter.h.

◆ _name

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

Definition at line 90 of file vtuPointWriter.h.

◆ clout

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

Definition at line 95 of file vtuPointWriter.h.

◆ functors

template<typename T , typename W >
std::vector<SuperF3D<T,W>*> olb::VTUpointWriter< T, W, 3 >::functors
protected

Definition at line 91 of file vtuPointWriter.h.

◆ functorsA

template<typename T , typename W >
std::vector<AnalyticalF3D<T,W>*> olb::VTUpointWriter< T, W, 3 >::functorsA
protected

Definition at line 92 of file vtuPointWriter.h.

◆ pos

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

Definition at line 93 of file vtuPointWriter.h.


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