vtkSurfaceWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "vtkSurfaceWriter.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  makeSurfaceWriterType(vtkSurfaceWriter);
34 }
35 
36 
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 
40 (
41  Ostream& os,
42  const pointField& points,
43  const faceList& faces
44 )
45 {
46  // header
47  os
48  << "# vtk DataFile Version 2.0" << nl
49  << "sampleSurface" << nl
50  << "ASCII" << nl
51  << "DATASET POLYDATA" << nl;
52 
53  // Write vertex coords
54  os << "POINTS " << points.size() << " float" << nl;
55  forAll(points, pointI)
56  {
57  const point& pt = points[pointI];
58  os << float(pt.x()) << ' '
59  << float(pt.y()) << ' '
60  << float(pt.z()) << nl;
61  }
62  os << nl;
63 
64 
65  // Write faces
66  label nNodes = 0;
67  forAll(faces, faceI)
68  {
69  nNodes += faces[faceI].size();
70  }
71 
72  os << "POLYGONS " << faces.size() << ' '
73  << faces.size() + nNodes << nl;
74 
75  forAll(faces, faceI)
76  {
77  const face& f = faces[faceI];
78 
79  os << f.size();
80  forAll(f, fp)
81  {
82  os << ' ' << f[fp];
83  }
84  os << nl;
85  }
86 }
87 
88 
89 namespace Foam
90 {
91 
92  template<>
94  (
95  Ostream& os,
96  const Field<scalar>& values
97  )
98  {
99  os << "1 " << values.size() << " float" << nl;
100 
101  forAll(values, elemI)
102  {
103  if (elemI)
104  {
105  if (elemI % 10)
106  {
107  os << ' ';
108  }
109  else
110  {
111  os << nl;
112  }
113  }
114 
115  os << float(values[elemI]);
116  }
117  os << nl;
118  }
119 
120 
121  template<>
123  (
124  Ostream& os,
125  const Field<vector>& values
126  )
127  {
128  os << "3 " << values.size() << " float" << nl;
129 
130  forAll(values, elemI)
131  {
132  const vector& v = values[elemI];
133  os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
134  << nl;
135  }
136  }
137 
138 
139  template<>
141  (
142  Ostream& os,
143  const Field<sphericalTensor>& values
144  )
145  {
146  os << "1 " << values.size() << " float" << nl;
147 
148  forAll(values, elemI)
149  {
150  const sphericalTensor& v = values[elemI];
151  os << float(v[0]) << nl;
152  }
153  }
154 
155 
156  template<>
158  (
159  Ostream& os,
160  const Field<symmTensor>& values
161  )
162  {
163  os << "6 " << values.size() << " float" << nl;
164 
165  forAll(values, elemI)
166  {
167  const symmTensor& v = values[elemI];
168  os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
169  << ' '
170  << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
171  << nl;
172 
173  }
174  }
175 
176 
177  template<>
179  (
180  Ostream& os,
181  const Field<tensor>& values
182  )
183  {
184  os << "9 " << values.size() << " float" << nl;
185 
186  forAll(values, elemI)
187  {
188  const tensor& v = values[elemI];
189  os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
190  << ' '
191  << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
192  << ' '
193  << float(v[6]) << ' ' << float(v[7]) << ' ' << float(v[8])
194  << nl;
195  }
196  }
197 
198 }
199 
200 
201 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
202 
204 :
205  surfaceWriter()
206 {}
207 
208 
209 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
210 
212 {}
213 
214 
215 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
216 
218 (
219  const fileName& outputDir,
220  const fileName& surfaceName,
221  const pointField& points,
222  const faceList& faces,
223  const bool verbose
224 ) const
225 {
226  if (!isDir(outputDir))
227  {
228  mkDir(outputDir);
229  }
230 
231  OFstream os(outputDir/surfaceName + ".vtk");
232 
233  if (verbose)
234  {
235  Info<< "Writing geometry to " << os.name() << endl;
236  }
237 
238  writeGeometry(os, points, faces);
239 
240  return os.name();
241 }
242 
243 
244 // create write methods
246 
247 
248 // ************************************************************************* //
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::SymmTensor< scalar >
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:54
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::vtkSurfaceWriter::write
virtual fileName write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const bool verbose=false) const
Write single surface geometry to file.
Definition: vtkSurfaceWriter.C:218
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::vtkSurfaceWriter::vtkSurfaceWriter
vtkSurfaceWriter()
Construct null.
Definition: vtkSurfaceWriter.C:203
makeSurfaceWriterMethods.H
Convenience macros for instantiating writer methods for surfaceWriter classes.
Foam::vtkSurfaceWriter::writeData
static void writeData(Ostream &, const Field< Type > &)
Definition: vtkSurfaceWriterTemplates.C:33
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::defineSurfaceWriterWriteFields
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
Foam::vtkSurfaceWriter::writeGeometry
static void writeGeometry(Ostream &, const pointField &, const faceList &)
Definition: vtkSurfaceWriter.C:40
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::vtkSurfaceWriter::~vtkSurfaceWriter
virtual ~vtkSurfaceWriter()
Destructor.
Definition: vtkSurfaceWriter.C:211
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::SphericalTensor
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component,...
Definition: SphericalTensor.H:51
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
f
labelList f(nPoints)
Foam::Vector< scalar >
vtkSurfaceWriter.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::vtkSurfaceWriter
A surfaceWriter for VTK legacy format.
Definition: vtkSurfaceWriter.H:48
Foam::OFstream::name
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:118
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::makeSurfaceWriterType
makeSurfaceWriterType(boundaryDataSurfaceWriter)
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419