25#ifndef VTU_POINT_WRITER_HH
26#define VTU_POINT_WRITER_HH
34template<
typename T,
typename W>
36 : _name( name ), _binary( binary ),
37 clout(std::cout,
"VTUpointWriter2D")
40template<
typename T,
typename W>
43 functorsA.push_back(&f);
46template<
typename T,
typename W>
48 functorsA.push_back(&f);
51template<
typename T,
typename W>
54 functors.push_back(&f);
57template<
typename T,
typename W>
59 functors.push_back(&f);
62template<
typename T,
typename W>
64 for(
unsigned long i=0; i<new_positions.size(); i++ ){
65 pos.push_back(new_positions[i]);
69template<
typename T,
typename W>
71 pos.push_back(new_position);
75template<
typename T,
typename W>
79#ifdef PARALLEL_MODE_MPI
85 f->getSuperStructure().communicate();
94 preamblePVD( fullNamePVD );
95 std::string namePiece =
"data/" +
createFileName(_name, iT, 0) +
".vtu";
98 dataPVD(iT, 1, fullNamePVD, namePiece);
101 dataPVDmaster(iT, 1, fullNamePVDmaster, namePiece);
102 closePVD(fullNamePVD);
107 preambleVTU(fullNameVTU, pos.size());
110 this->dataArray( fullNameVTU );
111 closeVTU(fullNameVTU);
116template<
typename T,
typename W>
119 addPoints(new_positions);
123template<
typename T,
typename W>
128 preamblePVD(fullNamePVDmaster);
129 closePVD(fullNamePVDmaster);
133template<
typename T,
typename W>
135 const std::string& fullNamePVD)
137 std::ofstream fout(fullNamePVD.c_str(), std::ios::trunc);
139 clout <<
"Error: could not open " << fullNamePVD << std::endl;
141 fout <<
"<?xml version=\"1.0\"?>\n";
142 fout <<
"<VTKFile type=\"Collection\" version=\"0.1\" "
143 <<
"byte_order=\"LittleEndian\">\n" <<
"<Collection>\n";
148template<
typename T,
typename W>
150 const std::string& fullNamePVD)
152 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
154 clout <<
"Error: could not open " << fullNamePVD << std::endl;
156 fout <<
"</Collection>\n";
157 fout <<
"</VTKFile>\n";
162template<
typename T,
typename W>
164 const std::string& fullName,
int num)
166 std::ofstream fout(fullName.c_str(), std::ios::trunc);
168 clout <<
"Error: could not open " << fullName << std::endl;
170 fout <<
"<?xml version=\"1.0\"?>" << std::endl << std::flush;
172 <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">"
174 fout <<
"<UnstructuredGrid>" << std::endl;
175 fout <<
"<Piece NumberOfPoints=\"" << num
176 <<
"\" NumberOfCells=\"" << num <<
"\">"
178 fout <<
"<PointData Vectors=\"Particles\">" << std::endl;
182template<
typename T,
typename W>
184 const std::string& fullNamePiece)
186 std::ofstream fout(fullNamePiece.c_str(), std::ios::app);
188 clout <<
"Error: could not open " << fullNamePiece << std::endl;
190 fout <<
"</UnstructuredGrid>\n";
191 fout <<
"</VTKFile>\n";
196template<
typename T,
typename W>
198 const std::string& fullNamePVD,
const std::string& namePiece)
200 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
202 clout <<
"Error: could not open " << fullNamePVD << std::endl;
204 fout <<
"<DataSet timestep=\"" << iT <<
"\" " <<
"group=\"\" part=\" " << i
205 <<
"\" " <<
"file=\"" << namePiece <<
"\"/>\n";
209template<
typename T,
typename W>
211 const std::string& fullNamePVDMaster,
const std::string& namePiece)
213 std::ofstream fout(fullNamePVDMaster.c_str(),
214 std::ios::in | std::ios::out | std::ios::ate);
216 fout.seekp(-25, std::ios::end);
217 fout <<
"<DataSet timestep=\"" << iT <<
"\" " <<
"group=\"\" part=\" "
218 << i <<
"\" " <<
"file=\"" << namePiece <<
"\"/>\n";
220 closePVD(fullNamePVDMaster);
222 clout <<
"Error: could not open " << fullNamePVDMaster << std::endl;
227template<
typename T,
typename W>
229 const std::string& fullName )
231 std::ofstream fout(fullName.c_str(), std::ios::app);
233 clout <<
"Error: could not open " << fullName << std::endl;
236 for(
unsigned long i=0; i<functors.size(); i++){
237 writeFunctor( fullName, fout, *functors[i]);
240 for(
unsigned long i=0; i<functorsA.size(); i++){
241 writeAnalyticalFunctor( fullName, fout, *functorsA[i]);
244 fout <<
"</PointData>" << std::endl;
245 fout <<
"<CellData /> " << std::endl;
246 fout <<
"<Cells>" << std::endl;
247 fout <<
"<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">"
249 for (
int i=0; i < 1; ++i){
250 for (
unsigned long j=0; j<pos.size(); ++j){
254 fout <<
"</DataArray>" << std::endl;
255 fout <<
"<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">"
257 for (
int i=0; i < 1; ++i){
258 for (
unsigned long j=1; j <= pos.size(); ++j){
262 fout <<
"</DataArray>" << std::endl;
263 fout <<
"<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">"
265 for (
unsigned long j=0; j < pos.size(); ++j){
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;
279template<
typename T,
typename W>
281 fout <<
"<DataArray type=\"Float32\" Name=\"Point\" NumberOfComponents=\""<< 3
282 <<
"\">" << std::endl;
284 int num = pos.size();
285 for (
int j=0; j < num; ++j){
286 fout << pos[j][0] <<
" "<<pos[j][1] <<
" 0.0 ";
288 fout <<
"</DataArray>" << std::endl;
292template<
typename T,
typename W>
296 writeAnalyticalFunctor( fullName, fout , interpolateF );
300template<
typename T,
typename W>
304 fout <<
"<DataArray type=\"Float32\" Name=\""<< f.
getName()<<
"\" NumberOfComponents=\""<< dimF
305 <<
"\">" << std::endl;
307 fout <<
"<DataArray type=\"Float32\" Name=\""<< f.
getName()<<
"\" format=\"binary\" encoding=\"base64\" NumberOfComponents=\""<< dimF
308 <<
"\">" << std::endl;
314 size_t num = pos.size();
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));
320 unsigned int uintBinarySize = (
unsigned int) binarySize;
322 sizeEncoder.
encode(&uintBinarySize, 1);
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++){
330 const float helper=float(val[i]);
332 fout << helper <<
" ";
335 dataEncoder.
encode(&helper, 1);
343 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
345 fout <<
"</DataArray>" << std::endl;
353template<
typename T,
typename W>
356 : _name( name ), _binary( binary ),
357 clout(std::cout,
"VTUpointWriter3D")
360template<
typename T,
typename W>
363 functorsA.push_back(&f);
366template<
typename T,
typename W>
368 functorsA.push_back(&f);
371template<
typename T,
typename W>
374 functors.push_back(&f);
377template<
typename T,
typename W>
379 functors.push_back(&f);
382template<
typename T,
typename W>
384 for(
unsigned long i=0; i<new_positions.size(); i++ ){
385 pos.push_back(new_positions[i]);
389template<
typename T,
typename W>
391 pos.push_back(new_position);
395template<
typename T,
typename W>
399#ifdef PARALLEL_MODE_MPI
404 f->getSuperStructure().communicate();
413 preamblePVD( fullNamePVD );
414 std::string namePiece =
"data/" +
createFileName(_name, iT, 0) +
".vtu";
417 dataPVD(iT, 1, fullNamePVD, namePiece);
420 dataPVDmaster(iT, 1, fullNamePVDmaster, namePiece);
421 closePVD(fullNamePVD);
426 preambleVTU(fullNameVTU, pos.size());
428 this->dataArray( fullNameVTU );
430 closeVTU(fullNameVTU);
435template<
typename T,
typename W>
438 addPoints(new_positions);
443template<
typename T,
typename W>
445 const std::string& fullName,
int num)
447 std::ofstream fout(fullName.c_str(), std::ios::trunc);
449 clout <<
"Error: could not open " << fullName << std::endl;
451 fout <<
"<?xml version=\"1.0\"?>" << std::endl << std::flush;
453 <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">"
455 fout <<
"<UnstructuredGrid>" << std::endl;
456 fout <<
"<Piece NumberOfPoints=\"" << num
457 <<
"\" NumberOfCells=\"" << num <<
"\">"
459 fout <<
"<PointData Vectors=\"Particles\">" << std::endl;
463template<
typename T,
typename W>
465 const std::string& fullNamePiece)
467 std::ofstream fout(fullNamePiece.c_str(), std::ios::app);
469 clout <<
"Error: could not open " << fullNamePiece << std::endl;
471 fout <<
"</UnstructuredGrid>\n";
472 fout <<
"</VTKFile>\n";
477template<
typename T,
typename W>
479 const std::string& fullNamePVD,
const std::string& namePiece)
481 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
483 clout <<
"Error: could not open " << fullNamePVD << std::endl;
485 fout <<
"<DataSet timestep=\"" << iT <<
"\" " <<
"group=\"\" part=\" " << i
486 <<
"\" " <<
"file=\"" << namePiece <<
"\"/>\n";
490template<
typename T,
typename W>
492 const std::string& fullNamePVDMaster,
const std::string& namePiece)
494 std::ofstream fout(fullNamePVDMaster.c_str(),
495 std::ios::in | std::ios::out | std::ios::ate);
497 fout.seekp(-25, std::ios::end);
498 fout <<
"<DataSet timestep=\"" << iT <<
"\" " <<
"group=\"\" part=\" "
499 << i <<
"\" " <<
"file=\"" << namePiece <<
"\"/>\n";
501 closePVD(fullNamePVDMaster);
503 clout <<
"Error: could not open " << fullNamePVDMaster << std::endl;
507template<
typename T,
typename W>
512 preamblePVD(fullNamePVDmaster);
513 closePVD(fullNamePVDmaster);
518template<
typename T,
typename W>
520 const std::string& fullNamePVD)
522 std::ofstream fout(fullNamePVD.c_str(), std::ios::trunc);
524 clout <<
"Error: could not open " << fullNamePVD << std::endl;
526 fout <<
"<?xml version=\"1.0\"?>\n";
527 fout <<
"<VTKFile type=\"Collection\" version=\"0.1\" "
528 <<
"byte_order=\"LittleEndian\">\n" <<
"<Collection>\n";
532template<
typename T,
typename W>
534 const std::string& fullNamePVD)
536 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
538 clout <<
"Error: could not open " << fullNamePVD << std::endl;
540 fout <<
"</Collection>\n";
541 fout <<
"</VTKFile>\n";
545template<
typename T,
typename W>
547 const std::string& fullName )
549 std::ofstream fout(fullName.c_str(), std::ios::app);
551 clout <<
"Error: could not open " << fullName << std::endl;
554 for(
unsigned long i=0; i<functors.size(); i++){
555 writeFunctor( fullName, fout, *functors[i]);
557 for(
unsigned long i=0; i<functorsA.size(); i++){
558 writeAnalyticalFunctor( fullName, fout, *functorsA[i]);
560 fout <<
"</PointData>" << std::endl;
561 fout <<
"<CellData /> " << std::endl;
562 fout <<
"<Cells>" << std::endl;
563 fout <<
"<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">"
565 for (
size_t i=0; i < 1; ++i){
566 for (
unsigned long j=0; j<pos.size(); ++j){
570 fout <<
"</DataArray>" << std::endl;
571 fout <<
"<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">"
573 for (
size_t i=0; i < 1; ++i){
574 for (
unsigned long j=1; j <= pos.size(); ++j){
578 fout <<
"</DataArray>" << std::endl;
579 fout <<
"<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">"
581 for (
unsigned long j=0; j < pos.size(); ++j){
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;
594template<
typename T,
typename W>
596 fout <<
"<DataArray type=\"Float32\" Name=\"Point\" NumberOfComponents=\""<< 3
597 <<
"\">" << std::endl;
599 int num = pos.size();
600 for (
int j=0; j < num; ++j){
601 fout << pos[j][0] <<
" "<< pos[j][1] <<
" " << pos[j][2] <<
" ";
603 fout <<
"</DataArray>" << std::endl;
607template<
typename T,
typename W>
610 writeAnalyticalFunctor( fullName, fout , interpolateF );
614template<
typename T,
typename W>
618 fout <<
"<DataArray type=\"Float32\" Name=\""<< f.
getName()<<
"\" NumberOfComponents=\""<< dimF
619 <<
"\">" << std::endl;
621 fout <<
"<DataArray type=\"Float32\" Name=\""<< f.
getName()<<
"\" format=\"binary\" encoding=\"base64\" NumberOfComponents=\""<< dimF
622 <<
"\">" << std::endl;
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));
633 unsigned int uintBinarySize = (
unsigned int) binarySize;
635 sizeEncoder.
encode(&uintBinarySize, 1);
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++){
645 fout << val[i] <<
" ";
648 const float helper=float(val[i]);
649 dataEncoder.
encode(&helper, 1);
656 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
658 fout <<
"</DataArray>" << std::endl;
AnalyticalF are applications from DD to XD, where X is set by the constructor.
Converts super functions to analytical functions.
Converts super functors to analytical functors.
void encode(const T *data, size_t length)
int getTargetDim() const
read only access to member variable _n
std::string & getName()
read and write access to name
represents all functors that operate on a SuperStructure<T,2> in general
represents all functors that operate on a SuperStructure<T,3> in general
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, std::vector< Vector< T, 3 > > &new_positions)
write function to call during runtime, also accepts additional points during call
std::string getVtkOutDir() const
int getRank() const
Returns the process ID.
void write(BlockReduction3D2D< T > &blockReduction, int iT, const plotParam< T > param={}, const std::vector< T > &valueArea=std::vector< T >{})
This function is used to plot heat maps as jpeg files.
Directories & directories()
Top level namespace for all of OpenLB.
std::string createFileName(std::string name)
for .pvd masterFile