ABAQUSCore.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) 2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::fileFormats::ABAQUSCore
28 
29 Description
30  Core routines used when reading/writing ABAQUS files.
31 
32  Face mappings for abaqus deduced from libmesh internals
33 
34  Tet4 cells
35  \table
36  Face | OpenFOAM | libmesh | abaqus | starcd
37  (1 2 3) | 0 | 2 | 2 | 5
38  (0 3 2) | 1 | 3 | 3 | 4
39  (0 1 3) | 2 | 1 | 1 | 2
40  (0 2 1) | 3 | 0 | 0 | 0
41  \endtable
42 
43  Pyr5 cells
44  \table
45  Face | OpenFOAM | libmesh | abaqus | starcd
46  (0 3 2 1) | 0 | 4 | n/a | 0
47  (0 4 3) | 1 | 3 | n/a | 4
48  (3 4 2) | 2 | 2 | n/a | 3
49  (1 2 4) | 3 | 1 | n/a | 5
50  (0 1 4) | 4 | 0 | n/a | 2
51  \endtable
52 
53  Prism6 cells
54  \table
55  Face | OpenFOAM | libmesh | abaqus | starcd
56  (0 2 1) | 0 | 0 | 0 | 0
57  (3 4 5) | 1 | 4 | 1 | 1
58  (0 3 5 2) | 2 | 3 | 4 | 4
59  (1 2 5 4) | 3 | 2 | 3 | 5
60  (0 1 4 3) | 4 | 1 | 2 | 2
61  \endtable
62 
63  Hex8 cells
64  \table
65  Face | OpenFOAM | libmesh | abaqus | starcd
66  (0 4 7 3) | 0 | 4 | 5 | 4
67  (1 2 6 5) | 1 | 2 | 3 | 5
68  (0 1 5 4) | 2 | 1 | 2 | 2
69  (3 7 6 2) | 3 | 3 | 4 | 3
70  (0 3 2 1) | 4 | 0 | 0 | 0
71  (4 5 6 7) | 5 | 5 | 1 | 1
72  \endtable
73 
74 SourceFiles
75  ABAQUSCore.C
76 
77 \*---------------------------------------------------------------------------*/
78 
79 #ifndef ABAQUSCore_H
80 #define ABAQUSCore_H
81 
82 #include "Fstream.H"
83 #include "Enum.H"
84 #include "Map.H"
85 #include "face.H"
86 #include "point.H"
87 #include "DynamicList.H"
88 
89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90 
91 namespace Foam
92 {
93 namespace fileFormats
94 {
95 
96 /*---------------------------------------------------------------------------*\
97  Class fileFormats::ABAQUSCore Declaration
98 \*---------------------------------------------------------------------------*/
99 
100 class ABAQUSCore
101 {
102 public:
103 
104  // Public Data, Declarations
105 
106  //- Shape-Type - the values are for internal use only!
107  enum shapeType : uint8_t
108  {
109  abaqusUnknownShape = 0,
110  abaqusTria = 0x03,
111  abaqusQuad = 0x04,
112  abaqusTet = 0x84,
113  abaqusPyr = 0x85,
114  abaqusPrism = 0x86,
115  abaqusHex = 0x88
116  };
117 
118 
119  // Public Functions
120 
121  //- Classify named element type (eg, S4R) to known/supported
122  //- element types.
123  // The input string must be Uppercase!
124  static shapeType getElementType(const std::string& elemTypeName);
125 
126  //- The number of points associated with the element type
127  inline static int nPoints(shapeType tag)
128  {
129  return (tag & 0x3F);
130  }
131 
132  //- True if element type is not unknown/invalid
133  inline static bool isValidType(shapeType tag)
134  {
135  return tag;
136  }
137 
138  //- True if element type is a 2D shell
139  inline static bool isShellType(shapeType tag)
140  {
141  return (tag & 0x07) && !(tag & 0x80);
142  }
143 
144  //- True if element type is a 3D element
145  inline static bool isSolidType(shapeType tag)
146  {
147  return (tag & 0x80);
148  }
149 
150  //- Is a combined (synthetic) face Id?
151  inline static bool isEncodedSolidId(const label combinedId)
152  {
153  return (combinedId < 0);
154  }
155 
156  //- Combine solid element Id and side Id into synthetic face Id
157  inline static label encodeSolidId(const label id, const label side)
158  {
159  return -(10 * id + side);
160  }
161 
162  //- Entangle solid element id from synthetic face Id
163  inline static label decodeSolidElementId(const label combinedId)
164  {
165  return
166  (
167  isEncodedSolidId(combinedId)
168  ? (-combinedId / 10)
169  : combinedId
170  );
171  }
172 
173  //- Entangle solid side id from synthetic face Id
174  //- Synthesize faceId from solid element Id and sideId
175  inline static label decodeSolidSideNum(const label combinedId)
176  {
177  return
178  (
179  isEncodedSolidId(combinedId)
180  ? (-combinedId % 10)
181  : 0
182  );
183  }
184 
185 
186 protected:
187 
188  // Protected Member Functions
189 
190  //- From 1-based to 0-based
191  inline static void renumber0_elemId(label& elemId)
192  {
193  if (isEncodedSolidId(elemId))
194  {
195  // Eg,
196  // 1-based (solid 4, side 2) is -42
197  // 0-based (solid 3, side 2) is -32
198  elemId += 10;
199  }
200  else
201  {
202  --elemId;
203  }
204  }
205 
206  //- Face addressing from ABAQUS faces to OpenFOAM faces.
207  // For hex, prism, tet primitive shapes.
208  static const Map<labelList>& abaqusToFoamFaceAddr();
209 
210 
211  // Protected Classes
212 
213  //- Raw reader structure
214  struct readHelper
215  {
216  // General
217 
218  //- Additional verbosity
219  bool verbose_;
220 
221 
222  // Point Handling
223 
224  //- Locations of the points (nodes)
225  DynamicList<point> points_;
226 
227  //- The 1-based abaqus Id for the point (node)
228  DynamicList<label> nodeIds_;
229 
230 
231  // Element Handling
232 
233  //- The element connectivity.
234  // Initially uses the abaqus node Id (1-based)
235  // but remapped to 0-based compact form later.
236  DynamicList<labelList> connectivity_;
237 
238  //- The 1-based abaqus Id for the element
239  DynamicList<label> elemIds_;
240 
241  //- The element types
242  DynamicList<ABAQUSCore::shapeType> elemTypes_;
243 
244  //- The element set ids
246 
247  //- Mapping of elem set names
249 
250 
251  // Constructos
252 
253  //- Default construct without verbosity
254  explicit readHelper(bool verbosity = false)
255  :
256  verbose_(verbosity)
257  {}
258 
259 
260  // Member Functions
261 
262  //- Clear out contents.
263  void clear()
264  {
265  points_.clear();
266  nodeIds_.clear();
267 
268  connectivity_.clear();
269  elemTypes_.clear();
270 
271  elemIds_.clear();
272  elsetIds_.clear();
273  elsetMap_.clear();
274  }
275 
276  //- Add a new element set name or return an existing one.
277  // Case-insensitive.
278  label addNewElset(const std::string& setName);
279 
280 
281  //- Read an abaqus input file
282  void read(ISstream& is);
283 
284  //- Read entries within a "*Nodes" section.
285  // Appends to points and nodeIds lists.
286  //
287  // \return the number of points read
288  label readPoints(ISstream& is);
289 
290  //- Read entries within an "*Element" section.
291  // If the shape is known/supported, appends to
292  // connectivity, elemType, elemIds lists.
293  //
294  // \return the number of elements read
295  label readElements
296  (
297  ISstream& is,
298  const ABAQUSCore::shapeType shape,
299  const label setId = 0
300  );
301 
302  //- Read elements within an "*Surface" section.
303  // If the shape is known/supported, appends to
304  // connectivity, elemType, elemIds lists.
305  //
306  // \return the number of elements read
307  label readSurfaceElements
308  (
309  ISstream& is,
310  const label setId = 0
311  );
312 
313 
314  //- Remove non-shell elements and compact the points
315  void purge_solids();
316 
317  //- Compact unused points and relabel connectivity
319 
320  //- Renumber elements from 1-based to 0-based
321  void renumber_elements_1to0();
322  };
323 
324 
325  // Constructors
326 
327  //- Default construct
328  ABAQUSCore() = default;
329 
330 
331 public:
332 
333  // Public Member Functions
334 
335  //- Write '*NODE' header and entries to file, optionally with scaling
336  // This is a no-op for an empty list
337  static void writePoints
338  (
339  Ostream& os,
340  const UList<point>& points,
341  const scalar scaleFactor = 1.0
342  );
343 
344  //- Calculate face decomposition for non tri/quad faces
345  //
346  // \param points the surface points
347  // \param faces the surface faces
348  // \param decompOffsets begin/end offsets (size+1) into decompFaces
349  // \param decompFaces List of non-tri/quad decomposed into triangles
350  //
351  // \return number of decomposed faces
352  static label faceDecomposition
353  (
354  const UList<point>& points,
355  const UList<face>& faces,
356  labelList& decompOffsets,
357  DynamicList<face>& decompFaces
358  );
359 };
360 
361 
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 
364 } // End namespace fileFormats
365 } // End namespace Foam
366 
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
368 
369 #endif
370 
371 // ************************************************************************* //
Foam::fileFormats::ABAQUSCore::readHelper::readElements
label readElements(ISstream &is, const ABAQUSCore::shapeType shape, const label setId=0)
Read entries within an "*Element" section.
Definition: ABAQUSCore.C:353
Foam::fileFormats::ABAQUSCore::readHelper::addNewElset
label addNewElset(const std::string &setName)
Add a new element set name or return an existing one.
Definition: ABAQUSCore.C:268
Foam::fileFormats::ABAQUSCore::readHelper::verbose_
bool verbose_
Additional verbosity.
Definition: ABAQUSCore.H:362
Foam::fileFormats::ABAQUSCore::abaqusQuad
Definition: ABAQUSCore.H:254
Foam::fileFormats::ABAQUSCore::isEncodedSolidId
static bool isEncodedSolidId(const label combinedId)
Is a combined (synthetic) face Id?
Definition: ABAQUSCore.H:294
Foam::DynamicList< point >
point.H
Foam::fileFormats::ABAQUSCore::abaqusPyr
Definition: ABAQUSCore.H:256
Foam::fileFormats::ABAQUSCore::readHelper::elemIds_
DynamicList< label > elemIds_
The 1-based abaqus Id for the element.
Definition: ABAQUSCore.H:382
face.H
Foam::fileFormats::ABAQUSCore::readHelper::clear
void clear()
Clear out contents.
Definition: ABAQUSCore.H:406
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::fileFormats::ABAQUSCore::readHelper::read
void read(ISstream &is)
Read an abaqus input file.
Definition: ABAQUSCore.C:531
Foam::fileFormats::ABAQUSCore::isValidType
static bool isValidType(shapeType tag)
True if element type is not unknown/invalid.
Definition: ABAQUSCore.H:276
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::fileFormats::ABAQUSCore
Core routines used when reading/writing ABAQUS files.
Definition: ABAQUSCore.H:243
Foam::fileFormats::ABAQUSCore::readHelper::elsetMap_
HashTable< label, string > elsetMap_
Mapping of elem set names.
Definition: ABAQUSCore.H:391
Foam::DynamicList::clear
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
Foam::fileFormats::ABAQUSCore::encodeSolidId
static label encodeSolidId(const label id, const label side)
Combine solid element Id and side Id into synthetic face Id.
Definition: ABAQUSCore.H:300
Foam::fileFormats::ABAQUSCore::readHelper::compact_nodes
void compact_nodes()
Compact unused points and relabel connectivity.
Definition: ABAQUSCore.C:684
Map.H
Foam::fileFormats::ABAQUSCore::getElementType
static shapeType getElementType(const std::string &elemTypeName)
Definition: ABAQUSCore.C:204
Foam::fileFormats::ABAQUSCore::readHelper::readPoints
label readPoints(ISstream &is)
Read entries within a "*Nodes" section.
Definition: ABAQUSCore.C:316
Foam::fileFormats::ABAQUSCore::readHelper
Raw reader structure.
Definition: ABAQUSCore.H:357
Foam::fileFormats::ABAQUSCore::decodeSolidSideNum
static label decodeSolidSideNum(const label combinedId)
Definition: ABAQUSCore.H:318
Foam::fileFormats::ABAQUSCore::abaqusPrism
Definition: ABAQUSCore.H:257
Foam::fileFormats::ABAQUSCore::nPoints
static int nPoints(shapeType tag)
The number of points associated with the element type.
Definition: ABAQUSCore.H:270
Foam::fileFormats::ABAQUSCore::faceDecomposition
static label faceDecomposition(const UList< point > &points, const UList< face > &faces, labelList &decompOffsets, DynamicList< face > &decompFaces)
Calculate face decomposition for non tri/quad faces.
Definition: ABAQUSCore.C:823
Foam::fileFormats::ABAQUSCore::abaqusUnknownShape
Definition: ABAQUSCore.H:252
Foam::fileFormats::ABAQUSCore::abaqusToFoamFaceAddr
static const Map< labelList > & abaqusToFoamFaceAddr()
Face addressing from ABAQUS faces to OpenFOAM faces.
Definition: ABAQUSCore.C:190
Foam::fileFormats::ABAQUSCore::readHelper::points_
DynamicList< point > points_
Locations of the points (nodes)
Definition: ABAQUSCore.H:368
Foam::fileFormats::ABAQUSCore::decodeSolidElementId
static label decodeSolidElementId(const label combinedId)
Entangle solid element id from synthetic face Id.
Definition: ABAQUSCore.H:306
os
OBJstream os(runTime.globalPath()/outputName)
Foam::fileFormats::ABAQUSCore::ABAQUSCore
ABAQUSCore()=default
Default construct.
Foam::fileFormats::ABAQUSCore::abaqusHex
Definition: ABAQUSCore.H:258
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fileFormats::ABAQUSCore::readHelper::purge_solids
void purge_solids()
Remove non-shell elements and compact the points.
Definition: ABAQUSCore.C:658
Foam::fileFormats::ABAQUSCore::abaqusTet
Definition: ABAQUSCore.H:255
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::fileFormats::ABAQUSCore::readHelper::renumber_elements_1to0
void renumber_elements_1to0()
Renumber elements from 1-based to 0-based.
Definition: ABAQUSCore.C:778
Foam::fileFormats::ABAQUSCore::readHelper::elsetIds_
DynamicList< label > elsetIds_
The element set ids.
Definition: ABAQUSCore.H:388
Fstream.H
Foam::List< label >
Foam::fileFormats::ABAQUSCore::shapeType
shapeType
Shape-Type - the values are for internal use only!
Definition: ABAQUSCore.H:250
Foam::fileFormats::ABAQUSCore::isShellType
static bool isShellType(shapeType tag)
True if element type is a 2D shell.
Definition: ABAQUSCore.H:282
Foam::fileFormats::ABAQUSCore::readHelper::readHelper
readHelper(bool verbosity=false)
Default construct without verbosity.
Definition: ABAQUSCore.H:397
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::fileFormats::ABAQUSCore::readHelper::nodeIds_
DynamicList< label > nodeIds_
The 1-based abaqus Id for the point (node)
Definition: ABAQUSCore.H:371
Foam::fileFormats::ABAQUSCore::readHelper::readSurfaceElements
label readSurfaceElements(ISstream &is, const label setId=0)
Read elements within an "*Surface" section.
Definition: ABAQUSCore.C:408
Foam::fileFormats::ABAQUSCore::readHelper::connectivity_
DynamicList< labelList > connectivity_
The element connectivity.
Definition: ABAQUSCore.H:379
DynamicList.H
Foam::fileFormats::ABAQUSCore::writePoints
static void writePoints(Ostream &os, const UList< point > &points, const scalar scaleFactor=1.0)
Write '*NODE' header and entries to file, optionally with scaling.
Definition: ABAQUSCore.C:788
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::fileFormats::ABAQUSCore::renumber0_elemId
static void renumber0_elemId(label &elemId)
From 1-based to 0-based.
Definition: ABAQUSCore.H:334
Foam::fileFormats::ABAQUSCore::abaqusTria
Definition: ABAQUSCore.H:253
Foam::fileFormats::ABAQUSCore::readHelper::elemTypes_
DynamicList< ABAQUSCore::shapeType > elemTypes_
The element types.
Definition: ABAQUSCore.H:385
Foam::fileFormats::ABAQUSCore::isSolidType
static bool isSolidType(shapeType tag)
True if element type is a 3D element.
Definition: ABAQUSCore.H:288
Enum.H