OpenLB 1.7
Loading...
Searching...
No Matches
superParticleSysVTUout.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2016 Thomas Henn
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24#ifndef SUPERPARTICLESYSVTUOUT_HH
25#define SUPERPARTICLESYSVTUOUT_HH
26
28
29namespace olb {
30
31template<typename T, template<typename U> class PARTICLETYPE>
33{
34 return _psys._pSystems.size();
35}
36
37template<typename T, template<typename U> class PARTICLETYPE>
39{
40 _properties |= pref;
41}
42
43template<typename T, template<typename U> class PARTICLETYPE>
45 : _psys(rhs._psys), _name(rhs._name), _properties(rhs._properties), _binary(rhs._binary), _haveMaster(rhs._haveMaster), clout(std::cout, "SuperParticleSysVtuWriter")
46{
47}
48
49template<typename T, template<typename U> class PARTICLETYPE>
51 : _psys(rhs._psys), _name(rhs._name), _properties(rhs._properties), _binary(rhs._binary), _haveMaster(rhs._haveMaster), clout(std::cout, "SuperParticleSysVtuWriter")
52{
53}
54
56template<typename T, template<typename U> class PARTICLETYPE>
58 std::string const filename, unsigned short properties, bool binary)
59 : _psys(psys), _name(filename), _properties(properties), _binary(binary), _haveMaster(false), clout(std::cout, "SuperParticleSysVtuWriter")
61}
63template<typename T, template<typename U> class PARTICLETYPE>
65{
66 //std::cout << "Write base" << std::endl;
67 int rank = 0;
68 int size = 1;
69#ifdef PARALLEL_MODE_MPI
71 size = singleton::mpi().getSize();
72#endif
73
74 if (rank == 0) { // master only
75 if (!_haveMaster) {
76 createMasterFile();
77 }
79 std::string fullNamePVDmaster = singleton::directories().getVtkOutDir()
80 + createFileName(_name) + "_master.pvd";
81 std::string fullNamePVD = singleton::directories().getVtkOutDir() + "data/"
82 + createFileName(_name, iT) + ".pvd";
83
84 preamblePVD(fullNamePVD); // timestep
85 for (int iR = 0; iR < size; iR++) { // cuboid
86 std::string namePiece = "data/" + createFileName(_name, iT, iR) + ".vtu";
87 // puts name of .vti piece to a .pvd file [fullNamePVD]
88 dataPVD(iT, iR, fullNamePVD, namePiece);
89 // adds a namePiece to master.pvd file.
90 // To do so we overwrite closePVD() and add new entry.
91 dataPVDmaster(iT, iR, fullNamePVDmaster, namePiece);
92 } // cuboid
93 closePVD(fullNamePVD); // timestep
94 } // master only
95
96 std::string fullNameVTU = singleton::directories().getVtkOutDir()
97 + "data/" + createFileName(_name, iT, rank) + ".vtu";
98 preambleVTU(fullNameVTU);
99 if (_binary) {
100 this->dataArrayBinary(fullNameVTU);
101 }
102 else {
103 this->dataArray(fullNameVTU);
104 }
105 closeVTU(fullNameVTU);
106}
107
108template<typename T, template<typename U> class PARTICLETYPE>
110{
111 int rank = 0;
112#ifdef PARALLEL_MODE_MPI
113 rank = singleton::mpi().getRank();
114#endif
115 if (rank == 0) {
116 std::string fullNamePVDmaster = singleton::directories().getVtkOutDir()
117 + createFileName(_name) + "_master.pvd";
118 preamblePVD(fullNamePVDmaster);
119 closePVD(fullNamePVDmaster);
120 _haveMaster = true;
121 }
122}
123
124template<typename T, template<typename U> class PARTICLETYPE>
126 const std::string& fullName)
127{
128 std::ofstream fout(fullName.c_str(), std::ios::trunc);
129 if (!fout) {
130 clout << "Error: could not open " << fullName << std::endl;
131 }
132 fout << "<?xml version=\"1.0\"?>" << std::endl << std::flush;
133 fout
134 << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">"
135 << std::endl;
136 fout << "<UnstructuredGrid>" << std::endl;
137 fout << "<Piece NumberOfPoints=\"" << _psys.rankNumOfParticles()
138 << "\" NumberOfCells=\"" << _psys.rankNumOfParticles() << "\">"
139 << std::endl;
140 fout << "<PointData Vectors=\"Particles\">" << std::endl;
141 fout.close();
142}
143
144template<typename T, template<typename U> class PARTICLETYPE>
146 const std::string& fullNamePiece)
147{
148 std::ofstream fout(fullNamePiece.c_str(), std::ios::app);
149 if (!fout) {
150 clout << "Error: could not open " << fullNamePiece << std::endl;
151 }
152 fout << "</UnstructuredGrid>\n";
153 fout << "</VTKFile>\n";
154 fout.close();
155}
156
157template<typename T, template<typename U> class PARTICLETYPE>
159 const std::string& fullNamePVD)
160{
161 std::ofstream fout(fullNamePVD.c_str(), std::ios::trunc);
162 if (!fout) {
163 clout << "Error: could not open " << fullNamePVD << std::endl;
164 }
165
166 fout << "<?xml version=\"1.0\"?>\n";
167 fout << "<VTKFile type=\"Collection\" version=\"0.1\" "
168 << "byte_order=\"LittleEndian\">\n" << "<Collection>\n";
169 fout.close();
170}
171
172template<typename T, template<typename U> class PARTICLETYPE>
174 const std::string& fullNamePVD)
175{
176 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
177 if (!fout) {
178 clout << "Error: could not open " << fullNamePVD << std::endl;
179 }
180 fout << "</Collection>\n";
181 fout << "</VTKFile>\n";
182 fout.close();
183}
184
185template<typename T, template<typename U> class PARTICLETYPE>
187 const std::string& fullNamePVD, const std::string& namePiece)
188{
189 std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
190 if (!fout) {
191 clout << "Error: could not open " << fullNamePVD << std::endl;
192 }
193
194 fout << "<DataSet timestep=\"" << iT << "\" " << "group=\"\" part=\" " << iC
195 << "\" " << "file=\"" << namePiece << "\"/>\n";
196 fout.close();
197}
198
199template<typename T, template<typename U> class PARTICLETYPE>
201 const std::string& fullNamePVDMaster, const std::string& namePiece)
202{
203 std::ofstream fout(fullNamePVDMaster.c_str(),
204 std::ios::in | std::ios::out | std::ios::ate);
205 if (fout) {
206 fout.seekp(-25, std::ios::end); // jump -25 form the end of file to overwrite closePVD
207
208 fout << "<DataSet timestep=\"" << iT << "\" " << "group=\"\" part=\" "
209 << iC << "\" " << "file=\"" << namePiece << "\"/>\n";
210 fout.close();
211 closePVD(fullNamePVDMaster);
212 }
213 else {
214 clout << "Error: could not open " << fullNamePVDMaster << std::endl;
215 }
216}
217
218template<typename T, template<typename U> class PARTICLETYPE>
220 const std::string& fullName)
221{
222 //std::cout<< "Base member accessed" << std::endl;
223 std::ofstream fout(fullName.c_str(), std::ios::app);
224 if (!fout) {
225 clout << "Error: could not open " << fullName << std::endl;
226 }
227
228 if (_properties & particleProperties::radius) {
229 fout
230 << "<DataArray type=\"Float32\" Name=\"Radius\" NumberOfComponents=\"1\" format=\"ascii\">"
231 << std::endl;
232 for (auto pS : _psys._pSystems) {
233 for (auto& p : pS->_particles) {
234 fout << p.getRad() << " ";
235 }
236 }
237 fout << "</DataArray>" << std::endl;
238 }
239 if (_properties & particleProperties::mass) {
240 fout
241 << "<DataArray type=\"Float32\" Name=\"Mass\" NumberOfComponents=\"1\" format=\"ascii\">"
242 << std::endl;
243 for (auto pS : _psys._pSystems) {
244 for (auto& p : pS->_particles) {
245 fout << p.getMass() << " ";
246 }
247 }
248 fout << "</DataArray>" << std::endl;
249 }
250 if (_properties & particleProperties::cuboid) {
251 fout
252 << "<DataArray type=\"Int16\" Name=\"Cuboid\" NumberOfComponents=\"1\" format=\"ascii\">"
253 << std::endl;
254 for (auto pS : _psys._pSystems) {
255 for (auto& p : pS->_particles) {
256 fout << p.getCuboid() << " ";
257 }
258 }
259 fout << "</DataArray>" << std::endl;
260 }
261 if (_properties & particleProperties::active) {
262 fout
263 << "<DataArray type=\"Int16\" Name=\"Active\" NumberOfComponents=\"1\" format=\"ascii\">"
264 << std::endl;
265 for (auto pS : _psys._pSystems) {
266 for (auto& p : pS->_particles) {
267 if (p.getActive()) {
268 fout << "1 ";
269 }
270 else {
271 fout << "0 ";
272 }
273 }
274 }
275 fout << "</DataArray>" << std::endl;
276 }
277 if (_properties & particleProperties::velocity) {
278 fout
279 << "<DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"ascii\">"
280 << std::endl;
281 for (auto pS : _psys._pSystems) {
282 for (auto& p : pS->_particles) {
283 fout << p.getVel()[0] << " " << p.getVel()[1] << " " << p.getVel()[2]
284 << " ";
285 }
286 }
287 fout << "</DataArray>" << std::endl;
288 }
289 if (_properties & particleProperties::force) {
290 fout
291 << "<DataArray type=\"Float32\" Name=\"Force\" NumberOfComponents=\"3\" format=\"ascii\">"
292 << std::endl;
293 for (auto pS : _psys._pSystems) {
294 for (auto& p : pS->_particles) {
295 fout << p.getForce()[0] << " " << p.getForce()[1] << " " << p.getForce()[2]
296 << " ";
297 }
298 }
299 fout << "</DataArray>" << std::endl;
300 }
301 fout << "</PointData>" << std::endl;
302
303 fout << "<CellData /> " << std::endl;
304 fout << "<Cells>" << std::endl;
305 fout << "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">"
306 << std::endl;
307 int32_t i = 0;
308 for (auto pS : _psys._pSystems) {
309 for (unsigned int p=0; p<pS->_particles.size(); p++) {
310 fout << i++ << " ";
311 }
312 }
313 fout << "</DataArray>" << std::endl;
314 fout << "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">"
315 << std::endl;
316 i = 1;
317 for (auto pS : _psys._pSystems) {
318 for (unsigned int p=0; p<pS->_particles.size(); p++) {
319 fout << i++ << " ";
320 }
321 }
322 fout << "</DataArray>" << std::endl;
323 fout << "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">"
324 << std::endl;
325 for (auto pS : _psys._pSystems) {
326 for (unsigned int p=0; p<pS->_particles.size(); p++) {
327 fout << 1 << " ";
328 }
329 }
330 fout << "</DataArray>" << std::endl;
331 fout << "</Cells>" << std::endl;
332 fout << "<Points>" << std::endl;
333 fout
334 << "<DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\">"
335 << std::endl;
336
337 for (auto pS : _psys._pSystems) {
338 for (auto& p : pS->_particles) {
339 fout << p.getPos()[0] << " " << p.getPos()[1] << " " << p.getPos()[2] << " ";
340 }
341 }
342
343 fout << "</DataArray>" << std::endl;
344 fout << "</Points>" << std::endl;
345 fout << "</Piece>" << std::endl;
346 fout.close();
347}
348
349template<typename T, template<typename U> class PARTICLETYPE>
351 const std::string& fullName)
352{
353 //std::cout<< "Base member accessed - binary" << std::endl;
354 std::ofstream fout(fullName.c_str(), std::ios::app);
355 if (!fout) {
356 clout << "Error: could not open " << fullName << std::endl;
357 }
358
359 if (_properties & particleProperties::radius) {
360 fout
361 << "<DataArray type=\"Float32\" Name=\"Radius\" NumberOfComponents=\"1\" format=\"binary\" encoding=\"base64\">"
362 << std::endl;
363 fout.close();
364
365 std::ofstream ofstr(fullName.c_str(),
366 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
367 if (!ofstr) {
368 clout << "Error: could not open " << fullName << std::endl;
369 }
370
371 size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
372 size_t binarySize = size_t(fullSize * sizeof(float));
373 // writes first number, which have to be the size(byte) of the following data
374 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
375 unsigned int uintBinarySize = (unsigned int) binarySize;
376 sizeEncoder.encode(&uintBinarySize, 1);
377 // write numbers from functor
378 Base64Encoder<float> dataEncoder(ofstr, fullSize);
379 for (auto pS : _psys._pSystems) {
380 for (auto& p : pS->_particles) {
381 const float tmp = float(p.getRad());
382 dataEncoder.encode(&tmp, 1);
383 }
384 }
385 ofstr.close();
386
387 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
388 fout << "</DataArray>" << std::endl;
389 }
390
391 if (_properties & particleProperties::mass) {
392 fout
393 << "<DataArray type=\"Float32\" Name=\"Mass\" NumberOfComponents=\"1\" format=\"binary\" encoding=\"base64\">"
394 << std::endl;
395 fout.close();
396
397 std::ofstream ofstr(fullName.c_str(),
398 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
399 if (!ofstr) {
400 clout << "Error: could not open " << fullName << std::endl;
401 }
402
403 size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
404 size_t binarySize = size_t(fullSize * sizeof(float));
405 // writes first number, which have to be the size(byte) of the following data
406 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
407 unsigned int uintBinarySize = (unsigned int) binarySize;
408 sizeEncoder.encode(&uintBinarySize, 1);
409 // write numbers from functor
410 Base64Encoder<float> dataEncoder(ofstr, fullSize);
411 for (auto pS : _psys._pSystems) {
412 for (auto& p : pS->_particles) {
413 const float tmp = float(p.getMass());
414 dataEncoder.encode(&tmp, 1);
415 }
416 }
417 ofstr.close();
418
419 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
420 fout << "</DataArray>" << std::endl;
421 }
422 if (_properties & particleProperties::cuboid) {
423 fout
424 << "<DataArray type=\"Int32\" Name=\"Cuboid\" NumberOfComponents=\"1\" format=\"binary\" encoding=\"base64\">"
425 << std::endl;
426 fout.close();
427
428 std::ofstream ofstr(fullName.c_str(),
429 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
430 if (!ofstr) {
431 clout << "Error: could not open " << fullName << std::endl;
432 }
433
434 size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
435 size_t binarySize = size_t(fullSize * sizeof(int));
436 // writes first number, which have to be the size(byte) of the following data
437 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
438 unsigned int uintBinarySize = (unsigned int) binarySize;
439 sizeEncoder.encode(&uintBinarySize, 1);
440 // write numbers from functor
441 Base64Encoder<int> dataEncoder(ofstr,
442 fullSize);
443 for (auto pS : _psys._pSystems) {
444 for (auto& p : pS->_particles) {
445 const int tmp = int(p.getCuboid());
446 dataEncoder.encode(&tmp, 1);
447 }
448 }
449 ofstr.close();
450
451 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
452 fout << "</DataArray>" << std::endl;
453 }
454 if (_properties & particleProperties::active) {
455 fout
456 << "<DataArray type=\"Int32\" Name=\"Active\" NumberOfComponents=\"1\" format=\"binary\" encoding=\"base64\">"
457 << std::endl;
458 fout.close();
459
460 std::ofstream ofstr(fullName.c_str(),
461 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
462 if (!ofstr) {
463 clout << "Error: could not open " << fullName << std::endl;
464 }
465
466 size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
467 size_t binarySize = size_t(fullSize * sizeof(int));
468 // writes first number, which have to be the size(byte) of the following data
469 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
470 unsigned int uintBinarySize = (unsigned int) binarySize;
471 sizeEncoder.encode(&uintBinarySize, 1);
472 // write numbers from functor
473 Base64Encoder<int> dataEncoder(ofstr, fullSize);
474 for (auto pS : _psys._pSystems) {
475 for (auto& p : pS->_particles) {
476 int tmp = 0;
477 if (p.getActive()) {
478 tmp = 1;
479 }
480 dataEncoder.encode(&tmp, 1);
481 }
482 }
483 ofstr.close();
484
485 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
486 fout << "</DataArray>" << std::endl;
487 }
488
489 if (_properties & particleProperties::velocity) {
490 fout
491 << "<DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"binary\" encoding=\"base64\">"
492 << std::endl;
493 fout.close();
494
495 std::ofstream ofstr(fullName.c_str(),
496 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
497 if (!ofstr) {
498 clout << "Error: could not open " << fullName << std::endl;
499 }
500
501 size_t fullSize = _psys.rankNumOfParticles() * 3; // how many numbers to write
502 size_t binarySize = size_t(fullSize * sizeof(float));
503 // writes first number, which have to be the size(byte) of the following data
504 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
505 unsigned int uintBinarySize = (unsigned int) binarySize;
506 sizeEncoder.encode(&uintBinarySize, 1);
507 // write numbers from functor
508 Base64Encoder<float> dataEncoder(ofstr, fullSize);
509 for (auto pS : _psys._pSystems) {
510 for (auto& p : pS->_particles) {
511 for (int iDim = 0; iDim < 3; ++iDim) {
512 const float tmp = float(p.getVel()[iDim]);
513 dataEncoder.encode(&tmp, 1);
514 }
515 }
516 }
517 ofstr.close();
518 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
519 fout << "</DataArray>" << std::endl;
520 }
521 if (_properties & particleProperties::force) {
522 fout
523 << "<DataArray type=\"Float32\" Name=\"Force\" NumberOfComponents=\"3\" format=\"binary\" encoding=\"base64\">"
524 << std::endl;
525 fout.close();
526
527 std::ofstream ofstr(fullName.c_str(),
528 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
529 if (!ofstr) {
530 clout << "Error: could not open " << fullName << std::endl;
531 }
532
533 size_t fullSize = _psys.rankNumOfParticles() * 3; // how many numbers to write
534 size_t binarySize = size_t(fullSize * sizeof(float));
535 // writes first number, which have to be the size(byte) of the following data
536 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
537 unsigned int uintBinarySize = (unsigned int) binarySize;
538 sizeEncoder.encode(&uintBinarySize, 1);
539 // write numbers from functor
540 Base64Encoder<float> dataEncoder(ofstr, fullSize);
541 for (auto pS : _psys._pSystems) {
542 for (auto& p : pS->_particles) {
543 for (int iDim = 0; iDim < 3; ++iDim) {
544 const float tmp = float(p.getForce()[iDim]);
545 dataEncoder.encode(&tmp, 1);
546 }
547 }
548 }
549 ofstr.close();
550 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
551 fout << "</DataArray>" << std::endl;
552 }
553 fout << "</PointData>" << std::endl;
554
555 fout << "<CellData /> " << std::endl;
556 fout << "<Cells>" << std::endl;
557 fout << "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"binary\" encoding=\"base64\">" << std::endl;
558 fout.close();
559 {
560 std::ofstream ofstr(fullName.c_str(),
561 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
562 if (!ofstr) {
563 clout << "Error: could not open " << fullName << std::endl;
564 }
565
566 size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
567 size_t binarySize = size_t(fullSize * sizeof(int));
568 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
569 unsigned int uintBinarySize = (unsigned int) binarySize;
570 sizeEncoder.encode(&uintBinarySize, 1);
571 Base64Encoder<int32_t> dataEncoder(ofstr, fullSize);
572 int i = 0;
573 for (auto pS : _psys._pSystems) {
574 for (unsigned int p=0; p<pS->_particles.size(); p++) {
575 const int32_t tmp = i++;
576 dataEncoder.encode(&tmp, 1);
577 }
578 }
579 ofstr.close();
580 }
581 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
582 fout << "</DataArray>" << std::endl;
583
584 fout << "<DataArray type=\"Int32\" Name=\"offsets\" format=\"binary\" encoding=\"base64\">"
585 << std::endl;
586 fout.close();
587 {
588 std::ofstream ofstr(fullName.c_str(), std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
589 if (!ofstr) {
590 clout << "Error: could not open " << fullName << std::endl;
591 }
592
593 size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
594 size_t binarySize = size_t(fullSize * sizeof(int));
595 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
596 unsigned int uintBinarySize = (unsigned int) binarySize;
597 sizeEncoder.encode(&uintBinarySize, 1);
598 Base64Encoder<int32_t> dataEncoder(ofstr, fullSize);
599 int i = 1;
600 for (auto pS : _psys._pSystems) {
601 for (unsigned int p=0; p<pS->_particles.size(); p++) {
602 const int32_t tmp = i++;
603 dataEncoder.encode(&tmp, 1);
604 }
605 }
606 ofstr.close();
607 }
608 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
609 fout << "</DataArray>" << std::endl;
610
611
612 fout << "<DataArray type=\"UInt8\" Name=\"types\" format=\"binary\" encoding=\"base64\">"
613 << std::endl;
614 fout.close();
615 {
616 std::ofstream ofstr(fullName.c_str(),
617 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
618 if (!ofstr) {
619 clout << "Error: could not open " << fullName << std::endl;
620 }
621
622 size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
623 size_t binarySize = size_t(fullSize * sizeof(int));
624 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
625 unsigned int uintBinarySize = (unsigned int) binarySize;
626 sizeEncoder.encode(&uintBinarySize, 1);
627 Base64Encoder<uint8_t> dataEncoder(ofstr, fullSize);
628 for (auto pS : _psys._pSystems) {
629 for (unsigned int p=0; p<pS->_particles.size(); p++) {
630 const uint8_t tmp = 1;
631 dataEncoder.encode(&tmp, 1);
632 }
633 }
634 ofstr.close();
635 }
636 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
637 fout << "</DataArray>" << std::endl;
638 fout << "</Cells>" << std::endl;
639 fout << "<Points>" << std::endl;
640 fout << "<DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"binary\" encoding=\"base64\">"
641 << std::endl;
642
643 fout.close();
644
645 std::ofstream ofstr(fullName.c_str(),
646 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
647 if (!ofstr) {
648 clout << "Error: could not open " << fullName << std::endl;
649 }
650
651 size_t fullSize = _psys.rankNumOfParticles() * 3; // how many numbers to write
652 size_t binarySize = size_t(fullSize * sizeof(float));
653 // writes first number, which have to be the size(byte) of the following data
654 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
655 unsigned int uintBinarySize = (unsigned int) binarySize;
656 sizeEncoder.encode(&uintBinarySize, 1);
657 // write numbers from functor
658 Base64Encoder<float> dataEncoder(ofstr, fullSize);
659 for (auto pS : _psys._pSystems) {
660 for (auto& p : pS->_particles) {
661 for (int iDim = 0; iDim < 3; ++iDim) {
662 const float tmp = float(p.getPos()[iDim]);
663 dataEncoder.encode(&tmp, 1);
664 }
665 }
666 }
667 ofstr.close();
668 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
669
670 fout << "</DataArray>" << std::endl;
671 fout << "</Points>" << std::endl;
672 fout << "</Piece>" << std::endl;
673 fout.close();
674}
675
676
677
678// specialization for magnetic particle
679
680template<typename T>
683
684template<typename T>
687
688
689template<typename T>
692 std::string const filename, const std::bitset<9>& properties, bool binary) :
693 SuperParticleSysVtuWriter<T, MagneticParticle3D>(psys, filename, 0, binary), _properties(properties) {}
694
695
696template<typename T>
698 const std::string& fullName)
699{
700 //std::cout<< "Special member accessed - binary" << std::endl;
701 std::ofstream fout(fullName.c_str(), std::ios::app);
702 if (!fout) {
703 this->clout << "Error: could not open " << fullName << std::endl;
704 }
705
706 if (_properties.test(pPropRadius)) {
707 fout
708 << "<DataArray type=\"Float32\" Name=\"Radius\" NumberOfComponents=\"1\" format=\"binary\" encoding=\"base64\">"
709 << std::endl;
710 fout.close();
711
712 std::ofstream ofstr(fullName.c_str(),
713 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
714 if (!ofstr) {
715 this->clout << "Error: could not open " << fullName << std::endl;
716 }
717
718 size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
719 size_t binarySize = size_t(fullSize * sizeof(float));
720 // writes first number, which have to be the size(byte) of the following data
721 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
722 unsigned int uintBinarySize = (unsigned int) binarySize;
723 sizeEncoder.encode(&uintBinarySize, 1);
724 // write numbers from functor
725 Base64Encoder<float> dataEncoder(ofstr, fullSize);
726 for (auto pS : this->_psys._pSystems) {
727 for (auto& p : pS->_particles) {
728 const float tmp = float(p.getRad());
729 dataEncoder.encode(&tmp, 1);
730 }
731 }
732 ofstr.close();
733
734 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
735 fout << "</DataArray>" << std::endl;
736 }
737
738 if (_properties.test(pPropMass)) {
739 fout
740 << "<DataArray type=\"Float32\" Name=\"Mass\" NumberOfComponents=\"1\" format=\"binary\" encoding=\"base64\">"
741 << std::endl;
742 fout.close();
743
744 std::ofstream ofstr(fullName.c_str(),
745 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
746 if (!ofstr) {
747 this->clout << "Error: could not open " << fullName << std::endl;
748 }
749
750 size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
751 size_t binarySize = size_t(fullSize * sizeof(float));
752 // writes first number, which have to be the size(byte) of the following data
753 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
754 unsigned int uintBinarySize = (unsigned int) binarySize;
755 sizeEncoder.encode(&uintBinarySize, 1);
756 // write numbers from functor
757 Base64Encoder<float> dataEncoder(ofstr, fullSize);
758 for (auto pS : this->_psys._pSystems) {
759 for (auto& p : pS->_particles) {
760 const float tmp = float(p.getMass());
761 dataEncoder.encode(&tmp, 1);
762 }
763 }
764 ofstr.close();
765
766 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
767 fout << "</DataArray>" << std::endl;
768 }
769 if (_properties.test(pPropCuboid)) {
770 fout
771 << "<DataArray type=\"Int32\" Name=\"Cuboid\" NumberOfComponents=\"1\" format=\"binary\" encoding=\"base64\">"
772 << std::endl;
773 fout.close();
774
775 std::ofstream ofstr(fullName.c_str(),
776 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
777 if (!ofstr) {
778 this->clout << "Error: could not open " << fullName << std::endl;
779 }
780
781 size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
782 size_t binarySize = size_t(fullSize * sizeof(int));
783 // writes first number, which have to be the size(byte) of the following data
784 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
785 unsigned int uintBinarySize = (unsigned int) binarySize;
786 sizeEncoder.encode(&uintBinarySize, 1);
787 // write numbers from functor
788 Base64Encoder<int> dataEncoder(ofstr, fullSize);
789 for (auto pS : this->_psys._pSystems) {
790 for (auto& p : pS->_particles) {
791 const int tmp = int(p.getCuboid());
792 dataEncoder.encode(&tmp, 1);
793 }
794 }
795 ofstr.close();
796
797 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
798 fout << "</DataArray>" << std::endl;
799 }
800 if (_properties.test(pPropActive)) {
801 fout
802 << "<DataArray type=\"Int32\" Name=\"Active\" NumberOfComponents=\"1\" format=\"binary\" encoding=\"base64\">"
803 << std::endl;
804 fout.close();
805
806 std::ofstream ofstr(fullName.c_str(),
807 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
808 if (!ofstr) {
809 this->clout << "Error: could not open " << fullName << std::endl;
810 }
811
812 size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
813 size_t binarySize = size_t(fullSize * sizeof(int));
814 // writes first number, which have to be the size(byte) of the following data
815 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
816 unsigned int uintBinarySize = (unsigned int) binarySize;
817 sizeEncoder.encode(&uintBinarySize, 1);
818 // write numbers from functor
819 Base64Encoder<int> dataEncoder(ofstr, fullSize);
820 for (auto pS : this->_psys._pSystems) {
821 for (auto& p : pS->_particles) {
822 int tmp = 0;
823 if (p.getActive()) {
824 tmp = 1;
825 }
826 dataEncoder.encode(&tmp, 1);
827 }
828 }
829 ofstr.close();
830
831 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
832 fout << "</DataArray>" << std::endl;
833 }
834
835 if (_properties.test(pPropVelocity)) {
836 fout
837 << "<DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"binary\" encoding=\"base64\">"
838 << std::endl;
839 fout.close();
840
841 std::ofstream ofstr(fullName.c_str(),
842 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
843 if (!ofstr) {
844 this->clout << "Error: could not open " << fullName << std::endl;
845 }
846
847 size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
848 size_t binarySize = size_t(fullSize * sizeof(float));
849 // writes first number, which have to be the size(byte) of the following data
850 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
851 unsigned int uintBinarySize = (unsigned int) binarySize;
852 sizeEncoder.encode(&uintBinarySize, 1);
853 // write numbers from functor
854 Base64Encoder<float> dataEncoder(ofstr, fullSize);
855 for (auto pS : this->_psys._pSystems) {
856 for (auto& p : pS->_particles) {
857 for (int iDim = 0; iDim < 3; ++iDim) {
858 const float tmp = float(p.getVel()[iDim]);
859 dataEncoder.encode(&tmp, 1);
860 }
861 }
862 }
863 ofstr.close();
864 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
865 fout << "</DataArray>" << std::endl;
866 }
867
868 if (_properties.test(pPropForce)) {
869 fout
870 << "<DataArray type=\"Float32\" Name=\"Force\" NumberOfComponents=\"3\" format=\"binary\" encoding=\"base64\">"
871 << std::endl;
872 fout.close();
873
874 std::ofstream ofstr(fullName.c_str(),
875 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
876 if (!ofstr) {
877 this->clout << "Error: could not open " << fullName << std::endl;
878 }
879
880 size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
881 size_t binarySize = size_t(fullSize * sizeof(float));
882 // writes first number, which have to be the size(byte) of the following data
883 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
884 unsigned int uintBinarySize = (unsigned int) binarySize;
885 sizeEncoder.encode(&uintBinarySize, 1);
886 // write numbers from functor
887 Base64Encoder<float> dataEncoder(ofstr, fullSize);
888 for (auto pS : this->_psys._pSystems) {
889 for (auto& p : pS->_particles) {
890 for (int iDim = 0; iDim < 3; ++iDim) {
891 const float tmp = float(p.getForce()[iDim]);
892 dataEncoder.encode(&tmp, 1);
893 }
894 }
895 }
896 ofstr.close();
897 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
898 fout << "</DataArray>" << std::endl;
899 }
900 if (_properties.test(pPropMoment)) {
901 fout
902 << "<DataArray type=\"Float32\" Name=\"Moment\" NumberOfComponents=\"3\" format=\"binary\" encoding=\"base64\">"
903 << std::endl;
904 fout.close();
905
906 std::ofstream ofstr(fullName.c_str(),
907 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
908 if (!ofstr) {
909 this->clout << "Error: could not open " << fullName << std::endl;
910 }
911
912 size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
913 size_t binarySize = size_t(fullSize * sizeof(float));
914 // writes first number, which have to be the size(byte) of the following data
915 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
916 unsigned int uintBinarySize = (unsigned int) binarySize;
917 sizeEncoder.encode(&uintBinarySize, 1);
918 // write numbers from functor
919 Base64Encoder<float> dataEncoder(ofstr, fullSize);
920 for (auto pS : this->_psys._pSystems) {
921 for (auto& p : pS->_particles) {
922 for (int iDim = 0; iDim < 3; ++iDim) {
923 const float tmp = float(p.getMoment()[iDim]);
924 dataEncoder.encode(&tmp, 1);
925 }
926 }
927 }
928 ofstr.close();
929 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
930 fout << "</DataArray>" << std::endl;
931 }
932 if (_properties.test(pPropAVel)) {
933 fout
934 << "<DataArray type=\"Float32\" Name=\"AngularVelocity\" NumberOfComponents=\"3\" format=\"binary\" encoding=\"base64\">"
935 << std::endl;
936 fout.close();
937
938 std::ofstream ofstr(fullName.c_str(),
939 std::ios::out | std::ios::app | std::ios::binary);
940 if (!ofstr) {
941 this->clout << "Error: could not open " << fullName << std::endl;
942 }
943
944 size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
945 size_t binarySize = size_t(fullSize * sizeof(float));
946 // writes first number, which have to be the size(byte) of the following data
947 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
948 unsigned int uintBinarySize = (unsigned int) binarySize;
949 sizeEncoder.encode(&uintBinarySize, 1);
950 // write numbers from functor
951 Base64Encoder<float> dataEncoder(ofstr,
952 fullSize);
953 for (auto pS : this->_psys._pSystems) {
954 for (auto p : pS->_particles) {
955 for (int iDim = 0; iDim < 3; ++iDim) {
956 const float tmp = float(p.getAVel()[iDim]);
957 dataEncoder.encode(&tmp, 1);
958 }
959 }
960 }
961 ofstr.close();
962 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
963 fout << "</DataArray>" << std::endl;
964 }
965 if (_properties.test(pPropTorque)) {
966 fout
967 << "<DataArray type=\"Float32\" Name=\"Torque\" NumberOfComponents=\"3\" format=\"binary\" encoding=\"base64\">"
968 << std::endl;
969 fout.close();
970
971 std::ofstream ofstr(fullName.c_str(),
972 std::ios::out | std::ios::app | std::ios::binary);
973 if (!ofstr) {
974 this->clout << "Error: could not open " << fullName << std::endl;
975 }
976
977 size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
978 size_t binarySize = size_t(fullSize * sizeof(float));
979 // writes first number, which have to be the size(byte) of the following data
980 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
981 unsigned int uintBinarySize = (unsigned int) binarySize;
982 sizeEncoder.encode(&uintBinarySize, 1);
983 // write numbers from functor
984 Base64Encoder<float> dataEncoder(ofstr,
985 fullSize);
986 for (auto pS : this->_psys._pSystems) {
987 for (auto p : pS->_particles) {
988 for (int iDim = 0; iDim < 3; ++iDim) {
989 const float tmp = float(p.getTorque()[iDim]);
990 dataEncoder.encode(&tmp, 1);
991 }
992 }
993 }
994 ofstr.close();
995 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
996 fout << "</DataArray>" << std::endl;
997 }
998 fout << "</PointData>" << std::endl;
999
1000 fout << "<CellData /> " << std::endl;
1001 fout << "<Cells>" << std::endl;
1002 fout << "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"binary\" encoding=\"base64\">" << std::endl;
1003 fout.close();
1004 {
1005 std::ofstream ofstr(fullName.c_str(),
1006 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
1007 if (!ofstr) {
1008 this->clout << "Error: could not open " << fullName << std::endl;
1009 }
1010
1011 size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
1012 size_t binarySize = size_t(fullSize * sizeof(int));
1013 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
1014 unsigned int uintBinarySize = (unsigned int) binarySize;
1015 sizeEncoder.encode(&uintBinarySize, 1);
1016 Base64Encoder<int32_t> dataEncoder(ofstr,
1017 fullSize);
1018 int i = 0;
1019 for (auto pS : this->_psys._pSystems) {
1020 for (unsigned int p=0; p<pS->_particles.size(); p++) {
1021 const int32_t tmp = i++;
1022 dataEncoder.encode(&tmp, 1);
1023 }
1024 }
1025 ofstr.close();
1026 }
1027 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
1028 fout << "</DataArray>" << std::endl;
1029
1030 fout << "<DataArray type=\"Int32\" Name=\"offsets\" format=\"binary\" encoding=\"base64\">"
1031 << std::endl;
1032 fout.close();
1033 {
1034 std::ofstream ofstr(fullName.c_str(),
1035 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
1036 if (!ofstr) {
1037 this->clout << "Error: could not open " << fullName << std::endl;
1038 }
1039
1040 size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
1041 size_t binarySize = size_t(fullSize * sizeof(int));
1042 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
1043 unsigned int uintBinarySize = (unsigned int) binarySize;
1044 sizeEncoder.encode(&uintBinarySize, 1);
1045 Base64Encoder<int32_t> dataEncoder(ofstr, fullSize);
1046 int i = 1;
1047 for (auto pS : this->_psys._pSystems) {
1048 for (unsigned int p=0; p<pS->_particles.size(); p++) {
1049 const int32_t tmp = i++;
1050 dataEncoder.encode(&tmp, 1);
1051 }
1052 }
1053 ofstr.close();
1054 }
1055 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
1056 fout << "</DataArray>" << std::endl;
1057
1058
1059 fout << "<DataArray type=\"UInt8\" Name=\"types\" format=\"binary\" encoding=\"base64\">"
1060 << std::endl;
1061 fout.close();
1062 {
1063 std::ofstream ofstr(fullName.c_str(),
1064 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
1065 if (!ofstr) {
1066 this->clout << "Error: could not open " << fullName << std::endl;
1067 }
1068
1069 size_t fullSize = this-> _psys.rankNumOfParticles(); // how many numbers to write
1070 size_t binarySize = size_t(fullSize * sizeof(int));
1071 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
1072 unsigned int uintBinarySize = (unsigned int) binarySize;
1073 sizeEncoder.encode(&uintBinarySize, 1);
1074 Base64Encoder<uint8_t> dataEncoder(ofstr, fullSize);
1075 for (auto pS : this->_psys._pSystems) {
1076 for (unsigned int p=0; p<pS->_particles.size(); p++) {
1077 const uint8_t tmp = 1;
1078 dataEncoder.encode(&tmp, 1);
1079 }
1080 }
1081 ofstr.close();
1082 }
1083 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
1084 fout << "</DataArray>" << std::endl;
1085 fout << "</Cells>" << std::endl;
1086 fout << "<Points>" << std::endl;
1087 fout << "<DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"binary\" encoding=\"base64\">"
1088 << std::endl;
1089
1090 fout.close();
1091
1092 std::ofstream ofstr(fullName.c_str(),
1093 std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
1094 if (!ofstr) {
1095 this->clout << "Error: could not open " << fullName << std::endl;
1096 }
1097
1098 size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
1099 size_t binarySize = size_t(fullSize * sizeof(float));
1100 // writes first number, which have to be the size(byte) of the following data
1101 Base64Encoder<unsigned int> sizeEncoder(ofstr, 1);
1102 unsigned int uintBinarySize = (unsigned int) binarySize;
1103 sizeEncoder.encode(&uintBinarySize, 1);
1104 // write numbers from functor
1105 Base64Encoder<float> dataEncoder(ofstr, fullSize);
1106 for (auto pS : this->_psys._pSystems) {
1107 for (auto& p : pS->_particles) {
1108 for (int iDim = 0; iDim < 3; ++iDim) {
1109 const float tmp = float(p.getPos()[iDim]);
1110 dataEncoder.encode(&tmp, 1);
1111 }
1112 }
1113 }
1114 ofstr.close();
1115 fout.open(fullName.c_str(), std::ios::out | std::ios::app);
1116
1117 fout << "</DataArray>" << std::endl;
1118 fout << "</Points>" << std::endl;
1119 fout << "</Piece>" << std::endl;
1120 fout.close();
1121}
1122
1123template<typename T>
1124void SuperParticleSysVtuWriterMag<T>::dataArray(
1125 const std::string& fullName)
1126{
1127 std::cout<< "Special member accessed" << std::endl;
1128 std::ofstream fout(fullName.c_str(), std::ios::app);
1129 if (!fout) {
1130 this->clout << "Error: could not open " << fullName << std::endl;
1131 }
1132
1133 if (_properties.test(pPropRadius)) {
1134 fout
1135 << "<DataArray type=\"Float32\" Name=\"Radius\" NumberOfComponents=\"1\" format=\"ascii\">"
1136 << std::endl;
1137 for (auto pS : this->_psys._pSystems) {
1138 for (auto& p : pS->_particles) {
1139 fout << p.getRad() << " ";
1140 }
1141 }
1142 fout << "</DataArray>" << std::endl;
1143 }
1144 if (_properties.test(pPropMass)) {
1145 fout
1146 << "<DataArray type=\"Float32\" Name=\"Mass\" NumberOfComponents=\"1\" format=\"ascii\">"
1147 << std::endl;
1148 for (auto pS : this->_psys._pSystems) {
1149 for (auto& p : pS->_particles) {
1150 fout << p.getMass() << " ";
1151 }
1152 }
1153 fout << "</DataArray>" << std::endl;
1154 }
1155 if (_properties.test(pPropCuboid)) {
1156 fout
1157 << "<DataArray type=\"Int16\" Name=\"Cuboid\" NumberOfComponents=\"1\" format=\"ascii\">"
1158 << std::endl;
1159 for (auto pS : this->_psys._pSystems) {
1160 for (auto& p : pS->_particles) {
1161 fout << p.getCuboid() << " ";
1162 }
1163 }
1164 fout << "</DataArray>" << std::endl;
1165 }
1166 if (_properties.test(pPropActive)) {
1167 fout
1168 << "<DataArray type=\"Int16\" Name=\"Active\" NumberOfComponents=\"1\" format=\"ascii\">"
1169 << std::endl;
1170 for (auto pS : this->_psys._pSystems) {
1171 for (auto& p : pS->_particles) {
1172 if (p.getActive()) {
1173 fout << "1 ";
1174 }
1175 else {
1176 fout << "0 ";
1177 }
1178 }
1179 }
1180 fout << "</DataArray>" << std::endl;
1181 }
1182 if (_properties.test(pPropVelocity)) {
1183 fout
1184 << "<DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"ascii\">"
1185 << std::endl;
1186 for (auto pS : this->_psys._pSystems) {
1187 for (auto& p : pS->_particles) {
1188 fout << p.getVel()[0] << " " << p.getVel()[1] << " " << p.getVel()[2]
1189 << " ";
1190 }
1191 }
1192 fout << "</DataArray>" << std::endl;
1193 }
1194 if (_properties.test(pPropForce)) {
1195 fout
1196 << "<DataArray type=\"Float32\" Name=\"Force\" NumberOfComponents=\"3\" format=\"ascii\">"
1197 << std::endl;
1198 for (auto pS : this->_psys._pSystems) {
1199 for (auto& p : pS->_particles) {
1200 fout << p.getForce()[0] << " " << p.getForce()[1] << " " << p.getForce()[2]
1201 << " ";
1202 }
1203 }
1204 fout << "</DataArray>" << std::endl;
1205 }
1206 if (_properties.test(pPropMoment)) {
1207 fout
1208 << "<DataArray type=\"Float32\" Name=\"Moment\" NumberOfComponents=\"3\" format=\"ascii\">"
1209 << std::endl;
1210 for (auto pS : this->_psys._pSystems) {
1211 for (auto& p : pS->_particles) {
1212 fout << p.getMoment()[0] << " " << p.getMoment()[1] << " " << p.getMoment()[2]
1213 << " ";
1214 }
1215 }
1216 fout << "</DataArray>" << std::endl;
1217 }
1218 if (_properties.test(pPropTorque)) {
1219 fout
1220 << "<DataArray type=\"Float32\" Name=\"Torque\" NumberOfComponents=\"3\" format=\"ascii\">"
1221 << std::endl;
1222 for (auto pS : this->_psys._pSystems) {
1223 for (auto p : pS->_particles) {
1224 fout << p.getTorque()[0] << " " << p.getTorque()[1] << " " << p.getTorque()[2]
1225 << " ";
1226 }
1227 }
1228 fout << "</DataArray>" << std::endl;
1229 }
1230 fout << "</PointData>" << std::endl;
1231
1232 fout << "<CellData /> " << std::endl;
1233 fout << "<Cells>" << std::endl;
1234 fout << "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">"
1235 << std::endl;
1236 int32_t i = 0;
1237 for (auto pS : this->_psys._pSystems) {
1238 for (unsigned int p=0; p<pS->_particles.size(); p++) {
1239 fout << i++ << " ";
1240 }
1241 }
1242 fout << "</DataArray>" << std::endl;
1243 fout << "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">"
1244 << std::endl;
1245 i = 1;
1246 for (auto pS : this->_psys._pSystems) {
1247 for (unsigned int p=0; p<pS->_particles.size(); p++) {
1248 fout << i++ << " ";
1249 }
1250 }
1251 fout << "</DataArray>" << std::endl;
1252 fout << "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">"
1253 << std::endl;
1254 for (auto pS : this->_psys._pSystems) {
1255 for (unsigned int p=0; p<pS->_particles.size(); p++) {
1256 fout << 1 << " ";
1257 }
1258 }
1259 fout << "</DataArray>" << std::endl;
1260 fout << "</Cells>" << std::endl;
1261 fout << "<Points>" << std::endl;
1262 fout
1263 << "<DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\">"
1264 << std::endl;
1265
1266 for (auto pS : this->_psys._pSystems) {
1267 for (auto& p : pS->_particles) {
1268 fout << p.getPos()[0] << " " << p.getPos()[1] << " " << p.getPos()[2] << " ";
1269 }
1270 }
1271
1272 fout << "</DataArray>" << std::endl;
1273 fout << "</Points>" << std::endl;
1274 fout << "</Piece>" << std::endl;
1275 fout.close();
1276}
1277
1278template<typename T>
1280{
1281 //std::cout << "Write derived" << std::endl;
1282 int rank = 0;
1283 int size = 1;
1284#ifdef PARALLEL_MODE_MPI
1285 rank = singleton::mpi().getRank();
1286 size = singleton::mpi().getSize();
1287#endif
1288
1289 if (rank == 0) { // master only
1290 if (!this->_haveMaster) {
1291 this->createMasterFile();
1292 }
1293
1294 std::string fullNamePVDmaster = singleton::directories().getVtkOutDir()
1295 + createFileName(this->_name) + "_master.pvd";
1296 std::string fullNamePVD = singleton::directories().getVtkOutDir() + "data/"
1297 + createFileName(this->_name, iT) + ".pvd";
1298
1299 this->preamblePVD(fullNamePVD); // timestep
1300 for (int iR = 0; iR < size; iR++) { // cuboid
1301 std::string namePiece = "data/" + createFileName(this->_name, iT, iR) + ".vtu";
1302 // puts name of .vti piece to a .pvd file [fullNamePVD]
1303 this->dataPVD(iT, iR, fullNamePVD, namePiece);
1304 // adds a namePiece to master.pvd file.
1305 // To do so we overwrite closePVD() and add new entry.
1306 this->dataPVDmaster(iT, iR, fullNamePVDmaster, namePiece);
1307 } // cuboid
1308 this->closePVD(fullNamePVD); // timestep
1309 } // master only
1310
1311 std::string fullNameVTU = singleton::directories().getVtkOutDir()
1312 + "data/" + createFileName(this->_name, iT, rank) + ".vtu";
1313 this->preambleVTU(fullNameVTU);
1314 if (this->_binary) {
1315 this->dataArrayBinary(fullNameVTU);
1316 }
1317 else {
1318 this->dataArray(fullNameVTU);
1319 }
1320 this->closeVTU(fullNameVTU);
1321}
1322
1323template<typename T>
1325{
1326 _properties.set(pref);
1327}
1328
1329
1330
1331} // namespace OLB
1332
1333#endif /* SUPERPARTICLESYSVTUOUT_HH */
void encode(const T *data, size_t length)
Definition base64.hh:59
SuperParticleSysVtuWriterMag(SuperParticleSystem3D< T, MagneticParticle3D > &, std::string const, const std::bitset< 9 > &properties, bool binary=true)
void preamblePVD(const std::string &fullNamePVD)
performes <VTKFile ...> and <Collection>
SuperParticleSysVtuWriter(SuperParticleSystem3D< T, PARTICLETYPE > &, std::string const, unsigned short properties, bool binary=true)
void dataPVDmaster(int iT, int iR, const std::string &fullNamePVDMaster, const std::string &namePiece)
performes <DataSet timestep= ... file=namePiece >
void closeVTU(const std::string &fullNamePiece)
performes </ImageData> and </VTKFile>
void preambleVTU(const std::string &fullName)
performes <VTKFile ...>, <ImageData ...> and <PieceExtent ...>
void dataArrayBinary(const std::string &fullName)
writes functors stored at pointerVec
void dataPVD(int iT, int iR, const std::string &fullNamePVD, const std::string &namePiece)
performes <DataSet timestep= ... file=namePiece >
void closePVD(const std::string &fullNamePVD)
performes </Collection> and </VTKFile>
void dataArray(const std::string &fullName)
writes functors stored at pointerVec
The class superParticleSystem is the basis for particulate flows within OpenLB.
std::string getVtkOutDir() const
Definition singleton.h:97
int getSize() const
Returns the number of processes.
int getRank() const
Returns the process ID.
MpiManager & mpi()
Directories & directories()
Definition singleton.h:150
Top level namespace for all of OpenLB.
std::string createFileName(std::string name)
for .pvd masterFile
Definition fileName.hh:34