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