rawSurfaceWriter.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-2016 OpenFOAM Foundation
6  \\/ M anipulation |
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 "rawSurfaceWriter.H"
27 
28 #include "OFstream.H"
29 #include "OSspecific.H"
30 #include "IOmanip.H"
31 
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  makeSurfaceWriterType(rawSurfaceWriter);
39  addToRunTimeSelectionTable(surfaceWriter, rawSurfaceWriter, wordDict);
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 inline void Foam::rawSurfaceWriter::writeLocation
46 (
47  Ostream& os,
48  const pointField& points,
49  const label pointi
50 )
51 {
52  const point& pt = points[pointi];
53  os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << ' ';
54 }
55 
56 
57 inline void Foam::rawSurfaceWriter::writeLocation
58 (
59  Ostream& os,
60  const pointField& points,
61  const faceList& faces,
62  const label facei
63 )
64 {
65  const point& ct = faces[facei].centre(points);
66  os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' ';
67 }
68 
69 
70 namespace Foam
71 {
72  template<>
73  void Foam::rawSurfaceWriter::writeHeader
74  (
75  Ostream& os,
76  const word& fieldName,
77  const Field<scalar>& values
78  )
79  {
80  os << values.size() << nl
81  << "# x y z " << fieldName << nl;
82  }
83 
84 
85  template<>
86  void Foam::rawSurfaceWriter::writeHeader
87  (
88  Ostream& os,
89  const word& fieldName,
90  const Field<vector>& values
91  )
92  {
93  os << values.size() << nl
94  << "# x y z "
95  << fieldName << "_x "
96  << fieldName << "_y "
97  << fieldName << "_z "
98  << endl;
99  }
100 
101 
102  template<>
103  void Foam::rawSurfaceWriter::writeHeader
104  (
105  Ostream& os,
106  const word& fieldName,
107  const Field<sphericalTensor>& values
108  )
109  {
110  os << values.size() << nl
111  << "# ii "
112  << fieldName << "_ii" << nl;
113  }
114 
115 
116  template<>
117  void Foam::rawSurfaceWriter::writeHeader
118  (
119  Ostream& os,
120  const word& fieldName,
121  const Field<symmTensor>& values
122  )
123  {
124  os << values.size() << nl
125  << "# xx xy xz yy yz ";
126  for (int i=0; i<6; ++i)
127  {
128  os << fieldName << "_" << i << " ";
129  }
130  os << endl;
131  }
132 
133 
134  template<>
135  void Foam::rawSurfaceWriter::writeHeader
136  (
137  Ostream& os,
138  const word& fieldName,
139  const Field<tensor>& values
140  )
141  {
142  os << values.size() << nl
143  << "# xx xy xz yx yy yz zx zy zz";
144  for (int i=0; i<9; ++i)
145  {
146  os << fieldName << "_" << i << " ";
147  }
148  os << nl;
149  }
150 
151 
152  template<>
153  inline void Foam::rawSurfaceWriter::writeData
154  (
155  Ostream& os,
156  const scalar& v
157  )
158  {
159  os << v << nl;
160  }
161 
162 
163  template<>
164  inline void Foam::rawSurfaceWriter::writeData
165  (
166  Ostream& os,
167  const vector& v
168  )
169  {
170  os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
171  }
172 
173 
174  template<>
175  inline void Foam::rawSurfaceWriter::writeData
176  (
177  Ostream& os,
178  const sphericalTensor& v
179  )
180  {
181  os << v[0] << nl;
182  }
183 
184 
185  template<>
186  inline void Foam::rawSurfaceWriter::writeData
187  (
188  Ostream& os,
189  const symmTensor& v
190  )
191  {
192  os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
193  << v[3] << ' ' << v[4] << ' ' << v[5] << nl;
194  }
195 
196 
197  template<>
198  inline void Foam::rawSurfaceWriter::writeData
199  (
200  Ostream& os,
201  const tensor& v
202  )
203  {
204  os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
205  << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
206  << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
207  }
208 
209 }
210 
211 
212 template<class Type>
213 void Foam::rawSurfaceWriter::writeTemplate
214 (
215  const fileName& outputDir,
216  const fileName& surfaceName,
217  const pointField& points,
218  const faceList& faces,
219  const word& fieldName,
220  const Field<Type>& values,
221  const bool isNodeValues,
222  const bool verbose
223 ) const
224 {
225  if (!isDir(outputDir))
226  {
227  mkDir(outputDir);
228  }
229 
230  OFstream os
231  (
232  outputDir/fieldName + '_' + surfaceName + ".raw",
235  writeCompression_
236  );
237 
238  if (verbose)
239  {
240  Info<< "Writing field " << fieldName << " to " << os.name() << endl;
241  }
242 
243  // Header
244  os << "# " << fieldName;
245  if (isNodeValues)
246  {
247  os << " POINT_DATA ";
248  }
249  else
250  {
251  os << " FACE_DATA ";
252  }
253 
254  // Header
255  writeHeader(os, fieldName, values);
256 
257  // Values
258  if (isNodeValues)
259  {
260  forAll(values, elemI)
261  {
262  writeLocation(os, points, elemI);
263  writeData(os, values[elemI]);
264  }
265  }
266  else
267  {
268  forAll(values, elemI)
269  {
270  writeLocation(os, points, faces, elemI);
271  writeData(os, values[elemI]);
272  }
273  }
274 }
275 
276 
277 
278 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
279 
281 :
282  surfaceWriter(),
283  writeCompression_(IOstream::UNCOMPRESSED)
284 {}
285 
286 
288 :
289  surfaceWriter(),
290  writeCompression_(IOstream::UNCOMPRESSED)
291 {
292  if (options.found("compression"))
293  {
294  writeCompression_ =
295  IOstream::compressionEnum(options.lookup("compression"));
296  }
297 }
298 
299 
300 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
301 
303 {}
304 
305 
306 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
307 
309 (
310  const fileName& outputDir,
311  const fileName& surfaceName,
312  const pointField& points,
313  const faceList& faces,
314  const bool verbose
315 ) const
316 {
317  if (!isDir(outputDir))
318  {
319  mkDir(outputDir);
320  }
321 
322  OFstream os
323  (
324  outputDir/surfaceName + ".raw",
327  writeCompression_
328  );
329 
330  if (verbose)
331  {
332  Info<< "Writing geometry to " << os.name() << endl;
333  }
334 
335 
336  // Header
337  os << "# geometry NO_DATA " << faces.size() << nl
338  << "# x y z" << nl;
339 
340  // Write faces centres
341  forAll(faces, elemI)
342  {
343  writeLocation(os, points, faces, elemI);
344  os << nl;
345  }
346 
347  os << nl;
348 }
349 
350 
351 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 
353 // Create write methods
355 
356 
357 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A surfaceWriter for raw output.
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
static compressionType compressionEnum(const word &)
Return compression of given compression name.
Definition: IOstream.C:61
A class for handling file names.
Definition: fileName.H:69
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Output to file stream.
Definition: OFstream.H:82
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:120
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component, element access using th ii() member function and the inner-product (dot-product) and outer-product operators.
const Vector< Cmpt > & centre(const Foam::List< Vector< Cmpt >> &) const
Return *this (used for point which is a typedef to Vector<scalar>.
Definition: VectorI.H:116
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
virtual ~rawSurfaceWriter()
Destructor.
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:536
A class for handling words, derived from string.
Definition: word.H:59
Convenience macros for instantiating writer methods for surfaceWriter classes.
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
const Cmpt & x() const
Definition: VectorI.H:75
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Istream and Ostream manipulators taking arguments.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
static const char nl
Definition: Ostream.H:262
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:297
An IOstream is an abstract base class for all input/output systems; be they streams, files, token lists etc.
Definition: IOstream.H:71
vector point
Point is a vector.
Definition: point.H:41
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
messageStream Info
rawSurfaceWriter()
Construct null.
Base class for surface writers.
Definition: surfaceWriter.H:54
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const bool verbose=false) const
Write single surface geometry to file.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576
makeSurfaceWriterType(dxSurfaceWriter)