libMesh
dyna_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_DYNA_IO_H
21 #define LIBMESH_DYNA_IO_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/mesh_input.h"
26 #include "libmesh/mesh_output.h"
27 
28 // C++ includes
29 #include <algorithm>
30 #include <cstddef>
31 #include <map>
32 #include <vector>
33 
34 namespace libMesh
35 {
36 
37 // Forward declarations
38 class MeshBase;
39 
40 
41 
52 class DynaIO : public MeshInput<MeshBase>
53 {
54 public:
55 
66  explicit
67  DynaIO (MeshBase & mesh,
68  bool keep_spline_nodes = true);
69 
91  virtual void read (const std::string & name) override;
92 
98  void add_spline_constraints(DofMap & dof_map,
99  unsigned int sys_num,
100  unsigned int var_num);
101 
102 #ifdef LIBMESH_ENABLE_DEPRECATED
103 
110  void clear_spline_nodes();
111 #endif // LIBMESH_ENABLE_DEPRECATED
112 
116  typedef int32_t dyna_int_type;
117 
126  {
127  ElementDefinition(ElemType type_in,
128  dyna_int_type dyna_type_in,
129  dyna_int_type dim_in,
130  dyna_int_type p_in);
131 
132  ElementDefinition(ElemType type_in,
133  dyna_int_type dyna_type_in,
134  dyna_int_type dim_in,
135  dyna_int_type p_in,
136  std::vector<unsigned int> && nodes_in);
137 
142  std::vector<unsigned int> nodes;
143  };
144 
145 
150  static const ElementDefinition &
151  find_elem_definition(dyna_int_type dyna_elem, int dim, int p);
152 
153  static const ElementDefinition &
154  find_elem_definition(ElemType libmesh_elem, int dim, int p);
155 
156 private:
157  // Keep track of spline node indexing, so as to enable adding
158  // constraint rows easily later.
159  std::vector<Node *> spline_node_ptrs;
160  std::unordered_map<Node *, Elem *> spline_nodeelem_ptrs;
161 
166 
172  void read_mesh (std::istream & in);
173 
177  static const int max_ints_per_line = 10;
178 
182  typedef double dyna_fp_type;
183 
187  static const int max_fps_per_line = 5;
188 
193  struct ElementMaps
194  {
195  // Helper function to add a (key, value) pair to both maps
196  void add_def(const ElementDefinition & eledef)
197  {
198  out.emplace(eledef.type, eledef);
199  in.emplace(std::make_tuple(eledef.dyna_type, eledef.dim, eledef.p), eledef);
200  }
201 
202  std::map<ElemType, ElementDefinition> out;
203 
204  typedef std::tuple<dyna_int_type, dyna_int_type, dyna_int_type> Key;
205 
206  std::map<Key, ElementDefinition> in;
207  };
208 
214 
220 };
221 
222 
223 } // namespace libMesh
224 
225 #endif // LIBMESH_DYNA_IO_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
ElemType
Defines an enum for geometric element types.
virtual void read(const std::string &name) override
Reads in a mesh in the Dyna format from the ASCII file given by name.
Definition: dyna_io.C:139
std::vector< Node * > spline_node_ptrs
Definition: dyna_io.h:159
int32_t dyna_int_type
The integer type DYNA uses.
Definition: dyna_io.h:116
Reading and writing meshes in (a subset of) LS-DYNA format.
Definition: dyna_io.h:52
double dyna_fp_type
The floating-point type DYNA uses.
Definition: dyna_io.h:182
unsigned int dim
void read_mesh(std::istream &in)
Implementation of the read() function.
Definition: dyna_io.C:177
Defines mapping from libMesh element types to LS-DYNA element types or vice-versa.
Definition: dyna_io.h:125
void clear_spline_nodes()
Removes any spline nodes (both NodeElem and Node), leaving only the FE mesh generated from those spli...
Definition: dyna_io.C:744
void add_def(const ElementDefinition &eledef)
Definition: dyna_io.h:196
bool _keep_spline_nodes
Whether to keep or eventually discard spline nodes.
Definition: dyna_io.h:165
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:75
void add_spline_constraints(DofMap &dof_map, unsigned int sys_num, unsigned int var_num)
Constrains finite element degrees of freedom in terms of spline degrees of freedom by adding user-def...
Definition: dyna_io.C:736
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:179
static const ElementDefinition & find_elem_definition(dyna_int_type dyna_elem, int dim, int p)
Finds the ElementDefinition corresponding to a particular element type.
Definition: dyna_io.C:755
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:57
std::map< ElemType, ElementDefinition > out
Definition: dyna_io.h:202
static ElementMaps build_element_maps()
A static function used to construct the _element_maps struct, statically.
Definition: dyna_io.C:53
static const int max_fps_per_line
How many can we find on a line?
Definition: dyna_io.h:187
DynaIO(MeshBase &mesh, bool keep_spline_nodes=true)
Constructor.
Definition: dyna_io.C:130
std::tuple< dyna_int_type, dyna_int_type, dyna_int_type > Key
Definition: dyna_io.h:204
std::unordered_map< Node *, Elem * > spline_nodeelem_ptrs
Definition: dyna_io.h:160
static ElementMaps _element_maps
A static ElementMaps object that is built statically and used by all instances of this class...
Definition: dyna_io.h:213
static const int max_ints_per_line
How many can we find on a line?
Definition: dyna_io.h:177
struct which holds a map from LS-DYNA to libMesh element numberings and vice-versa.
Definition: dyna_io.h:193
std::vector< unsigned int > nodes
Definition: dyna_io.h:142
std::map< Key, ElementDefinition > in
Definition: dyna_io.h:206
ElementDefinition(ElemType type_in, dyna_int_type dyna_type_in, dyna_int_type dim_in, dyna_int_type p_in)
Definition: dyna_io.C:98