29#ifndef SUPER_VTM_WRITER_2D_HH
30#define SUPER_VTM_WRITER_2D_HH
48template<
typename T,
typename OUT_T,
typename W>
50 : clout( std::cout,
"SuperVTMwriter2D" ), _createFile(false), _name(name), _overlap(overlap), _binary(binary)
52 static_assert(std::is_same_v<OUT_T, float> || std::is_same_v<OUT_T, double>,
53 "OUT_T must be either float or double");
56template<
typename T,
typename OUT_T,
typename W>
60#ifdef PARALLEL_MODE_MPI
65 if ( _pointerVec.empty() ) {
66 clout <<
"Error: Did you add a Functor ?";
71 f->getSuperStructure().communicate();
77 auto it_begin = _pointerVec.cbegin();
78 if (it_begin == _pointerVec.end()) {
79 throw std::runtime_error(
"No functor to write");
81 CuboidGeometry2D<T> const& cGeometry = (**it_begin).getSuperStructure().getCuboidGeometry();
83 LoadBalancer<T>& load = (**it_begin).getSuperStructure().getLoadBalancer();
89 dataPVDmaster( iT, pathPVD,
"data/" +
createFileName( _name, iT ) +
".vtm" );
94 for (
int iC = 0; iC < cGeometry.
getNc(); iC++) {
100 int originLatticeR[3] = {int()};
101 for (
int iCloc = 0; iCloc < load.
size(); iCloc++) {
102 int nx = cGeometry.
get(load.
glob(iCloc)).getNx();
103 int ny = cGeometry.
get(load.
glob(iCloc)).getNy();
112 originLatticeR[0] = load.
glob(iCloc);
113 T originPhysR[2] = {T()};
114 cGeometry.
getPhysR(originPhysR,originLatticeR);
116 preambleVTI(fullNameVTI, -_overlap,-_overlap, nx+_overlap-1, ny+_overlap-1, originPhysR[0],originPhysR[1], delta);
117 for (
auto it : _pointerVec) {
119 dataArrayBinary(fullNameVTI, (*it), load.
glob(iCloc), nx,ny);
122 dataArray(fullNameVTI, (*it), load.
glob(iCloc), nx,ny);
125 closePiece(fullNameVTI);
126 closeVTI(fullNameVTI);
131template<
typename T,
typename OUT_T,
typename W>
141#ifdef PARALLEL_MODE_MPI
152 preambleVTM(pathVTM);
153 for (
int iC = 0; iC < cGeometry.
getNc(); iC++) {
156 dataVTM( iC, pathVTM, nameVTI );
161 for (
int iCloc = 0; iCloc < load.
size(); iCloc++) {
163 int nx = cGeometry.
get(load.
glob(iCloc)).getNx();
164 int ny = cGeometry.
get(load.
glob(iCloc)).getNy();
172 int const originLatticeR[3] = {load.
glob(iCloc),0,0};
173 T originPhysR[2] = {T()};
174 cGeometry.
getPhysR(originPhysR,originLatticeR);
176 preambleVTI(fullNameVTI, -_overlap,-_overlap, nx+_overlap-1, ny+_overlap-1, originPhysR[0],originPhysR[1], delta);
178 dataArrayBinary(fullNameVTI, f, load.
glob(iCloc), nx,ny);
181 dataArray(fullNameVTI, f, load.
glob(iCloc), nx,ny);
183 closePiece(fullNameVTI);
184 closeVTI(fullNameVTI);
188template<
typename T,
typename OUT_T,
typename W>
194template<
typename T,
typename OUT_T,
typename W>
198#ifdef PARALLEL_MODE_MPI
204 preamblePVD(fullNamePVDmaster);
205 closePVD(fullNamePVDmaster);
210template<
typename T,
typename OUT_T,
typename W>
213 _pointerVec.push_back(&f);
216template<
typename T,
typename OUT_T,
typename W>
220 _pointerVec.push_back(&f);
223template<
typename T,
typename OUT_T,
typename W>
229template<
typename T,
typename OUT_T,
typename W>
239template<
typename T,
typename OUT_T,
typename W>
241 int x0,
int y0,
int x1,
int y1, T originX, T originY, T delta)
244 const BaseType<T> d_origin[2] = {originX, originY};
245 std::ofstream fout(fullName, std::ios::trunc);
247 clout <<
"Error: could not open " << fullName << std::endl;
249 fout <<
"<?xml version=\"1.0\"?>\n";
250 fout <<
"<VTKFile type=\"ImageData\" version=\"0.1\" "
251 <<
"byte_order=\"LittleEndian\">\n";
252 fout <<
"<ImageData WholeExtent=\""
253 << x0 <<
" "<< x1 <<
" "
254 << y0 <<
" "<< y1 <<
" "
256 <<
"\" Origin=\"" << d_origin[0] <<
" " << d_origin[1] <<
" " <<
"0"
257 <<
"\" Spacing=\"" << d_delta <<
" " << d_delta <<
" " << d_delta <<
"\">\n";
258 fout <<
"<Piece Extent=\""
259 << x0 <<
" "<< x1 <<
" "
260 << y0 <<
" "<< y1 <<
" "
261 << 0 <<
" "<< 0 <<
"\">\n";
262 fout <<
"<PointData>\n";
266template<
typename T,
typename OUT_T,
typename W>
267void SuperVTMwriter2D<T,OUT_T,W>::closeVTI(
const std::string& fullNamePiece)
269 std::ofstream fout(fullNamePiece, std::ios::app );
271 clout <<
"Error: could not open " << fullNamePiece << std::endl;
273 fout <<
"</ImageData>\n";
274 fout <<
"</VTKFile>\n";
278template<
typename T,
typename OUT_T,
typename W>
279void SuperVTMwriter2D<T,OUT_T,W>::preamblePVD(
const std::string& fullNamePVD)
281 std::ofstream fout(fullNamePVD, std::ios::trunc);
283 clout <<
"Error: could not open " << fullNamePVD << std::endl;
285 fout <<
"<?xml version=\"1.0\"?>\n";
286 fout <<
"<VTKFile type=\"Collection\" version=\"0.1\" "
287 <<
"byte_order=\"LittleEndian\">\n"
292template<
typename T,
typename OUT_T,
typename W>
293void SuperVTMwriter2D<T,OUT_T,W>::closePVD(
const std::string& fullNamePVD)
295 std::ofstream fout(fullNamePVD, std::ios::app );
297 clout <<
"Error: could not open " << fullNamePVD << std::endl;
299 fout <<
"</Collection>\n";
300 fout <<
"</VTKFile>\n";
304template<
typename T,
typename OUT_T,
typename W>
305void SuperVTMwriter2D<T,OUT_T,W>::preambleVTM(
const std::string& fullNamePVD)
307 std::ofstream fout(fullNamePVD, std::ios::trunc);
309 clout <<
"Error: could not open " << fullNamePVD << std::endl;
311 fout <<
"<?xml version=\"1.0\"?>\n";
312 fout <<
"<VTKFile type=\"vtkMultiBlockDataSet\" version=\"1.0\" "
313 <<
"byte_order=\"LittleEndian\">\n"
314 <<
"<vtkMultiBlockDataSet>\n" ;
318template<
typename T,
typename OUT_T,
typename W>
319void SuperVTMwriter2D<T,OUT_T,W>::closeVTM(
const std::string& fullNamePVD)
321 std::ofstream fout(fullNamePVD, std::ios::app );
323 clout <<
"Error: could not open " << fullNamePVD << std::endl;
325 fout <<
"</vtkMultiBlockDataSet>\n";
326 fout <<
"</VTKFile>\n";
330template<
typename T,
typename OUT_T,
typename W>
331void SuperVTMwriter2D<T,OUT_T,W>::dataVTM(
int iC,
const std::string& fullNamePVD,
332 const std::string& namePiece)
334 std::ofstream fout(fullNamePVD, std::ios::app);
336 clout <<
"Error: could not open " << fullNamePVD << std::endl;
338 fout <<
"<Block index=\"" << iC <<
"\" >\n";
339 fout <<
"<DataSet index= \"0\" " <<
"file=\"" << namePiece <<
"\">\n"
341 fout <<
"</Block>\n";
345template<
typename T,
typename OUT_T,
typename W>
346void SuperVTMwriter2D<T,OUT_T,W>::dataPVDmaster(
int iT,
347 const std::string& fullNamePVDMaster,
348 const std::string& namePiece)
350 std::ofstream fout(fullNamePVDMaster, std::ios::in | std::ios::out | std::ios::ate);
352 fout.seekp(-25,std::ios::end);
354 fout <<
"<DataSet timestep=\"" << iT <<
"\" "
355 <<
"group=\"\" part=\"\" "
356 <<
"file=\"" << namePiece <<
"\"/>\n";
358 closePVD(fullNamePVDMaster);
361 clout <<
"Error: could not open " << fullNamePVDMaster << std::endl;
365template<
typename T,
typename OUT_T,
typename W>
366void SuperVTMwriter2D<T,OUT_T,W>::dataArray(
const std::string& fullName,
367 SuperF2D<T,W>& f,
int iC,
int nx,
int ny)
369 std::cout <<
"DIOCANE" <<std::endl <<std::endl <<std::endl <<std::endl <<std::endl;
370 std::ofstream fout( fullName, std::ios::out | std::ios::app );
372 clout <<
"Error: could not open " << fullName << std::endl;
375 fout <<
"<DataArray " ;
376 if constexpr (std::is_same_v<OUT_T, float>) {
377 fout <<
"type=\"Float32\" Name=\"" << f.getName() <<
"\" "
378 <<
"NumberOfComponents=\"" << f.getTargetDim() <<
"\">\n";
380 else if constexpr (std::is_same_v<OUT_T, double>) {
381 fout <<
"type=\"Float64\" Name=\"" << f.getName() <<
"\" "
382 <<
"NumberOfComponents=\"" << f.getTargetDim() <<
"\">\n";
385 int i[3] = {iC, 0, 0};
386 W evaluated[f.getTargetDim()];
387 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
388 evaluated[iDim] = W();
392 std::vector<int> tmpVec( 3,
int(0) );
393 for (i[2]=-_overlap; i[2] < ny+_overlap; ++i[2]) {
394 for (i[1]=-_overlap; i[1] < nx+_overlap; ++i[1]) {
396 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
398 fout << evaluated[iDim] <<
" ";
402 fout <<
"</DataArray>\n";
406template<
typename T,
typename OUT_T,
typename W>
407void SuperVTMwriter2D<T,OUT_T,W>::dataArrayBinary(
const std::string& fullName,
408 SuperF2D<T,W>& f,
int iC,
int nx,
int ny)
410 std::ofstream fout( fullName, std::ios::out | std::ios::app );
412 clout <<
"Error: could not open " << fullName << std::endl;
415 fout <<
"<DataArray ";
416 if constexpr (std::is_same_v<OUT_T, float>) {
417 fout <<
"type=\"Float32\" Name=\"" << f.getName() <<
"\" "
418 <<
"format=\"binary\" encoding=\"base64\" "
419 <<
"NumberOfComponents=\"" << f.getTargetDim() <<
"\">\n";
421 else if constexpr (std::is_same_v<OUT_T, double>) {
422 fout <<
"type=\"Float64\" Name=\"" << f.getName() <<
"\" "
423 <<
"format=\"binary\" encoding=\"base64\" "
424 <<
"NumberOfComponents=\"" << f.getTargetDim() <<
"\">\n";
428 std::ofstream ofstr( fullName, std::ios::out | std::ios::app | std::ios::binary );
430 clout <<
"Error: could not open " << fullName << std::endl;
433 size_t fullSize = f.getTargetDim() * (nx+2*_overlap) * (ny+2*_overlap);
434 size_t binarySize = size_t( fullSize*
sizeof(OUT_T) );
436 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
437 unsigned int uintBinarySize = (
unsigned int)binarySize;
438 sizeEncoder.encode(&uintBinarySize, 1);
440 Base64Encoder<OUT_T>* dataEncoder =
new Base64Encoder<OUT_T>( ofstr, fullSize );
442 int i[3] = {iC, 0, 0};
443 W evaluated[f.getTargetDim()];
444 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
445 evaluated[iDim] = W();
448 std::unique_ptr<OUT_T[]> bufferFloat(
new OUT_T[fullSize]);
449 for (i[2] = -_overlap; i[2] < ny+_overlap; ++i[2]) {
450 for (i[1] = -_overlap; i[1] < nx+_overlap; ++i[1]) {
452 for (
int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
453 bufferFloat[ itter ] = OUT_T( evaluated[iDim] );
458 dataEncoder->encode( &bufferFloat[0], fullSize );
461 std::ofstream ffout( fullName, std::ios::out | std::ios::app );
463 clout <<
"Error: could not open " << fullName << std::endl;
465 ffout <<
"\n</DataArray>\n";
470template<
typename T,
typename OUT_T,
typename W>
471void SuperVTMwriter2D<T,OUT_T,W>::closePiece(
const std::string& fullNamePiece)
473 std::ofstream fout(fullNamePiece, std::ios::app );
475 clout <<
"Error: could not open " << fullNamePiece << std::endl;
477 fout <<
"</PointData>\n";
478 fout <<
"</Piece>\n";
A cuboid structure represents the grid of a considered domain.
int getNc() const
Returns the number of cuboids in t < 2he structure.
Cuboid2D< T > getMotherCuboid() const
Returns the smallest cuboid that includes all cuboids of the structure.
Cuboid2D< T > & get(int i)
Read and write access to the cuboids.
std::vector< T > getPhysR(int iCglob, int iX, int iY) const
Returns the physical position to the given lattice position respecting periodicity for the overlap no...
std::string & getName()
read and write access to name
Base class for all LoadBalancer.
represents all functors that operate on a SuperStructure<T,2> in general
SuperStructure< T, 2 > & getSuperStructure()
CuboidGeometry< T, D > & getCuboidGeometry()
Read and write access to cuboid geometry.
virtual void communicate()
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
SuperVTMwriter2D writes any SuperF2D to vtk-based output files.
void createMasterFile()
have to be called before calling write(int iT=0), since it creates
void write(int iT=0)
writes functors stored in pointerVec every thread writes a vti file with data from his cuboids the vt...
SuperVTMwriter2D(std::string name, int overlap=1, bool binary=true)
void clearAddedFunctors()
to clear stored functors, not yet used due to lack of necessity
std::string getName() const
getter for _name
void addFunctor(SuperF2D< T, W > &f)
put functor to _pointerVec to simplify writing process of several functors
std::string getVtkOutDir() const
int getRank() const
Returns the process ID.
The description of a vector of 2D cuboid – header file.
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
typename util::BaseTypeHelper< T >::type BaseType
Definition of singletons: global, publicly available information.
A method to write vtk data for cuboid geometries (only for uniform grids) – header file.