libMesh
dyna_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2026 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 
105  typedef int32_t dyna_int_type;
106 
115  {
116  ElementDefinition(ElemType type_in,
117  dyna_int_type dyna_type_in,
118  dyna_int_type dim_in,
119  dyna_int_type p_in);
120 
121  ElementDefinition(ElemType type_in,
122  dyna_int_type dyna_type_in,
123  dyna_int_type dim_in,
124  dyna_int_type p_in,
125  std::vector<unsigned int> && nodes_in);
126 
131  std::vector<unsigned int> nodes;
132  };
133 
134 
139  static const ElementDefinition &
140  find_elem_definition(dyna_int_type dyna_elem, int dim, int p);
141 
142  static const ElementDefinition &
143  find_elem_definition(ElemType libmesh_elem, int dim, int p);
144 
145 private:
146  // Keep track of spline node indexing, so as to enable adding
147  // constraint rows easily later.
148  std::vector<Node *> spline_node_ptrs;
149  std::unordered_map<Node *, Elem *> spline_nodeelem_ptrs;
150 
155 
161  void read_mesh (std::istream & in);
162 
166  static const int max_ints_per_line = 10;
167 
171  typedef double dyna_fp_type;
172 
176  static const int max_fps_per_line = 5;
177 
182  struct ElementMaps
183  {
184  // Helper function to add a (key, value) pair to both maps
185  void add_def(const ElementDefinition & eledef)
186  {
187  out.emplace(eledef.type, eledef);
188  in.emplace(std::make_tuple(eledef.dyna_type, eledef.dim, eledef.p), eledef);
189  }
190 
191  std::map<ElemType, ElementDefinition> out;
192 
193  typedef std::tuple<dyna_int_type, dyna_int_type, dyna_int_type> Key;
194 
195  std::map<Key, ElementDefinition> in;
196  };
197 
203 
209 };
210 
211 
212 } // namespace libMesh
213 
214 #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:148
int32_t dyna_int_type
The integer type DYNA uses.
Definition: dyna_io.h:105
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:171
unsigned int dim
void read_mesh(std::istream &in)
Implementation of the read() function.
Definition: dyna_io.C:174
Defines mapping from libMesh element types to LS-DYNA element types or vice-versa.
Definition: dyna_io.h:114
void add_def(const ElementDefinition &eledef)
Definition: dyna_io.h:185
bool _keep_spline_nodes
Whether to keep or eventually discard spline nodes.
Definition: dyna_io.h:154
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:80
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:733
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:741
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:60
std::map< ElemType, ElementDefinition > out
Definition: dyna_io.h:191
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:176
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:193
std::unordered_map< Node *, Elem * > spline_nodeelem_ptrs
Definition: dyna_io.h:149
static ElementMaps _element_maps
A static ElementMaps object that is built statically and used by all instances of this class...
Definition: dyna_io.h:202
static const int max_ints_per_line
How many can we find on a line?
Definition: dyna_io.h:166
struct which holds a map from LS-DYNA to libMesh element numberings and vice-versa.
Definition: dyna_io.h:182
std::vector< unsigned int > nodes
Definition: dyna_io.h:131
std::map< Key, ElementDefinition > in
Definition: dyna_io.h:195
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