From 94d3e79a8617f88dc0219cfdeedfa3147833719d Mon Sep 17 00:00:00 2001
From: Adrian Kummerlaender
Date: Mon, 24 Jun 2019 14:43:36 +0200
Subject: Initialize at openlb-1-3
---
src/particles/superParticleSysVTUout.hh | 1328 +++++++++++++++++++++++++++++++
1 file changed, 1328 insertions(+)
create mode 100644 src/particles/superParticleSysVTUout.hh
(limited to 'src/particles/superParticleSysVTUout.hh')
diff --git a/src/particles/superParticleSysVTUout.hh b/src/particles/superParticleSysVTUout.hh
new file mode 100644
index 0000000..a0b9481
--- /dev/null
+++ b/src/particles/superParticleSysVTUout.hh
@@ -0,0 +1,1328 @@
+/* This file is part of the OpenLB library
+ *
+ * Copyright (C) 2016 Thomas Henn
+ * E-mail contact: info@openlb.net
+ * The most recent release of OpenLB can be downloaded at
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SUPERPARTICLESYSVTUOUT_HH
+#define SUPERPARTICLESYSVTUOUT_HH
+
+#include "superParticleSysVTUout.h"
+
+namespace olb {
+
+template class PARTICLETYPE>
+int SuperParticleSysVtuWriter::numofpsys()
+{
+ return _psys._pSystems.size();
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::set(unsigned short pref)
+{
+ _properties |= pref;
+}
+
+template class PARTICLETYPE>
+SuperParticleSysVtuWriter::SuperParticleSysVtuWriter(const SuperParticleSysVtuWriter& rhs)
+ : _psys(rhs._psys), _name(rhs._name), _properties(rhs._properties), _binary(rhs._binary), _haveMaster(rhs._haveMaster), clout(std::cout, "SuperParticleSysVtuWriter")
+{
+}
+
+template class PARTICLETYPE>
+SuperParticleSysVtuWriter::SuperParticleSysVtuWriter(const SuperParticleSysVtuWriter&& rhs)
+ : _psys(rhs._psys), _name(rhs._name), _properties(rhs._properties), _binary(rhs._binary), _haveMaster(rhs._haveMaster), clout(std::cout, "SuperParticleSysVtuWriter")
+{
+}
+
+
+template class PARTICLETYPE>
+SuperParticleSysVtuWriter::SuperParticleSysVtuWriter( SuperParticleSystem3D& psys,
+ std::string const filename, unsigned short properties, bool binary)
+ : _psys(psys), _name(filename), _properties(properties), _binary(binary), _haveMaster(false), clout(std::cout, "SuperParticleSysVtuWriter")
+{
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::write(int iT)
+{
+ //std::cout << "Write base" << std::endl;
+ int rank = 0;
+ int size = 1;
+#ifdef PARALLEL_MODE_MPI
+ rank = singleton::mpi().getRank();
+ size = singleton::mpi().getSize();
+#endif
+
+ if (rank == 0) { // master only
+ if (!_haveMaster) {
+ createMasterFile();
+ }
+
+ std::string fullNamePVDmaster = singleton::directories().getVtkOutDir()
+ + createFileName(_name) + "_master.pvd";
+ std::string fullNamePVD = singleton::directories().getVtkOutDir() + "data/"
+ + createFileName(_name, iT) + ".pvd";
+
+ preamblePVD(fullNamePVD); // timestep
+ for (int iR = 0; iR < size; iR++) { // cuboid
+ std::string namePiece = "data/" + createFileName(_name, iT, iR) + ".vtu";
+ // puts name of .vti piece to a .pvd file [fullNamePVD]
+ dataPVD(iT, iR, fullNamePVD, namePiece);
+ // adds a namePiece to master.pvd file.
+ // To do so we overwrite closePVD() and add new entry.
+ dataPVDmaster(iT, iR, fullNamePVDmaster, namePiece);
+ } // cuboid
+ closePVD(fullNamePVD); // timestep
+ } // master only
+
+ std::string fullNameVTU = singleton::directories().getVtkOutDir()
+ + "data/" + createFileName(_name, iT, rank) + ".vtu";
+ preambleVTU(fullNameVTU);
+ if (_binary) {
+ this->dataArrayBinary(fullNameVTU);
+ } else {
+ this->dataArray(fullNameVTU);
+ }
+ closeVTU(fullNameVTU);
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::createMasterFile()
+{
+ int rank = 0;
+#ifdef PARALLEL_MODE_MPI
+ rank = singleton::mpi().getRank();
+#endif
+ if (rank == 0) {
+ std::string fullNamePVDmaster = singleton::directories().getVtkOutDir()
+ + createFileName(_name) + "_master.pvd";
+ preamblePVD(fullNamePVDmaster);
+ closePVD(fullNamePVDmaster);
+ _haveMaster = true;
+ }
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::preambleVTU(
+ const std::string& fullName)
+{
+ std::ofstream fout(fullName.c_str(), std::ios::trunc);
+ if (!fout) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+ fout << "" << std::endl << std::flush;
+ fout
+ << ""
+ << std::endl;
+ fout << "" << std::endl;
+ fout << ""
+ << std::endl;
+ fout << "" << std::endl;
+ fout.close();
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::closeVTU(
+ const std::string& fullNamePiece)
+{
+ std::ofstream fout(fullNamePiece.c_str(), std::ios::app);
+ if (!fout) {
+ clout << "Error: could not open " << fullNamePiece << std::endl;
+ }
+ fout << "\n";
+ fout << "\n";
+ fout.close();
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::preamblePVD(
+ const std::string& fullNamePVD)
+{
+ std::ofstream fout(fullNamePVD.c_str(), std::ios::trunc);
+ if (!fout) {
+ clout << "Error: could not open " << fullNamePVD << std::endl;
+ }
+
+ fout << "\n";
+ fout << "\n" << "\n";
+ fout.close();
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::closePVD(
+ const std::string& fullNamePVD)
+{
+ std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
+ if (!fout) {
+ clout << "Error: could not open " << fullNamePVD << std::endl;
+ }
+ fout << "\n";
+ fout << "\n";
+ fout.close();
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::dataPVD(int iT, int iC,
+ const std::string& fullNamePVD, const std::string& namePiece)
+{
+ std::ofstream fout(fullNamePVD.c_str(), std::ios::app);
+ if (!fout) {
+ clout << "Error: could not open " << fullNamePVD << std::endl;
+ }
+
+ fout << "\n";
+ fout.close();
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::dataPVDmaster(int iT, int iC,
+ const std::string& fullNamePVDMaster, const std::string& namePiece)
+{
+ std::ofstream fout(fullNamePVDMaster.c_str(),
+ std::ios::in | std::ios::out | std::ios::ate);
+ if (fout) {
+ fout.seekp(-25, std::ios::end); // jump -25 form the end of file to overwrite closePVD
+
+ fout << "\n";
+ fout.close();
+ closePVD(fullNamePVDMaster);
+ } else {
+ clout << "Error: could not open " << fullNamePVDMaster << std::endl;
+ }
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::dataArray(
+ const std::string& fullName)
+{
+ //std::cout<< "Base member accessed" << std::endl;
+ std::ofstream fout(fullName.c_str(), std::ios::app);
+ if (!fout) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ if (_properties & particleProperties::radius) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getRad() << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties & particleProperties::mass) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getMass() << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties & particleProperties::cuboid) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getCuboid() << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties & particleProperties::active) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ if (p.getActive()) {
+ fout << "1 ";
+ } else {
+ fout << "0 ";
+ }
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties & particleProperties::velocity) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getVel()[0] << " " << p.getVel()[1] << " " << p.getVel()[2]
+ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties & particleProperties::force) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getForce()[0] << " " << p.getForce()[1] << " " << p.getForce()[2]
+ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ fout << "" << std::endl;
+
+ fout << " " << std::endl;
+ fout << "" << std::endl;
+ fout << ""
+ << std::endl;
+ int32_t i = 0;
+ for (auto pS : _psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ fout << i++ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ fout << ""
+ << std::endl;
+ i = 1;
+ for (auto pS : _psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ fout << i++ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ fout << ""
+ << std::endl;
+ for (auto pS : _psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ fout << 1 << " ";
+ }
+ }
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout
+ << ""
+ << std::endl;
+
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getPos()[0] << " " << p.getPos()[1] << " " << p.getPos()[2] << " ";
+ }
+ }
+
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout.close();
+}
+
+template class PARTICLETYPE>
+void SuperParticleSysVtuWriter::dataArrayBinary(
+ const std::string& fullName)
+{
+ //std::cout<< "Base member accessed - binary" << std::endl;
+ std::ofstream fout(fullName.c_str(), std::ios::app);
+ if (!fout) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ if (_properties & particleProperties::radius) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ const float tmp = float(p.getRad());
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+
+ if (_properties & particleProperties::mass) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ const float tmp = float(p.getMass());
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ if (_properties & particleProperties::cuboid) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr,
+ fullSize);
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ const int tmp = int(p.getCuboid());
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ if (_properties & particleProperties::active) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ int tmp = 0;
+ if (p.getActive()) {
+ tmp = 1;
+ }
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+
+ if (_properties & particleProperties::velocity) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles() * 3; // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ for (int iDim = 0; iDim < 3; ++iDim) {
+ const float tmp = float(p.getVel()[iDim]);
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ }
+ ofstr.close();
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ if (_properties & particleProperties::force) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles() * 3; // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ for (int iDim = 0; iDim < 3; ++iDim) {
+ const float tmp = float(p.getForce()[iDim]);
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ }
+ ofstr.close();
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ fout << "" << std::endl;
+
+ fout << " " << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout.close();
+ {
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ int i = 0;
+ for (auto pS : _psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ const int32_t tmp = i++;
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+ }
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+
+ fout << ""
+ << std::endl;
+ fout.close();
+ {
+ std::ofstream ofstr(fullName.c_str(), std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ int i = 1;
+ for (auto pS : _psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ const int32_t tmp = i++;
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+ }
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+
+
+ fout << ""
+ << std::endl;
+ fout.close();
+ {
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : _psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ const uint8_t tmp = 1;
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+ }
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << ""
+ << std::endl;
+
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = _psys.rankNumOfParticles() * 3; // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : _psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ for (int iDim = 0; iDim < 3; ++iDim) {
+ const float tmp = float(p.getPos()[iDim]);
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ }
+ ofstr.close();
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout.close();
+}
+
+
+
+// specialization for magnetic particle
+
+template
+SuperParticleSysVtuWriterMag::SuperParticleSysVtuWriterMag(const SuperParticleSysVtuWriterMag& rhs) :
+ SuperParticleSysVtuWriter(rhs), _properties(rhs._properties) {}
+
+template
+SuperParticleSysVtuWriterMag::SuperParticleSysVtuWriterMag(const SuperParticleSysVtuWriterMag&& rhs) :
+ SuperParticleSysVtuWriter(rhs), _properties(rhs._properties) {}
+
+
+template
+SuperParticleSysVtuWriterMag::SuperParticleSysVtuWriterMag(
+ SuperParticleSystem3D& psys,
+ std::string const filename, const std::bitset<9>& properties, bool binary) :
+ SuperParticleSysVtuWriter(psys, filename, 0, binary), _properties(properties) {}
+
+
+template
+void SuperParticleSysVtuWriterMag::dataArrayBinary(
+ const std::string& fullName)
+{
+ //std::cout<< "Special member accessed - binary" << std::endl;
+ std::ofstream fout(fullName.c_str(), std::ios::app);
+ if (!fout) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ if (_properties.test(pPropRadius)) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ const float tmp = float(p.getRad());
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+
+ if (_properties.test(pPropMass)) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ const float tmp = float(p.getMass());
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropCuboid)) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ const int tmp = int(p.getCuboid());
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropActive)) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ int tmp = 0;
+ if (p.getActive()) {
+ tmp = 1;
+ }
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+
+ if (_properties.test(pPropVelocity)) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ for (int iDim = 0; iDim < 3; ++iDim) {
+ const float tmp = float(p.getVel()[iDim]);
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ }
+ ofstr.close();
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+
+ if (_properties.test(pPropForce)) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ for (int iDim = 0; iDim < 3; ++iDim) {
+ const float tmp = float(p.getForce()[iDim]);
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ }
+ ofstr.close();
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropMoment)) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ for (int iDim = 0; iDim < 3; ++iDim) {
+ const float tmp = float(p.getMoment()[iDim]);
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ }
+ ofstr.close();
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropAVel)) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary);
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr,
+ fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto p : pS->_particles) {
+ for (int iDim = 0; iDim < 3; ++iDim) {
+ const float tmp = float(p.getAVel()[iDim]);
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ }
+ ofstr.close();
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropTorque)) {
+ fout
+ << ""
+ << std::endl;
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary);
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr,
+ fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto p : pS->_particles) {
+ for (int iDim = 0; iDim < 3; ++iDim) {
+ const float tmp = float(p.getTorque()[iDim]);
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ }
+ ofstr.close();
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ }
+ fout << "" << std::endl;
+
+ fout << " " << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout.close();
+ {
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ Base64Encoder dataEncoder(ofstr,
+ fullSize);
+ int i = 0;
+ for (auto pS : this->_psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ const int32_t tmp = i++;
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+ }
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+
+ fout << ""
+ << std::endl;
+ fout.close();
+ {
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ int i = 1;
+ for (auto pS : this->_psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ const int32_t tmp = i++;
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+ }
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+
+
+ fout << ""
+ << std::endl;
+ fout.close();
+ {
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this-> _psys.rankNumOfParticles(); // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(int));
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ const uint8_t tmp = 1;
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ ofstr.close();
+ }
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << ""
+ << std::endl;
+
+ fout.close();
+
+ std::ofstream ofstr(fullName.c_str(),
+ std::ios::out | std::ios::app | std::ios::binary); // only used for binary output // passed to Base64Encoder
+ if (!ofstr) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ size_t fullSize = this->_psys.rankNumOfParticles() * 3; // how many numbers to write
+ size_t binarySize = size_t(fullSize * sizeof(float));
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int) binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder dataEncoder(ofstr, fullSize);
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ for (int iDim = 0; iDim < 3; ++iDim) {
+ const float tmp = float(p.getPos()[iDim]);
+ dataEncoder.encode(&tmp, 1);
+ }
+ }
+ }
+ ofstr.close();
+ fout.open(fullName.c_str(), std::ios::out | std::ios::app);
+
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout.close();
+}
+
+template
+void SuperParticleSysVtuWriterMag::dataArray(
+ const std::string& fullName)
+{
+ std::cout<< "Special member accessed" << std::endl;
+ std::ofstream fout(fullName.c_str(), std::ios::app);
+ if (!fout) {
+ this->clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ if (_properties.test(pPropRadius)) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getRad() << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropMass)) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getMass() << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropCuboid)) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getCuboid() << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropActive)) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ if (p.getActive()) {
+ fout << "1 ";
+ } else {
+ fout << "0 ";
+ }
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropVelocity)) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getVel()[0] << " " << p.getVel()[1] << " " << p.getVel()[2]
+ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropForce)) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getForce()[0] << " " << p.getForce()[1] << " " << p.getForce()[2]
+ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropMoment)) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getMoment()[0] << " " << p.getMoment()[1] << " " << p.getMoment()[2]
+ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ if (_properties.test(pPropTorque)) {
+ fout
+ << ""
+ << std::endl;
+ for (auto pS : this->_psys._pSystems) {
+ for (auto p : pS->_particles) {
+ fout << p.getTorque()[0] << " " << p.getTorque()[1] << " " << p.getTorque()[2]
+ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ }
+ fout << "" << std::endl;
+
+ fout << " " << std::endl;
+ fout << "" << std::endl;
+ fout << ""
+ << std::endl;
+ int32_t i = 0;
+ for (auto pS : this->_psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ fout << i++ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ fout << ""
+ << std::endl;
+ i = 1;
+ for (auto pS : this->_psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ fout << i++ << " ";
+ }
+ }
+ fout << "" << std::endl;
+ fout << ""
+ << std::endl;
+ for (auto pS : this->_psys._pSystems) {
+ for (unsigned int p=0; p_particles.size(); p++) {
+ fout << 1 << " ";
+ }
+ }
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout
+ << ""
+ << std::endl;
+
+ for (auto pS : this->_psys._pSystems) {
+ for (auto& p : pS->_particles) {
+ fout << p.getPos()[0] << " " << p.getPos()[1] << " " << p.getPos()[2] << " ";
+ }
+ }
+
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout << "" << std::endl;
+ fout.close();
+}
+
+template
+void SuperParticleSysVtuWriterMag::write(int iT)
+{
+ //std::cout << "Write derived" << std::endl;
+ int rank = 0;
+ int size = 1;
+#ifdef PARALLEL_MODE_MPI
+ rank = singleton::mpi().getRank();
+ size = singleton::mpi().getSize();
+#endif
+
+ if (rank == 0) { // master only
+ if (!this->_haveMaster) {
+ this->createMasterFile();
+ }
+
+ std::string fullNamePVDmaster = singleton::directories().getVtkOutDir()
+ + createFileName(this->_name) + "_master.pvd";
+ std::string fullNamePVD = singleton::directories().getVtkOutDir() + "data/"
+ + createFileName(this->_name, iT) + ".pvd";
+
+ this->preamblePVD(fullNamePVD); // timestep
+ for (int iR = 0; iR < size; iR++) { // cuboid
+ std::string namePiece = "data/" + createFileName(this->_name, iT, iR) + ".vtu";
+ // puts name of .vti piece to a .pvd file [fullNamePVD]
+ this->dataPVD(iT, iR, fullNamePVD, namePiece);
+ // adds a namePiece to master.pvd file.
+ // To do so we overwrite closePVD() and add new entry.
+ this->dataPVDmaster(iT, iR, fullNamePVDmaster, namePiece);
+ } // cuboid
+ this->closePVD(fullNamePVD); // timestep
+ } // master only
+
+ std::string fullNameVTU = singleton::directories().getVtkOutDir()
+ + "data/" + createFileName(this->_name, iT, rank) + ".vtu";
+ this->preambleVTU(fullNameVTU);
+ if (this->_binary) {
+ this->dataArrayBinary(fullNameVTU);
+ } else {
+ this->dataArray(fullNameVTU);
+ }
+ this->closeVTU(fullNameVTU);
+}
+
+template
+void SuperParticleSysVtuWriterMag::set(int pref)
+{
+ _properties.set(pref);
+}
+
+
+
+} // namespace OLB
+
+#endif /* SUPERPARTICLESYSVTUOUT_HH */
--
cgit v1.2.3