Line data Source code
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 :
42 : /**
43 : * \brief Reading and writing meshes in (a subset of) LS-DYNA format.
44 : *
45 : * The initial implementation only handles cards in the format
46 : * described in "Geometry import to LS-DYNA", for isogeometric
47 : * analysis.
48 : *
49 : * \author Roy H. Stogner
50 : * \date 2019
51 : */
52 : class DynaIO : public MeshInput<MeshBase>
53 : {
54 : public:
55 :
56 : /**
57 : * Constructor. Takes a non-const Mesh reference which it
58 : * will fill up with elements via the read() command.
59 : *
60 : * By default \p keep_spline_nodes is true, and when reading a BEXT
61 : * file we retain the spline nodes and their constraints on FE
62 : * nodes. If \p keep_spline_nodes is false, we only keep the FE
63 : * elements, which are no longer constrained to have higher
64 : * continuity.
65 : */
66 : explicit
67 : DynaIO (MeshBase & mesh,
68 : bool keep_spline_nodes = true);
69 :
70 : /**
71 : * Reads in a mesh in the Dyna format from the ASCII file given by
72 : * name.
73 : *
74 : * \note The user is responsible for calling Mesh::prepare_for_use()
75 : * after reading the mesh and before using it.
76 : *
77 : * \note To safely use DynaIO::add_spline_constraints with a
78 : * DistributedMesh, currently the user must
79 : * allow_remote_element_removal(false) and allow_renumbering(false)
80 : * before the mesh is read.
81 : *
82 : * The patch ids defined in the Dyna file are stored as subdomain
83 : * ids.
84 : *
85 : * The spline nodes defined in the Dyna file are added to the mesh
86 : * with type NodeElem. The only connection between spline nodes and
87 : * finite element nodes will be user constraint equations, so using
88 : * a space-filling-curve partitioner for these meshes might be a
89 : * good idea.
90 : */
91 : virtual void read (const std::string & name) override;
92 :
93 : /**
94 : * Constrains finite element degrees of freedom in terms of spline
95 : * degrees of freedom by adding user-defined constraint rows to \p
96 : * sys
97 : */
98 : void add_spline_constraints(DofMap & dof_map,
99 : unsigned int sys_num,
100 : unsigned int var_num);
101 :
102 : /**
103 : * The integer type DYNA uses
104 : */
105 : typedef int32_t dyna_int_type;
106 :
107 : /**
108 : * Defines mapping from libMesh element types to LS-DYNA element
109 : * types or vice-versa.
110 : *
111 : * For the foreseeable future only isotropic p elements, with the
112 : * same polynomial degree in every direction, are supported.
113 : */
114 112924 : struct ElementDefinition
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 :
127 : ElemType type;
128 : dyna_int_type dyna_type;
129 : dyna_int_type dim;
130 : dyna_int_type p;
131 : std::vector<unsigned int> nodes;
132 : };
133 :
134 :
135 : /**
136 : * Finds the ElementDefinition corresponding to a particular element
137 : * type.
138 : */
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 :
151 : /**
152 : * Whether to keep or eventually discard spline nodes
153 : */
154 : bool _keep_spline_nodes;
155 :
156 : /**
157 : * Implementation of the read() function. This function
158 : * is called by the public interface function and implements
159 : * reading the file.
160 : */
161 : void read_mesh (std::istream & in);
162 :
163 : /**
164 : * How many can we find on a line?
165 : */
166 : static const int max_ints_per_line = 10;
167 :
168 : /**
169 : * The floating-point type DYNA uses
170 : */
171 : typedef double dyna_fp_type;
172 :
173 : /**
174 : * How many can we find on a line?
175 : */
176 : static const int max_fps_per_line = 5;
177 :
178 : /**
179 : * struct which holds a map from LS-DYNA to libMesh element numberings
180 : * and vice-versa.
181 : */
182 : struct ElementMaps
183 : {
184 : // Helper function to add a (key, value) pair to both maps
185 116200 : void add_def(const ElementDefinition & eledef)
186 : {
187 116200 : out.emplace(eledef.type, eledef);
188 116200 : in.emplace(std::make_tuple(eledef.dyna_type, eledef.dim, eledef.p), eledef);
189 116200 : }
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 :
198 : /**
199 : * A static ElementMaps object that is built statically and used by
200 : * all instances of this class.
201 : */
202 : static ElementMaps _element_maps;
203 :
204 : /**
205 : * A static function used to construct the _element_maps struct,
206 : * statically.
207 : */
208 : static ElementMaps build_element_maps();
209 : };
210 :
211 :
212 : } // namespace libMesh
213 :
214 : #endif // LIBMESH_DYNA_IO_H
|