rawSurfaceWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 #include "OFstream.H"
28 #include "OSspecific.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  makeSurfaceWriterType(rawSurfaceWriter);
36  addToRunTimeSelectionTable(surfaceWriter, rawSurfaceWriter, wordDict);
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 inline void Foam::rawSurfaceWriter::writeLocation
43 (
44  Ostream& os,
45  const pointField& points,
46  const label pointi
47 )
48 {
49  const point& pt = points[pointi];
50  os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << ' ';
51 }
52 
53 
54 inline void Foam::rawSurfaceWriter::writeLocation
55 (
56  Ostream& os,
57  const pointField& points,
58  const faceList& faces,
59  const label facei
60 )
61 {
62  const point& ct = faces[facei].centre(points);
63  os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' ';
64 }
65 
66 
67 namespace Foam
68 {
69  template<>
70  void Foam::rawSurfaceWriter::writeHeader
71  (
72  Ostream& os,
73  const word& fieldName,
74  const Field<scalar>& values
75  )
76  {
77  os << values.size() << nl
78  << "# x y z " << fieldName << nl;
79  }
80 
81 
82  template<>
83  void Foam::rawSurfaceWriter::writeHeader
84  (
85  Ostream& os,
86  const word& fieldName,
87  const Field<vector>& values
88  )
89  {
90  os << values.size() << nl
91  << "# x y z "
92  << fieldName << "_x "
93  << fieldName << "_y "
94  << fieldName << "_z "
95  << endl;
96  }
97 
98 
99  template<>
100  void Foam::rawSurfaceWriter::writeHeader
101  (
102  Ostream& os,
103  const word& fieldName,
104  const Field<sphericalTensor>& values
105  )
106  {
107  os << values.size() << nl
108  << "# ii "
109  << fieldName << "_ii" << nl;
110  }
111 
112 
113  template<>
114  void Foam::rawSurfaceWriter::writeHeader
115  (
116  Ostream& os,
117  const word& fieldName,
118  const Field<symmTensor>& values
119  )
120  {
121  os << values.size() << nl
122  << "# xx xy xz yy yz ";
123  for (int i=0; i<6; ++i)
124  {
125  os << fieldName << "_" << i << " ";
126  }
127  os << endl;
128  }
129 
130 
131  template<>
132  void Foam::rawSurfaceWriter::writeHeader
133  (
134  Ostream& os,
135  const word& fieldName,
136  const Field<tensor>& values
137  )
138  {
139  os << values.size() << nl
140  << "# xx xy xz yx yy yz zx zy zz";
141  for (int i=0; i<9; ++i)
142  {
143  os << fieldName << "_" << i << " ";
144  }
145  os << nl;
146  }
147 
148 
149  template<>
150  inline void Foam::rawSurfaceWriter::writeData
151  (
152  Ostream& os,
153  const scalar& v
154  )
155  {
156  os << v << nl;
157  }
158 
159 
160  template<>
161  inline void Foam::rawSurfaceWriter::writeData
162  (
163  Ostream& os,
164  const vector& v
165  )
166  {
167  os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
168  }
169 
170 
171  template<>
172  inline void Foam::rawSurfaceWriter::writeData
173  (
174  Ostream& os,
175  const sphericalTensor& v
176  )
177  {
178  os << v[0] << nl;
179  }
180 
181 
182  template<>
183  inline void Foam::rawSurfaceWriter::writeData
184  (
185  Ostream& os,
186  const symmTensor& v
187  )
188  {
189  os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
190  << v[3] << ' ' << v[4] << ' ' << v[5] << nl;
191  }
192 
193 
194  template<>
195  inline void Foam::rawSurfaceWriter::writeData
196  (
197  Ostream& os,
198  const tensor& v
199  )
200  {
201  os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
202  << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
203  << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
204  }
205 
206 }
207 
208 
209 template<class Type>
210 void Foam::rawSurfaceWriter::writeTemplate
211 (
212  const fileName& outputDir,
213  const fileName& surfaceName,
214  const pointField& points,
215  const faceList& faces,
216  const word& fieldName,
217  const Field<Type>& values,
218  const bool isNodeValues,
219  const bool verbose
220 ) const
221 {
222  if (!isDir(outputDir))
223  {
224  mkDir(outputDir);
225  }
226 
227  OFstream os
228  (
229  outputDir/fieldName + '_' + surfaceName + ".raw",
232  writeCompression_
233  );
234 
235  if (verbose)
236  {
237  Info<< "Writing field " << fieldName << " to " << os.name() << endl;
238  }
239 
240  // Header
241  os << "# " << fieldName;
242  if (isNodeValues)
243  {
244  os << " POINT_DATA ";
245  }
246  else
247  {
248  os << " FACE_DATA ";
249  }
250 
251  // Header
252  writeHeader(os, fieldName, values);
253 
254  // Values
255  if (isNodeValues)
256  {
257  forAll(values, elemI)
258  {
259  writeLocation(os, points, elemI);
260  writeData(os, values[elemI]);
261  }
262  }
263  else
264  {
265  forAll(values, elemI)
266  {
267  writeLocation(os, points, faces, elemI);
268  writeData(os, values[elemI]);
269  }
270  }
271 }
272 
273 
274 
275 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
276 
278 :
279  surfaceWriter(),
280  writeCompression_(IOstream::UNCOMPRESSED)
281 {}
282 
283 
285 :
286  surfaceWriter(),
287  writeCompression_(IOstream::UNCOMPRESSED)
288 {
289  if (options.found("compression"))
290  {
291  writeCompression_ =
292  IOstream::compressionEnum(options.lookup("compression"));
293  }
294 }
295 
296 
297 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
298 
300 {}
301 
302 
303 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
304 
306 (
307  const fileName& outputDir,
308  const fileName& surfaceName,
309  const pointField& points,
310  const faceList& faces,
311  const bool verbose
312 ) const
313 {
314  if (!isDir(outputDir))
315  {
316  mkDir(outputDir);
317  }
318 
319  OFstream os
320  (
321  outputDir/surfaceName + ".raw",
324  writeCompression_
325  );
326 
327  if (verbose)
328  {
329  Info<< "Writing geometry to " << os.name() << endl;
330  }
331 
332 
333  // Header
334  os << "# geometry NO_DATA " << faces.size() << nl
335  << "# x y z" << nl;
336 
337  // Write faces centres
338  forAll(faces, elemI)
339  {
340  writeLocation(os, points, faces, elemI);
341  os << nl;
342  }
343 
344  os << nl;
345 }
346 
347 
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349 
350 // Create write methods
352 
353 
354 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:438
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:79
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
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:256
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:539
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
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
static const char nl
Definition: Ostream.H:265
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:290
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
makeSurfaceWriterType(ensightSurfaceWriter)
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:583