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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::surfaceWriters::nastranWriter
29 
30 Description
31  A surface writer for the Nastran file format - both surface mesh and fields
32 
33  The formatOptions for nastran:
34  \table
35  Property | Description | Required | Default
36  fields | field pairs for PLOAD2/PLOAD4 | yes |
37  format | short / long / free | no | long
38  scale | output geometry scaling | no | 1
39  fieldScale | output field scaling (dictionary) | no | empty
40  commonGeometry | use separate geometry files | no | false
41  \endtable
42 
43  For example,
44  \verbatim
45  formatOptions
46  {
47  nastran
48  {
49  // OpenFOAM field name to NASTRAN load types
50  fields
51  (
52  (pMean PLOAD2)
53  (p PLOAD4)
54  );
55 
56  format free; // format type
57 
58  scale 1000; // [m] -> [mm]
59  fieldScale
60  {
61  "p.*" 0.01; // [Pa] -> [mbar]
62  }
63  }
64  }
65  \endverbatim
66 
67  \section Output file locations
68 
69  The \c rootdir normally corresponds to something like
70  \c postProcessing/<name>
71 
72  \subsection Geometry
73  \verbatim
74  rootdir
75  `-- <time>
76  |-- surfaceName0.{nas}
77  `-- surfaceName1.{nas}
78  \endverbatim
79 
80  \subsection Fields
81  \verbatim
82  rootdir
83  `-- <time>
84  `-- field0
85  | |-- surfaceName0.{bdf}
86  | `-- surfaceName1.{bdf}
87  `-- field1
88  |-- surfaceName0.{bdf}
89  `-- surfaceName1.{bdf}
90  \endverbatim
91 
92 Note
93  Output variable scaling does not apply to integer types such as Ids.
94  Field pairs default to PLOAD2 for scalars and PLOAD4 for vectors etc.
95 
96 SourceFiles
97  nastranSurfaceWriter.C
98  nastranSurfaceWriterImpl.C
99 
100 \*---------------------------------------------------------------------------*/
101 
102 #ifndef nastranSurfaceWriter_H
103 #define nastranSurfaceWriter_H
104 
105 #include "surfaceWriter.H"
106 #include "NASCore.H"
107 #include "HashTable.H"
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 namespace Foam
112 {
113 namespace surfaceWriters
114 {
115 
116 /*---------------------------------------------------------------------------*\
117  Class nastranWriter Declaration
118 \*---------------------------------------------------------------------------*/
119 
120 class nastranWriter
121 :
122  public surfaceWriter
123 {
124 public:
125 
126  //- File field formats
128 
129  //- Output load format
131 
132 
133 private:
134 
135  // Private Data
136 
137  //- Field format (width and separator)
138  fieldFormat writeFormat_;
139 
140  //- Mapping from field name to data format enumeration
141  HashTable<loadFormat> fieldMap_;
142 
143  //- Use common geometry file
144  bool commonGeometry_;
145 
146  //- Output geometry scaling
147  const scalar geometryScale_;
148 
149  //- Output field scaling
150  const dictionary fieldScale_;
151 
152  //- Separator used for free format
153  word separator_;
154 
155 
156  // Private Member Functions
157 
158  //- Write a coordinate
159  void writeCoord
160  (
161  Ostream& os,
162  const point& pt,
163  const label pointI
164  ) const;
165 
166  //- Write a face element (CTRIA3 or CQUAD4)
167  void writeFace
168  (
169  Ostream& os,
170  const word& faceType,
171  const labelUList& facePts,
172  const label elemId,
173  const label propId
174  ) const;
175 
176  //- Write the surface mesh geometry, tracking face decomposition
177  // Includes SHELL/MAT information
178  //
179  // \param decompOffsets begin/end offsets (size+1) into decompFaces
180  // \param decompFaces Non tri/quad decomposed into triangles
181  void writeGeometry
182  (
183  Ostream& os,
184  const meshedSurf& surf,
185  labelList& decompOffsets,
186  DynamicList<face>& decompFaces
187  ) const;
188 
189  //- Write the formatted keyword to the output stream
190  Ostream& writeKeyword
191  (
192  Ostream& os,
193  const word& keyword
194  ) const;
195 
196  //- Write a formatted value to the output stream
197  template<class Type>
198  Ostream& writeValue(Ostream& os, const Type& value) const;
199 
200  //- Write a face-based value
201  template<class Type>
202  Ostream& writeFaceValue
203  (
204  Ostream& os,
205  const loadFormat format,
206  const Type& value,
207  const label elemId
208  ) const;
209 
210 
211  //- Templated write operation
212  template<class Type>
213  fileName writeTemplate
214  (
215  const word& fieldName,
216  const Field<Type>& localValues
217  );
218 
219 
220 public:
221 
222  //- Declare type-name, virtual type (with debug switch)
223  TypeNameNoDebug("nastran");
224 
225 
226  // Constructors
227 
228  //- Default construct. Default SHORT format
229  nastranWriter();
230 
231  //- Construct with some output options. Default LONG format
232  explicit nastranWriter(const dictionary& options);
233 
234  //- Construct from components
236  (
237  const meshedSurf& surf,
238  const fileName& outputPath,
239  bool parallel = Pstream::parRun(),
240  const dictionary& options = dictionary()
241  );
242 
243  //- Construct from components
245  (
246  const pointField& points,
247  const faceList& faces,
248  const fileName& outputPath,
249  bool parallel = Pstream::parRun(),
250  const dictionary& options = dictionary()
251  );
252 
253 
254  //- Destructor
255  virtual ~nastranWriter() = default;
256 
257 
258  // Member Functions
259 
260  //- Format uses faceIds as part of its output
261  virtual bool usesFaceIds() const // override
262  {
263  return true;
264  }
265 
266  //- Write surface geometry to file.
267  virtual fileName write(); // override
268 
275 };
276 
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 } // End namespace surfaceWriters
281 } // End namespace Foam
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
285 #endif
286 
287 // ************************************************************************* //
Foam::surfaceWriters::nastranWriter::usesFaceIds
virtual bool usesFaceIds() const
Format uses faceIds as part of its output.
Definition: nastranSurfaceWriter.H:290
Foam::Tensor< scalar >
Foam::SymmTensor< scalar >
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:114
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
HashTable.H
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::surfaceWriters::nastranWriter::declareSurfaceWriterWriteMethod
declareSurfaceWriterWriteMethod(label)
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
surfaceWriter.H
format
word format(conversionProperties.get< word >("format"))
Foam::surfaceWriters::nastranWriter::loadFormat
Foam::fileFormats::NASCore::loadFormat loadFormat
Output load format.
Definition: nastranSurfaceWriter.H:159
Foam::Field
Generic templated field type.
Definition: Field.H:63
NASCore.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SphericalTensor< scalar >
Foam::HashTable< loadFormat >
Foam::fileFormats::NASCore::loadFormat
loadFormat
Output load format.
Definition: NASCore.H:74
Foam::surfaceWriters::nastranWriter::~nastranWriter
virtual ~nastranWriter()=default
Destructor.
Foam::surfaceWriters::nastranWriter::write
virtual fileName write()
Write surface geometry to file.
Definition: nastranSurfaceWriter.C:438
Foam::Vector< scalar >
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< label >
Foam::UList< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::surfaceWriters::nastranWriter::TypeNameNoDebug
TypeNameNoDebug("nastran")
Declare type-name, virtual type (with debug switch)
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::surfaceWriters::nastranWriter
A surface writer for the Nastran file format - both surface mesh and fields.
Definition: nastranSurfaceWriter.H:149
Foam::surfaceWriters::nastranWriter::nastranWriter
nastranWriter()
Default construct. Default SHORT format.
Definition: nastranSurfaceWriter.C:354
Foam::fileFormats::NASCore::fieldFormat
fieldFormat
File field formats.
Definition: NASCore.H:63
Foam::surfaceWriters::nastranWriter::fieldFormat
Foam::fileFormats::NASCore::fieldFormat fieldFormat
File field formats.
Definition: nastranSurfaceWriter.H:156