MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SphericalParticleVtkWriter.cc
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
27 #include "DPMBase.h"
28 
36 {
37  std::fstream file = makeVTKFileWithHeader();
38  long numberOfParticlesToWrite = std::count_if(handler_.begin(), handler_.end(),
39  [this](BaseParticle* p){return particleMustBeWritten(p);});
40  file << "<Piece NumberOfPoints=\"" << numberOfParticlesToWrite
41  << "\" NumberOfCells=\"" << 0 << "\">\n";
42  writeVTKPositions(file);
43  file << "<PointData Vectors=\"vector\">\n";
44  writeVTKVelocity(file);
45  writeVTKRadius(file);
46  writeVTKIndSpecies(file);
47  writeExtraFields(file);
48 
49  file << "</PointData>\n";
51 }
52 
53 void SphericalParticleVtkWriter::writeVTKVelocity(std::fstream& file) const
54 {
55  file << " <DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"ascii\">\n";
56  // Add velocity
57  for (const auto& p: handler_) {
58 #ifdef MERCURY_USE_MPI
59  if (particleMustBeWritten(p))
60 #endif
61  {
62  file << ' ' << (float) p->getVelocity().X
63  << ' ' << (float) p->getVelocity().Y
64  << ' ' << (float) p->getVelocity().Z << '\n';
65  }
66  }
67  file << " </DataArray>\n";
68 }
69 
76 void SphericalParticleVtkWriter::writeVTKRadius(std::fstream& file) const
77 {
78  file << " <DataArray type=\"Float32\" Name=\"Radius\" format=\"ascii\">\n";
79  // Add radius
80  for (const auto& p: handler_)
81  {
82 #ifdef MERCURY_USE_MPI
83  if (particleMustBeWritten(p))
84  {
85  file << '\t' << p->getRadius() << '\n';
86  }
87 #else
88  file << '\t' << p->getRadius() << '\n';//Radius
89 #endif
90  }
91  file << " </DataArray>\n";
92 }
void writeVTK() const override
Writes all particles into a vtk file format (unstructured grid), consisting of particle positions...
void writeVTKPositions(std::fstream &file) const
void writeVTKIndSpecies(std::fstream &file) const
ParticleHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
bool particleMustBeWritten(BaseParticle *particle) const
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:704
std::fstream makeVTKFileWithHeader() const
void writeVTKFooterAndClose(std::fstream &file) const
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:690
void writeVTKVelocity(std::fstream &file) const
void writeExtraFields(std::fstream &file) const
void writeVTKRadius(std::fstream &file) const