29#ifndef BLOCK_VTK_WRITER_3D_HH
30#define BLOCK_VTK_WRITER_3D_HH
44 : clout( std::cout,
"BlockVTKwriter3D" ), _name(name), _binary(binary)
56 if ( _pointerVec.empty() ) {
57 clout <<
"Error: Please add functor via addFunctor()";
61 auto it = _pointerVec.cbegin();
66 int nx = (**it).getBlockStructure().getNx() -1;
67 int ny = (**it).getBlockStructure().getNy() -1;
68 int nz = (**it).getBlockStructure().getNz() -1;
73 preamble( fullNameVti, nx,ny,nz, originX,originY,originZ );
76 for (
auto functor = _pointerVec.cbegin(); functor != _pointerVec.cend(); ++functor) {
77 writeRawDataBinary( fullNameVti, **functor, nx, ny, nz);
81 for (
auto functor = _pointerVec.cbegin(); functor != _pointerVec.cend(); ++functor) {
82 writeRawData( fullNameVti, **functor, nx, ny, nz);
85 closePreamble( fullNameVti );
102 preamble( fullNameVti, nx,ny,nz, originX,originY,originZ );
104 writeRawData( fullNameVti, f, nx,ny,nz );
107 writeRawDataBinary( fullNameVti, f, nx,ny,nz );
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;
136 double spacing = 1/double(nx);
138 fout <<
"<?xml version=\"1.0\"?>\n";
139 fout <<
"<VTKFile type=\"ImageData\" version=\"0.1\" "
140 <<
"byte_order=\"LittleEndian\">\n";
141 fout <<
"<ImageData WholeExtent=\""
142 <<
"0" <<
" "<< nx <<
" "
143 <<
"0" <<
" "<< ny <<
" "
145 <<
"\" Origin=\"" << originX <<
" " << originY <<
" " << originZ
146 <<
"\" Spacing=\"" << spacing <<
" " << spacing <<
" " << spacing <<
"\">\n";
148 fout <<
"<Piece Extent=\""
149 << 0 <<
" "<< nx <<
" "
150 << 0 <<
" "<< ny <<
" "
151 << 0 <<
" "<< nz <<
"\">\n";
153 fout <<
"<PointData>\n";
159void BlockVTKwriter3D<T>::closePreamble(
const std::string& fullNamePiece)
162 std::ofstream fout(fullNamePiece.c_str(), std::ios::app );
164 clout <<
"Error: could not open " << fullNamePiece << std::endl;
166 fout <<
"</PointData>\n";
167 fout <<
"</Piece>\n";
168 fout <<
"</ImageData>\n";
169 fout <<
"</VTKFile>\n";
177void BlockVTKwriter3D<T>::writeRawData(
const std::string& fullNameVti, BlockF3D<T>& f,
178 int nx,
int ny,
int nz)
180 std::ofstream fout(fullNameVti.c_str(), std::ios::app);
182 clout <<
"Error: could not open " << fullNameVti << std::endl;
186 fout <<
"<DataArray " ;
187 fout <<
"type=\"Float32\" Name=\"" << f.getName() <<
"\" "
188 <<
"NumberOfComponents=\"" << f.getTargetDim() <<
"\">\n";
192 T evaluated[f.getTargetDim()];
193 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
194 evaluated[iDim] = T();
196 for (i[2] = 0; i[2] < nz+1; ++i[2]) {
197 for (i[1] = 0; i[1] < ny+1; ++i[1]) {
198 for (i[0] = 0; i[0] < nx+1; ++i[0]) {
200 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
202 fout << evaluated[iDim] <<
" ";
209 fout <<
"\n</DataArray>\n";
221void BlockVTKwriter3D<T>::writeRawDataBinary(
const std::string& fullNameVti,
222 BlockF3D<T>& f,
int nx,
int ny,
int nz)
224 const char* fileName = fullNameVti.c_str();
225 std::ofstream fout(fileName, std::ios::app);
227 clout <<
"Error: could not open " << fileName << std::endl;
231 fout <<
"<DataArray " ;
232 if (f.getTargetDim() == 1) {
233 fout <<
"type=\"Float32\" Name=\"" << f.getName() <<
"\" "
234 <<
"format=\"binary\" encoding=\"base64\">\n";
237 fout <<
"type=\"Float32\" Name=\"" << f.getName() <<
"\" "
238 <<
"format=\"binary\" encoding=\"base64\" "
239 <<
"NumberOfComponents=\"" << f.getTargetDim() <<
"\">\n";
244 std::ofstream ofstr( fileName, std::ios::out | std::ios::app | std::ios::binary );
246 clout <<
"Error: could not open " << fileName << std::endl;
249 size_t fullSize = f.getTargetDim() * (1 + nx) * (1 + ny) * (1 + nz);
250 size_t binarySize = size_t( fullSize *
sizeof(
float) );
252 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
253 unsigned int uintBinarySize = (
unsigned int)binarySize;
254 sizeEncoder.encode(&uintBinarySize, 1);
256 Base64Encoder<float>* dataEncoder =
nullptr;
257 dataEncoder =
new Base64Encoder<float>( ofstr, fullSize );
260 T evaluated[f.getTargetDim()];
261 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
262 evaluated[iDim] = T();
264 for (i[2] = 0; i[2] < nz+1; ++i[2]) {
265 for (i[1] = 0; i[1] < ny+1; ++i[1]) {
266 for (i[0] = 0; i[0] < nx+1; ++i[0]) {
268 for (
int iDim = 0; iDim<f.getTargetDim(); ++iDim) {
270 const float evaluated2 = float( evaluated[iDim] );
271 dataEncoder->encode( &evaluated2, 1 );
280 std::ofstream foutt(fileName, std::ios::out | std::ios::app);
282 clout <<
"Error: could not open " << fileName << std::endl;
284 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< 3 > & getBlockStructure() const
int getNy() const
Read only access to block height.
int getNx() const
Read only access to block width.
int getNz() const
Read only access to block height.
BlockVTKwriter3D writes any BLockF3D to vtk-based output files.
BlockVTKwriter3D(std::string name, bool binary=true)
void clearAddedFunctors()
to clear stored functors
void write(BlockF3D< T > &f, int iT=0)
method calls preamble(), pointData(), data() and coresponding closing methods.
void addFunctor(BlockF3D< 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.