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 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 "rawSurfaceWriter.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  makeSurfaceWriterType(rawSurfaceWriter);
34 }
35 
36 
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 
40 (
41  Ostream& os,
42  const pointField& points,
43  const label pointI
44 )
45 {
46  const point& pt = points[pointI];
47  os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << ' ';
48 }
49 
50 
52 (
53  Ostream& os,
54  const pointField& points,
55  const faceList& faces,
56  const label faceI
57 )
58 {
59  const point& ct = faces[faceI].centre(points);
60  os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' ';
61 }
62 
63 
64 namespace Foam
65 {
66  template<>
68  (
69  Ostream& os,
70  const word& fieldName,
71  const Field<scalar>& values
72  )
73  {
74  os << values.size() << nl
75  << "# x y z " << fieldName << nl;
76  }
77 
78 
79  template<>
81  (
82  Ostream& os,
83  const word& fieldName,
84  const Field<vector>& values
85  )
86  {
87  os << values.size() << nl
88  << "# x y z "
89  << fieldName << "_x "
90  << fieldName << "_y "
91  << fieldName << "_z "
92  << endl;
93  }
94 
95 
96  template<>
98  (
99  Ostream& os,
100  const word& fieldName,
101  const Field<sphericalTensor>& values
102  )
103  {
104  os << values.size() << nl
105  << "# ii "
106  << fieldName << "_ii" << nl;
107  }
108 
109 
110  template<>
112  (
113  Ostream& os,
114  const word& fieldName,
115  const Field<symmTensor>& values
116  )
117  {
118  os << values.size() << nl
119  << "# xx xy xz yy yz ";
120  for (int i=0; i<6; ++i)
121  {
122  os << fieldName << "_" << i << " ";
123  }
124  os << endl;
125  }
126 
127 
128  template<>
130  (
131  Ostream& os,
132  const word& fieldName,
133  const Field<tensor>& values
134  )
135  {
136  os << values.size() << nl
137  << "# xx xy xz yx yy yz zx zy zz";
138  for (int i=0; i<9; ++i)
139  {
140  os << fieldName << "_" << i << " ";
141  }
142  os << nl;
143  }
144 
145 
146  template<>
148  (
149  Ostream& os,
150  const scalar& v
151  )
152  {
153  os << v << nl;
154  }
155 
156 
157  template<>
159  (
160  Ostream& os,
161  const vector& v
162  )
163  {
164  os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
165  }
166 
167 
168  template<>
170  (
171  Ostream& os,
172  const sphericalTensor& v
173  )
174  {
175  os << v[0] << nl;
176  }
177 
178 
179  template<>
181  (
182  Ostream& os,
183  const symmTensor& v
184  )
185  {
186  os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
187  << v[3] << ' ' << v[4] << ' ' << v[5] << nl;
188  }
189 
190 
191  template<>
193  (
194  Ostream& os,
195  const tensor& v
196  )
197  {
198  os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
199  << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
200  << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
201  }
202 
203 }
204 
205 
206 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
207 
209 :
210  surfaceWriter()
211 {}
212 
213 
214 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
215 
217 {}
218 
219 
220 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
221 
223 (
224  const fileName& outputDir,
225  const fileName& surfaceName,
226  const pointField& points,
227  const faceList& faces,
228  const bool verbose
229 ) const
230 {
231  if (!isDir(outputDir))
232  {
233  mkDir(outputDir);
234  }
235 
236  OFstream os(outputDir/surfaceName + ".raw");
237 
238  if (verbose)
239  {
240  Info<< "Writing geometry to " << os.name() << endl;
241  }
242 
243 
244  // header
245  os << "# geometry NO_DATA " << faces.size() << nl
246  << "# x y z" << nl;
247 
248  // Write faces centres
249  forAll(faces, elemI)
250  {
251  writeLocation(os, points, faces, elemI);
252  os << nl;
253  }
254 
255  os << nl;
256 
257  return os.name();
258 }
259 
260 
261 // create write methods
263 
264 
265 // ************************************************************************* //
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::SymmTensor< scalar >
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:54
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::rawSurfaceWriter::rawSurfaceWriter
rawSurfaceWriter()
Construct null.
Definition: rawSurfaceWriter.C:208
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
rawSurfaceWriter.H
Foam::rawSurfaceWriter
A surfaceWriter for raw output.
Definition: rawSurfaceWriter.H:49
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::rawSurfaceWriter::~rawSurfaceWriter
virtual ~rawSurfaceWriter()
Destructor.
Definition: rawSurfaceWriter.C:216
makeSurfaceWriterMethods.H
Convenience macros for instantiating writer methods for surfaceWriter classes.
Foam::rawSurfaceWriter::writeHeader
static void writeHeader(Ostream &, const word &fieldName, const Field< Type > &)
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::rawSurfaceWriter::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: rawSurfaceWriter.C:223
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
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
Foam::rawSurfaceWriter::writeLocation
static void writeLocation(Ostream &, const pointField &, const label pointI)
Definition: rawSurfaceWriter.C:40
Foam::Vector< scalar >
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::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
Foam::rawSurfaceWriter::writeData
static void writeData(Ostream &, const Type &)