nastranSurfaceWriter.H
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) 2012-2018 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 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 ((pMean PLOAD2));
36  // Optional scale
37  scale 2.0;
38  // Optional format
39  format free; // short, long, free
40  }
41  };
42 
43 SourceFiles
44  nastranSurfaceWriter.C
45  nastranSurfaceWriterTemplates.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef nastranSurfaceWriter_H
50 #define nastranSurfaceWriter_H
51 
52 #include "surfaceWriter.H"
53 #include "NamedEnum.H"
54 #include "OFstream.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class nastranSurfaceWriter Declaration
63 \*---------------------------------------------------------------------------*/
64 
66 :
67  public surfaceWriter
68 {
69 public:
70 
71  enum writeFormat
72  {
75  wfFree
76  };
77 
79 
80 
81 private:
82 
83  // Private data
84 
85  //- Write option
86  writeFormat writeFormat_;
87 
88  //- Map of OpenFOAM field name vs nastran field name
89  HashTable<word> fieldMap_;
90 
91  //- Scale to apply to values (default = 1.0)
92  scalar scale_;
93 
94 
95  // Private Member Functions
96 
97  //- Initialise the output stream format params
98  void formatOS(OFstream& os) const;
99 
100  //- Write a co-ordinate
101  void writeCoord
102  (
103  const point& p,
104  const label pointi,
105  OFstream& os
106  ) const;
107 
108  //- Write a face element (CTRIA3 or CQUAD4)
109  void writeFace
110  (
111  const word& faceType,
112  const labelList& facePts,
113  label& nFace,
114  OFstream& os
115  ) const;
116 
117  //- Main driver to write the surface mesh geometry
118  void writeGeometry
119  (
120  const pointField& points,
121  const faceList& faces,
122  List<DynamicList<face>>& decomposedFaces,
123  OFstream& os
124  ) const;
125 
126  //- Write a face-based value
127  template<class Type>
128  void writeFaceValue
129  (
130  const word& nasFieldName,
131  const Type& value,
132  const label EID,
133  OFstream& os
134  ) const;
135 
136  //- Templated write operation
137  template<class Type>
138  void writeTemplate
139  (
140  const fileName& outputDir,
141  const fileName& surfaceName,
142  const pointField& points,
143  const faceList& faces,
144  const word& fieldName,
145  const Field<Type>& values,
146  const bool isNodeValues,
147  const bool verbose
148  ) const;
149 
150 
151 public:
152 
153  //- Runtime type information
154  TypeName("nastran");
155 
156 
157  // Constructors
158 
159  //- Construct null
161 
162  //- Construct with some output options
163  nastranSurfaceWriter(const dictionary& options);
164 
165 
166  //- Destructor
167  virtual ~nastranSurfaceWriter();
168 
169 
170  // Member Functions
171 
172  //- True if the surface format supports geometry in a separate file.
173  // False if geometry and field must be in a single file
174  virtual bool separateGeometry()
175  {
176  return false;
177  }
178 
179  //- Write single surface geometry to file.
180  virtual void write
181  (
182  const fileName& outputDir,
183  const fileName& surfaceName,
184  const pointField& points,
185  const faceList& faces,
186  const bool verbose = false
187  ) const;
188 
189  //- Write scalarField for a single surface to file.
190  // One value per face or vertex (isNodeValues = true)
191  virtual void write
192  (
193  const fileName& outputDir,
194  const fileName& surfaceName,
195  const pointField& points,
196  const faceList& faces,
197  const word& fieldName,
198  const Field<scalar>& values,
199  const bool isNodeValues,
200  const bool verbose = false
201  ) const;
202 
203  //- Write vectorField for a single surface to file.
204  // One value per face or vertex (isNodeValues = true)
205  virtual void write
206  (
207  const fileName& outputDir,
208  const fileName& surfaceName,
209  const pointField& points,
210  const faceList& faces,
211  const word& fieldName,
212  const Field<vector>& values,
213  const bool isNodeValues,
214  const bool verbose = false
215  ) const;
216 
217  //- Write sphericalTensorField for a single surface to file.
218  // One value per face or vertex (isNodeValues = true)
219  virtual void write
220  (
221  const fileName& outputDir,
222  const fileName& surfaceName,
223  const pointField& points,
224  const faceList& faces,
225  const word& fieldName,
226  const Field<sphericalTensor>& values,
227  const bool isNodeValues,
228  const bool verbose = false
229  ) const;
230 
231  //- Write symmTensorField for a single surface to file.
232  // One value per face or vertex (isNodeValues = true)
233  virtual void write
234  (
235  const fileName& outputDir,
236  const fileName& surfaceName,
237  const pointField& points,
238  const faceList& faces,
239  const word& fieldName,
240  const Field<symmTensor>& values,
241  const bool isNodeValues,
242  const bool verbose = false
243  ) const;
244 
245  //- Write tensorField for a single surface to file.
246  // One value per face or vertex (isNodeValues = true)
247  virtual void write
248  (
249  const fileName& outputDir,
250  const fileName& surfaceName,
251  const pointField& points,
252  const faceList& faces,
253  const word& fieldName,
254  const Field<tensor>& values,
255  const bool isNodeValues,
256  const bool verbose = false
257  ) const;
258 };
259 
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 } // End namespace Foam
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 #ifdef NoRepository
269 #endif
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #endif
274 
275 // ************************************************************************* //
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
A class for handling file names.
Definition: fileName.H:69
A surface writer for the Nastran file format - both surface mesh and fields.
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
nastranSurfaceWriter()
Construct null.
virtual ~nastranSurfaceWriter()
Destructor.
TypeName("nastran")
Runtime type information.
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.
const pointField & points
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
A class for handling words, derived from string.
Definition: word.H:59
An STL-conforming hash table.
Definition: HashTable.H:62
virtual bool separateGeometry()
True if the surface format supports geometry in a separate file.
static const NamedEnum< writeFormat, 3 > writeFormatNames_
Base class for surface writers.
Definition: surfaceWriter.H:54
volScalarField & p
Namespace for OpenFOAM.