29#ifndef BLOCK_VTK_WRITER_2D_HH
30#define BLOCK_VTK_WRITER_2D_HH
45 : clout( std::cout,
"BlockVTKwriter2D" ), _name(name), _binary(binary)
59 if ( _pointerVec.empty() ) {
60 clout <<
"Error: Please add functor via addFunctor()";
63 auto it = _pointerVec.cbegin();
68 int nx = (**it).getBlockStructure().getNx() -1;
69 int ny = (**it).getBlockStructure().getNy() -1;
75 preamble( fullNameVti, nx,ny, originX,originY,originZ );
77 for (
auto functor = _pointerVec.cbegin(); functor != _pointerVec.cend(); ++functor) {
78 writeRawDataBinary( fullNameVti, **functor, nx, ny);
82 for (
auto functor = _pointerVec.cbegin(); functor != _pointerVec.cend(); ++functor) {
83 writeRawData( fullNameVti, **functor, nx, ny);
86 closePreamble( fullNameVti );
102 preamble( fullNameVti, nx,ny, originX,originY,originZ );
104 writeRawDataBinary( fullNameVti, f, nx,ny );
107 writeRawData( fullNameVti, f, nx,ny );
109 closePreamble( fullNameVti );
115 _pointerVec.push_back(&f);
126 T originX, T originY, T originZ)
129 std::ofstream fout(fullName.c_str());
131 clout <<
"Error: could not open " << fullName << std::endl;
137 double spacing = double(1.0/nx);
139 fout <<
"<?xml version=\"1.0\"?>\n";
140 fout <<
"<VTKFile type=\"ImageData\" version=\"0.1\" "
141 <<
"byte_order=\"LittleEndian\">\n";
142 fout <<
"<ImageData WholeExtent=\""
143 << 0 <<
" "<< nx <<
" "
144 << 0 <<
" "<< ny <<
" "
146 <<
"\" Origin=\"" << originX <<
" " << originY <<
" " << originZ
147 <<
"\" Spacing=\"" << spacing <<
" " << spacing <<
" " << spacing <<
"\">\n";
149 fout <<
"<Piece Extent=\""
150 << 0 <<
" "<< nx <<
" "
151 << 0 <<
" "<< ny <<
" "
152 << 0 <<
" "<< 0 <<
"\">\n";
154 fout <<
"<PointData>\n";
160void BlockVTKwriter2D<T>::closePreamble(
const std::string& fullNamePiece)
163 std::ofstream fout(fullNamePiece.c_str(), std::ios::app );
165 clout <<
"Error: could not open " << fullNamePiece << std::endl;
167 fout <<
"</PointData>\n";
168 fout <<
"</Piece>\n";
169 fout <<
"</ImageData>\n";
170 fout <<
"</VTKFile>\n";
176void BlockVTKwriter2D<T>::writeRawData(
const std::string& fullNameVti, BlockF2D<T>& f,
179 std::ofstream fout(fullNameVti.c_str(), std::ios::app);
181 clout <<
"Error: could not open " << fullNameVti << std::endl;
185 fout <<
"<DataArray " ;
186 fout <<
"type=\"Float32\" Name=\"" << f.getName() <<
"\" "
187 <<
"NumberOfComponents=\"" << f.getTargetDim() <<
"\">\n";
191 T evaluated[f.getTargetDim()];
192 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
193 evaluated[iDim] = T();
195 for (i[1] = 0; i[1] < ny+1; ++i[1]) {
196 for (i[0] = 0; i[0] < nx+1; ++i[0]) {
198 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
200 fout << evaluated[iDim] <<
" ";
207 fout <<
"\n</DataArray>\n";
214void BlockVTKwriter2D<T>::writeRawDataBinary(
const std::string& fullNameVti,
215 BlockF2D<T>& f,
int nx,
int ny)
217 const char* fileName = fullNameVti.c_str();
218 std::ofstream fout(fileName, std::ios::app);
220 clout <<
"Error: could not open " << fileName << std::endl;
224 fout <<
"<DataArray " ;
225 if (f.getTargetDim() == 1) {
226 fout <<
"type=\"Float32\" Name=\"" << f.getName() <<
"\" "
227 <<
"format=\"binary\" encoding=\"base64\">\n";
230 fout <<
"type=\"Float32\" Name=\"" << f.getName() <<
"\" "
231 <<
"format=\"binary\" encoding=\"base64\" "
232 <<
"NumberOfComponents=\"" << f.getTargetDim() <<
"\">\n";
237 std::ofstream ofstr( fileName, std::ios::out | std::ios::app | std::ios::binary );
239 clout <<
"Error: could not open " << fileName << std::endl;
242 size_t fullSize = f.getTargetDim() * (1 + nx) * (1 + ny) * (1);
243 size_t binarySize = size_t( fullSize *
sizeof(
float) );
245 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
246 unsigned int uintBinarySize = (
unsigned int)binarySize;
247 sizeEncoder.encode(&uintBinarySize, 1);
249 Base64Encoder<float>* dataEncoder =
nullptr;
250 dataEncoder =
new Base64Encoder<float>( ofstr, fullSize );
254 T evaluated[f.getTargetDim()];
255 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
256 evaluated[iDim] = T();
258 for (i[1] = 0; i[1] < ny+1; ++i[1]) {
259 for (i[0] = 0; i[0] < nx+1; ++i[0]) {
261 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
263 const float evaluated2 = float( evaluated[iDim] );
264 dataEncoder->encode( &evaluated2, 1 );
272 std::ofstream foutt(fileName, std::ios::out | std::ios::app);
274 clout <<
"Error: could not open " << fileName << std::endl;
276 foutt <<
"\n</DataArray>\n";
A method to write vtk data for block geometries (only for uniform grids) – header file.
represents all functors that operate on a cuboid in general, mother class of BlockLatticeF,...
virtual BlockStructureD< 2 > & getBlockStructure()
virtual destructor for defined behaviour
int getNy() const
Read only access to block height.
int getNx() const
Read only access to block width.
BlockVTKwriter2D writes any BLockF2D to vtk-based output files.
void write(int iT=0)
method calls preamble(), pointData(), data() and coresponding closing methods.
void clearAddedFunctors()
to clear stored functors
BlockVTKwriter2D(std::string name, bool binary=true)
void addFunctor(BlockF2D< T > &f)
put functor to _pointerVec to simplify writing process of several functors
std::string & getName()
read and write access to name
std::string getVtkOutDir() const
These functions help you to create file names.
Wrapper functions that simplify the use of MPI.
Directories & directories()
Top level namespace for all of OpenLB.
std::string createFileName(std::string name)
for .pvd masterFile
Definition of singletons: global, publicly available information.