MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InteractionVTKWriter.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 
30 {
31  std::fstream file = makeVTKFileWithHeader();
32  file << "<Piece NumberOfPoints=\"" << handler_.getNumberOfObjects() << "\" NumberOfCells=\"" << 0 << "\">\n";
33  file << "<Points>\n";
34  writeVTKPoints(file);
35  file << "</Points>\n";
36  file << "<PointData Vectors=\"vector\">\n";
37  writeVTKPointData(file);
38  file << "</PointData>\n";
40 }
41 
42 void InteractionVTKWriter::writeVTKPoints(std::fstream& file) const
43 {
44  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
45  for (const auto& p: handler_)
46  {
47  file << '\t' << p->getContactPoint() << '\n';
48  }
49  file << " </DataArray>\n";
50 }
51 
52 void InteractionVTKWriter::writeVTKPointData(std::fstream& file) const
53 {
54  file << " <DataArray type=\"Float32\" Name=\"Normal\" NumberOfComponents=\"3\" format=\"ascii\">\n";
55  // Add velocity
56  for (const auto& p: handler_)
57  {
58  file << '\t' << p->getNormal() << '\n';
59  }
60  file << " </DataArray>\n";
61  file << " <DataArray type=\"Float32\" Name=\"Overlap\" format=\"ascii\">\n";
62 
63  // Add overlap
64  for (const auto& p: handler_)
65  {
66  file << '\t' << p->getOverlap() << '\n';
67  }
68  file << " </DataArray>\n";
69  file << " <DataArray type=\"Float32\" Name=\"ContactRadius\" format=\"ascii\">\n";
70 
71  // Add radius
72  for (const auto& p: handler_)
73  {
74  file << '\t' << p->getContactRadius() << '\n';
75  }
76  file << " </DataArray>\n";
77  file << " <DataArray type=\"Float32\" Name=\"Force\" format=\"ascii\">\n";
78 
79  // Add species type
80  for (const auto& p: handler_)
81  {
82  file << '\t' << p->getForce() << '\n';
83  }
84  file << " </DataArray>\n";
85  file << " <DataArray type=\"Float32\" Name=\"TangentialOverlap\" format=\"ascii\">\n";
86 
87  // Add species type
88  for (const auto& p: handler_)
89  {
90  file << '\t' << p->getTangentialOverlap() << '\n';
91  }
92  file << " </DataArray>\n";
93  file << " <DataArray type=\"Float32\" Name=\"Torque\" format=\"ascii\">\n";
94 
95  // Add species type
96  for (const auto& p: handler_)
97  {
98  file << '\t' << p->getTorque() << '\n';
99  }
100  file << " </DataArray>\n";
101 
102  //check if this type of Interaction has extra fields
103  if (handler_.getSize() != 0)
104  {
105  for (unsigned i = 0; i < handler_.getLastObject()->getNumberOfFieldsVTK(); i++)
106  {
107  file << " <DataArray type=\"" << handler_.getLastObject()->getTypeVTK(i) << "\" Name=\""
108  << handler_.getLastObject()->getNameVTK(i) << "\" format=\"ascii\">\n";
109  // Add species type
110  for (const auto& p: handler_)
111  {
112  for (auto f : p->getFieldVTK(i))
113  file << '\t' << f << '\n';
114  }
115  file << " </DataArray>\n";
116  }
117  }
118 }
void writeVTKPoints(std::fstream &file) const
writes the point data to the vtu file (i.e.
void writeVTK() const override
writes a vtk file
InteractionHandler & handler_
particle handler from which the particles should be written
Definition: BaseVTKWriter.h:72
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
std::fstream makeVTKFileWithHeader() const
void writeVTKFooterAndClose(std::fstream &file) const
void writeVTKPointData(std::fstream &file) const
writes the point data to the vtu file (i.e.
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
Definition: BaseHandler.h:648