nastranSurfaceWriter.H
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) 2012-2013 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 Class
25  Foam::nastranSurfaceWriter
26 
27 Description
28  A surface writer for the Nastran file format - both surface mesh and fields
29 
30  formatOptions
31  {
32  nastran
33  {
34  // From OpenFOAM field name to Nastran field name
35  fields
36  (
37  (pMean PLOAD2)
38  (p PLOAD4)
39  );
40  // Optional scale
41  scale 2.0;
42  // Optional format
43  format free; //short, long, free
44  }
45  };
46 
47 SourceFiles
48  nastranSurfaceWriter.C
49  nastranSurfaceWriterTemplates.C
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef nastranSurfaceWriter_H
54 #define nastranSurfaceWriter_H
55 
56 #include "surfaceWriter.H"
57 #include "NamedEnum.H"
58 #include "OFstream.H"
59 #include "HashTable.H"
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 namespace Foam
64 {
65 
66 /*---------------------------------------------------------------------------*\
67  Class nastranSurfaceWriter Declaration
68 \*---------------------------------------------------------------------------*/
69 
71 :
72  public surfaceWriter
73 {
74 public:
75 
76  enum writeFormat
77  {
80  wfFree
81  };
82 
84 
85  enum dataFormat
86  {
88  dfPLOAD4
89  };
90 
92 
93 
94 private:
95 
96  // Private data
97 
98  //- Write option
100 
101  //- Mapping from field name to data format enumeration
103 
104  //- Scale to apply to values (default = 1.0)
105  scalar scale_;
106 
107  //- Separator used for free format
109 
110 
111  // Private Member Functions
112 
113  //- Initialise the output stream format params
114  void formatOS(OFstream& os) const;
115 
116  //- Write a co-ordinate
117  void writeCoord
118  (
119  const point& p,
120  const label pointI,
121  OFstream& os
122  ) const;
123 
124  //- Write a face element (CTRIA3 or CQUAD4)
125  void writeFace
126  (
127  const word& faceType,
128  const labelList& facePts,
129  label& nFace,
130  OFstream& os
131  ) const;
132 
133  //- Main driver to write the surface mesh geometry
134  void writeGeometry
135  (
136  const pointField& points,
137  const faceList& faces,
138  List<DynamicList<face> >& decomposedFaces,
139  OFstream& os
140  ) const;
141 
142  //- Write the formatted keyword to the output stream
143  void writeKeyword
144  (
145  const word& keyword,
146  Ostream& os
147  ) const;
148 
149  //- Write the footer information
150  void writeFooter(Ostream& os) const;
151 
152  //- Write a formatted value to the output stream
153  template<class Type>
154  void writeValue
155  (
156  const Type& value,
157  Ostream& os
158  ) const;
159 
160  //- Write a face-based value
161  template<class Type>
162  void writeFaceValue
163  (
164  const dataFormat& format,
165  const Type& value,
166  const label EID,
167  Ostream& os
168  ) const;
169 
170  //- Templated write operation
171  template<class Type>
173  (
174  const fileName& outputDir,
175  const fileName& surfaceName,
176  const pointField& points,
177  const faceList& faces,
178  const word& fieldName,
179  const Field<Type>& values,
180  const bool isNodeValues,
181  const bool verbose
182  ) const;
183 
184 
185 public:
186 
187  //- Runtime type information
188  TypeName("nastran");
189 
190 
191  // Constructors
192 
193  //- Construct null
195 
196  //- Construct with some output options
197  nastranSurfaceWriter(const dictionary& options);
198 
199 
200  //- Destructor
201  virtual ~nastranSurfaceWriter();
202 
203 
204  // Member Functions
205 
206  //- True if the surface format supports geometry in a separate file.
207  // False if geometry and field must be in a single file
208  virtual bool separateGeometry() const
209  {
210  return false;
211  }
212 
213  //- Write single surface geometry to file.
214  virtual fileName write
215  (
216  const fileName& outputDir,
217  const fileName& surfaceName,
218  const pointField& points,
219  const faceList& faces,
220  const bool verbose = false
221  ) const;
222 
223  //- Write scalarField for a single surface to file.
224  // One value per face or vertex (isNodeValues = true)
225  virtual fileName write
226  (
227  const fileName& outputDir,
228  const fileName& surfaceName,
229  const pointField& points,
230  const faceList& faces,
231  const word& fieldName,
232  const Field<scalar>& values,
233  const bool isNodeValues,
234  const bool verbose = false
235  ) const;
236 
237  //- Write vectorField for a single surface to file.
238  // One value per face or vertex (isNodeValues = true)
239  virtual fileName write
240  (
241  const fileName& outputDir,
242  const fileName& surfaceName,
243  const pointField& points,
244  const faceList& faces,
245  const word& fieldName,
246  const Field<vector>& values,
247  const bool isNodeValues,
248  const bool verbose = false
249  ) const;
250 
251  //- Write sphericalTensorField for a single surface to file.
252  // One value per face or vertex (isNodeValues = true)
253  virtual fileName write
254  (
255  const fileName& outputDir,
256  const fileName& surfaceName,
257  const pointField& points,
258  const faceList& faces,
259  const word& fieldName,
260  const Field<sphericalTensor>& values,
261  const bool isNodeValues,
262  const bool verbose = false
263  ) const;
264 
265  //- Write symmTensorField for a single surface to file.
266  // One value per face or vertex (isNodeValues = true)
267  virtual fileName write
268  (
269  const fileName& outputDir,
270  const fileName& surfaceName,
271  const pointField& points,
272  const faceList& faces,
273  const word& fieldName,
274  const Field<symmTensor>& values,
275  const bool isNodeValues,
276  const bool verbose = false
277  ) const;
278 
279  //- Write tensorField for a single surface to file.
280  // One value per face or vertex (isNodeValues = true)
281  virtual fileName write
282  (
283  const fileName& outputDir,
284  const fileName& surfaceName,
285  const pointField& points,
286  const faceList& faces,
287  const word& fieldName,
288  const Field<tensor>& values,
289  const bool isNodeValues,
290  const bool verbose = false
291  ) const;
292 };
293 
294 
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 
297 } // End namespace Foam
298 
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 
301 #ifdef NoRepository
303 #endif
304 
305 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
306 
307 #endif
308 
309 // ************************************************************************* //
Foam::nastranSurfaceWriter::nastranSurfaceWriter
nastranSurfaceWriter()
Construct null.
Definition: nastranSurfaceWriter.C:384
format
word format(conversionProperties.lookup("format"))
Foam::nastranSurfaceWriter::writeTemplate
fileName writeTemplate(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const word &fieldName, const Field< Type > &values, const bool isNodeValues, const bool verbose) const
Templated write operation.
p
p
Definition: pEqn.H:62
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
HashTable.H
Foam::nastranSurfaceWriter::dataFormat
dataFormat
Definition: nastranSurfaceWriter.H:84
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::nastranSurfaceWriter::scale_
scalar scale_
Scale to apply to values (default = 1.0)
Definition: nastranSurfaceWriter.H:104
Foam::nastranSurfaceWriter::writeFormat
writeFormat
Definition: nastranSurfaceWriter.H:75
NamedEnum.H
Foam::nastranSurfaceWriter::~nastranSurfaceWriter
virtual ~nastranSurfaceWriter()
Destructor.
Definition: nastranSurfaceWriter.C:424
Foam::nastranSurfaceWriter::writeFace
void writeFace(const word &faceType, const labelList &facePts, label &nFace, OFstream &os) const
Write a face element (CTRIA3 or CQUAD4)
Definition: nastranSurfaceWriter.C:203
Foam::nastranSurfaceWriter::dfPLOAD4
@ dfPLOAD4
Definition: nastranSurfaceWriter.H:87
Foam::nastranSurfaceWriter::writeCoord
void writeCoord(const point &p, const label pointI, OFstream &os) const
Write a co-ordinate.
Definition: nastranSurfaceWriter.C:130
Foam::nastranSurfaceWriter::separateGeometry
virtual bool separateGeometry() const
True if the surface format supports geometry in a separate file.
Definition: nastranSurfaceWriter.H:207
surfaceWriter.H
Foam::nastranSurfaceWriter::dataFormatNames_
static const NamedEnum< dataFormat, 2 > dataFormatNames_
Definition: nastranSurfaceWriter.H:90
Foam::nastranSurfaceWriter::separator_
word separator_
Separator used for free format.
Definition: nastranSurfaceWriter.H:107
OFstream.H
Foam::nastranSurfaceWriter
A surface writer for the Nastran file format - both surface mesh and fields.
Definition: nastranSurfaceWriter.H:69
Foam::nastranSurfaceWriter::TypeName
TypeName("nastran")
Runtime type information.
Foam::nastranSurfaceWriter::wfLong
@ wfLong
Definition: nastranSurfaceWriter.H:78
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::nastranSurfaceWriter::writeFooter
void writeFooter(Ostream &os) const
Write the footer information.
Definition: nastranSurfaceWriter.C:346
Foam::nastranSurfaceWriter::writeFormat_
writeFormat writeFormat_
Write option.
Definition: nastranSurfaceWriter.H:98
Foam::nastranSurfaceWriter::dfPLOAD2
@ dfPLOAD2
Definition: nastranSurfaceWriter.H:86
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::nastranSurfaceWriter::wfShort
@ wfShort
Definition: nastranSurfaceWriter.H:77
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::nastranSurfaceWriter::formatOS
void formatOS(OFstream &os) const
Initialise the output stream format params.
Definition: nastranSurfaceWriter.C:67
nastranSurfaceWriterTemplates.C
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
Foam::nastranSurfaceWriter::writeKeyword
void writeKeyword(const word &keyword, Ostream &os) const
Write the formatted keyword to the output stream.
Definition: nastranSurfaceWriter.C:99
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::nastranSurfaceWriter::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: nastranSurfaceWriter.C:431
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::nastranSurfaceWriter::writeValue
void writeValue(const Type &value, Ostream &os) const
Write a formatted value to the output stream.
Definition: nastranSurfaceWriterTemplates.C:34
Foam::nastranSurfaceWriter::writeFormatNames_
static const NamedEnum< writeFormat, 3 > writeFormatNames_
Definition: nastranSurfaceWriter.H:82
Foam::nastranSurfaceWriter::writeGeometry
void writeGeometry(const pointField &points, const faceList &faces, List< DynamicList< face > > &decomposedFaces, OFstream &os) const
Main driver to write the surface mesh geometry.
Definition: nastranSurfaceWriter.C:288
Foam::NamedEnum< writeFormat, 3 >
Foam::nastranSurfaceWriter::fieldMap_
HashTable< dataFormat, word > fieldMap_
Mapping from field name to data format enumeration.
Definition: nastranSurfaceWriter.H:101
Foam::nastranSurfaceWriter::wfFree
@ wfFree
Definition: nastranSurfaceWriter.H:79
Foam::nastranSurfaceWriter::writeFaceValue
void writeFaceValue(const dataFormat &format, const Type &value, const label EID, Ostream &os) const
Write a face-based value.
Definition: nastranSurfaceWriterTemplates.C:62