Line data Source code
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 :
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 : #ifdef LIBMESH_ENABLE_DEPRECATED
103 : /**
104 : * Removes any spline nodes (both NodeElem and Node), leaving only
105 : * the FE mesh generated from those splines. Also removes node
106 : * constraints to the now-missing nodes.
107 : *
108 : * \p deprecated - use MeshTools::clear_spline_nodes(mesh) instead.
109 : */
110 : void clear_spline_nodes();
111 : #endif // LIBMESH_ENABLE_DEPRECATED
112 :
113 : /**
114 : * The integer type DYNA uses
115 : */
116 : typedef int32_t dyna_int_type;
117 :
118 : /**
119 : * Defines mapping from libMesh element types to LS-DYNA element
120 : * types or vice-versa.
121 : *
122 : * For the foreseeable future only isotropic p elements, with the
123 : * same polynomial degree in every direction, are supported.
124 : */
125 111489 : struct ElementDefinition
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 :
138 : ElemType type;
139 : dyna_int_type dyna_type;
140 : dyna_int_type dim;
141 : dyna_int_type p;
142 : std::vector<unsigned int> nodes;
143 : };
144 :
145 :
146 : /**
147 : * Finds the ElementDefinition corresponding to a particular element
148 : * type.
149 : */
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 :
162 : /**
163 : * Whether to keep or eventually discard spline nodes
164 : */
165 : bool _keep_spline_nodes;
166 :
167 : /**
168 : * Implementation of the read() function. This function
169 : * is called by the public interface function and implements
170 : * reading the file.
171 : */
172 : void read_mesh (std::istream & in);
173 :
174 : /**
175 : * How many can we find on a line?
176 : */
177 : static const int max_ints_per_line = 10;
178 :
179 : /**
180 : * The floating-point type DYNA uses
181 : */
182 : typedef double dyna_fp_type;
183 :
184 : /**
185 : * How many can we find on a line?
186 : */
187 : static const int max_fps_per_line = 5;
188 :
189 : /**
190 : * struct which holds a map from LS-DYNA to libMesh element numberings
191 : * and vice-versa.
192 : */
193 : struct ElementMaps
194 : {
195 : // Helper function to add a (key, value) pair to both maps
196 114723 : void add_def(const ElementDefinition & eledef)
197 : {
198 114723 : out.emplace(eledef.type, eledef);
199 114723 : in.emplace(std::make_tuple(eledef.dyna_type, eledef.dim, eledef.p), eledef);
200 114723 : }
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 :
209 : /**
210 : * A static ElementMaps object that is built statically and used by
211 : * all instances of this class.
212 : */
213 : static ElementMaps _element_maps;
214 :
215 : /**
216 : * A static function used to construct the _element_maps struct,
217 : * statically.
218 : */
219 : static ElementMaps build_element_maps();
220 : };
221 :
222 :
223 : } // namespace libMesh
224 :
225 : #endif // LIBMESH_DYNA_IO_H
|