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  \endtable
41 
42  For example,
43  \verbatim
44  formatOptions
45  {
46  nastran
47  {
48  // OpenFOAM field name to NASTRAN field name
49  fields
50  (
51  (pMean PLOAD2)
52  (p PLOAD4)
53  );
54 
55  format free; // format type
56 
57  scale 1000; // [m] -> [mm]
58  fieldScale
59  {
60  "p.*" 0.01; // [Pa] -> [mbar]
61  }
62  }
63  }
64  \endverbatim
65 
66  \heading Output file locations
67 
68  The \c rootdir normally corresponds to something like
69  \c postProcessing/<name>
70 
71  \subheading Geometry
72  \verbatim
73  rootdir
74  `-- timeName
75  |-- surfaceName0.{nas}
76  `-- surfaceName1.{nas}
77  \endverbatim
78 
79  \subheading Fields
80  \verbatim
81  rootdir
82  `-- timeName
83  `-- field0
84  | |-- surfaceName0.{nas}
85  | `-- surfaceName1.{nas}
86  `-- field1
87  |-- surfaceName0.{nas}
88  `-- surfaceName1.{nas}
89  \endverbatim
90 
91 Note
92  Output variable scaling does not apply to integer types such as Ids.
93 
94 SourceFiles
95  nastranSurfaceWriter.C
96  nastranSurfaceWriterImpl.C
97 
98 \*---------------------------------------------------------------------------*/
99 
100 #ifndef nastranSurfaceWriter_H
101 #define nastranSurfaceWriter_H
102 
103 #include "surfaceWriter.H"
104 #include "NASCore.H"
105 #include "HashTable.H"
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 namespace Foam
110 {
111 namespace surfaceWriters
112 {
113 
114 /*---------------------------------------------------------------------------*\
115  Class nastranWriter Declaration
116 \*---------------------------------------------------------------------------*/
117 
118 class nastranWriter
119 :
120  public surfaceWriter
121 {
122 public:
123 
124  //- File field formats
126 
127  //- Output load format
129 
130 
131 private:
132 
133  // Private Data
134 
135  //- Field format (width and separator)
136  fieldFormat writeFormat_;
137 
138  //- Mapping from field name to data format enumeration
139  HashTable<loadFormat> fieldMap_;
140 
141  //- Output geometry scaling
142  const scalar geometryScale_;
143 
144  //- Output field scaling
145  const dictionary fieldScale_;
146 
147  //- Separator used for free format
148  word separator_;
149 
150 
151  // Private Member Functions
152 
153  //- Write a coordinate
154  void writeCoord
155  (
156  Ostream& os,
157  const point& pt,
158  const label pointI
159  ) const;
160 
161  //- Write a face element (CTRIA3 or CQUAD4)
162  void writeFace
163  (
164  Ostream& os,
165  const word& faceType,
166  const labelUList& facePts,
167  const label elemId,
168  const label propId
169  ) const;
170 
171  //- Write the surface mesh geometry, tracking face decomposition
172  //
173  // \param decompOffsets begin/end offsets (size+1) into decompFaces
174  // \param decompFaces Non tri/quad decomposed into triangles
175  void writeGeometry
176  (
177  Ostream& os,
178  const meshedSurf& surf,
179  labelList& decompOffsets,
180  DynamicList<face>& decompFaces
181  ) const;
182 
183  //- Write the formatted keyword to the output stream
184  Ostream& writeKeyword
185  (
186  Ostream& os,
187  const word& keyword
188  ) const;
189 
190  //- Write the footer information
191  Ostream& writeFooter(Ostream& os, const meshedSurf& surf) const;
192 
193  //- Write a formatted value to the output stream
194  template<class Type>
195  Ostream& writeValue(Ostream& os, const Type& value) const;
196 
197  //- Write a face-based value
198  template<class Type>
199  Ostream& writeFaceValue
200  (
201  Ostream& os,
202  const loadFormat format,
203  const Type& value,
204  const label elemId
205  ) const;
206 
207 
208  //- Templated write operation
209  template<class Type>
210  fileName writeTemplate
211  (
212  const word& fieldName,
213  const Field<Type>& localValues
214  );
215 
216 
217 public:
218 
219  //- Declare type-name, virtual type (with debug switch)
220  TypeNameNoDebug("nastran");
221 
222 
223  // Constructors
224 
225  //- Default construct. Default SHORT format
226  nastranWriter();
227 
228  //- Construct with some output options. Default LONG format
229  explicit nastranWriter(const dictionary& options);
230 
231  //- Construct from components
233  (
234  const meshedSurf& surf,
235  const fileName& outputPath,
236  bool parallel = Pstream::parRun(),
237  const dictionary& options = dictionary()
238  );
239 
240  //- Construct from components
242  (
243  const pointField& points,
244  const faceList& faces,
245  const fileName& outputPath,
246  bool parallel = Pstream::parRun(),
247  const dictionary& options = dictionary()
248  );
249 
250 
251  //- Destructor
252  virtual ~nastranWriter() = default;
253 
254 
255  // Member Functions
256 
257  //- Write surface geometry to file.
258  virtual fileName write(); // override
259 
266 };
267 
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 } // End namespace surfaceWriters
272 } // End namespace Foam
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 #endif
277 
278 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::SymmTensor< scalar >
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:111
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
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::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:415
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:152
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:121
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:437
Foam::Vector< scalar >
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:142
Foam::surfaceWriters::nastranWriter::nastranWriter
nastranWriter()
Default construct. Default SHORT format.
Definition: nastranSurfaceWriter.C:355
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:149