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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::surfaceWriters::nastranWriter
29
30Description
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 | Reqd | Default
36 fields | Field pairs for PLOAD2/PLOAD4 | yes |
37 format | Nastran format (short/long/free) | no | long
38 scale | Output geometry scaling | no | 1
39 transform | Output coordinate transform | no |
40 fieldLevel | Subtract field level before scaling | no | empty dict
41 fieldScale | Output field scaling | no | empty dict
42 commonGeometry | use separate geometry files | no | false
43 \endtable
44
45 For example,
46 \verbatim
47 formatOptions
48 {
49 nastran
50 {
51 // OpenFOAM field name to NASTRAN load types
52 fields
53 (
54 (pMean PLOAD2)
55 (p PLOAD4)
56 );
57
58 format free; // format type
59
60 scale 1000; // [m] -> [mm]
61 fieldScale
62 {
63 "p.*" 0.01; // [Pa] -> [mbar]
64 }
65 }
66 }
67 \endverbatim
68
69 \section Output file locations
70
71 The \c rootdir normally corresponds to something like
72 \c postProcessing/<name>
73
74 \subsection Geometry
75 \verbatim
76 rootdir
77 `-- <time>
78 |-- surfaceName0.{nas}
79 `-- surfaceName1.{nas}
80 \endverbatim
81
82 \subsection Fields
83 \verbatim
84 rootdir
85 `-- <time>
86 `-- field0
87 | |-- surfaceName0.{bdf}
88 | `-- surfaceName1.{bdf}
89 `-- field1
90 |-- surfaceName0.{bdf}
91 `-- surfaceName1.{bdf}
92 \endverbatim
93
94Note
95 Output variable scaling does not apply to integer types such as Ids.
96 Field pairs default to PLOAD2 for scalars and PLOAD4 for vectors etc.
97
98SourceFiles
99 nastranSurfaceWriter.C
100 nastranSurfaceWriterImpl.C
101
102\*---------------------------------------------------------------------------*/
103
104#ifndef Foam_surfaceWriters_nastranWriter_H
105#define Foam_surfaceWriters_nastranWriter_H
106
107#include "surfaceWriter.H"
108#include "NASCore.H"
109#include "HashTable.H"
110
111// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112
113namespace Foam
114{
115namespace surfaceWriters
116{
117
118/*---------------------------------------------------------------------------*\
119 Class nastranWriter Declaration
120\*---------------------------------------------------------------------------*/
121
122class nastranWriter
123:
124 public surfaceWriter
125{
126public:
127
128 //- File field formats
130
131 //- Output load format
133
134
135private:
136
137 // Private Data
138
139 //- Field format (width and separator)
140 fieldFormat writeFormat_;
141
142 //- Mapping from field name to data format enumeration
143 HashTable<loadFormat> fieldMap_;
144
145 //- Use common geometry file
146 bool commonGeometry_;
147
148 //- Separator (used for free format)
149 word separator_;
150
151
152 // Private Member Functions
153
154 //- Write a coordinate
155 void writeCoord
156 (
157 Ostream& os,
158 const point& p,
159 const label pointId
160 ) const;
162 //- Write a face element (CTRIA3 or CQUAD4)
163 void writeFace
164 (
165 Ostream& os,
166 const word& faceType,
167 const labelUList& facePts,
168 const label elemId,
169 const label propId
170 ) const;
172 //- Write the surface mesh geometry, tracking face decomposition
173 // Includes SHELL/MAT information
174 //
175 // \param decompOffsets begin/end offsets (size+1) into decompFaces
176 // \param decompFaces Non tri/quad decomposed into triangles
177 void writeGeometry
178 (
179 Ostream& os,
180 const meshedSurf& surf,
181 labelList& decompOffsets,
182 DynamicList<face>& decompFaces
183 ) const;
184
185 //- Write the formatted keyword to the output stream
186 Ostream& writeKeyword
187 (
188 Ostream& os,
189 const word& keyword
190 ) const;
191
192 //- Write a formatted value to the output stream
193 template<class Type>
194 Ostream& writeValue(Ostream& os, const Type& value) const;
195
196 //- Write a face-based value
197 template<class Type>
198 Ostream& writeFaceValue
199 (
200 Ostream& os,
201 const loadFormat format,
202 const Type& value,
203 const label elemId
204 ) const;
205
206
207 //- Templated write operation
208 template<class Type>
209 fileName writeTemplate
210 (
211 const word& fieldName,
212 const Field<Type>& localValues
213 );
214
215
216public:
217
218 //- Declare type-name, virtual type (with debug switch)
219 TypeNameNoDebug("nastran");
220
221
222 // Constructors
223
224 //- Default construct. Default SHORT format
226
227 //- Construct with some output options. Default LONG format
228 explicit nastranWriter(const dictionary& options);
229
230 //- Construct from components
232 (
233 const meshedSurf& surf,
234 const fileName& outputPath,
235 bool parallel = Pstream::parRun(),
236 const dictionary& options = dictionary()
237 );
238
239 //- Construct from components
241 (
242 const pointField& points,
243 const faceList& faces,
244 const fileName& outputPath,
245 bool parallel = Pstream::parRun(),
246 const dictionary& options = dictionary()
247 );
248
249
250 //- Destructor
251 virtual ~nastranWriter() = default;
252
253
254 // Member Functions
255
256 //- Format uses faceIds as part of its output
257 virtual bool usesFaceIds() const // override
259 return true;
260 }
261
262 //- Write surface geometry to file.
263 virtual fileName write(); // override
264
271};
272
273
274// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275
276} // End namespace surfaceWriters
277} // End namespace Foam
278
279// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280
281#endif
282
283// ************************************************************************* //
writer writeGeometry()
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
Generic templated field type.
Definition: Field.H:82
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
fieldFormat
File field formats.
Definition: NASCore.H:64
loadFormat
Output load format.
Definition: NASCore.H:75
A class for handling file names.
Definition: fileName.H:76
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:50
Base class for surface writers.
A surface writer for the Nastran file format - both surface mesh and fields.
virtual ~nastranWriter()=default
Destructor.
Foam::fileFormats::NASCore::loadFormat loadFormat
Output load format.
declareSurfaceWriterWriteMethod(sphericalTensor)
TypeNameNoDebug("nastran")
Declare type-name, virtual type (with debug switch)
Foam::fileFormats::NASCore::fieldFormat fieldFormat
File field formats.
virtual bool usesFaceIds() const
Format uses faceIds as part of its output.
nastranWriter()
Default construct. Default SHORT format.
virtual fileName write()
Write surface geometry to file.
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
Namespace for OpenFOAM.
vector point
Point is a vector.
Definition: point.H:43
word format(conversionProperties.get< word >("format"))
#define declareSurfaceWriterWriteMethod(Type)
#define TypeNameNoDebug(TypeNameString)
Declare a ClassNameNoDebug() with extra virtual type info.
Definition: typeInfo.H:68